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>
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include <hal/simulation/DriverStationData.h>
|
|
|
|
|
|
|
|
|
|
using namespace halsimgui;
|
|
|
|
|
|
|
|
|
|
static bool gDisableOutputsOnDSDisable = true;
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
ImGui::MenuItem(viewEntry->name.c_str(), nullptr, &visible,
|
|
|
|
|
visible || exists);
|
|
|
|
|
if (!wasVisible && visible) {
|
|
|
|
|
Show(viewEntry.get(), viewEntry->window);
|
|
|
|
|
} else if (wasVisible && !visible && viewEntry->window) {
|
|
|
|
|
viewEntry->window->SetVisible(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HALProvider::Update() {
|
|
|
|
|
Provider::Update();
|
|
|
|
|
|
|
|
|
|
// check for visible windows that need displays (typically this is due to
|
|
|
|
|
// file loading)
|
|
|
|
|
for (auto&& window : m_windows) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!window->IsVisible() || window->HasView()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
auto id = window->GetId();
|
|
|
|
|
auto it = FindViewEntry(id);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (it == m_viewEntries.end() || (*it)->name != id) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
Show(it->get(), window.get());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glass::Model* HALProvider::GetModel(wpi::StringRef name) {
|
|
|
|
|
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) {
|
|
|
|
|
// if there's already a window, just show it
|
|
|
|
|
if (entry->window) {
|
|
|
|
|
entry->window->SetVisible(true);
|
|
|
|
|
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) {
|
|
|
|
|
window = GetOrAddWindow(entry->name, true);
|
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
entry->window->SetVisible(true);
|
|
|
|
|
}
|