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

Progress with restoring state at runtime

parent 2e59ec9f
......@@ -19,7 +19,7 @@ import ctypes
from functools import partial
from PySide.QtGui import (QDockWidget, QPushButton, QGridLayout, QListWidget,
QUndoStack)
QUndoStack, QToolButton)
from PySide.QtCore import QObject, Signal, Slot, Qt, QFile
from PySide.QtUiTools import QUiLoader
......@@ -88,7 +88,12 @@ class sdlHandler(QObject):
self.set_of_states = {}
# Create a stack for handling undo/redo commands
self.undo_stack = QUndoStack(self)
# Associate the Undo, Redo, Reset buttons with an action
widget = self.dock_simu.widget()
undo_button = widget.findChild(QToolButton, 'undoButton')
redo_button = widget.findChild(QToolButton, 'redoButton')
reset_button = widget.findChild(QToolButton, 'resetButton')
reset_button.clicked.connect(self.reset_simulation)
@property
def dll(self):
......@@ -136,7 +141,7 @@ class sdlHandler(QObject):
# Initialization: set current state and internal variables
self.current_sdl_state = None
self.check_state()
self.on_event()
self.init_state = self.on_event()
self.init_timers()
@Slot()
......@@ -160,16 +165,26 @@ class sdlHandler(QObject):
self.state_change.emit(state)
self.log_area.addItem('New state: {}'.format(state))
def reset_simulation(self):
''' Jump to the first step of simulation '''
self.restore_global_state(self.init_state)
# TODO: clean log, clean MSC, rewind undo stack
def restore_global_state(self, statehash):
''' From a hashcode, restore a global state in the DLL (state +
all internal variables '''
target_state = self.set_of_states[statehash]
for idx, var, (sort, _) in enumerate(self.proc.variables.viewitems()):
for idx, (var, (sort, _)) in enumerate(self.proc.variables.viewitems()):
# get internal variables, translate them to swig, and print them
typename = sort.ReferencedTypeName.replace('-', '_')
setter_ptr = getattr(self.dll, "_set_{}".format(var))
value = target_state[idx]
print "Restoring {} = {}", var, value.GSER()
value_asn1 = target_state[idx]
value_ptr = ctypes.cast(value_asn1._ptr.__long__(),
ctypes.POINTER(ctypes.c_uint32))
setter_ptr(value_ptr)
state_value = target_state[idx+1]
setter_state = getattr(self.dll, "_set_state")
# todo string to cyptes, and call setter_state
self.on_event()
def on_event(self, tc_name=None, param=None):
''' Process signals indicating that a PI was called in the shared lib:
......@@ -197,6 +212,8 @@ class sdlHandler(QObject):
asn1_instance = getattr(ASN1, typename)()
setter = getattr(ASN1.DV, "SetDataFor_{}".format(typename))
setter(asn1_instance._ptr, swig_ptr)
#if not getattr(asn1_instance._ptr, '__long__', None):
# print dir(asn1_instance[0].__long__._ptr)
gser = asn1_instance.GSER()
as_pyside = vn.fromValueNotationToPySide(var, gser)
self.asn1_editor.updateVariable(as_pyside,
......@@ -205,8 +222,8 @@ class sdlHandler(QObject):
# Add the SDL state to the current state
complete_state.append(self.current_sdl_state)
# And save the current state in a graph
self.current_hash = hash(frozenset(complete_state))
self.set_of_states[self.current_hash] = complete_state
new_hash = hash(frozenset(complete_state))
self.set_of_states[new_hash] = complete_state
# Find the list of allowed TC based on the current state
inputs = self.proc.mapping[self.current_sdl_state.lower()]
allowed_tc = []
......@@ -226,6 +243,7 @@ class sdlHandler(QObject):
# Log all TC sent
self.log_area.addItem('Sent {}({})'.format(tc_name,
param or ''))
return new_hash
def start_simu(self):
......
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