Commit 2ae7644c authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

gui: refactor editor simulation and application access

parent 5718fc36
Pipeline #34353 failed with stage
in 53 seconds
......@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(irritator-gui VERSION 0.1.0 LANGUAGES CXX)
set(gui_sources
dialog-file.cpp gui.hpp imnodes.cpp imnodes.hpp implot.h implot.cpp
dialog-file.cpp gui.cpp gui.hpp imnodes.cpp imnodes.hpp implot.h implot.cpp
window-logger.cpp node-editor.hpp node-editor.cpp simulation-editor.cpp
sources.cpp
${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.cpp
......
......@@ -10,6 +10,9 @@
namespace irt {
// Forward declarations
struct simulation;
void
application_initialize();
......@@ -19,6 +22,12 @@ application_show();
void
application_shutdown();
void
simulation_run_for(simulation& sim,
const long long int duration_in_microseconds,
const double end,
double& current);
/* Move into internal API */
std::optional<std::filesystem::path>
......
......@@ -3186,17 +3186,17 @@ make_combo_editor_name(application& app, editor_id& current) noexcept
}
void
show_plot_box(application& app, bool* show_plot)
application::show_plot_window()
{
ImGui::SetNextWindowPos(ImVec2(50, 400), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(600, 350), ImGuiCond_Once);
if (!ImGui::Begin("Plot", show_plot)) {
if (!ImGui::Begin("Plot", &show_plot)) {
ImGui::End();
return;
}
static editor_id current = undefined<editor_id>();
if (auto* ed = make_combo_editor_name(app, current); ed) {
if (auto* ed = make_combo_editor_name(*this, current); ed) {
if (ImPlot::BeginPlot("simulation", "t", "s")) {
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 1.f);
......@@ -3217,102 +3217,4 @@ show_plot_box(application& app, bool* show_plot)
ImGui::End();
}
void
application_initialize()
{
if (auto ret = app.editors.init(50u); is_bad(ret)) {
log_w.log(2, "Fail to initialize irritator: %s\n", status_string(ret));
} else {
if (auto* ed = app.alloc_editor(); ed) {
ed->context = imnodes::EditorContextCreate();
ed->settings.compute_colors();
}
}
}
bool
application_show()
{
bool ret = true;
if (ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("New")) {
if (auto* ed = app.alloc_editor(); ed)
ed->context = imnodes::EditorContextCreate();
}
ImGui::Separator();
if (ImGui::MenuItem("Quit"))
ret = false;
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Window")) {
editor* ed = nullptr;
while (app.editors.next(ed))
ImGui::MenuItem(ed->name.c_str(), nullptr, &ed->show);
ImGui::MenuItem("Simulation", nullptr, &app.show_simulation);
ImGui::MenuItem("Plot", nullptr, &app.show_plot);
ImGui::MenuItem("Sources", nullptr, &app.show_sources_window);
ImGui::MenuItem("Settings", nullptr, &app.show_settings);
ImGui::MenuItem("Log", nullptr, &app.show_log);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Help")) {
ImGui::MenuItem("Demo window", nullptr, &app.show_demo);
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
editor* ed = nullptr;
while (app.editors.next(ed)) {
if (ed->show) {
if (!ed->show_editor()) {
editor* next = ed;
app.editors.next(next);
app.free_editor(*ed);
} else {
if (app.show_simulation)
show_simulation_box(*ed, &app.show_simulation);
if (app.show_plot)
show_plot_box(app, &app.show_plot);
if (ed->show_settings)
ed->settings.show(&ed->show_settings);
}
}
}
if (app.show_log)
log_w.show(&app.show_log);
if (app.show_settings)
app.settings.show(&app.show_settings);
if (app.show_demo)
ImGui::ShowDemoWindow();
if (app.show_sources_window)
app.show_sources(&app.show_sources_window);
return ret;
}
void
application_shutdown()
{
editor* ed = nullptr;
while (app.editors.next(ed))
imnodes::EditorContextFree(ed->context);
}
} // namespace irt
......@@ -582,6 +582,9 @@ struct application
void show_sources(bool* is_show);
void show_menu_sources(const char* title, source& src);
void show_plot_window();
void show_simulation_window();
bool show_log = true;
bool show_simulation = true;
bool show_demo = false;
......
......@@ -520,46 +520,49 @@ show_simulation_run_debug(window_logger& log_w, editor& ed)
}
void
show_simulation_box(editor& ed, bool* show_simulation)
application::show_simulation_window()
{
ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(250, 350), ImGuiCond_Once);
if (!ImGui::Begin("Simulation", show_simulation)) {
if (!ImGui::Begin("Simulation", &show_simulation)) {
ImGui::End();
return;
}
ImGui::InputDouble("Begin", &ed.simulation_begin);
ImGui::InputDouble("End", &ed.simulation_end);
ImGui::Checkbox("Show values", &ed.simulation_show_value);
static editor_id current = undefined<editor_id>();
if (auto* ed = make_combo_editor_name(*this, current); ed) {
ImGui::InputDouble("Begin", &ed->simulation_begin);
ImGui::InputDouble("End", &ed->simulation_end);
ImGui::Checkbox("Show values", &ed->simulation_show_value);
if (ImGui::Button("Output files"))
ed.show_select_directory_dialog = true;
if (ImGui::Button("Output files"))
ed->show_select_directory_dialog = true;
ImGui::Text("output directory: ");
ImGui::Text("output directory: ");
#if _WIN32
ImGui::Text("%s", ed.observation_directory.u8string().c_str());
ImGui::Text("%s", ed->observation_directory.u8string().c_str());
#else
ImGui::Text("%s",
reinterpret_cast<const char*>(
ed.observation_directory.u8string().c_str()));
ImGui::Text("%s",
reinterpret_cast<const char*>(
ed->observation_directory.u8string().c_str()));
#endif
if (ImGui::CollapsingHeader("Simulation run one"))
show_simulation_run_once(log_w, ed);
if (ImGui::CollapsingHeader("Simulation run one"))
show_simulation_run_once(log_w, *ed);
if (ImGui::CollapsingHeader("Debug simulation"))
show_simulation_run_debug(log_w, ed);
if (ImGui::CollapsingHeader("Debug simulation"))
show_simulation_run_debug(log_w, *ed);
if (ed.st != editor_status::editing) {
ImGui::Text("Current: %g", ed.simulation_current);
if (ed->st != editor_status::editing) {
ImGui::Text("Current: %g", ed->simulation_current);
const double duration = ed.simulation_end - ed.simulation_begin;
const double elapsed = ed.simulation_current - ed.simulation_begin;
const double fraction = elapsed / duration;
ImGui::ProgressBar(static_cast<float>(fraction));
const double duration = ed->simulation_end - ed->simulation_begin;
const double elapsed =
ed->simulation_current - ed->simulation_begin;
const double fraction = elapsed / duration;
ImGui::ProgressBar(static_cast<float>(fraction));
}
}
ImGui::End();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment