Commit 2c905ff7 authored by Maxime Perrotin's avatar Maxime Perrotin

Introduce the state recovery function

parent 33d944b2
......@@ -18,7 +18,8 @@ import os
import ctypes
from functools import partial
from PySide.QtGui import QDockWidget, QPushButton, QGridLayout, QListWidget
from PySide.QtGui import (QDockWidget, QPushButton, QGridLayout, QListWidget,
QUndoStack)
from PySide.QtCore import QObject, Signal, Slot, Qt, QFile
from PySide.QtUiTools import QUiLoader
......@@ -31,6 +32,8 @@ try:
except ImportError:
print 'OpenGEODE module is not available'
import opengeode.undoCommands as undo
try:
import dataview_uniq_asn as ASN1
except ImportError:
......@@ -82,7 +85,10 @@ class sdlHandler(QObject):
# Handle the state of all timers ({'timerName': 'set'/'unset'})
self.timers = {}
# Keep a state graph to allow undo/redo and state exploration
self.state_graph = {}
self.set_of_states = {}
# Create a stack for handling undo/redo commands
self.undo_stack = QUndoStack(self)
@property
def dll(self):
......@@ -129,6 +135,7 @@ class sdlHandler(QObject):
self.get_sdl_state.restype = ctypes.c_char_p
# Initialization: set current state and internal variables
self.current_sdl_state = None
self.check_state()
self.on_event()
self.init_timers()
......@@ -157,7 +164,16 @@ class sdlHandler(QObject):
self.state_change.emit(state)
self.log_area.addItem('New state: {}'.format(state))
@Slot()
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()):
# get internal variables, translate them to swig, and print them
typename = sort.ReferencedTypeName.replace('-', '_')
setter_ptr = getattr(self.dll, "_set_{}".format(var))
value_as_gser = target_state[idx]
def on_event(self, tc_name=None, param=None):
''' Process signals indicating that a PI was called in the shared lib:
update global state, manage undo/redo, manage active buttons '''
......@@ -188,14 +204,12 @@ class sdlHandler(QObject):
as_pyside = vn.fromValueNotationToPySide(var, gser)
self.asn1_editor.updateVariable(as_pyside,
root=self.tree_items[var])
complete_state.append(gser)
# Check if the SDL state has changed
self.check_state()
complete_state.append(asn1_instance) # not gser
# 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.state_graph[self.current_hash] = complete_state
self.set_of_states[self.current_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 = []
......@@ -260,7 +274,7 @@ class sdlHandler(QObject):
self.on_event(tc_name=name, param=param.GSER() if param else None)
def receive_tm(self, tm_name):
''' Function called when a paramless TM is received '''
''' Callback function when a paramless TM is received '''
self.msc.emit('in', tm_name)
self.log_area.addItem('Received event "{}"'.format(tm_name))
......
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