Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
05ba8fbf
Commit
05ba8fbf
authored
Jan 22, 2015
by
Maxime Perrotin
Browse files
Add option to the API for generating simpler statecharts
parent
36d32dc2
Changes
3
Hide whitespace changes
Inline
Side-by-side
opengeode/AdaGenerator.py
View file @
05ba8fbf
...
...
@@ -103,7 +103,6 @@ def generate(*args, **kwargs):
@
generate
.
register
(
ogAST
.
Process
)
def
_process
(
process
,
simu
=
False
,
**
kwargs
):
''' Generate the code for a complete process (AST Top level) '''
print
"SIMU="
,
simu
process_name
=
process
.
processName
global
TYPES
TYPES
=
process
.
dataview
...
...
opengeode/Statechart.py
View file @
05ba8fbf
...
...
@@ -20,6 +20,7 @@
"""
import
logging
from
collections
import
defaultdict
import
re
from
PySide
import
QtGui
,
QtCore
...
...
@@ -407,8 +408,11 @@ def render_statechart(scene, graph=None, keep_pos=False):
Edge
(
edge
,
graph
)
def
create_dot_graph
(
root_ast
):
''' Return a dot.AGraph item, from an ogAST.Process or child entry '''
def
create_dot_graph
(
root_ast
,
basic
=
False
):
''' Return a dot.AGraph item, from an ogAST.Process or child entry
Set basic=True to generate a simple graph with at most one edge
between two states and no diamond nodes
'''
graph
=
dotgraph
.
AGraph
(
strict
=
False
,
directed
=
True
)
diamond
=
0
for
state
in
root_ast
.
mapping
.
viewkeys
():
...
...
@@ -432,6 +436,9 @@ def create_dot_graph(root_ast):
inputs
if
not
state
.
endswith
(
'START'
)
\
else
[
root_ast
.
transitions
[
inputs
]]
#[root_ast.content.start]
# Allow simplified graph, without diamonds and with at most one
# transition from a given state to another
target_states
=
defaultdict
(
set
)
for
trans
in
transitions
:
source
=
state
# transition label - there can be several inputs
...
...
@@ -469,7 +476,7 @@ def create_dot_graph(root_ast):
# Determine the list of terminators in this transition
next_states
=
find_terminators
(
trans
)
if
len
(
next_states
)
>
1
:
if
len
(
next_states
)
>
1
and
not
basic
:
# more than one terminator - add intermediate node
graph
.
add_node
(
str
(
diamond
),
shape
=
'diamond'
,
...
...
@@ -485,14 +492,18 @@ def create_dot_graph(root_ast):
target
=
state
else
:
target
=
term
.
inputString
.
lower
()
LOG
.
debug
(
'Edge from '
+
source
+
' to '
+
term
.
inputString
+
' label: '
+
label
)
for
each
in
root_ast
.
composite_states
:
# check with deeper nesting
if
each
.
statename
.
lower
()
==
target
.
lower
():
target
=
'cluster_'
+
target
break
graph
.
add_edge
(
source
,
target
,
label
=
label
)
if
basic
:
target_states
[
target
].
add
(
label
)
else
:
graph
.
add_edge
(
source
,
target
,
label
=
label
)
for
target
,
labels
in
target_states
.
viewitems
():
# Basic mode
graph
.
add_edge
(
source
,
target
,
label
=
',
\n
'
.
join
(
labels
))
#print graph.to_string()
return
graph
...
...
opengeode/opengeode.py
View file @
05ba8fbf
...
...
@@ -770,7 +770,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
self
.
undo_stack
.
endMacro
()
self
.
refresh
()
def
sdl_to_statechart
(
self
):
def
sdl_to_statechart
(
self
,
basic
=
False
):
''' Create a graphviz representation of the SDL model '''
pr_raw
=
Pr
.
parse_scene
(
self
)
pr_data
=
unicode
(
'
\n
'
.
join
(
pr_raw
))
...
...
@@ -782,7 +782,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
return
None
# Flatten nested states
Helper
.
flatten
(
process_ast
)
return
Statechart
.
create_dot_graph
(
process_ast
)
return
Statechart
.
create_dot_graph
(
process_ast
,
basic
)
def
export_branch_to_picture
(
self
,
symbol
,
filename
,
doc_format
):
''' Save a symbol and its followers to a file '''
...
...
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