Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
asn1-value-editor
Commits
6f029b3d
Commit
6f029b3d
authored
Jan 05, 2015
by
Maxime Perrotin
Browse files
Complete undo/redo on sdl and msc levels
parent
0857b6c0
Changes
1
Show whitespace changes
Inline
Side-by-side
asn1_value_editor/sdlHandler.py
View file @
6f029b3d
...
@@ -43,33 +43,22 @@ except ImportError:
...
@@ -43,33 +43,22 @@ except ImportError:
class
SendTC
(
QUndoCommand
):
class
SendTC
(
QUndoCommand
):
''' Undo command to send a message to the running system '''
''' Undo command to send a message to the running system '''
def
__init__
(
self
,
handler
,
tc_ptr
,
param
):
def
__init__
(
self
,
handler
,
old_state
):
''' Init: save the current
state and compute parameter pointer
'''
''' Init: save the current
and old states
'''
super
(
SendTC
,
self
).
__init__
()
super
(
SendTC
,
self
).
__init__
()
self
.
handler
=
handler
self
.
handler
=
handler
self
.
recover_hash
=
handler
.
current_hash
self
.
new_state
=
handler
.
current_hash
self
.
tc_ptr
=
tc_ptr
self
.
old_state
=
old_state
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
))
def
undo
(
self
):
def
undo
(
self
):
''' Undo a send TC: Restore the system state as it was before the TC
''' Undo a send TC: Restore the system state as it was before the TC
was sent - setting back all global variables and internal state '''
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
):
def
redo
(
self
):
''' Execute the send TC action: just call the function in the DLL '''
''' Set the internal variables to the new state '''
if
self
.
param
:
if
self
.
new_state
!=
self
.
handler
.
current_hash
:
self
.
tc_ptr
(
self
.
param_ptr
)
self
.
handler
.
restore_global_state
(
self
.
new_state
)
else
:
self
.
tc_ptr
()
class
sdlHandler
(
QObject
):
class
sdlHandler
(
QObject
):
...
@@ -246,7 +235,7 @@ class sdlHandler(QObject):
...
@@ -246,7 +235,7 @@ class sdlHandler(QObject):
state_value
=
target_state
[
idx
+
1
]
state_value
=
target_state
[
idx
+
1
]
set_state
=
getattr
(
self
.
dll
,
"_set_state"
)
set_state
=
getattr
(
self
.
dll
,
"_set_state"
)
set_state
(
ctypes
.
c_char_p
(
state_value
))
set_state
(
ctypes
.
c_char_p
(
state_value
))
self
.
current_sdl_state
=
state_value
#
self.current_sdl_state = state_value
#self.check_state()
#self.check_state()
#self.on_event()
#self.on_event()
...
@@ -344,14 +333,31 @@ class sdlHandler(QObject):
...
@@ -344,14 +333,31 @@ class sdlHandler(QObject):
arg
=
'({})'
.
format
(
param
.
GSER
())
arg
=
'({})'
.
format
(
param
.
GSER
())
if
param
else
''
)
if
param
else
''
)
self
.
add_to_msc
(
'out'
,
msg
)
self
.
add_to_msc
(
'out'
,
msg
)
undo_cmd
=
SendTC
(
self
,
tc_func_ptr
,
param
)
old_state
=
self
.
current_hash
self
.
undo_stack
.
push
(
undo_cmd
)
self
.
check_state
()
# 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.
# Update windows, highlight state, enable/disable buttons, etc.
self
.
current_hash
=
self
.
on_event
(
tc_name
=
name
,
self
.
current_hash
=
self
.
on_event
(
tc_name
=
name
,
param
=
param
.
GSER
()
if
param
param
=
param
.
GSER
()
if
param
else
None
)
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
()
self
.
msc_macro_stop
.
emit
()
def
receive_tm
(
self
,
tm_name
):
def
receive_tm
(
self
,
tm_name
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment