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.
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <glass/Context.h>
|
|
|
|
|
#include <glass/other/Plot.h>
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <string_view>
|
|
|
|
|
|
2020-09-02 20:51:43 -07:00
|
|
|
#include <hal/Extensions.h>
|
2019-09-23 00:24:10 -07:00
|
|
|
#include <hal/Main.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <imgui.h>
|
|
|
|
|
#include <wpigui.h>
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
#include "AccelerometerSimGui.h"
|
2019-11-17 16:35:45 -08:00
|
|
|
#include "AddressableLEDGui.h"
|
2020-09-12 10:55:46 -07:00
|
|
|
#include "AnalogGyroSimGui.h"
|
|
|
|
|
#include "AnalogInputSimGui.h"
|
|
|
|
|
#include "AnalogOutputSimGui.h"
|
|
|
|
|
#include "DIOSimGui.h"
|
2019-09-23 00:24:10 -07:00
|
|
|
#include "DriverStationGui.h"
|
2020-09-12 10:55:46 -07:00
|
|
|
#include "EncoderSimGui.h"
|
2019-09-23 00:24:10 -07:00
|
|
|
#include "HALSimGui.h"
|
2020-09-12 10:55:46 -07:00
|
|
|
#include "NetworkTablesSimGui.h"
|
|
|
|
|
#include "PCMSimGui.h"
|
|
|
|
|
#include "PDPSimGui.h"
|
|
|
|
|
#include "PWMSimGui.h"
|
|
|
|
|
#include "RelaySimGui.h"
|
|
|
|
|
#include "RoboRioSimGui.h"
|
2019-09-23 00:24:10 -07:00
|
|
|
#include "SimDeviceGui.h"
|
2019-11-10 20:55:42 -08:00
|
|
|
#include "TimingGui.h"
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
using namespace halsimgui;
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
namespace gui = wpi::gui;
|
|
|
|
|
|
|
|
|
|
static glass::PlotProvider gPlotProvider{"Plot"};
|
|
|
|
|
|
2019-09-23 00:24:10 -07:00
|
|
|
extern "C" {
|
|
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
|
|
|
__declspec(dllexport)
|
|
|
|
|
#endif
|
|
|
|
|
int HALSIM_InitExtension(void) {
|
2021-06-06 16:13:58 -07:00
|
|
|
std::puts("Simulator GUI Initializing.");
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
gui::CreateContext();
|
|
|
|
|
glass::CreateContext();
|
2020-08-26 00:35:44 -07:00
|
|
|
HALSimGui::GlobalInit();
|
2020-09-12 10:55:46 -07:00
|
|
|
DriverStationGui::GlobalInit();
|
|
|
|
|
gPlotProvider.GlobalInit();
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
// These need to initialize first
|
|
|
|
|
gui::AddInit(EncoderSimGui::Initialize);
|
|
|
|
|
gui::AddInit(SimDeviceGui::Initialize);
|
|
|
|
|
|
|
|
|
|
gui::AddInit(AccelerometerSimGui::Initialize);
|
|
|
|
|
gui::AddInit(AddressableLEDGui::Initialize);
|
|
|
|
|
gui::AddInit(AnalogGyroSimGui::Initialize);
|
|
|
|
|
gui::AddInit(AnalogInputSimGui::Initialize);
|
|
|
|
|
gui::AddInit(AnalogOutputSimGui::Initialize);
|
|
|
|
|
gui::AddInit(DIOSimGui::Initialize);
|
|
|
|
|
gui::AddInit(NetworkTablesSimGui::Initialize);
|
|
|
|
|
gui::AddInit(PCMSimGui::Initialize);
|
|
|
|
|
gui::AddInit(PDPSimGui::Initialize);
|
|
|
|
|
gui::AddInit(PWMSimGui::Initialize);
|
|
|
|
|
gui::AddInit(RelaySimGui::Initialize);
|
|
|
|
|
gui::AddInit(RoboRioSimGui::Initialize);
|
|
|
|
|
gui::AddInit(TimingGui::Initialize);
|
|
|
|
|
|
|
|
|
|
HALSimGui::mainMenu.AddMainMenu([] {
|
|
|
|
|
if (ImGui::BeginMenu("Hardware")) {
|
|
|
|
|
HALSimGui::halProvider.DisplayMenu();
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::BeginMenu("NetworkTables")) {
|
|
|
|
|
NetworkTablesSimGui::DisplayMenu();
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
HALSimGui::ntProvider.DisplayMenu();
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::BeginMenu("DS")) {
|
|
|
|
|
DriverStationGui::dsManager.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();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::BeginMenu("Window")) {
|
|
|
|
|
HALSimGui::manager.DisplayMenu();
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!gui::Initialize("Robot Simulation", 1280, 720)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2020-09-02 20:51:43 -07:00
|
|
|
HAL_RegisterExtensionListener(
|
|
|
|
|
nullptr, [](void*, const char* name, void* data) {
|
2021-06-06 16:13:58 -07:00
|
|
|
if (std::string_view{name} == "ds_socket") {
|
2020-09-02 20:51:43 -07:00
|
|
|
DriverStationGui::SetDSSocketExtension(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-09-12 10:55:46 -07:00
|
|
|
HAL_SetMain(
|
|
|
|
|
nullptr,
|
|
|
|
|
[](void*) {
|
|
|
|
|
gui::Main();
|
|
|
|
|
glass::DestroyContext();
|
|
|
|
|
gui::DestroyContext();
|
|
|
|
|
},
|
|
|
|
|
[](void*) { gui::Exit(); });
|
2021-06-06 16:13:58 -07:00
|
|
|
std::puts("Simulator GUI Initialized!");
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
} // extern "C"
|