Skip to content

Commit 7fa933d

Browse files
committed
Quick and dirty display critical from Julia
1 parent bf9d701 commit 7fa933d

6 files changed

Lines changed: 44 additions & 11 deletions

File tree

data/imgui.ini

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ Size=1100,749
102102
Collapsed=0
103103

104104
[Window][Critical Cycle]
105-
Pos=809,289
106-
Size=301,428
105+
Pos=809,386
106+
Size=16,35
107107
Collapsed=0
108108

109109
[Window][Choose the Petri file to save before creating new document##ChooseFileDlgKey]
@@ -208,6 +208,16 @@ Pos=750,271
208208
Size=224,71
209209
Collapsed=0
210210

211+
[Window][Critical Circuit]
212+
Pos=401,259
213+
Size=16,35
214+
Collapsed=0
215+
216+
[Window][Critical circuit analysis]
217+
Pos=261,154
218+
Size=424,325
219+
Collapsed=0
220+
211221
[Table][0x90C2C115,4]
212222
RefScale=13
213223
Column 0 Sort=0v
@@ -680,6 +690,14 @@ Column 0 Sort=0v
680690
RefScale=13
681691
Column 0 Sort=0v
682692

693+
[Table][0x9B24456E,4]
694+
RefScale=13
695+
Column 0 Sort=0v
696+
697+
[Table][0xBDA44527,4]
698+
RefScale=13
699+
Column 0 Sort=0v
700+
683701
[Docking][Data]
684702
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,19 Size=1100,749 Split=Y
685703
DockNode ID=0x00000005 Parent=0x08BD597D SizeRef=1100,867 Split=X

src/Editor/Editor.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,18 @@ void Editor::setSavePath(std::string const& filepath)
316316
}
317317

318318
//------------------------------------------------------------------------------
319-
void Editor::run(Net const& net_to_load)
319+
void Editor::run(Net const& net_to_load, bool show_critical_cycle)
320320
{
321321
this->net() = net_to_load;
322322

323+
if (show_critical_cycle)
324+
{
325+
m_states.do_find_critical_circuit = true;
326+
CriticalCycleResult const cc = findCriticalCycle(this->net());
327+
if (cc.success)
328+
m_marked_arcs = cc.arcs;
329+
}
330+
323331
// Start the infinite loop
324332
Application::run();
325333
}

src/Editor/Editor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Editor: public Application
7070
//! string if you do not want to load a Petri net file.
7171
//-------------------------------------------------------------------------
7272
void run(std::string const& petri_file);
73-
void run(Net const& net);
73+
void run(Net const& net, bool show_critical_cycle = false);
7474

7575
//-------------------------------------------------------------------------
7676
//! \brief Save a screenshot after the next rendered frame.

src/julia/Julia.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ bool petri_is_empty(int64_t const pn, bool* empty)
101101
// Equivalent to the main() but separated to allow to export function and create
102102
// shared library.
103103
// -----------------------------------------------------------------------------
104-
bool petri_editor(int64_t const pn, char const* screenshot_path)
104+
bool petri_editor(int64_t const pn, char const* screenshot_path,
105+
bool show_critical_cycle)
105106
{
106107
CHECK_VALID_PETRI_HANDLE(pn, false);
107108

@@ -112,7 +113,7 @@ bool petri_editor(int64_t const pn, char const* screenshot_path)
112113

113114
try
114115
{
115-
editor.run(*g_petri_nets[size_t(pn)]);
116+
editor.run(*g_petri_nets[size_t(pn)], show_critical_cycle);
116117
*g_petri_nets[size_t(pn)] = editor.net();
117118
}
118119
catch (std::string const& msg)

src/julia/Julia.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ extern "C" bool petri_is_empty(int64_t const pn, bool* empty);
9595
//! \param[in] pn: the handle of the petri net created by create_petri_net().
9696
//! \param[in] screenshot_path: optional PNG path saved after the first frame.
9797
//! Pass nullptr to skip.
98+
//! \param[in] show_critical_cycle: if true, highlight the critical cycle and
99+
//! open the analysis dialog on startup (as in ScicosLab show_cr_graph).
98100
//! \return false if the handle is invalid or the GUI cannot be started else
99101
//! return true.
100102
// ****************************************************************************
101-
extern "C" bool petri_editor(int64_t const pn, char const* screenshot_path);
103+
extern "C" bool petri_editor(int64_t const pn, char const* screenshot_path,
104+
bool show_critical_cycle);
102105

103106
// ****************************************************************************
104107
//! \brief Open the editor, save a PNG screenshot after the first frame, then

src/julia/TimedPetriNetEditor.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ julia> places(pn)
207207
Place(607.0, 266.0, 0)
208208
```
209209
"""
210-
function petri_editor!(pn::PetriNet; screenshot::Union{Nothing,String}=nothing)
210+
function petri_editor!(pn::PetriNet; screenshot::Union{Nothing,String}=nothing,
211+
critical_cycle::Bool=false)
211212
sc = screenshot === nothing ? C_NULL : screenshot
212-
ccall((:petri_editor, libtpne), Bool, (Clonglong, Cstring), pn.handle, sc) || throw_error()
213+
ccall((:petri_editor, libtpne), Bool, (Clonglong, Cstring, Bool),
214+
pn.handle, sc, critical_cycle) || throw_error()
213215
end
214216

215217
"""
@@ -241,9 +243,10 @@ Once presed ESCAPE key, the editor will quit and modifications applied on the du
241243
while the original net is not modified.
242244
Throw an exception if the Petri net handle is invalid.
243245
"""
244-
function petri_editor(pn::PetriNet)
246+
function petri_editor(pn::PetriNet; critical_cycle::Bool=false)
245247
pn1 = petri_net(pn)
246-
ccall((:petri_editor, libtpne), Bool, (Clonglong, Cstring), pn1.handle, C_NULL) || throw_error()
248+
ccall((:petri_editor, libtpne), Bool, (Clonglong, Cstring, Bool),
249+
pn1.handle, C_NULL, critical_cycle) || throw_error()
247250
return pn1
248251
end
249252

0 commit comments

Comments
 (0)