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
2e1ba712
Commit
2e1ba712
authored
Feb 12, 2015
by
Maxime Perrotin
Browse files
Export also the statechart as png
parent
d099b34f
Changes
3
Hide whitespace changes
Inline
Side-by-side
opengeode/Statechart.py
View file @
2e1ba712
...
...
@@ -19,6 +19,7 @@
Contact: maxime.perrotin@esa.int
"""
import
os
import
logging
from
collections
import
defaultdict
import
re
...
...
@@ -352,8 +353,10 @@ def update(scene):
item
.
position
=
QtCore
.
QPointF
(
item
.
position
-
delta
)
def
render_statechart
(
scene
,
graph
=
None
,
keep_pos
=
False
):
''' Render a graphviz/dot statechart on the QGraphicsScene '''
def
render_statechart
(
scene
,
graph
=
None
,
keep_pos
=
False
,
dump_gfx
=
''
):
''' Render a graphviz/dot statechart on the QGraphicsScene
set a filename to "dump_gfx" parameter to create a PNG of the graph
'''
# Statechart symbols lookup table
lookup
=
{
'point'
:
Point
,
'record'
:
Record
,
'diamond'
:
Diamond
}
try
:
...
...
@@ -373,11 +376,18 @@ def render_statechart(scene, graph=None, keep_pos=False):
# Compute all the coordinates (self-modifying function)
# Force the fontsize of the nodes to be 12, as in OpenGEODE
# use -n2 below to keep user-specified node coordinates
if
dump_gfx
:
dump_name
=
'sc_'
+
os
.
path
.
basename
(
dump_gfx
)
dump_gfx
=
os
.
path
.
dirname
(
dump_gfx
)
or
'.'
+
os
.
sep
+
dump_name
if
dump_gfx
.
split
(
'.'
)[
-
1
].
lower
()
!=
'png'
:
dump_gfx
+=
'.png'
graph
.
layout
(
prog
=
'neato'
,
args
=
'-Nfontsize=12, -Efontsize=8 '
'-Gsplines=curved -Gsep=1 '
'-Gstart=random10 -Goverlap=false '
'-Nstyle=rounded -Nshape=record -Elen=1 {kp} -Tpng -ocoucou.png'
.
format
(
kp
=
'-n1'
if
keep_pos
else
''
))
'-Nstyle=rounded -Nshape=record -Elen=1 {kp} {dump}'
.
format
(
kp
=
'-n1'
if
keep_pos
else
''
,
dump
=
(
'-Tpng -o'
+
dump_gfx
)
if
dump_gfx
else
''
))
# bb is not visible directly - extract it from the low level api:
bounding_rect
=
[
float
(
val
)
for
val
in
dotgraph
.
graphviz
.
agget
(
graph
.
handle
,
'bb'
).
split
(
','
)]
...
...
@@ -390,8 +400,8 @@ def render_statechart(scene, graph=None, keep_pos=False):
#fontname = graph.graph_attr.get('fontname')
#fontsize = graph.graph_attr.get('fontsize')
with
open
(
'statechart.dot'
,
'w'
)
as
output
:
output
.
write
(
graph
.
to_string
())
#
with open('statechart.dot', 'w') as output:
#
output.write(graph.to_string())
nodes
=
preprocess_nodes
(
graph
,
bounding_rect
,
dot_dpi
)
node_symbols
=
[]
...
...
opengeode/genericSymbols.py
View file @
2e1ba712
...
...
@@ -947,7 +947,7 @@ class HorizontalSymbol(Symbol, object):
def
insert_symbol
(
self
,
parent
,
pos_x
,
pos_y
):
''' Insert the symbol in the scene - Align below the parent '''
if
not
parent
:
self
.
position
=
QPointF
(
pos_x
,
pos_y
)
self
.
position
=
QPointF
(
pos_x
or
0
,
pos_y
or
0
)
return
super
(
HorizontalSymbol
,
self
).
insert_symbol
(
parent
,
pos_x
,
pos_y
)
if
pos_x
is
None
or
pos_y
is
None
:
...
...
opengeode/opengeode.py
View file @
2e1ba712
...
...
@@ -2120,6 +2120,18 @@ def export(ast, options):
LOG
.
info
(
'Saving {ext} file: {name}.{ext}'
.
format
(
ext
=
doc_fmt
,
name
=
name
))
diagram
.
export_img
(
name
,
doc_format
=
doc_fmt
,
split
=
options
.
split
)
if
diagram
.
context
==
'block'
and
graphviz
:
# Also save the statechart viewa of the current scene
LOG
.
info
(
'Saving statechart sc_{}.png'
.
format
(
process
.
processName
))
sc_scene
=
SDL_Scene
(
context
=
'statechart'
)
graph
=
diagram
.
sdl_to_statechart
()
try
:
Statechart
.
render_statechart
(
sc_scene
,
graph
,
dump_gfx
=
process
.
processName
)
sc_scene
.
refresh
()
except
(
IOError
,
TypeError
)
as
err
:
LOG
.
debug
(
str
(
err
))
def
cli
(
options
):
...
...
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