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

Complete undo/redo on sdl and msc levels

parent 0857b6c0
......@@ -43,33 +43,22 @@ except ImportError:
class SendTC(QUndoCommand):
''' Undo command to send a message to the running system '''
def __init__(self, handler, tc_ptr, param):
''' Init: save the current state and compute parameter pointer '''
def __init__(self, handler, old_state):
''' Init: save the current and old states '''
super(SendTC, self).__init__()
self.handler = handler
self.recover_hash = handler.current_hash
self.tc_ptr = tc_ptr
self.param = param
if param:
# Cast the SWIG type (ASN.1 Native format) to a ctypes pointer
try:
swig_ptr = int(param._ptr)
except TypeError:
# when swig uses a proxy class, pointer is in _ptr.this
swig_ptr = int(param._ptr.this)
self.param_ptr = ctypes.cast(swig_ptr,
ctypes.POINTER(ctypes.c_uint32))
self.new_state = handler.current_hash
self.old_state = old_state
def undo(self):
''' Undo a send TC: Restore the system state as it was before the TC
was sent - setting back all global variables and internal state '''
self.handler.restore_global_state(self.recover_hash)
self.handler.restore_global_state(self.old_state)
def redo(self):
''' Execute the send TC action: just call the function in the DLL '''
if self.param:
self.tc_ptr(self.param_ptr)
else:
self.tc_ptr()
''' Set the internal variables to the new state '''
if self.new_state != self.handler.current_hash:
self.handler.restore_global_state(self.new_state)
class sdlHandler(QObject):
......@@ -246,7 +235,7 @@ class sdlHandler(QObject):
state_value = target_state[idx+1]
set_state = getattr(self.dll, "_set_state")
set_state(ctypes.c_char_p(state_value))
self.current_sdl_state = state_value
#self.current_sdl_state = state_value
#self.check_state()
#self.on_event()
......@@ -344,14 +333,31 @@ class sdlHandler(QObject):
arg='({})'.format(param.GSER())
if param else '')
self.add_to_msc('out', msg)
undo_cmd = SendTC(self, tc_func_ptr, param)
self.undo_stack.push(undo_cmd)
old_state = self.current_hash
# Send the TC
if param:
# Cast the SWIG type (ASN.1 Native format) to a ctypes pointer
try:
swig_ptr = int(param._ptr)
except TypeError:
# when swig uses a proxy class, pointer is in _ptr.this
swig_ptr = int(param._ptr.this)
param_ptr = ctypes.cast(swig_ptr,
ctypes.POINTER(ctypes.c_uint32))
tc_func_ptr(param_ptr)
else:
tc_func_ptr()
self.check_state()
# Update windows, highlight state, enable/disable buttons, etc.
self.current_hash = self.on_event(tc_name=name,
param=param.GSER() if param
else None)
# Update windows, highlight state, enable/disable buttons, etc.
self.current_hash = self.on_event(tc_name=name,
param=param.GSER() if param
else None)
# Create the Undo command to restore the previous state
undo_cmd = SendTC(self, old_state)
self.undo_stack.push(undo_cmd)
self.msc_macro_stop.emit()
def receive_tm(self, tm_name):
......
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