mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Add braces to C++ single-line loops and conditionals (NFC) (#2973)
This makes code easier to read and more consistent between C++ and Java. Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
@@ -27,22 +27,26 @@ NTCommandSchedulerModel::NTCommandSchedulerModel(NT_Inst instance,
|
||||
}
|
||||
|
||||
void NTCommandSchedulerModel::CancelCommand(size_t index) {
|
||||
if (index < m_idsValue.size())
|
||||
if (index < m_idsValue.size()) {
|
||||
nt::SetEntryValue(
|
||||
m_cancel, nt::NetworkTableValue::MakeDoubleArray({m_idsValue[index]}));
|
||||
}
|
||||
}
|
||||
|
||||
void NTCommandSchedulerModel::Update() {
|
||||
for (auto&& event : m_nt.PollListener()) {
|
||||
if (event.entry == m_name) {
|
||||
if (event.value && event.value->IsString())
|
||||
if (event.value && event.value->IsString()) {
|
||||
m_nameValue = event.value->GetString();
|
||||
}
|
||||
} else if (event.entry == m_commands) {
|
||||
if (event.value && event.value->IsStringArray())
|
||||
if (event.value && event.value->IsStringArray()) {
|
||||
m_commandsValue = event.value->GetStringArray();
|
||||
}
|
||||
} else if (event.entry == m_ids) {
|
||||
if (event.value && event.value->IsDoubleArray())
|
||||
if (event.value && event.value->IsDoubleArray()) {
|
||||
m_idsValue = event.value->GetDoubleArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,13 @@ void NTCommandSelectorModel::SetRunning(bool run) {
|
||||
void NTCommandSelectorModel::Update() {
|
||||
for (auto&& event : m_nt.PollListener()) {
|
||||
if (event.entry == m_running) {
|
||||
if (event.value && event.value->IsBoolean())
|
||||
if (event.value && event.value->IsBoolean()) {
|
||||
m_runningData.SetValue(event.value->GetBoolean());
|
||||
}
|
||||
} else if (event.entry == m_name) {
|
||||
if (event.value && event.value->IsString())
|
||||
if (event.value && event.value->IsString()) {
|
||||
m_nameValue = event.value->GetString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ class NTField2DModel::GroupModel : public FieldObjectGroupModel {
|
||||
void NTUpdate(const nt::Value& value);
|
||||
|
||||
void Update() override {
|
||||
if (auto value = nt::GetEntryValue(m_entry)) NTUpdate(*value);
|
||||
if (auto value = nt::GetEntryValue(m_entry)) {
|
||||
NTUpdate(*value);
|
||||
}
|
||||
}
|
||||
bool Exists() override { return nt::GetEntryType(m_entry) != NT_UNASSIGNED; }
|
||||
bool IsReadOnly() override { return false; }
|
||||
@@ -96,12 +98,14 @@ void NTField2DModel::GroupModel::NTUpdate(const nt::Value& value) {
|
||||
m_count = arr.size() / 3;
|
||||
if (m_count > m_objects.size()) {
|
||||
m_objects.reserve(m_count);
|
||||
for (size_t i = m_objects.size(); i < m_count; ++i)
|
||||
for (size_t i = m_objects.size(); i < m_count; ++i) {
|
||||
m_objects.emplace_back(std::make_unique<ObjectModel>(m_name, m_entry, i));
|
||||
}
|
||||
}
|
||||
if (m_count < m_objects.size()) {
|
||||
for (size_t i = m_count; i < m_objects.size(); ++i)
|
||||
for (size_t i = m_count; i < m_objects.size(); ++i) {
|
||||
m_objects[i]->SetExists(false);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_count; ++i) {
|
||||
@@ -139,19 +143,31 @@ void NTField2DModel::GroupModel::ObjectModel::SetPoseImpl(double x, double y,
|
||||
bool setRot) {
|
||||
// get from NT, validate type and size
|
||||
auto value = nt::GetEntryValue(m_entry);
|
||||
if (!value || !value->IsDoubleArray()) return;
|
||||
if (!value || !value->IsDoubleArray()) {
|
||||
return;
|
||||
}
|
||||
auto origArr = value->GetDoubleArray();
|
||||
if (origArr.size() < static_cast<size_t>((m_index + 1) * 3)) return;
|
||||
if (origArr.size() < static_cast<size_t>((m_index + 1) * 3)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// copy existing array
|
||||
wpi::SmallVector<double, 8> arr;
|
||||
arr.reserve(origArr.size());
|
||||
for (auto&& elem : origArr) arr.emplace_back(elem);
|
||||
for (auto&& elem : origArr) {
|
||||
arr.emplace_back(elem);
|
||||
}
|
||||
|
||||
// update value
|
||||
if (setX) arr[m_index * 3 + 0] = x;
|
||||
if (setY) arr[m_index * 3 + 1] = y;
|
||||
if (setRot) arr[m_index * 3 + 2] = rot;
|
||||
if (setX) {
|
||||
arr[m_index * 3 + 0] = x;
|
||||
}
|
||||
if (setY) {
|
||||
arr[m_index * 3 + 1] = y;
|
||||
}
|
||||
if (setRot) {
|
||||
arr[m_index * 3 + 2] = rot;
|
||||
}
|
||||
|
||||
// set back to NT
|
||||
nt::SetEntryValue(m_entry, nt::Value::MakeDoubleArray(arr));
|
||||
@@ -194,19 +210,24 @@ void NTField2DModel::Update() {
|
||||
// handle create/delete
|
||||
if (wpi::StringRef{event.name}.startswith(m_path)) {
|
||||
auto name = wpi::StringRef{event.name}.drop_front(m_path.size());
|
||||
if (name.empty() || name[0] == '.') continue;
|
||||
if (name.empty() || name[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
auto it = std::lower_bound(m_groups.begin(), m_groups.end(), name,
|
||||
[](const auto& e, wpi::StringRef name) {
|
||||
return e->GetName() < name;
|
||||
});
|
||||
bool match = (it != m_groups.end() && (*it)->GetName() == name);
|
||||
if (event.flags & NT_NOTIFY_DELETE) {
|
||||
if (match) m_groups.erase(it);
|
||||
if (match) {
|
||||
m_groups.erase(it);
|
||||
}
|
||||
continue;
|
||||
} else if (event.flags & NT_NOTIFY_NEW) {
|
||||
if (!match)
|
||||
if (!match) {
|
||||
it = m_groups.emplace(
|
||||
it, std::make_unique<GroupModel>(event.name, event.entry));
|
||||
}
|
||||
} else if (!match) {
|
||||
continue;
|
||||
}
|
||||
@@ -221,13 +242,16 @@ bool NTField2DModel::Exists() {
|
||||
return m_nt.IsConnected() && nt::GetEntryType(m_name) != NT_UNASSIGNED;
|
||||
}
|
||||
|
||||
bool NTField2DModel::IsReadOnly() { return false; }
|
||||
bool NTField2DModel::IsReadOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void NTField2DModel::ForEachFieldObjectGroup(
|
||||
wpi::function_ref<void(FieldObjectGroupModel& model, wpi::StringRef name)>
|
||||
func) {
|
||||
for (auto&& group : m_groups) {
|
||||
if (group->Exists())
|
||||
if (group->Exists()) {
|
||||
func(*group, wpi::StringRef{group->GetName()}.drop_front(m_path.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,13 @@ NTGyroModel::NTGyroModel(NT_Inst instance, wpi::StringRef path)
|
||||
void NTGyroModel::Update() {
|
||||
for (auto&& event : m_nt.PollListener()) {
|
||||
if (event.entry == m_angle) {
|
||||
if (event.value && event.value->IsDouble())
|
||||
if (event.value && event.value->IsDouble()) {
|
||||
m_angleData.SetValue(event.value->GetDouble());
|
||||
}
|
||||
} else if (event.entry == m_name) {
|
||||
if (event.value && event.value->IsString())
|
||||
if (event.value && event.value->IsString()) {
|
||||
m_nameValue = event.value->GetString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,20 +49,25 @@ void NTPIDControllerModel::SetSetpoint(double value) {
|
||||
void NTPIDControllerModel::Update() {
|
||||
for (auto&& event : m_nt.PollListener()) {
|
||||
if (event.entry == m_name) {
|
||||
if (event.value && event.value->IsString())
|
||||
if (event.value && event.value->IsString()) {
|
||||
m_nameValue = event.value->GetString();
|
||||
}
|
||||
} else if (event.entry == m_p) {
|
||||
if (event.value && event.value->IsDouble())
|
||||
if (event.value && event.value->IsDouble()) {
|
||||
m_pData.SetValue(event.value->GetDouble());
|
||||
}
|
||||
} else if (event.entry == m_i) {
|
||||
if (event.value && event.value->IsDouble())
|
||||
if (event.value && event.value->IsDouble()) {
|
||||
m_iData.SetValue(event.value->GetDouble());
|
||||
}
|
||||
} else if (event.entry == m_d) {
|
||||
if (event.value && event.value->IsDouble())
|
||||
if (event.value && event.value->IsDouble()) {
|
||||
m_dData.SetValue(event.value->GetDouble());
|
||||
}
|
||||
} else if (event.entry == m_setpoint) {
|
||||
if (event.value && event.value->IsDouble())
|
||||
if (event.value && event.value->IsDouble()) {
|
||||
m_setpointData.SetValue(event.value->GetDouble());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,13 @@ void NTSpeedControllerModel::SetPercent(double value) {
|
||||
void NTSpeedControllerModel::Update() {
|
||||
for (auto&& event : m_nt.PollListener()) {
|
||||
if (event.entry == m_value) {
|
||||
if (event.value && event.value->IsDouble())
|
||||
if (event.value && event.value->IsDouble()) {
|
||||
m_valueData.SetValue(event.value->GetDouble());
|
||||
}
|
||||
} else if (event.entry == m_name) {
|
||||
if (event.value && event.value->IsString())
|
||||
if (event.value && event.value->IsString()) {
|
||||
m_nameValue = event.value->GetString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,13 @@ NTSubsystemModel::NTSubsystemModel(NT_Inst instance, wpi::StringRef path)
|
||||
void NTSubsystemModel::Update() {
|
||||
for (auto&& event : m_nt.PollListener()) {
|
||||
if (event.entry == m_name) {
|
||||
if (event.value && event.value->IsString())
|
||||
if (event.value && event.value->IsString()) {
|
||||
m_nameValue = event.value->GetString();
|
||||
}
|
||||
} else if (event.entry == m_defaultCommand) {
|
||||
if (event.value && event.value->IsString())
|
||||
if (event.value && event.value->IsString()) {
|
||||
m_defaultCommandValue = event.value->GetString();
|
||||
}
|
||||
} else if (event.entry == m_currentCommand) {
|
||||
if (event.value && event.value->IsString()) {
|
||||
m_currentCommandValue = event.value->GetString();
|
||||
|
||||
@@ -32,12 +32,15 @@ static std::string BooleanArrayToString(wpi::ArrayRef<int> in) {
|
||||
os << '[';
|
||||
bool first = true;
|
||||
for (auto v : in) {
|
||||
if (!first) os << ',';
|
||||
if (!first) {
|
||||
os << ',';
|
||||
}
|
||||
first = false;
|
||||
if (v)
|
||||
if (v) {
|
||||
os << "true";
|
||||
else
|
||||
} else {
|
||||
os << "false";
|
||||
}
|
||||
}
|
||||
os << ']';
|
||||
return rv;
|
||||
@@ -49,7 +52,9 @@ static std::string DoubleArrayToString(wpi::ArrayRef<double> in) {
|
||||
os << '[';
|
||||
bool first = true;
|
||||
for (auto v : in) {
|
||||
if (!first) os << ',';
|
||||
if (!first) {
|
||||
os << ',';
|
||||
}
|
||||
first = false;
|
||||
os << wpi::format("%.6f", v);
|
||||
}
|
||||
@@ -63,7 +68,9 @@ static std::string StringArrayToString(wpi::ArrayRef<std::string> in) {
|
||||
os << '[';
|
||||
bool first = true;
|
||||
for (auto&& v : in) {
|
||||
if (!first) os << ',';
|
||||
if (!first) {
|
||||
os << ',';
|
||||
}
|
||||
first = false;
|
||||
os << '"';
|
||||
os.write_escaped(v);
|
||||
@@ -99,14 +106,16 @@ NetworkTablesModel::Entry::Entry(nt::EntryNotification&& event)
|
||||
void NetworkTablesModel::Entry::UpdateValue() {
|
||||
switch (value->type()) {
|
||||
case NT_BOOLEAN:
|
||||
if (!source)
|
||||
if (!source) {
|
||||
source = std::make_unique<DataSource>(wpi::Twine{"NT:"} + name);
|
||||
}
|
||||
source->SetValue(value->GetBoolean() ? 1 : 0);
|
||||
source->SetDigital(true);
|
||||
break;
|
||||
case NT_DOUBLE:
|
||||
if (!source)
|
||||
if (!source) {
|
||||
source = std::make_unique<DataSource>(wpi::Twine{"NT:"} + name);
|
||||
}
|
||||
source->SetValue(value->GetDouble());
|
||||
source->SetDigital(false);
|
||||
break;
|
||||
@@ -136,12 +145,16 @@ void NetworkTablesModel::Update() {
|
||||
updateTree = true;
|
||||
}
|
||||
}
|
||||
if (!entry) continue;
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
if (event.flags & NT_NOTIFY_DELETE) {
|
||||
auto it = std::find(m_sortedEntries.begin(), m_sortedEntries.end(),
|
||||
entry.get());
|
||||
// will be removed completely below
|
||||
if (it != m_sortedEntries.end()) *it = nullptr;
|
||||
if (it != m_sortedEntries.end()) {
|
||||
*it = nullptr;
|
||||
}
|
||||
m_entries.erase(event.entry);
|
||||
updateTree = true;
|
||||
continue;
|
||||
@@ -156,7 +169,9 @@ void NetworkTablesModel::Update() {
|
||||
}
|
||||
|
||||
// shortcut common case (updates)
|
||||
if (!updateTree) return;
|
||||
if (!updateTree) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove deleted entries
|
||||
m_sortedEntries.erase(
|
||||
@@ -204,15 +219,22 @@ void NetworkTablesModel::Update() {
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkTablesModel::Exists() { return nt::IsConnected(m_inst); }
|
||||
bool NetworkTablesModel::Exists() {
|
||||
return nt::IsConnected(m_inst);
|
||||
}
|
||||
|
||||
static std::shared_ptr<nt::Value> StringToBooleanArray(wpi::StringRef in) {
|
||||
in = in.trim();
|
||||
if (in.empty())
|
||||
if (in.empty()) {
|
||||
return nt::NetworkTableValue::MakeBooleanArray(
|
||||
std::initializer_list<bool>{});
|
||||
if (in.front() == '[') in = in.drop_front();
|
||||
if (in.back() == ']') in = in.drop_back();
|
||||
}
|
||||
if (in.front() == '[') {
|
||||
in = in.drop_front();
|
||||
}
|
||||
if (in.back() == ']') {
|
||||
in = in.drop_back();
|
||||
}
|
||||
in = in.trim();
|
||||
|
||||
wpi::SmallVector<wpi::StringRef, 16> inSplit;
|
||||
@@ -237,11 +259,16 @@ static std::shared_ptr<nt::Value> StringToBooleanArray(wpi::StringRef in) {
|
||||
|
||||
static std::shared_ptr<nt::Value> StringToDoubleArray(wpi::StringRef in) {
|
||||
in = in.trim();
|
||||
if (in.empty())
|
||||
if (in.empty()) {
|
||||
return nt::NetworkTableValue::MakeBooleanArray(
|
||||
std::initializer_list<bool>{});
|
||||
if (in.front() == '[') in = in.drop_front();
|
||||
if (in.back() == ']') in = in.drop_back();
|
||||
}
|
||||
if (in.front() == '[') {
|
||||
in = in.drop_front();
|
||||
}
|
||||
if (in.back() == ']') {
|
||||
in = in.drop_back();
|
||||
}
|
||||
in = in.trim();
|
||||
|
||||
wpi::SmallVector<wpi::StringRef, 16> inSplit;
|
||||
@@ -265,12 +292,13 @@ static std::shared_ptr<nt::Value> StringToDoubleArray(wpi::StringRef in) {
|
||||
}
|
||||
|
||||
static int fromxdigit(char ch) {
|
||||
if (ch >= 'a' && ch <= 'f')
|
||||
if (ch >= 'a' && ch <= 'f') {
|
||||
return (ch - 'a' + 10);
|
||||
else if (ch >= 'A' && ch <= 'F')
|
||||
} else if (ch >= 'A' && ch <= 'F') {
|
||||
return (ch - 'A' + 10);
|
||||
else
|
||||
} else {
|
||||
return ch - '0';
|
||||
}
|
||||
}
|
||||
|
||||
static wpi::StringRef UnescapeString(wpi::StringRef source,
|
||||
@@ -313,11 +341,16 @@ static wpi::StringRef UnescapeString(wpi::StringRef source,
|
||||
|
||||
static std::shared_ptr<nt::Value> StringToStringArray(wpi::StringRef in) {
|
||||
in = in.trim();
|
||||
if (in.empty())
|
||||
if (in.empty()) {
|
||||
return nt::NetworkTableValue::MakeStringArray(
|
||||
std::initializer_list<std::string>{});
|
||||
if (in.front() == '[') in = in.drop_front();
|
||||
if (in.back() == ']') in = in.drop_back();
|
||||
}
|
||||
if (in.front() == '[') {
|
||||
in = in.drop_front();
|
||||
}
|
||||
if (in.back() == ']') {
|
||||
in = in.drop_back();
|
||||
}
|
||||
in = in.trim();
|
||||
|
||||
wpi::SmallVector<wpi::StringRef, 16> inSplit;
|
||||
@@ -327,7 +360,9 @@ static std::shared_ptr<nt::Value> StringToStringArray(wpi::StringRef in) {
|
||||
in.split(inSplit, ',', -1, false);
|
||||
for (auto val : inSplit) {
|
||||
val = val.trim();
|
||||
if (val.empty()) continue;
|
||||
if (val.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (val.front() != '"' || val.back() != '"') {
|
||||
wpi::errs() << "GUI: NetworkTables: Could not understand value '" << val
|
||||
<< "'\n";
|
||||
@@ -341,7 +376,9 @@ static std::shared_ptr<nt::Value> StringToStringArray(wpi::StringRef in) {
|
||||
|
||||
static void EmitEntryValueReadonly(NetworkTablesModel::Entry& entry) {
|
||||
auto& val = entry.value;
|
||||
if (!val) return;
|
||||
if (!val) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (val->type()) {
|
||||
case NT_BOOLEAN:
|
||||
@@ -388,37 +425,43 @@ static char* GetTextBuffer(wpi::StringRef in) {
|
||||
|
||||
static void EmitEntryValueEditable(NetworkTablesModel::Entry& entry) {
|
||||
auto& val = entry.value;
|
||||
if (!val) return;
|
||||
if (!val) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::PushID(entry.name.c_str());
|
||||
switch (val->type()) {
|
||||
case NT_BOOLEAN: {
|
||||
static const char* boolOptions[] = {"false", "true"};
|
||||
int v = val->GetBoolean() ? 1 : 0;
|
||||
if (ImGui::Combo("boolean", &v, boolOptions, 2))
|
||||
if (ImGui::Combo("boolean", &v, boolOptions, 2)) {
|
||||
nt::SetEntryValue(entry.entry, nt::NetworkTableValue::MakeBoolean(v));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NT_DOUBLE: {
|
||||
double v = val->GetDouble();
|
||||
if (ImGui::InputDouble("double", &v, 0, 0, "%.6f",
|
||||
ImGuiInputTextFlags_EnterReturnsTrue))
|
||||
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
nt::SetEntryValue(entry.entry, nt::NetworkTableValue::MakeDouble(v));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NT_STRING: {
|
||||
char* v = GetTextBuffer(val->GetString());
|
||||
if (ImGui::InputText("string", v, kTextBufferSize,
|
||||
ImGuiInputTextFlags_EnterReturnsTrue))
|
||||
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
nt::SetEntryValue(entry.entry, nt::NetworkTableValue::MakeString(v));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NT_BOOLEAN_ARRAY: {
|
||||
char* v = GetTextBuffer(entry.valueStr);
|
||||
if (ImGui::InputText("boolean[]", v, kTextBufferSize,
|
||||
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
if (auto outv = StringToBooleanArray(v))
|
||||
if (auto outv = StringToBooleanArray(v)) {
|
||||
nt::SetEntryValue(entry.entry, std::move(outv));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -426,8 +469,9 @@ static void EmitEntryValueEditable(NetworkTablesModel::Entry& entry) {
|
||||
char* v = GetTextBuffer(entry.valueStr);
|
||||
if (ImGui::InputText("double[]", v, kTextBufferSize,
|
||||
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
if (auto outv = StringToDoubleArray(v))
|
||||
if (auto outv = StringToDoubleArray(v)) {
|
||||
nt::SetEntryValue(entry.entry, std::move(outv));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -435,8 +479,9 @@ static void EmitEntryValueEditable(NetworkTablesModel::Entry& entry) {
|
||||
char* v = GetTextBuffer(entry.valueStr);
|
||||
if (ImGui::InputText("string[]", v, kTextBufferSize,
|
||||
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
if (auto outv = StringToStringArray(v))
|
||||
if (auto outv = StringToStringArray(v)) {
|
||||
nt::SetEntryValue(entry.entry, std::move(outv));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -463,26 +508,29 @@ static void EmitEntry(NetworkTablesModel::Entry& entry, const char* name,
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
|
||||
if (flags & NetworkTablesFlags_ReadOnly)
|
||||
if (flags & NetworkTablesFlags_ReadOnly) {
|
||||
EmitEntryValueReadonly(entry);
|
||||
else
|
||||
} else {
|
||||
EmitEntryValueEditable(entry);
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
|
||||
if (flags & NetworkTablesFlags_ShowFlags) {
|
||||
if ((entry.flags & NT_PERSISTENT) != 0)
|
||||
if ((entry.flags & NT_PERSISTENT) != 0) {
|
||||
ImGui::Text("Persistent");
|
||||
else if (entry.flags != 0)
|
||||
} else if (entry.flags != 0) {
|
||||
ImGui::Text("%02x", entry.flags);
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
|
||||
if (flags & NetworkTablesFlags_ShowTimestamp) {
|
||||
if (entry.value)
|
||||
if (entry.value) {
|
||||
ImGui::Text("%f", (entry.value->last_change() * 1.0e-6) -
|
||||
(GetZeroTime() * 1.0e-6));
|
||||
else
|
||||
} else {
|
||||
ImGui::TextUnformatted("");
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
ImGui::Separator();
|
||||
@@ -500,8 +548,12 @@ static void EmitTree(const std::vector<NetworkTablesModel::TreeNode>& tree,
|
||||
TreeNodeEx(node.name.c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
|
||||
ImGui::NextColumn();
|
||||
ImGui::NextColumn();
|
||||
if (flags & NetworkTablesFlags_ShowFlags) ImGui::NextColumn();
|
||||
if (flags & NetworkTablesFlags_ShowTimestamp) ImGui::NextColumn();
|
||||
if (flags & NetworkTablesFlags_ShowFlags) {
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
if (flags & NetworkTablesFlags_ShowTimestamp) {
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (open) {
|
||||
EmitTree(node.children, flags);
|
||||
@@ -543,7 +595,9 @@ void glass::DisplayNetworkTables(NetworkTablesModel* model,
|
||||
ImGui::Columns();
|
||||
}
|
||||
|
||||
if (!CollapsingHeader("Values", ImGuiTreeNodeFlags_DefaultOpen)) return;
|
||||
if (!CollapsingHeader("Values", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const bool showFlags = (flags & NetworkTablesFlags_ShowFlags);
|
||||
@@ -551,13 +605,17 @@ void glass::DisplayNetworkTables(NetworkTablesModel* model,
|
||||
|
||||
static bool first = true;
|
||||
ImGui::Columns(2 + (showFlags ? 1 : 0) + (showTimestamp ? 1 : 0), "values");
|
||||
if (first) ImGui::SetColumnWidth(-1, 0.5f * ImGui::GetWindowWidth());
|
||||
if (first) {
|
||||
ImGui::SetColumnWidth(-1, 0.5f * ImGui::GetWindowWidth());
|
||||
}
|
||||
ImGui::Text("Name");
|
||||
ImGui::NextColumn();
|
||||
ImGui::Text("Value");
|
||||
ImGui::NextColumn();
|
||||
if (showFlags) {
|
||||
if (first) ImGui::SetColumnWidth(-1, 12 * ImGui::GetFontSize());
|
||||
if (first) {
|
||||
ImGui::SetColumnWidth(-1, 12 * ImGui::GetFontSize());
|
||||
}
|
||||
ImGui::Text("Flags");
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
|
||||
@@ -57,7 +57,9 @@ void NetworkTablesProvider::DisplayMenu() {
|
||||
}
|
||||
}
|
||||
|
||||
for (; depth > 0; --depth) ImGui::EndMenu();
|
||||
for (; depth > 0; --depth) {
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,13 +71,16 @@ void NetworkTablesProvider::Update() {
|
||||
// look for .type fields
|
||||
wpi::StringRef eventName{event.name};
|
||||
if (!eventName.endswith("/.type") || !event.value ||
|
||||
!event.value->IsString())
|
||||
!event.value->IsString()) {
|
||||
continue;
|
||||
}
|
||||
auto tableName = eventName.drop_back(6);
|
||||
|
||||
// only handle ones where we have a builder
|
||||
auto builderIt = m_typeMap.find(event.value->GetString());
|
||||
if (builderIt == m_typeMap.end()) continue;
|
||||
if (builderIt == m_typeMap.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (event.flags & NT_NOTIFY_DELETE) {
|
||||
auto it = std::find_if(
|
||||
@@ -96,18 +101,26 @@ void NetworkTablesProvider::Update() {
|
||||
// check for visible windows that need displays (typically this is due to
|
||||
// file loading)
|
||||
for (auto&& window : m_windows) {
|
||||
if (!window->IsVisible() || window->HasView()) continue;
|
||||
if (!window->IsVisible() || window->HasView()) {
|
||||
continue;
|
||||
}
|
||||
auto id = window->GetId();
|
||||
auto typeIt = m_typeCache.find(id);
|
||||
if (typeIt == m_typeCache.end()) continue;
|
||||
if (typeIt == m_typeCache.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// only handle ones where we have a builder
|
||||
auto builderIt = m_typeMap.find(typeIt->second.GetName());
|
||||
if (builderIt == m_typeMap.end()) continue;
|
||||
if (builderIt == m_typeMap.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto entry = GetOrCreateView(
|
||||
builderIt->second, nt::GetEntry(m_nt.GetInstance(), id + "/.type"), id);
|
||||
if (entry) Show(entry, window.get());
|
||||
if (entry) {
|
||||
Show(entry, window.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,20 +138,29 @@ void NetworkTablesProvider::Show(ViewEntry* entry, Window* window) {
|
||||
}
|
||||
|
||||
// get or create model
|
||||
if (!entry->modelEntry->model)
|
||||
if (!entry->modelEntry->model) {
|
||||
entry->modelEntry->model =
|
||||
entry->modelEntry->createModel(m_nt.GetInstance(), entry->name.c_str());
|
||||
if (!entry->modelEntry->model) return;
|
||||
}
|
||||
if (!entry->modelEntry->model) {
|
||||
return;
|
||||
}
|
||||
|
||||
// the window might exist and we're just not associated to it yet
|
||||
if (!window) window = GetOrAddWindow(entry->name, true);
|
||||
if (!window) return;
|
||||
if (!window) {
|
||||
window = GetOrAddWindow(entry->name, true);
|
||||
}
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
entry->window = window;
|
||||
|
||||
// create view
|
||||
auto view = entry->createView(window, entry->modelEntry->model.get(),
|
||||
entry->name.c_str());
|
||||
if (!view) return;
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
window->SetView(std::move(view));
|
||||
|
||||
entry->window->SetVisible(true);
|
||||
|
||||
Reference in New Issue
Block a user