mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -24,9 +24,9 @@
|
||||
#include "wpi/util/raw_ostream.hpp"
|
||||
#include "wpi/util/timestamp.h"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
Context* glass::gContext;
|
||||
Context* wpi::glass::gContext;
|
||||
|
||||
static void WorkspaceResetImpl() {
|
||||
// call reset functions
|
||||
@@ -57,7 +57,7 @@ static void WorkspaceInit() {
|
||||
}
|
||||
}
|
||||
|
||||
static bool JsonToWindow(const wpi::json& jfile, const char* filename) {
|
||||
static bool JsonToWindow(const wpi::util::json& jfile, const char* filename) {
|
||||
if (!jfile.is_object()) {
|
||||
ImGui::LogText("%s top level is not object", filename);
|
||||
return false;
|
||||
@@ -65,7 +65,7 @@ static bool JsonToWindow(const wpi::json& jfile, const char* filename) {
|
||||
|
||||
// loop over JSON and generate ini format
|
||||
std::string iniStr;
|
||||
wpi::raw_string_ostream ini{iniStr};
|
||||
wpi::util::raw_string_ostream ini{iniStr};
|
||||
|
||||
for (auto&& jsection : jfile.items()) {
|
||||
if (jsection.key() == "Docking") {
|
||||
@@ -87,7 +87,7 @@ static bool JsonToWindow(const wpi::json& jfile, const char* filename) {
|
||||
try {
|
||||
auto& value = jkv.value().get_ref<const std::string&>();
|
||||
ini << jkv.key() << '=' << value << "\n";
|
||||
} catch (wpi::json::exception&) {
|
||||
} catch (wpi::util::json::exception&) {
|
||||
ImGui::LogText("%s section %s subsection %s value %s is not string",
|
||||
filename, jsection.key().c_str(),
|
||||
jsubsection.key().c_str(), jkv.key().c_str());
|
||||
@@ -112,7 +112,7 @@ static bool JsonToWindow(const wpi::json& jfile, const char* filename) {
|
||||
try {
|
||||
auto& value = jv.get_ref<const std::string&>();
|
||||
ini << value << "\n";
|
||||
} catch (wpi::json::exception&) {
|
||||
} catch (wpi::util::json::exception&) {
|
||||
ImGui::LogText("%s section %s subsection %s value is not string",
|
||||
filename, "Docking", jsubsection.key().c_str());
|
||||
return false;
|
||||
@@ -129,16 +129,16 @@ static bool JsonToWindow(const wpi::json& jfile, const char* filename) {
|
||||
}
|
||||
|
||||
static bool LoadWindowStorageImpl(const std::string& filename) {
|
||||
auto fileBuffer = wpi::MemoryBuffer::GetFile(filename);
|
||||
auto fileBuffer = wpi::util::MemoryBuffer::GetFile(filename);
|
||||
if (!fileBuffer) {
|
||||
ImGui::LogText("error opening %s: %s", filename.c_str(),
|
||||
fileBuffer.error().message().c_str());
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return JsonToWindow(wpi::json::parse(fileBuffer.value()->GetCharBuffer()),
|
||||
return JsonToWindow(wpi::util::json::parse(fileBuffer.value()->GetCharBuffer()),
|
||||
filename.c_str());
|
||||
} catch (wpi::json::parse_error& e) {
|
||||
} catch (wpi::util::json::parse_error& e) {
|
||||
ImGui::LogText("Error loading %s: %s", filename.c_str(), e.what());
|
||||
return false;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ static bool LoadWindowStorageImpl(const std::string& filename) {
|
||||
|
||||
static bool LoadStorageRootImpl(Context* ctx, const std::string& filename,
|
||||
std::string_view rootName) {
|
||||
auto fileBuffer = wpi::MemoryBuffer::GetFile(filename);
|
||||
auto fileBuffer = wpi::util::MemoryBuffer::GetFile(filename);
|
||||
if (!fileBuffer) {
|
||||
ImGui::LogText("error opening %s: %s", filename.c_str(),
|
||||
fileBuffer.error().message().c_str());
|
||||
@@ -154,9 +154,9 @@ static bool LoadStorageRootImpl(Context* ctx, const std::string& filename,
|
||||
}
|
||||
auto [it, createdStorage] = ctx->storageRoots.try_emplace(rootName);
|
||||
try {
|
||||
it->second.FromJson(wpi::json::parse(fileBuffer.value()->GetCharBuffer()),
|
||||
it->second.FromJson(wpi::util::json::parse(fileBuffer.value()->GetCharBuffer()),
|
||||
filename.c_str());
|
||||
} catch (wpi::json::parse_error& e) {
|
||||
} catch (wpi::util::json::parse_error& e) {
|
||||
ImGui::LogText("Error loading %s: %s", filename.c_str(), e.what());
|
||||
if (createdStorage) {
|
||||
ctx->storageRoots.erase(it);
|
||||
@@ -187,7 +187,7 @@ static bool LoadStorageImpl(Context* ctx, std::string_view dir,
|
||||
return rv;
|
||||
}
|
||||
|
||||
static wpi::json WindowToJson() {
|
||||
static wpi::util::json WindowToJson() {
|
||||
size_t iniLen;
|
||||
const char* iniData = ImGui::SaveIniSettingsToMemory(&iniLen);
|
||||
std::string_view ini{iniData, iniLen};
|
||||
@@ -202,30 +202,30 @@ static wpi::json WindowToJson() {
|
||||
// }
|
||||
// }
|
||||
|
||||
wpi::json out = wpi::json::object();
|
||||
wpi::json* curSection = nullptr;
|
||||
wpi::util::json out = wpi::util::json::object();
|
||||
wpi::util::json* curSection = nullptr;
|
||||
while (!ini.empty()) {
|
||||
std::string_view line;
|
||||
std::tie(line, ini) = wpi::split(ini, '\n');
|
||||
line = wpi::trim(line);
|
||||
std::tie(line, ini) = wpi::util::split(ini, '\n');
|
||||
line = wpi::util::trim(line);
|
||||
if (line.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (line[0] == '[') {
|
||||
// new section
|
||||
auto [section, subsection] = wpi::split(line, ']');
|
||||
section = wpi::drop_front(section); // drop '['; ']' was dropped by split
|
||||
subsection = wpi::drop_back(wpi::drop_front(subsection)); // drop []
|
||||
auto [section, subsection] = wpi::util::split(line, ']');
|
||||
section = wpi::util::drop_front(section); // drop '['; ']' was dropped by split
|
||||
subsection = wpi::util::drop_back(wpi::util::drop_front(subsection)); // drop []
|
||||
auto& jsection = out[section];
|
||||
if (jsection.is_null()) {
|
||||
jsection = wpi::json::object();
|
||||
jsection = wpi::util::json::object();
|
||||
}
|
||||
curSection = &jsection[subsection];
|
||||
if (curSection->is_null()) {
|
||||
if (section == "Docking") {
|
||||
*curSection = wpi::json::array();
|
||||
*curSection = wpi::util::json::array();
|
||||
} else {
|
||||
*curSection = wpi::json::object();
|
||||
*curSection = wpi::util::json::object();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -233,7 +233,7 @@ static wpi::json WindowToJson() {
|
||||
if (!curSection) {
|
||||
continue; // shouldn't happen, but just in case
|
||||
}
|
||||
auto [name, value] = wpi::split(line, '=');
|
||||
auto [name, value] = wpi::util::split(line, '=');
|
||||
if (curSection->is_object()) {
|
||||
(*curSection)[name] = value;
|
||||
} else if (curSection->is_array()) {
|
||||
@@ -247,7 +247,7 @@ static wpi::json WindowToJson() {
|
||||
|
||||
bool SaveWindowStorageImpl(const std::string& filename) {
|
||||
std::error_code ec;
|
||||
wpi::raw_fd_ostream os{filename, ec};
|
||||
wpi::util::raw_fd_ostream os{filename, ec};
|
||||
if (ec) {
|
||||
ImGui::LogText("error opening %s: %s", filename.c_str(),
|
||||
ec.message().c_str());
|
||||
@@ -261,7 +261,7 @@ bool SaveWindowStorageImpl(const std::string& filename) {
|
||||
static bool SaveStorageRootImpl(Context* ctx, const std::string& filename,
|
||||
const Storage& storage) {
|
||||
std::error_code ec;
|
||||
wpi::raw_fd_ostream os{filename, ec};
|
||||
wpi::util::raw_fd_ostream os{filename, ec};
|
||||
if (ec) {
|
||||
ImGui::LogText("error opening %s: %s", filename.c_str(),
|
||||
ec.message().c_str());
|
||||
@@ -335,7 +335,7 @@ Context::~Context() {
|
||||
wpi::gui::ConfigureCustomSaveSettings(nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
Context* glass::CreateContext() {
|
||||
Context* wpi::glass::CreateContext() {
|
||||
Context* ctx = new Context;
|
||||
if (!gContext) {
|
||||
SetCurrentContext(ctx);
|
||||
@@ -343,7 +343,7 @@ Context* glass::CreateContext() {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void glass::DestroyContext(Context* ctx) {
|
||||
void wpi::glass::DestroyContext(Context* ctx) {
|
||||
if (!ctx) {
|
||||
ctx = gContext;
|
||||
}
|
||||
@@ -353,44 +353,44 @@ void glass::DestroyContext(Context* ctx) {
|
||||
delete ctx;
|
||||
}
|
||||
|
||||
Context* glass::GetCurrentContext() {
|
||||
Context* wpi::glass::GetCurrentContext() {
|
||||
return gContext;
|
||||
}
|
||||
|
||||
void glass::SetCurrentContext(Context* ctx) {
|
||||
void wpi::glass::SetCurrentContext(Context* ctx) {
|
||||
gContext = ctx;
|
||||
}
|
||||
|
||||
void glass::ResetTime() {
|
||||
gContext->zeroTime = wpi::Now();
|
||||
void wpi::glass::ResetTime() {
|
||||
gContext->zeroTime = wpi::util::Now();
|
||||
}
|
||||
|
||||
uint64_t glass::GetZeroTime() {
|
||||
uint64_t wpi::glass::GetZeroTime() {
|
||||
return gContext->zeroTime;
|
||||
}
|
||||
|
||||
void glass::WorkspaceReset() {
|
||||
void wpi::glass::WorkspaceReset() {
|
||||
WorkspaceResetImpl();
|
||||
WorkspaceInit();
|
||||
}
|
||||
|
||||
void glass::AddWorkspaceInit(std::function<void()> init) {
|
||||
void wpi::glass::AddWorkspaceInit(std::function<void()> init) {
|
||||
if (init) {
|
||||
gContext->workspaceInit.emplace_back(std::move(init));
|
||||
}
|
||||
}
|
||||
|
||||
void glass::AddWorkspaceReset(std::function<void()> reset) {
|
||||
void wpi::glass::AddWorkspaceReset(std::function<void()> reset) {
|
||||
if (reset) {
|
||||
gContext->workspaceReset.emplace_back(std::move(reset));
|
||||
}
|
||||
}
|
||||
|
||||
void glass::SetStorageName(std::string_view name) {
|
||||
void wpi::glass::SetStorageName(std::string_view name) {
|
||||
gContext->storageName = name;
|
||||
}
|
||||
|
||||
void glass::SetStorageDir(std::string_view dir) {
|
||||
void wpi::glass::SetStorageDir(std::string_view dir) {
|
||||
if (dir.empty()) {
|
||||
gContext->storageLoadDir = ".";
|
||||
gContext->storageAutoSaveDir = ".";
|
||||
@@ -401,11 +401,11 @@ void glass::SetStorageDir(std::string_view dir) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string glass::GetStorageDir() {
|
||||
std::string wpi::glass::GetStorageDir() {
|
||||
return gContext->storageAutoSaveDir;
|
||||
}
|
||||
|
||||
bool glass::LoadStorage(std::string_view dir) {
|
||||
bool wpi::glass::LoadStorage(std::string_view dir) {
|
||||
SaveStorage();
|
||||
SetStorageDir(dir);
|
||||
WorkspaceResetImpl();
|
||||
@@ -415,24 +415,24 @@ bool glass::LoadStorage(std::string_view dir) {
|
||||
return LoadStorageImpl(gContext, dir, gContext->storageName);
|
||||
}
|
||||
|
||||
bool glass::SaveStorage() {
|
||||
bool wpi::glass::SaveStorage() {
|
||||
return SaveStorageImpl(gContext, gContext->storageAutoSaveDir,
|
||||
gContext->storageName, false);
|
||||
}
|
||||
|
||||
bool glass::SaveStorage(std::string_view dir) {
|
||||
bool wpi::glass::SaveStorage(std::string_view dir) {
|
||||
return SaveStorageImpl(gContext, dir, gContext->storageName, false);
|
||||
}
|
||||
|
||||
Storage& glass::GetCurStorageRoot() {
|
||||
Storage& wpi::glass::GetCurStorageRoot() {
|
||||
return *gContext->storageStack.front();
|
||||
}
|
||||
|
||||
Storage& glass::GetStorageRoot(std::string_view rootName) {
|
||||
Storage& wpi::glass::GetStorageRoot(std::string_view rootName) {
|
||||
return gContext->storageRoots[rootName];
|
||||
}
|
||||
|
||||
void glass::ResetStorageStack(std::string_view rootName) {
|
||||
void wpi::glass::ResetStorageStack(std::string_view rootName) {
|
||||
if (gContext->storageStack.size() != 1) {
|
||||
ImGui::LogText("resetting non-empty storage stack");
|
||||
}
|
||||
@@ -440,20 +440,20 @@ void glass::ResetStorageStack(std::string_view rootName) {
|
||||
gContext->storageStack.emplace_back(&GetStorageRoot(rootName));
|
||||
}
|
||||
|
||||
Storage& glass::GetStorage() {
|
||||
Storage& wpi::glass::GetStorage() {
|
||||
return *gContext->storageStack.back();
|
||||
}
|
||||
|
||||
void glass::PushStorageStack(std::string_view label_id) {
|
||||
void wpi::glass::PushStorageStack(std::string_view label_id) {
|
||||
gContext->storageStack.emplace_back(
|
||||
&gContext->storageStack.back()->GetChild(label_id));
|
||||
}
|
||||
|
||||
void glass::PushStorageStack(Storage& storage) {
|
||||
void wpi::glass::PushStorageStack(Storage& storage) {
|
||||
gContext->storageStack.emplace_back(&storage);
|
||||
}
|
||||
|
||||
void glass::PopStorageStack() {
|
||||
void wpi::glass::PopStorageStack() {
|
||||
if (gContext->storageStack.size() <= 1) {
|
||||
ImGui::LogText("attempted to pop empty storage stack, mismatch push/pop?");
|
||||
return; // ignore
|
||||
@@ -461,28 +461,28 @@ void glass::PopStorageStack() {
|
||||
gContext->storageStack.pop_back();
|
||||
}
|
||||
|
||||
bool glass::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) {
|
||||
bool wpi::glass::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) {
|
||||
PushStorageStack(name);
|
||||
return ImGui::Begin(name, p_open, flags);
|
||||
}
|
||||
|
||||
void glass::End() {
|
||||
void wpi::glass::End() {
|
||||
ImGui::End();
|
||||
PopStorageStack();
|
||||
}
|
||||
|
||||
bool glass::BeginChild(const char* str_id, const ImVec2& size, bool border,
|
||||
bool wpi::glass::BeginChild(const char* str_id, const ImVec2& size, bool border,
|
||||
ImGuiWindowFlags flags) {
|
||||
PushStorageStack(str_id);
|
||||
return ImGui::BeginChild(str_id, size, border, flags);
|
||||
}
|
||||
|
||||
void glass::EndChild() {
|
||||
void wpi::glass::EndChild() {
|
||||
ImGui::EndChild();
|
||||
PopStorageStack();
|
||||
}
|
||||
|
||||
bool glass::CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags) {
|
||||
bool wpi::glass::CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags) {
|
||||
bool& open = GetStorage().GetChild(label).GetBool(
|
||||
"open", (flags & ImGuiTreeNodeFlags_DefaultOpen) != 0);
|
||||
ImGui::SetNextItemOpen(open);
|
||||
@@ -490,7 +490,7 @@ bool glass::CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags) {
|
||||
return open;
|
||||
}
|
||||
|
||||
bool glass::TreeNodeEx(const char* label, ImGuiTreeNodeFlags flags) {
|
||||
bool wpi::glass::TreeNodeEx(const char* label, ImGuiTreeNodeFlags flags) {
|
||||
PushStorageStack(label);
|
||||
bool& open = GetStorage().GetBool(
|
||||
"open", (flags & ImGuiTreeNodeFlags_DefaultOpen) != 0);
|
||||
@@ -502,35 +502,35 @@ bool glass::TreeNodeEx(const char* label, ImGuiTreeNodeFlags flags) {
|
||||
return open;
|
||||
}
|
||||
|
||||
void glass::TreePop() {
|
||||
void wpi::glass::TreePop() {
|
||||
ImGui::TreePop();
|
||||
PopStorageStack();
|
||||
}
|
||||
|
||||
void glass::PushID(const char* str_id) {
|
||||
void wpi::glass::PushID(const char* str_id) {
|
||||
PushStorageStack(str_id);
|
||||
ImGui::PushID(str_id);
|
||||
}
|
||||
|
||||
void glass::PushID(const char* str_id_begin, const char* str_id_end) {
|
||||
void wpi::glass::PushID(const char* str_id_begin, const char* str_id_end) {
|
||||
PushStorageStack(std::string_view(str_id_begin, str_id_end - str_id_begin));
|
||||
ImGui::PushID(str_id_begin, str_id_end);
|
||||
}
|
||||
|
||||
void glass::PushID(int int_id) {
|
||||
void wpi::glass::PushID(int int_id) {
|
||||
char buf[16];
|
||||
wpi::format_to_n_c_str(buf, sizeof(buf), "{}", int_id);
|
||||
wpi::util::format_to_n_c_str(buf, sizeof(buf), "{}", int_id);
|
||||
|
||||
PushStorageStack(buf);
|
||||
ImGui::PushID(int_id);
|
||||
}
|
||||
|
||||
void glass::PopID() {
|
||||
void wpi::glass::PopID() {
|
||||
ImGui::PopID();
|
||||
PopStorageStack();
|
||||
}
|
||||
|
||||
bool glass::PopupEditName(const char* label, std::string* name) {
|
||||
bool wpi::glass::PopupEditName(const char* label, std::string* name) {
|
||||
bool rv = false;
|
||||
if (ImGui::BeginPopupContextItem(label)) {
|
||||
rv = ItemEditName(name);
|
||||
@@ -540,7 +540,7 @@ bool glass::PopupEditName(const char* label, std::string* name) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool glass::ItemEditName(std::string* name) {
|
||||
bool wpi::glass::ItemEditName(std::string* name) {
|
||||
bool rv = false;
|
||||
|
||||
ImGui::Text("Edit name:");
|
||||
|
||||
@@ -12,15 +12,15 @@
|
||||
|
||||
#include "wpi/glass/ContextInternal.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
wpi::sig::Signal<const char*, DataSource*> DataSource::sourceCreated;
|
||||
wpi::util::sig::Signal<const char*, DataSource*> DataSource::sourceCreated;
|
||||
|
||||
std::string glass::MakeSourceId(std::string_view id, int index) {
|
||||
std::string wpi::glass::MakeSourceId(std::string_view id, int index) {
|
||||
return fmt::format("{}[{}]", id, index);
|
||||
}
|
||||
|
||||
std::string glass::MakeSourceId(std::string_view id, int index, int index2) {
|
||||
std::string wpi::glass::MakeSourceId(std::string_view id, int index, int index2) {
|
||||
return fmt::format("{}[{},{}]", id, index, index2);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "wpi/gui/wpigui.hpp"
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void MainMenuBar::AddMainMenu(std::function<void()> menu) {
|
||||
if (menu) {
|
||||
@@ -54,7 +54,7 @@ void MainMenuBar::Display() {
|
||||
|
||||
#if 0
|
||||
char str[64];
|
||||
wpi::format_to_n_c_str(str, sizeof(str), "{:.3f} ms/frame ({:.1f} FPS)",
|
||||
wpi::util::format_to_n_c_str(str, sizeof(str), "{:.3f} ms/frame ({:.1f} FPS)",
|
||||
1000.0f / ImGui::GetIO().Framerate,
|
||||
ImGui::GetIO().Framerate);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "wpi/glass/Model.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
bool Model::IsReadOnly() {
|
||||
return false;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
#include "wpi/util/json.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
template <typename To>
|
||||
bool ConvertFromString(To* out, std::string_view str) {
|
||||
@@ -24,19 +24,19 @@ bool ConvertFromString(To* out, std::string_view str) {
|
||||
*out = true;
|
||||
} else if (str == "false") {
|
||||
*out = false;
|
||||
} else if (auto val = wpi::parse_integer<int>(str, 10)) {
|
||||
} else if (auto val = wpi::util::parse_integer<int>(str, 10)) {
|
||||
*out = val.value() != 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if constexpr (std::floating_point<To>) {
|
||||
if (auto val = wpi::parse_float<To>(str)) {
|
||||
if (auto val = wpi::util::parse_float<To>(str)) {
|
||||
*out = val.value();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (auto val = wpi::parse_integer<To>(str, 10)) {
|
||||
if (auto val = wpi::util::parse_integer<To>(str, 10)) {
|
||||
*out = val.value();
|
||||
} else {
|
||||
return false;
|
||||
@@ -300,7 +300,7 @@ DEFUN(Double, double, double, double, double)
|
||||
DEFUN(String, string, std::string, std::string_view, std::string)
|
||||
|
||||
Storage& Storage::GetChild(std::string_view label_id) {
|
||||
auto [label, id] = wpi::split(label_id, "###");
|
||||
auto [label, id] = wpi::util::split(label_id, "###");
|
||||
if (id.empty()) {
|
||||
id = label;
|
||||
}
|
||||
@@ -345,9 +345,9 @@ void Storage::EraseChildren() {
|
||||
});
|
||||
}
|
||||
|
||||
static bool JsonArrayToStorage(Storage::Value* valuePtr, const wpi::json& jarr,
|
||||
static bool JsonArrayToStorage(Storage::Value* valuePtr, const wpi::util::json& jarr,
|
||||
const char* filename) {
|
||||
auto& arr = jarr.get_ref<const wpi::json::array_t&>();
|
||||
auto& arr = jarr.get_ref<const wpi::util::json::array_t&>();
|
||||
if (arr.empty()) {
|
||||
ImGui::LogText("empty array in %s, ignoring", filename);
|
||||
return false;
|
||||
@@ -355,42 +355,42 @@ static bool JsonArrayToStorage(Storage::Value* valuePtr, const wpi::json& jarr,
|
||||
|
||||
// guess array type from first element
|
||||
switch (arr[0].type()) {
|
||||
case wpi::json::value_t::boolean:
|
||||
case wpi::util::json::value_t::boolean:
|
||||
if (valuePtr->type != Storage::Value::kBoolArray) {
|
||||
valuePtr->Reset(Storage::Value::kBoolArray);
|
||||
valuePtr->boolArray = new std::vector<int>();
|
||||
valuePtr->boolArrayDefault = nullptr;
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::number_float:
|
||||
case wpi::util::json::value_t::number_float:
|
||||
if (valuePtr->type != Storage::Value::kDoubleArray) {
|
||||
valuePtr->Reset(Storage::Value::kDoubleArray);
|
||||
valuePtr->doubleArray = new std::vector<double>();
|
||||
valuePtr->doubleArrayDefault = nullptr;
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::number_integer:
|
||||
case wpi::json::value_t::number_unsigned:
|
||||
case wpi::util::json::value_t::number_integer:
|
||||
case wpi::util::json::value_t::number_unsigned:
|
||||
if (valuePtr->type != Storage::Value::kInt64Array) {
|
||||
valuePtr->Reset(Storage::Value::kInt64Array);
|
||||
valuePtr->int64Array = new std::vector<int64_t>();
|
||||
valuePtr->int64ArrayDefault = nullptr;
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::string:
|
||||
case wpi::util::json::value_t::string:
|
||||
if (valuePtr->type != Storage::Value::kStringArray) {
|
||||
valuePtr->Reset(Storage::Value::kStringArray);
|
||||
valuePtr->stringArray = new std::vector<std::string>();
|
||||
valuePtr->stringArrayDefault = nullptr;
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::object:
|
||||
case wpi::util::json::value_t::object:
|
||||
if (valuePtr->type != Storage::Value::kChildArray) {
|
||||
valuePtr->Reset(Storage::Value::kChildArray);
|
||||
valuePtr->childArray = new std::vector<std::unique_ptr<Storage>>();
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::array:
|
||||
case wpi::util::json::value_t::array:
|
||||
ImGui::LogText("nested array in %s, ignoring", filename);
|
||||
return false;
|
||||
default:
|
||||
@@ -401,21 +401,21 @@ static bool JsonArrayToStorage(Storage::Value* valuePtr, const wpi::json& jarr,
|
||||
// loop over array to store elements
|
||||
for (auto jvalue : arr) {
|
||||
switch (jvalue.type()) {
|
||||
case wpi::json::value_t::boolean:
|
||||
case wpi::util::json::value_t::boolean:
|
||||
if (valuePtr->type == Storage::Value::kBoolArray) {
|
||||
valuePtr->boolArray->push_back(jvalue.get<bool>());
|
||||
} else {
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::number_float:
|
||||
case wpi::util::json::value_t::number_float:
|
||||
if (valuePtr->type == Storage::Value::kDoubleArray) {
|
||||
valuePtr->doubleArray->push_back(jvalue.get<double>());
|
||||
} else {
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::number_integer:
|
||||
case wpi::util::json::value_t::number_integer:
|
||||
if (valuePtr->type == Storage::Value::kInt64Array) {
|
||||
valuePtr->int64Array->push_back(jvalue.get<int64_t>());
|
||||
} else if (valuePtr->type == Storage::Value::kDoubleArray) {
|
||||
@@ -424,7 +424,7 @@ static bool JsonArrayToStorage(Storage::Value* valuePtr, const wpi::json& jarr,
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::number_unsigned:
|
||||
case wpi::util::json::value_t::number_unsigned:
|
||||
if (valuePtr->type == Storage::Value::kInt64Array) {
|
||||
valuePtr->int64Array->push_back(jvalue.get<uint64_t>());
|
||||
} else if (valuePtr->type == Storage::Value::kDoubleArray) {
|
||||
@@ -433,7 +433,7 @@ static bool JsonArrayToStorage(Storage::Value* valuePtr, const wpi::json& jarr,
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::string:
|
||||
case wpi::util::json::value_t::string:
|
||||
if (valuePtr->type == Storage::Value::kStringArray) {
|
||||
valuePtr->stringArray->emplace_back(
|
||||
jvalue.get_ref<const std::string&>());
|
||||
@@ -441,7 +441,7 @@ static bool JsonArrayToStorage(Storage::Value* valuePtr, const wpi::json& jarr,
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::object:
|
||||
case wpi::util::json::value_t::object:
|
||||
if (valuePtr->type == Storage::Value::kChildArray) {
|
||||
valuePtr->childArray->emplace_back(std::make_unique<Storage>());
|
||||
valuePtr->childArray->back()->FromJson(jvalue, filename);
|
||||
@@ -449,7 +449,7 @@ static bool JsonArrayToStorage(Storage::Value* valuePtr, const wpi::json& jarr,
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case wpi::json::value_t::array:
|
||||
case wpi::util::json::value_t::array:
|
||||
ImGui::LogText("nested array in %s, ignoring", filename);
|
||||
return false;
|
||||
default:
|
||||
@@ -464,7 +464,7 @@ error:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Storage::FromJson(const wpi::json& json, const char* filename) {
|
||||
bool Storage::FromJson(const wpi::util::json& json, const char* filename) {
|
||||
if (m_fromJson) {
|
||||
return m_fromJson(json, filename);
|
||||
}
|
||||
@@ -482,34 +482,34 @@ bool Storage::FromJson(const wpi::json& json, const char* filename) {
|
||||
}
|
||||
auto& jvalue = jkv.value();
|
||||
switch (jvalue.type()) {
|
||||
case wpi::json::value_t::boolean:
|
||||
case wpi::util::json::value_t::boolean:
|
||||
valuePtr->Reset(Value::kBool);
|
||||
valuePtr->boolVal = jvalue.get<bool>();
|
||||
break;
|
||||
case wpi::json::value_t::number_float:
|
||||
case wpi::util::json::value_t::number_float:
|
||||
valuePtr->Reset(Value::kDouble);
|
||||
valuePtr->doubleVal = jvalue.get<double>();
|
||||
break;
|
||||
case wpi::json::value_t::number_integer:
|
||||
case wpi::util::json::value_t::number_integer:
|
||||
valuePtr->Reset(Value::kInt64);
|
||||
valuePtr->int64Val = jvalue.get<int64_t>();
|
||||
break;
|
||||
case wpi::json::value_t::number_unsigned:
|
||||
case wpi::util::json::value_t::number_unsigned:
|
||||
valuePtr->Reset(Value::kInt64);
|
||||
valuePtr->int64Val = jvalue.get<uint64_t>();
|
||||
break;
|
||||
case wpi::json::value_t::string:
|
||||
case wpi::util::json::value_t::string:
|
||||
valuePtr->Reset(Value::kString);
|
||||
valuePtr->stringVal = jvalue.get_ref<const std::string&>();
|
||||
break;
|
||||
case wpi::json::value_t::object:
|
||||
case wpi::util::json::value_t::object:
|
||||
if (valuePtr->type != Value::kChild) {
|
||||
valuePtr->Reset(Value::kChild);
|
||||
valuePtr->child = new Storage;
|
||||
}
|
||||
valuePtr->child->FromJson(jvalue, filename); // recurse
|
||||
break;
|
||||
case wpi::json::value_t::array:
|
||||
case wpi::util::json::value_t::array:
|
||||
if (!JsonArrayToStorage(valuePtr.get(), jvalue, filename)) {
|
||||
if (created) {
|
||||
m_values.erase(jkv.key());
|
||||
@@ -528,8 +528,8 @@ bool Storage::FromJson(const wpi::json& json, const char* filename) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static wpi::json StorageToJsonArray(const std::vector<T>& arr) {
|
||||
wpi::json jarr = wpi::json::array();
|
||||
static wpi::util::json StorageToJsonArray(const std::vector<T>& arr) {
|
||||
wpi::util::json jarr = wpi::util::json::array();
|
||||
for (auto&& v : arr) {
|
||||
jarr.emplace_back(v);
|
||||
}
|
||||
@@ -537,27 +537,27 @@ static wpi::json StorageToJsonArray(const std::vector<T>& arr) {
|
||||
}
|
||||
|
||||
template <>
|
||||
wpi::json StorageToJsonArray<std::unique_ptr<Storage>>(
|
||||
wpi::util::json StorageToJsonArray<std::unique_ptr<Storage>>(
|
||||
const std::vector<std::unique_ptr<Storage>>& arr) {
|
||||
wpi::json jarr = wpi::json::array();
|
||||
wpi::util::json jarr = wpi::util::json::array();
|
||||
for (auto&& v : arr) {
|
||||
jarr.emplace_back(v->ToJson());
|
||||
}
|
||||
// remove any trailing empty items
|
||||
while (!jarr.empty() && jarr.back().empty()) {
|
||||
jarr.get_ref<wpi::json::array_t&>().pop_back();
|
||||
jarr.get_ref<wpi::util::json::array_t&>().pop_back();
|
||||
}
|
||||
return jarr;
|
||||
}
|
||||
|
||||
wpi::json Storage::ToJson() const {
|
||||
wpi::util::json Storage::ToJson() const {
|
||||
if (m_toJson) {
|
||||
return m_toJson();
|
||||
}
|
||||
|
||||
wpi::json j = wpi::json::object();
|
||||
wpi::util::json j = wpi::util::json::object();
|
||||
for (auto&& kv : m_values) {
|
||||
wpi::json jelem;
|
||||
wpi::util::json jelem;
|
||||
auto& value = *kv.second;
|
||||
switch (value.type) {
|
||||
#define CASE(CapsName, LowerName) \
|
||||
|
||||
@@ -7,23 +7,23 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
namespace {
|
||||
class FunctionView : public View {
|
||||
public:
|
||||
explicit FunctionView(wpi::unique_function<void()> display)
|
||||
explicit FunctionView(wpi::util::unique_function<void()> display)
|
||||
: m_display(std::move(display)) {}
|
||||
|
||||
void Display() override { m_display(); }
|
||||
|
||||
private:
|
||||
wpi::unique_function<void()> m_display;
|
||||
wpi::util::unique_function<void()> m_display;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<View> glass::MakeFunctionView(
|
||||
wpi::unique_function<void()> display) {
|
||||
std::unique_ptr<View> wpi::glass::MakeFunctionView(
|
||||
wpi::util::unique_function<void()> display) {
|
||||
return std::make_unique<FunctionView>(std::move(display));
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "wpi/glass/Storage.hpp"
|
||||
#include "wpi/glass/support/ExtraGuiWidgets.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
Window::Window(Storage& storage, std::string_view id,
|
||||
Visibility defaultVisibility)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "wpi/gui/wpigui.hpp"
|
||||
#include "wpi/util/print.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
WindowManager::WindowManager(Storage& storage) : m_storage{storage} {
|
||||
storage.SetCustomApply([this] {
|
||||
@@ -27,14 +27,14 @@ WindowManager::WindowManager(Storage& storage) : m_storage{storage} {
|
||||
}
|
||||
|
||||
Window* WindowManager::AddWindow(std::string_view id,
|
||||
wpi::unique_function<void()> display,
|
||||
wpi::util::unique_function<void()> display,
|
||||
Window::Visibility defaultVisibility) {
|
||||
auto win = GetOrAddWindow(id, false, defaultVisibility);
|
||||
if (!win) {
|
||||
return nullptr;
|
||||
}
|
||||
if (win->HasView()) {
|
||||
wpi::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
wpi::util::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
return nullptr;
|
||||
}
|
||||
win->SetView(MakeFunctionView(std::move(display)));
|
||||
@@ -49,7 +49,7 @@ Window* WindowManager::AddWindow(std::string_view id,
|
||||
return nullptr;
|
||||
}
|
||||
if (win->HasView()) {
|
||||
wpi::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
wpi::util::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
return nullptr;
|
||||
}
|
||||
win->SetView(std::move(view));
|
||||
@@ -64,7 +64,7 @@ Window* WindowManager::GetOrAddWindow(std::string_view id, bool duplicateOk,
|
||||
[](const auto& elem, std::string_view s) { return elem->GetId() < s; });
|
||||
if (it != m_windows.end() && (*it)->GetId() == id) {
|
||||
if (!duplicateOk) {
|
||||
wpi::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
wpi::util::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
return nullptr;
|
||||
}
|
||||
return it->get();
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#include "wpi/glass/Storage.hpp"
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayAnalogInput(AnalogInputModel* model, int index) {
|
||||
void wpi::glass::DisplayAnalogInput(AnalogInputModel* model, int index) {
|
||||
auto voltageData = model->GetVoltageData();
|
||||
if (!voltageData) {
|
||||
return;
|
||||
@@ -25,9 +25,9 @@ void glass::DisplayAnalogInput(AnalogInputModel* model, int index) {
|
||||
std::string& name = GetStorage().GetString("name");
|
||||
char label[128];
|
||||
if (!name.empty()) {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{} [{}]###name", name, index);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{}]###name", name, index);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "In[{}]###name", index);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "In[{}]###name", index);
|
||||
}
|
||||
|
||||
if (auto simDevice = model->GetSimDevice()) {
|
||||
@@ -47,7 +47,7 @@ void glass::DisplayAnalogInput(AnalogInputModel* model, int index) {
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayAnalogInputs(AnalogInputsModel* model,
|
||||
void wpi::glass::DisplayAnalogInputs(AnalogInputsModel* model,
|
||||
std::string_view noneMsg) {
|
||||
ImGui::Text("(Use Ctrl+Click to edit value)");
|
||||
bool hasAny = false;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "wpi/glass/hardware/Encoder.hpp"
|
||||
#include "wpi/glass/support/NameSetting.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
static void LabelSimDevice(const char* name, const char* simDeviceName) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));
|
||||
@@ -99,13 +99,13 @@ void DisplayDIOImpl(DIOModel* model, int index, bool outputsEnabled) {
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayDIO(DIOModel* model, int index, bool outputsEnabled) {
|
||||
void wpi::glass::DisplayDIO(DIOModel* model, int index, bool outputsEnabled) {
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
|
||||
DisplayDIOImpl(model, index, outputsEnabled);
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
|
||||
void glass::DisplayDIOs(DIOsModel* model, bool outputsEnabled,
|
||||
void wpi::glass::DisplayDIOs(DIOsModel* model, bool outputsEnabled,
|
||||
std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "wpi/glass/Storage.hpp"
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void EncoderModel::SetName(std::string_view name) {
|
||||
if (name.empty()) {
|
||||
@@ -58,7 +58,7 @@ void EncoderModel::SetName(std::string_view name) {
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayEncoder(EncoderModel* model) {
|
||||
void wpi::glass::DisplayEncoder(EncoderModel* model) {
|
||||
if (auto simDevice = model->GetSimDevice()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));
|
||||
ImGui::TextUnformatted(simDevice);
|
||||
@@ -73,10 +73,10 @@ void glass::DisplayEncoder(EncoderModel* model) {
|
||||
std::string& name = GetStorage().GetString("name");
|
||||
char label[128];
|
||||
if (!name.empty()) {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{} [{},{}]###header", name,
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{},{}]###header", name,
|
||||
chA, chB);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "Encoder[{},{}]###header", chA,
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "Encoder[{},{}]###header", chA,
|
||||
chB);
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ void glass::DisplayEncoder(EncoderModel* model) {
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
|
||||
void glass::DisplayEncoders(EncodersModel* model, std::string_view noneMsg) {
|
||||
void wpi::glass::DisplayEncoders(EncodersModel* model, std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
model->ForEachEncoder([&](EncoderModel& encoder, int i) {
|
||||
hasAny = true;
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
#include "wpi/glass/DataSource.hpp"
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayGyro(GyroModel* m) {
|
||||
void wpi::glass::DisplayGyro(GyroModel* m) {
|
||||
ImColor primaryColor = ImGui::GetStyle().Colors[ImGuiCol_Text];
|
||||
ImColor disabledColor = ImGui::GetStyle().Colors[ImGuiCol_TextDisabled];
|
||||
ImColor secondaryColor = ImGui::GetStyle().Colors[ImGuiCol_Header];
|
||||
@@ -64,7 +64,7 @@ void glass::DisplayGyro(GyroModel* m) {
|
||||
color, 1.2f);
|
||||
if (major) {
|
||||
char txt[16];
|
||||
wpi::format_to_n_c_str(txt, sizeof(txt), "{}°", i);
|
||||
wpi::util::format_to_n_c_str(txt, sizeof(txt), "{}°", i);
|
||||
|
||||
draw->AddText(
|
||||
center + (direction * radius * 1.25) - ImGui::CalcTextSize(txt) * 0.5,
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "wpi/glass/support/ExtraGuiWidgets.hpp"
|
||||
#include "wpi/util/SmallVector.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
namespace {
|
||||
struct IndicatorData {
|
||||
@@ -20,8 +20,8 @@ struct IndicatorData {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
void glass::DisplayLEDDisplay(LEDDisplayModel* model, int index) {
|
||||
wpi::SmallVector<LEDDisplayModel::Data, 64> dataBuf;
|
||||
void wpi::glass::DisplayLEDDisplay(LEDDisplayModel* model, int index) {
|
||||
wpi::util::SmallVector<LEDDisplayModel::Data, 64> dataBuf;
|
||||
auto data = model->GetData(dataBuf);
|
||||
int length = data.size();
|
||||
auto& storage = GetStorage();
|
||||
@@ -75,7 +75,7 @@ void glass::DisplayLEDDisplay(LEDDisplayModel* model, int index) {
|
||||
config);
|
||||
}
|
||||
|
||||
void glass::DisplayLEDDisplays(LEDDisplaysModel* model) {
|
||||
void wpi::glass::DisplayLEDDisplays(LEDDisplaysModel* model) {
|
||||
bool hasAny = false;
|
||||
|
||||
model->ForEachLEDDisplay([&](LEDDisplayModel& display, int i) {
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
#include "wpi/glass/DataSource.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayMotorController(MotorControllerModel* m) {
|
||||
void wpi::glass::DisplayMotorController(MotorControllerModel* m) {
|
||||
// Get duty cycle data from the model and do not display anything if the data
|
||||
// is null.
|
||||
auto dc = m->GetPercentData();
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#include "wpi/glass/Storage.hpp"
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayPWM(PWMModel* model, int index, bool outputsEnabled) {
|
||||
void wpi::glass::DisplayPWM(PWMModel* model, int index, bool outputsEnabled) {
|
||||
auto data = model->GetSpeedData();
|
||||
if (!data) {
|
||||
return;
|
||||
@@ -25,9 +25,9 @@ void glass::DisplayPWM(PWMModel* model, int index, bool outputsEnabled) {
|
||||
std::string& name = GetStorage().GetString("name");
|
||||
char label[128];
|
||||
if (!name.empty()) {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{} [{}]###name", name, index);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{}]###name", name, index);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "PWM[{}]###name", index);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "PWM[{}]###name", index);
|
||||
}
|
||||
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
||||
@@ -38,7 +38,7 @@ void glass::DisplayPWM(PWMModel* model, int index, bool outputsEnabled) {
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayPWMs(PWMsModel* model, bool outputsEnabled,
|
||||
void wpi::glass::DisplayPWMs(PWMsModel* model, bool outputsEnabled,
|
||||
std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
bool first = true;
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
#include "wpi/util/SmallVector.hpp"
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
bool glass::DisplayPneumaticControlSolenoids(PneumaticControlModel* model,
|
||||
bool wpi::glass::DisplayPneumaticControlSolenoids(PneumaticControlModel* model,
|
||||
int index, bool outputsEnabled) {
|
||||
wpi::SmallVector<int, 16> channels;
|
||||
wpi::util::SmallVector<int, 16> channels;
|
||||
model->ForEachSolenoid([&](SolenoidModel& solenoid, int j) {
|
||||
if (auto data = solenoid.GetOutputData()) {
|
||||
if (j >= static_cast<int>(channels.size())) {
|
||||
@@ -48,10 +48,10 @@ bool glass::DisplayPneumaticControlSolenoids(PneumaticControlModel* model,
|
||||
std::string& name = GetStorage().GetString("name");
|
||||
char label[128];
|
||||
if (!name.empty()) {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{} [{}]###header", name,
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{} [{}]###header", name,
|
||||
index);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{}[{}]###header",
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}[{}]###header",
|
||||
model->GetName(), index);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ bool glass::DisplayPneumaticControlSolenoids(PneumaticControlModel* model,
|
||||
return true;
|
||||
}
|
||||
|
||||
void glass::DisplayPneumaticControlsSolenoids(PneumaticControlsModel* model,
|
||||
void wpi::glass::DisplayPneumaticControlsSolenoids(PneumaticControlsModel* model,
|
||||
bool outputsEnabled,
|
||||
std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
@@ -105,13 +105,13 @@ void glass::DisplayPneumaticControlsSolenoids(PneumaticControlsModel* model,
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayCompressorDevice(CompressorModel* model, int index,
|
||||
void wpi::glass::DisplayCompressorDevice(CompressorModel* model, int index,
|
||||
bool outputsEnabled) {
|
||||
if (!model || !model->Exists()) {
|
||||
return;
|
||||
}
|
||||
char name[32];
|
||||
wpi::format_to_n_c_str(name, sizeof(name), "Compressor[{}]", index);
|
||||
wpi::util::format_to_n_c_str(name, sizeof(name), "Compressor[{}]", index);
|
||||
|
||||
if (BeginDevice(name)) {
|
||||
// output enabled
|
||||
@@ -154,7 +154,7 @@ void glass::DisplayCompressorDevice(CompressorModel* model, int index,
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayCompressorsDevice(PneumaticControlsModel* model,
|
||||
void wpi::glass::DisplayCompressorsDevice(PneumaticControlsModel* model,
|
||||
bool outputsEnabled) {
|
||||
model->ForEachPneumaticControl(
|
||||
[&](PneumaticControlModel& pneumaticControl, int i) {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "wpi/glass/support/NameSetting.hpp"
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
static float DisplayChannel(PowerDistributionModel& pdp, int channel) {
|
||||
float width = 0;
|
||||
@@ -34,9 +34,9 @@ static float DisplayChannel(PowerDistributionModel& pdp, int channel) {
|
||||
return width;
|
||||
}
|
||||
|
||||
void glass::DisplayPowerDistribution(PowerDistributionModel* model, int index) {
|
||||
void wpi::glass::DisplayPowerDistribution(PowerDistributionModel* model, int index) {
|
||||
char name[128];
|
||||
wpi::format_to_n_c_str(name, sizeof(name), "PowerDistribution[{}]", index);
|
||||
wpi::util::format_to_n_c_str(name, sizeof(name), "PowerDistribution[{}]", index);
|
||||
|
||||
if (CollapsingHeader(name)) {
|
||||
// temperature
|
||||
@@ -80,7 +80,7 @@ void glass::DisplayPowerDistribution(PowerDistributionModel* model, int index) {
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayPowerDistributions(PowerDistributionsModel* model,
|
||||
void wpi::glass::DisplayPowerDistributions(PowerDistributionsModel* model,
|
||||
std::string_view noneMsg) {
|
||||
bool hasAny = false;
|
||||
model->ForEachPowerDistribution([&](PowerDistributionModel& pdp, int i) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "wpi/glass/Context.hpp"
|
||||
#include "wpi/glass/DataSource.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
static void DisplayRail(RoboRioRailModel& rail, const char* name) {
|
||||
if (CollapsingHeader(name)) {
|
||||
@@ -46,7 +46,7 @@ static void DisplayRail(RoboRioRailModel& rail, const char* name) {
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayRoboRio(RoboRioModel* model) {
|
||||
void wpi::glass::DisplayRoboRio(RoboRioModel* model) {
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
|
||||
|
||||
if (CollapsingHeader("RoboRIO Input")) {
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
#include <IconsFontAwesome6.h>
|
||||
#include <imgui.h>
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayAlerts(AlertsModel* model) {
|
||||
void wpi::glass::DisplayAlerts(AlertsModel* model) {
|
||||
auto& infos = model->GetInfos();
|
||||
auto& warnings = model->GetWarnings();
|
||||
auto& errors = model->GetErrors();
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#include "wpi/glass/Context.hpp"
|
||||
#include "wpi/glass/DataSource.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayCommandScheduler(CommandSchedulerModel* m) {
|
||||
void wpi::glass::DisplayCommandScheduler(CommandSchedulerModel* m) {
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 20);
|
||||
ImGui::Text("Scheduled Commands: ");
|
||||
ImGui::Separator();
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
#include "wpi/glass/DataSource.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayCommandSelector(CommandSelectorModel* m) {
|
||||
void wpi::glass::DisplayCommandSelector(CommandSelectorModel* m) {
|
||||
if (auto name = m->GetName()) {
|
||||
ImGui::Text("%s", name);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "wpi/glass/DataSource.hpp"
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void DeviceTreeModel::Update() {
|
||||
for (auto&& display : m_displays) {
|
||||
@@ -41,11 +41,11 @@ void DeviceTreeModel::Display() {
|
||||
}
|
||||
}
|
||||
|
||||
void glass::HideDevice(const char* id) {
|
||||
void wpi::glass::HideDevice(const char* id) {
|
||||
gContext->deviceHidden[id] = true;
|
||||
}
|
||||
|
||||
bool glass::BeginDevice(const char* id, ImGuiTreeNodeFlags flags) {
|
||||
bool wpi::glass::BeginDevice(const char* id, ImGuiTreeNodeFlags flags) {
|
||||
if (gContext->deviceHidden[id]) {
|
||||
return false;
|
||||
}
|
||||
@@ -56,9 +56,9 @@ bool glass::BeginDevice(const char* id, ImGuiTreeNodeFlags flags) {
|
||||
std::string& name = GetStorage().GetString("name");
|
||||
char label[128];
|
||||
if (name.empty()) {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{}###header", id);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###header", id);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{}###header", name);
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###header", name);
|
||||
}
|
||||
|
||||
bool open = CollapsingHeader(label, flags);
|
||||
@@ -70,7 +70,7 @@ bool glass::BeginDevice(const char* id, ImGuiTreeNodeFlags flags) {
|
||||
return open;
|
||||
}
|
||||
|
||||
void glass::EndDevice() {
|
||||
void wpi::glass::EndDevice() {
|
||||
PopID();
|
||||
}
|
||||
|
||||
@@ -150,29 +150,29 @@ static inline bool DeviceValueImpl(const char* name, bool readonly,
|
||||
}
|
||||
}
|
||||
|
||||
bool glass::DeviceBoolean(const char* name, bool readonly, bool* value,
|
||||
bool wpi::glass::DeviceBoolean(const char* name, bool readonly, bool* value,
|
||||
const DataSource* source) {
|
||||
return DeviceValueImpl(name, readonly, source, DeviceBooleanImpl, value);
|
||||
}
|
||||
|
||||
bool glass::DeviceDouble(const char* name, bool readonly, double* value,
|
||||
bool wpi::glass::DeviceDouble(const char* name, bool readonly, double* value,
|
||||
const DataSource* source) {
|
||||
return DeviceValueImpl(name, readonly, source, DeviceDoubleImpl, value);
|
||||
}
|
||||
|
||||
bool glass::DeviceEnum(const char* name, bool readonly, int* value,
|
||||
bool wpi::glass::DeviceEnum(const char* name, bool readonly, int* value,
|
||||
const char** options, int32_t numOptions,
|
||||
const DataSource* source) {
|
||||
return DeviceValueImpl(name, readonly, source, DeviceEnumImpl, value, options,
|
||||
numOptions);
|
||||
}
|
||||
|
||||
bool glass::DeviceInt(const char* name, bool readonly, int32_t* value,
|
||||
bool wpi::glass::DeviceInt(const char* name, bool readonly, int32_t* value,
|
||||
const DataSource* source) {
|
||||
return DeviceValueImpl(name, readonly, source, DeviceIntImpl, value);
|
||||
}
|
||||
|
||||
bool glass::DeviceLong(const char* name, bool readonly, int64_t* value,
|
||||
bool wpi::glass::DeviceLong(const char* name, bool readonly, int64_t* value,
|
||||
const DataSource* source) {
|
||||
return DeviceValueImpl(name, readonly, source, DeviceLongImpl, value);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
|
||||
#include "wpi/glass/DataSource.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayDrive(DriveModel* m) {
|
||||
void wpi::glass::DisplayDrive(DriveModel* m) {
|
||||
// Check if the model exists.
|
||||
if (!m->Exists()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
#include "wpi/glass/DataSource.hpp"
|
||||
#include "wpi/util/SmallString.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
static const char* stations[] = {"Invalid", "Red 1", "Red 2", "Red 3",
|
||||
"Blue 1", "Blue 2", "Blue 3"};
|
||||
|
||||
void glass::DisplayFMS(FMSModel* model, bool editableDsAttached) {
|
||||
void wpi::glass::DisplayFMS(FMSModel* model, bool editableDsAttached) {
|
||||
if (!model->Exists() || model->IsReadOnly()) {
|
||||
return DisplayFMSReadOnly(model);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ void glass::DisplayFMS(FMSModel* model, bool editableDsAttached) {
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayFMSReadOnly(FMSModel* model) {
|
||||
void wpi::glass::DisplayFMSReadOnly(FMSModel* model) {
|
||||
bool exists = model->Exists();
|
||||
if (!exists) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));
|
||||
@@ -150,7 +150,7 @@ void glass::DisplayFMSReadOnly(FMSModel* model) {
|
||||
}
|
||||
if (auto data = model->GetGameSpecificMessageData()) {
|
||||
if (exists) {
|
||||
wpi::SmallString<64> gsmBuf;
|
||||
wpi::util::SmallString<64> gsmBuf;
|
||||
std::string_view gsm = data->GetValue(gsmBuf);
|
||||
ImGui::Text("Game Specific: %.*s", static_cast<int>(gsm.size()),
|
||||
gsm.data());
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "wpi/util/json.hpp"
|
||||
#include "wpi/util/print.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
namespace gui = wpi::gui;
|
||||
|
||||
@@ -47,12 +47,12 @@ enum DisplayUnits { kDisplayMeters = 0, kDisplayFeet, kDisplayInches };
|
||||
|
||||
// Per-frame field data (not persistent)
|
||||
struct FieldFrameData {
|
||||
frc::Translation2d GetPosFromScreen(const ImVec2& cursor) const {
|
||||
wpi::math::Translation2d GetPosFromScreen(const ImVec2& cursor) const {
|
||||
return {
|
||||
units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) / scale},
|
||||
units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) / scale}};
|
||||
wpi::units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) / scale},
|
||||
wpi::units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) / scale}};
|
||||
}
|
||||
ImVec2 GetScreenFromPos(const frc::Translation2d& pos) const {
|
||||
ImVec2 GetScreenFromPos(const wpi::math::Translation2d& pos) const {
|
||||
return {min.x + scale * pos.X().to<float>(),
|
||||
max.y - scale * pos.Y().to<float>()};
|
||||
}
|
||||
@@ -71,7 +71,7 @@ struct SelectedTargetInfo {
|
||||
FieldObjectModel* objModel = nullptr;
|
||||
std::string name;
|
||||
size_t index;
|
||||
units::radian_t rot;
|
||||
wpi::units::radian_t rot;
|
||||
ImVec2 poseCenter; // center of the pose (screen coordinates)
|
||||
ImVec2 center; // center of the target (screen coordinates)
|
||||
float radius; // target radius
|
||||
@@ -83,18 +83,18 @@ struct SelectedTargetInfo {
|
||||
struct PoseDragState {
|
||||
SelectedTargetInfo target;
|
||||
ImVec2 initialOffset;
|
||||
units::radian_t initialAngle = 0_rad;
|
||||
wpi::units::radian_t initialAngle = 0_rad;
|
||||
};
|
||||
|
||||
// Popup edit state
|
||||
class PopupState {
|
||||
public:
|
||||
void Open(SelectedTargetInfo* target, const frc::Translation2d& pos);
|
||||
void Open(SelectedTargetInfo* target, const wpi::math::Translation2d& pos);
|
||||
void Close();
|
||||
|
||||
SelectedTargetInfo* GetTarget() { return &m_target; }
|
||||
FieldObjectModel* GetInsertModel() { return m_insertModel; }
|
||||
std::span<const frc::Pose2d> GetInsertPoses() const { return m_insertPoses; }
|
||||
std::span<const wpi::math::Pose2d> GetInsertPoses() const { return m_insertPoses; }
|
||||
|
||||
void Display(Field2DModel* model, const FieldFrameData& ffd);
|
||||
|
||||
@@ -106,7 +106,7 @@ class PopupState {
|
||||
|
||||
// for insert
|
||||
FieldObjectModel* m_insertModel;
|
||||
std::vector<frc::Pose2d> m_insertPoses;
|
||||
std::vector<wpi::math::Pose2d> m_insertPoses;
|
||||
std::string m_insertName;
|
||||
int m_insertIndex;
|
||||
};
|
||||
@@ -133,8 +133,8 @@ struct DisplayOptions {
|
||||
float weight = kDefaultWeight;
|
||||
int color = kDefaultColor;
|
||||
|
||||
units::meter_t width = kDefaultWidth;
|
||||
units::meter_t length = kDefaultLength;
|
||||
wpi::units::meter_t width = kDefaultWidth;
|
||||
wpi::units::meter_t length = kDefaultLength;
|
||||
|
||||
bool arrows = kDefaultArrows;
|
||||
int arrowSize = kDefaultArrowSize;
|
||||
@@ -149,13 +149,13 @@ struct DisplayOptions {
|
||||
// Per-frame pose data (not persistent)
|
||||
class PoseFrameData {
|
||||
public:
|
||||
explicit PoseFrameData(const frc::Pose2d& pose, FieldObjectModel& model,
|
||||
explicit PoseFrameData(const wpi::math::Pose2d& pose, FieldObjectModel& model,
|
||||
size_t index, const FieldFrameData& ffd,
|
||||
const DisplayOptions& displayOptions);
|
||||
void SetPosition(const frc::Translation2d& pos);
|
||||
void SetRotation(units::radian_t rot);
|
||||
const frc::Rotation2d& GetRotation() const { return m_pose.Rotation(); }
|
||||
const frc::Pose2d& GetPose() const { return m_pose; }
|
||||
void SetPosition(const wpi::math::Translation2d& pos);
|
||||
void SetRotation(wpi::units::radian_t rot);
|
||||
const wpi::math::Rotation2d& GetRotation() const { return m_pose.Rotation(); }
|
||||
const wpi::math::Pose2d& GetPose() const { return m_pose; }
|
||||
float GetHitRadius() const { return m_hitRadius; }
|
||||
void UpdateFrameData();
|
||||
std::pair<int, float> IsHovered(const ImVec2& cursor) const;
|
||||
@@ -181,7 +181,7 @@ class PoseFrameData {
|
||||
|
||||
float m_hitRadius;
|
||||
|
||||
frc::Pose2d m_pose;
|
||||
wpi::math::Pose2d m_pose;
|
||||
};
|
||||
|
||||
class ObjectInfo {
|
||||
@@ -233,7 +233,7 @@ class FieldInfo {
|
||||
FieldFrameData GetFrameData(ImVec2 min, ImVec2 max) const;
|
||||
void Draw(ImDrawList* drawList, const FieldFrameData& frameData) const;
|
||||
|
||||
wpi::StringMap<ObjectInfo> m_objects;
|
||||
wpi::util::StringMap<ObjectInfo> m_objects;
|
||||
|
||||
private:
|
||||
void Reset();
|
||||
@@ -266,37 +266,37 @@ static PoseDragState gDragState;
|
||||
static PopupState gPopupState;
|
||||
static DisplayUnits gDisplayUnits = kDisplayMeters;
|
||||
|
||||
static double ConvertDisplayLength(units::meter_t v) {
|
||||
static double ConvertDisplayLength(wpi::units::meter_t v) {
|
||||
switch (gDisplayUnits) {
|
||||
case kDisplayFeet:
|
||||
return v.convert<units::feet>().value();
|
||||
return v.convert<wpi::units::feet>().value();
|
||||
case kDisplayInches:
|
||||
return v.convert<units::inches>().value();
|
||||
return v.convert<wpi::units::inches>().value();
|
||||
case kDisplayMeters:
|
||||
default:
|
||||
return v.value();
|
||||
}
|
||||
}
|
||||
|
||||
static double ConvertDisplayAngle(units::degree_t v) {
|
||||
static double ConvertDisplayAngle(wpi::units::degree_t v) {
|
||||
return v.value();
|
||||
}
|
||||
|
||||
static bool InputLength(const char* label, units::meter_t* v, double step = 0.0,
|
||||
static bool InputLength(const char* label, wpi::units::meter_t* v, double step = 0.0,
|
||||
double step_fast = 0.0, const char* format = "%.6f",
|
||||
ImGuiInputTextFlags flags = 0) {
|
||||
double dv = ConvertDisplayLength(*v);
|
||||
if (ImGui::InputDouble(label, &dv, step, step_fast, format, flags)) {
|
||||
switch (gDisplayUnits) {
|
||||
case kDisplayFeet:
|
||||
*v = units::foot_t{dv};
|
||||
*v = wpi::units::foot_t{dv};
|
||||
break;
|
||||
case kDisplayInches:
|
||||
*v = units::inch_t{dv};
|
||||
*v = wpi::units::inch_t{dv};
|
||||
break;
|
||||
case kDisplayMeters:
|
||||
default:
|
||||
*v = units::meter_t{dv};
|
||||
*v = wpi::units::meter_t{dv};
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
@@ -308,7 +308,7 @@ static bool InputFloatLength(const char* label, float* v, double step = 0.0,
|
||||
double step_fast = 0.0,
|
||||
const char* format = "%.3f",
|
||||
ImGuiInputTextFlags flags = 0) {
|
||||
units::meter_t uv{*v};
|
||||
wpi::units::meter_t uv{*v};
|
||||
if (InputLength(label, &uv, step, step_fast, format, flags)) {
|
||||
*v = uv.to<float>();
|
||||
return true;
|
||||
@@ -316,18 +316,18 @@ static bool InputFloatLength(const char* label, float* v, double step = 0.0,
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool InputAngle(const char* label, units::degree_t* v, double step = 0.0,
|
||||
static bool InputAngle(const char* label, wpi::units::degree_t* v, double step = 0.0,
|
||||
double step_fast = 0.0, const char* format = "%.6f",
|
||||
ImGuiInputTextFlags flags = 0) {
|
||||
double dv = ConvertDisplayAngle(*v);
|
||||
if (ImGui::InputDouble(label, &dv, step, step_fast, format, flags)) {
|
||||
*v = units::degree_t{dv};
|
||||
*v = wpi::units::degree_t{dv};
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool InputPose(frc::Pose2d* pose) {
|
||||
static bool InputPose(wpi::math::Pose2d* pose) {
|
||||
auto x = pose->X();
|
||||
auto y = pose->Y();
|
||||
auto rot = pose->Rotation().Degrees();
|
||||
@@ -337,7 +337,7 @@ static bool InputPose(frc::Pose2d* pose) {
|
||||
changed = InputLength("y", &y) || changed;
|
||||
changed = InputAngle("rot", &rot) || changed;
|
||||
if (changed) {
|
||||
*pose = frc::Pose2d{x, y, rot};
|
||||
*pose = wpi::math::Pose2d{x, y, rot};
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
@@ -359,7 +359,7 @@ void FieldInfo::DisplaySettings() {
|
||||
if (ImGui::Selectable("Custom", m_builtin.empty())) {
|
||||
Reset();
|
||||
}
|
||||
for (auto&& field : fields::GetFields()) {
|
||||
for (auto&& field : wpi::fields::GetFields()) {
|
||||
bool selected = field.name == m_builtin;
|
||||
if (ImGui::Selectable(field.name, selected)) {
|
||||
Reset();
|
||||
@@ -406,7 +406,7 @@ void FieldInfo::LoadImage() {
|
||||
if (m_fileOpener && m_fileOpener->ready(0)) {
|
||||
auto result = m_fileOpener->result();
|
||||
if (!result.empty()) {
|
||||
if (wpi::ends_with(result[0], ".json")) {
|
||||
if (wpi::util::ends_with(result[0], ".json")) {
|
||||
LoadJsonFile(result[0]);
|
||||
} else {
|
||||
LoadImageImpl(result[0].c_str());
|
||||
@@ -420,7 +420,7 @@ void FieldInfo::LoadImage() {
|
||||
}
|
||||
if (!m_texture) {
|
||||
if (!m_builtin.empty()) {
|
||||
for (auto&& field : fields::GetFields()) {
|
||||
for (auto&& field : wpi::fields::GetFields()) {
|
||||
if (field.name == m_builtin) {
|
||||
auto jsonstr = field.getJson();
|
||||
auto imagedata = field.getImage();
|
||||
@@ -446,11 +446,11 @@ void FieldInfo::LoadImage() {
|
||||
|
||||
bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
// parse file
|
||||
wpi::json j;
|
||||
wpi::util::json j;
|
||||
try {
|
||||
j = wpi::json::parse(is);
|
||||
} catch (const wpi::json::parse_error& e) {
|
||||
wpi::print(stderr, "GUI: JSON: could not parse: {}\n", e.what());
|
||||
j = wpi::util::json::parse(is);
|
||||
} catch (const wpi::util::json::parse_error& e) {
|
||||
wpi::util::print(stderr, "GUI: JSON: could not parse: {}\n", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -464,8 +464,8 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
std::string image;
|
||||
try {
|
||||
image = j.at("field-image").get<std::string>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::print(stderr, "GUI: JSON: could not read field-image: {}\n", e.what());
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-image: {}\n", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -476,8 +476,8 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
left = j.at("field-corners").at("top-left").at(0).get<int>();
|
||||
bottom = j.at("field-corners").at("bottom-right").at(1).get<int>();
|
||||
right = j.at("field-corners").at("bottom-right").at(0).get<int>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::print(stderr, "GUI: JSON: could not read field-corners: {}\n",
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-corners: {}\n",
|
||||
e.what());
|
||||
return false;
|
||||
}
|
||||
@@ -488,8 +488,8 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
try {
|
||||
width = j.at("field-size").at(0).get<float>();
|
||||
height = j.at("field-size").at(1).get<float>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::print(stderr, "GUI: JSON: could not read field-size: {}\n", e.what());
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-size: {}\n", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -497,22 +497,22 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
std::string unit;
|
||||
try {
|
||||
unit = j.at("field-unit").get<std::string>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::print(stderr, "GUI: JSON: could not read field-unit: {}\n", e.what());
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "GUI: JSON: could not read field-unit: {}\n", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
// convert size units to meters
|
||||
if (unit == "foot" || unit == "feet") {
|
||||
width = units::convert<units::feet, units::meters>(width);
|
||||
height = units::convert<units::feet, units::meters>(height);
|
||||
width = wpi::units::convert<wpi::units::feet, wpi::units::meters>(width);
|
||||
height = wpi::units::convert<wpi::units::feet, wpi::units::meters>(height);
|
||||
}
|
||||
|
||||
// check scaling
|
||||
int fieldWidth = m_right - m_left;
|
||||
int fieldHeight = m_bottom - m_top;
|
||||
if (std::abs((fieldWidth / width) - (fieldHeight / height)) > 0.3) {
|
||||
wpi::print(stderr,
|
||||
wpi::util::print(stderr,
|
||||
"GUI: Field X and Y scaling substantially different: "
|
||||
"xscale={} yscale={}\n",
|
||||
(fieldWidth / width), (fieldHeight / height));
|
||||
@@ -540,7 +540,7 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
}
|
||||
|
||||
void FieldInfo::LoadJsonFile(std::string_view jsonfile) {
|
||||
auto fileBuffer = wpi::MemoryBuffer::GetFile(jsonfile);
|
||||
auto fileBuffer = wpi::util::MemoryBuffer::GetFile(jsonfile);
|
||||
if (!fileBuffer) {
|
||||
std::fputs("GUI: could not open field JSON file\n", stderr);
|
||||
return;
|
||||
@@ -551,7 +551,7 @@ void FieldInfo::LoadJsonFile(std::string_view jsonfile) {
|
||||
}
|
||||
|
||||
bool FieldInfo::LoadImageImpl(const std::string& fn) {
|
||||
wpi::print("GUI: loading field image '{}'\n", fn);
|
||||
wpi::util::print("GUI: loading field image '{}'\n", fn);
|
||||
auto texture = gui::Texture::CreateFromFile(fn.c_str());
|
||||
if (!texture) {
|
||||
std::puts("GUI: could not read field image");
|
||||
@@ -651,8 +651,8 @@ DisplayOptions ObjectInfo::GetDisplayOptions() const {
|
||||
rv.style = static_cast<DisplayOptions::Style>(m_style.GetValue());
|
||||
rv.weight = m_weight;
|
||||
rv.color = ImGui::ColorConvertFloat4ToU32(m_color.GetColor());
|
||||
rv.width = units::meter_t{m_width};
|
||||
rv.length = units::meter_t{m_length};
|
||||
rv.width = wpi::units::meter_t{m_width};
|
||||
rv.length = wpi::units::meter_t{m_length};
|
||||
rv.arrows = m_arrows;
|
||||
rv.arrowSize = m_arrowSize;
|
||||
rv.arrowWeight = m_arrowWeight;
|
||||
@@ -761,7 +761,7 @@ void ObjectInfo::LoadImage() {
|
||||
}
|
||||
|
||||
bool ObjectInfo::LoadImageImpl(const std::string& fn) {
|
||||
wpi::print("GUI: loading object image '{}'\n", fn);
|
||||
wpi::util::print("GUI: loading object image '{}'\n", fn);
|
||||
auto texture = gui::Texture::CreateFromFile(fn.c_str());
|
||||
if (!texture) {
|
||||
std::fputs("GUI: could not read object image\n", stderr);
|
||||
@@ -772,7 +772,7 @@ bool ObjectInfo::LoadImageImpl(const std::string& fn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PoseFrameData::PoseFrameData(const frc::Pose2d& pose, FieldObjectModel& model,
|
||||
PoseFrameData::PoseFrameData(const wpi::math::Pose2d& pose, FieldObjectModel& model,
|
||||
size_t index, const FieldFrameData& ffd,
|
||||
const DisplayOptions& displayOptions)
|
||||
: m_model{model},
|
||||
@@ -786,13 +786,13 @@ PoseFrameData::PoseFrameData(const frc::Pose2d& pose, FieldObjectModel& model,
|
||||
UpdateFrameData();
|
||||
}
|
||||
|
||||
void PoseFrameData::SetPosition(const frc::Translation2d& pos) {
|
||||
m_pose = frc::Pose2d{pos, m_pose.Rotation()};
|
||||
void PoseFrameData::SetPosition(const wpi::math::Translation2d& pos) {
|
||||
m_pose = wpi::math::Pose2d{pos, m_pose.Rotation()};
|
||||
m_model.SetPose(m_index, m_pose);
|
||||
}
|
||||
|
||||
void PoseFrameData::SetRotation(units::radian_t rot) {
|
||||
m_pose = frc::Pose2d{m_pose.Translation(), rot};
|
||||
void PoseFrameData::SetRotation(wpi::units::radian_t rot) {
|
||||
m_pose = wpi::math::Pose2d{m_pose.Translation(), rot};
|
||||
m_model.SetPose(m_index, m_pose);
|
||||
}
|
||||
|
||||
@@ -896,7 +896,7 @@ void PoseFrameData::HandleDrag(const ImVec2& cursor) {
|
||||
} else {
|
||||
ImVec2 off = cursor - m_center;
|
||||
SetRotation(gDragState.initialAngle -
|
||||
units::radian_t{std::atan2(off.y, off.x)});
|
||||
wpi::units::radian_t{std::atan2(off.y, off.x)});
|
||||
gDragState.target.center = m_corners[gDragState.target.corner - 2];
|
||||
gDragState.target.rot = GetRotation().Radians();
|
||||
}
|
||||
@@ -935,7 +935,7 @@ void PoseFrameData::Draw(ImDrawList* drawList, std::vector<ImVec2>* center,
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayField2DSettings(Field2DModel* model) {
|
||||
void wpi::glass::DisplayField2DSettings(Field2DModel* model) {
|
||||
auto& storage = GetStorage();
|
||||
auto field = storage.GetData<FieldInfo>();
|
||||
if (!field) {
|
||||
@@ -963,7 +963,7 @@ void glass::DisplayField2DSettings(Field2DModel* model) {
|
||||
}
|
||||
PushID(name);
|
||||
|
||||
wpi::SmallString<64> nameBuf{name};
|
||||
wpi::util::SmallString<64> nameBuf{name};
|
||||
if (ImGui::CollapsingHeader(nameBuf.c_str())) {
|
||||
auto& obj =
|
||||
field->m_objects.try_emplace(name, GetStorage()).first->second;
|
||||
@@ -1085,7 +1085,7 @@ void FieldDisplay::Display(FieldInfo* field, Field2DModel* model,
|
||||
gDragState.initialOffset = m_mousePos - target->poseCenter;
|
||||
if (target->corner != 1) {
|
||||
gDragState.initialAngle =
|
||||
units::radian_t{std::atan2(gDragState.initialOffset.y,
|
||||
wpi::units::radian_t{std::atan2(gDragState.initialOffset.y,
|
||||
gDragState.initialOffset.x)} +
|
||||
target->rot;
|
||||
}
|
||||
@@ -1152,7 +1152,7 @@ void FieldDisplay::DisplayObject(FieldObjectModel& model,
|
||||
}
|
||||
|
||||
void PopupState::Open(SelectedTargetInfo* target,
|
||||
const frc::Translation2d& pos) {
|
||||
const wpi::math::Translation2d& pos) {
|
||||
if (target) {
|
||||
m_target = *target;
|
||||
} else {
|
||||
@@ -1182,7 +1182,7 @@ void PopupState::Display(Field2DModel* model, const FieldFrameData& ffd) {
|
||||
void PopupState::DisplayTarget(Field2DModel* model, const FieldFrameData& ffd) {
|
||||
ImGui::Text("%s[%d]", m_target.name.c_str(),
|
||||
static_cast<int>(m_target.index));
|
||||
frc::Pose2d pose{ffd.GetPosFromScreen(m_target.poseCenter), m_target.rot};
|
||||
wpi::math::Pose2d pose{ffd.GetPosFromScreen(m_target.poseCenter), m_target.rot};
|
||||
if (InputPose(&pose)) {
|
||||
m_target.poseCenter = ffd.GetScreenFromPos(pose.Translation());
|
||||
m_target.rot = pose.Rotation().Radians();
|
||||
@@ -1190,7 +1190,7 @@ void PopupState::DisplayTarget(Field2DModel* model, const FieldFrameData& ffd) {
|
||||
}
|
||||
if (ImGui::Button("Delete Pose")) {
|
||||
auto posesRef = m_target.objModel->GetPoses();
|
||||
std::vector<frc::Pose2d> poses{posesRef.begin(), posesRef.end()};
|
||||
std::vector<wpi::math::Pose2d> poses{posesRef.begin(), posesRef.end()};
|
||||
if (m_target.index < poses.size()) {
|
||||
poses.erase(poses.begin() + m_target.index);
|
||||
m_target.objModel->SetPoses(poses);
|
||||
@@ -1277,7 +1277,7 @@ void PopupState::DisplayInsert(Field2DModel* model) {
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayField2D(Field2DModel* model, const ImVec2& contentSize) {
|
||||
void wpi::glass::DisplayField2D(Field2DModel* model, const ImVec2& contentSize) {
|
||||
auto& storage = GetStorage();
|
||||
auto field = storage.GetData<FieldInfo>();
|
||||
if (!field) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
LogData::LogData(size_t maxLines) : m_maxLines{maxLines} {}
|
||||
|
||||
@@ -36,7 +36,7 @@ const std::string& LogData::GetBuffer() {
|
||||
return m_buf;
|
||||
}
|
||||
|
||||
void glass::DisplayLog(LogData* data, bool autoScroll) {
|
||||
void wpi::glass::DisplayLog(LogData* data, bool autoScroll) {
|
||||
if (data->m_buf.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "wpi/units/length.hpp"
|
||||
#include "wpi/util/print.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
namespace gui = wpi::gui;
|
||||
|
||||
@@ -37,19 +37,19 @@ namespace {
|
||||
|
||||
// Per-frame data (not persistent)
|
||||
struct FrameData {
|
||||
frc::Translation2d GetPosFromScreen(const ImVec2& cursor) const {
|
||||
wpi::math::Translation2d GetPosFromScreen(const ImVec2& cursor) const {
|
||||
return {
|
||||
units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) / scale},
|
||||
units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) / scale}};
|
||||
wpi::units::meter_t{(std::clamp(cursor.x, min.x, max.x) - min.x) / scale},
|
||||
wpi::units::meter_t{(max.y - std::clamp(cursor.y, min.y, max.y)) / scale}};
|
||||
}
|
||||
ImVec2 GetScreenFromPos(const frc::Translation2d& pos) const {
|
||||
ImVec2 GetScreenFromPos(const wpi::math::Translation2d& pos) const {
|
||||
return {min.x + scale * pos.X().to<float>(),
|
||||
max.y - scale * pos.Y().to<float>()};
|
||||
}
|
||||
void DrawObject(ImDrawList* drawList, MechanismObjectModel& objModel,
|
||||
const frc::Pose2d& pose) const;
|
||||
const wpi::math::Pose2d& pose) const;
|
||||
void DrawGroup(ImDrawList* drawList, MechanismObjectGroup& group,
|
||||
const frc::Pose2d& pose) const;
|
||||
const wpi::math::Pose2d& pose) const;
|
||||
|
||||
// in screen coordinates
|
||||
ImVec2 imageMin;
|
||||
@@ -67,7 +67,7 @@ class BackgroundInfo {
|
||||
void DisplaySettings();
|
||||
|
||||
void LoadImage();
|
||||
FrameData GetFrameData(ImVec2 min, ImVec2 max, frc::Translation2d dims) const;
|
||||
FrameData GetFrameData(ImVec2 min, ImVec2 max, wpi::math::Translation2d dims) const;
|
||||
void Draw(ImDrawList* drawList, const FrameData& frameData,
|
||||
ImU32 bgColor) const;
|
||||
|
||||
@@ -126,7 +126,7 @@ void BackgroundInfo::LoadImage() {
|
||||
}
|
||||
|
||||
bool BackgroundInfo::LoadImageImpl(const std::string& fn) {
|
||||
wpi::print("GUI: loading background image '{}'\n", fn);
|
||||
wpi::util::print("GUI: loading background image '{}'\n", fn);
|
||||
auto texture = gui::Texture::CreateFromFile(fn.c_str());
|
||||
if (!texture) {
|
||||
std::puts("GUI: could not read background image");
|
||||
@@ -140,7 +140,7 @@ bool BackgroundInfo::LoadImageImpl(const std::string& fn) {
|
||||
}
|
||||
|
||||
FrameData BackgroundInfo::GetFrameData(ImVec2 min, ImVec2 max,
|
||||
frc::Translation2d dims) const {
|
||||
wpi::math::Translation2d dims) const {
|
||||
// fit the image into the window
|
||||
if (m_texture && m_imageHeight != 0 && m_imageWidth != 0) {
|
||||
gui::MaxFit(&min, &max, m_imageWidth, m_imageHeight);
|
||||
@@ -170,7 +170,7 @@ void BackgroundInfo::Draw(ImDrawList* drawList, const FrameData& frameData,
|
||||
}
|
||||
}
|
||||
|
||||
void glass::DisplayMechanism2DSettings(Mechanism2DModel* model) {
|
||||
void wpi::glass::DisplayMechanism2DSettings(Mechanism2DModel* model) {
|
||||
auto& storage = GetStorage();
|
||||
auto bg = storage.GetData<BackgroundInfo>();
|
||||
if (!bg) {
|
||||
@@ -181,14 +181,14 @@ void glass::DisplayMechanism2DSettings(Mechanism2DModel* model) {
|
||||
}
|
||||
|
||||
void FrameData::DrawObject(ImDrawList* drawList, MechanismObjectModel& objModel,
|
||||
const frc::Pose2d& pose) const {
|
||||
const wpi::math::Pose2d& pose) const {
|
||||
const char* type = objModel.GetType();
|
||||
if (std::string_view{type} == "line") {
|
||||
auto startPose =
|
||||
pose + frc::Transform2d{frc::Translation2d{}, objModel.GetAngle()};
|
||||
pose + wpi::math::Transform2d{wpi::math::Translation2d{}, objModel.GetAngle()};
|
||||
auto endPose =
|
||||
startPose +
|
||||
frc::Transform2d{frc::Translation2d{objModel.GetLength(), 0_m}, 0_deg};
|
||||
wpi::math::Transform2d{wpi::math::Translation2d{objModel.GetLength(), 0_m}, 0_deg};
|
||||
drawList->AddLine(GetScreenFromPos(startPose.Translation()),
|
||||
GetScreenFromPos(endPose.Translation()),
|
||||
objModel.GetColor(), objModel.GetWeight());
|
||||
@@ -197,12 +197,12 @@ void FrameData::DrawObject(ImDrawList* drawList, MechanismObjectModel& objModel,
|
||||
}
|
||||
|
||||
void FrameData::DrawGroup(ImDrawList* drawList, MechanismObjectGroup& group,
|
||||
const frc::Pose2d& pose) const {
|
||||
const wpi::math::Pose2d& pose) const {
|
||||
group.ForEachObject(
|
||||
[&](auto& objModel) { DrawObject(drawList, objModel, pose); });
|
||||
}
|
||||
|
||||
void glass::DisplayMechanism2D(Mechanism2DModel* model,
|
||||
void wpi::glass::DisplayMechanism2D(Mechanism2DModel* model,
|
||||
const ImVec2& contentSize) {
|
||||
auto& storage = GetStorage();
|
||||
auto bg = storage.GetData<BackgroundInfo>();
|
||||
@@ -233,7 +233,7 @@ void glass::DisplayMechanism2D(Mechanism2DModel* model,
|
||||
// elements
|
||||
model->ForEachRoot([&](auto& rootModel) {
|
||||
frameData.DrawGroup(drawList, rootModel,
|
||||
frc::Pose2d{rootModel.GetPosition(), 0_deg});
|
||||
wpi::math::Pose2d{rootModel.GetPosition(), 0_deg});
|
||||
});
|
||||
|
||||
#if 0
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
#include "wpi/glass/DataSource.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayPIDController(PIDControllerModel* m) {
|
||||
void wpi::glass::DisplayPIDController(PIDControllerModel* m) {
|
||||
if (auto name = m->GetName()) {
|
||||
ImGui::Text("%s", name);
|
||||
ImGui::Separator();
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#include "wpi/glass/support/EnumSetting.hpp"
|
||||
#include "wpi/glass/support/ExtraGuiWidgets.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
static constexpr int kAxisCount = 3;
|
||||
|
||||
@@ -89,8 +89,8 @@ class PlotSeries {
|
||||
// source linkage
|
||||
DataSource* m_source = nullptr;
|
||||
bool m_digitalSource = false;
|
||||
wpi::sig::ScopedConnection m_sourceCreatedConn;
|
||||
wpi::sig::ScopedConnection m_newValueConn;
|
||||
wpi::util::sig::ScopedConnection m_sourceCreatedConn;
|
||||
wpi::util::sig::ScopedConnection m_newValueConn;
|
||||
std::string& m_id;
|
||||
|
||||
// user settings
|
||||
@@ -292,7 +292,7 @@ void PlotSeries::SetSource(DataSource* source) {
|
||||
}
|
||||
|
||||
void PlotSeries::AppendValue(double value, int64_t timeUs) {
|
||||
double time = (timeUs != 0 ? timeUs : wpi::Now()) * 1.0e-6;
|
||||
double time = (timeUs != 0 ? timeUs : wpi::util::Now()) * 1.0e-6;
|
||||
if (IsDigital()) {
|
||||
if (m_size < kMaxSize) {
|
||||
m_data[m_size] = ImPlotPoint{time, value};
|
||||
@@ -350,7 +350,7 @@ PlotSeries::Action PlotSeries::EmitPlot(PlotView& view, double now, size_t i,
|
||||
CheckSource();
|
||||
|
||||
char label[128];
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{}###name{}_{}", GetName(),
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###name{}_{}", GetName(),
|
||||
static_cast<int>(i), static_cast<int>(plotIndex));
|
||||
|
||||
int size = m_size;
|
||||
@@ -618,7 +618,7 @@ void Plot::EmitPlot(PlotView& view, double now, bool paused, size_t i) {
|
||||
}
|
||||
|
||||
char label[128];
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{}###plot{}", m_name,
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###plot{}", m_name,
|
||||
static_cast<int>(i));
|
||||
|
||||
ImPlotFlags plotFlags = (m_legend ? 0 : ImPlotFlags_NoLegend) |
|
||||
@@ -865,7 +865,7 @@ void PlotView::Display() {
|
||||
}
|
||||
}
|
||||
|
||||
double now = wpi::Now() * 1.0e-6;
|
||||
double now = wpi::util::Now() * 1.0e-6;
|
||||
for (size_t i = 0; i < m_plots.size(); ++i) {
|
||||
ImGui::PushID(i);
|
||||
m_plots[i]->EmitPlot(*this, now, m_provider->IsPaused(), i);
|
||||
@@ -976,14 +976,14 @@ void PlotView::Settings() {
|
||||
|
||||
char name[64];
|
||||
if (!plot->GetName().empty()) {
|
||||
wpi::format_to_n_c_str(name, sizeof(name), "{}", plot->GetName().c_str());
|
||||
wpi::util::format_to_n_c_str(name, sizeof(name), "{}", plot->GetName().c_str());
|
||||
} else {
|
||||
wpi::format_to_n_c_str(name, sizeof(name), "Plot {}",
|
||||
wpi::util::format_to_n_c_str(name, sizeof(name), "Plot {}",
|
||||
static_cast<int>(i));
|
||||
}
|
||||
|
||||
char label[90];
|
||||
wpi::format_to_n_c_str(label, sizeof(label), "{}###header{}", name,
|
||||
wpi::util::format_to_n_c_str(label, sizeof(label), "{}###header{}", name,
|
||||
static_cast<int>(i));
|
||||
|
||||
bool open = ImGui::CollapsingHeader(label);
|
||||
@@ -1053,7 +1053,7 @@ void PlotProvider::DisplayMenu() {
|
||||
char id[32];
|
||||
size_t numWindows = m_windows.size();
|
||||
for (size_t i = 0; i <= numWindows; ++i) {
|
||||
wpi::format_to_n_c_str(id, sizeof(id), "Plot <{}>", static_cast<int>(i));
|
||||
wpi::util::format_to_n_c_str(id, sizeof(id), "Plot <{}>", static_cast<int>(i));
|
||||
|
||||
bool match = false;
|
||||
for (size_t j = 0; j < numWindows; ++j) {
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
#include "wpi/glass/DataSource.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayProfiledPIDController(ProfiledPIDControllerModel* m) {
|
||||
void wpi::glass::DisplayProfiledPIDController(ProfiledPIDControllerModel* m) {
|
||||
if (auto name = m->GetName()) {
|
||||
ImGui::Text("%s", name);
|
||||
ImGui::Separator();
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplayStringChooser(StringChooserModel* model) {
|
||||
void wpi::glass::DisplayStringChooser(StringChooserModel* model) {
|
||||
auto& defaultValue = model->GetDefault();
|
||||
auto& selected = model->GetSelected();
|
||||
auto& active = model->GetActive();
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void glass::DisplaySubsystem(SubsystemModel* m) {
|
||||
void wpi::glass::DisplaySubsystem(SubsystemModel* m) {
|
||||
if (auto name = m->GetName()) {
|
||||
ImGui::Text("%s", name);
|
||||
ImGui::Separator();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "wpi/glass/support/ColorSetting.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
ColorSetting::ColorSetting(std::vector<float>& color) : m_color{color} {
|
||||
m_color.resize(4);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
EnumSetting::EnumSetting(std::string& str, int defaultValue,
|
||||
std::initializer_list<const char*> choices)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
#include "wpi/util/expected"
|
||||
|
||||
namespace glass::expression {
|
||||
namespace wpi::glass::expression {
|
||||
|
||||
enum class TokenType {
|
||||
Number,
|
||||
@@ -74,7 +74,7 @@ class Lexer {
|
||||
return Token(TokenType::CloseParen);
|
||||
default:
|
||||
currentIdx--;
|
||||
if (wpi::isDigit(c) || c == '.') {
|
||||
if (wpi::util::isDigit(c) || c == '.') {
|
||||
return nextNumber();
|
||||
}
|
||||
return Token(TokenType::Error, &input[currentIdx], 1);
|
||||
@@ -92,7 +92,7 @@ class Lexer {
|
||||
Token nextNumber() {
|
||||
// Read whole part
|
||||
bool hasDigitsBeforeDecimal = false;
|
||||
while (wpi::isDigit(input[currentIdx])) {
|
||||
while (wpi::util::isDigit(input[currentIdx])) {
|
||||
currentIdx++;
|
||||
hasDigitsBeforeDecimal = true;
|
||||
}
|
||||
@@ -106,12 +106,12 @@ class Lexer {
|
||||
|
||||
currentIdx++;
|
||||
// Report a single '.' with no digits as an error
|
||||
if (!hasDigitsBeforeDecimal && !wpi::isDigit(input[currentIdx])) {
|
||||
if (!hasDigitsBeforeDecimal && !wpi::util::isDigit(input[currentIdx])) {
|
||||
// Report the decimal as the unexpected char
|
||||
return Token(TokenType::Error, &input[currentIdx - 1], 1);
|
||||
}
|
||||
|
||||
while (wpi::isDigit(input[currentIdx])) {
|
||||
while (wpi::util::isDigit(input[currentIdx])) {
|
||||
currentIdx++;
|
||||
}
|
||||
|
||||
@@ -205,31 +205,31 @@ std::optional<V> ValueFromString(std::string_view str);
|
||||
|
||||
template <>
|
||||
std::optional<int64_t> ValueFromString(std::string_view str) {
|
||||
return wpi::parse_integer<int64_t>(str, 10);
|
||||
return wpi::util::parse_integer<int64_t>(str, 10);
|
||||
}
|
||||
|
||||
template <>
|
||||
std::optional<float> ValueFromString(std::string_view str) {
|
||||
return wpi::parse_float<float>(str);
|
||||
return wpi::util::parse_float<float>(str);
|
||||
}
|
||||
|
||||
template <>
|
||||
std::optional<double> ValueFromString(std::string_view str) {
|
||||
return wpi::parse_float<double>(str);
|
||||
return wpi::util::parse_float<double>(str);
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
wpi::expected<V, std::string> EvalAll(std::stack<Operator>& operStack,
|
||||
wpi::util::expected<V, std::string> EvalAll(std::stack<Operator>& operStack,
|
||||
std::stack<V>& valStack) {
|
||||
while (!operStack.empty()) {
|
||||
if (valStack.size() < 2) {
|
||||
return wpi::unexpected("Missing operand");
|
||||
return wpi::util::unexpected("Missing operand");
|
||||
}
|
||||
ApplyOperator<V>(valStack, operStack.top());
|
||||
operStack.pop();
|
||||
}
|
||||
if (valStack.empty()) {
|
||||
return wpi::unexpected("No value");
|
||||
return wpi::util::unexpected("No value");
|
||||
}
|
||||
|
||||
// Intentionally leaves the result value on top of valStack so unmatched
|
||||
@@ -238,7 +238,7 @@ wpi::expected<V, std::string> EvalAll(std::stack<Operator>& operStack,
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
wpi::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
wpi::util::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
std::stack<Operator> operStack;
|
||||
std::stack<V> valStack;
|
||||
|
||||
@@ -257,7 +257,7 @@ wpi::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
// is probably not what the user intended in this case, so give them an
|
||||
// error.
|
||||
if (prevType == TokenType::Number) {
|
||||
return wpi::unexpected("Missing operator");
|
||||
return wpi::util::unexpected("Missing operator");
|
||||
}
|
||||
|
||||
// Implicit multiplication. Ex: "2(4 + 5)"
|
||||
@@ -270,7 +270,7 @@ wpi::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
if (value) {
|
||||
valStack.push(value.value());
|
||||
} else {
|
||||
return wpi::unexpected("Invalid number");
|
||||
return wpi::util::unexpected("Invalid number");
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -282,7 +282,7 @@ wpi::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
operStack.push(Operator::Multiply);
|
||||
}
|
||||
|
||||
wpi::expected<V, std::string> result = ParseExpr<V>(lexer, true);
|
||||
wpi::util::expected<V, std::string> result = ParseExpr<V>(lexer, true);
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
@@ -293,7 +293,7 @@ wpi::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
if (nextType == TokenType::End) {
|
||||
goto end; // Act as if closed at end of expression
|
||||
}
|
||||
return wpi::unexpected("Expected )");
|
||||
return wpi::util::unexpected("Expected )");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -307,7 +307,7 @@ wpi::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
// Acts as if there was open paren at start of expression. EvalAll will
|
||||
// clear both stacks, and leave the result value on top of valStack.
|
||||
// This makes sure everything inside the parentheses is evaluated first
|
||||
wpi::expected<V, std::string> result = EvalAll<V>(operStack, valStack);
|
||||
wpi::util::expected<V, std::string> result = EvalAll<V>(operStack, valStack);
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
@@ -315,7 +315,7 @@ wpi::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
}
|
||||
|
||||
case TokenType::Error:
|
||||
return wpi::unexpected(std::string("Unexpected character: ")
|
||||
return wpi::util::unexpected(std::string("Unexpected character: ")
|
||||
.append(token.str, token.strLen));
|
||||
|
||||
default:
|
||||
@@ -342,7 +342,7 @@ wpi::expected<V, std::string> ParseExpr(Lexer& lexer, bool insideParen) {
|
||||
precedence < prevPrecedence) {
|
||||
operStack.pop();
|
||||
if (valStack.size() < 2) {
|
||||
return wpi::unexpected("Missing operand");
|
||||
return wpi::util::unexpected("Missing operand");
|
||||
}
|
||||
ApplyOperator<V>(valStack, prevOp);
|
||||
} else {
|
||||
@@ -363,13 +363,13 @@ end:
|
||||
|
||||
// expr is null-terminated string, as ImGui::inputText() uses
|
||||
template <typename V>
|
||||
wpi::expected<V, std::string> TryParseExpr(const char* expr) {
|
||||
wpi::util::expected<V, std::string> TryParseExpr(const char* expr) {
|
||||
Lexer lexer(expr, std::is_integral_v<V>);
|
||||
return ParseExpr<V>(lexer, false);
|
||||
}
|
||||
|
||||
template wpi::expected<double, std::string> TryParseExpr(const char*);
|
||||
template wpi::expected<float, std::string> TryParseExpr(const char*);
|
||||
template wpi::expected<int64_t, std::string> TryParseExpr(const char*);
|
||||
template wpi::util::expected<double, std::string> TryParseExpr(const char*);
|
||||
template wpi::util::expected<float, std::string> TryParseExpr(const char*);
|
||||
template wpi::util::expected<int64_t, std::string> TryParseExpr(const char*);
|
||||
|
||||
} // namespace glass::expression
|
||||
} // namespace wpi::glass::expression
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "wpi/glass/support/ExpressionParser.hpp"
|
||||
#include "wpi/util/DenseMap.hpp"
|
||||
|
||||
namespace glass {
|
||||
namespace wpi::glass {
|
||||
|
||||
void DrawLEDSources(const int* values, BooleanSource** sources, int numValues,
|
||||
int cols, const ImU32* colors, float size, float spacing,
|
||||
@@ -228,7 +228,7 @@ struct InputExprState {
|
||||
char inputBuffer[kBufferSize];
|
||||
};
|
||||
|
||||
static wpi::DenseMap<int, InputExprState> exprStates;
|
||||
static wpi::util::DenseMap<int, InputExprState> exprStates;
|
||||
// Shared string buffer for inactive inputs
|
||||
static char previewBuffer[kBufferSize];
|
||||
|
||||
@@ -267,7 +267,7 @@ bool InputExpr(const char* label, V* v, const char* format,
|
||||
}
|
||||
|
||||
// Attempt to parse current value
|
||||
auto result = glass::expression::TryParseExpr<V>(state.inputBuffer);
|
||||
auto result = wpi::glass::expression::TryParseExpr<V>(state.inputBuffer);
|
||||
if (result) {
|
||||
*v = result.value();
|
||||
} else if (active) {
|
||||
@@ -289,4 +289,4 @@ template bool InputExpr(const char*, int64_t*, const char*,
|
||||
template bool InputExpr(const char*, float*, const char*, ImGuiInputTextFlags);
|
||||
template bool InputExpr(const char*, double*, const char*, ImGuiInputTextFlags);
|
||||
|
||||
} // namespace glass
|
||||
} // namespace wpi::glass
|
||||
|
||||
@@ -9,50 +9,50 @@
|
||||
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
|
||||
using namespace glass;
|
||||
using namespace wpi::glass;
|
||||
|
||||
void NameSetting::GetName(char* buf, size_t size,
|
||||
const char* defaultName) const {
|
||||
if (!m_name.empty()) {
|
||||
wpi::format_to_n_c_str(buf, size, "{}", m_name);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}", m_name);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(buf, size, "{}", defaultName);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}", defaultName);
|
||||
}
|
||||
}
|
||||
|
||||
void NameSetting::GetName(char* buf, size_t size, const char* defaultName,
|
||||
int index) const {
|
||||
if (!m_name.empty()) {
|
||||
wpi::format_to_n_c_str(buf, size, "{} [{}]", m_name, index);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{} [{}]", m_name, index);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(buf, size, "{}[{}]", defaultName, index);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}[{}]", defaultName, index);
|
||||
}
|
||||
}
|
||||
|
||||
void NameSetting::GetName(char* buf, size_t size, const char* defaultName,
|
||||
int index, int index2) const {
|
||||
if (!m_name.empty()) {
|
||||
wpi::format_to_n_c_str(buf, size, "{} [{},{}]", m_name, index, index2);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{} [{},{}]", m_name, index, index2);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(buf, size, "{}[{},{}]", defaultName, index, index2);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}[{},{}]", defaultName, index, index2);
|
||||
}
|
||||
}
|
||||
|
||||
void NameSetting::GetLabel(char* buf, size_t size,
|
||||
const char* defaultName) const {
|
||||
if (!m_name.empty()) {
|
||||
wpi::format_to_n_c_str(buf, size, "{}###Name{}", m_name, defaultName);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}###Name{}", m_name, defaultName);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(buf, size, "{}###Name{}", defaultName, defaultName);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}###Name{}", defaultName, defaultName);
|
||||
}
|
||||
}
|
||||
|
||||
void NameSetting::GetLabel(char* buf, size_t size, const char* defaultName,
|
||||
int index) const {
|
||||
if (!m_name.empty()) {
|
||||
wpi::format_to_n_c_str(buf, size, "{} [{}]###Name{}", m_name, index, index);
|
||||
wpi::util::format_to_n_c_str(buf, size, "{} [{}]###Name{}", m_name, index, index);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(buf, size, "{}[{}]###Name{}", defaultName, index,
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}[{}]###Name{}", defaultName, index,
|
||||
index);
|
||||
}
|
||||
}
|
||||
@@ -60,24 +60,24 @@ void NameSetting::GetLabel(char* buf, size_t size, const char* defaultName,
|
||||
void NameSetting::GetLabel(char* buf, size_t size, const char* defaultName,
|
||||
int index, int index2) const {
|
||||
if (!m_name.empty()) {
|
||||
wpi::format_to_n_c_str(buf, size, "{} [{},{}]###Name{}", m_name, index,
|
||||
wpi::util::format_to_n_c_str(buf, size, "{} [{},{}]###Name{}", m_name, index,
|
||||
index2, index);
|
||||
} else {
|
||||
wpi::format_to_n_c_str(buf, size, "{}[{},{}]###Name{}", defaultName, index,
|
||||
wpi::util::format_to_n_c_str(buf, size, "{}[{},{}]###Name{}", defaultName, index,
|
||||
index2, index);
|
||||
}
|
||||
}
|
||||
|
||||
void NameSetting::PushEditNameId(int index) {
|
||||
char id[64];
|
||||
wpi::format_to_n_c_str(id, sizeof(id), "Name{}", index);
|
||||
wpi::util::format_to_n_c_str(id, sizeof(id), "Name{}", index);
|
||||
|
||||
ImGui::PushID(id);
|
||||
}
|
||||
|
||||
void NameSetting::PushEditNameId(const char* name) {
|
||||
char id[128];
|
||||
wpi::format_to_n_c_str(id, sizeof(id), "Name{}", name);
|
||||
wpi::util::format_to_n_c_str(id, sizeof(id), "Name{}", name);
|
||||
|
||||
ImGui::PushID(id);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ bool NameSetting::PopupEditName(int index) {
|
||||
bool rv = false;
|
||||
|
||||
char id[64];
|
||||
wpi::format_to_n_c_str(id, sizeof(id), "Name{}", index);
|
||||
wpi::util::format_to_n_c_str(id, sizeof(id), "Name{}", index);
|
||||
|
||||
if (ImGui::BeginPopupContextItem(id)) {
|
||||
ImGui::Text("Edit name:");
|
||||
@@ -106,7 +106,7 @@ bool NameSetting::PopupEditName(const char* name) {
|
||||
bool rv = false;
|
||||
|
||||
char id[128];
|
||||
wpi::format_to_n_c_str(id, sizeof(id), "Name{}", name);
|
||||
wpi::util::format_to_n_c_str(id, sizeof(id), "Name{}", name);
|
||||
|
||||
if (ImGui::BeginPopupContextItem(id)) {
|
||||
ImGui::Text("Edit name:");
|
||||
|
||||
Reference in New Issue
Block a user