Commit 86500b1d authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Handle state changes in the SdlHandler, not in B mappers

parent e5c10dad
......@@ -310,6 +310,7 @@ def gui():
sdl = sdlHandler(myWidget)
sdl.dll = dll
sdl.msc.connect(msc.addToMsc)
sdl.state_change.connect(msc.addCondition)
except IOError:
log.info('SDL viewer not available')
sdl = None
......@@ -332,16 +333,16 @@ def gui():
encoder_backend.editor = editor
TMHandler = type('TMHandler', (QObject,), {'got_tm': Signal()})
# Callback in the backend to create a condition box in the MSC
MSCHandler = type('TCHandler', (QObject,), {'msc_box': Signal(unicode)})
# MSCHandler = type('TCHandler', (QObject,), {'msc_box': Signal(unicode)})
encoder_backend.tm_callback = TMHandler()
encoder_backend.msc_callback = MSCHandler()
encoder_backend.msc_callback.msc_box.connect(msc.addCondition)
# encoder_backend.msc_callback = MSCHandler()
# encoder_backend.msc_callback.msc_box.connect(msc.addCondition)
encoder_backend.tm_callback.got_tm.connect(editor.receivedTM)
# Callback in the backend to update the state of the SDL diagram
SDLHandler = type('SDLHandler', (QObject,), {'change_state':
Signal(unicode)})
encoder_backend.sdl_callback = SDLHandler()
encoder_backend.sdl_callback.change_state.connect(sdl.change_state)
# SDLHandler = type('SDLHandler', (QObject,), {'change_state':
# Signal(unicode)})
# encoder_backend.sdl_callback = SDLHandler()
# encoder_backend.sdl_callback.change_state.connect(sdl.change_state)
encoder_backend.log = log
encoder_backend.statusbar = statusbar
......
......@@ -44,6 +44,8 @@ class sdlHandler(QObject):
'''
# signal sent whenever a paramless TM or TC event happens
msc = Signal(unicode, unicode)
# Signal sent when the state of the SDL model changes
state_change = Signal(unicode)
def __init__(self, parent):
''' Startup: check if there are some SDL files in
the directory and try to parse them and build the widget '''
......@@ -75,6 +77,7 @@ class sdlHandler(QObject):
self.asn1_editor = None
self.tree_items = {}
self.dock_simu = self.start_simu()
self.current_sdl_state = None
@property
def dll(self):
......@@ -115,6 +118,12 @@ class sdlHandler(QObject):
# In the simulation panel, set the buttons to send paramless TC/timers
self.set_paramless_tc()
self.set_paramless_tm()
self.get_sdl_state = getattr(value,
'{}_state'.format(self.proc.processName))
self.get_sdl_state.restype = ctypes.c_char_p
# Initialization: set current state and internal variables
self.current_sdl_state = None
self.on_event()
@Slot()
def startStop(self):
......@@ -129,12 +138,16 @@ class sdlHandler(QObject):
self.dock_state.hide()
self.dock_simu.hide()
@Slot(unicode)
def change_state(self, new_state):
def check_state(self):
''' Highlight the current state on the statechart diagram '''
self.sdl_scene.clear_highlight()
for each in self.sdl_scene.find_text(u'\\b{}\\b'.format(new_state)):
self.sdl_scene.highlight(each)
state = self.get_sdl_state()
if state != self.current_sdl_state:
self.current_sdl_state = state
self.sdl_scene.clear_highlight()
for each in self.sdl_scene.find_text(u'\\b{}\\b'.format(state)):
self.sdl_scene.highlight(each)
# Propagate event for other updates (e.g. MSC)
self.state_change.emit(state)
@Slot()
def on_event(self):
......@@ -167,7 +180,10 @@ class sdlHandler(QObject):
#print "GSER= '{}'".format(gser)
as_pyside = vn.fromValueNotationToPySide(var, gser)
#print "PYSIDE:", as_pyside
self.asn1_editor.updateVariable(as_pyside, root=self.tree_items[var])
self.asn1_editor.updateVariable(as_pyside,
root=self.tree_items[var])
# Check if the SDL state has changed
self.check_state()
def start_simu(self):
'''
......@@ -178,11 +194,11 @@ class sdlHandler(QObject):
loader = QUiLoader()
widgets = loader.load(ui, parent=self.parent)
dock = QDockWidget('Simulation bay', self.parent)
dock.setFloating(True)
dock.setFloating(False)
dock.resize(400, 400)
dock.setObjectName('Simulation')
self.parent.addDockWidget(Qt.RightDockWidgetArea, dock)
dock.setAllowedAreas(Qt.NoDockWidgetArea)
#dock.setAllowedAreas(Qt.NoDockWidgetArea)
dock.setWidget(widgets)
dock.hide()
return dock
......@@ -191,6 +207,7 @@ class sdlHandler(QObject):
''' Send a parameterless TC '''
self.msc.emit('out', name)
tc_func_ptr()
self.on_event()
def receive_tm(self, tm_name):
''' Function called when a paramless TM is received '''
......
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