SCRIPT namespace replacements

This commit is contained in:
PJ Reiniger
2025-11-07 20:00:05 -05:00
committed by Peter Johnson
parent ae6c043632
commit 9aca8e0fd6
2622 changed files with 22275 additions and 22275 deletions

View File

@@ -7,9 +7,9 @@
#include <IconsFontAwesome6.h>
#include <imgui.h>
using namespace glass;
using namespace wpi::glass;
void glass::DisplayAlerts(AlertsModel* model) {
void wpi::glass::DisplayAlerts(AlertsModel* model) {
auto& infos = model->GetInfos();
auto& warnings = model->GetWarnings();
auto& errors = model->GetErrors();

View File

@@ -9,9 +9,9 @@
#include "wpi/glass/Context.hpp"
#include "wpi/glass/DataSource.hpp"
using namespace glass;
using namespace wpi::glass;
void glass::DisplayCommandScheduler(CommandSchedulerModel* m) {
void wpi::glass::DisplayCommandScheduler(CommandSchedulerModel* m) {
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 20);
ImGui::Text("Scheduled Commands: ");
ImGui::Separator();

View File

@@ -8,9 +8,9 @@
#include "wpi/glass/DataSource.hpp"
using namespace glass;
using namespace wpi::glass;
void glass::DisplayCommandSelector(CommandSelectorModel* m) {
void wpi::glass::DisplayCommandSelector(CommandSelectorModel* m) {
if (auto name = m->GetName()) {
ImGui::Text("%s", name);
}

View File

@@ -14,7 +14,7 @@
#include "wpi/glass/DataSource.hpp"
#include "wpi/util/StringExtras.hpp"
using namespace glass;
using namespace wpi::glass;
void DeviceTreeModel::Update() {
for (auto&& display : m_displays) {
@@ -41,11 +41,11 @@ void DeviceTreeModel::Display() {
}
}
void glass::HideDevice(const char* id) {
void wpi::glass::HideDevice(const char* id) {
gContext->deviceHidden[id] = true;
}
bool glass::BeginDevice(const char* id, ImGuiTreeNodeFlags flags) {
bool wpi::glass::BeginDevice(const char* id, ImGuiTreeNodeFlags flags) {
if (gContext->deviceHidden[id]) {
return false;
}
@@ -56,9 +56,9 @@ bool glass::BeginDevice(const char* id, ImGuiTreeNodeFlags flags) {
std::string& name = GetStorage().GetString("name");
char label[128];
if (name.empty()) {
wpi::format_to_n_c_str(label, sizeof(label), "{}###header", id);
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###header", id);
} else {
wpi::format_to_n_c_str(label, sizeof(label), "{}###header", name);
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###header", name);
}
bool open = CollapsingHeader(label, flags);
@@ -70,7 +70,7 @@ bool glass::BeginDevice(const char* id, ImGuiTreeNodeFlags flags) {
return open;
}
void glass::EndDevice() {
void wpi::glass::EndDevice() {
PopID();
}
@@ -150,29 +150,29 @@ static inline bool DeviceValueImpl(const char* name, bool readonly,
}
}
bool glass::DeviceBoolean(const char* name, bool readonly, bool* value,
bool wpi::glass::DeviceBoolean(const char* name, bool readonly, bool* value,
const DataSource* source) {
return DeviceValueImpl(name, readonly, source, DeviceBooleanImpl, value);
}
bool glass::DeviceDouble(const char* name, bool readonly, double* value,
bool wpi::glass::DeviceDouble(const char* name, bool readonly, double* value,
const DataSource* source) {
return DeviceValueImpl(name, readonly, source, DeviceDoubleImpl, value);
}
bool glass::DeviceEnum(const char* name, bool readonly, int* value,
bool wpi::glass::DeviceEnum(const char* name, bool readonly, int* value,
const char** options, int32_t numOptions,
const DataSource* source) {
return DeviceValueImpl(name, readonly, source, DeviceEnumImpl, value, options,
numOptions);
}
bool glass::DeviceInt(const char* name, bool readonly, int32_t* value,
bool wpi::glass::DeviceInt(const char* name, bool readonly, int32_t* value,
const DataSource* source) {
return DeviceValueImpl(name, readonly, source, DeviceIntImpl, value);
}
bool glass::DeviceLong(const char* name, bool readonly, int64_t* value,
bool wpi::glass::DeviceLong(const char* name, bool readonly, int64_t* value,
const DataSource* source) {
return DeviceValueImpl(name, readonly, source, DeviceLongImpl, value);
}

View File

@@ -13,9 +13,9 @@
#include "wpi/glass/DataSource.hpp"
using namespace glass;
using namespace wpi::glass;
void glass::DisplayDrive(DriveModel* m) {
void wpi::glass::DisplayDrive(DriveModel* m) {
// Check if the model exists.
if (!m->Exists()) {
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));

View File

@@ -12,12 +12,12 @@
#include "wpi/glass/DataSource.hpp"
#include "wpi/util/SmallString.hpp"
using namespace glass;
using namespace wpi::glass;
static const char* stations[] = {"Invalid", "Red 1", "Red 2", "Red 3",
"Blue 1", "Blue 2", "Blue 3"};
void glass::DisplayFMS(FMSModel* model, bool editableDsAttached) {
void wpi::glass::DisplayFMS(FMSModel* model, bool editableDsAttached) {
if (!model->Exists() || model->IsReadOnly()) {
return DisplayFMSReadOnly(model);
}
@@ -89,7 +89,7 @@ void glass::DisplayFMS(FMSModel* model, bool editableDsAttached) {
}
}
void glass::DisplayFMSReadOnly(FMSModel* model) {
void wpi::glass::DisplayFMSReadOnly(FMSModel* model) {
bool exists = model->Exists();
if (!exists) {
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));
@@ -150,7 +150,7 @@ void glass::DisplayFMSReadOnly(FMSModel* model) {
}
if (auto data = model->GetGameSpecificMessageData()) {
if (exists) {
wpi::SmallString<64> gsmBuf;
wpi::util::SmallString<64> gsmBuf;
std::string_view gsm = data->GetValue(gsmBuf);
ImGui::Text("Game Specific: %.*s", static_cast<int>(gsm.size()),
gsm.data());

View File

@@ -37,7 +37,7 @@
#include "wpi/util/json.hpp"
#include "wpi/util/print.hpp"
using namespace glass;
using namespace wpi::glass;
namespace gui = wpi::gui;
@@ -47,12 +47,12 @@ enum DisplayUnits { kDisplayMeters = 0, kDisplayFeet, kDisplayInches };
// Per-frame field data (not persistent)
struct FieldFrameData {
frc::Translation2d GetPosFromScreen(const ImVec2& cursor) const {
wpi::math::Translation2d GetPosFromScreen(const ImVec2& cursor) const {
return {
units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) / scale},
units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) / scale}};
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 frc::Translation2d& pos) const {
ImVec2 GetScreenFromPos(const wpi::math::Translation2d& pos) const {
return {min.x + scale * pos.X().to<float>(),
max.y - scale * pos.Y().to<float>()};
}
@@ -71,7 +71,7 @@ struct SelectedTargetInfo {
FieldObjectModel* objModel = nullptr;
std::string name;
size_t index;
units::radian_t rot;
wpi::units::radian_t rot;
ImVec2 poseCenter; // center of the pose (screen coordinates)
ImVec2 center; // center of the target (screen coordinates)
float radius; // target radius
@@ -83,18 +83,18 @@ struct SelectedTargetInfo {
struct PoseDragState {
SelectedTargetInfo target;
ImVec2 initialOffset;
units::radian_t initialAngle = 0_rad;
wpi::units::radian_t initialAngle = 0_rad;
};
// Popup edit state
class PopupState {
public:
void Open(SelectedTargetInfo* target, const frc::Translation2d& pos);
void Open(SelectedTargetInfo* target, const wpi::math::Translation2d& pos);
void Close();
SelectedTargetInfo* GetTarget() { return &m_target; }
FieldObjectModel* GetInsertModel() { return m_insertModel; }
std::span<const frc::Pose2d> GetInsertPoses() const { return m_insertPoses; }
std::span<const wpi::math::Pose2d> GetInsertPoses() const { return m_insertPoses; }
void Display(Field2DModel* model, const FieldFrameData& ffd);
@@ -106,7 +106,7 @@ class PopupState {
// for insert
FieldObjectModel* m_insertModel;
std::vector<frc::Pose2d> m_insertPoses;
std::vector<wpi::math::Pose2d> m_insertPoses;
std::string m_insertName;
int m_insertIndex;
};
@@ -133,8 +133,8 @@ struct DisplayOptions {
float weight = kDefaultWeight;
int color = kDefaultColor;
units::meter_t width = kDefaultWidth;
units::meter_t length = kDefaultLength;
wpi::units::meter_t width = kDefaultWidth;
wpi::units::meter_t length = kDefaultLength;
bool arrows = kDefaultArrows;
int arrowSize = kDefaultArrowSize;
@@ -149,13 +149,13 @@ struct DisplayOptions {
// Per-frame pose data (not persistent)
class PoseFrameData {
public:
explicit PoseFrameData(const frc::Pose2d& pose, FieldObjectModel& model,
explicit PoseFrameData(const wpi::math::Pose2d& pose, FieldObjectModel& model,
size_t index, const FieldFrameData& ffd,
const DisplayOptions& displayOptions);
void SetPosition(const frc::Translation2d& pos);
void SetRotation(units::radian_t rot);
const frc::Rotation2d& GetRotation() const { return m_pose.Rotation(); }
const frc::Pose2d& GetPose() const { return m_pose; }
void SetPosition(const wpi::math::Translation2d& pos);
void SetRotation(wpi::units::radian_t rot);
const wpi::math::Rotation2d& GetRotation() const { return m_pose.Rotation(); }
const wpi::math::Pose2d& GetPose() const { return m_pose; }
float GetHitRadius() const { return m_hitRadius; }
void UpdateFrameData();
std::pair<int, float> IsHovered(const ImVec2& cursor) const;
@@ -181,7 +181,7 @@ class PoseFrameData {
float m_hitRadius;
frc::Pose2d m_pose;
wpi::math::Pose2d m_pose;
};
class ObjectInfo {
@@ -233,7 +233,7 @@ class FieldInfo {
FieldFrameData GetFrameData(ImVec2 min, ImVec2 max) const;
void Draw(ImDrawList* drawList, const FieldFrameData& frameData) const;
wpi::StringMap<ObjectInfo> m_objects;
wpi::util::StringMap<ObjectInfo> m_objects;
private:
void Reset();
@@ -266,37 +266,37 @@ static PoseDragState gDragState;
static PopupState gPopupState;
static DisplayUnits gDisplayUnits = kDisplayMeters;
static double ConvertDisplayLength(units::meter_t v) {
static double ConvertDisplayLength(wpi::units::meter_t v) {
switch (gDisplayUnits) {
case kDisplayFeet:
return v.convert<units::feet>().value();
return v.convert<wpi::units::feet>().value();
case kDisplayInches:
return v.convert<units::inches>().value();
return v.convert<wpi::units::inches>().value();
case kDisplayMeters:
default:
return v.value();
}
}
static double ConvertDisplayAngle(units::degree_t v) {
static double ConvertDisplayAngle(wpi::units::degree_t v) {
return v.value();
}
static bool InputLength(const char* label, units::meter_t* v, double step = 0.0,
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)) {
switch (gDisplayUnits) {
case kDisplayFeet:
*v = units::foot_t{dv};
*v = wpi::units::foot_t{dv};
break;
case kDisplayInches:
*v = units::inch_t{dv};
*v = wpi::units::inch_t{dv};
break;
case kDisplayMeters:
default:
*v = units::meter_t{dv};
*v = wpi::units::meter_t{dv};
break;
}
return true;
@@ -308,7 +308,7 @@ static bool InputFloatLength(const char* label, float* v, double step = 0.0,
double step_fast = 0.0,
const char* format = "%.3f",
ImGuiInputTextFlags flags = 0) {
units::meter_t uv{*v};
wpi::units::meter_t uv{*v};
if (InputLength(label, &uv, step, step_fast, format, flags)) {
*v = uv.to<float>();
return true;
@@ -316,18 +316,18 @@ static bool InputFloatLength(const char* label, float* v, double step = 0.0,
return false;
}
static bool InputAngle(const char* label, units::degree_t* v, double step = 0.0,
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)) {
*v = units::degree_t{dv};
*v = wpi::units::degree_t{dv};
return true;
}
return false;
}
static bool InputPose(frc::Pose2d* pose) {
static bool InputPose(wpi::math::Pose2d* pose) {
auto x = pose->X();
auto y = pose->Y();
auto rot = pose->Rotation().Degrees();
@@ -337,7 +337,7 @@ static bool InputPose(frc::Pose2d* pose) {
changed = InputLength("y", &y) || changed;
changed = InputAngle("rot", &rot) || changed;
if (changed) {
*pose = frc::Pose2d{x, y, rot};
*pose = wpi::math::Pose2d{x, y, rot};
}
return changed;
}
@@ -359,7 +359,7 @@ void FieldInfo::DisplaySettings() {
if (ImGui::Selectable("Custom", m_builtin.empty())) {
Reset();
}
for (auto&& field : fields::GetFields()) {
for (auto&& field : wpi::fields::GetFields()) {
bool selected = field.name == m_builtin;
if (ImGui::Selectable(field.name, selected)) {
Reset();
@@ -406,7 +406,7 @@ void FieldInfo::LoadImage() {
if (m_fileOpener && m_fileOpener->ready(0)) {
auto result = m_fileOpener->result();
if (!result.empty()) {
if (wpi::ends_with(result[0], ".json")) {
if (wpi::util::ends_with(result[0], ".json")) {
LoadJsonFile(result[0]);
} else {
LoadImageImpl(result[0].c_str());
@@ -420,7 +420,7 @@ void FieldInfo::LoadImage() {
}
if (!m_texture) {
if (!m_builtin.empty()) {
for (auto&& field : fields::GetFields()) {
for (auto&& field : wpi::fields::GetFields()) {
if (field.name == m_builtin) {
auto jsonstr = field.getJson();
auto imagedata = field.getImage();
@@ -446,11 +446,11 @@ void FieldInfo::LoadImage() {
bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
// parse file
wpi::json j;
wpi::util::json j;
try {
j = wpi::json::parse(is);
} catch (const wpi::json::parse_error& e) {
wpi::print(stderr, "GUI: JSON: could not parse: {}\n", e.what());
j = wpi::util::json::parse(is);
} catch (const wpi::util::json::parse_error& e) {
wpi::util::print(stderr, "GUI: JSON: could not parse: {}\n", e.what());
return false;
}
@@ -464,8 +464,8 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
std::string image;
try {
image = j.at("field-image").get<std::string>();
} catch (const wpi::json::exception& e) {
wpi::print(stderr, "GUI: JSON: could not read field-image: {}\n", e.what());
} catch (const wpi::util::json::exception& e) {
wpi::util::print(stderr, "GUI: JSON: could not read field-image: {}\n", e.what());
return false;
}
@@ -476,8 +476,8 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
left = j.at("field-corners").at("top-left").at(0).get<int>();
bottom = j.at("field-corners").at("bottom-right").at(1).get<int>();
right = j.at("field-corners").at("bottom-right").at(0).get<int>();
} catch (const wpi::json::exception& e) {
wpi::print(stderr, "GUI: JSON: could not read field-corners: {}\n",
} catch (const wpi::util::json::exception& e) {
wpi::util::print(stderr, "GUI: JSON: could not read field-corners: {}\n",
e.what());
return false;
}
@@ -488,8 +488,8 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
try {
width = j.at("field-size").at(0).get<float>();
height = j.at("field-size").at(1).get<float>();
} catch (const wpi::json::exception& e) {
wpi::print(stderr, "GUI: JSON: could not read field-size: {}\n", e.what());
} catch (const wpi::util::json::exception& e) {
wpi::util::print(stderr, "GUI: JSON: could not read field-size: {}\n", e.what());
return false;
}
@@ -497,22 +497,22 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
std::string unit;
try {
unit = j.at("field-unit").get<std::string>();
} catch (const wpi::json::exception& e) {
wpi::print(stderr, "GUI: JSON: could not read field-unit: {}\n", e.what());
} catch (const wpi::util::json::exception& e) {
wpi::util::print(stderr, "GUI: JSON: could not read field-unit: {}\n", e.what());
return false;
}
// convert size units to meters
if (unit == "foot" || unit == "feet") {
width = units::convert<units::feet, units::meters>(width);
height = units::convert<units::feet, units::meters>(height);
width = wpi::units::convert<wpi::units::feet, wpi::units::meters>(width);
height = wpi::units::convert<wpi::units::feet, wpi::units::meters>(height);
}
// check scaling
int fieldWidth = m_right - m_left;
int fieldHeight = m_bottom - m_top;
if (std::abs((fieldWidth / width) - (fieldHeight / height)) > 0.3) {
wpi::print(stderr,
wpi::util::print(stderr,
"GUI: Field X and Y scaling substantially different: "
"xscale={} yscale={}\n",
(fieldWidth / width), (fieldHeight / height));
@@ -540,7 +540,7 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
}
void FieldInfo::LoadJsonFile(std::string_view jsonfile) {
auto fileBuffer = wpi::MemoryBuffer::GetFile(jsonfile);
auto fileBuffer = wpi::util::MemoryBuffer::GetFile(jsonfile);
if (!fileBuffer) {
std::fputs("GUI: could not open field JSON file\n", stderr);
return;
@@ -551,7 +551,7 @@ void FieldInfo::LoadJsonFile(std::string_view jsonfile) {
}
bool FieldInfo::LoadImageImpl(const std::string& fn) {
wpi::print("GUI: loading field image '{}'\n", fn);
wpi::util::print("GUI: loading field image '{}'\n", fn);
auto texture = gui::Texture::CreateFromFile(fn.c_str());
if (!texture) {
std::puts("GUI: could not read field image");
@@ -651,8 +651,8 @@ DisplayOptions ObjectInfo::GetDisplayOptions() const {
rv.style = static_cast<DisplayOptions::Style>(m_style.GetValue());
rv.weight = m_weight;
rv.color = ImGui::ColorConvertFloat4ToU32(m_color.GetColor());
rv.width = units::meter_t{m_width};
rv.length = units::meter_t{m_length};
rv.width = wpi::units::meter_t{m_width};
rv.length = wpi::units::meter_t{m_length};
rv.arrows = m_arrows;
rv.arrowSize = m_arrowSize;
rv.arrowWeight = m_arrowWeight;
@@ -761,7 +761,7 @@ void ObjectInfo::LoadImage() {
}
bool ObjectInfo::LoadImageImpl(const std::string& fn) {
wpi::print("GUI: loading object image '{}'\n", fn);
wpi::util::print("GUI: loading object image '{}'\n", fn);
auto texture = gui::Texture::CreateFromFile(fn.c_str());
if (!texture) {
std::fputs("GUI: could not read object image\n", stderr);
@@ -772,7 +772,7 @@ bool ObjectInfo::LoadImageImpl(const std::string& fn) {
return true;
}
PoseFrameData::PoseFrameData(const frc::Pose2d& pose, FieldObjectModel& model,
PoseFrameData::PoseFrameData(const wpi::math::Pose2d& pose, FieldObjectModel& model,
size_t index, const FieldFrameData& ffd,
const DisplayOptions& displayOptions)
: m_model{model},
@@ -786,13 +786,13 @@ PoseFrameData::PoseFrameData(const frc::Pose2d& pose, FieldObjectModel& model,
UpdateFrameData();
}
void PoseFrameData::SetPosition(const frc::Translation2d& pos) {
m_pose = frc::Pose2d{pos, m_pose.Rotation()};
void PoseFrameData::SetPosition(const wpi::math::Translation2d& pos) {
m_pose = wpi::math::Pose2d{pos, m_pose.Rotation()};
m_model.SetPose(m_index, m_pose);
}
void PoseFrameData::SetRotation(units::radian_t rot) {
m_pose = frc::Pose2d{m_pose.Translation(), rot};
void PoseFrameData::SetRotation(wpi::units::radian_t rot) {
m_pose = wpi::math::Pose2d{m_pose.Translation(), rot};
m_model.SetPose(m_index, m_pose);
}
@@ -896,7 +896,7 @@ void PoseFrameData::HandleDrag(const ImVec2& cursor) {
} else {
ImVec2 off = cursor - m_center;
SetRotation(gDragState.initialAngle -
units::radian_t{std::atan2(off.y, off.x)});
wpi::units::radian_t{std::atan2(off.y, off.x)});
gDragState.target.center = m_corners[gDragState.target.corner - 2];
gDragState.target.rot = GetRotation().Radians();
}
@@ -935,7 +935,7 @@ void PoseFrameData::Draw(ImDrawList* drawList, std::vector<ImVec2>* center,
}
}
void glass::DisplayField2DSettings(Field2DModel* model) {
void wpi::glass::DisplayField2DSettings(Field2DModel* model) {
auto& storage = GetStorage();
auto field = storage.GetData<FieldInfo>();
if (!field) {
@@ -963,7 +963,7 @@ void glass::DisplayField2DSettings(Field2DModel* model) {
}
PushID(name);
wpi::SmallString<64> nameBuf{name};
wpi::util::SmallString<64> nameBuf{name};
if (ImGui::CollapsingHeader(nameBuf.c_str())) {
auto& obj =
field->m_objects.try_emplace(name, GetStorage()).first->second;
@@ -1085,7 +1085,7 @@ void FieldDisplay::Display(FieldInfo* field, Field2DModel* model,
gDragState.initialOffset = m_mousePos - target->poseCenter;
if (target->corner != 1) {
gDragState.initialAngle =
units::radian_t{std::atan2(gDragState.initialOffset.y,
wpi::units::radian_t{std::atan2(gDragState.initialOffset.y,
gDragState.initialOffset.x)} +
target->rot;
}
@@ -1152,7 +1152,7 @@ void FieldDisplay::DisplayObject(FieldObjectModel& model,
}
void PopupState::Open(SelectedTargetInfo* target,
const frc::Translation2d& pos) {
const wpi::math::Translation2d& pos) {
if (target) {
m_target = *target;
} else {
@@ -1182,7 +1182,7 @@ 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));
frc::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();
@@ -1190,7 +1190,7 @@ void PopupState::DisplayTarget(Field2DModel* model, const FieldFrameData& ffd) {
}
if (ImGui::Button("Delete Pose")) {
auto posesRef = m_target.objModel->GetPoses();
std::vector<frc::Pose2d> poses{posesRef.begin(), posesRef.end()};
std::vector<wpi::math::Pose2d> poses{posesRef.begin(), posesRef.end()};
if (m_target.index < poses.size()) {
poses.erase(poses.begin() + m_target.index);
m_target.objModel->SetPoses(poses);
@@ -1277,7 +1277,7 @@ void PopupState::DisplayInsert(Field2DModel* model) {
}
}
void 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) {

View File

@@ -8,7 +8,7 @@
#include <imgui.h>
using namespace glass;
using namespace wpi::glass;
LogData::LogData(size_t maxLines) : m_maxLines{maxLines} {}
@@ -36,7 +36,7 @@ const std::string& LogData::GetBuffer() {
return m_buf;
}
void glass::DisplayLog(LogData* data, bool autoScroll) {
void wpi::glass::DisplayLog(LogData* data, bool autoScroll) {
if (data->m_buf.empty()) {
return;
}

View File

@@ -29,7 +29,7 @@
#include "wpi/units/length.hpp"
#include "wpi/util/print.hpp"
using namespace glass;
using namespace wpi::glass;
namespace gui = wpi::gui;
@@ -37,19 +37,19 @@ namespace {
// Per-frame data (not persistent)
struct FrameData {
frc::Translation2d GetPosFromScreen(const ImVec2& cursor) const {
wpi::math::Translation2d GetPosFromScreen(const ImVec2& cursor) const {
return {
units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) / scale},
units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) / scale}};
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 frc::Translation2d& pos) const {
ImVec2 GetScreenFromPos(const wpi::math::Translation2d& pos) const {
return {min.x + scale * pos.X().to<float>(),
max.y - scale * pos.Y().to<float>()};
}
void DrawObject(ImDrawList* drawList, MechanismObjectModel& objModel,
const frc::Pose2d& pose) const;
const wpi::math::Pose2d& pose) const;
void DrawGroup(ImDrawList* drawList, MechanismObjectGroup& group,
const frc::Pose2d& pose) const;
const wpi::math::Pose2d& pose) const;
// in screen coordinates
ImVec2 imageMin;
@@ -67,7 +67,7 @@ class BackgroundInfo {
void DisplaySettings();
void LoadImage();
FrameData GetFrameData(ImVec2 min, ImVec2 max, frc::Translation2d dims) const;
FrameData GetFrameData(ImVec2 min, ImVec2 max, wpi::math::Translation2d dims) const;
void Draw(ImDrawList* drawList, const FrameData& frameData,
ImU32 bgColor) const;
@@ -126,7 +126,7 @@ void BackgroundInfo::LoadImage() {
}
bool BackgroundInfo::LoadImageImpl(const std::string& fn) {
wpi::print("GUI: loading background image '{}'\n", fn);
wpi::util::print("GUI: loading background image '{}'\n", fn);
auto texture = gui::Texture::CreateFromFile(fn.c_str());
if (!texture) {
std::puts("GUI: could not read background image");
@@ -140,7 +140,7 @@ bool BackgroundInfo::LoadImageImpl(const std::string& fn) {
}
FrameData BackgroundInfo::GetFrameData(ImVec2 min, ImVec2 max,
frc::Translation2d dims) const {
wpi::math::Translation2d dims) const {
// fit the image into the window
if (m_texture && m_imageHeight != 0 && m_imageWidth != 0) {
gui::MaxFit(&min, &max, m_imageWidth, m_imageHeight);
@@ -170,7 +170,7 @@ void BackgroundInfo::Draw(ImDrawList* drawList, const FrameData& frameData,
}
}
void glass::DisplayMechanism2DSettings(Mechanism2DModel* model) {
void wpi::glass::DisplayMechanism2DSettings(Mechanism2DModel* model) {
auto& storage = GetStorage();
auto bg = storage.GetData<BackgroundInfo>();
if (!bg) {
@@ -181,14 +181,14 @@ void glass::DisplayMechanism2DSettings(Mechanism2DModel* model) {
}
void FrameData::DrawObject(ImDrawList* drawList, MechanismObjectModel& objModel,
const frc::Pose2d& pose) const {
const wpi::math::Pose2d& pose) const {
const char* type = objModel.GetType();
if (std::string_view{type} == "line") {
auto startPose =
pose + frc::Transform2d{frc::Translation2d{}, objModel.GetAngle()};
pose + wpi::math::Transform2d{wpi::math::Translation2d{}, objModel.GetAngle()};
auto endPose =
startPose +
frc::Transform2d{frc::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());
@@ -197,12 +197,12 @@ void FrameData::DrawObject(ImDrawList* drawList, MechanismObjectModel& objModel,
}
void FrameData::DrawGroup(ImDrawList* drawList, MechanismObjectGroup& group,
const frc::Pose2d& pose) const {
const wpi::math::Pose2d& pose) const {
group.ForEachObject(
[&](auto& objModel) { DrawObject(drawList, objModel, pose); });
}
void glass::DisplayMechanism2D(Mechanism2DModel* model,
void wpi::glass::DisplayMechanism2D(Mechanism2DModel* model,
const ImVec2& contentSize) {
auto& storage = GetStorage();
auto bg = storage.GetData<BackgroundInfo>();
@@ -233,7 +233,7 @@ void glass::DisplayMechanism2D(Mechanism2DModel* model,
// elements
model->ForEachRoot([&](auto& rootModel) {
frameData.DrawGroup(drawList, rootModel,
frc::Pose2d{rootModel.GetPosition(), 0_deg});
wpi::math::Pose2d{rootModel.GetPosition(), 0_deg});
});
#if 0

View File

@@ -8,9 +8,9 @@
#include "wpi/glass/DataSource.hpp"
using namespace glass;
using namespace wpi::glass;
void glass::DisplayPIDController(PIDControllerModel* m) {
void wpi::glass::DisplayPIDController(PIDControllerModel* m) {
if (auto name = m->GetName()) {
ImGui::Text("%s", name);
ImGui::Separator();

View File

@@ -39,7 +39,7 @@
#include "wpi/glass/support/EnumSetting.hpp"
#include "wpi/glass/support/ExtraGuiWidgets.hpp"
using namespace glass;
using namespace wpi::glass;
static constexpr int kAxisCount = 3;
@@ -89,8 +89,8 @@ class PlotSeries {
// source linkage
DataSource* m_source = nullptr;
bool m_digitalSource = false;
wpi::sig::ScopedConnection m_sourceCreatedConn;
wpi::sig::ScopedConnection m_newValueConn;
wpi::util::sig::ScopedConnection m_sourceCreatedConn;
wpi::util::sig::ScopedConnection m_newValueConn;
std::string& m_id;
// user settings
@@ -292,7 +292,7 @@ void PlotSeries::SetSource(DataSource* source) {
}
void PlotSeries::AppendValue(double value, int64_t timeUs) {
double time = (timeUs != 0 ? timeUs : wpi::Now()) * 1.0e-6;
double time = (timeUs != 0 ? timeUs : wpi::util::Now()) * 1.0e-6;
if (IsDigital()) {
if (m_size < kMaxSize) {
m_data[m_size] = ImPlotPoint{time, value};
@@ -350,7 +350,7 @@ PlotSeries::Action PlotSeries::EmitPlot(PlotView& view, double now, size_t i,
CheckSource();
char label[128];
wpi::format_to_n_c_str(label, sizeof(label), "{}###name{}_{}", GetName(),
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###name{}_{}", GetName(),
static_cast<int>(i), static_cast<int>(plotIndex));
int size = m_size;
@@ -618,7 +618,7 @@ void Plot::EmitPlot(PlotView& view, double now, bool paused, size_t i) {
}
char label[128];
wpi::format_to_n_c_str(label, sizeof(label), "{}###plot{}", m_name,
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###plot{}", m_name,
static_cast<int>(i));
ImPlotFlags plotFlags = (m_legend ? 0 : ImPlotFlags_NoLegend) |
@@ -865,7 +865,7 @@ void PlotView::Display() {
}
}
double now = wpi::Now() * 1.0e-6;
double now = wpi::util::Now() * 1.0e-6;
for (size_t i = 0; i < m_plots.size(); ++i) {
ImGui::PushID(i);
m_plots[i]->EmitPlot(*this, now, m_provider->IsPaused(), i);
@@ -976,14 +976,14 @@ void PlotView::Settings() {
char name[64];
if (!plot->GetName().empty()) {
wpi::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::format_to_n_c_str(name, sizeof(name), "Plot {}",
wpi::util::format_to_n_c_str(name, sizeof(name), "Plot {}",
static_cast<int>(i));
}
char label[90];
wpi::format_to_n_c_str(label, sizeof(label), "{}###header{}", name,
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###header{}", name,
static_cast<int>(i));
bool open = ImGui::CollapsingHeader(label);
@@ -1053,7 +1053,7 @@ void PlotProvider::DisplayMenu() {
char id[32];
size_t numWindows = m_windows.size();
for (size_t i = 0; i <= numWindows; ++i) {
wpi::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) {

View File

@@ -8,9 +8,9 @@
#include "wpi/glass/DataSource.hpp"
using namespace glass;
using namespace wpi::glass;
void glass::DisplayProfiledPIDController(ProfiledPIDControllerModel* m) {
void wpi::glass::DisplayProfiledPIDController(ProfiledPIDControllerModel* m) {
if (auto name = m->GetName()) {
ImGui::Text("%s", name);
ImGui::Separator();

View File

@@ -6,9 +6,9 @@
#include <imgui.h>
using namespace glass;
using namespace wpi::glass;
void glass::DisplayStringChooser(StringChooserModel* model) {
void wpi::glass::DisplayStringChooser(StringChooserModel* model) {
auto& defaultValue = model->GetDefault();
auto& selected = model->GetSelected();
auto& active = model->GetActive();

View File

@@ -8,9 +8,9 @@
#include <imgui.h>
using namespace glass;
using namespace wpi::glass;
void glass::DisplaySubsystem(SubsystemModel* m) {
void wpi::glass::DisplaySubsystem(SubsystemModel* m) {
if (auto name = m->GetName()) {
ImGui::Text("%s", name);
ImGui::Separator();