Commit 2e1ba712 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Export also the statechart as png

parent d099b34f
......@@ -19,6 +19,7 @@
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}
......@@ -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('', 'w') as output:
#with open('', 'w') as output:
# output.write(graph.to_string())
nodes = preprocess_nodes(graph, bounding_rect, dot_dpi)
node_symbols = []
......@@ -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)
super(HorizontalSymbol, self).insert_symbol(parent, pos_x, pos_y)
if pos_x is None or pos_y is None:
......@@ -2120,6 +2120,18 @@ def export(ast, options):'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'Saving statechart sc_{}.png'.format(process.processName))
sc_scene = SDL_Scene(context='statechart')
graph = diagram.sdl_to_statechart()
Statechart.render_statechart(sc_scene, graph,
except (IOError, TypeError) as err:
def cli(options):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment