Commit 11467ba0 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

gui: replace ImGui Column with Table

parent 81e4cd0f
......@@ -1937,7 +1937,9 @@ show_dynamics_inputs(simulation& /*sim*/, counter& /*dyn*/)
static void
show_dynamics_inputs(simulation& /*sim*/, queue& dyn)
{
ImGui::InputDouble("time", &dyn.default_ta);
ImGui::InputDouble("delay", &dyn.default_ta);
ImGui::SameLine();
HelpMarker("Delay to resent the first input receives (FIFO queue)");
}
static void
......@@ -2743,13 +2745,15 @@ editor::show_editor() noexcept
"D -- duplicate selected nodes / "
"G -- group model");
ImGui::Columns(2, "Edit");
if (starting) {
ImGui::SetColumnWidth(0, 580.f);
starting = false;
}
constexpr ImGuiTableFlags flags =
ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_Resizable |
ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV |
ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_Resizable |
ImGuiTableFlags_BordersV;
ImGui::Separator();
if (ImGui::BeginTable("Editor", 2, flags)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imnodes::BeginNodeEditor();
......@@ -2809,8 +2813,10 @@ editor::show_editor() noexcept
}
if (ImGui::BeginMenu("AQSS (experimental)")) {
add_popup_menuitem(*this, dynamics_type::integrator, &new_model);
add_popup_menuitem(*this, dynamics_type::quantifier, &new_model);
add_popup_menuitem(
*this, dynamics_type::integrator, &new_model);
add_popup_menuitem(
*this, dynamics_type::quantifier, &new_model);
add_popup_menuitem(*this, dynamics_type::adder_2, &new_model);
add_popup_menuitem(*this, dynamics_type::adder_3, &new_model);
add_popup_menuitem(*this, dynamics_type::adder_4, &new_model);
......@@ -2824,7 +2830,8 @@ editor::show_editor() noexcept
add_popup_menuitem(*this, dynamics_type::counter, &new_model);
add_popup_menuitem(*this, dynamics_type::queue, &new_model);
add_popup_menuitem(*this, dynamics_type::dynamic_queue, &new_model);
add_popup_menuitem(*this, dynamics_type::priority_queue, &new_model);
add_popup_menuitem(
*this, dynamics_type::priority_queue, &new_model);
add_popup_menuitem(*this, dynamics_type::generator, &new_model);
add_popup_menuitem(*this, dynamics_type::constant, &new_model);
add_popup_menuitem(*this, dynamics_type::time_func, &new_model);
......@@ -2873,7 +2880,8 @@ editor::show_editor() noexcept
free_children(selected_nodes);
} else if (ImGui::GetIO().KeyCtrl && ImGui::IsKeyReleased('D')) {
imnodes::GetSelectedNodes(selected_nodes.begin());
log_w.log(7, "%d model(s)/group(s) to copy\n", num_selected_nodes);
log_w.log(
7, "%d model(s)/group(s) to copy\n", num_selected_nodes);
copy(selected_nodes);
} else if (ImGui::GetIO().KeyCtrl && ImGui::IsKeyReleased('G')) {
if (num_selected_nodes > 1) {
......@@ -2893,14 +2901,16 @@ editor::show_editor() noexcept
if (ImGui::GetIO().KeyCtrl && ImGui::IsKeyReleased('X')) {
std::fill_n(selected_links.begin(), selected_links.size(), -1);
imnodes::GetSelectedLinks(selected_links.begin());
std::sort(
selected_links.begin(), selected_links.end(), std::less<int>());
std::sort(selected_links.begin(),
selected_links.end(),
std::less<int>());
int i = 0;
int link_id_to_delete = selected_links[0];
int current_link_id = 0;
log_w.log(7, "%d connection(s) to delete\n", num_selected_links);
log_w.log(
7, "%d connection(s) to delete\n", num_selected_links);
auto selected_links_ptr = selected_links.Data;
auto selected_links_size = selected_links.Size;
......@@ -2918,9 +2928,12 @@ editor::show_editor() noexcept
&link_id_to_delete]<typename Dynamics>(Dynamics& dyn) {
if constexpr (is_detected_v<has_output_port_t,
Dynamics>) {
for (sz j = 0, e = std::size(dyn.y); j != e; ++j) {
for (const auto& elem : dyn.y[j].connections) {
if (current_link_id == link_id_to_delete) {
for (sz j = 0, e = std::size(dyn.y); j != e;
++j) {
for (const auto& elem :
dyn.y[j].connections) {
if (current_link_id ==
link_id_to_delete) {
this->sim.disconnect(
*mdl,
(int)j,
......@@ -2947,7 +2960,7 @@ editor::show_editor() noexcept
selected_links.resize(0);
}
ImGui::NextColumn();
ImGui::TableSetColumnIndex(1);
if (ImGui::CollapsingHeader("Selected Models",
ImGuiTreeNodeFlags_CollapsingHeader |
......@@ -2985,10 +2998,12 @@ editor::show_editor() noexcept
auto old_choose = static_cast<int>(out.index());
auto choose = old_choose;
ImGui::Text("%s",
dynamics_type_names[static_cast<int>(mdl->type)]);
ImGui::Text(
"%s", dynamics_type_names[static_cast<int>(mdl->type)]);
const char* items[] = { "none", "plot", "file", "file dt " };
const char* items[] = {
"none", "plot", "file", "file dt "
};
ImGui::Combo("type", &choose, items, IM_ARRAYSIZE(items));
if (choose == 1) {
......@@ -3006,13 +3021,14 @@ editor::show_editor() noexcept
auto& o = sim.observers.alloc(names[i].c_str(), tf);
sim.observe(*mdl, o);
} else {
plot =
plot_outs.try_to_get(std::get<plot_output_id>(out));
plot = plot_outs.try_to_get(
std::get<plot_output_id>(out));
irt_assert(plot);
}
ImGui::InputText(
"name##plot", plot->name.begin(), plot->name.capacity());
ImGui::InputText("name##plot",
plot->name.begin(),
plot->name.capacity());
ImGui::InputDouble(
"dt##plot", &plot->time_step, 0.001, 1.0, "%.8f");
} else if (choose == 2) {
......@@ -3030,13 +3046,14 @@ editor::show_editor() noexcept
auto& o = sim.observers.alloc(names[i].c_str(), tf);
sim.observe(*mdl, o);
} else {
file =
file_outs.try_to_get(std::get<file_output_id>(out));
file = file_outs.try_to_get(
std::get<file_output_id>(out));
irt_assert(file);
}
ImGui::InputText(
"name##file", file->name.begin(), file->name.capacity());
ImGui::InputText("name##file",
file->name.begin(),
file->name.capacity());
} else if (choose == 3) {
if (old_choose == 1 || old_choose == 2) {
sim.observers.free(mdl->obs_id);
......@@ -3069,7 +3086,9 @@ editor::show_editor() noexcept
observation_outputs_free(index);
}
sim.dispatch(*mdl, [this]<typename Dynamics>(Dynamics& dyn) {
sim.dispatch(*mdl,
[this]<typename Dynamics>(Dynamics& dyn) {
ImGui::Spacing();
show_dynamics_inputs(this->sim, dyn);
});
......@@ -3078,6 +3097,9 @@ editor::show_editor() noexcept
}
}
ImGui::EndTable();
}
ImGui::End();
return true;
......
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