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"
|
|
|
|
|
|
2020-12-26 14:31:24 -08:00
|
|
|
#include <networktables/NetworkTableValue.h>
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <cinttypes>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <initializer_list>
|
|
|
|
|
#include <memory>
|
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>
|
|
|
|
|
#include <ntcore_cpp.h>
|
|
|
|
|
#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>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <wpi/raw_ostream.h>
|
2021-06-06 19:51:14 -07:00
|
|
|
#include <wpi/span.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
2021-06-06 19:51:14 -07:00
|
|
|
static std::string BooleanArrayToString(wpi::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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 19:51:14 -07:00
|
|
|
static std::string DoubleArrayToString(wpi::span<const double> in) {
|
2021-06-06 16:13:58 -07:00
|
|
|
return fmt::format("[{:.6f}]", fmt::join(in, ","));
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 19:51:14 -07:00
|
|
|
static std::string StringArrayToString(wpi::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()
|
|
|
|
|
: NetworkTablesModel{nt::GetDefaultInstance()} {}
|
|
|
|
|
|
|
|
|
|
NetworkTablesModel::NetworkTablesModel(NT_Inst inst)
|
|
|
|
|
: m_inst{inst}, m_poller{nt::CreateEntryListenerPoller(inst)} {
|
|
|
|
|
nt::AddPolledEntryListener(m_poller, "",
|
|
|
|
|
NT_NOTIFY_LOCAL | NT_NOTIFY_NEW |
|
|
|
|
|
NT_NOTIFY_UPDATE | NT_NOTIFY_DELETE |
|
|
|
|
|
NT_NOTIFY_FLAGS | NT_NOTIFY_IMMEDIATE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetworkTablesModel::~NetworkTablesModel() {
|
|
|
|
|
nt::DestroyEntryListenerPoller(m_poller);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetworkTablesModel::Entry::Entry(nt::EntryNotification&& event)
|
|
|
|
|
: entry{event.entry},
|
|
|
|
|
name{std::move(event.name)},
|
|
|
|
|
value{std::move(event.value)},
|
|
|
|
|
flags{nt::GetEntryFlags(event.entry)} {
|
|
|
|
|
UpdateValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkTablesModel::Entry::UpdateValue() {
|
|
|
|
|
switch (value->type()) {
|
|
|
|
|
case NT_BOOLEAN:
|
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
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
source->SetValue(value->GetBoolean() ? 1 : 0);
|
|
|
|
|
source->SetDigital(true);
|
|
|
|
|
break;
|
|
|
|
|
case NT_DOUBLE:
|
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
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
source->SetValue(value->GetDouble());
|
|
|
|
|
source->SetDigital(false);
|
|
|
|
|
break;
|
|
|
|
|
case NT_BOOLEAN_ARRAY:
|
|
|
|
|
valueStr = BooleanArrayToString(value->GetBooleanArray());
|
|
|
|
|
break;
|
|
|
|
|
case NT_DOUBLE_ARRAY:
|
|
|
|
|
valueStr = DoubleArrayToString(value->GetDoubleArray());
|
|
|
|
|
break;
|
|
|
|
|
case NT_STRING_ARRAY:
|
|
|
|
|
valueStr = StringArrayToString(value->GetStringArray());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkTablesModel::Update() {
|
|
|
|
|
bool timedOut = false;
|
|
|
|
|
bool updateTree = false;
|
|
|
|
|
for (auto&& event : nt::PollEntryListener(m_poller, 0, &timedOut)) {
|
|
|
|
|
auto& entry = m_entries[event.entry];
|
|
|
|
|
if (event.flags & NT_NOTIFY_NEW) {
|
|
|
|
|
if (!entry) {
|
|
|
|
|
entry = std::make_unique<Entry>(std::move(event));
|
|
|
|
|
m_sortedEntries.emplace_back(entry.get());
|
|
|
|
|
updateTree = true;
|
2020-12-28 13:02:24 -08:00
|
|
|
continue;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!entry) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
if (event.flags & NT_NOTIFY_DELETE) {
|
|
|
|
|
auto it = std::find(m_sortedEntries.begin(), m_sortedEntries.end(),
|
|
|
|
|
entry.get());
|
|
|
|
|
// will be removed completely below
|
2020-12-28 12:58:06 -08:00
|
|
|
if (it != m_sortedEntries.end()) {
|
|
|
|
|
*it = nullptr;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
m_entries.erase(event.entry);
|
|
|
|
|
updateTree = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (event.flags & NT_NOTIFY_UPDATE) {
|
|
|
|
|
entry->value = std::move(event.value);
|
|
|
|
|
entry->UpdateValue();
|
|
|
|
|
}
|
|
|
|
|
if (event.flags & NT_NOTIFY_FLAGS) {
|
|
|
|
|
entry->flags = nt::GetEntryFlags(event.entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
m_sortedEntries.erase(
|
|
|
|
|
std::remove(m_sortedEntries.begin(), m_sortedEntries.end(), nullptr),
|
|
|
|
|
m_sortedEntries.end());
|
|
|
|
|
|
|
|
|
|
// sort by name
|
|
|
|
|
std::sort(m_sortedEntries.begin(), m_sortedEntries.end(),
|
|
|
|
|
[](const auto& a, const auto& b) { return a->name < b->name; });
|
|
|
|
|
|
|
|
|
|
// rebuild tree
|
|
|
|
|
m_root.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) {
|
|
|
|
|
parts.clear();
|
2021-06-06 16:13:58 -07:00
|
|
|
wpi::split(entry->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
|
|
|
|
|
auto nodes = &m_root;
|
2021-06-06 19:51:14 -07:00
|
|
|
for (auto part : wpi::drop_back(wpi::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
|
|
|
|
|
// entry->name
|
2021-06-06 16:13:58 -07:00
|
|
|
nodes->back().path.assign(
|
|
|
|
|
entry->name.data(), part.data() + part.size() - entry->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() {
|
|
|
|
|
return nt::IsConnected(m_inst);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
static std::shared_ptr<nt::Value> StringToBooleanArray(std::string_view in) {
|
|
|
|
|
in = wpi::trim(in);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (in.empty()) {
|
2020-09-12 10:55:46 -07:00
|
|
|
return nt::NetworkTableValue::MakeBooleanArray(
|
|
|
|
|
std::initializer_list<bool>{});
|
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
|
|
|
wpi::SmallVector<int, 16> out;
|
|
|
|
|
|
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")) {
|
2020-09-12 10:55:46 -07:00
|
|
|
out.emplace_back(1);
|
2021-06-06 16:13:58 -07:00
|
|
|
} else if (wpi::equals_lower(val, "false")) {
|
2020-09-12 10:55:46 -07:00
|
|
|
out.emplace_back(0);
|
|
|
|
|
} else {
|
2021-06-06 16:13:58 -07:00
|
|
|
fmt::print(stderr,
|
|
|
|
|
"GUI: NetworkTables: Could not understand value '{}'\n", val);
|
2020-09-12 10:55:46 -07:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nt::NetworkTableValue::MakeBooleanArray(out);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
static std::shared_ptr<nt::Value> StringToDoubleArray(std::string_view in) {
|
|
|
|
|
in = wpi::trim(in);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (in.empty()) {
|
2021-02-26 11:43:12 -05:00
|
|
|
return nt::NetworkTableValue::MakeDoubleArray(
|
|
|
|
|
std::initializer_list<double>{});
|
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
|
|
|
wpi::SmallVector<double, 16> out;
|
|
|
|
|
|
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
|
|
|
if (auto num = wpi::parse_float<double>(wpi::trim(val))) {
|
|
|
|
|
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);
|
2020-09-12 10:55:46 -07:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nt::NetworkTableValue::MakeDoubleArray(out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int fromxdigit(char ch) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (ch >= 'a' && ch <= 'f') {
|
2020-09-12 10:55:46 -07:00
|
|
|
return (ch - 'a' + 10);
|
2020-12-28 12:58:06 -08:00
|
|
|
} else if (ch >= 'A' && ch <= 'F') {
|
2020-09-12 10:55:46 -07:00
|
|
|
return (ch - 'A' + 10);
|
2020-12-28 12:58:06 -08:00
|
|
|
} else {
|
2020-09-12 10:55:46 -07:00
|
|
|
return ch - '0';
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
static std::string_view UnescapeString(std::string_view source,
|
|
|
|
|
wpi::SmallVectorImpl<char>& buf) {
|
2020-09-12 10:55:46 -07:00
|
|
|
assert(source.size() >= 2 && source.front() == '"' && source.back() == '"');
|
|
|
|
|
buf.clear();
|
|
|
|
|
buf.reserve(source.size() - 2);
|
|
|
|
|
for (auto s = source.begin() + 1, end = source.end() - 1; s != end; ++s) {
|
|
|
|
|
if (*s != '\\') {
|
|
|
|
|
buf.push_back(*s);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
switch (*++s) {
|
|
|
|
|
case 't':
|
|
|
|
|
buf.push_back('\t');
|
|
|
|
|
break;
|
|
|
|
|
case 'n':
|
|
|
|
|
buf.push_back('\n');
|
|
|
|
|
break;
|
|
|
|
|
case 'x': {
|
|
|
|
|
if (!isxdigit(*(s + 1))) {
|
|
|
|
|
buf.push_back('x'); // treat it like a unknown escape
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
int ch = fromxdigit(*++s);
|
|
|
|
|
if (std::isxdigit(*(s + 1))) {
|
|
|
|
|
ch <<= 4;
|
|
|
|
|
ch |= fromxdigit(*++s);
|
|
|
|
|
}
|
|
|
|
|
buf.push_back(static_cast<char>(ch));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
buf.push_back(*s);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
return {buf.data(), buf.size()};
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
static std::shared_ptr<nt::Value> StringToStringArray(std::string_view in) {
|
|
|
|
|
in = wpi::trim(in);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (in.empty()) {
|
2020-09-12 10:55:46 -07:00
|
|
|
return nt::NetworkTableValue::MakeStringArray(
|
|
|
|
|
std::initializer_list<std::string>{});
|
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
|
|
|
std::vector<std::string> out;
|
|
|
|
|
wpi::SmallString<32> buf;
|
|
|
|
|
|
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);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (val.empty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
if (val.front() != '"' || val.back() != '"') {
|
2021-06-06 16:13:58 -07:00
|
|
|
fmt::print(stderr,
|
|
|
|
|
"GUI: NetworkTables: Could not understand value '{}'\n", val);
|
2020-09-12 10:55:46 -07:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
out.emplace_back(UnescapeString(val, buf));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nt::NetworkTableValue::MakeStringArray(std::move(out));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 22:21:52 -06:00
|
|
|
static void EmitEntryValueReadonly(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
|
|
|
|
|
|
|
|
switch (val->type()) {
|
|
|
|
|
case NT_BOOLEAN:
|
|
|
|
|
ImGui::LabelText("boolean", "%s", val->GetBoolean() ? "true" : "false");
|
|
|
|
|
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
|
|
|
|
|
ImGui::LabelText("double", fmt::format("%.{}f", precision).c_str(),
|
|
|
|
|
val->GetDouble());
|
|
|
|
|
#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: {
|
|
|
|
|
// GetString() comes from a std::string, so it's null terminated
|
|
|
|
|
ImGui::LabelText("string", "%s", val->GetString().data());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_BOOLEAN_ARRAY:
|
|
|
|
|
ImGui::LabelText("boolean[]", "%s", entry.valueStr.c_str());
|
|
|
|
|
break;
|
|
|
|
|
case NT_DOUBLE_ARRAY:
|
|
|
|
|
ImGui::LabelText("double[]", "%s", entry.valueStr.c_str());
|
|
|
|
|
break;
|
|
|
|
|
case NT_STRING_ARRAY:
|
|
|
|
|
ImGui::LabelText("string[]", "%s", entry.valueStr.c_str());
|
|
|
|
|
break;
|
|
|
|
|
case NT_RAW:
|
|
|
|
|
ImGui::LabelText("raw", "[...]");
|
|
|
|
|
break;
|
|
|
|
|
case NT_RPC:
|
|
|
|
|
ImGui::LabelText("rpc", "[...]");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ImGui::LabelText("other", "?");
|
|
|
|
|
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
|
|
|
|
|
|
|
|
ImGui::PushID(entry.name.c_str());
|
|
|
|
|
switch (val->type()) {
|
|
|
|
|
case NT_BOOLEAN: {
|
|
|
|
|
static const char* boolOptions[] = {"false", "true"};
|
|
|
|
|
int v = val->GetBoolean() ? 1 : 0;
|
2020-12-28 12:58:06 -08:00
|
|
|
if (ImGui::Combo("boolean", &v, boolOptions, 2)) {
|
2020-09-12 10:55:46 -07:00
|
|
|
nt::SetEntryValue(entry.entry, nt::NetworkTableValue::MakeBoolean(v));
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_DOUBLE: {
|
|
|
|
|
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
|
|
|
|
|
if (ImGui::InputDouble("double", &v, 0, 0,
|
|
|
|
|
fmt::format("%.{}f", precision).c_str(),
|
2020-12-28 12:58:06 -08:00
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
2020-09-12 10:55:46 -07:00
|
|
|
nt::SetEntryValue(entry.entry, nt::NetworkTableValue::MakeDouble(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: {
|
|
|
|
|
char* v = GetTextBuffer(val->GetString());
|
|
|
|
|
if (ImGui::InputText("string", v, kTextBufferSize,
|
2020-12-28 12:58:06 -08:00
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
2020-09-12 10:55:46 -07:00
|
|
|
nt::SetEntryValue(entry.entry, nt::NetworkTableValue::MakeString(v));
|
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);
|
|
|
|
|
if (ImGui::InputText("boolean[]", v, kTextBufferSize,
|
|
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (auto outv = StringToBooleanArray(v)) {
|
2020-09-12 10:55:46 -07:00
|
|
|
nt::SetEntryValue(entry.entry, std::move(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);
|
|
|
|
|
if (ImGui::InputText("double[]", v, kTextBufferSize,
|
|
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (auto outv = StringToDoubleArray(v)) {
|
2020-09-12 10:55:46 -07:00
|
|
|
nt::SetEntryValue(entry.entry, std::move(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);
|
|
|
|
|
if (ImGui::InputText("string[]", v, kTextBufferSize,
|
|
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (auto outv = StringToStringArray(v)) {
|
2020-09-12 10:55:46 -07:00
|
|
|
nt::SetEntryValue(entry.entry, std::move(outv));
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NT_RAW:
|
|
|
|
|
ImGui::LabelText("raw", "[...]");
|
|
|
|
|
break;
|
|
|
|
|
case NT_RPC:
|
|
|
|
|
ImGui::LabelText("rpc", "[...]");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ImGui::LabelText("other", "?");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 20:49:29 -08:00
|
|
|
static void EmitParentContextMenu(const std::string& path,
|
|
|
|
|
NetworkTablesFlags flags) {
|
|
|
|
|
// Workaround https://github.com/ocornut/imgui/issues/331
|
|
|
|
|
bool openWarningPopup = false;
|
|
|
|
|
static char nameBuffer[kTextBufferSize];
|
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();
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginMenu("Add new...")) {
|
|
|
|
|
if (ImGui::IsWindowAppearing()) {
|
|
|
|
|
nameBuffer[0] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::InputTextWithHint("New item name", "example", nameBuffer,
|
|
|
|
|
kTextBufferSize);
|
|
|
|
|
std::string fullNewPath;
|
|
|
|
|
if (path == "/") {
|
|
|
|
|
fullNewPath = path + nameBuffer;
|
|
|
|
|
} else {
|
2021-06-06 16:13:58 -07:00
|
|
|
fullNewPath = fmt::format("{}/{}", path, nameBuffer);
|
2020-12-29 20:49:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::Text("Adding: %s", fullNewPath.c_str());
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
auto entry = nt::GetEntry(nt::GetDefaultInstance(), fullNewPath);
|
|
|
|
|
bool enabled = (flags & NetworkTablesFlags_CreateNoncanonicalKeys ||
|
|
|
|
|
nameBuffer[0] != '\0') &&
|
|
|
|
|
nt::GetEntryType(entry) == NT_Type::NT_UNASSIGNED;
|
|
|
|
|
if (ImGui::MenuItem("string", nullptr, false, enabled)) {
|
|
|
|
|
if (!nt::SetEntryValue(entry, nt::Value::MakeString(""))) {
|
|
|
|
|
openWarningPopup = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::MenuItem("double", nullptr, false, enabled)) {
|
|
|
|
|
if (!nt::SetEntryValue(entry, nt::Value::MakeDouble(0.0))) {
|
|
|
|
|
openWarningPopup = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::MenuItem("boolean", nullptr, false, enabled)) {
|
|
|
|
|
if (!nt::SetEntryValue(entry, nt::Value::MakeBoolean(false))) {
|
|
|
|
|
openWarningPopup = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::MenuItem("string[]", nullptr, false, enabled)) {
|
|
|
|
|
if (!nt::SetEntryValue(entry, nt::Value::MakeStringArray({""}))) {
|
|
|
|
|
openWarningPopup = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::MenuItem("double[]", nullptr, false, enabled)) {
|
|
|
|
|
if (!nt::SetEntryValue(entry, nt::Value::MakeDoubleArray({0.0}))) {
|
|
|
|
|
openWarningPopup = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::MenuItem("boolean[]", nullptr, false, enabled)) {
|
|
|
|
|
if (!nt::SetEntryValue(entry, nt::Value::MakeBooleanArray({false}))) {
|
|
|
|
|
openWarningPopup = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
if (ImGui::MenuItem("Remove All")) {
|
|
|
|
|
for (auto&& entry : nt::GetEntries(nt::GetDefaultInstance(), path, 0)) {
|
|
|
|
|
nt::DeleteEntry(entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Workaround https://github.com/ocornut/imgui/issues/331
|
|
|
|
|
if (openWarningPopup) {
|
|
|
|
|
ImGui::OpenPopup("Value exists");
|
|
|
|
|
}
|
2020-12-29 22:46:11 -08:00
|
|
|
if (ImGui::BeginPopupModal("Value exists", nullptr,
|
2020-12-29 20:49:29 -08:00
|
|
|
ImGuiWindowFlags_AlwaysAutoResize)) {
|
|
|
|
|
ImGui::Text("The provided name %s already exists in the tree!", nameBuffer);
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
|
|
if (ImGui::Button("OK", ImVec2(120, 0))) {
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
}
|
|
|
|
|
ImGui::SetItemDefaultFocus();
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
static void EmitEntry(NetworkTablesModel::Entry& entry, const char* name,
|
|
|
|
|
NetworkTablesFlags flags) {
|
|
|
|
|
if (entry.source) {
|
|
|
|
|
ImGui::Selectable(name);
|
|
|
|
|
entry.source->EmitDrag();
|
|
|
|
|
} else {
|
|
|
|
|
ImGui::Text("%s", name);
|
|
|
|
|
}
|
2020-12-29 20:49:29 -08:00
|
|
|
if (ImGui::BeginPopupContextItem(entry.name.c_str())) {
|
|
|
|
|
ImGui::Text("%s", entry.name.c_str());
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
if (ImGui::MenuItem("Remove")) {
|
|
|
|
|
nt::DeleteEntry(entry.entry);
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::NextColumn();
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
if (flags & NetworkTablesFlags_ReadOnly) {
|
2022-06-15 22:21:52 -06:00
|
|
|
EmitEntryValueReadonly(entry, 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
|
|
|
ImGui::NextColumn();
|
|
|
|
|
|
|
|
|
|
if (flags & NetworkTablesFlags_ShowFlags) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if ((entry.flags & NT_PERSISTENT) != 0) {
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::Text("Persistent");
|
2020-12-28 12:58:06 -08:00
|
|
|
} else if (entry.flags != 0) {
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::Text("%02x", entry.flags);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::NextColumn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags & NetworkTablesFlags_ShowTimestamp) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (entry.value) {
|
2020-12-17 07:29:00 -08:00
|
|
|
ImGui::Text("%f", (entry.value->last_change() * 1.0e-6) -
|
|
|
|
|
(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
|
|
|
ImGui::NextColumn();
|
|
|
|
|
}
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void EmitTree(const std::vector<NetworkTablesModel::TreeNode>& tree,
|
|
|
|
|
NetworkTablesFlags flags) {
|
|
|
|
|
for (auto&& node : tree) {
|
|
|
|
|
if (node.entry) {
|
|
|
|
|
EmitEntry(*node.entry, node.name.c_str(), flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!node.children.empty()) {
|
|
|
|
|
bool open =
|
|
|
|
|
TreeNodeEx(node.name.c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
|
2020-12-29 20:49:29 -08:00
|
|
|
EmitParentContextMenu(node.path, flags);
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::NextColumn();
|
|
|
|
|
ImGui::NextColumn();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (flags & NetworkTablesFlags_ShowFlags) {
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
}
|
|
|
|
|
if (flags & NetworkTablesFlags_ShowTimestamp) {
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::Separator();
|
|
|
|
|
if (open) {
|
|
|
|
|
EmitTree(node.children, flags);
|
|
|
|
|
TreePop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glass::DisplayNetworkTables(NetworkTablesModel* model,
|
|
|
|
|
NetworkTablesFlags flags) {
|
|
|
|
|
auto inst = model->GetInstance();
|
|
|
|
|
|
|
|
|
|
if (flags & NetworkTablesFlags_ShowConnections) {
|
|
|
|
|
if (CollapsingHeader("Connections")) {
|
|
|
|
|
ImGui::Columns(4, "connections");
|
|
|
|
|
ImGui::Text("Id");
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
ImGui::Text("Address");
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
ImGui::Text("Updated");
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
ImGui::Text("Proto");
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
for (auto&& i : nt::GetConnections(inst)) {
|
|
|
|
|
ImGui::Text("%s", i.remote_id.c_str());
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
ImGui::Text("%s", i.remote_ip.c_str());
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
ImGui::Text("%llu",
|
|
|
|
|
static_cast<unsigned long long>( // NOLINT(runtime/int)
|
|
|
|
|
i.last_update));
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
ImGui::Text("%d.%d", i.protocol_version >> 8,
|
|
|
|
|
i.protocol_version & 0xff);
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
}
|
|
|
|
|
ImGui::Columns();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!CollapsingHeader("Values", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool showFlags = (flags & NetworkTablesFlags_ShowFlags);
|
|
|
|
|
const bool showTimestamp = (flags & NetworkTablesFlags_ShowTimestamp);
|
|
|
|
|
|
|
|
|
|
static bool first = true;
|
|
|
|
|
ImGui::Columns(2 + (showFlags ? 1 : 0) + (showTimestamp ? 1 : 0), "values");
|
2020-12-28 12:58:06 -08:00
|
|
|
if (first) {
|
|
|
|
|
ImGui::SetColumnWidth(-1, 0.5f * ImGui::GetWindowWidth());
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::Text("Name");
|
2020-12-29 20:49:29 -08:00
|
|
|
EmitParentContextMenu("/", flags);
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::NextColumn();
|
|
|
|
|
ImGui::Text("Value");
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
if (showFlags) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (first) {
|
|
|
|
|
ImGui::SetColumnWidth(-1, 12 * ImGui::GetFontSize());
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::Text("Flags");
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
}
|
|
|
|
|
if (showTimestamp) {
|
|
|
|
|
ImGui::Text("Changed");
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
}
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
first = false;
|
|
|
|
|
|
|
|
|
|
if (flags & NetworkTablesFlags_TreeView) {
|
|
|
|
|
EmitTree(model->GetTreeRoot(), flags);
|
|
|
|
|
} else {
|
|
|
|
|
for (auto entry : model->GetEntries()) {
|
|
|
|
|
EmitEntry(*entry, entry->name.c_str(), flags);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::Columns();
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
m_pShowConnections = &storage.GetBool(
|
2021-03-16 22:05:41 -07:00
|
|
|
"connections", m_defaultFlags & NetworkTablesFlags_ShowConnections);
|
[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_pShowFlags = &storage.GetBool(
|
2021-03-16 22:05:41 -07:00
|
|
|
"flags", m_defaultFlags & NetworkTablesFlags_ShowFlags);
|
[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);
|
[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 &= ~(
|
|
|
|
|
NetworkTablesFlags_TreeView | NetworkTablesFlags_ShowConnections |
|
|
|
|
|
NetworkTablesFlags_ShowFlags | NetworkTablesFlags_ShowTimestamp |
|
|
|
|
|
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) |
|
|
|
|
|
(*m_pShowConnections ? NetworkTablesFlags_ShowConnections : 0) |
|
|
|
|
|
(*m_pShowFlags ? NetworkTablesFlags_ShowFlags : 0) |
|
|
|
|
|
(*m_pShowTimestamp ? NetworkTablesFlags_ShowTimestamp : 0) |
|
|
|
|
|
(*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);
|
|
|
|
|
ImGui::MenuItem("Show Connections", "", m_pShowConnections);
|
|
|
|
|
ImGui::MenuItem("Show Flags", "", m_pShowFlags);
|
|
|
|
|
ImGui::MenuItem("Show Timestamp", "", m_pShowTimestamp);
|
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();
|
|
|
|
|
if (ImGui::BeginPopupContextItem()) {
|
|
|
|
|
m_flags.DisplayMenu();
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
DisplayNetworkTables(m_model, m_flags.GetFlags());
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|