Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Maintenance - Mise à jour mensuelle Lundi 6 Février entre 7h00 et 9h00
Open sidebar
Gauthier Quesnel
irritator
Commits
f27ce12a
Commit
f27ce12a
authored
Aug 27, 2020
by
Gauthier Quesnel
Browse files
gui: improve debug mode
parent
e5935662
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/gui/node-editor.cpp
View file @
f27ce12a
...
...
@@ -26,11 +26,14 @@ static int kernel_message_cache = 32768;
static
int
gui_node_cache
=
1024
;
static
ImVec4
gui_model_color
{
.27
f
,
.27
f
,
.54
f
,
1.
f
};
static
ImVec4
gui_model_transition_color
{
.27
f
,
.54
f
,
.54
f
,
1.
f
};
static
ImVec4
gui_cluster_color
{
.27
f
,
.54
f
,
.27
f
,
1.
f
};
static
ImU32
gui_hovered_model_color
;
static
ImU32
gui_hovered_cluster_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
int
automatic_layout_iteration_limit
=
200
;
...
...
@@ -39,7 +42,8 @@ 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
);
}
...
...
@@ -52,6 +56,11 @@ compute_color() noexcept
gui_selected_model_color
=
ImGui
::
ColorConvertFloat4ToU32
(
gui_model_color
*
1.5
f
);
gui_hovered_model_transition_color
=
ImGui
::
ColorConvertFloat4ToU32
(
gui_model_transition_color
*
1.25
f
);
gui_selected_model_transition_color
=
ImGui
::
ColorConvertFloat4ToU32
(
gui_model_transition_color
*
1.5
f
);
gui_hovered_cluster_color
=
ImGui
::
ColorConvertFloat4ToU32
(
gui_cluster_color
*
1.25
f
);
gui_selected_cluster_color
=
...
...
@@ -607,49 +616,48 @@ 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
);
}
...
...
@@ -984,6 +992,7 @@ editor::initialize(u32 id) noexcept
is_bad
(
clusters
.
init
(
sim
.
models
.
capacity
()))
||
is_bad
(
models_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
))))
return
status
::
gui_not_enough_memory
;
...
...
@@ -991,6 +1000,8 @@ editor::initialize(u32 id) noexcept
displacements
.
resize
(
sim
.
models
.
capacity
()
+
clusters
.
capacity
(),
ImVec2
{
0.
f
,
0.
f
});
std
::
fill_n
(
models_make_transition
.
data
(),
sim
.
models
.
capacity
(),
false
);
format
(
name
,
"Editor {}"
,
id
);
initialized
=
true
;
...
...
@@ -2261,13 +2272,33 @@ editor::show_top() noexcept
if
(
top
.
children
[
i
].
first
.
index
()
==
0
)
{
const
auto
id
=
std
::
get
<
model_id
>
(
top
.
children
[
i
].
first
);
if
(
auto
*
mdl
=
sim
.
models
.
try_to_get
(
id
);
mdl
)
{
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
);
if
(
match
(
st
,
simulation_status
::
success
,
simulation_status
::
running_once
,
simulation_status
::
running_once_need_join
,
simulation_status
::
running_step
)
&&
models_make_transition
[
get_index
(
id
)])
{
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
::
BeginNodeTitleBar
();
...
...
app/gui/node-editor.hpp
View file @
f27ce12a
...
...
@@ -252,11 +252,15 @@ struct editor
bool
show
=
true
;
simulation
sim
;
double
simulation_begin
=
0.0
;
double
simulation_end
=
10.0
;
double
simulation_current
=
10.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
;
simulation_status
st
=
simulation_status
::
success
;
...
...
@@ -272,6 +276,8 @@ struct editor
array
<
cluster_id
>
clusters_mapper
;
/* group per cluster_id */
array
<
cluster_id
>
models_mapper
;
/* group per model_id */
array
<
bool
>
models_make_transition
;
ImVector
<
ImVec2
>
positions
;
ImVector
<
ImVec2
>
displacements
;
...
...
app/gui/simulation-editor.cpp
View file @
f27ce12a
...
...
@@ -7,6 +7,8 @@
#define WINDOWS_LEAN_AND_MEAN
#endif
#include
<cstdlib>
#include
"gui.hpp"
#include
"imnodes.hpp"
#include
"implot.h"
...
...
@@ -226,7 +228,10 @@ simulation_init(window_logger& log_w, editor& ed)
initialize_observation
(
log_w
,
ed
);
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
))
{
log_w
.
log
(
3
,
...
...
@@ -237,6 +242,7 @@ simulation_init(window_logger& log_w, editor& ed)
ed
.
simulation_next_time
=
ed
.
sim
.
sched
.
empty
()
?
time_domain
<
time
>::
infinity
:
ed
.
sim
.
sched
.
tn
();
ed
.
simulation_bag_id
=
0
;
ed
.
st
=
simulation_status
::
running_step
;
}
}
...
...
@@ -251,8 +257,9 @@ show_simulation_run_debug(window_logger& log_w, editor& ed)
simulation_init
(
log_w
,
ed
);
}
else
{
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
(
"
Bag size
%lu"
,
(
unsigned
long
)
ed
.
sim
.
sched
.
size
());
ImGui
::
Text
(
"
Model
%lu"
,
(
unsigned
long
)
ed
.
sim
.
sched
.
size
());
if
(
ImGui
::
Button
(
"re-init."
))
simulation_init
(
log_w
,
ed
);
...
...
@@ -260,15 +267,80 @@ show_simulation_run_debug(window_logger& log_w, editor& ed)
ImGui
::
SameLine
();
if
(
ImGui
::
Button
(
"Next bag"
))
{
auto
ret
=
ed
.
sim
.
run
(
ed
.
simulation_current
);
if
(
is_bad
(
ret
))
{
if
(
auto
ret
=
ed
.
sim
.
run
(
ed
.
simulation_current
);
is_bad
(
ret
))
{
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
;
}
}
}
...
...
lib/include/irritator/core.hpp
View file @
f27ce12a
...
...
@@ -5638,6 +5638,11 @@ public:
return
m_list
;
}
const
list
&
list_model_id
()
const
noexcept
{
return
m_list
;
}
time
tn
()
const
noexcept
{
return
m_heap
.
top
()
->
tn
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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