Commit 028040b1 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Generate first level of system hierarchy

parent be4d1007
......@@ -36,29 +36,64 @@ class Indent(deque):
super(Indent, self).append(' ' * Indent.indent + string)
def parse_scene(scene):
''' Return the PR string for a complete scene) '''
def parse_scene(scene, full_model=False):
''' Return the PR string for a complete scene
Optionally, also generate the SYSTEM structure, with channels, etc. '''
pr_data = deque()
for each in scene.processes:
pr_data.extend(generate(each))
for each in chain(scene.texts, scene.procs, scene.start):
pr_data.extend(generate(each))
for each in scene.floating_labels:
pr_data.extend(generate(each))
composite = set(scene.composite_states.keys())
for each in scene.states:
if each.is_composite():
statename = unicode(each).split()[0].lower() # Ignore via clause
try:
composite.remove(statename)
sub_state = generate(each, composite=True, nextstate=False)
if sub_state:
sub_state.reverse()
pr_data.extendleft(sub_state)
except KeyError:
pass
pr_data.extend(generate(each, nextstate=False))
if full_model:
# Generate a complete SDL system - to have everything in a single file
# (1) get system name
# (2) get all signal names from declaration in text boxes
# (3) get signal directions from the connection of the process to env
# (4) generate all the text
processes = list(scene.processes)
system_name = unicode(processes[0]) if processes else u'OpenGEODE'
signals, routes = [], []
pr_txt = []
for each in scene.texts:
# Parse text areas to retrieve signal names
pr = generate(each)
txt = '\n'.join(pr)
pr_txt.append(txt)
ast, _, _, _, _ = each.parser.parseSingleElement('text_area', txt)
signals.extend(['SIGNAL {}{};'
.format(sig['name'], ('(' + sig['type'] + ')')
if sig['type'] else '') for sig in ast.signals])
#routes = scene.CONTEXT.signalroutes
pr_data.append('SYSTEM {};'.format(system_name))
pr_data.extend(pr_txt)
pr_data.extend(signals)
#pr_data.extend(routes)
pr_data.append('BLOCK {};'.format(system_name))
#pr_data.extend(route)
for each in processes:
pr_data.extend(generate(each))
pr_data.append('ENDBLOCK;')
pr_data.append('ENDSYSTEM;')
print '\n'.join(pr_data)
else:
for each in scene.processes:
pr_data.extend(generate(each))
for each in chain(scene.texts, scene.procs, scene.start):
pr_data.extend(generate(each))
for each in scene.floating_labels:
pr_data.extend(generate(each))
composite = set(scene.composite_states.keys())
for each in scene.states:
if each.is_composite():
# Ignore via clause:
statename = unicode(each).split()[0].lower()
try:
composite.remove(statename)
sub_state = generate(each, composite=True, nextstate=False)
if sub_state:
sub_state.reverse()
pr_data.extendleft(sub_state)
except KeyError:
pass
pr_data.extend(generate(each, nextstate=False))
return list(pr_data)
......
......@@ -887,6 +887,8 @@ class Block(object):
self.blocks = []
# list of class Process
self.processes = []
# list of ogAST.Procedure
self.procedures = []
class System(object):
......
......@@ -139,7 +139,7 @@ G_SYMBOLS = set()
# Lookup table used to configure the context-dependent toolbars
ACTIONS = {
'block': [Process, Comment],
'block': [Process, Comment, TextSymbol],
'process': [Start, State, Input, Connect, Task, Decision, DecisionAnswer,
Output, ProcedureCall, TextSymbol, Comment, Label,
Join, Procedure],
......@@ -1553,7 +1553,8 @@ class SDL_View(QtGui.QGraphicsView, object):
scene = self.parent_scene[0][0]
else:
scene = self.scene()
pr_raw = Pr.parse_scene(scene)
pr_raw = Pr.parse_scene(scene, full_model=True
if not self.readonly_pr else False)
pr_data = unicode('\n'.join(pr_raw))
if pr_data:
_, warnings, errors = ogParser.parse_pr(files=self.readonly_pr,
......
......@@ -812,8 +812,12 @@ class TextSymbol(HorizontalSymbol):
''' When text was entered, update list of variables/FPAR/Timers '''
# Get AST for the symbol
ast, _, _, _, _ = self.parser.parseSingleElement('text_area', pr_text)
CONTEXT.variables.update(ast.variables)
CONTEXT.timers = list(set(CONTEXT.timers + ast.timers))
try:
CONTEXT.variables.update(ast.variables)
CONTEXT.timers = list(set(CONTEXT.timers + ast.timers))
except AttributeError:
# context ma not have variables/timers (eg if context = block)
pass
CONTEXT.procedures = list(set(CONTEXT.procedures + ast.procedures))
try:
CONTEXT.fpar.extend(ast.fpar)
......@@ -823,13 +827,10 @@ class TextSymbol(HorizontalSymbol):
@property
def completion_list(self):
''' Set auto-completion list '''
res = set(CONTEXT.global_timers + CONTEXT.timers)
try:
res = res.union(AST.dataview.keys())
return set(AST.dataview.keys())
except AttributeError:
# No Dataview
pass
return res
return [] # No Dataview
def set_shape(self, width, height):
''' Define the polygon of the text symbol '''
......
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