Commit 7788e556 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

implot: add new plot library

parent 16d22725
Pipeline #15048 passed with stage
in 1 minute and 7 seconds
...@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR) ...@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(irritator-gui VERSION 0.1.0 LANGUAGES CXX) project(irritator-gui VERSION 0.1.0 LANGUAGES CXX)
set(gui_sources set(gui_sources
dialog-file.cpp gui.hpp imnodes.cpp imnodes.hpp window-logger.cpp dialog-file.cpp gui.hpp imnodes.cpp imnodes.hpp implot.h implot.cpp
node-editor.hpp node-editor.cpp window-logger.cpp node-editor.hpp node-editor.cpp
${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.cpp ${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.cpp
${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.h ${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.h
${PROJECT_SOURCE_DIR}/../../external/imgui/imgui_demo.cpp ${PROJECT_SOURCE_DIR}/../../external/imgui/imgui_demo.cpp
......
This diff is collapsed.
This diff is collapsed.
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "node-editor.hpp" #include "node-editor.hpp"
#include "gui.hpp" #include "gui.hpp"
#include "imnodes.hpp" #include "imnodes.hpp"
#include "implot.h"
#include <fstream> #include <fstream>
#include <string> #include <string>
...@@ -38,8 +39,7 @@ static auto automatic_layout_y_distance = 350.f; ...@@ -38,8 +39,7 @@ 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 static ImVec4 operator*(const ImVec4& lhs, const float rhs) noexcept
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);
} }
...@@ -659,48 +659,49 @@ struct copier ...@@ -659,48 +659,49 @@ struct copier
auto ret = sim.dispatch( auto ret = sim.dispatch(
mdl->type, mdl->type,
[this, &sim, mdl, &mdl_id_dst]<typename DynamicsM>( [ this, &sim, mdl, &
DynamicsM& dynamics_models) -> status { mdl_id_dst ]<typename DynamicsM>(DynamicsM & dynamics_models)
using Dynamics = typename DynamicsM::value_type; ->status {
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);
} }
...@@ -2618,12 +2619,52 @@ node_editor_initialize() ...@@ -2618,12 +2619,52 @@ node_editor_initialize()
} }
} }
void
show_plot_box(bool* show_plot)
{
// static editor_id current_editor_id = static_cast<editor_id>(0);
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_Always);
if (!ImGui::Begin("Plot", show_plot)) {
ImGui::End();
return;
}
if (ImGui::CollapsingHeader("Line Plots")) {
static float xs1[1001], ys1[1001];
for (int i = 0; i < 1001; ++i) {
xs1[i] = (float)i * 0.001f;
ys1[i] = 0.5f + 0.5f * std::sin(50 * xs1[i]);
}
static float xs2[11], ys2[11];
for (int i = 0; i < 11; ++i) {
xs2[i] = (float)i * 0.1f;
ys2[i] = xs2[i] * xs2[i];
}
static float weight = ImPlot::GetStyle().LineWeight;
ImGui::BulletText("Anti-aliasing can be enabled from the plot's "
"context menu (see Help).");
ImGui::DragFloat("Line Weight", &weight, 0.05f, 1.0f, 5.0f, "%.2f px");
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)")) {
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, weight);
ImPlot::PlotLine("0.5 + 0.5*sin(50*x)", xs1, ys1, 1001);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
ImPlot::PlotLine("x^2", xs2, ys2, 11);
ImPlot::PopStyleVar(2);
ImPlot::EndPlot();
}
}
ImGui::End();
}
bool bool
node_editor_show() node_editor_show()
{ {
static bool show_log = true; static bool show_log = true;
static bool show_simulation = true; static bool show_simulation = true;
static bool show_demo = false; static bool show_demo = false;
static bool show_plot = false;
static bool show_settings = false; static bool show_settings = false;
bool ret = true; bool ret = true;
...@@ -2647,7 +2688,7 @@ node_editor_show() ...@@ -2647,7 +2688,7 @@ node_editor_show()
ImGui::MenuItem(ed->name.c_str(), nullptr, &ed->show); ImGui::MenuItem(ed->name.c_str(), nullptr, &ed->show);
ImGui::MenuItem("Simulation", nullptr, &show_simulation); ImGui::MenuItem("Simulation", nullptr, &show_simulation);
ImGui::MenuItem("Plot", nullptr, &show_plot);
ImGui::MenuItem("Settings", nullptr, &show_settings); ImGui::MenuItem("Settings", nullptr, &show_settings);
ImGui::MenuItem("Log", nullptr, &show_log); ImGui::MenuItem("Log", nullptr, &show_log);
...@@ -2680,6 +2721,9 @@ node_editor_show() ...@@ -2680,6 +2721,9 @@ node_editor_show()
if (show_simulation) if (show_simulation)
show_simulation_box(&show_simulation); show_simulation_box(&show_simulation);
if (show_plot)
show_plot_box(&show_plot);
if (show_demo) if (show_demo)
ImGui::ShowDemoWindow(); ImGui::ShowDemoWindow();
......
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