mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
SCRIPT: wpiformat
This commit is contained in:
committed by
Peter Johnson
parent
ae6bdc9d25
commit
2109161534
@@ -41,7 +41,8 @@ static std::unique_ptr<wpi::glass::PlotProvider> gPlotProvider;
|
||||
static std::unique_ptr<wpi::glass::NetworkTablesProvider> gNtProvider;
|
||||
|
||||
static std::unique_ptr<wpi::glass::NetworkTablesModel> gNetworkTablesModel;
|
||||
static std::unique_ptr<wpi::glass::NetworkTablesSettings> gNetworkTablesSettings;
|
||||
static std::unique_ptr<wpi::glass::NetworkTablesSettings>
|
||||
gNetworkTablesSettings;
|
||||
static wpi::glass::LogData gNetworkTablesLog;
|
||||
static std::unique_ptr<wpi::glass::Window> gNetworkTablesWindow;
|
||||
static std::unique_ptr<wpi::glass::Window> gNetworkTablesInfoWindow;
|
||||
@@ -95,7 +96,8 @@ static std::string MakeTitle(NT_Inst inst, wpi::nt::Event event) {
|
||||
static void NtInitialize() {
|
||||
auto inst = wpi::nt::GetDefaultInstance();
|
||||
auto poller = wpi::nt::CreateListenerPoller(inst);
|
||||
wpi::nt::AddPolledListener(poller, inst, NT_EVENT_CONNECTION | NT_EVENT_IMMEDIATE);
|
||||
wpi::nt::AddPolledListener(poller, inst,
|
||||
NT_EVENT_CONNECTION | NT_EVENT_IMMEDIATE);
|
||||
wpi::nt::AddPolledLogger(poller, NT_LOG_INFO, 100);
|
||||
gui::AddEarlyExecute([inst, poller] {
|
||||
auto win = gui::GetSystemWindow();
|
||||
@@ -149,9 +151,10 @@ static void NtInitialize() {
|
||||
gui::AddEarlyExecute([] { gNetworkTablesModel->Update(); });
|
||||
|
||||
gNetworkTablesWindow = std::make_unique<wpi::glass::Window>(
|
||||
wpi::glass::GetStorageRoot().GetChild("NetworkTables View"), "NetworkTables");
|
||||
gNetworkTablesWindow->SetView(
|
||||
std::make_unique<wpi::glass::NetworkTablesView>(gNetworkTablesModel.get()));
|
||||
wpi::glass::GetStorageRoot().GetChild("NetworkTables View"),
|
||||
"NetworkTables");
|
||||
gNetworkTablesWindow->SetView(std::make_unique<wpi::glass::NetworkTablesView>(
|
||||
gNetworkTablesModel.get()));
|
||||
gNetworkTablesWindow->SetDefaultPos(250, 277);
|
||||
gNetworkTablesWindow->SetDefaultSize(750, 185);
|
||||
gNetworkTablesWindow->DisableRenamePopup();
|
||||
@@ -161,8 +164,9 @@ static void NtInitialize() {
|
||||
gNetworkTablesInfoWindow = std::make_unique<wpi::glass::Window>(
|
||||
wpi::glass::GetStorageRoot().GetChild("NetworkTables Info"),
|
||||
"NetworkTables Info");
|
||||
gNetworkTablesInfoWindow->SetView(wpi::glass::MakeFunctionView(
|
||||
[&] { wpi::glass::DisplayNetworkTablesInfo(gNetworkTablesModel.get()); }));
|
||||
gNetworkTablesInfoWindow->SetView(wpi::glass::MakeFunctionView([&] {
|
||||
wpi::glass::DisplayNetworkTablesInfo(gNetworkTablesModel.get());
|
||||
}));
|
||||
gNetworkTablesInfoWindow->SetDefaultPos(250, 130);
|
||||
gNetworkTablesInfoWindow->SetDefaultSize(750, 145);
|
||||
gNetworkTablesInfoWindow->SetDefaultVisibility(wpi::glass::Window::kHide);
|
||||
@@ -228,7 +232,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
wpi::glass::SetStorageName("glass");
|
||||
wpi::glass::SetStorageDir(saveDir.empty() ? gui::GetPlatformSaveFileDir()
|
||||
: saveDir);
|
||||
: saveDir);
|
||||
gPlotProvider->GlobalInit();
|
||||
gui::AddInit([] { wpi::glass::ResetTime(); });
|
||||
gNtProvider->GlobalInit();
|
||||
@@ -328,12 +332,13 @@ int main(int argc, char** argv) {
|
||||
char nameBuf[32];
|
||||
const char* name = glfwGetKeyName(*gEnterKey, 0);
|
||||
if (!name) {
|
||||
wpi::util::format_to_n_c_str(nameBuf, sizeof(nameBuf), "{}", *gEnterKey);
|
||||
wpi::util::format_to_n_c_str(nameBuf, sizeof(nameBuf), "{}",
|
||||
*gEnterKey);
|
||||
|
||||
name = nameBuf;
|
||||
}
|
||||
wpi::util::format_to_n_c_str(editLabel, sizeof(editLabel), "{}###edit",
|
||||
gKeyEdit ? "(press key)" : name);
|
||||
gKeyEdit ? "(press key)" : name);
|
||||
|
||||
if (ImGui::SmallButton(editLabel)) {
|
||||
gKeyEdit = true;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,8 @@ class StringSource : public DataSource {
|
||||
return {buf.begin(), buf.end()};
|
||||
}
|
||||
|
||||
wpi::util::sig::SignalBase<wpi::util::spinlock, std::string_view, int64_t> valueChanged;
|
||||
wpi::util::sig::SignalBase<wpi::util::spinlock, std::string_view, int64_t>
|
||||
valueChanged;
|
||||
|
||||
private:
|
||||
std::string m_value;
|
||||
|
||||
@@ -213,7 +213,8 @@ class Storage {
|
||||
* @param toJson replacement for ToJson()
|
||||
*/
|
||||
void SetCustomJson(
|
||||
std::function<bool(const wpi::util::json& json, const char* filename)> fromJson,
|
||||
std::function<bool(const wpi::util::json& json, const char* filename)>
|
||||
fromJson,
|
||||
std::function<wpi::util::json()> toJson) {
|
||||
m_fromJson = std::move(fromJson);
|
||||
m_toJson = std::move(toJson);
|
||||
@@ -230,7 +231,8 @@ class Storage {
|
||||
private:
|
||||
mutable ValueMap m_values;
|
||||
std::shared_ptr<void> m_data;
|
||||
std::function<bool(const wpi::util::json& json, const char* filename)> m_fromJson;
|
||||
std::function<bool(const wpi::util::json& json, const char* filename)>
|
||||
m_fromJson;
|
||||
std::function<wpi::util::json()> m_toJson;
|
||||
std::function<void()> m_clear;
|
||||
std::function<void()> m_apply;
|
||||
|
||||
@@ -54,6 +54,7 @@ class View {
|
||||
* @param display Display function
|
||||
* @return unique_ptr to View
|
||||
*/
|
||||
std::unique_ptr<View> MakeFunctionView(wpi::util::unique_function<void()> display);
|
||||
std::unique_ptr<View> MakeFunctionView(
|
||||
wpi::util::unique_function<void()> display);
|
||||
|
||||
} // namespace wpi::glass
|
||||
|
||||
@@ -64,7 +64,8 @@ class WindowManager {
|
||||
* @param display window contents display function
|
||||
* @param defaultVisibility default window visibility
|
||||
*/
|
||||
Window* AddWindow(std::string_view id, wpi::util::unique_function<void()> display,
|
||||
Window* AddWindow(std::string_view id,
|
||||
wpi::util::unique_function<void()> display,
|
||||
Window::Visibility defaultVisibility = Window::kShow);
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,8 @@ class AnalogInputModel : public Model {
|
||||
class AnalogInputsModel : public Model {
|
||||
public:
|
||||
virtual void ForEachAnalogInput(
|
||||
wpi::util::function_ref<void(AnalogInputModel& model, int index)> func) = 0;
|
||||
wpi::util::function_ref<void(AnalogInputModel& model, int index)>
|
||||
func) = 0;
|
||||
};
|
||||
|
||||
void DisplayAnalogInput(AnalogInputModel* model, int index);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace wpi::util {
|
||||
template <typename T>
|
||||
class SmallVectorImpl;
|
||||
} // namespace wpi
|
||||
} // namespace wpi::util
|
||||
|
||||
namespace wpi::glass {
|
||||
|
||||
@@ -24,7 +24,8 @@ class LEDDisplayModel : public wpi::glass::Model {
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
virtual std::span<const Data> GetData(wpi::util::SmallVectorImpl<Data>& buf) = 0;
|
||||
virtual std::span<const Data> GetData(
|
||||
wpi::util::SmallVectorImpl<Data>& buf) = 0;
|
||||
};
|
||||
|
||||
class LEDDisplaysModel : public wpi::glass::Model {
|
||||
@@ -32,7 +33,8 @@ class LEDDisplaysModel : public wpi::glass::Model {
|
||||
virtual size_t GetNumLEDDisplays() = 0;
|
||||
|
||||
virtual void ForEachLEDDisplay(
|
||||
wpi::util::function_ref<void(LEDDisplayModel& model, int index)> func) = 0;
|
||||
wpi::util::function_ref<void(LEDDisplayModel& model, int index)>
|
||||
func) = 0;
|
||||
};
|
||||
|
||||
void DisplayLEDDisplay(LEDDisplayModel* model, int index);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace wpi::util {
|
||||
template <typename T>
|
||||
class SmallVectorImpl;
|
||||
} // namespace wpi
|
||||
} // namespace wpi::util
|
||||
|
||||
namespace wpi::glass {
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ class Field2DModel : public Model {
|
||||
virtual FieldObjectModel* AddFieldObject(std::string_view name) = 0;
|
||||
virtual void RemoveFieldObject(std::string_view name) = 0;
|
||||
virtual void ForEachFieldObject(
|
||||
wpi::util::function_ref<void(FieldObjectModel& model, std::string_view name)>
|
||||
wpi::util::function_ref<void(FieldObjectModel& model,
|
||||
std::string_view name)>
|
||||
func) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,8 +15,11 @@ namespace wpi::glass::expression {
|
||||
template <typename V>
|
||||
wpi::util::expected<V, std::string> TryParseExpr(const char* expr);
|
||||
|
||||
extern template wpi::util::expected<double, std::string> TryParseExpr(const char*);
|
||||
extern template wpi::util::expected<float, std::string> TryParseExpr(const char*);
|
||||
extern template wpi::util::expected<int64_t, std::string> TryParseExpr(const char*);
|
||||
extern template wpi::util::expected<double, std::string> TryParseExpr(
|
||||
const char*);
|
||||
extern template wpi::util::expected<float, std::string> TryParseExpr(
|
||||
const char*);
|
||||
extern template wpi::util::expected<int64_t, std::string> TryParseExpr(
|
||||
const char*);
|
||||
|
||||
} // namespace wpi::glass::expression
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
using namespace wpi::glass;
|
||||
|
||||
NTCommandSchedulerModel::NTCommandSchedulerModel(std::string_view path)
|
||||
: NTCommandSchedulerModel(wpi::nt::NetworkTableInstance::GetDefault(), path) {}
|
||||
: NTCommandSchedulerModel(wpi::nt::NetworkTableInstance::GetDefault(),
|
||||
path) {}
|
||||
|
||||
NTCommandSchedulerModel::NTCommandSchedulerModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path)
|
||||
NTCommandSchedulerModel::NTCommandSchedulerModel(
|
||||
wpi::nt::NetworkTableInstance inst, std::string_view path)
|
||||
: m_inst{inst},
|
||||
m_name{inst.GetStringTopic(fmt::format("{}/.name", path)).Subscribe("")},
|
||||
m_commands{inst.GetStringArrayTopic(fmt::format("{}/Names", path))
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
using namespace wpi::glass;
|
||||
|
||||
NTCommandSelectorModel::NTCommandSelectorModel(std::string_view path)
|
||||
: NTCommandSelectorModel(wpi::nt::NetworkTableInstance::GetDefault(), path) {}
|
||||
: NTCommandSelectorModel(wpi::nt::NetworkTableInstance::GetDefault(),
|
||||
path) {}
|
||||
|
||||
NTCommandSelectorModel::NTCommandSelectorModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path)
|
||||
NTCommandSelectorModel::NTCommandSelectorModel(
|
||||
wpi::nt::NetworkTableInstance inst, std::string_view path)
|
||||
: m_inst{inst},
|
||||
m_running{inst.GetBooleanTopic(fmt::format("{}/running", path))
|
||||
.GetEntry(false)},
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
using namespace wpi::glass;
|
||||
|
||||
NTDifferentialDriveModel::NTDifferentialDriveModel(std::string_view path)
|
||||
: NTDifferentialDriveModel(wpi::nt::NetworkTableInstance::GetDefault(), path) {}
|
||||
: NTDifferentialDriveModel(wpi::nt::NetworkTableInstance::GetDefault(),
|
||||
path) {}
|
||||
|
||||
NTDifferentialDriveModel::NTDifferentialDriveModel(
|
||||
wpi::nt::NetworkTableInstance inst, std::string_view path)
|
||||
|
||||
@@ -18,7 +18,8 @@ using namespace wpi::glass;
|
||||
NTFMSModel::NTFMSModel(std::string_view path)
|
||||
: NTFMSModel{wpi::nt::NetworkTableInstance::GetDefault(), path} {}
|
||||
|
||||
NTFMSModel::NTFMSModel(wpi::nt::NetworkTableInstance inst, std::string_view path)
|
||||
NTFMSModel::NTFMSModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path)
|
||||
: m_inst{inst},
|
||||
m_gameSpecificMessage{
|
||||
inst.GetStringTopic(fmt::format("{}/GameSpecificMessage", path))
|
||||
|
||||
@@ -62,7 +62,8 @@ void NTField2DModel::ObjectModel::NTUpdate(const wpi::nt::Value& value) {
|
||||
m_poses.resize(size / 3);
|
||||
for (size_t i = 0; i < size / 3; ++i) {
|
||||
m_poses[i] = wpi::math::Pose2d{
|
||||
wpi::units::meter_t{arr[i * 3 + 0]}, wpi::units::meter_t{arr[i * 3 + 1]},
|
||||
wpi::units::meter_t{arr[i * 3 + 0]},
|
||||
wpi::units::meter_t{arr[i * 3 + 1]},
|
||||
wpi::math::Rotation2d{wpi::units::degree_t{arr[i * 3 + 2]}}};
|
||||
}
|
||||
}
|
||||
@@ -82,7 +83,8 @@ void NTField2DModel::ObjectModel::UpdateNT() {
|
||||
m_pub.Set(arr);
|
||||
}
|
||||
|
||||
void NTField2DModel::ObjectModel::SetPoses(std::span<const wpi::math::Pose2d> poses) {
|
||||
void NTField2DModel::ObjectModel::SetPoses(
|
||||
std::span<const wpi::math::Pose2d> poses) {
|
||||
m_poses.assign(poses.begin(), poses.end());
|
||||
UpdateNT();
|
||||
}
|
||||
@@ -102,7 +104,8 @@ void NTField2DModel::ObjectModel::SetPosition(size_t i,
|
||||
}
|
||||
}
|
||||
|
||||
void NTField2DModel::ObjectModel::SetRotation(size_t i, wpi::math::Rotation2d rot) {
|
||||
void NTField2DModel::ObjectModel::SetRotation(size_t i,
|
||||
wpi::math::Rotation2d rot) {
|
||||
if (i < m_poses.size()) {
|
||||
m_poses[i] = wpi::math::Pose2d{m_poses[i].Translation(), rot};
|
||||
UpdateNT();
|
||||
@@ -198,7 +201,8 @@ void NTField2DModel::RemoveFieldObject(std::string_view name) {
|
||||
}
|
||||
|
||||
void NTField2DModel::ForEachFieldObject(
|
||||
wpi::util::function_ref<void(FieldObjectModel& model, std::string_view name)>
|
||||
wpi::util::function_ref<void(FieldObjectModel& model,
|
||||
std::string_view name)>
|
||||
func) {
|
||||
for (auto&& obj : m_objects) {
|
||||
if (obj->Exists()) {
|
||||
|
||||
@@ -15,7 +15,8 @@ using namespace wpi::glass;
|
||||
NTGyroModel::NTGyroModel(std::string_view path)
|
||||
: NTGyroModel(wpi::nt::NetworkTableInstance::GetDefault(), path) {}
|
||||
|
||||
NTGyroModel::NTGyroModel(wpi::nt::NetworkTableInstance inst, std::string_view path)
|
||||
NTGyroModel::NTGyroModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path)
|
||||
: m_inst{inst},
|
||||
m_angle{inst.GetDoubleTopic(fmt::format("{}/Value", path)).Subscribe(0)},
|
||||
m_name{inst.GetStringTopic(fmt::format("{}/.name", path)).Subscribe({})},
|
||||
|
||||
@@ -37,8 +37,8 @@ void NTMechanism2DModel::NTMechanismGroupImpl::ForEachObject(
|
||||
}
|
||||
}
|
||||
|
||||
void NTMechanism2DModel::NTMechanismGroupImpl::NTUpdate(const wpi::nt::Event& event,
|
||||
std::string_view name) {
|
||||
void NTMechanism2DModel::NTMechanismGroupImpl::NTUpdate(
|
||||
const wpi::nt::Event& event, std::string_view name) {
|
||||
if (name.empty()) {
|
||||
return;
|
||||
}
|
||||
@@ -130,8 +130,8 @@ bool NTMechanism2DModel::RootModel::NTUpdate(const wpi::nt::Event& event,
|
||||
} else if (auto valueData = event.GetValueEventData()) {
|
||||
if (valueData->topic == m_xTopic.GetHandle()) {
|
||||
if (valueData->value && valueData->value.IsDouble()) {
|
||||
m_pos = wpi::math::Translation2d{wpi::units::meter_t{valueData->value.GetDouble()},
|
||||
m_pos.Y()};
|
||||
m_pos = wpi::math::Translation2d{
|
||||
wpi::units::meter_t{valueData->value.GetDouble()}, m_pos.Y()};
|
||||
}
|
||||
} else if (valueData->topic == m_yTopic.GetHandle()) {
|
||||
if (valueData->value && valueData->value.IsDouble()) {
|
||||
@@ -208,8 +208,8 @@ void NTMechanism2DModel::Update() {
|
||||
if (valueData->value && valueData->value.IsDoubleArray()) {
|
||||
auto arr = valueData->value.GetDoubleArray();
|
||||
if (arr.size() == 2) {
|
||||
m_dimensionsValue = wpi::math::Translation2d{wpi::units::meter_t{arr[0]},
|
||||
wpi::units::meter_t{arr[1]}};
|
||||
m_dimensionsValue = wpi::math::Translation2d{
|
||||
wpi::units::meter_t{arr[0]}, wpi::units::meter_t{arr[1]}};
|
||||
}
|
||||
}
|
||||
} else if (valueData->topic == m_bgColorTopic.GetHandle()) {
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
using namespace wpi::glass;
|
||||
|
||||
NTMotorControllerModel::NTMotorControllerModel(std::string_view path)
|
||||
: NTMotorControllerModel(wpi::nt::NetworkTableInstance::GetDefault(), path) {}
|
||||
: NTMotorControllerModel(wpi::nt::NetworkTableInstance::GetDefault(),
|
||||
path) {}
|
||||
|
||||
NTMotorControllerModel::NTMotorControllerModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path)
|
||||
NTMotorControllerModel::NTMotorControllerModel(
|
||||
wpi::nt::NetworkTableInstance inst, std::string_view path)
|
||||
: m_inst{inst},
|
||||
m_value{inst.GetDoubleTopic(fmt::format("{}/Value", path)).GetEntry(0)},
|
||||
m_name{inst.GetStringTopic(fmt::format("{}/.name", path)).Subscribe("")},
|
||||
|
||||
@@ -22,9 +22,9 @@ NTStringChooserModel::NTStringChooserModel(wpi::nt::NetworkTableInstance inst,
|
||||
m_inst.GetStringTopic(fmt::format("{}/default", path)).Subscribe("")},
|
||||
m_selected{m_inst.GetStringTopic(fmt::format("{}/selected", path))
|
||||
.Subscribe("")},
|
||||
m_selectedPub{
|
||||
m_inst.GetStringTopic(fmt::format("{}/selected", path))
|
||||
.PublishEx(wpi::nt::StringTopic::kTypeString, {{"retained", true}})},
|
||||
m_selectedPub{m_inst.GetStringTopic(fmt::format("{}/selected", path))
|
||||
.PublishEx(wpi::nt::StringTopic::kTypeString,
|
||||
{{"retained", true}})},
|
||||
m_active{
|
||||
m_inst.GetStringTopic(fmt::format("{}/active", path)).Subscribe("")},
|
||||
m_options{m_inst.GetStringArrayTopic(fmt::format("{}/options", path))
|
||||
|
||||
@@ -133,7 +133,8 @@ static void UpdateMsgpackValueSource(NetworkTablesModel& model,
|
||||
mpack_tag_t tag = mpack_read_tag(&r);
|
||||
switch (mpack_tag_type(&tag)) {
|
||||
case mpack::mpack_type_bool:
|
||||
out->value = wpi::nt::Value::MakeBoolean(mpack_tag_bool_value(&tag), time);
|
||||
out->value =
|
||||
wpi::nt::Value::MakeBoolean(mpack_tag_bool_value(&tag), time);
|
||||
out->UpdateFromValue(model, name, "");
|
||||
break;
|
||||
case mpack::mpack_type_int:
|
||||
@@ -141,7 +142,8 @@ static void UpdateMsgpackValueSource(NetworkTablesModel& model,
|
||||
out->UpdateFromValue(model, name, "");
|
||||
break;
|
||||
case mpack::mpack_type_uint:
|
||||
out->value = wpi::nt::Value::MakeInteger(mpack_tag_uint_value(&tag), time);
|
||||
out->value =
|
||||
wpi::nt::Value::MakeInteger(mpack_tag_uint_value(&tag), time);
|
||||
out->UpdateFromValue(model, name, "");
|
||||
break;
|
||||
case mpack::mpack_type_float:
|
||||
@@ -149,7 +151,8 @@ static void UpdateMsgpackValueSource(NetworkTablesModel& model,
|
||||
out->UpdateFromValue(model, name, "");
|
||||
break;
|
||||
case mpack::mpack_type_double:
|
||||
out->value = wpi::nt::Value::MakeDouble(mpack_tag_double_value(&tag), time);
|
||||
out->value =
|
||||
wpi::nt::Value::MakeDouble(mpack_tag_double_value(&tag), time);
|
||||
out->UpdateFromValue(model, name, "");
|
||||
break;
|
||||
case mpack::mpack_type_str: {
|
||||
@@ -275,12 +278,14 @@ static void UpdateStructValueSource(NetworkTablesModel& model,
|
||||
}
|
||||
child.value = wpi::nt::Value::MakeBooleanArray(std::move(v), time);
|
||||
} else {
|
||||
child.value = wpi::nt::Value::MakeBoolean(s.GetBoolField(&field), time);
|
||||
child.value =
|
||||
wpi::nt::Value::MakeBoolean(s.GetBoolField(&field), time);
|
||||
}
|
||||
child.UpdateFromValue(model, child.path, "");
|
||||
break;
|
||||
case wpi::util::StructFieldType::kChar:
|
||||
child.value = wpi::nt::Value::MakeString(s.GetStringField(&field), time);
|
||||
child.value =
|
||||
wpi::nt::Value::MakeString(s.GetStringField(&field), time);
|
||||
child.UpdateFromValue(model, child.path, "");
|
||||
break;
|
||||
case wpi::util::StructFieldType::kInt8:
|
||||
@@ -329,9 +334,11 @@ static void UpdateStructValueSource(NetworkTablesModel& model,
|
||||
child.value = wpi::nt::Value::MakeIntegerArray(std::move(v), time);
|
||||
} else {
|
||||
if (isUint) {
|
||||
child.value = wpi::nt::Value::MakeInteger(s.GetUintField(&field), time);
|
||||
child.value =
|
||||
wpi::nt::Value::MakeInteger(s.GetUintField(&field), time);
|
||||
} else {
|
||||
child.value = wpi::nt::Value::MakeInteger(s.GetIntField(&field), time);
|
||||
child.value =
|
||||
wpi::nt::Value::MakeInteger(s.GetIntField(&field), time);
|
||||
}
|
||||
}
|
||||
child.UpdateFromValue(model, child.path, "");
|
||||
@@ -346,7 +353,8 @@ static void UpdateStructValueSource(NetworkTablesModel& model,
|
||||
}
|
||||
child.value = wpi::nt::Value::MakeFloatArray(std::move(v), time);
|
||||
} else {
|
||||
child.value = wpi::nt::Value::MakeFloat(s.GetFloatField(&field), time);
|
||||
child.value =
|
||||
wpi::nt::Value::MakeFloat(s.GetFloatField(&field), time);
|
||||
}
|
||||
child.UpdateFromValue(model, child.path, "");
|
||||
break;
|
||||
@@ -359,7 +367,8 @@ static void UpdateStructValueSource(NetworkTablesModel& model,
|
||||
}
|
||||
child.value = wpi::nt::Value::MakeDoubleArray(std::move(v), time);
|
||||
} else {
|
||||
child.value = wpi::nt::Value::MakeDouble(s.GetDoubleField(&field), time);
|
||||
child.value =
|
||||
wpi::nt::Value::MakeDouble(s.GetDoubleField(&field), time);
|
||||
}
|
||||
child.UpdateFromValue(model, child.path, "");
|
||||
break;
|
||||
@@ -630,8 +639,8 @@ static void UpdateProtobufValueSource(NetworkTablesModel& model,
|
||||
|
||||
static void UpdateJsonValueSource(NetworkTablesModel& model,
|
||||
NetworkTablesModel::ValueSource* out,
|
||||
const wpi::util::json& j, std::string_view name,
|
||||
int64_t time) {
|
||||
const wpi::util::json& j,
|
||||
std::string_view name, int64_t time) {
|
||||
switch (j.type()) {
|
||||
case wpi::util::json::value_t::object: {
|
||||
if (!out->valueChildrenMap) {
|
||||
@@ -689,7 +698,8 @@ static void UpdateJsonValueSource(NetworkTablesModel& model,
|
||||
break;
|
||||
}
|
||||
case wpi::util::json::value_t::string:
|
||||
out->value = wpi::nt::Value::MakeString(j.get_ref<const std::string&>(), time);
|
||||
out->value =
|
||||
wpi::nt::Value::MakeString(j.get_ref<const std::string&>(), time);
|
||||
out->UpdateFromValue(model, name, "");
|
||||
break;
|
||||
case wpi::util::json::value_t::boolean:
|
||||
@@ -896,7 +906,8 @@ void NetworkTablesModel::ValueSource::UpdateFromValue(
|
||||
mpack_reader_init_data(&r, value.GetRaw());
|
||||
UpdateMsgpackValueSource(model, this, r, name, value.last_change());
|
||||
mpack_reader_destroy(&r);
|
||||
} else if (auto structNameOpt = wpi::util::remove_prefix(typeStr, "struct:")) {
|
||||
} else if (auto structNameOpt =
|
||||
wpi::util::remove_prefix(typeStr, "struct:")) {
|
||||
auto structName = *structNameOpt;
|
||||
auto withoutArray = wpi::util::remove_suffix(structName, "[]");
|
||||
bool isArray = withoutArray.has_value();
|
||||
@@ -1020,8 +1031,8 @@ void NetworkTablesModel::Update() {
|
||||
if (entry) {
|
||||
entry->value = std::move(valueData->value);
|
||||
entry->UpdateFromValue(*this);
|
||||
if (wpi::util::starts_with(entry->info.name, '$') && entry->value.IsRaw() &&
|
||||
entry->info.type_str == "msgpack") {
|
||||
if (wpi::util::starts_with(entry->info.name, '$') &&
|
||||
entry->value.IsRaw() && entry->info.type_str == "msgpack") {
|
||||
// meta topic handling
|
||||
if (entry->info.name == "$clients") {
|
||||
// need to remove deleted entries as UpdateClients() uses GetEntry()
|
||||
@@ -1033,21 +1044,21 @@ void NetworkTablesModel::Update() {
|
||||
m_server.UpdatePublishers(entry->value.GetRaw());
|
||||
} else if (entry->info.name == "$serversub") {
|
||||
m_server.UpdateSubscribers(entry->value.GetRaw());
|
||||
} else if (auto client =
|
||||
wpi::util::remove_prefix(entry->info.name, "$clientpub$")) {
|
||||
} else if (auto client = wpi::util::remove_prefix(entry->info.name,
|
||||
"$clientpub$")) {
|
||||
auto it = m_clients.find(*client);
|
||||
if (it != m_clients.end()) {
|
||||
it->second.UpdatePublishers(entry->value.GetRaw());
|
||||
}
|
||||
} else if (auto client =
|
||||
wpi::util::remove_prefix(entry->info.name, "$clientsub$")) {
|
||||
} else if (auto client = wpi::util::remove_prefix(entry->info.name,
|
||||
"$clientsub$")) {
|
||||
auto it = m_clients.find(*client);
|
||||
if (it != m_clients.end()) {
|
||||
it->second.UpdateSubscribers(entry->value.GetRaw());
|
||||
}
|
||||
}
|
||||
} else if (auto typeStr =
|
||||
wpi::util::remove_prefix(entry->info.name, "/.schema/struct:");
|
||||
} else if (auto typeStr = wpi::util::remove_prefix(entry->info.name,
|
||||
"/.schema/struct:");
|
||||
entry->value.IsRaw() && typeStr &&
|
||||
entry->info.type_str == "structschema") {
|
||||
// struct schema handling
|
||||
@@ -1058,24 +1069,25 @@ void NetworkTablesModel::Update() {
|
||||
auto desc = m_structDb.Add(*typeStr, schema, &err);
|
||||
if (!desc) {
|
||||
wpi::util::print("could not decode struct '{}' schema '{}': {}\n",
|
||||
entry->info.name, schema, err);
|
||||
entry->info.name, schema, err);
|
||||
} else if (desc->IsValid()) {
|
||||
// loop over all entries with this type and update
|
||||
for (auto&& entryPair : m_entries) {
|
||||
if (!entryPair.second) {
|
||||
continue;
|
||||
}
|
||||
if (auto ts = wpi::util::remove_prefix(entryPair.second->info.type_str,
|
||||
"struct:")) {
|
||||
if (auto ts = wpi::util::remove_prefix(
|
||||
entryPair.second->info.type_str, "struct:")) {
|
||||
if (*ts == *typeStr ||
|
||||
wpi::util::remove_suffix(*ts, "[]").value_or(*ts) == *typeStr) {
|
||||
wpi::util::remove_suffix(*ts, "[]").value_or(*ts) ==
|
||||
*typeStr) {
|
||||
entryPair.second->UpdateFromValue(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (auto filename =
|
||||
wpi::util::remove_prefix(entry->info.name, "/.schema/proto:");
|
||||
} else if (auto filename = wpi::util::remove_prefix(entry->info.name,
|
||||
"/.schema/proto:");
|
||||
entry->value.IsRaw() && filename &&
|
||||
entry->info.type_str == "proto:FileDescriptorProto") {
|
||||
// protobuf descriptor handling
|
||||
@@ -1090,7 +1102,7 @@ void NetworkTablesModel::Update() {
|
||||
&status);
|
||||
if (!status.ok) {
|
||||
wpi::util::print("could not decode protobuf '{}' filename '{}'\n",
|
||||
entry->info.name, *filename);
|
||||
entry->info.name, *filename);
|
||||
} else {
|
||||
// loop over all protobuf entries and update (conservatively)
|
||||
for (auto&& entryPair : m_entries) {
|
||||
@@ -1142,7 +1154,7 @@ void NetworkTablesModel::RebuildTreeImpl(std::vector<TreeNode>* tree,
|
||||
}
|
||||
parts.clear();
|
||||
wpi::util::split(entry->info.name, '/', -1, false,
|
||||
[&](auto part) { parts.emplace_back(part); });
|
||||
[&](auto part) { parts.emplace_back(part); });
|
||||
|
||||
// ignore a raw "/" key
|
||||
if (parts.empty()) {
|
||||
@@ -1151,7 +1163,8 @@ void NetworkTablesModel::RebuildTreeImpl(std::vector<TreeNode>* tree,
|
||||
|
||||
// get to leaf
|
||||
auto nodes = tree;
|
||||
for (auto part : wpi::util::drop_back(std::span{parts.begin(), parts.end()})) {
|
||||
for (auto part :
|
||||
wpi::util::drop_back(std::span{parts.begin(), parts.end()})) {
|
||||
auto it =
|
||||
std::find_if(nodes->begin(), nodes->end(),
|
||||
[&](const auto& node) { return node.name == part; });
|
||||
@@ -1577,7 +1590,8 @@ static void EmitEntryValueEditable(NetworkTablesModel* model,
|
||||
if (InputExpr<int64_t>(typeStr, &v, "%" PRId64,
|
||||
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
if (entry.publisher == 0) {
|
||||
entry.publisher = wpi::nt::Publish(entry.info.topic, NT_INTEGER, "int");
|
||||
entry.publisher =
|
||||
wpi::nt::Publish(entry.info.topic, NT_INTEGER, "int");
|
||||
}
|
||||
wpi::nt::SetInteger(entry.publisher, v);
|
||||
}
|
||||
@@ -1588,7 +1602,8 @@ static void EmitEntryValueEditable(NetworkTablesModel* model,
|
||||
if (InputExpr<float>(typeStr, &v, "%.6f",
|
||||
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
if (entry.publisher == 0) {
|
||||
entry.publisher = wpi::nt::Publish(entry.info.topic, NT_FLOAT, "float");
|
||||
entry.publisher =
|
||||
wpi::nt::Publish(entry.info.topic, NT_FLOAT, "float");
|
||||
}
|
||||
wpi::nt::SetFloat(entry.publisher, v);
|
||||
}
|
||||
@@ -1606,7 +1621,8 @@ static void EmitEntryValueEditable(NetworkTablesModel* model,
|
||||
fmt::format("%.{}f", precision).c_str(),
|
||||
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
if (entry.publisher == 0) {
|
||||
entry.publisher = wpi::nt::Publish(entry.info.topic, NT_DOUBLE, "double");
|
||||
entry.publisher =
|
||||
wpi::nt::Publish(entry.info.topic, NT_DOUBLE, "double");
|
||||
}
|
||||
wpi::nt::SetDouble(entry.publisher, v);
|
||||
}
|
||||
@@ -1627,7 +1643,7 @@ static void EmitEntryValueEditable(NetworkTablesModel* model,
|
||||
}
|
||||
wpi::util::SmallString<128> buf;
|
||||
wpi::nt::SetString(entry.publisher,
|
||||
wpi::util::UnescapeCString(v + 1, buf).first);
|
||||
wpi::util::UnescapeCString(v + 1, buf).first);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1721,8 +1737,8 @@ static void CreateTopicMenuItem(NetworkTablesModel* model,
|
||||
std::string_view path, NT_Type type,
|
||||
const char* typeStr, bool enabled) {
|
||||
if (ImGui::MenuItem(typeStr, nullptr, false, enabled)) {
|
||||
auto entry =
|
||||
model->AddEntry(wpi::nt::GetTopic(model->GetInstance().GetHandle(), path));
|
||||
auto entry = model->AddEntry(
|
||||
wpi::nt::GetTopic(model->GetInstance().GetHandle(), path));
|
||||
if (entry->publisher == 0) {
|
||||
entry->publisher = wpi::nt::Publish(entry->info.topic, type, typeStr);
|
||||
// publish a default value so it's editable
|
||||
@@ -1765,8 +1781,8 @@ static void CreateTopicMenuItem(NetworkTablesModel* model,
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayNetworkTablesAddMenu(NetworkTablesModel* model,
|
||||
std::string_view path,
|
||||
NetworkTablesFlags flags) {
|
||||
std::string_view path,
|
||||
NetworkTablesFlags flags) {
|
||||
static char nameBuffer[kTextBufferSize];
|
||||
|
||||
if (ImGui::BeginMenu("Add new...")) {
|
||||
@@ -1850,7 +1866,7 @@ static void EmitValueTree(
|
||||
std::string_view ts = child.typeStr;
|
||||
bool havePopup = GetHeadingTypeString(&ts);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}##v_{}", ts.data(),
|
||||
child.name.c_str());
|
||||
child.name.c_str());
|
||||
bool valueChildrenOpen =
|
||||
TreeNodeEx(label, ImGuiTreeNodeFlags_SpanFullWidth);
|
||||
if (havePopup) {
|
||||
@@ -1892,7 +1908,7 @@ static void EmitEntry(NetworkTablesModel* model,
|
||||
std::string_view ts = entry.info.type_str;
|
||||
bool havePopup = GetHeadingTypeString(&ts);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}##v_{}", ts.data(),
|
||||
entry.info.name.c_str());
|
||||
entry.info.name.c_str());
|
||||
valueChildrenOpen =
|
||||
TreeNodeEx(label, ImGuiTreeNodeFlags_SpanFullWidth |
|
||||
ImGuiTreeNodeFlags_AllowItemOverlap);
|
||||
@@ -2194,7 +2210,7 @@ void wpi::glass::DisplayNetworkTablesInfo(NetworkTablesModel* model) {
|
||||
}
|
||||
|
||||
void wpi::glass::DisplayNetworkTables(NetworkTablesModel* model,
|
||||
NetworkTablesFlags flags) {
|
||||
NetworkTablesFlags flags) {
|
||||
gArrayEditorID = ImGui::GetID("Array Editor");
|
||||
if (ImGui::BeginPopupModal("Array Editor", nullptr,
|
||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
using namespace wpi::glass;
|
||||
|
||||
NetworkTablesProvider::NetworkTablesProvider(Storage& storage)
|
||||
: NetworkTablesProvider{storage, wpi::nt::NetworkTableInstance::GetDefault()} {}
|
||||
: NetworkTablesProvider{storage,
|
||||
wpi::nt::NetworkTableInstance::GetDefault()} {}
|
||||
|
||||
NetworkTablesProvider::NetworkTablesProvider(Storage& storage,
|
||||
wpi::nt::NetworkTableInstance inst)
|
||||
@@ -69,7 +70,7 @@ void NetworkTablesProvider::DisplayMenu() {
|
||||
for (auto&& entry : m_viewEntries) {
|
||||
path.clear();
|
||||
wpi::util::split(entry->name, '/', -1, false,
|
||||
[&](auto name) { path.emplace_back(name); });
|
||||
[&](auto name) { path.emplace_back(name); });
|
||||
|
||||
bool fullDepth = true;
|
||||
int depth = 0;
|
||||
@@ -119,8 +120,8 @@ void NetworkTablesProvider::Update() {
|
||||
if (auto info = event.GetTopicInfo()) {
|
||||
// add/remove entries from NT changes
|
||||
// look for .type fields
|
||||
if (!wpi::util::ends_with(info->name, "/.type") || info->type != NT_STRING ||
|
||||
info->type_str != "string") {
|
||||
if (!wpi::util::ends_with(info->name, "/.type") ||
|
||||
info->type != NT_STRING || info->type_str != "string") {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -142,7 +143,8 @@ void NetworkTablesProvider::Update() {
|
||||
} else if (event.flags & wpi::nt::EventFlags::kPublish) {
|
||||
// subscribe to it; use a subscriber so we only get string values
|
||||
SubListener sublistener;
|
||||
sublistener.subscriber = wpi::nt::StringTopic{info->topic}.Subscribe("");
|
||||
sublistener.subscriber =
|
||||
wpi::nt::StringTopic{info->topic}.Subscribe("");
|
||||
sublistener.listener = m_poller.AddListener(
|
||||
sublistener.subscriber,
|
||||
wpi::nt::EventFlags::kValueAll | wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
@@ -80,7 +80,7 @@ void NetworkTablesSettings::Thread::Main() {
|
||||
}
|
||||
} else if (m_mode == 3) {
|
||||
wpi::nt::StartServer(m_inst, m_iniName.c_str(), m_listenAddress.c_str(),
|
||||
m_port);
|
||||
m_port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
|
||||
using namespace wpi::glass;
|
||||
|
||||
void wpi::glass::AddStandardNetworkTablesViews(NetworkTablesProvider& provider) {
|
||||
void wpi::glass::AddStandardNetworkTablesViews(
|
||||
NetworkTablesProvider& provider) {
|
||||
provider.Register(
|
||||
NTAlertsModel::kType,
|
||||
[](wpi::nt::NetworkTableInstance inst, const char* path) {
|
||||
|
||||
@@ -23,7 +23,8 @@ class NTCommandSchedulerModel : public CommandSchedulerModel {
|
||||
static constexpr const char* kType = "Scheduler";
|
||||
|
||||
explicit NTCommandSchedulerModel(std::string_view path);
|
||||
NTCommandSchedulerModel(wpi::nt::NetworkTableInstance inst, std::string_view path);
|
||||
NTCommandSchedulerModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path);
|
||||
|
||||
const char* GetName() const override { return m_nameValue.c_str(); }
|
||||
const std::vector<std::string>& GetCurrentCommands() override {
|
||||
|
||||
@@ -19,7 +19,8 @@ class NTCommandSelectorModel : public CommandSelectorModel {
|
||||
static constexpr const char* kType = "Command";
|
||||
|
||||
explicit NTCommandSelectorModel(std::string_view path);
|
||||
NTCommandSelectorModel(wpi::nt::NetworkTableInstance inst, std::string_view path);
|
||||
NTCommandSelectorModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path);
|
||||
|
||||
const char* GetName() const override { return m_nameValue.c_str(); }
|
||||
BooleanSource* GetRunningData() override { return &m_runningData; }
|
||||
|
||||
@@ -21,7 +21,8 @@ class NTDigitalInputModel : public DIOModel {
|
||||
|
||||
// path is to the table containing ".type", excluding the trailing /
|
||||
explicit NTDigitalInputModel(std::string_view path);
|
||||
NTDigitalInputModel(wpi::nt::NetworkTableInstance inst, std::string_view path);
|
||||
NTDigitalInputModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path);
|
||||
|
||||
const char* GetName() const override { return m_nameValue.c_str(); }
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ class NTDigitalOutputModel : public DIOModel {
|
||||
|
||||
// path is to the table containing ".type", excluding the trailing /
|
||||
explicit NTDigitalOutputModel(std::string_view path);
|
||||
NTDigitalOutputModel(wpi::nt::NetworkTableInstance inst, std::string_view path);
|
||||
NTDigitalOutputModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path);
|
||||
|
||||
const char* GetName() const override { return m_nameValue.c_str(); }
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@ class NTField2DModel : public Field2DModel {
|
||||
|
||||
FieldObjectModel* AddFieldObject(std::string_view name) override;
|
||||
void RemoveFieldObject(std::string_view name) override;
|
||||
void ForEachFieldObject(
|
||||
wpi::util::function_ref<void(FieldObjectModel& model, std::string_view name)>
|
||||
func) override;
|
||||
void ForEachFieldObject(wpi::util::function_ref<void(FieldObjectModel& model,
|
||||
std::string_view name)>
|
||||
func) override;
|
||||
|
||||
private:
|
||||
std::string m_path;
|
||||
|
||||
@@ -21,7 +21,8 @@ class NTMecanumDriveModel : public DriveModel {
|
||||
static constexpr const char* kType = "MecanumDrive";
|
||||
|
||||
explicit NTMecanumDriveModel(std::string_view path);
|
||||
NTMecanumDriveModel(wpi::nt::NetworkTableInstance inst, std::string_view path);
|
||||
NTMecanumDriveModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path);
|
||||
|
||||
const char* GetName() const override { return m_nameValue.c_str(); }
|
||||
const std::vector<DriveModel::WheelInfo>& GetWheels() const override {
|
||||
|
||||
@@ -57,8 +57,8 @@ class NTMechanism2DModel : public Mechanism2DModel {
|
||||
class NTMechanismObjectModel;
|
||||
class NTMechanismGroupImpl final {
|
||||
public:
|
||||
NTMechanismGroupImpl(wpi::nt::NetworkTableInstance inst, std::string_view path,
|
||||
std::string_view name)
|
||||
NTMechanismGroupImpl(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path, std::string_view name)
|
||||
: m_inst{inst}, m_path{path}, m_name{name} {}
|
||||
|
||||
const char* GetName() const { return m_name.c_str(); }
|
||||
@@ -76,8 +76,8 @@ class NTMechanism2DModel : public Mechanism2DModel {
|
||||
|
||||
class NTMechanismObjectModel final : public MechanismObjectModel {
|
||||
public:
|
||||
NTMechanismObjectModel(wpi::nt::NetworkTableInstance inst, std::string_view path,
|
||||
std::string_view name)
|
||||
NTMechanismObjectModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path, std::string_view name)
|
||||
: m_group{inst, path, name},
|
||||
m_typeTopic{inst.GetTopic(fmt::format("{}/.type", path))},
|
||||
m_colorTopic{inst.GetTopic(fmt::format("{}/color", path))},
|
||||
|
||||
@@ -20,7 +20,8 @@ class NTMotorControllerModel : public MotorControllerModel {
|
||||
static constexpr const char* kType = "Motor Controller";
|
||||
|
||||
explicit NTMotorControllerModel(std::string_view path);
|
||||
NTMotorControllerModel(wpi::nt::NetworkTableInstance inst, std::string_view path);
|
||||
NTMotorControllerModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path);
|
||||
|
||||
const char* GetName() const override { return m_nameValue.c_str(); }
|
||||
const char* GetSimDevice() const override { return nullptr; }
|
||||
|
||||
@@ -20,7 +20,8 @@ class NTPIDControllerModel : public PIDControllerModel {
|
||||
static constexpr const char* kType = "PIDController";
|
||||
|
||||
explicit NTPIDControllerModel(std::string_view path);
|
||||
NTPIDControllerModel(wpi::nt::NetworkTableInstance inst, std::string_view path);
|
||||
NTPIDControllerModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path);
|
||||
|
||||
const char* GetName() const override { return m_nameValue.c_str(); }
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ class NTStringChooserModel : public StringChooserModel {
|
||||
|
||||
// path is to the table containing ".type", excluding the trailing /
|
||||
explicit NTStringChooserModel(std::string_view path);
|
||||
NTStringChooserModel(wpi::nt::NetworkTableInstance inst, std::string_view path);
|
||||
NTStringChooserModel(wpi::nt::NetworkTableInstance inst,
|
||||
std::string_view path);
|
||||
|
||||
const std::string& GetDefault() override { return m_defaultValue; }
|
||||
const std::string& GetSelected() override { return m_selectedValue; }
|
||||
|
||||
@@ -176,7 +176,9 @@ class NetworkTablesModel : public Model {
|
||||
Entry* GetEntry(std::string_view name);
|
||||
Entry* AddEntry(NT_Topic topic);
|
||||
|
||||
wpi::util::StructDescriptorDatabase& GetStructDatabase() { return m_structDb; }
|
||||
wpi::util::StructDescriptorDatabase& GetStructDatabase() {
|
||||
return m_structDb;
|
||||
}
|
||||
upb_DefPool* GetProtobufDatabase() { return m_protoPool; }
|
||||
upb_Arena* GetProtobufArena() { return m_arena; }
|
||||
|
||||
|
||||
@@ -100,7 +100,8 @@ class NetworkTablesProvider : private Provider<detail::NTProviderFunctions> {
|
||||
wpi::util::DenseMap<NT_Topic, SubListener> m_topicMap;
|
||||
|
||||
struct Entry : public ModelEntry {
|
||||
Entry(wpi::nt::Topic typeTopic, std::string_view name, const Builder& builder)
|
||||
Entry(wpi::nt::Topic typeTopic, std::string_view name,
|
||||
const Builder& builder)
|
||||
: ModelEntry{name, [](auto, const char*) { return true; },
|
||||
builder.createModel},
|
||||
typeTopic{typeTopic} {}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
namespace wpi::util {
|
||||
template <typename T>
|
||||
class SmallVectorImpl;
|
||||
} // namespace wpi
|
||||
} // namespace wpi::util
|
||||
|
||||
namespace wpi::glass {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user