Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gauthier Quesnel
irritator
Commits
7788e556
Commit
7788e556
authored
Jul 02, 2020
by
Gauthier Quesnel
Browse files
implot: add new plot library
parent
16d22725
Pipeline
#15048
passed with stage
in 1 minute and 7 seconds
Changes
4
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
app/gui/CMakeLists.txt
View file @
7788e556
...
...
@@ -2,8 +2,8 @@ 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
window-logger
.cpp
node-editor.hpp node-editor.cpp
dialog-file.cpp gui.hpp imnodes.cpp imnodes.hpp
implot.h implot
.cpp
window-logger.cpp
node-editor.hpp node-editor.cpp
${
PROJECT_SOURCE_DIR
}
/../../external/imgui/imgui.cpp
${
PROJECT_SOURCE_DIR
}
/../../external/imgui/imgui.h
${
PROJECT_SOURCE_DIR
}
/../../external/imgui/imgui_demo.cpp
...
...
app/gui/implot.cpp
0 → 100644
View file @
7788e556
This diff is collapsed.
Click to expand it.
app/gui/implot.h
0 → 100644
View file @
7788e556
This diff is collapsed.
Click to expand it.
app/gui/node-editor.cpp
View file @
7788e556
...
...
@@ -10,6 +10,7 @@
#include "node-editor.hpp"
#include "gui.hpp"
#include "imnodes.hpp"
#include "implot.h"
#include <fstream>
#include <string>
...
...
@@ -38,8 +39,7 @@ static auto automatic_layout_y_distance = 350.f;
static
auto
grid_layout_x_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
);
}
...
...
@@ -659,48 +659,49 @@ struct copier
auto
ret
=
sim
.
dispatch
(
mdl
->
type
,
[
this
,
&
sim
,
mdl
,
&
mdl_id_dst
]
<
typename
DynamicsM
>
(
DynamicsM
&
dynamics_models
)
->
status
{
using
Dynamics
=
typename
DynamicsM
::
value_type
;
[
this
,
&
sim
,
mdl
,
&
mdl_id_dst
]
<
typename
DynamicsM
>
(
DynamicsM
&
dynamics_models
)
->
status
{
using
Dynamics
=
typename
DynamicsM
::
value_type
;
irt_return_if_fail
(
dynamics_models
.
can_alloc
(
1
),
status
::
dynamics_not_enough_memory
);
irt_return_if_fail
(
dynamics_models
.
can_alloc
(
1
),
status
::
dynamics_not_enough_memory
);
auto
*
dyn_ptr
=
dynamics_models
.
try_to_get
(
mdl
->
id
);
irt_return_if_fail
(
dyn_ptr
,
status
::
dynamics_unknown_id
);
auto
*
dyn_ptr
=
dynamics_models
.
try_to_get
(
mdl
->
id
);
irt_return_if_fail
(
dyn_ptr
,
status
::
dynamics_unknown_id
);
auto
&
new_dyn
=
dynamics_models
.
alloc
(
*
dyn_ptr
);
auto
new_dyn_id
=
dynamics_models
.
get_id
(
new_dyn
);
auto
&
new_dyn
=
dynamics_models
.
alloc
(
*
dyn_ptr
);
auto
new_dyn_id
=
dynamics_models
.
get_id
(
new_dyn
);
if
constexpr
(
is_detected_v
<
has_input_port_t
,
Dynamics
>
)
std
::
fill_n
(
new_dyn
.
x
,
std
::
size
(
new_dyn
.
x
),
static_cast
<
input_port_id
>
(
0
));
if
constexpr
(
is_detected_v
<
has_input_port_t
,
Dynamics
>
)
std
::
fill_n
(
new_dyn
.
x
,
std
::
size
(
new_dyn
.
x
),
static_cast
<
input_port_id
>
(
0
));
if
constexpr
(
is_detected_v
<
has_output_port_t
,
Dynamics
>
)
std
::
fill_n
(
new_dyn
.
y
,
std
::
size
(
new_dyn
.
y
),
static_cast
<
output_port_id
>
(
0
));
if
constexpr
(
is_detected_v
<
has_output_port_t
,
Dynamics
>
)
std
::
fill_n
(
new_dyn
.
y
,
std
::
size
(
new_dyn
.
y
),
static_cast
<
output_port_id
>
(
0
));
irt_return_if_bad
(
sim
.
alloc
(
new_dyn
,
new_dyn_id
,
mdl
->
name
.
c_str
()));
irt_return_if_bad
(
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
>
)
for
(
size_t
j
=
0
,
ej
=
std
::
size
(
new_dyn
.
x
);
j
!=
ej
;
++
j
)
this
->
c_input_ports
.
emplace_back
(
dyn_ptr
->
x
[
j
],
new_dyn
.
x
[
j
]);
if
constexpr
(
is_detected_v
<
has_input_port_t
,
Dynamics
>
)
for
(
size_t
j
=
0
,
ej
=
std
::
size
(
new_dyn
.
x
);
j
!=
ej
;
++
j
)
this
->
c_input_ports
.
emplace_back
(
dyn_ptr
->
x
[
j
],
new_dyn
.
x
[
j
]);
if
constexpr
(
is_detected_v
<
has_output_port_t
,
Dynamics
>
)
for
(
size_t
j
=
0
,
ej
=
std
::
size
(
new_dyn
.
y
);
j
!=
ej
;
++
j
)
this
->
c_output_ports
.
emplace_back
(
dyn_ptr
->
y
[
j
],
new_dyn
.
y
[
j
]);
if
constexpr
(
is_detected_v
<
has_output_port_t
,
Dynamics
>
)
for
(
size_t
j
=
0
,
ej
=
std
::
size
(
new_dyn
.
y
);
j
!=
ej
;
++
j
)
this
->
c_output_ports
.
emplace_back
(
dyn_ptr
->
y
[
j
],
new_dyn
.
y
[
j
]);
return
status
::
success
;
});
return
status
::
success
;
});
irt_return_if_bad
(
ret
);
}
...
...
@@ -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.001
f
;
ys1
[
i
]
=
0.5
f
+
0.5
f
*
std
::
sin
(
50
*
xs1
[
i
]);
}
static
float
xs2
[
11
],
ys2
[
11
];
for
(
int
i
=
0
;
i
<
11
;
++
i
)
{
xs2
[
i
]
=
(
float
)
i
*
0.1
f
;
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.05
f
,
1.0
f
,
5.0
f
,
"%.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
node_editor_show
()
{
static
bool
show_log
=
true
;
static
bool
show_simulation
=
true
;
static
bool
show_demo
=
false
;
static
bool
show_plot
=
false
;
static
bool
show_settings
=
false
;
bool
ret
=
true
;
...
...
@@ -2647,7 +2688,7 @@ node_editor_show()
ImGui
::
MenuItem
(
ed
->
name
.
c_str
(),
nullptr
,
&
ed
->
show
);
ImGui
::
MenuItem
(
"Simulation"
,
nullptr
,
&
show_simulation
);
ImGui
::
MenuItem
(
"Plot"
,
nullptr
,
&
show_plot
);
ImGui
::
MenuItem
(
"Settings"
,
nullptr
,
&
show_settings
);
ImGui
::
MenuItem
(
"Log"
,
nullptr
,
&
show_log
);
...
...
@@ -2680,6 +2721,9 @@ node_editor_show()
if
(
show_simulation
)
show_simulation_box
(
&
show_simulation
);
if
(
show_plot
)
show_plot_box
(
&
show_plot
);
if
(
show_demo
)
ImGui
::
ShowDemoWindow
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment