Commit f27ce12a authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

gui: improve debug mode

parent e5935662
...@@ -26,11 +26,14 @@ static int kernel_message_cache = 32768; ...@@ -26,11 +26,14 @@ static int kernel_message_cache = 32768;
static int gui_node_cache = 1024; static int gui_node_cache = 1024;
static ImVec4 gui_model_color{ .27f, .27f, .54f, 1.f }; static ImVec4 gui_model_color{ .27f, .27f, .54f, 1.f };
static ImVec4 gui_model_transition_color{ .27f, .54f, .54f, 1.f };
static ImVec4 gui_cluster_color{ .27f, .54f, .27f, 1.f }; static ImVec4 gui_cluster_color{ .27f, .54f, .27f, 1.f };
static ImU32 gui_hovered_model_color; static ImU32 gui_hovered_model_color;
static ImU32 gui_hovered_cluster_color;
static ImU32 gui_selected_model_color; static ImU32 gui_selected_model_color;
static ImU32 gui_hovered_model_transition_color;
static ImU32 gui_selected_model_transition_color;
static ImU32 gui_hovered_cluster_color;
static ImU32 gui_selected_cluster_color; static ImU32 gui_selected_cluster_color;
static int automatic_layout_iteration_limit = 200; static int automatic_layout_iteration_limit = 200;
...@@ -39,7 +42,8 @@ static auto automatic_layout_y_distance = 350.f; ...@@ -39,7 +42,8 @@ static auto automatic_layout_y_distance = 350.f;
static auto grid_layout_x_distance = 250.f; static auto grid_layout_x_distance = 250.f;
static auto grid_layout_y_distance = 250.f; static auto grid_layout_y_distance = 250.f;
static ImVec4 operator*(const ImVec4& lhs, const float rhs) noexcept static ImVec4
operator*(const ImVec4& lhs, const float rhs) noexcept
{ {
return ImVec4(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs); return ImVec4(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs);
} }
...@@ -52,6 +56,11 @@ compute_color() noexcept ...@@ -52,6 +56,11 @@ compute_color() noexcept
gui_selected_model_color = gui_selected_model_color =
ImGui::ColorConvertFloat4ToU32(gui_model_color * 1.5f); ImGui::ColorConvertFloat4ToU32(gui_model_color * 1.5f);
gui_hovered_model_transition_color =
ImGui::ColorConvertFloat4ToU32(gui_model_transition_color * 1.25f);
gui_selected_model_transition_color =
ImGui::ColorConvertFloat4ToU32(gui_model_transition_color * 1.5f);
gui_hovered_cluster_color = gui_hovered_cluster_color =
ImGui::ColorConvertFloat4ToU32(gui_cluster_color * 1.25f); ImGui::ColorConvertFloat4ToU32(gui_cluster_color * 1.25f);
gui_selected_cluster_color = gui_selected_cluster_color =
...@@ -607,49 +616,48 @@ struct copier ...@@ -607,49 +616,48 @@ struct copier
auto ret = sim.dispatch( auto ret = sim.dispatch(
mdl->type, mdl->type,
[ this, &sim, mdl, & [this, &sim, mdl, &mdl_id_dst]<typename DynamicsM>(
mdl_id_dst ]<typename DynamicsM>(DynamicsM & dynamics_models) DynamicsM& dynamics_models) -> status {
->status { using Dynamics = typename DynamicsM::value_type;
using Dynamics = typename DynamicsM::value_type;
irt_return_if_fail(dynamics_models.can_alloc(1), irt_return_if_fail(dynamics_models.can_alloc(1),
status::dynamics_not_enough_memory); status::dynamics_not_enough_memory);
auto* dyn_ptr = dynamics_models.try_to_get(mdl->id); auto* dyn_ptr = dynamics_models.try_to_get(mdl->id);
irt_return_if_fail(dyn_ptr, status::dynamics_unknown_id); irt_return_if_fail(dyn_ptr, status::dynamics_unknown_id);
auto& new_dyn = dynamics_models.alloc(*dyn_ptr); auto& new_dyn = dynamics_models.alloc(*dyn_ptr);
auto new_dyn_id = dynamics_models.get_id(new_dyn); auto new_dyn_id = dynamics_models.get_id(new_dyn);
if constexpr (is_detected_v<has_input_port_t, Dynamics>) if constexpr (is_detected_v<has_input_port_t, Dynamics>)
std::fill_n(new_dyn.x, std::fill_n(new_dyn.x,
std::size(new_dyn.x), std::size(new_dyn.x),
static_cast<input_port_id>(0)); static_cast<input_port_id>(0));
if constexpr (is_detected_v<has_output_port_t, Dynamics>) if constexpr (is_detected_v<has_output_port_t, Dynamics>)
std::fill_n(new_dyn.y, std::fill_n(new_dyn.y,
std::size(new_dyn.y), std::size(new_dyn.y),
static_cast<output_port_id>(0)); static_cast<output_port_id>(0));
irt_return_if_bad( irt_return_if_bad(
sim.alloc(new_dyn, new_dyn_id, mdl->name.c_str())); sim.alloc(new_dyn, new_dyn_id, mdl->name.c_str()));
*mdl_id_dst = new_dyn.id; *mdl_id_dst = new_dyn.id;
if constexpr (is_detected_v<has_input_port_t, Dynamics>) if constexpr (is_detected_v<has_input_port_t, Dynamics>)
for (size_t j = 0, ej = std::size(new_dyn.x); j != ej; for (size_t j = 0, ej = std::size(new_dyn.x); j != ej;
++j) ++j)
this->c_input_ports.emplace_back(dyn_ptr->x[j], this->c_input_ports.emplace_back(dyn_ptr->x[j],
new_dyn.x[j]); new_dyn.x[j]);
if constexpr (is_detected_v<has_output_port_t, Dynamics>) if constexpr (is_detected_v<has_output_port_t, Dynamics>)
for (size_t j = 0, ej = std::size(new_dyn.y); j != ej; for (size_t j = 0, ej = std::size(new_dyn.y); j != ej;
++j) ++j)
this->c_output_ports.emplace_back(dyn_ptr->y[j], this->c_output_ports.emplace_back(dyn_ptr->y[j],
new_dyn.y[j]); new_dyn.y[j]);
return status::success; return status::success;
}); });
irt_return_if_bad(ret); irt_return_if_bad(ret);
} }
...@@ -984,6 +992,7 @@ editor::initialize(u32 id) noexcept ...@@ -984,6 +992,7 @@ editor::initialize(u32 id) noexcept
is_bad(clusters.init(sim.models.capacity())) || is_bad(clusters.init(sim.models.capacity())) ||
is_bad(models_mapper.init(sim.models.capacity())) || is_bad(models_mapper.init(sim.models.capacity())) ||
is_bad(clusters_mapper.init(sim.models.capacity())) || is_bad(clusters_mapper.init(sim.models.capacity())) ||
is_bad(models_make_transition.init(sim.models.capacity())) ||
is_bad(top.init(static_cast<unsigned>(gui_node_cache)))) is_bad(top.init(static_cast<unsigned>(gui_node_cache))))
return status::gui_not_enough_memory; return status::gui_not_enough_memory;
...@@ -991,6 +1000,8 @@ editor::initialize(u32 id) noexcept ...@@ -991,6 +1000,8 @@ editor::initialize(u32 id) noexcept
displacements.resize(sim.models.capacity() + clusters.capacity(), displacements.resize(sim.models.capacity() + clusters.capacity(),
ImVec2{ 0.f, 0.f }); ImVec2{ 0.f, 0.f });
std::fill_n(models_make_transition.data(), sim.models.capacity(), false);
format(name, "Editor {}", id); format(name, "Editor {}", id);
initialized = true; initialized = true;
...@@ -2261,13 +2272,33 @@ editor::show_top() noexcept ...@@ -2261,13 +2272,33 @@ editor::show_top() noexcept
if (top.children[i].first.index() == 0) { if (top.children[i].first.index() == 0) {
const auto id = std::get<model_id>(top.children[i].first); const auto id = std::get<model_id>(top.children[i].first);
if (auto* mdl = sim.models.try_to_get(id); mdl) { if (auto* mdl = sim.models.try_to_get(id); mdl) {
imnodes::PushColorStyle( if (match(st,
imnodes::ColorStyle_TitleBar, simulation_status::success,
ImGui::ColorConvertFloat4ToU32(gui_model_color)); simulation_status::running_once,
imnodes::PushColorStyle(imnodes::ColorStyle_TitleBarHovered, simulation_status::running_once_need_join,
gui_hovered_model_color); simulation_status::running_step) &&
imnodes::PushColorStyle(imnodes::ColorStyle_TitleBarSelected, models_make_transition[get_index(id)]) {
gui_selected_model_color);
imnodes::PushColorStyle(imnodes::ColorStyle_TitleBar,
ImGui::ColorConvertFloat4ToU32(
gui_model_transition_color));
imnodes::PushColorStyle(imnodes::ColorStyle_TitleBarHovered,
gui_hovered_model_transition_color);
imnodes::PushColorStyle(
imnodes::ColorStyle_TitleBarSelected,
gui_selected_model_transition_color);
} else {
imnodes::PushColorStyle(
imnodes::ColorStyle_TitleBar,
ImGui::ColorConvertFloat4ToU32(gui_model_color));
imnodes::PushColorStyle(imnodes::ColorStyle_TitleBarHovered,
gui_hovered_model_color);
imnodes::PushColorStyle(
imnodes::ColorStyle_TitleBarSelected,
gui_selected_model_color);
}
imnodes::BeginNode(top.children[i].second); imnodes::BeginNode(top.children[i].second);
imnodes::BeginNodeTitleBar(); imnodes::BeginNodeTitleBar();
......
...@@ -252,11 +252,15 @@ struct editor ...@@ -252,11 +252,15 @@ struct editor
bool show = true; bool show = true;
simulation sim; simulation sim;
double simulation_begin = 0.0; double simulation_begin = 0.0;
double simulation_end = 10.0; double simulation_end = 10.0;
double simulation_current = 10.0; double simulation_current = 10.0;
double simulation_next_time = 0.0; double simulation_next_time = 0.0;
float simulation_until; long simulation_bag_id = 0;
double simulation_during_date;
int simulation_during_bag;
std::thread simulation_thread; std::thread simulation_thread;
simulation_status st = simulation_status::success; simulation_status st = simulation_status::success;
...@@ -272,6 +276,8 @@ struct editor ...@@ -272,6 +276,8 @@ struct editor
array<cluster_id> clusters_mapper; /* group per cluster_id */ array<cluster_id> clusters_mapper; /* group per cluster_id */
array<cluster_id> models_mapper; /* group per model_id */ array<cluster_id> models_mapper; /* group per model_id */
array<bool> models_make_transition;
ImVector<ImVec2> positions; ImVector<ImVec2> positions;
ImVector<ImVec2> displacements; ImVector<ImVec2> displacements;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#define WINDOWS_LEAN_AND_MEAN #define WINDOWS_LEAN_AND_MEAN
#endif #endif
#include <cstdlib>
#include "gui.hpp" #include "gui.hpp"
#include "imnodes.hpp" #include "imnodes.hpp"
#include "implot.h" #include "implot.h"
...@@ -226,7 +228,10 @@ simulation_init(window_logger& log_w, editor& ed) ...@@ -226,7 +228,10 @@ simulation_init(window_logger& log_w, editor& ed)
initialize_observation(log_w, ed); initialize_observation(log_w, ed);
ed.simulation_current = ed.simulation_begin; ed.simulation_current = ed.simulation_begin;
ed.simulation_until = static_cast<float>(ed.simulation_begin); ed.simulation_during_date = ed.simulation_begin;
std::fill_n(
ed.models_make_transition.data(), ed.sim.models.max_used(), false);
if (auto ret = ed.sim.initialize(ed.simulation_current); irt::is_bad(ret)) { if (auto ret = ed.sim.initialize(ed.simulation_current); irt::is_bad(ret)) {
log_w.log(3, log_w.log(3,
...@@ -237,6 +242,7 @@ simulation_init(window_logger& log_w, editor& ed) ...@@ -237,6 +242,7 @@ simulation_init(window_logger& log_w, editor& ed)
ed.simulation_next_time = ed.sim.sched.empty() ed.simulation_next_time = ed.sim.sched.empty()
? time_domain<time>::infinity ? time_domain<time>::infinity
: ed.sim.sched.tn(); : ed.sim.sched.tn();
ed.simulation_bag_id = 0;
ed.st = simulation_status::running_step; ed.st = simulation_status::running_step;
} }
} }
...@@ -251,8 +257,9 @@ show_simulation_run_debug(window_logger& log_w, editor& ed) ...@@ -251,8 +257,9 @@ show_simulation_run_debug(window_logger& log_w, editor& ed)
simulation_init(log_w, ed); simulation_init(log_w, ed);
} else { } else {
ImGui::Text("Current time %g", ed.simulation_current); ImGui::Text("Current time %g", ed.simulation_current);
ImGui::Text("Current bag %ld", ed.simulation_bag_id);
ImGui::Text("Next time %g", ed.simulation_next_time); ImGui::Text("Next time %g", ed.simulation_next_time);
ImGui::Text("Bag size %lu", (unsigned long)ed.sim.sched.size()); ImGui::Text("Model %lu", (unsigned long)ed.sim.sched.size());
if (ImGui::Button("re-init.")) if (ImGui::Button("re-init."))
simulation_init(log_w, ed); simulation_init(log_w, ed);
...@@ -260,15 +267,80 @@ show_simulation_run_debug(window_logger& log_w, editor& ed) ...@@ -260,15 +267,80 @@ show_simulation_run_debug(window_logger& log_w, editor& ed)
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Next bag")) { if (ImGui::Button("Next bag")) {
auto ret = ed.sim.run(ed.simulation_current); if (auto ret = ed.sim.run(ed.simulation_current); is_bad(ret)) {
if (is_bad(ret)) {
ed.st = simulation_status::success; ed.st = simulation_status::success;
ed.simulation_next_time = time_domain<time>::infinity;
} else {
ed.simulation_next_time = ed.sim.sched.empty()
? time_domain<time>::infinity
: ed.sim.sched.tn();
} }
++ed.simulation_bag_id;
}
ImGui::SameLine();
if (ImGui::Button("Bag >> 10")) {
for (int i = 0; i < 10; ++i) {
if (auto ret = ed.sim.run(ed.simulation_current); is_bad(ret)) {
ed.st = simulation_status::success;
break;
}
++ed.simulation_bag_id;
}
}
ImGui::SameLine();
if (ImGui::Button("Bag >> 100")) {
for (int i = 0; i < 100; ++i) {
if (auto ret = ed.sim.run(ed.simulation_current); is_bad(ret)) {
ed.st = simulation_status::success;
break;
}
++ed.simulation_bag_id;
}
}
ImGui::InputDouble("##date", &ed.simulation_during_date);
ImGui::SameLine();
if (ImGui::Button("run##date")) {
const auto end = ed.simulation_current + ed.simulation_during_date;
while (ed.simulation_current < end) {
if (auto ret = ed.sim.run(ed.simulation_current); is_bad(ret)) {
ed.st = simulation_status::success;
break;
}
++ed.simulation_bag_id;
}
}
ImGui::InputInt("##bag", &ed.simulation_during_bag);
ImGui::SameLine();
if (ImGui::Button("run##bag")) {
for (int i = 0, e = ed.simulation_during_bag; i != e; ++i) {
if (auto ret = ed.sim.run(ed.simulation_current); is_bad(ret)) {
ed.st = simulation_status::success;
break;
}
++ed.simulation_bag_id;
}
}
if (ed.st == simulation_status::running_step) {
ed.simulation_next_time = ed.sim.sched.empty()
? time_domain<time>::infinity
: ed.sim.sched.tn();
const auto& l = ed.sim.sched.list_model_id();
std::fill_n(ed.models_make_transition.data(),
ed.sim.models.max_used(),
false);
for (auto it = l.begin(), e = l.end(); it != e; ++it)
ed.models_make_transition[get_index(*it)] = true;
} else {
ed.simulation_next_time = time_domain<time>::infinity;
} }
} }
} }
......
...@@ -5638,6 +5638,11 @@ public: ...@@ -5638,6 +5638,11 @@ public:
return m_list; return m_list;
} }
const list& list_model_id() const noexcept
{
return m_list;
}
time tn() const noexcept time tn() const noexcept
{ {
return m_heap.top()->tn; return m_heap.top()->tn;
......
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