mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
SCRIPT: wpiformat
This commit is contained in:
committed by
Peter Johnson
parent
ae6bdc9d25
commit
2109161534
@@ -136,8 +136,9 @@ static bool LoadWindowStorageImpl(const std::string& filename) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return JsonToWindow(wpi::util::json::parse(fileBuffer.value()->GetCharBuffer()),
|
||||
filename.c_str());
|
||||
return JsonToWindow(
|
||||
wpi::util::json::parse(fileBuffer.value()->GetCharBuffer()),
|
||||
filename.c_str());
|
||||
} catch (wpi::util::json::parse_error& e) {
|
||||
ImGui::LogText("Error loading %s: %s", filename.c_str(), e.what());
|
||||
return false;
|
||||
@@ -154,8 +155,9 @@ static bool LoadStorageRootImpl(Context* ctx, const std::string& filename,
|
||||
}
|
||||
auto [it, createdStorage] = ctx->storageRoots.try_emplace(rootName);
|
||||
try {
|
||||
it->second.FromJson(wpi::util::json::parse(fileBuffer.value()->GetCharBuffer()),
|
||||
filename.c_str());
|
||||
it->second.FromJson(
|
||||
wpi::util::json::parse(fileBuffer.value()->GetCharBuffer()),
|
||||
filename.c_str());
|
||||
} catch (wpi::util::json::parse_error& e) {
|
||||
ImGui::LogText("Error loading %s: %s", filename.c_str(), e.what());
|
||||
if (createdStorage) {
|
||||
@@ -214,8 +216,10 @@ static wpi::util::json WindowToJson() {
|
||||
if (line[0] == '[') {
|
||||
// new section
|
||||
auto [section, subsection] = wpi::util::split(line, ']');
|
||||
section = wpi::util::drop_front(section); // drop '['; ']' was dropped by split
|
||||
subsection = wpi::util::drop_back(wpi::util::drop_front(subsection)); // drop []
|
||||
section =
|
||||
wpi::util::drop_front(section); // drop '['; ']' was dropped by split
|
||||
subsection =
|
||||
wpi::util::drop_back(wpi::util::drop_front(subsection)); // drop []
|
||||
auto& jsection = out[section];
|
||||
if (jsection.is_null()) {
|
||||
jsection = wpi::util::json::object();
|
||||
@@ -472,7 +476,7 @@ void wpi::glass::End() {
|
||||
}
|
||||
|
||||
bool wpi::glass::BeginChild(const char* str_id, const ImVec2& size, bool border,
|
||||
ImGuiWindowFlags flags) {
|
||||
ImGuiWindowFlags flags) {
|
||||
PushStorageStack(str_id);
|
||||
return ImGui::BeginChild(str_id, size, border, flags);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ std::string wpi::glass::MakeSourceId(std::string_view id, int index) {
|
||||
return fmt::format("{}[{}]", id, index);
|
||||
}
|
||||
|
||||
std::string wpi::glass::MakeSourceId(std::string_view id, int index, int index2) {
|
||||
std::string wpi::glass::MakeSourceId(std::string_view id, int index,
|
||||
int index2) {
|
||||
return fmt::format("{}[{},{}]", id, index, index2);
|
||||
}
|
||||
|
||||
|
||||
@@ -345,7 +345,8 @@ void Storage::EraseChildren() {
|
||||
});
|
||||
}
|
||||
|
||||
static bool JsonArrayToStorage(Storage::Value* valuePtr, const wpi::util::json& jarr,
|
||||
static bool JsonArrayToStorage(Storage::Value* valuePtr,
|
||||
const wpi::util::json& jarr,
|
||||
const char* filename) {
|
||||
auto& arr = jarr.get_ref<const wpi::util::json::array_t&>();
|
||||
if (arr.empty()) {
|
||||
|
||||
@@ -25,7 +25,8 @@ void wpi::glass::DisplayAnalogInput(AnalogInputModel* model, int index) {
|
||||
std::string& name = GetStorage().GetString("name");
|
||||
char label[128];
|
||||
if (!name.empty()) {
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{}]###name", name, index);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{}]###name", name,
|
||||
index);
|
||||
} else {
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "In[{}]###name", index);
|
||||
}
|
||||
@@ -48,7 +49,7 @@ void wpi::glass::DisplayAnalogInput(AnalogInputModel* model, int index) {
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayAnalogInputs(AnalogInputsModel* model,
|
||||
std::string_view noneMsg) {
|
||||
std::string_view noneMsg) {
|
||||
ImGui::Text("(Use Ctrl+Click to edit value)");
|
||||
bool hasAny = false;
|
||||
bool first = true;
|
||||
|
||||
@@ -106,7 +106,7 @@ void wpi::glass::DisplayDIO(DIOModel* model, int index, bool outputsEnabled) {
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayDIOs(DIOsModel* model, bool outputsEnabled,
|
||||
std::string_view noneMsg) {
|
||||
std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
|
||||
|
||||
@@ -73,11 +73,11 @@ void wpi::glass::DisplayEncoder(EncoderModel* model) {
|
||||
std::string& name = GetStorage().GetString("name");
|
||||
char label[128];
|
||||
if (!name.empty()) {
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{},{}]###header", name,
|
||||
chA, chB);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{},{}]###header",
|
||||
name, chA, chB);
|
||||
} else {
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "Encoder[{},{}]###header", chA,
|
||||
chB);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label),
|
||||
"Encoder[{},{}]###header", chA, chB);
|
||||
}
|
||||
|
||||
// header
|
||||
@@ -159,7 +159,8 @@ void wpi::glass::DisplayEncoder(EncoderModel* model) {
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayEncoders(EncodersModel* model, std::string_view noneMsg) {
|
||||
void wpi::glass::DisplayEncoders(EncodersModel* model,
|
||||
std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
model->ForEachEncoder([&](EncoderModel& encoder, int i) {
|
||||
hasAny = true;
|
||||
|
||||
@@ -25,7 +25,8 @@ void wpi::glass::DisplayPWM(PWMModel* model, int index, bool outputsEnabled) {
|
||||
std::string& name = GetStorage().GetString("name");
|
||||
char label[128];
|
||||
if (!name.empty()) {
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{}]###name", name, index);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{}]###name", name,
|
||||
index);
|
||||
} else {
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "PWM[{}]###name", index);
|
||||
}
|
||||
@@ -39,7 +40,7 @@ void wpi::glass::DisplayPWM(PWMModel* model, int index, bool outputsEnabled) {
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayPWMs(PWMsModel* model, bool outputsEnabled,
|
||||
std::string_view noneMsg) {
|
||||
std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
bool first = true;
|
||||
model->ForEachPWM([&](PWMModel& pwm, int i) {
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
using namespace wpi::glass;
|
||||
|
||||
bool wpi::glass::DisplayPneumaticControlSolenoids(PneumaticControlModel* model,
|
||||
int index, bool outputsEnabled) {
|
||||
int index,
|
||||
bool outputsEnabled) {
|
||||
wpi::util::SmallVector<int, 16> channels;
|
||||
model->ForEachSolenoid([&](SolenoidModel& solenoid, int j) {
|
||||
if (auto data = solenoid.GetOutputData()) {
|
||||
@@ -49,10 +50,10 @@ bool wpi::glass::DisplayPneumaticControlSolenoids(PneumaticControlModel* model,
|
||||
char label[128];
|
||||
if (!name.empty()) {
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{}]###header", name,
|
||||
index);
|
||||
index);
|
||||
} else {
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}[{}]###header",
|
||||
model->GetName(), index);
|
||||
model->GetName(), index);
|
||||
}
|
||||
|
||||
// header
|
||||
@@ -87,9 +88,9 @@ bool wpi::glass::DisplayPneumaticControlSolenoids(PneumaticControlModel* model,
|
||||
return true;
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayPneumaticControlsSolenoids(PneumaticControlsModel* model,
|
||||
bool outputsEnabled,
|
||||
std::string_view noneMsg) {
|
||||
void wpi::glass::DisplayPneumaticControlsSolenoids(
|
||||
PneumaticControlsModel* model, bool outputsEnabled,
|
||||
std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
model->ForEachPneumaticControl(
|
||||
[&](PneumaticControlModel& pneumaticControl, int i) {
|
||||
@@ -106,7 +107,7 @@ void wpi::glass::DisplayPneumaticControlsSolenoids(PneumaticControlsModel* model
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayCompressorDevice(CompressorModel* model, int index,
|
||||
bool outputsEnabled) {
|
||||
bool outputsEnabled) {
|
||||
if (!model || !model->Exists()) {
|
||||
return;
|
||||
}
|
||||
@@ -155,7 +156,7 @@ void wpi::glass::DisplayCompressorDevice(CompressorModel* model, int index,
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayCompressorsDevice(PneumaticControlsModel* model,
|
||||
bool outputsEnabled) {
|
||||
bool outputsEnabled) {
|
||||
model->ForEachPneumaticControl(
|
||||
[&](PneumaticControlModel& pneumaticControl, int i) {
|
||||
DisplayCompressorDevice(pneumaticControl.GetCompressor(), i,
|
||||
|
||||
@@ -34,9 +34,11 @@ static float DisplayChannel(PowerDistributionModel& pdp, int channel) {
|
||||
return width;
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayPowerDistribution(PowerDistributionModel* model, int index) {
|
||||
void wpi::glass::DisplayPowerDistribution(PowerDistributionModel* model,
|
||||
int index) {
|
||||
char name[128];
|
||||
wpi::util::format_to_n_c_str(name, sizeof(name), "PowerDistribution[{}]", index);
|
||||
wpi::util::format_to_n_c_str(name, sizeof(name), "PowerDistribution[{}]",
|
||||
index);
|
||||
|
||||
if (CollapsingHeader(name)) {
|
||||
// temperature
|
||||
@@ -81,7 +83,7 @@ void wpi::glass::DisplayPowerDistribution(PowerDistributionModel* model, int ind
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayPowerDistributions(PowerDistributionsModel* model,
|
||||
std::string_view noneMsg) {
|
||||
std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
model->ForEachPowerDistribution([&](PowerDistributionModel& pdp, int i) {
|
||||
hasAny = true;
|
||||
|
||||
@@ -151,28 +151,28 @@ static inline bool DeviceValueImpl(const char* name, bool readonly,
|
||||
}
|
||||
|
||||
bool wpi::glass::DeviceBoolean(const char* name, bool readonly, bool* value,
|
||||
const DataSource* source) {
|
||||
const DataSource* source) {
|
||||
return DeviceValueImpl(name, readonly, source, DeviceBooleanImpl, value);
|
||||
}
|
||||
|
||||
bool wpi::glass::DeviceDouble(const char* name, bool readonly, double* value,
|
||||
const DataSource* source) {
|
||||
const DataSource* source) {
|
||||
return DeviceValueImpl(name, readonly, source, DeviceDoubleImpl, value);
|
||||
}
|
||||
|
||||
bool wpi::glass::DeviceEnum(const char* name, bool readonly, int* value,
|
||||
const char** options, int32_t numOptions,
|
||||
const DataSource* source) {
|
||||
const char** options, int32_t numOptions,
|
||||
const DataSource* source) {
|
||||
return DeviceValueImpl(name, readonly, source, DeviceEnumImpl, value, options,
|
||||
numOptions);
|
||||
}
|
||||
|
||||
bool wpi::glass::DeviceInt(const char* name, bool readonly, int32_t* value,
|
||||
const DataSource* source) {
|
||||
const DataSource* source) {
|
||||
return DeviceValueImpl(name, readonly, source, DeviceIntImpl, value);
|
||||
}
|
||||
|
||||
bool wpi::glass::DeviceLong(const char* name, bool readonly, int64_t* value,
|
||||
const DataSource* source) {
|
||||
const DataSource* source) {
|
||||
return DeviceValueImpl(name, readonly, source, DeviceLongImpl, value);
|
||||
}
|
||||
|
||||
@@ -48,9 +48,10 @@ enum DisplayUnits { kDisplayMeters = 0, kDisplayFeet, kDisplayInches };
|
||||
// Per-frame field data (not persistent)
|
||||
struct FieldFrameData {
|
||||
wpi::math::Translation2d GetPosFromScreen(const ImVec2& cursor) const {
|
||||
return {
|
||||
wpi::units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) / scale},
|
||||
wpi::units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) / scale}};
|
||||
return {wpi::units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) /
|
||||
scale},
|
||||
wpi::units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) /
|
||||
scale}};
|
||||
}
|
||||
ImVec2 GetScreenFromPos(const wpi::math::Translation2d& pos) const {
|
||||
return {min.x + scale * pos.X().to<float>(),
|
||||
@@ -94,7 +95,9 @@ class PopupState {
|
||||
|
||||
SelectedTargetInfo* GetTarget() { return &m_target; }
|
||||
FieldObjectModel* GetInsertModel() { return m_insertModel; }
|
||||
std::span<const wpi::math::Pose2d> GetInsertPoses() const { return m_insertPoses; }
|
||||
std::span<const wpi::math::Pose2d> GetInsertPoses() const {
|
||||
return m_insertPoses;
|
||||
}
|
||||
|
||||
void Display(Field2DModel* model, const FieldFrameData& ffd);
|
||||
|
||||
@@ -282,8 +285,9 @@ static double ConvertDisplayAngle(wpi::units::degree_t v) {
|
||||
return v.value();
|
||||
}
|
||||
|
||||
static bool InputLength(const char* label, wpi::units::meter_t* v, double step = 0.0,
|
||||
double step_fast = 0.0, const char* format = "%.6f",
|
||||
static bool InputLength(const char* label, wpi::units::meter_t* v,
|
||||
double step = 0.0, double step_fast = 0.0,
|
||||
const char* format = "%.6f",
|
||||
ImGuiInputTextFlags flags = 0) {
|
||||
double dv = ConvertDisplayLength(*v);
|
||||
if (ImGui::InputDouble(label, &dv, step, step_fast, format, flags)) {
|
||||
@@ -316,8 +320,9 @@ static bool InputFloatLength(const char* label, float* v, double step = 0.0,
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool InputAngle(const char* label, wpi::units::degree_t* v, double step = 0.0,
|
||||
double step_fast = 0.0, const char* format = "%.6f",
|
||||
static bool InputAngle(const char* label, wpi::units::degree_t* v,
|
||||
double step = 0.0, double step_fast = 0.0,
|
||||
const char* format = "%.6f",
|
||||
ImGuiInputTextFlags flags = 0) {
|
||||
double dv = ConvertDisplayAngle(*v);
|
||||
if (ImGui::InputDouble(label, &dv, step, step_fast, format, flags)) {
|
||||
@@ -465,7 +470,8 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
try {
|
||||
image = j.at("field-image").get<std::string>();
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-image: {}\n", e.what());
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-image: {}\n",
|
||||
e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -478,7 +484,7 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
right = j.at("field-corners").at("bottom-right").at(0).get<int>();
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-corners: {}\n",
|
||||
e.what());
|
||||
e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -489,7 +495,8 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
width = j.at("field-size").at(0).get<float>();
|
||||
height = j.at("field-size").at(1).get<float>();
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-size: {}\n", e.what());
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-size: {}\n",
|
||||
e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -498,7 +505,8 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
try {
|
||||
unit = j.at("field-unit").get<std::string>();
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-unit: {}\n", e.what());
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-unit: {}\n",
|
||||
e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -513,9 +521,9 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
int fieldHeight = m_bottom - m_top;
|
||||
if (std::abs((fieldWidth / width) - (fieldHeight / height)) > 0.3) {
|
||||
wpi::util::print(stderr,
|
||||
"GUI: Field X and Y scaling substantially different: "
|
||||
"xscale={} yscale={}\n",
|
||||
(fieldWidth / width), (fieldHeight / height));
|
||||
"GUI: Field X and Y scaling substantially different: "
|
||||
"xscale={} yscale={}\n",
|
||||
(fieldWidth / width), (fieldHeight / height));
|
||||
}
|
||||
|
||||
if (!filename.empty()) {
|
||||
@@ -772,8 +780,9 @@ bool ObjectInfo::LoadImageImpl(const std::string& fn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PoseFrameData::PoseFrameData(const wpi::math::Pose2d& pose, FieldObjectModel& model,
|
||||
size_t index, const FieldFrameData& ffd,
|
||||
PoseFrameData::PoseFrameData(const wpi::math::Pose2d& pose,
|
||||
FieldObjectModel& model, size_t index,
|
||||
const FieldFrameData& ffd,
|
||||
const DisplayOptions& displayOptions)
|
||||
: m_model{model},
|
||||
m_index{index},
|
||||
@@ -1086,7 +1095,7 @@ void FieldDisplay::Display(FieldInfo* field, Field2DModel* model,
|
||||
if (target->corner != 1) {
|
||||
gDragState.initialAngle =
|
||||
wpi::units::radian_t{std::atan2(gDragState.initialOffset.y,
|
||||
gDragState.initialOffset.x)} +
|
||||
gDragState.initialOffset.x)} +
|
||||
target->rot;
|
||||
}
|
||||
}
|
||||
@@ -1182,7 +1191,8 @@ void PopupState::Display(Field2DModel* model, const FieldFrameData& ffd) {
|
||||
void PopupState::DisplayTarget(Field2DModel* model, const FieldFrameData& ffd) {
|
||||
ImGui::Text("%s[%d]", m_target.name.c_str(),
|
||||
static_cast<int>(m_target.index));
|
||||
wpi::math::Pose2d pose{ffd.GetPosFromScreen(m_target.poseCenter), m_target.rot};
|
||||
wpi::math::Pose2d pose{ffd.GetPosFromScreen(m_target.poseCenter),
|
||||
m_target.rot};
|
||||
if (InputPose(&pose)) {
|
||||
m_target.poseCenter = ffd.GetScreenFromPos(pose.Translation());
|
||||
m_target.rot = pose.Rotation().Radians();
|
||||
@@ -1277,7 +1287,8 @@ void PopupState::DisplayInsert(Field2DModel* model) {
|
||||
}
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayField2D(Field2DModel* model, const ImVec2& contentSize) {
|
||||
void wpi::glass::DisplayField2D(Field2DModel* model,
|
||||
const ImVec2& contentSize) {
|
||||
auto& storage = GetStorage();
|
||||
auto field = storage.GetData<FieldInfo>();
|
||||
if (!field) {
|
||||
|
||||
@@ -38,9 +38,10 @@ namespace {
|
||||
// Per-frame data (not persistent)
|
||||
struct FrameData {
|
||||
wpi::math::Translation2d GetPosFromScreen(const ImVec2& cursor) const {
|
||||
return {
|
||||
wpi::units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) / scale},
|
||||
wpi::units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) / scale}};
|
||||
return {wpi::units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) /
|
||||
scale},
|
||||
wpi::units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) /
|
||||
scale}};
|
||||
}
|
||||
ImVec2 GetScreenFromPos(const wpi::math::Translation2d& pos) const {
|
||||
return {min.x + scale * pos.X().to<float>(),
|
||||
@@ -67,7 +68,8 @@ class BackgroundInfo {
|
||||
void DisplaySettings();
|
||||
|
||||
void LoadImage();
|
||||
FrameData GetFrameData(ImVec2 min, ImVec2 max, wpi::math::Translation2d dims) const;
|
||||
FrameData GetFrameData(ImVec2 min, ImVec2 max,
|
||||
wpi::math::Translation2d dims) const;
|
||||
void Draw(ImDrawList* drawList, const FrameData& frameData,
|
||||
ImU32 bgColor) const;
|
||||
|
||||
@@ -184,11 +186,12 @@ void FrameData::DrawObject(ImDrawList* drawList, MechanismObjectModel& objModel,
|
||||
const wpi::math::Pose2d& pose) const {
|
||||
const char* type = objModel.GetType();
|
||||
if (std::string_view{type} == "line") {
|
||||
auto startPose =
|
||||
pose + wpi::math::Transform2d{wpi::math::Translation2d{}, objModel.GetAngle()};
|
||||
auto startPose = pose + wpi::math::Transform2d{wpi::math::Translation2d{},
|
||||
objModel.GetAngle()};
|
||||
auto endPose =
|
||||
startPose +
|
||||
wpi::math::Transform2d{wpi::math::Translation2d{objModel.GetLength(), 0_m}, 0_deg};
|
||||
wpi::math::Transform2d{
|
||||
wpi::math::Translation2d{objModel.GetLength(), 0_m}, 0_deg};
|
||||
drawList->AddLine(GetScreenFromPos(startPose.Translation()),
|
||||
GetScreenFromPos(endPose.Translation()),
|
||||
objModel.GetColor(), objModel.GetWeight());
|
||||
@@ -203,7 +206,7 @@ void FrameData::DrawGroup(ImDrawList* drawList, MechanismObjectGroup& group,
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayMechanism2D(Mechanism2DModel* model,
|
||||
const ImVec2& contentSize) {
|
||||
const ImVec2& contentSize) {
|
||||
auto& storage = GetStorage();
|
||||
auto bg = storage.GetData<BackgroundInfo>();
|
||||
if (!bg) {
|
||||
|
||||
@@ -350,8 +350,9 @@ PlotSeries::Action PlotSeries::EmitPlot(PlotView& view, double now, size_t i,
|
||||
CheckSource();
|
||||
|
||||
char label[128];
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###name{}_{}", GetName(),
|
||||
static_cast<int>(i), static_cast<int>(plotIndex));
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###name{}_{}",
|
||||
GetName(), static_cast<int>(i),
|
||||
static_cast<int>(plotIndex));
|
||||
|
||||
int size = m_size;
|
||||
int offset = m_offset;
|
||||
@@ -619,7 +620,7 @@ void Plot::EmitPlot(PlotView& view, double now, bool paused, size_t i) {
|
||||
|
||||
char label[128];
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###plot{}", m_name,
|
||||
static_cast<int>(i));
|
||||
static_cast<int>(i));
|
||||
|
||||
ImPlotFlags plotFlags = (m_legend ? 0 : ImPlotFlags_NoLegend) |
|
||||
(m_crosshairs ? ImPlotFlags_Crosshairs : 0) |
|
||||
@@ -976,15 +977,16 @@ void PlotView::Settings() {
|
||||
|
||||
char name[64];
|
||||
if (!plot->GetName().empty()) {
|
||||
wpi::util::format_to_n_c_str(name, sizeof(name), "{}", plot->GetName().c_str());
|
||||
wpi::util::format_to_n_c_str(name, sizeof(name), "{}",
|
||||
plot->GetName().c_str());
|
||||
} else {
|
||||
wpi::util::format_to_n_c_str(name, sizeof(name), "Plot {}",
|
||||
static_cast<int>(i));
|
||||
static_cast<int>(i));
|
||||
}
|
||||
|
||||
char label[90];
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###header{}", name,
|
||||
static_cast<int>(i));
|
||||
static_cast<int>(i));
|
||||
|
||||
bool open = ImGui::CollapsingHeader(label);
|
||||
|
||||
@@ -1053,7 +1055,8 @@ void PlotProvider::DisplayMenu() {
|
||||
char id[32];
|
||||
size_t numWindows = m_windows.size();
|
||||
for (size_t i = 0; i <= numWindows; ++i) {
|
||||
wpi::util::format_to_n_c_str(id, sizeof(id), "Plot <{}>", static_cast<int>(i));
|
||||
wpi::util::format_to_n_c_str(id, sizeof(id), "Plot <{}>",
|
||||
static_cast<int>(i));
|
||||
|
||||
bool match = false;
|
||||
for (size_t j = 0; j < numWindows; ++j) {
|
||||
|
||||
@@ -220,7 +220,7 @@ std::optional<double> ValueFromString(std::string_view str) {
|
||||
|
||||
template <typename V>
|
||||
wpi::util::expected<V, std::string> EvalAll(std::stack<Operator>& operStack,
|
||||
std::stack<V>& valStack) {
|
||||
std::stack<V>& valStack) {
|
||||
while (!operStack.empty()) {
|
||||
if (valStack.size() < 2) {
|
||||
return wpi::util::unexpected("Missing operand");
|
||||
@@ -307,7 +307,8 @@ wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
// Acts as if there was open paren at start of expression. EvalAll will
|
||||
// clear both stacks, and leave the result value on top of valStack.
|
||||
// This makes sure everything inside the parentheses is evaluated first
|
||||
wpi::util::expected<V, std::string> result = EvalAll<V>(operStack, valStack);
|
||||
wpi::util::expected<V, std::string> result =
|
||||
EvalAll<V>(operStack, valStack);
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
@@ -316,7 +317,7 @@ wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
|
||||
case TokenType::Error:
|
||||
return wpi::util::unexpected(std::string("Unexpected character: ")
|
||||
.append(token.str, token.strLen));
|
||||
.append(token.str, token.strLen));
|
||||
|
||||
default:
|
||||
Operator op = GetOperator(token.type);
|
||||
|
||||
@@ -32,9 +32,11 @@ void NameSetting::GetName(char* buf, size_t size, const char* defaultName,
|
||||
void NameSetting::GetName(char* buf, size_t size, const char* defaultName,
|
||||
int index, int index2) const {
|
||||
if (!m_name.empty()) {
|
||||
wpi::util::format_to_n_c_str(buf, size, "{} [{},{}]", m_name, index, index2);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{} [{},{}]", m_name, index,
|
||||
index2);
|
||||
} else {
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}[{},{}]", defaultName, index, index2);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}[{},{}]", defaultName, index,
|
||||
index2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,28 +45,30 @@ void NameSetting::GetLabel(char* buf, size_t size,
|
||||
if (!m_name.empty()) {
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}###Name{}", m_name, defaultName);
|
||||
} else {
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}###Name{}", defaultName, defaultName);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}###Name{}", defaultName,
|
||||
defaultName);
|
||||
}
|
||||
}
|
||||
|
||||
void NameSetting::GetLabel(char* buf, size_t size, const char* defaultName,
|
||||
int index) const {
|
||||
if (!m_name.empty()) {
|
||||
wpi::util::format_to_n_c_str(buf, size, "{} [{}]###Name{}", m_name, index, index);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{} [{}]###Name{}", m_name, index,
|
||||
index);
|
||||
} else {
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}[{}]###Name{}", defaultName, index,
|
||||
index);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}[{}]###Name{}", defaultName,
|
||||
index, index);
|
||||
}
|
||||
}
|
||||
|
||||
void NameSetting::GetLabel(char* buf, size_t size, const char* defaultName,
|
||||
int index, int index2) const {
|
||||
if (!m_name.empty()) {
|
||||
wpi::util::format_to_n_c_str(buf, size, "{} [{},{}]###Name{}", m_name, index,
|
||||
index2, index);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{} [{},{}]###Name{}", m_name,
|
||||
index, index2, index);
|
||||
} else {
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}[{},{}]###Name{}", defaultName, index,
|
||||
index2, index);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}[{},{}]###Name{}", defaultName,
|
||||
index, index2, index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user