Commit b511a5a8 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Merge branch 'master' of https://github.com/maxime-esa/opengeode

parents 9159383c 68ee9196
......@@ -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
......@@ -149,6 +148,28 @@ def _process(process, simu=False, **kwargs):
res.append('END {}.GUI_{};\n'.format(sp_name, pi_or_ri))
return '\n'.join(res)
# bash script to simulate the system (TEMPORARY)
simu_script = '''#!/bin/bash -e
opengeode {pr}.pr --shared
asn1.exe -Ada dataview-uniq.asn -typePrefix asn1Scc -equal
asn1.exe -c dataview-uniq.asn -typePrefix asn1Scc -equal
gnatmake -gnat2012 -c *.adb
gnatbind -n -Llib{pr} {pr}
gnatmake -c -gnat2012 b~{pr}.adb
gcc -shared -fPIC -o lib{pr}.so b~{pr}.o {pr}.o taste_dataview.o adaasn1rtl.o -lgnat
rm -rf simu
mkdir -p simu
asn2aadlPlus dataview-uniq.asn simu/DataView.aadl
cp lib{pr}.so dataview-uniq.asn *.pr simu
mv *.aadl simu
cd simu
aadl2glueC DataView.aadl {pr}_interface.aadl
asn2dataModel -toPython dataview-uniq.asn
make -f Makefile.python
echo "errCodes=$(taste-asn1-errCodes ./dataview-uniq.h)" >>datamodel.py
LD_LIBRARY_PATH=. taste-gui -l
'''.format(pr=process_name)
LOG.info('Generating Ada code for process ' + str(process_name))
......@@ -575,6 +596,10 @@ package {process_name} is'''.format(process_name=process_name,
with open(u'{}_interface.aadl'.format(process_name), 'w') as aadl:
aadl.write(u'\n'.join(minicv).encode('latin1'))
if not simu:
with open('{}_simu.sh'.format(process_name), 'w') as bash_script:
bash_script.write(simu_script)
def write_statement(param, newline):
''' Generate the code for the special "write" operator '''
......
......@@ -20,9 +20,9 @@ import logging
from PySide.QtCore import Qt, QPointF, QLineF, Slot
from PySide.QtGui import QGraphicsPathItem, QPainterPath, QGraphicsItem, QPen,\
QPainter, QFont, QGraphicsTextItem, QColor, \
QFontMetrics
from PySide.QtGui import(QGraphicsPathItem, QPainterPath, QGraphicsItem, QPen,
QPainter, QFont, QGraphicsTextItem, QColor,
QFontMetrics, QTextBlockFormat, QTextCursor)
import ogParser
from TextInteraction import EditableText
......@@ -521,17 +521,28 @@ class Edge(Connection):
try:
# Add the transition label, if any (none for the START edge)
font = QFont('arial', pointSize=8)
width = QFontMetrics(font).width(
self.edge.get('label', 0))
metrics = QFontMetrics(font)
label = self.edge.get('label', '')
lines = label.split('\n')
width = metrics.width(max(lines)) # longest line
height = metrics.height() * len(lines)
# lp is the position of the center of the text
pos = self.mapFromScene(*self.edge['lp'])
#path.addText(pos.x() - width/2, pos.y(),
# font, self.edge['label'])
if not self.text_label:
self.text_label = QGraphicsTextItem(
self.edge.get('label', ''), parent=self)
self.text_label.setX(pos.x() - width / 2)
self.text_label.setY(pos.y())
self.text_label.setY(pos.y() - height / 2)
self.text_label.setFont(font)
# Make horizontal center alignment, as dot does
self.text_label.setTextWidth(self.text_label.boundingRect().width())
fmt = QTextBlockFormat()
fmt.setAlignment(Qt.AlignHCenter)
cursor = self.text_label.textCursor()
cursor.select(QTextCursor.Document)
cursor.mergeBlockFormat(fmt)
cursor.clearSelection()
self.text_label.setTextCursor(cursor)
self.text_label.show()
except KeyError:
# no label
......
......@@ -20,6 +20,7 @@
"""
import logging
from collections import defaultdict
import re
from PySide import QtGui, QtCore
......@@ -202,6 +203,7 @@ def preprocess_edges(my_graph, nodes, bounding_rect, dpi):
pass
else:
# translate the label position from dot-coordinates to Qt
# Note: lp is the position of the CENTER of the label
new_edge['lp'][0] *= RENDER_DPI['X'] / dpi
new_edge['lp'][1] = (
bb_height - new_edge['lp'][1]) * (RENDER_DPI['Y'] / dpi)
......@@ -371,9 +373,10 @@ 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
graph.layout(prog='neato', args='-Nfontsize=12, -Gsplines=true -Gsep=1 '
'-Gstart=random10 '
'-Nstyle=rounded -Nshape=record -Elen=1.5 {kp}'
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 ''))
# bb is not visible directly - extract it from the low level api:
bounding_rect = [float(val) for val in
......@@ -387,7 +390,8 @@ def render_statechart(scene, graph=None, keep_pos=False):
#fontname = graph.graph_attr.get('fontname')
#fontsize = graph.graph_attr.get('fontsize')
#print 'AFTER PROCESSING: ', 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 = []
......@@ -407,8 +411,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 +439,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 +479,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,15 +495,20 @@ 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)
#print graph.to_string()
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))
# with open('statechart.dot', 'w') as output:
# output.write(graph.to_string())
return graph
......
......@@ -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 '''
......
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