2020-12-26 14:31:24 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
#include <GLFW/glfw3.h>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <fmt/format.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <imgui.h>
|
|
|
|
|
#include <ntcore_cpp.h>
|
|
|
|
|
#include <wpigui.h>
|
|
|
|
|
|
|
|
|
|
#include "glass/Context.h"
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
#include "glass/MainMenuBar.h"
|
2020-09-12 10:55:46 -07:00
|
|
|
#include "glass/Model.h"
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
#include "glass/Storage.h"
|
2020-09-12 10:55:46 -07:00
|
|
|
#include "glass/View.h"
|
|
|
|
|
#include "glass/networktables/NetworkTables.h"
|
|
|
|
|
#include "glass/networktables/NetworkTablesProvider.h"
|
2021-03-06 22:19:00 -08:00
|
|
|
#include "glass/networktables/NetworkTablesSettings.h"
|
2020-12-29 20:47:58 -08:00
|
|
|
#include "glass/other/Log.h"
|
2020-09-12 10:55:46 -07:00
|
|
|
#include "glass/other/Plot.h"
|
|
|
|
|
|
|
|
|
|
namespace gui = wpi::gui;
|
|
|
|
|
|
2021-01-01 18:59:00 -05:00
|
|
|
const char* GetWPILibVersion();
|
|
|
|
|
|
2020-12-23 13:05:44 -08:00
|
|
|
namespace glass {
|
2021-06-06 16:13:58 -07:00
|
|
|
std::string_view GetResource_glass_16_png();
|
|
|
|
|
std::string_view GetResource_glass_32_png();
|
|
|
|
|
std::string_view GetResource_glass_48_png();
|
|
|
|
|
std::string_view GetResource_glass_64_png();
|
|
|
|
|
std::string_view GetResource_glass_128_png();
|
|
|
|
|
std::string_view GetResource_glass_256_png();
|
|
|
|
|
std::string_view GetResource_glass_512_png();
|
2020-12-23 13:05:44 -08:00
|
|
|
} // namespace glass
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
static std::unique_ptr<glass::PlotProvider> gPlotProvider;
|
|
|
|
|
static std::unique_ptr<glass::NetworkTablesProvider> gNtProvider;
|
|
|
|
|
|
|
|
|
|
static std::unique_ptr<glass::NetworkTablesModel> gNetworkTablesModel;
|
2021-03-06 22:19:00 -08:00
|
|
|
static std::unique_ptr<glass::NetworkTablesSettings> gNetworkTablesSettings;
|
2020-12-29 20:47:58 -08:00
|
|
|
static glass::LogData gNetworkTablesLog;
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
static std::unique_ptr<glass::Window> gNetworkTablesWindow;
|
2022-10-08 10:01:31 -07:00
|
|
|
static std::unique_ptr<glass::Window> gNetworkTablesInfoWindow;
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
static std::unique_ptr<glass::Window> gNetworkTablesSettingsWindow;
|
|
|
|
|
static std::unique_ptr<glass::Window> gNetworkTablesLogWindow;
|
|
|
|
|
|
|
|
|
|
static glass::MainMenuBar gMainMenu;
|
|
|
|
|
static bool gAbout = false;
|
2022-02-06 00:11:37 -08:00
|
|
|
static bool gSetEnterKey = false;
|
|
|
|
|
static bool gKeyEdit = false;
|
2022-05-29 18:44:52 -07:00
|
|
|
static int* gEnterKey;
|
|
|
|
|
static void (*gPrevKeyCallback)(GLFWwindow*, int, int, int, int);
|
|
|
|
|
|
|
|
|
|
static void RemapEnterKeyCallback(GLFWwindow* window, int key, int scancode,
|
|
|
|
|
int action, int mods) {
|
|
|
|
|
if (action == GLFW_PRESS || action == GLFW_RELEASE) {
|
|
|
|
|
if (gKeyEdit) {
|
|
|
|
|
*gEnterKey = key;
|
|
|
|
|
gKeyEdit = false;
|
|
|
|
|
} else if (*gEnterKey == key) {
|
|
|
|
|
key = GLFW_KEY_ENTER;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gPrevKeyCallback) {
|
|
|
|
|
gPrevKeyCallback(window, key, scancode, action, mods);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
static void NtInitialize() {
|
|
|
|
|
// update window title when connection status changes
|
|
|
|
|
auto inst = nt::GetDefaultInstance();
|
|
|
|
|
auto poller = nt::CreateConnectionListenerPoller(inst);
|
|
|
|
|
nt::AddPolledConnectionListener(poller, true);
|
|
|
|
|
gui::AddEarlyExecute([poller] {
|
|
|
|
|
auto win = gui::GetSystemWindow();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!win) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
for (auto&& event : nt::ReadConnectionListenerQueue(poller)) {
|
2020-09-12 10:55:46 -07:00
|
|
|
if (event.connected) {
|
2021-06-06 16:13:58 -07:00
|
|
|
glfwSetWindowTitle(
|
|
|
|
|
win, fmt::format("Glass - Connected ({})", event.conn.remote_ip)
|
|
|
|
|
.c_str());
|
2020-09-12 10:55:46 -07:00
|
|
|
} else {
|
|
|
|
|
glfwSetWindowTitle(win, "Glass - DISCONNECTED");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-29 20:47:58 -08:00
|
|
|
// handle NetworkTables log messages
|
|
|
|
|
auto logPoller = nt::CreateLoggerPoller(inst);
|
|
|
|
|
nt::AddPolledLogger(logPoller, NT_LOG_INFO, 100);
|
|
|
|
|
gui::AddEarlyExecute([logPoller] {
|
2022-10-08 10:01:31 -07:00
|
|
|
for (auto&& msg : nt::ReadLoggerQueue(logPoller)) {
|
2020-12-29 20:47:58 -08:00
|
|
|
const char* level = "";
|
|
|
|
|
if (msg.level >= NT_LOG_CRITICAL) {
|
|
|
|
|
level = "CRITICAL: ";
|
|
|
|
|
} else if (msg.level >= NT_LOG_ERROR) {
|
|
|
|
|
level = "ERROR: ";
|
|
|
|
|
} else if (msg.level >= NT_LOG_WARNING) {
|
|
|
|
|
level = "WARNING: ";
|
|
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
gNetworkTablesLog.Append(fmt::format("{}{} ({}:{})\n", level, msg.message,
|
|
|
|
|
msg.filename, msg.line));
|
2020-12-29 20:47:58 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gNetworkTablesLogWindow = std::make_unique<glass::Window>(
|
|
|
|
|
glass::GetStorageRoot().GetChild("NetworkTables Log"),
|
|
|
|
|
"NetworkTables Log", glass::Window::kHide);
|
|
|
|
|
gNetworkTablesLogWindow->SetView(
|
2020-12-29 20:47:58 -08:00
|
|
|
std::make_unique<glass::LogView>(&gNetworkTablesLog));
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gNetworkTablesLogWindow->SetDefaultPos(250, 615);
|
|
|
|
|
gNetworkTablesLogWindow->SetDefaultSize(600, 130);
|
|
|
|
|
gNetworkTablesLogWindow->DisableRenamePopup();
|
|
|
|
|
gui::AddLateExecute([] { gNetworkTablesLogWindow->Display(); });
|
2020-12-29 20:47:58 -08:00
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
// NetworkTables table window
|
|
|
|
|
gNetworkTablesModel = std::make_unique<glass::NetworkTablesModel>();
|
|
|
|
|
gui::AddEarlyExecute([] { gNetworkTablesModel->Update(); });
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gNetworkTablesWindow = std::make_unique<glass::Window>(
|
|
|
|
|
glass::GetStorageRoot().GetChild("NetworkTables View"), "NetworkTables");
|
|
|
|
|
gNetworkTablesWindow->SetView(
|
2020-09-12 10:55:46 -07:00
|
|
|
std::make_unique<glass::NetworkTablesView>(gNetworkTablesModel.get()));
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gNetworkTablesWindow->SetDefaultPos(250, 277);
|
|
|
|
|
gNetworkTablesWindow->SetDefaultSize(750, 185);
|
|
|
|
|
gNetworkTablesWindow->DisableRenamePopup();
|
|
|
|
|
gui::AddLateExecute([] { gNetworkTablesWindow->Display(); });
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
// NetworkTables info window
|
|
|
|
|
gNetworkTablesInfoWindow = std::make_unique<glass::Window>(
|
|
|
|
|
glass::GetStorageRoot().GetChild("NetworkTables Info"),
|
|
|
|
|
"NetworkTables Info");
|
|
|
|
|
gNetworkTablesInfoWindow->SetView(glass::MakeFunctionView(
|
|
|
|
|
[&] { glass::DisplayNetworkTablesInfo(gNetworkTablesModel.get()); }));
|
|
|
|
|
gNetworkTablesInfoWindow->SetDefaultPos(250, 130);
|
|
|
|
|
gNetworkTablesInfoWindow->SetDefaultSize(750, 145);
|
|
|
|
|
gNetworkTablesInfoWindow->SetDefaultVisibility(glass::Window::kHide);
|
|
|
|
|
gNetworkTablesInfoWindow->DisableRenamePopup();
|
|
|
|
|
gui::AddLateExecute([] { gNetworkTablesInfoWindow->Display(); });
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
// NetworkTables settings window
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gNetworkTablesSettings = std::make_unique<glass::NetworkTablesSettings>(
|
2022-10-08 10:01:31 -07:00
|
|
|
"glass", glass::GetStorageRoot().GetChild("NetworkTables Settings"));
|
2020-09-12 10:55:46 -07:00
|
|
|
gui::AddEarlyExecute([] { gNetworkTablesSettings->Update(); });
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gNetworkTablesSettingsWindow = std::make_unique<glass::Window>(
|
|
|
|
|
glass::GetStorageRoot().GetChild("NetworkTables Settings"),
|
|
|
|
|
"NetworkTables Settings");
|
|
|
|
|
gNetworkTablesSettingsWindow->SetView(
|
|
|
|
|
glass::MakeFunctionView([] { gNetworkTablesSettings->Display(); }));
|
|
|
|
|
gNetworkTablesSettingsWindow->SetDefaultPos(30, 30);
|
|
|
|
|
gNetworkTablesSettingsWindow->SetFlags(ImGuiWindowFlags_AlwaysAutoResize);
|
|
|
|
|
gNetworkTablesSettingsWindow->DisableRenamePopup();
|
|
|
|
|
gui::AddLateExecute([] { gNetworkTablesSettingsWindow->Display(); });
|
|
|
|
|
|
|
|
|
|
gui::AddWindowScaler([](float scale) {
|
|
|
|
|
// scale default window positions
|
|
|
|
|
gNetworkTablesLogWindow->ScaleDefault(scale);
|
|
|
|
|
gNetworkTablesWindow->ScaleDefault(scale);
|
|
|
|
|
gNetworkTablesSettingsWindow->ScaleDefault(scale);
|
|
|
|
|
});
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
int __stdcall WinMain(void* hInstance, void* hPrevInstance, char* pCmdLine,
|
|
|
|
|
int nCmdShow) {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
int argc = __argc;
|
|
|
|
|
char** argv = __argv;
|
2020-09-12 10:55:46 -07:00
|
|
|
#else
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
int main(int argc, char** argv) {
|
2020-09-12 10:55:46 -07:00
|
|
|
#endif
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
std::string_view saveDir;
|
|
|
|
|
if (argc == 2) {
|
|
|
|
|
saveDir = argv[1];
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
gui::CreateContext();
|
|
|
|
|
glass::CreateContext();
|
|
|
|
|
|
2020-12-23 13:05:44 -08:00
|
|
|
gui::AddIcon(glass::GetResource_glass_16_png());
|
|
|
|
|
gui::AddIcon(glass::GetResource_glass_32_png());
|
|
|
|
|
gui::AddIcon(glass::GetResource_glass_48_png());
|
|
|
|
|
gui::AddIcon(glass::GetResource_glass_64_png());
|
|
|
|
|
gui::AddIcon(glass::GetResource_glass_128_png());
|
|
|
|
|
gui::AddIcon(glass::GetResource_glass_256_png());
|
|
|
|
|
gui::AddIcon(glass::GetResource_glass_512_png());
|
|
|
|
|
|
2022-06-01 21:36:54 -07:00
|
|
|
gui::AddEarlyExecute(
|
|
|
|
|
[] { ImGui::DockSpaceOverViewport(ImGui::GetMainViewport()); });
|
|
|
|
|
|
|
|
|
|
gui::AddInit([] { ImGui::GetIO().ConfigDockingWithShift = true; });
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gPlotProvider = std::make_unique<glass::PlotProvider>(
|
|
|
|
|
glass::GetStorageRoot().GetChild("Plots"));
|
|
|
|
|
gNtProvider = std::make_unique<glass::NetworkTablesProvider>(
|
|
|
|
|
glass::GetStorageRoot().GetChild("NetworkTables"));
|
2020-09-12 10:55:46 -07:00
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
glass::SetStorageName("glass");
|
|
|
|
|
glass::SetStorageDir(saveDir.empty() ? gui::GetPlatformSaveFileDir()
|
|
|
|
|
: saveDir);
|
2020-09-12 10:55:46 -07:00
|
|
|
gPlotProvider->GlobalInit();
|
2020-12-17 07:27:29 -08:00
|
|
|
gui::AddInit([] { glass::ResetTime(); });
|
2020-09-12 10:55:46 -07:00
|
|
|
gNtProvider->GlobalInit();
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
NtInitialize();
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
glass::AddStandardNetworkTablesViews(*gNtProvider);
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gui::AddLateExecute([] { gMainMenu.Display(); });
|
|
|
|
|
|
|
|
|
|
gMainMenu.AddMainMenu([] {
|
2020-12-17 07:27:29 -08:00
|
|
|
if (ImGui::BeginMenu("View")) {
|
2022-02-06 00:11:37 -08:00
|
|
|
if (ImGui::MenuItem("Set Enter Key")) {
|
|
|
|
|
gSetEnterKey = true;
|
|
|
|
|
}
|
2020-12-28 12:58:06 -08:00
|
|
|
if (ImGui::MenuItem("Reset Time")) {
|
|
|
|
|
glass::ResetTime();
|
|
|
|
|
}
|
2020-12-17 07:27:29 -08:00
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
if (ImGui::BeginMenu("NetworkTables")) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (gNetworkTablesSettingsWindow) {
|
2020-09-12 10:55:46 -07:00
|
|
|
gNetworkTablesSettingsWindow->DisplayMenuItem("NetworkTables Settings");
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
|
|
|
|
if (gNetworkTablesWindow) {
|
2020-09-12 10:55:46 -07:00
|
|
|
gNetworkTablesWindow->DisplayMenuItem("NetworkTables View");
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2022-10-08 10:01:31 -07:00
|
|
|
if (gNetworkTablesInfoWindow) {
|
|
|
|
|
gNetworkTablesInfoWindow->DisplayMenuItem("NetworkTables Info");
|
|
|
|
|
}
|
2020-12-29 20:47:58 -08:00
|
|
|
if (gNetworkTablesLogWindow) {
|
|
|
|
|
gNetworkTablesLogWindow->DisplayMenuItem("NetworkTables Log");
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::Separator();
|
|
|
|
|
gNtProvider->DisplayMenu();
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::BeginMenu("Plot")) {
|
|
|
|
|
bool paused = gPlotProvider->IsPaused();
|
|
|
|
|
if (ImGui::MenuItem("Pause All Plots", nullptr, &paused)) {
|
|
|
|
|
gPlotProvider->SetPaused(paused);
|
|
|
|
|
}
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
gPlotProvider->DisplayMenu();
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
2021-01-01 18:59:00 -05:00
|
|
|
|
|
|
|
|
if (ImGui::BeginMenu("Info")) {
|
|
|
|
|
if (ImGui::MenuItem("About")) {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gAbout = true;
|
2021-01-01 18:59:00 -05:00
|
|
|
}
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
});
|
2021-01-01 18:59:00 -05:00
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gui::AddLateExecute([] {
|
|
|
|
|
if (gAbout) {
|
2021-01-01 18:59:00 -05:00
|
|
|
ImGui::OpenPopup("About");
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gAbout = false;
|
2021-01-01 18:59:00 -05:00
|
|
|
}
|
|
|
|
|
if (ImGui::BeginPopupModal("About")) {
|
|
|
|
|
ImGui::Text("Glass: A different kind of dashboard");
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
ImGui::Text("v%s", GetWPILibVersion());
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
ImGui::Separator();
|
|
|
|
|
ImGui::Text("Save location: %s", glass::GetStorageDir().c_str());
|
2021-01-01 18:59:00 -05:00
|
|
|
if (ImGui::Button("Close")) {
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
2022-02-06 00:11:37 -08:00
|
|
|
|
|
|
|
|
if (gSetEnterKey) {
|
|
|
|
|
ImGui::OpenPopup("Set Enter Key");
|
|
|
|
|
gSetEnterKey = false;
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::BeginPopupModal("Set Enter Key")) {
|
|
|
|
|
ImGui::Text("Set the key to use to mean 'Enter'");
|
|
|
|
|
ImGui::Text("This is useful to edit values without the DS disabling");
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
|
|
ImGui::Text("Key:");
|
|
|
|
|
ImGui::SameLine();
|
2022-02-12 22:29:26 -08:00
|
|
|
char editLabel[40];
|
2022-02-06 00:11:37 -08:00
|
|
|
char nameBuf[32];
|
2022-05-29 18:44:52 -07:00
|
|
|
const char* name = glfwGetKeyName(*gEnterKey, 0);
|
2022-02-06 00:11:37 -08:00
|
|
|
if (!name) {
|
2022-05-29 18:44:52 -07:00
|
|
|
std::snprintf(nameBuf, sizeof(nameBuf), "%d", *gEnterKey);
|
2022-02-06 00:11:37 -08:00
|
|
|
name = nameBuf;
|
|
|
|
|
}
|
|
|
|
|
std::snprintf(editLabel, sizeof(editLabel), "%s###edit",
|
|
|
|
|
gKeyEdit ? "(press key)" : name);
|
|
|
|
|
if (ImGui::SmallButton(editLabel)) {
|
|
|
|
|
gKeyEdit = true;
|
|
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::SmallButton("Reset")) {
|
2022-05-29 18:44:52 -07:00
|
|
|
*gEnterKey = GLFW_KEY_ENTER;
|
2022-02-06 00:11:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::Button("Close")) {
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
gKeyEdit = false;
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
});
|
|
|
|
|
|
2022-06-01 21:36:54 -07:00
|
|
|
gui::Initialize("Glass - DISCONNECTED", 1024, 768,
|
|
|
|
|
ImGuiConfigFlags_DockingEnable);
|
2022-05-29 18:44:52 -07:00
|
|
|
gEnterKey = &glass::GetStorageRoot().GetInt("enterKey", GLFW_KEY_ENTER);
|
|
|
|
|
if (auto win = gui::GetSystemWindow()) {
|
|
|
|
|
gPrevKeyCallback = glfwSetKeyCallback(win, RemapEnterKeyCallback);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
gui::Main();
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gNetworkTablesSettingsWindow.reset();
|
|
|
|
|
gNetworkTablesLogWindow.reset();
|
|
|
|
|
gNetworkTablesWindow.reset();
|
2020-09-12 10:55:46 -07:00
|
|
|
gNetworkTablesModel.reset();
|
|
|
|
|
gNtProvider.reset();
|
|
|
|
|
gPlotProvider.reset();
|
|
|
|
|
|
|
|
|
|
glass::DestroyContext();
|
|
|
|
|
gui::DestroyContext();
|
2021-11-26 23:19:45 -08:00
|
|
|
|
|
|
|
|
return 0;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|