2020-12-26 14:31:24 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#include "glass/networktables/NetworkTables.h"
|
|
|
|
|
|
|
|
|
|
#include <cinttypes>
|
2023-06-08 19:59:54 -07:00
|
|
|
#include <concepts>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <cstring>
|
|
|
|
|
#include <initializer_list>
|
|
|
|
|
#include <memory>
|
2022-10-15 16:33:14 -07:00
|
|
|
#include <span>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <string_view>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <vector>
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <fmt/format.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <imgui.h>
|
2022-10-08 10:01:31 -07:00
|
|
|
#include <networktables/NetworkTableInstance.h>
|
|
|
|
|
#include <networktables/NetworkTableValue.h>
|
|
|
|
|
#include <ntcore_c.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <ntcore_cpp.h>
|
2022-10-08 10:01:31 -07:00
|
|
|
#include <ntcore_cpp_types.h>
|
|
|
|
|
#include <wpi/MessagePack.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <wpi/SmallString.h>
|
2021-06-06 19:51:14 -07:00
|
|
|
#include <wpi/SpanExtras.h>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <wpi/StringExtras.h>
|
2022-10-08 10:01:31 -07:00
|
|
|
#include <wpi/mpack.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <wpi/raw_ostream.h>
|
|
|
|
|
|
|
|
|
|
#include "glass/Context.h"
|
|
|
|
|
#include "glass/DataSource.h"
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
#include "glass/Storage.h"
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
using namespace glass;
|
2022-10-08 10:01:31 -07:00
|
|
|
using namespace mpack;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
enum ShowCategory {
|
|
|
|
|
ShowPersistent,
|
|
|
|
|
ShowRetained,
|
|
|
|
|
ShowTransitory,
|
|
|
|
|
ShowAll,
|
|
|
|
|
};
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
static bool IsVisible(ShowCategory category, bool persistent, bool retained) {
|
|
|
|
|
switch (category) {
|
|
|
|
|
case ShowPersistent:
|
|
|
|
|
return persistent;
|
|
|
|
|
case ShowRetained:
|
|
|
|
|
return retained && !persistent;
|
|
|
|
|
case ShowTransitory:
|
|
|
|
|
return !retained && !persistent;
|
|
|
|
|
case ShowAll:
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-15 16:33:14 -07:00
|
|
|
static std::string BooleanArrayToString(std::span<const int> in) {
|
2020-09-12 10:55:46 -07:00
|
|
|
std::string rv;
|
|
|
|
|
wpi::raw_string_ostream os{rv};
|
|
|
|
|
os << '[';
|
|
|
|
|
bool first = true;
|
|
|
|
|
for (auto v : in) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!first) {
|
|
|
|
|
os << ',';
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
first = false;
|
2020-12-28 12:58:06 -08:00
|
|
|
if (v) {
|
2020-09-12 10:55:46 -07:00
|
|
|
os << "true";
|
2020-12-28 12:58:06 -08:00
|
|
|
} else {
|
2020-09-12 10:55:46 -07:00
|
|
|
os << "false";
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
os << ']';
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-15 16:33:14 -07:00
|
|
|
static std::string IntegerArrayToString(std::span<const int64_t> in) {
|
2022-10-08 10:01:31 -07:00
|
|
|
return fmt::format("[{:d}]", fmt::join(in, ","));
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-07 09:50:09 -07:00
|
|
|
template <std::floating_point T>
|
2022-10-15 16:33:14 -07:00
|
|
|
static std::string FloatArrayToString(std::span<const T> in) {
|
2021-06-06 16:13:58 -07:00
|
|
|
return fmt::format("[{:.6f}]", fmt::join(in, ","));
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-15 16:33:14 -07:00
|
|
|
static std::string StringArrayToString(std::span<const std::string> in) {
|
2020-09-12 10:55:46 -07:00
|
|
|
std::string rv;
|
|
|
|
|
wpi::raw_string_ostream os{rv};
|
|
|
|
|
os << '[';
|
|
|
|
|
bool first = true;
|
|
|
|
|
for (auto&& v : in) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!first) {
|
|
|
|
|
os << ',';
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
first = false;
|
|
|
|
|
os << '"';
|
|
|
|
|
os.write_escaped(v);
|
|
|
|
|
os << '"';
|
|
|
|
|
}
|
|
|
|
|
os << ']';
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetworkTablesModel::NetworkTablesModel()
|
2022-10-08 10:01:31 -07:00
|
|
|
: NetworkTablesModel{nt::NetworkTableInstance::GetDefault()} {}
|
|
|
|
|
|
|
|
|
|
NetworkTablesModel::NetworkTablesModel(nt::NetworkTableInstance inst)
|
2022-10-31 21:52:14 -07:00
|
|
|
: m_inst{inst}, m_poller{inst} {
|
|
|
|
|
m_poller.AddListener({{"", "$"}}, nt::EventFlags::kTopic |
|
|
|
|
|
nt::EventFlags::kValueAll |
|
|
|
|
|
nt::EventFlags::kImmediate);
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
NetworkTablesModel::Entry::~Entry() {
|
|
|
|
|
if (publisher != 0) {
|
|
|
|
|
nt::Unpublish(publisher);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
void NetworkTablesModel::Entry::UpdateInfo(nt::TopicInfo&& info_) {
|
|
|
|
|
info = std::move(info_);
|
|
|
|
|
properties = info.GetProperties();
|
|
|
|
|
|
|
|
|
|
persistent = false;
|
|
|
|
|
auto it = properties.find("persistent");
|
|
|
|
|
if (it != properties.end()) {
|
|
|
|
|
if (auto v = it->get_ptr<const bool*>()) {
|
|
|
|
|
persistent = *v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retained = false;
|
|
|
|
|
it = properties.find("retained");
|
|
|
|
|
if (it != properties.end()) {
|
|
|
|
|
if (auto v = it->get_ptr<const bool*>()) {
|
|
|
|
|
retained = *v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void UpdateMsgpackValueSource(NetworkTablesModel::ValueSource* out,
|
|
|
|
|
mpack_reader_t& r, std::string_view name,
|
|
|
|
|
int64_t time) {
|
|
|
|
|
mpack_tag_t tag = mpack_read_tag(&r);
|
|
|
|
|
switch (mpack_tag_type(&tag)) {
|
|
|
|
|
case mpack::mpack_type_bool:
|
|
|
|
|
out->UpdateFromValue(
|
|
|
|
|
nt::Value::MakeBoolean(mpack_tag_bool_value(&tag), time), name, "");
|
|
|
|
|
break;
|
|
|
|
|
case mpack::mpack_type_int:
|
|
|
|
|
out->UpdateFromValue(
|
|
|
|
|
nt::Value::MakeInteger(mpack_tag_int_value(&tag), time), name, "");
|
|
|
|
|
break;
|
|
|
|
|
case mpack::mpack_type_uint:
|
|
|
|
|
out->UpdateFromValue(
|
|
|
|
|
nt::Value::MakeInteger(mpack_tag_uint_value(&tag), time), name, "");
|
|
|
|
|
break;
|
|
|
|
|
case mpack::mpack_type_float:
|
|
|
|
|
out->UpdateFromValue(
|
|
|
|
|
nt::Value::MakeFloat(mpack_tag_float_value(&tag), time), name, "");
|
|
|
|
|
break;
|
|
|
|
|
case mpack::mpack_type_double:
|
|
|
|
|
out->UpdateFromValue(
|
|
|
|
|
nt::Value::MakeDouble(mpack_tag_double_value(&tag), time), name, "");
|
|
|
|
|
break;
|
|
|
|
|
case mpack::mpack_type_str: {
|
|
|
|
|
std::string str;
|
|
|
|
|
mpack_read_str(&r, &tag, &str);
|
|
|
|
|
out->UpdateFromValue(nt::Value::MakeString(std::move(str), time), name,
|
|
|
|
|
"");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case mpack::mpack_type_bin:
|
|
|
|
|
// just skip it
|
|
|
|
|
mpack_skip_bytes(&r, mpack_tag_bin_length(&tag));
|
|
|
|
|
mpack_done_bin(&r);
|
|
|
|
|
break;
|
|
|
|
|
case mpack::mpack_type_array: {
|
|
|
|
|
if (out->valueChildrenMap) {
|
|
|
|
|
out->valueChildren.clear();
|
|
|
|
|
out->valueChildrenMap = false;
|
|
|
|
|
}
|
|
|
|
|
out->valueChildren.resize(mpack_tag_array_count(&tag));
|
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
for (auto&& child : out->valueChildren) {
|
|
|
|
|
if (child.name.empty()) {
|
|
|
|
|
child.name = fmt::format("[{}]", i);
|
|
|
|
|
child.path = fmt::format("{}{}", name, child.name);
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
UpdateMsgpackValueSource(&child, r, child.path, time); // recurse
|
|
|
|
|
}
|
|
|
|
|
mpack_done_array(&r);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case mpack::mpack_type_map: {
|
|
|
|
|
if (!out->valueChildrenMap) {
|
|
|
|
|
out->valueChildren.clear();
|
|
|
|
|
out->valueChildrenMap = true;
|
|
|
|
|
}
|
|
|
|
|
wpi::StringMap<size_t> elems;
|
|
|
|
|
for (size_t i = 0, size = out->valueChildren.size(); i < size; ++i) {
|
|
|
|
|
elems[out->valueChildren[i].name] = i;
|
|
|
|
|
}
|
|
|
|
|
bool added = false;
|
|
|
|
|
uint32_t count = mpack_tag_map_count(&tag);
|
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
|
std::string key;
|
|
|
|
|
if (mpack_expect_str(&r, &key) == mpack_ok) {
|
|
|
|
|
auto it = elems.find(key);
|
|
|
|
|
if (it != elems.end()) {
|
|
|
|
|
auto& child = out->valueChildren[it->second];
|
|
|
|
|
UpdateMsgpackValueSource(&child, r, child.path, time);
|
|
|
|
|
elems.erase(it);
|
|
|
|
|
} else {
|
|
|
|
|
added = true;
|
|
|
|
|
out->valueChildren.emplace_back();
|
|
|
|
|
auto& child = out->valueChildren.back();
|
|
|
|
|
child.name = std::move(key);
|
|
|
|
|
child.path = fmt::format("{}/{}", name, child.name);
|
|
|
|
|
UpdateMsgpackValueSource(&child, r, child.path, time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// erase unmatched keys
|
|
|
|
|
out->valueChildren.erase(
|
|
|
|
|
std::remove_if(
|
|
|
|
|
out->valueChildren.begin(), out->valueChildren.end(),
|
|
|
|
|
[&](const auto& child) { return elems.count(child.name) > 0; }),
|
|
|
|
|
out->valueChildren.end());
|
|
|
|
|
if (added) {
|
|
|
|
|
// sort by name
|
|
|
|
|
std::sort(out->valueChildren.begin(), out->valueChildren.end(),
|
|
|
|
|
[](const auto& a, const auto& b) { return a.name < b.name; });
|
|
|
|
|
}
|
|
|
|
|
mpack_done_map(&r);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
out->value = {};
|
|
|
|
|
mpack_done_type(&r, mpack_tag_type(&tag));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static void UpdateJsonValueSource(NetworkTablesModel::ValueSource* out,
|
|
|
|
|
const wpi::json& j, std::string_view name,
|
|
|
|
|
int64_t time) {
|
|
|
|
|
switch (j.type()) {
|
|
|
|
|
case wpi::json::value_t::object: {
|
|
|
|
|
if (!out->valueChildrenMap) {
|
|
|
|
|
out->valueChildren.clear();
|
|
|
|
|
out->valueChildrenMap = true;
|
|
|
|
|
}
|
|
|
|
|
wpi::StringMap<size_t> elems;
|
|
|
|
|
for (size_t i = 0, size = out->valueChildren.size(); i < size; ++i) {
|
|
|
|
|
elems[out->valueChildren[i].name] = i;
|
|
|
|
|
}
|
|
|
|
|
bool added = false;
|
|
|
|
|
for (auto&& kv : j.items()) {
|
|
|
|
|
auto it = elems.find(kv.key());
|
|
|
|
|
if (it != elems.end()) {
|
|
|
|
|
auto& child = out->valueChildren[it->second];
|
|
|
|
|
UpdateJsonValueSource(&child, kv.value(), child.path, time);
|
|
|
|
|
elems.erase(it);
|
|
|
|
|
} else {
|
|
|
|
|
added = true;
|
|
|
|
|
out->valueChildren.emplace_back();
|
|
|
|
|
auto& child = out->valueChildren.back();
|
|
|
|
|
child.name = kv.key();
|
|
|
|
|
child.path = fmt::format("{}/{}", name, child.name);
|
|
|
|
|
UpdateJsonValueSource(&child, kv.value(), child.path, time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// erase unmatched keys
|
|
|
|
|
out->valueChildren.erase(
|
|
|
|
|
std::remove_if(
|
|
|
|
|
out->valueChildren.begin(), out->valueChildren.end(),
|
|
|
|
|
[&](const auto& child) { return elems.count(child.name) > 0; }),
|
|
|
|
|
out->valueChildren.end());
|
|
|
|
|
if (added) {
|
|
|
|
|
// sort by name
|
|
|
|
|
std::sort(out->valueChildren.begin(), out->valueChildren.end(),
|
|
|
|
|
[](const auto& a, const auto& b) { return a.name < b.name; });
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case wpi::json::value_t::array: {
|
|
|
|
|
if (out->valueChildrenMap) {
|
|
|
|
|
out->valueChildren.clear();
|
|
|
|
|
out->valueChildrenMap = false;
|
|
|
|
|
}
|
|
|
|
|
out->valueChildren.resize(j.size());
|
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
for (auto&& child : out->valueChildren) {
|
|
|
|
|
if (child.name.empty()) {
|
|
|
|
|
child.name = fmt::format("[{}]", i);
|
|
|
|
|
child.path = fmt::format("{}{}", name, child.name);
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
UpdateJsonValueSource(&child, j[i], child.path, time); // recurse
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case wpi::json::value_t::string:
|
|
|
|
|
out->UpdateFromValue(
|
|
|
|
|
nt::Value::MakeString(j.get_ref<const std::string&>(), time), name,
|
|
|
|
|
"");
|
|
|
|
|
break;
|
|
|
|
|
case wpi::json::value_t::boolean:
|
|
|
|
|
out->UpdateFromValue(nt::Value::MakeBoolean(j.get<bool>(), time), name,
|
|
|
|
|
"");
|
|
|
|
|
break;
|
|
|
|
|
case wpi::json::value_t::number_integer:
|
|
|
|
|
out->UpdateFromValue(nt::Value::MakeInteger(j.get<int64_t>(), time), name,
|
|
|
|
|
"");
|
|
|
|
|
break;
|
|
|
|
|
case wpi::json::value_t::number_unsigned:
|
|
|
|
|
out->UpdateFromValue(nt::Value::MakeInteger(j.get<uint64_t>(), time),
|
|
|
|
|
name, "");
|
|
|
|
|
break;
|
|
|
|
|
case wpi::json::value_t::number_float:
|
|
|
|
|
out->UpdateFromValue(nt::Value::MakeDouble(j.get<double>(), time), name,
|
|
|
|
|
"");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
out->value = {};
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
void NetworkTablesModel::ValueSource::UpdateFromValue(
|
|
|
|
|
nt::Value&& v, std::string_view name, std::string_view typeStr) {
|
|
|
|
|
value = v;
|
|
|
|
|
switch (value.type()) {
|
2020-09-12 10:55:46 -07:00
|
|
|
case NT_BOOLEAN:
|
2022-10-08 10:01:31 -07:00
|
|
|
valueChildren.clear();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!source) {
|
2021-06-06 16:13:58 -07:00
|
|
|
source = std::make_unique<DataSource>(fmt::format("NT:{}", name));
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
source->SetValue(value.GetBoolean() ? 1 : 0, value.last_change());
|
2020-09-12 10:55:46 -07:00
|
|
|
source->SetDigital(true);
|
|
|
|
|
break;
|
2022-10-08 10:01:31 -07:00
|
|
|
case NT_INTEGER:
|
|
|
|
|
valueChildren.clear();
|
|
|
|
|
if (!source) {
|
|
|
|
|
source = std::make_unique<DataSource>(fmt::format("NT:{}", name));
|
|
|
|
|
}
|
|
|
|
|
source->SetValue(value.GetInteger(), value.last_change());
|
|
|
|
|
source->SetDigital(false);
|
|
|
|
|
break;
|
|
|
|
|
case NT_FLOAT:
|
|
|
|
|
valueChildren.clear();
|
|
|
|
|
if (!source) {
|
|
|
|
|
source = std::make_unique<DataSource>(fmt::format("NT:{}", name));
|
|
|
|
|
}
|
|
|
|
|
source->SetValue(value.GetFloat(), value.last_change());
|
|
|
|
|
source->SetDigital(false);
|
|
|
|
|
break;
|
2020-09-12 10:55:46 -07:00
|
|
|
case NT_DOUBLE:
|
2022-10-08 10:01:31 -07:00
|
|
|
valueChildren.clear();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!source) {
|
2021-06-06 16:13:58 -07:00
|
|
|
source = std::make_unique<DataSource>(fmt::format("NT:{}", name));
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
source->SetValue(value.GetDouble(), value.last_change());
|
2020-09-12 10:55:46 -07:00
|
|
|
source->SetDigital(false);
|
|
|
|
|
break;
|
|
|
|
|
case NT_BOOLEAN_ARRAY:
|
2022-10-08 10:01:31 -07:00
|
|
|
valueChildren.clear();
|
|
|
|
|
valueStr = BooleanArrayToString(value.GetBooleanArray());
|
|
|
|
|
break;
|
|
|
|
|
case NT_INTEGER_ARRAY:
|
|
|
|
|
valueChildren.clear();
|
|
|
|
|
valueStr = IntegerArrayToString(value.GetIntegerArray());
|
|
|
|
|
break;
|
|
|
|
|
case NT_FLOAT_ARRAY:
|
|
|
|
|
valueChildren.clear();
|
|
|
|
|
valueStr = FloatArrayToString(value.GetFloatArray());
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
case NT_DOUBLE_ARRAY:
|
2022-10-08 10:01:31 -07:00
|
|
|
valueChildren.clear();
|
|
|
|
|
valueStr = FloatArrayToString(value.GetDoubleArray());
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
case NT_STRING_ARRAY:
|
2022-10-08 10:01:31 -07:00
|
|
|
valueChildren.clear();
|
|
|
|
|
valueStr = StringArrayToString(value.GetStringArray());
|
|
|
|
|
break;
|
|
|
|
|
case NT_STRING:
|
|
|
|
|
if (typeStr == "json") {
|
|
|
|
|
try {
|
|
|
|
|
UpdateJsonValueSource(this, wpi::json::parse(value.GetString()), name,
|
|
|
|
|
value.last_change());
|
|
|
|
|
} catch (wpi::json::exception&) {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
valueChildren.clear();
|
2023-02-17 18:01:54 -08:00
|
|
|
valueStr.clear();
|
|
|
|
|
wpi::raw_string_ostream os{valueStr};
|
|
|
|
|
os << '"';
|
|
|
|
|
os.write_escaped(value.GetString());
|
|
|
|
|
os << '"';
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NT_RAW:
|
|
|
|
|
if (typeStr == "msgpack") {
|
|
|
|
|
mpack_reader_t r;
|
|
|
|
|
mpack_reader_init_data(&r, value.GetRaw());
|
|
|
|
|
UpdateMsgpackValueSource(this, r, name, value.last_change());
|
|
|
|
|
|
|
|
|
|
mpack_reader_destroy(&r);
|
|
|
|
|
} else {
|
|
|
|
|
valueChildren.clear();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
default:
|
2022-10-08 10:01:31 -07:00
|
|
|
valueChildren.clear();
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkTablesModel::Update() {
|
|
|
|
|
bool updateTree = false;
|
2022-10-31 21:52:14 -07:00
|
|
|
for (auto&& event : m_poller.ReadQueue()) {
|
|
|
|
|
if (auto info = event.GetTopicInfo()) {
|
|
|
|
|
auto& entry = m_entries[info->topic];
|
|
|
|
|
if (event.flags & nt::EventFlags::kPublish) {
|
|
|
|
|
if (!entry) {
|
|
|
|
|
entry = std::make_unique<Entry>();
|
|
|
|
|
m_sortedEntries.emplace_back(entry.get());
|
|
|
|
|
updateTree = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (event.flags & nt::EventFlags::kUnpublish) {
|
2022-11-29 21:57:48 -08:00
|
|
|
// meta topic handling
|
|
|
|
|
if (wpi::starts_with(info->name, '$')) {
|
|
|
|
|
// meta topic handling
|
|
|
|
|
if (info->name == "$clients") {
|
|
|
|
|
m_clients.clear();
|
|
|
|
|
} else if (info->name == "$serverpub") {
|
|
|
|
|
m_server.publishers.clear();
|
|
|
|
|
} else if (info->name == "$serversub") {
|
|
|
|
|
m_server.subscribers.clear();
|
|
|
|
|
} else if (wpi::starts_with(info->name, "$clientpub$")) {
|
|
|
|
|
auto it = m_clients.find(wpi::drop_front(info->name, 11));
|
|
|
|
|
if (it != m_clients.end()) {
|
|
|
|
|
it->second.publishers.clear();
|
|
|
|
|
}
|
|
|
|
|
} else if (wpi::starts_with(info->name, "$clientsub$")) {
|
|
|
|
|
auto it = m_clients.find(wpi::drop_front(info->name, 11));
|
|
|
|
|
if (it != m_clients.end()) {
|
|
|
|
|
it->second.subscribers.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-31 21:52:14 -07:00
|
|
|
auto it = std::find(m_sortedEntries.begin(), m_sortedEntries.end(),
|
|
|
|
|
entry.get());
|
|
|
|
|
// will be removed completely below
|
|
|
|
|
if (it != m_sortedEntries.end()) {
|
|
|
|
|
*it = nullptr;
|
|
|
|
|
}
|
|
|
|
|
m_entries.erase(info->topic);
|
2020-09-12 10:55:46 -07:00
|
|
|
updateTree = true;
|
2022-10-31 21:52:14 -07:00
|
|
|
continue;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2022-10-31 21:52:14 -07:00
|
|
|
if (event.flags & nt::EventFlags::kProperties) {
|
|
|
|
|
updateTree = true;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2022-10-31 21:52:14 -07:00
|
|
|
if (entry) {
|
|
|
|
|
entry->UpdateTopic(std::move(event));
|
|
|
|
|
}
|
|
|
|
|
} else if (auto valueData = event.GetValueEventData()) {
|
|
|
|
|
auto& entry = m_entries[valueData->topic];
|
|
|
|
|
if (entry) {
|
|
|
|
|
entry->UpdateFromValue(std::move(valueData->value), entry->info.name,
|
|
|
|
|
entry->info.type_str);
|
|
|
|
|
if (wpi::starts_with(entry->info.name, '$') && entry->value.IsRaw() &&
|
|
|
|
|
entry->info.type_str == "msgpack") {
|
|
|
|
|
// meta topic handling
|
|
|
|
|
if (entry->info.name == "$clients") {
|
2022-12-12 23:38:36 -08:00
|
|
|
// need to remove deleted entries as UpdateClients() uses GetEntry()
|
|
|
|
|
if (updateTree) {
|
|
|
|
|
std::erase(m_sortedEntries, nullptr);
|
|
|
|
|
}
|
2022-10-31 21:52:14 -07:00
|
|
|
UpdateClients(entry->value.GetRaw());
|
|
|
|
|
} else if (entry->info.name == "$serverpub") {
|
|
|
|
|
m_server.UpdatePublishers(entry->value.GetRaw());
|
|
|
|
|
} else if (entry->info.name == "$serversub") {
|
|
|
|
|
m_server.UpdateSubscribers(entry->value.GetRaw());
|
|
|
|
|
} else if (wpi::starts_with(entry->info.name, "$clientpub$")) {
|
|
|
|
|
auto it = m_clients.find(wpi::drop_front(entry->info.name, 11));
|
|
|
|
|
if (it != m_clients.end()) {
|
|
|
|
|
it->second.UpdatePublishers(entry->value.GetRaw());
|
|
|
|
|
}
|
|
|
|
|
} else if (wpi::starts_with(entry->info.name, "$clientsub$")) {
|
|
|
|
|
auto it = m_clients.find(wpi::drop_front(entry->info.name, 11));
|
|
|
|
|
if (it != m_clients.end()) {
|
|
|
|
|
it->second.UpdateSubscribers(entry->value.GetRaw());
|
|
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// shortcut common case (updates)
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!updateTree) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
// remove deleted entries
|
2022-12-12 23:38:36 -08:00
|
|
|
std::erase(m_sortedEntries, nullptr);
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
RebuildTree();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkTablesModel::RebuildTree() {
|
2020-09-12 10:55:46 -07:00
|
|
|
// sort by name
|
2022-10-08 10:01:31 -07:00
|
|
|
std::sort(
|
|
|
|
|
m_sortedEntries.begin(), m_sortedEntries.end(),
|
|
|
|
|
[](const auto& a, const auto& b) { return a->info.name < b->info.name; });
|
|
|
|
|
|
|
|
|
|
RebuildTreeImpl(&m_root, ShowAll);
|
|
|
|
|
RebuildTreeImpl(&m_persistentRoot, ShowPersistent);
|
|
|
|
|
RebuildTreeImpl(&m_retainedRoot, ShowRetained);
|
|
|
|
|
RebuildTreeImpl(&m_transitoryRoot, ShowTransitory);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
void NetworkTablesModel::RebuildTreeImpl(std::vector<TreeNode>* tree,
|
|
|
|
|
int category) {
|
|
|
|
|
tree->clear();
|
2021-06-06 16:13:58 -07:00
|
|
|
wpi::SmallVector<std::string_view, 16> parts;
|
2020-09-12 10:55:46 -07:00
|
|
|
for (auto& entry : m_sortedEntries) {
|
2022-10-08 10:01:31 -07:00
|
|
|
if (!IsVisible(static_cast<ShowCategory>(category), entry->persistent,
|
|
|
|
|
entry->retained)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
parts.clear();
|
2022-10-08 10:01:31 -07:00
|
|
|
wpi::split(entry->info.name, parts, '/', -1, false);
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2020-12-28 14:36:30 -08:00
|
|
|
// ignore a raw "/" key
|
|
|
|
|
if (parts.empty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
// get to leaf
|
2022-10-08 10:01:31 -07:00
|
|
|
auto nodes = tree;
|
2022-10-15 16:33:14 -07:00
|
|
|
for (auto part : wpi::drop_back(std::span{parts.begin(), parts.end()})) {
|
2020-09-12 10:55:46 -07:00
|
|
|
auto it =
|
|
|
|
|
std::find_if(nodes->begin(), nodes->end(),
|
|
|
|
|
[&](const auto& node) { return node.name == part; });
|
|
|
|
|
if (it == nodes->end()) {
|
|
|
|
|
nodes->emplace_back(part);
|
|
|
|
|
// path is from the beginning of the string to the end of the current
|
|
|
|
|
// part; this works because part is a reference to the internals of
|
2022-10-08 10:01:31 -07:00
|
|
|
// entry->info.name
|
2021-06-06 16:13:58 -07:00
|
|
|
nodes->back().path.assign(
|
2022-10-08 10:01:31 -07:00
|
|
|
entry->info.name.data(),
|
|
|
|
|
part.data() + part.size() - entry->info.name.data());
|
2020-09-12 10:55:46 -07:00
|
|
|
it = nodes->end() - 1;
|
|
|
|
|
}
|
|
|
|
|
nodes = &it->children;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto it = std::find_if(nodes->begin(), nodes->end(), [&](const auto& node) {
|
|
|
|
|
return node.name == parts.back();
|
|
|
|
|
});
|
|
|
|
|
if (it == nodes->end()) {
|
|
|
|
|
nodes->emplace_back(parts.back());
|
|
|
|
|
// no need to set path, as it's identical to entry->name
|
|
|
|
|
it = nodes->end() - 1;
|
|
|
|
|
}
|
|
|
|
|
it->entry = entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
bool NetworkTablesModel::Exists() {
|
2022-11-20 17:27:28 -08:00
|
|
|
return true;
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetworkTablesModel::Entry* NetworkTablesModel::GetEntry(std::string_view name) {
|
|
|
|
|
auto entryIt = std::lower_bound(
|
|
|
|
|
m_sortedEntries.begin(), m_sortedEntries.end(), name,
|
|
|
|
|
[](auto&& entry, auto&& name) { return entry->info.name < name; });
|
|
|
|
|
if (entryIt == m_sortedEntries.end() || (*entryIt)->info.name != name) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return *entryIt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetworkTablesModel::Entry* NetworkTablesModel::AddEntry(NT_Topic topic) {
|
|
|
|
|
auto& entry = m_entries[topic];
|
|
|
|
|
if (!entry) {
|
|
|
|
|
entry = std::make_unique<Entry>();
|
|
|
|
|
entry->info = nt::GetTopicInfo(topic);
|
|
|
|
|
entry->properties = entry->info.GetProperties();
|
|
|
|
|
m_sortedEntries.emplace_back(entry.get());
|
|
|
|
|
}
|
|
|
|
|
RebuildTree();
|
|
|
|
|
return entry.get();
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-31 12:01:51 -08:00
|
|
|
NetworkTablesModel::Client::Subscriber::Subscriber(
|
|
|
|
|
nt::meta::ClientSubscriber&& oth)
|
|
|
|
|
: ClientSubscriber{std::move(oth)},
|
|
|
|
|
topicsStr{StringArrayToString(topics)} {}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
void NetworkTablesModel::Client::UpdatePublishers(
|
2022-10-15 16:33:14 -07:00
|
|
|
std::span<const uint8_t> data) {
|
2022-12-31 12:01:51 -08:00
|
|
|
if (auto pubs = nt::meta::DecodeClientPublishers(data)) {
|
|
|
|
|
publishers = std::move(*pubs);
|
2022-10-08 10:01:31 -07:00
|
|
|
} else {
|
|
|
|
|
fmt::print(stderr, "Failed to update publishers\n");
|
|
|
|
|
}
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
void NetworkTablesModel::Client::UpdateSubscribers(
|
2022-10-15 16:33:14 -07:00
|
|
|
std::span<const uint8_t> data) {
|
2022-12-31 12:01:51 -08:00
|
|
|
if (auto subs = nt::meta::DecodeClientSubscribers(data)) {
|
|
|
|
|
subscribers.clear();
|
|
|
|
|
subscribers.reserve(subs->size());
|
|
|
|
|
for (auto&& sub : *subs) {
|
|
|
|
|
subscribers.emplace_back(std::move(sub));
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
fmt::print(stderr, "Failed to update subscribers\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-15 16:33:14 -07:00
|
|
|
void NetworkTablesModel::UpdateClients(std::span<const uint8_t> data) {
|
2022-12-31 12:01:51 -08:00
|
|
|
auto clientsArr = nt::meta::DecodeClients(data);
|
|
|
|
|
if (!clientsArr) {
|
2022-10-08 10:01:31 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we need to create a new map so deletions are reflected
|
|
|
|
|
std::map<std::string, Client, std::less<>> newClients;
|
2022-12-31 12:01:51 -08:00
|
|
|
for (auto&& client : *clientsArr) {
|
2022-10-08 10:01:31 -07:00
|
|
|
auto& newClient = newClients[client.id];
|
|
|
|
|
newClient = std::move(client);
|
|
|
|
|
auto it = m_clients.find(newClient.id);
|
|
|
|
|
if (it != m_clients.end()) {
|
|
|
|
|
// transfer from existing
|
|
|
|
|
newClient.publishers = std::move(it->second.publishers);
|
|
|
|
|
newClient.subscribers = std::move(it->second.subscribers);
|
|
|
|
|
} else {
|
|
|
|
|
// initially populate
|
|
|
|
|
if (Entry* entry = GetEntry(fmt::format("$clientpub${}", newClient.id))) {
|
|
|
|
|
if (entry->value.IsRaw() && entry->info.type_str == "msgpack") {
|
|
|
|
|
newClient.UpdatePublishers(entry->value.GetRaw());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (Entry* entry = GetEntry(fmt::format("$clientsub${}", newClient.id))) {
|
|
|
|
|
if (entry->value.IsRaw() && entry->info.type_str == "msgpack") {
|
|
|
|
|
newClient.UpdateSubscribers(entry->value.GetRaw());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// replace map
|
|
|
|
|
m_clients = std::move(newClients);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool StringToBooleanArray(std::string_view in, std::vector<int>* out) {
|
2021-06-06 16:13:58 -07:00
|
|
|
in = wpi::trim(in);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (in.empty()) {
|
2022-10-08 10:01:31 -07:00
|
|
|
return false;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
|
|
|
|
if (in.front() == '[') {
|
2021-06-06 16:13:58 -07:00
|
|
|
in.remove_prefix(1);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
|
|
|
|
if (in.back() == ']') {
|
2021-06-06 16:13:58 -07:00
|
|
|
in.remove_suffix(1);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
in = wpi::trim(in);
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
wpi::SmallVector<std::string_view, 16> inSplit;
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
wpi::split(in, inSplit, ',', -1, false);
|
2020-09-12 10:55:46 -07:00
|
|
|
for (auto val : inSplit) {
|
2021-06-06 16:13:58 -07:00
|
|
|
val = wpi::trim(val);
|
|
|
|
|
if (wpi::equals_lower(val, "true")) {
|
2022-10-08 10:01:31 -07:00
|
|
|
out->emplace_back(1);
|
2021-06-06 16:13:58 -07:00
|
|
|
} else if (wpi::equals_lower(val, "false")) {
|
2022-10-08 10:01:31 -07:00
|
|
|
out->emplace_back(0);
|
2020-09-12 10:55:46 -07:00
|
|
|
} else {
|
2021-06-06 16:13:58 -07:00
|
|
|
fmt::print(stderr,
|
|
|
|
|
"GUI: NetworkTables: Could not understand value '{}'\n", val);
|
2022-10-08 10:01:31 -07:00
|
|
|
return false;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
return true;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static bool StringToIntegerArray(std::string_view in,
|
|
|
|
|
std::vector<int64_t>* out) {
|
2021-06-06 16:13:58 -07:00
|
|
|
in = wpi::trim(in);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (in.empty()) {
|
2022-10-08 10:01:31 -07:00
|
|
|
return false;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
|
|
|
|
if (in.front() == '[') {
|
2021-06-06 16:13:58 -07:00
|
|
|
in.remove_prefix(1);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
|
|
|
|
if (in.back() == ']') {
|
2021-06-06 16:13:58 -07:00
|
|
|
in.remove_suffix(1);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
in = wpi::trim(in);
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
wpi::SmallVector<std::string_view, 16> inSplit;
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
wpi::split(in, inSplit, ',', -1, false);
|
2020-09-12 10:55:46 -07:00
|
|
|
for (auto val : inSplit) {
|
2022-10-08 10:01:31 -07:00
|
|
|
if (auto num = wpi::parse_integer<int64_t>(wpi::trim(val), 0)) {
|
|
|
|
|
out->emplace_back(num.value());
|
2020-09-12 10:55:46 -07:00
|
|
|
} else {
|
2021-06-06 16:13:58 -07:00
|
|
|
fmt::print(stderr,
|
|
|
|
|
"GUI: NetworkTables: Could not understand value '{}'\n", val);
|
2022-10-08 10:01:31 -07:00
|
|
|
return false;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-07 09:50:09 -07:00
|
|
|
template <std::floating_point T>
|
2022-10-08 10:01:31 -07:00
|
|
|
static bool StringToFloatArray(std::string_view in, std::vector<T>* out) {
|
|
|
|
|
in = wpi::trim(in);
|
|
|
|
|
if (in.empty()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (in.front() == '[') {
|
|
|
|
|
in.remove_prefix(1);
|
|
|
|
|
}
|
|
|
|
|
if (in.back() == ']') {
|
|
|
|
|
in.remove_suffix(1);
|
|
|
|
|
}
|
|
|
|
|
in = wpi::trim(in);
|
|
|
|
|
|
|
|
|
|
wpi::SmallVector<std::string_view, 16> inSplit;
|
|
|
|
|
|
|
|
|
|
wpi::split(in, inSplit, ',', -1, false);
|
|
|
|
|
for (auto val : inSplit) {
|
|
|
|
|
if (auto num = wpi::parse_float<T>(wpi::trim(val))) {
|
|
|
|
|
out->emplace_back(num.value());
|
|
|
|
|
} else {
|
|
|
|
|
fmt::print(stderr,
|
|
|
|
|
"GUI: NetworkTables: Could not understand value '{}'\n", val);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static bool StringToStringArray(std::string_view in,
|
|
|
|
|
std::vector<std::string>* out) {
|
2021-06-06 16:13:58 -07:00
|
|
|
in = wpi::trim(in);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (in.empty()) {
|
2022-10-08 10:01:31 -07:00
|
|
|
return false;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
|
|
|
|
if (in.front() == '[') {
|
2021-06-06 16:13:58 -07:00
|
|
|
in.remove_prefix(1);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
|
|
|
|
if (in.back() == ']') {
|
2021-06-06 16:13:58 -07:00
|
|
|
in.remove_suffix(1);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
in = wpi::trim(in);
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2023-02-17 18:01:54 -08:00
|
|
|
while (!in.empty()) {
|
|
|
|
|
if (in.front() != '"') {
|
|
|
|
|
fmt::print(stderr, "GUI: NetworkTables: Expected '\"'");
|
2022-10-08 10:01:31 -07:00
|
|
|
return false;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2023-02-17 18:01:54 -08:00
|
|
|
in.remove_prefix(1);
|
|
|
|
|
wpi::SmallString<128> buf;
|
|
|
|
|
std::string_view val;
|
|
|
|
|
std::tie(val, in) = wpi::UnescapeCString(in, buf);
|
|
|
|
|
out->emplace_back(val);
|
|
|
|
|
if (!in.empty()) {
|
|
|
|
|
if (in.front() != '"') {
|
|
|
|
|
fmt::print(stderr, "GUI: NetworkTables: Error escaping string");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
in.remove_prefix(1);
|
|
|
|
|
in = wpi::ltrim(in);
|
|
|
|
|
}
|
|
|
|
|
if (!in.empty()) {
|
|
|
|
|
if (in.front() != ',') {
|
|
|
|
|
fmt::print(stderr, "GUI: NetworkTables: Expected ','");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
in.remove_prefix(1);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
return true;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static void EmitEntryValueReadonly(const NetworkTablesModel::ValueSource& entry,
|
|
|
|
|
const char* typeStr,
|
2022-06-15 22:21:52 -06:00
|
|
|
NetworkTablesFlags flags) {
|
2020-09-12 10:55:46 -07:00
|
|
|
auto& val = entry.value;
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!val) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
switch (val.type()) {
|
2020-09-12 10:55:46 -07:00
|
|
|
case NT_BOOLEAN:
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "boolean", "%s",
|
|
|
|
|
val.GetBoolean() ? "true" : "false");
|
|
|
|
|
break;
|
|
|
|
|
case NT_INTEGER:
|
|
|
|
|
ImGui::LabelText(typeStr ? typeStr : "int", "%" PRId64, val.GetInteger());
|
|
|
|
|
break;
|
|
|
|
|
case NT_FLOAT:
|
|
|
|
|
ImGui::LabelText(typeStr ? typeStr : "double", "%.6f", val.GetFloat());
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
2022-06-15 22:21:52 -06:00
|
|
|
case NT_DOUBLE: {
|
|
|
|
|
unsigned char precision = (flags & NetworkTablesFlags_Precision) >>
|
|
|
|
|
kNetworkTablesFlags_PrecisionBitShift;
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
|
|
|
|
#endif
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "double",
|
|
|
|
|
fmt::format("%.{}f", precision).c_str(),
|
|
|
|
|
val.GetDouble());
|
2022-06-15 22:21:52 -06:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
#endif
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
2022-06-15 22:21:52 -06:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
case NT_STRING: {
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "string", "%s",
|
2023-02-17 18:01:54 -08:00
|
|
|
entry.valueStr.c_str());
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_BOOLEAN_ARRAY:
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "boolean[]", "%s",
|
|
|
|
|
entry.valueStr.c_str());
|
|
|
|
|
break;
|
|
|
|
|
case NT_INTEGER_ARRAY:
|
|
|
|
|
ImGui::LabelText(typeStr ? typeStr : "int[]", "%s",
|
|
|
|
|
entry.valueStr.c_str());
|
|
|
|
|
break;
|
|
|
|
|
case NT_FLOAT_ARRAY:
|
|
|
|
|
ImGui::LabelText(typeStr ? typeStr : "float[]", "%s",
|
|
|
|
|
entry.valueStr.c_str());
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
case NT_DOUBLE_ARRAY:
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "double[]", "%s",
|
|
|
|
|
entry.valueStr.c_str());
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
case NT_STRING_ARRAY:
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "string[]", "%s",
|
|
|
|
|
entry.valueStr.c_str());
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
case NT_RAW:
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "raw", "[...]");
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
default:
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "other", "?");
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static constexpr size_t kTextBufferSize = 4096;
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
static char* GetTextBuffer(std::string_view in) {
|
2020-09-12 10:55:46 -07:00
|
|
|
static char textBuffer[kTextBufferSize];
|
|
|
|
|
size_t len = (std::min)(in.size(), kTextBufferSize - 1);
|
|
|
|
|
std::memcpy(textBuffer, in.data(), len);
|
|
|
|
|
textBuffer[len] = '\0';
|
|
|
|
|
return textBuffer;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 22:21:52 -06:00
|
|
|
static void EmitEntryValueEditable(NetworkTablesModel::Entry& entry,
|
|
|
|
|
NetworkTablesFlags flags) {
|
2020-09-12 10:55:46 -07:00
|
|
|
auto& val = entry.value;
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!val) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
const char* typeStr =
|
|
|
|
|
entry.info.type_str.empty() ? nullptr : entry.info.type_str.c_str();
|
|
|
|
|
ImGui::PushID(entry.info.name.c_str());
|
|
|
|
|
switch (val.type()) {
|
2020-09-12 10:55:46 -07:00
|
|
|
case NT_BOOLEAN: {
|
|
|
|
|
static const char* boolOptions[] = {"false", "true"};
|
2022-10-08 10:01:31 -07:00
|
|
|
int v = val.GetBoolean() ? 1 : 0;
|
|
|
|
|
if (ImGui::Combo(typeStr ? typeStr : "boolean", &v, boolOptions, 2)) {
|
|
|
|
|
if (entry.publisher == 0) {
|
|
|
|
|
entry.publisher =
|
|
|
|
|
nt::Publish(entry.info.topic, NT_BOOLEAN, "boolean");
|
|
|
|
|
}
|
|
|
|
|
nt::SetBoolean(entry.publisher, v);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_INTEGER: {
|
|
|
|
|
int64_t v = val.GetInteger();
|
|
|
|
|
if (ImGui::InputScalar(typeStr ? typeStr : "int", ImGuiDataType_S64, &v,
|
|
|
|
|
nullptr, nullptr, nullptr,
|
|
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
|
|
|
|
if (entry.publisher == 0) {
|
|
|
|
|
entry.publisher = nt::Publish(entry.info.topic, NT_INTEGER, "int");
|
|
|
|
|
}
|
|
|
|
|
nt::SetInteger(entry.publisher, v);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_FLOAT: {
|
|
|
|
|
float v = val.GetFloat();
|
|
|
|
|
if (ImGui::InputFloat(typeStr ? typeStr : "float", &v, 0, 0, "%.6f",
|
|
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
|
|
|
|
if (entry.publisher == 0) {
|
|
|
|
|
entry.publisher = nt::Publish(entry.info.topic, NT_FLOAT, "float");
|
|
|
|
|
}
|
|
|
|
|
nt::SetFloat(entry.publisher, v);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_DOUBLE: {
|
2022-10-08 10:01:31 -07:00
|
|
|
double v = val.GetDouble();
|
2022-06-15 22:21:52 -06:00
|
|
|
unsigned char precision = (flags & NetworkTablesFlags_Precision) >>
|
|
|
|
|
kNetworkTablesFlags_PrecisionBitShift;
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
|
|
|
|
#endif
|
2022-10-08 10:01:31 -07:00
|
|
|
if (ImGui::InputDouble(typeStr ? typeStr : "double", &v, 0, 0,
|
2022-06-15 22:21:52 -06:00
|
|
|
fmt::format("%.{}f", precision).c_str(),
|
2020-12-28 12:58:06 -08:00
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
2022-10-08 10:01:31 -07:00
|
|
|
if (entry.publisher == 0) {
|
|
|
|
|
entry.publisher = nt::Publish(entry.info.topic, NT_DOUBLE, "double");
|
|
|
|
|
}
|
|
|
|
|
nt::SetDouble(entry.publisher, v);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2022-06-15 22:21:52 -06:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
#endif
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_STRING: {
|
2023-02-17 18:01:54 -08:00
|
|
|
char* v = GetTextBuffer(entry.valueStr);
|
2022-10-08 10:01:31 -07:00
|
|
|
if (ImGui::InputText(typeStr ? typeStr : "string", v, kTextBufferSize,
|
2020-12-28 12:58:06 -08:00
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
2023-02-17 18:01:54 -08:00
|
|
|
if (v[0] == '"') {
|
|
|
|
|
if (entry.publisher == 0) {
|
|
|
|
|
entry.publisher =
|
|
|
|
|
nt::Publish(entry.info.topic, NT_STRING, "string");
|
|
|
|
|
}
|
|
|
|
|
wpi::SmallString<128> buf;
|
|
|
|
|
nt::SetString(entry.publisher,
|
|
|
|
|
wpi::UnescapeCString(v + 1, buf).first);
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_BOOLEAN_ARRAY: {
|
|
|
|
|
char* v = GetTextBuffer(entry.valueStr);
|
2022-10-08 10:01:31 -07:00
|
|
|
if (ImGui::InputText(typeStr ? typeStr : "boolean[]", v, kTextBufferSize,
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
2022-10-08 10:01:31 -07:00
|
|
|
std::vector<int> outv;
|
|
|
|
|
if (StringToBooleanArray(v, &outv)) {
|
|
|
|
|
if (entry.publisher == 0) {
|
|
|
|
|
entry.publisher =
|
|
|
|
|
nt::Publish(entry.info.topic, NT_BOOLEAN_ARRAY, "boolean[]");
|
|
|
|
|
}
|
|
|
|
|
nt::SetBooleanArray(entry.publisher, outv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_INTEGER_ARRAY: {
|
|
|
|
|
char* v = GetTextBuffer(entry.valueStr);
|
|
|
|
|
if (ImGui::InputText(typeStr ? typeStr : "int[]", v, kTextBufferSize,
|
|
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
|
|
|
|
std::vector<int64_t> outv;
|
|
|
|
|
if (StringToIntegerArray(v, &outv)) {
|
|
|
|
|
if (entry.publisher == 0) {
|
|
|
|
|
entry.publisher =
|
|
|
|
|
nt::Publish(entry.info.topic, NT_INTEGER_ARRAY, "int[]");
|
|
|
|
|
}
|
|
|
|
|
nt::SetIntegerArray(entry.publisher, outv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_FLOAT_ARRAY: {
|
|
|
|
|
char* v = GetTextBuffer(entry.valueStr);
|
|
|
|
|
if (ImGui::InputText(typeStr ? typeStr : "float[]", v, kTextBufferSize,
|
|
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
|
|
|
|
std::vector<float> outv;
|
|
|
|
|
if (StringToFloatArray(v, &outv)) {
|
|
|
|
|
if (entry.publisher == 0) {
|
|
|
|
|
entry.publisher =
|
|
|
|
|
nt::Publish(entry.info.topic, NT_DOUBLE_ARRAY, "float[]");
|
|
|
|
|
}
|
|
|
|
|
nt::SetFloatArray(entry.publisher, outv);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_DOUBLE_ARRAY: {
|
|
|
|
|
char* v = GetTextBuffer(entry.valueStr);
|
2022-10-08 10:01:31 -07:00
|
|
|
if (ImGui::InputText(typeStr ? typeStr : "double[]", v, kTextBufferSize,
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
2022-10-08 10:01:31 -07:00
|
|
|
std::vector<double> outv;
|
|
|
|
|
if (StringToFloatArray(v, &outv)) {
|
|
|
|
|
if (entry.publisher == 0) {
|
|
|
|
|
entry.publisher =
|
|
|
|
|
nt::Publish(entry.info.topic, NT_DOUBLE_ARRAY, "double[]");
|
|
|
|
|
}
|
|
|
|
|
nt::SetDoubleArray(entry.publisher, outv);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_STRING_ARRAY: {
|
|
|
|
|
char* v = GetTextBuffer(entry.valueStr);
|
2022-10-08 10:01:31 -07:00
|
|
|
if (ImGui::InputText(typeStr ? typeStr : "string[]", v, kTextBufferSize,
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
2022-10-08 10:01:31 -07:00
|
|
|
std::vector<std::string> outv;
|
|
|
|
|
if (StringToStringArray(v, &outv)) {
|
|
|
|
|
if (entry.publisher == 0) {
|
|
|
|
|
entry.publisher =
|
|
|
|
|
nt::Publish(entry.info.topic, NT_STRING_ARRAY, "string[]");
|
|
|
|
|
}
|
|
|
|
|
nt::SetStringArray(entry.publisher, outv);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_RAW:
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "raw",
|
|
|
|
|
val.GetRaw().empty() ? "[]" : "[...]");
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
case NT_RPC:
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "rpc", "[...]");
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
default:
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::LabelText(typeStr ? typeStr : "other", "?");
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
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(nt::GetTopic(model->GetInstance().GetHandle(), path));
|
|
|
|
|
if (entry->publisher == 0) {
|
|
|
|
|
entry->publisher = nt::Publish(entry->info.topic, type, typeStr);
|
2023-02-17 16:45:38 -08:00
|
|
|
// publish a default value so it's editable
|
|
|
|
|
switch (type) {
|
|
|
|
|
case NT_BOOLEAN:
|
|
|
|
|
nt::SetDefaultBoolean(entry->publisher, false);
|
|
|
|
|
break;
|
|
|
|
|
case NT_INTEGER:
|
|
|
|
|
nt::SetDefaultInteger(entry->publisher, 0);
|
|
|
|
|
break;
|
|
|
|
|
case NT_FLOAT:
|
|
|
|
|
nt::SetDefaultFloat(entry->publisher, 0.0);
|
|
|
|
|
break;
|
|
|
|
|
case NT_DOUBLE:
|
|
|
|
|
nt::SetDefaultDouble(entry->publisher, 0.0);
|
|
|
|
|
break;
|
|
|
|
|
case NT_STRING:
|
|
|
|
|
nt::SetDefaultString(entry->publisher, "");
|
|
|
|
|
break;
|
|
|
|
|
case NT_BOOLEAN_ARRAY:
|
|
|
|
|
nt::SetDefaultBooleanArray(entry->publisher, {});
|
|
|
|
|
break;
|
|
|
|
|
case NT_INTEGER_ARRAY:
|
|
|
|
|
nt::SetDefaultIntegerArray(entry->publisher, {});
|
|
|
|
|
break;
|
|
|
|
|
case NT_FLOAT_ARRAY:
|
|
|
|
|
nt::SetDefaultFloatArray(entry->publisher, {});
|
|
|
|
|
break;
|
|
|
|
|
case NT_DOUBLE_ARRAY:
|
|
|
|
|
nt::SetDefaultDoubleArray(entry->publisher, {});
|
|
|
|
|
break;
|
|
|
|
|
case NT_STRING_ARRAY:
|
|
|
|
|
nt::SetDefaultStringArray(entry->publisher, {});
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-17 16:46:02 -08:00
|
|
|
void glass::DisplayNetworkTablesAddMenu(NetworkTablesModel* model,
|
|
|
|
|
std::string_view path,
|
|
|
|
|
NetworkTablesFlags flags) {
|
|
|
|
|
static char nameBuffer[kTextBufferSize];
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginMenu("Add new...")) {
|
|
|
|
|
if (ImGui::IsWindowAppearing()) {
|
|
|
|
|
nameBuffer[0] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::InputTextWithHint("New item name", "example", nameBuffer,
|
|
|
|
|
kTextBufferSize);
|
|
|
|
|
std::string fullNewPath;
|
|
|
|
|
if (path == "/") {
|
|
|
|
|
path = "";
|
|
|
|
|
}
|
|
|
|
|
fullNewPath = fmt::format("{}/{}", path, nameBuffer);
|
|
|
|
|
|
|
|
|
|
ImGui::Text("Adding: %s", fullNewPath.c_str());
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
auto entry = model->GetEntry(fullNewPath);
|
|
|
|
|
bool exists = entry && entry->info.type != NT_Type::NT_UNASSIGNED;
|
|
|
|
|
bool enabled = (flags & NetworkTablesFlags_CreateNoncanonicalKeys ||
|
|
|
|
|
nameBuffer[0] != '\0') &&
|
|
|
|
|
!exists;
|
|
|
|
|
|
|
|
|
|
CreateTopicMenuItem(model, fullNewPath, NT_STRING, "string", enabled);
|
|
|
|
|
CreateTopicMenuItem(model, fullNewPath, NT_INTEGER, "int", enabled);
|
|
|
|
|
CreateTopicMenuItem(model, fullNewPath, NT_FLOAT, "float", enabled);
|
|
|
|
|
CreateTopicMenuItem(model, fullNewPath, NT_DOUBLE, "double", enabled);
|
|
|
|
|
CreateTopicMenuItem(model, fullNewPath, NT_BOOLEAN, "boolean", enabled);
|
|
|
|
|
CreateTopicMenuItem(model, fullNewPath, NT_STRING_ARRAY, "string[]",
|
|
|
|
|
enabled);
|
|
|
|
|
CreateTopicMenuItem(model, fullNewPath, NT_INTEGER_ARRAY, "int[]", enabled);
|
|
|
|
|
CreateTopicMenuItem(model, fullNewPath, NT_FLOAT_ARRAY, "float[]", enabled);
|
|
|
|
|
CreateTopicMenuItem(model, fullNewPath, NT_DOUBLE_ARRAY, "double[]",
|
|
|
|
|
enabled);
|
|
|
|
|
CreateTopicMenuItem(model, fullNewPath, NT_BOOLEAN_ARRAY, "boolean[]",
|
|
|
|
|
enabled);
|
|
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static void EmitParentContextMenu(NetworkTablesModel* model,
|
|
|
|
|
const std::string& path,
|
2020-12-29 20:49:29 -08:00
|
|
|
NetworkTablesFlags flags) {
|
2020-12-30 22:43:35 -08:00
|
|
|
if (ImGui::BeginPopupContextItem(path.c_str())) {
|
2020-12-29 20:49:29 -08:00
|
|
|
ImGui::Text("%s", path.c_str());
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
2023-02-17 16:46:02 -08:00
|
|
|
DisplayNetworkTablesAddMenu(model, path, flags);
|
2020-12-29 20:49:29 -08:00
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
2020-12-29 20:49:29 -08:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static void EmitValueName(DataSource* source, const char* name,
|
|
|
|
|
const char* path) {
|
|
|
|
|
if (source) {
|
|
|
|
|
ImGui::Selectable(name);
|
|
|
|
|
source->EmitDrag();
|
|
|
|
|
} else {
|
|
|
|
|
ImGui::TextUnformatted(name);
|
2020-12-29 20:49:29 -08:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
if (ImGui::BeginPopupContextItem(path)) {
|
|
|
|
|
ImGui::TextUnformatted(path);
|
2020-12-29 20:49:29 -08:00
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static void EmitValueTree(
|
|
|
|
|
const std::vector<NetworkTablesModel::EntryValueTreeNode>& children,
|
|
|
|
|
NetworkTablesFlags flags) {
|
|
|
|
|
for (auto&& child : children) {
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
EmitValueName(child.source.get(), child.name.c_str(), child.path.c_str());
|
2023-09-17 20:00:16 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
if (!child.valueChildren.empty()) {
|
|
|
|
|
char label[64];
|
2023-09-17 20:00:16 -07:00
|
|
|
if (child.valueChildrenMap) {
|
|
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "{{...}}##v_{}",
|
|
|
|
|
child.name);
|
|
|
|
|
} else {
|
|
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "[...]##v_{}", child.name);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
if (TreeNodeEx(label, ImGuiTreeNodeFlags_SpanFullWidth)) {
|
|
|
|
|
EmitValueTree(child.valueChildren, flags);
|
|
|
|
|
TreePop();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
EmitEntryValueReadonly(child, nullptr, flags);
|
2020-12-29 20:49:29 -08:00
|
|
|
}
|
|
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static void EmitEntry(NetworkTablesModel* model,
|
|
|
|
|
NetworkTablesModel::Entry& entry, const char* name,
|
|
|
|
|
NetworkTablesFlags flags, ShowCategory category) {
|
|
|
|
|
if (!IsVisible(category, entry.persistent, entry.retained)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool valueChildrenOpen = false;
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
EmitValueName(entry.source.get(), name, entry.info.name.c_str());
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
if (!entry.valueChildren.empty()) {
|
|
|
|
|
auto pos = ImGui::GetCursorPos();
|
2023-09-17 20:00:16 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
char label[64];
|
2023-09-17 20:00:16 -07:00
|
|
|
if (entry.valueChildrenMap) {
|
|
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "{{...}}##v_{}",
|
|
|
|
|
entry.info.name.c_str());
|
|
|
|
|
} else {
|
|
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "[...]##v_{}",
|
|
|
|
|
entry.info.name.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
valueChildrenOpen =
|
|
|
|
|
TreeNodeEx(label, ImGuiTreeNodeFlags_SpanFullWidth |
|
|
|
|
|
ImGuiTreeNodeFlags_AllowItemOverlap);
|
|
|
|
|
// make it look like a normal label w/type
|
|
|
|
|
ImGui::SetCursorPos(pos);
|
|
|
|
|
ImGui::LabelText(entry.info.type_str.c_str(), "%s", "");
|
|
|
|
|
} else if (flags & NetworkTablesFlags_ReadOnly) {
|
|
|
|
|
EmitEntryValueReadonly(
|
|
|
|
|
entry,
|
|
|
|
|
entry.info.type_str.empty() ? nullptr : entry.info.type_str.c_str(),
|
|
|
|
|
flags);
|
2020-12-28 12:58:06 -08:00
|
|
|
} else {
|
2022-06-15 22:21:52 -06:00
|
|
|
EmitEntryValueEditable(entry, flags);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
if (flags & NetworkTablesFlags_ShowProperties) {
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("%s", entry.info.properties.c_str());
|
|
|
|
|
if (ImGui::BeginPopupContextItem(entry.info.name.c_str())) {
|
|
|
|
|
if (ImGui::Checkbox("persistent", &entry.persistent)) {
|
|
|
|
|
nt::SetTopicPersistent(entry.info.topic, entry.persistent);
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::Checkbox("retained", &entry.retained)) {
|
|
|
|
|
if (entry.retained) {
|
|
|
|
|
nt::SetTopicProperty(entry.info.topic, "retained", true);
|
|
|
|
|
} else {
|
|
|
|
|
nt::DeleteTopicProperty(entry.info.topic, "retained");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags & NetworkTablesFlags_ShowTimestamp) {
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::TableNextColumn();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (entry.value) {
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::Text("%f", (entry.value.last_change() * 1.0e-6) -
|
2020-12-17 07:29:00 -08:00
|
|
|
(GetZeroTime() * 1.0e-6));
|
2020-12-28 12:58:06 -08:00
|
|
|
} else {
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::TextUnformatted("");
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
|
|
|
|
|
if (flags & NetworkTablesFlags_ShowServerTimestamp) {
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
if (entry.value && entry.value.server_time() != 0) {
|
|
|
|
|
if (entry.value.server_time() == 1) {
|
|
|
|
|
ImGui::TextUnformatted("---");
|
|
|
|
|
} else {
|
|
|
|
|
ImGui::Text("%f", entry.value.server_time() * 1.0e-6);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ImGui::TextUnformatted("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (valueChildrenOpen) {
|
|
|
|
|
EmitValueTree(entry.valueChildren, flags);
|
|
|
|
|
TreePop();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static void EmitTree(NetworkTablesModel* model,
|
|
|
|
|
const std::vector<NetworkTablesModel::TreeNode>& tree,
|
|
|
|
|
NetworkTablesFlags flags, ShowCategory category,
|
|
|
|
|
bool root) {
|
2020-09-12 10:55:46 -07:00
|
|
|
for (auto&& node : tree) {
|
2022-10-08 10:01:31 -07:00
|
|
|
if (root && (flags & NetworkTablesFlags_ShowSpecial) == 0 &&
|
|
|
|
|
wpi::starts_with(node.name, '$')) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
if (node.entry) {
|
2022-10-08 10:01:31 -07:00
|
|
|
EmitEntry(model, *node.entry, node.name.c_str(), flags, category);
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!node.children.empty()) {
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
2020-09-12 10:55:46 -07:00
|
|
|
bool open =
|
|
|
|
|
TreeNodeEx(node.name.c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
|
2022-10-08 10:01:31 -07:00
|
|
|
EmitParentContextMenu(model, node.path, flags);
|
2020-09-12 10:55:46 -07:00
|
|
|
if (open) {
|
2022-10-08 10:01:31 -07:00
|
|
|
EmitTree(model, node.children, flags, category, false);
|
2020-09-12 10:55:46 -07:00
|
|
|
TreePop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static void DisplayTable(NetworkTablesModel* model,
|
|
|
|
|
const std::vector<NetworkTablesModel::TreeNode>& tree,
|
|
|
|
|
NetworkTablesFlags flags, ShowCategory category) {
|
|
|
|
|
if (tree.empty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
const bool showProperties = (flags & NetworkTablesFlags_ShowProperties);
|
|
|
|
|
const bool showTimestamp = (flags & NetworkTablesFlags_ShowTimestamp);
|
|
|
|
|
const bool showServerTimestamp =
|
|
|
|
|
(flags & NetworkTablesFlags_ShowServerTimestamp);
|
|
|
|
|
|
|
|
|
|
ImGui::BeginTable("values",
|
|
|
|
|
2 + (showProperties ? 1 : 0) + (showTimestamp ? 1 : 0) +
|
|
|
|
|
(showServerTimestamp ? 1 : 0),
|
|
|
|
|
ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingFixedFit |
|
|
|
|
|
ImGuiTableFlags_BordersInner);
|
|
|
|
|
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed,
|
|
|
|
|
0.35f * ImGui::GetWindowWidth());
|
|
|
|
|
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_WidthFixed,
|
|
|
|
|
12 * ImGui::GetFontSize());
|
|
|
|
|
if (showProperties) {
|
|
|
|
|
ImGui::TableSetupColumn("Properties", ImGuiTableColumnFlags_WidthFixed,
|
|
|
|
|
12 * ImGui::GetFontSize());
|
|
|
|
|
}
|
|
|
|
|
if (showTimestamp) {
|
|
|
|
|
ImGui::TableSetupColumn("Time");
|
|
|
|
|
}
|
|
|
|
|
if (showServerTimestamp) {
|
|
|
|
|
ImGui::TableSetupColumn("Server Time");
|
|
|
|
|
}
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
|
|
if (flags & NetworkTablesFlags_TreeView) {
|
|
|
|
|
switch (category) {
|
|
|
|
|
case ShowPersistent:
|
|
|
|
|
PushID("persistent");
|
|
|
|
|
break;
|
|
|
|
|
case ShowRetained:
|
|
|
|
|
PushID("retained");
|
|
|
|
|
break;
|
|
|
|
|
case ShowTransitory:
|
|
|
|
|
PushID("transitory");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
EmitTree(model, tree, flags, category, true);
|
|
|
|
|
if (category != ShowAll) {
|
|
|
|
|
PopID();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (auto entry : model->GetEntries()) {
|
|
|
|
|
if ((flags & NetworkTablesFlags_ShowSpecial) != 0 ||
|
|
|
|
|
!wpi::starts_with(entry->info.name, '$')) {
|
|
|
|
|
EmitEntry(model, *entry, entry->info.name.c_str(), flags, category);
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
static void DisplayClient(const NetworkTablesModel::Client& client) {
|
|
|
|
|
if (CollapsingHeader("Publishers")) {
|
|
|
|
|
ImGui::BeginTable("publishers", 2, ImGuiTableFlags_Resizable);
|
|
|
|
|
ImGui::TableSetupColumn("UID", ImGuiTableColumnFlags_WidthFixed,
|
|
|
|
|
10 * ImGui::GetFontSize());
|
|
|
|
|
ImGui::TableSetupColumn("Topic");
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
for (auto&& pub : client.publishers) {
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("%" PRId64, pub.uid);
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("%s", pub.topic.c_str());
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::EndTable();
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
if (CollapsingHeader("Subscribers")) {
|
|
|
|
|
ImGui::BeginTable(
|
|
|
|
|
"subscribers", 6,
|
|
|
|
|
ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingStretchProp);
|
|
|
|
|
ImGui::TableSetupColumn("UID", ImGuiTableColumnFlags_WidthFixed,
|
|
|
|
|
10 * ImGui::GetFontSize());
|
|
|
|
|
ImGui::TableSetupColumn("Topics", ImGuiTableColumnFlags_WidthStretch, 6.0f);
|
|
|
|
|
ImGui::TableSetupColumn("Periodic", ImGuiTableColumnFlags_WidthStretch,
|
|
|
|
|
1.0f);
|
2022-11-26 17:01:40 -08:00
|
|
|
ImGui::TableSetupColumn("Topics Only", ImGuiTableColumnFlags_WidthStretch,
|
2022-10-08 10:01:31 -07:00
|
|
|
1.0f);
|
|
|
|
|
ImGui::TableSetupColumn("Send All", ImGuiTableColumnFlags_WidthStretch,
|
|
|
|
|
1.0f);
|
|
|
|
|
ImGui::TableSetupColumn("Prefix Match", ImGuiTableColumnFlags_WidthStretch,
|
|
|
|
|
1.0f);
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
for (auto&& sub : client.subscribers) {
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("%" PRId64, sub.uid);
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("%s", sub.topicsStr.c_str());
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("%0.3f", sub.options.periodic);
|
|
|
|
|
ImGui::TableNextColumn();
|
2022-11-26 17:01:40 -08:00
|
|
|
ImGui::Text(sub.options.topicsOnly ? "Yes" : "No");
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text(sub.options.sendAll ? "Yes" : "No");
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text(sub.options.prefixMatch ? "Yes" : "No");
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
void glass::DisplayNetworkTablesInfo(NetworkTablesModel* model) {
|
|
|
|
|
auto inst = model->GetInstance();
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
if (CollapsingHeader("Connections")) {
|
|
|
|
|
ImGui::BeginTable("connections", 4, ImGuiTableFlags_Resizable);
|
|
|
|
|
ImGui::TableSetupColumn("Id");
|
|
|
|
|
ImGui::TableSetupColumn("Address");
|
|
|
|
|
ImGui::TableSetupColumn("Updated");
|
|
|
|
|
ImGui::TableSetupColumn("Proto");
|
|
|
|
|
ImGui::TableSetupScrollFreeze(1, 0);
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
for (auto&& i : inst.GetConnections()) {
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("%s", i.remote_id.c_str());
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("%s", i.remote_ip.c_str());
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("%llu",
|
|
|
|
|
static_cast<unsigned long long>( // NOLINT(runtime/int)
|
|
|
|
|
i.last_update));
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("%d.%d", i.protocol_version >> 8, i.protocol_version & 0xff);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::EndTable();
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
|
|
|
|
|
auto netMode = inst.GetNetworkMode();
|
|
|
|
|
if (netMode == NT_NET_MODE_SERVER || netMode == NT_NET_MODE_CLIENT4) {
|
|
|
|
|
if (CollapsingHeader("Server")) {
|
|
|
|
|
PushID("Server");
|
|
|
|
|
ImGui::Indent();
|
|
|
|
|
DisplayClient(model->GetServer());
|
|
|
|
|
ImGui::Unindent();
|
|
|
|
|
PopID();
|
|
|
|
|
}
|
|
|
|
|
if (CollapsingHeader("Clients")) {
|
|
|
|
|
ImGui::Indent();
|
|
|
|
|
for (auto&& client : model->GetClients()) {
|
|
|
|
|
if (CollapsingHeader(client.second.id.c_str())) {
|
|
|
|
|
PushID(client.second.id.c_str());
|
|
|
|
|
ImGui::Indent();
|
2022-12-31 12:01:51 -08:00
|
|
|
ImGui::Text("%s (version %u.%u)", client.second.conn.c_str(),
|
|
|
|
|
client.second.version >> 8, client.second.version & 0xff);
|
2022-10-08 10:01:31 -07:00
|
|
|
DisplayClient(client.second);
|
|
|
|
|
ImGui::Unindent();
|
|
|
|
|
PopID();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::Unindent();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
void glass::DisplayNetworkTables(NetworkTablesModel* model,
|
|
|
|
|
NetworkTablesFlags flags) {
|
|
|
|
|
if (flags & NetworkTablesFlags_CombinedView) {
|
|
|
|
|
DisplayTable(model, model->GetTreeRoot(), flags, ShowAll);
|
2020-09-12 10:55:46 -07:00
|
|
|
} else {
|
2022-10-08 10:01:31 -07:00
|
|
|
if (CollapsingHeader("Persistent Values", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
DisplayTable(model, model->GetPersistentTreeRoot(), flags,
|
|
|
|
|
ShowPersistent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CollapsingHeader("Retained Values", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
DisplayTable(model, model->GetRetainedTreeRoot(), flags, ShowRetained);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CollapsingHeader("Transitory Values", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
DisplayTable(model, model->GetTransitoryTreeRoot(), flags,
|
|
|
|
|
ShowTransitory);
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-16 22:05:41 -07:00
|
|
|
void NetworkTablesFlagsSettings::Update() {
|
|
|
|
|
if (!m_pTreeView) {
|
|
|
|
|
auto& storage = GetStorage();
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
m_pTreeView =
|
|
|
|
|
&storage.GetBool("tree", m_defaultFlags & NetworkTablesFlags_TreeView);
|
2022-10-08 10:01:31 -07:00
|
|
|
m_pCombinedView = &storage.GetBool(
|
|
|
|
|
"combined", m_defaultFlags & NetworkTablesFlags_CombinedView);
|
|
|
|
|
m_pShowSpecial = &storage.GetBool(
|
|
|
|
|
"special", m_defaultFlags & NetworkTablesFlags_ShowSpecial);
|
|
|
|
|
m_pShowProperties = &storage.GetBool(
|
|
|
|
|
"properties", m_defaultFlags & NetworkTablesFlags_ShowProperties);
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
m_pShowTimestamp = &storage.GetBool(
|
2021-03-16 22:05:41 -07:00
|
|
|
"timestamp", m_defaultFlags & NetworkTablesFlags_ShowTimestamp);
|
2022-10-08 10:01:31 -07:00
|
|
|
m_pShowServerTimestamp = &storage.GetBool(
|
|
|
|
|
"serverTimestamp",
|
|
|
|
|
m_defaultFlags & NetworkTablesFlags_ShowServerTimestamp);
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
m_pCreateNoncanonicalKeys = &storage.GetBool(
|
2021-03-16 22:05:41 -07:00
|
|
|
"createNonCanonical",
|
|
|
|
|
m_defaultFlags & NetworkTablesFlags_CreateNoncanonicalKeys);
|
2022-06-15 22:21:52 -06:00
|
|
|
m_pPrecision = &storage.GetInt(
|
|
|
|
|
"precision", (m_defaultFlags & NetworkTablesFlags_Precision) >>
|
|
|
|
|
kNetworkTablesFlags_PrecisionBitShift);
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2022-06-15 22:21:52 -06:00
|
|
|
m_flags &= ~(
|
2022-10-08 10:01:31 -07:00
|
|
|
NetworkTablesFlags_TreeView | NetworkTablesFlags_CombinedView |
|
|
|
|
|
NetworkTablesFlags_ShowSpecial | NetworkTablesFlags_ShowProperties |
|
|
|
|
|
NetworkTablesFlags_ShowTimestamp |
|
|
|
|
|
NetworkTablesFlags_ShowServerTimestamp |
|
2022-06-15 22:21:52 -06:00
|
|
|
NetworkTablesFlags_CreateNoncanonicalKeys | NetworkTablesFlags_Precision);
|
2020-12-29 20:49:29 -08:00
|
|
|
m_flags |=
|
2021-03-16 22:05:41 -07:00
|
|
|
(*m_pTreeView ? NetworkTablesFlags_TreeView : 0) |
|
2022-10-08 10:01:31 -07:00
|
|
|
(*m_pCombinedView ? NetworkTablesFlags_CombinedView : 0) |
|
|
|
|
|
(*m_pShowSpecial ? NetworkTablesFlags_ShowSpecial : 0) |
|
|
|
|
|
(*m_pShowProperties ? NetworkTablesFlags_ShowProperties : 0) |
|
2021-03-16 22:05:41 -07:00
|
|
|
(*m_pShowTimestamp ? NetworkTablesFlags_ShowTimestamp : 0) |
|
2022-10-08 10:01:31 -07:00
|
|
|
(*m_pShowServerTimestamp ? NetworkTablesFlags_ShowServerTimestamp : 0) |
|
2021-03-16 22:05:41 -07:00
|
|
|
(*m_pCreateNoncanonicalKeys ? NetworkTablesFlags_CreateNoncanonicalKeys
|
2022-06-15 22:21:52 -06:00
|
|
|
: 0) |
|
|
|
|
|
(*m_pPrecision << kNetworkTablesFlags_PrecisionBitShift);
|
2021-03-16 22:05:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkTablesFlagsSettings::DisplayMenu() {
|
|
|
|
|
if (!m_pTreeView) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ImGui::MenuItem("Tree View", "", m_pTreeView);
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::MenuItem("Combined View", "", m_pCombinedView);
|
|
|
|
|
ImGui::MenuItem("Show Special", "", m_pShowSpecial);
|
|
|
|
|
ImGui::MenuItem("Show Properties", "", m_pShowProperties);
|
2021-03-16 22:05:41 -07:00
|
|
|
ImGui::MenuItem("Show Timestamp", "", m_pShowTimestamp);
|
2022-10-08 10:01:31 -07:00
|
|
|
ImGui::MenuItem("Show Server Timestamp", "", m_pShowServerTimestamp);
|
2022-06-15 22:21:52 -06:00
|
|
|
if (ImGui::BeginMenu("Decimal Precision")) {
|
|
|
|
|
static const char* precisionOptions[] = {"1", "2", "3", "4", "5",
|
|
|
|
|
"6", "7", "8", "9", "10"};
|
|
|
|
|
for (int i = 1; i <= 10; i++) {
|
|
|
|
|
if (ImGui::MenuItem(precisionOptions[i - 1], nullptr,
|
|
|
|
|
i == *m_pPrecision)) {
|
|
|
|
|
*m_pPrecision = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
2021-03-16 22:05:41 -07:00
|
|
|
ImGui::Separator();
|
|
|
|
|
ImGui::MenuItem("Allow creation of non-canonical keys", "",
|
|
|
|
|
m_pCreateNoncanonicalKeys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkTablesView::Display() {
|
|
|
|
|
m_flags.Update();
|
|
|
|
|
DisplayNetworkTables(m_model, m_flags.GetFlags());
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2023-01-01 21:05:09 -07:00
|
|
|
|
|
|
|
|
void NetworkTablesView::Settings() {
|
|
|
|
|
m_flags.DisplayMenu();
|
2023-02-17 16:46:02 -08:00
|
|
|
DisplayNetworkTablesAddMenu(m_model, {}, m_flags.GetFlags());
|
2023-01-01 21:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NetworkTablesView::HasSettings() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|