Commit 9faa0058 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Minor bugfix in Parsing/Rendering composite states

parent 47e75c78
......@@ -101,18 +101,19 @@ def _automaton(ast, scene):
top_level_symbols.append(render(label, scene, ast.states))
# Render floating states
nested_states = {}
nested_states = []
for state in ast.states:
# Create only floating states
try:
new_state = render(state, scene=scene, states=ast.states,
terminators=ast.parent.terminators)
if new_state.nested_scene:
if str(new_state).lower() in nested_states.viewkeys():
if str(new_state).lower() in nested_states: #.viewkeys():
new_state.nested_scene = None
else:
nested_states[str(new_state).lower()] = \
new_state.nested_scene
nested_states.append(str(new_state).lower())
#nested_states[str(new_state).lower()] = \
# new_state.nested_scene
except TypeError:
# Discard terminators (see _state function for explanation)
pass
......@@ -171,8 +172,7 @@ def _start(ast, scene, states, parent=None):
start_symbol = sdlSymbols.Start(ast)
scene.addItem(start_symbol)
if ast.transition:
render(ast.transition,
scene=scene, parent=start_symbol, states=states)
render(ast.transition, scene=scene, parent=start_symbol, states=states)
return start_symbol
......@@ -195,8 +195,7 @@ def _procedure_start(ast, scene, states, parent=None):
start_symbol = sdlSymbols.ProcedureStart(ast)
scene.addItem(start_symbol)
if ast.transition:
render(ast.transition,
scene=scene, parent=start_symbol, states=states)
render(ast.transition, scene=scene, parent=start_symbol, states=states)
return start_symbol
......@@ -209,24 +208,19 @@ def _floating_label(ast, scene, states, parent=None):
scene.addItem(lab)
lab.setPos(ast.pos_x, ast.pos_y)
if ast.transition:
render(ast.transition,
scene=scene,
parent=lab,
states=states)
render(ast.transition, scene=scene, parent=lab, states=states)
return lab
@render.register(ogAST.Transition)
def _transition(ast, scene, parent, states):
''' Add a transition to a scene '''
for action_symbol in ast.actions:
for each in ast.actions:
# pylint: disable=E1111
parent = render(action_symbol,
scene=scene, parent=parent, states=states)
parent = render(each, scene=scene, parent=parent, states=states)
if ast.terminator:
render(ast.terminator,
scene=scene, parent=parent, states=states)
render(ast.terminator, scene=scene, parent=parent, states=states)
@render.register(ogAST.Comment)
......@@ -296,8 +290,7 @@ def _terminator(ast, scene, parent, states):
''' Create a TERMINATOR symbol '''
if ast.label:
# pylint: disable=E1111
parent = render(ast.label,
scene=scene, parent=parent, states=states)
parent = render(ast.label,scene=scene, parent=parent, states=states)
if ast.kind == 'next_state':
LOG.debug('ADDING NEXT_STATE ' + ast.inputString)
# Create a new state symbol
......@@ -309,9 +302,11 @@ def _terminator(ast, scene, parent, states):
state_ast.pos_x == ast.pos_x and
state_ast.pos_y == ast.pos_y):
LOG.debug('MERGING TERMINATOR "' + ast.inputString + '"')
for input_ast in state_ast.inputs:
render(input_ast,
scene=scene, parent=symbol, states=states)
symbol.nested_scene = state_ast.composite or \
ogAST.CompositeState()
for each in chain(state_ast.inputs, state_ast.connects):
render(each, scene=scene, parent=symbol, states=states)
break
elif ast.kind == 'join':
symbol = sdlSymbols.Join(parent, ast)
elif ast.kind in ('return', 'stop'):
......
......@@ -375,7 +375,7 @@ class EditableText(QGraphicsTextItem, object):
text_cursor.clearSelection()
self.setTextCursor(text_cursor)
# If something has changed, check syntax and create undo command
if(self.oldSize != self.parentItem().boundingRect() or
if(self.oldSize != self.parentItem().boundingRect() or
self.oldText != str(self)):
# Call syntax checker from item containing the text (if any)
self.parentItem().check_syntax()
......
......@@ -770,8 +770,12 @@ class CompositeState(Process):
self.exit_procedure = None
# Body can contain text areas, procedures, composite states,
# one nameless START, named START (one per entrypoint), states,
# and floating labels.
# XXX check what to do with local DCL and timers
# amd floating labels
def __repr__(self):
''' Debug output for composite state '''
return 'COMPOSITE STATE {exp} ({l},{c})'.format(exp=self.statename,
l=self.line, c=self.charPositionInLine)
class Block(object):
......
......@@ -53,7 +53,7 @@ from PySide.QtUiTools import QUiLoader
from PySide import QtSvg
from genericSymbols import(Symbol, Comment, EditableText, Cornergrabber,
Connection)
Connection, Completer)
from sdlSymbols import(Input, Output, Decision, DecisionAnswer, Task,
ProcedureCall, TextSymbol, State, Start, Join, Label, Procedure,
ProcedureStart, ProcedureStop, StateStart, Connect)
......@@ -287,6 +287,8 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
self.messages_window = None
self.click_coordinates = None
self.process_name = 'opengeode'
# Scene name is used to update the tab window name when scene changes
self.name = ''
# search_item/search_pattern are used for search/replace function
self.search_item = None
self.search_pattern = None
......@@ -300,7 +302,8 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
def visible_symb(self):
''' Return the visible items of a scene '''
return (it for it in self.items() if it.isVisible() and not
isinstance(it, (Cornergrabber, Connection, EditableText)))
isinstance(it, (Cornergrabber, Connection,
Completer, EditableText)))
@property
def floating_symb(self):
......@@ -377,26 +380,28 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
''' Render a process and its children scenes, recursively '''
self.process_name = process.processName or 'opengeode'
def recursive_render(content, dest_scene):
for item in Renderer.render(content, dest_scene):
G_SYMBOLS.add(item)
if item.nested_scene:
subscene = SDL_Scene(
context=item.__class__.__name__.lower())
subscene.messages_window = self.messages_window
recursive_render(item.nested_scene.content, subscene)
item.nested_scene = subscene
items_with_nested_scene = []
# Render top-level items and their children:
for each in Renderer.render(content, dest_scene):
G_SYMBOLS.add(each)
# Render nested scenes, recursively:
for each in (item for item in dest_scene.visible_symb
if item.nested_scene):
subscene = SDL_Scene(context=each.__class__.__name__.lower())
subscene.messages_window = self.messages_window
recursive_render(each.nested_scene.content, subscene)
each.nested_scene = subscene
# Make sure all composite states are initially up to date
# (Needed for the symbol shape to have dashed lines)
for each in dest_scene.states:
# Update the list of composite states at scene level
if each.is_composite():
dest_scene.composite_states[str(each).lower()] =\
each.nested_scene
for each in dest_scene.states:
# Make sure all composite states are initially up to date
# (Needed for the symbol shape)
if str(each).lower() in dest_scene.composite_states.viewkeys()\
and not each.nested_scene:
and not each.nested_scene:
each.nested_scene = dest_scene.composite_states[
str(each).lower()]
str(each).lower()]
recursive_render(process, self)
......@@ -1233,6 +1238,7 @@ class SDL_View(QtGui.QGraphicsView, object):
self.scene().scene_left.emit()
scene, horpos, verpos = self.parent_scene.pop()
self.setScene(scene)
self.wrapping_window.setWindowTitle(self.scene().name)
self.horizontalScrollBar().setSliderPosition(horpos)
self.verticalScrollBar().setSliderPosition(verpos)
self.set_toolbar()
......@@ -1242,13 +1248,16 @@ class SDL_View(QtGui.QGraphicsView, object):
self.horizontalScrollBar().setSliderPosition(horpos)
self.verticalScrollBar().setSliderPosition(verpos)
def go_down(self, scene):
def go_down(self, scene, name=''):
''' Enter a nested diagram (procedure, composite state) '''
horpos = self.horizontalScrollBar().value()
verpos = self.verticalScrollBar().value()
self.scene().name = self.wrapping_window.windowTitle()
self.parent_scene.append((self.scene(), horpos, verpos))
self.scene().clear_focus()
self.setScene(scene)
self.scene().name = name + '[*]'
self.wrapping_window.setWindowTitle(self.scene().name)
self.up_button.setEnabled(True)
self.set_toolbar()
self.scene().scene_left.emit()
......@@ -1263,12 +1272,12 @@ class SDL_View(QtGui.QGraphicsView, object):
try:
if item.allow_nesting:
item.double_click()
ctx = item.__class__.__name__.lower()
if not isinstance(item.nested_scene, SDL_Scene):
subscene = SDL_Scene(
context=item.__class__.__name__.lower())
subscene = SDL_Scene(context=ctx)
subscene.messages_window = self.messages_window
item.nested_scene = subscene
self.go_down(item.nested_scene)
self.go_down(item.nested_scene, name=ctx + ' ' + str(item))
else:
# Otherwise, double-click edits the item text
item.edit_text(self.mapToScene(evt.pos()))
......
......@@ -509,7 +509,7 @@ class Join(VerticalSymbol):
size = min(rect.width(), rect.height())
rect.setWidth(size)
rect.setHeight(size)
super(Join, self).resize_item(rect)
super(Join, self).resize_item(rect)
def set_shape(self, width, height):
''' Define the bouding rectangle of the JOIN symbol '''
......@@ -858,8 +858,8 @@ class State(VerticalSymbol):
if parent:
try:
# Map AST scene coordinates to get actual position
self.setPos(self.pos()
+ self.mapFromScene(ast.pos_x, ast.pos_y))
self.setPos(self.pos()
+ self.mapFromScene(ast.pos_x, ast.pos_y))
except TypeError:
self.update_position()
else:
......@@ -922,6 +922,8 @@ class State(VerticalSymbol):
if self.nested_scene and self.is_composite():
# Distinguish composite states with dash line
self.setPen(QPen(Qt.DashLine))
else:
self.setPen(QPen(Qt.SolidLine))
self.setPath(path)
super(State, self).set_shape(width, height)
......
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