2020-12-26 14:12:05 -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 "HALProvider.h"
|
|
|
|
|
|
|
|
|
|
#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 <algorithm>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include <hal/simulation/DriverStationData.h>
|
|
|
|
|
|
|
|
|
|
using namespace halsimgui;
|
|
|
|
|
|
|
|
|
|
static bool gDisableOutputsOnDSDisable = 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
|
|
|
HALProvider::HALProvider(glass::Storage& storage) : Provider{storage} {
|
|
|
|
|
storage.SetCustomApply([this] {
|
|
|
|
|
for (auto&& childIt : m_storage.GetChildren()) {
|
|
|
|
|
auto it = FindViewEntry(childIt.key());
|
|
|
|
|
if (it != m_viewEntries.end() && (*it)->name == childIt.key()) {
|
|
|
|
|
Show(it->get(), nullptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (auto&& entry : m_viewEntries) {
|
|
|
|
|
if (entry->showDefault) {
|
|
|
|
|
Show(entry.get(), entry->window);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
storage.SetCustomClear([this, &storage] {
|
|
|
|
|
for (auto&& entry : m_viewEntries) {
|
|
|
|
|
entry->window = nullptr;
|
|
|
|
|
}
|
|
|
|
|
m_windows.clear();
|
|
|
|
|
storage.ClearValues();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
bool HALProvider::AreOutputsDisabled() {
|
|
|
|
|
return gDisableOutputsOnDSDisable && !HALSIM_GetDriverStationEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HALProvider::DisplayMenu() {
|
|
|
|
|
ImGui::MenuItem("Disable outputs on DS disable", nullptr,
|
|
|
|
|
&gDisableOutputsOnDSDisable, true);
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
|
|
for (auto&& viewEntry : m_viewEntries) {
|
|
|
|
|
bool visible = viewEntry->window && viewEntry->window->IsVisible();
|
|
|
|
|
bool wasVisible = visible;
|
|
|
|
|
bool exists = viewEntry->modelEntry->exists();
|
[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
|
|
|
if (ImGui::MenuItem(viewEntry->name.c_str(), nullptr, &visible,
|
|
|
|
|
visible || exists)) {
|
|
|
|
|
if (!wasVisible && visible) {
|
|
|
|
|
Show(viewEntry.get(), viewEntry->window);
|
2022-02-06 00:11:12 -08:00
|
|
|
if (viewEntry->window) {
|
|
|
|
|
viewEntry->window->SetVisible(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
|
|
|
} else if (wasVisible && !visible && viewEntry->window) {
|
|
|
|
|
viewEntry->window->SetVisible(false);
|
|
|
|
|
}
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
glass::Model* HALProvider::GetModel(std::string_view name) {
|
2020-09-12 10:55:46 -07:00
|
|
|
auto it = FindModelEntry(name);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (it == m_modelEntries.end() || (*it)->name != name) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
auto entry = it->get();
|
|
|
|
|
|
|
|
|
|
// get or create model
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!entry->model) {
|
|
|
|
|
entry->model = entry->createModel();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
return entry->model.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HALProvider::Show(ViewEntry* entry, glass::Window* window) {
|
2022-02-06 00:11:12 -08:00
|
|
|
// if there's already a window, we're done
|
2020-09-12 10:55:46 -07:00
|
|
|
if (entry->window) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get or create model
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!entry->modelEntry->model) {
|
2020-09-12 10:55:46 -07:00
|
|
|
entry->modelEntry->model = entry->modelEntry->createModel();
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
|
|
|
|
if (!entry->modelEntry->model) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
// the window might exist and we're just not associated to it yet
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!window) {
|
2022-02-06 00:11:12 -08:00
|
|
|
window = GetOrAddWindow(
|
|
|
|
|
entry->name, true,
|
|
|
|
|
entry->showDefault ? glass::Window::kShow : glass::Window::kHide);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
|
|
|
|
if (!window) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
entry->window = window;
|
|
|
|
|
|
|
|
|
|
// create view
|
|
|
|
|
auto view = entry->createView(window, entry->modelEntry->model.get());
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!view) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
window->SetView(std::move(view));
|
|
|
|
|
}
|