Commit 6b4aba86 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Scene creation bugfix

parent 635d40cd
...@@ -284,6 +284,8 @@ class SDL_Scene(QtGui.QGraphicsScene, object): ...@@ -284,6 +284,8 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
process, procedure or composite state process, procedure or composite state
''' '''
super(SDL_Scene, self).__init__() super(SDL_Scene, self).__init__()
# Reference to the parent scene
self.parent_scene = None
self.mode = 'idle' self.mode = 'idle'
self.context = context self.context = context
self.allowed_symbols = ACTIONS[context] self.allowed_symbols = ACTIONS[context]
...@@ -401,6 +403,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object): ...@@ -401,6 +403,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
def render_everything(self, ast): def render_everything(self, ast):
''' Render a process and its children scenes, recursively ''' ''' Render a process and its children scenes, recursively '''
already_created = []
def recursive_render(content, dest_scene): def recursive_render(content, dest_scene):
''' Process the rendering in scenes and nested scenes ''' ''' Process the rendering in scenes and nested scenes '''
if isinstance(content, ogAST.Process): if isinstance(content, ogAST.Process):
...@@ -417,11 +420,16 @@ class SDL_Scene(QtGui.QGraphicsScene, object): ...@@ -417,11 +420,16 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
# Render nested scenes, recursively: # Render nested scenes, recursively:
for each in (item for item in dest_scene.visible_symb for each in (item for item in dest_scene.visible_symb
if item.nested_scene): if item.nested_scene):
if isinstance(each.nested_scene, ogAST.CompositeState) \
and (not each.nested_scene.statename
or each.nested_scene in already_created):
# Ignore nested state scenes that already exist
continue
subscene = \ subscene = \
self.create_subscene(each.__class__.__name__.lower()) self.create_subscene(each.__class__.__name__.lower())
#subscene = SDL_Scene(context=each.__class__.__name__.lower()) already_created.append(each.nested_scene)
#subscene.messages_window = self.messages_window
subscene.name = unicode(each) subscene.name = unicode(each)
LOG.debug('Created scene: {}'.format(subscene.name))
recursive_render(each.nested_scene.content, subscene) recursive_render(each.nested_scene.content, subscene)
each.nested_scene = subscene each.nested_scene = subscene
...@@ -429,8 +437,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object): ...@@ -429,8 +437,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
# (Needed for the symbol shape to have dashed lines) # (Needed for the symbol shape to have dashed lines)
for each in dest_scene.states: for each in dest_scene.states:
if unicode(each).lower() in \ if unicode(each).lower() in \
dest_scene.composite_states.viewkeys() and not \ dest_scene.composite_states.viewkeys():
each.nested_scene:
each.nested_scene = dest_scene.composite_states[ each.nested_scene = dest_scene.composite_states[
unicode(each).lower()] unicode(each).lower()]
...@@ -986,6 +993,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object): ...@@ -986,6 +993,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
''' Create a new SDL scene, e.g. for nested symbols ''' ''' Create a new SDL scene, e.g. for nested symbols '''
subscene = SDL_Scene(context=context) subscene = SDL_Scene(context=context)
subscene.messages_window = self.messages_window subscene.messages_window = self.messages_window
subscene.parent_scene = self
return subscene return subscene
......
/* CIF PROCESS (288, 143), (150, 75) */ /* CIF PROCESS (288, 143), (150, 75) */
PROCESS trafficlight; PROCESS trafficlight;
STATE Maintenance; STATE Maintenance;
SUBSTRUCTURE SUBSTRUCTURE
STATE YellowOff; STATE YellowOff;
SUBSTRUCTURE SUBSTRUCTURE
/* CIF PROCEDURE (239, 367), (73, 35) */ /* CIF PROCEDURE (239, 367), (73, 35) */
PROCEDURE entry; PROCEDURE entry;
/* CIF START (180, 35), (70, 35) */ /* CIF START (180, 35), (70, 35) */
...@@ -23,8 +23,8 @@ SUBSTRUCTURE ...@@ -23,8 +23,8 @@ SUBSTRUCTURE
STATE idle; STATE idle;
ENDSTATE; ENDSTATE;
ENDSUBSTRUCTURE; ENDSUBSTRUCTURE;
STATE YellowOn; STATE YellowOn;
SUBSTRUCTURE SUBSTRUCTURE
/* CIF PROCEDURE (291, 312), (73, 35) */ /* CIF PROCEDURE (291, 312), (73, 35) */
PROCEDURE entry; PROCEDURE entry;
/* CIF START (292, 124), (70, 35) */ /* CIF START (292, 124), (70, 35) */
...@@ -65,13 +65,13 @@ SUBSTRUCTURE ...@@ -65,13 +65,13 @@ SUBSTRUCTURE
NEXTSTATE YellowOff; NEXTSTATE YellowOff;
ENDSTATE; ENDSTATE;
ENDSUBSTRUCTURE; ENDSUBSTRUCTURE;
STATE on; STATE on;
SUBSTRUCTURE SUBSTRUCTURE
STATE PedWaiting; STATE PedWaiting;
SUBSTRUCTURE SUBSTRUCTURE
out (counter_expired); out (counter_expired);
STATE waitOn; STATE waitOn;
SUBSTRUCTURE SUBSTRUCTURE
/* CIF PROCEDURE (548, 222), (73, 35) */ /* CIF PROCEDURE (548, 222), (73, 35) */
PROCEDURE entry; PROCEDURE entry;
/* CIF START (185, 47), (70, 35) */ /* CIF START (185, 47), (70, 35) */
...@@ -81,7 +81,7 @@ SUBSTRUCTURE ...@@ -81,7 +81,7 @@ SUBSTRUCTURE
/* CIF RETURN (202, 147), (35, 35) */ /* CIF RETURN (202, 147), (35, 35) */
RETURN ; RETURN ;
ENDPROCEDURE; ENDPROCEDURE;
/* CIF PROCEDURE (560, 288), (70, 35) */ /* CIF PROCEDURE (560, 289), (70, 35) */
PROCEDURE exit; PROCEDURE exit;
/* CIF START (280, 159), (70, 35) */ /* CIF START (280, 159), (70, 35) */
START; START;
......
Supports Markdown
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