Skip to content

Commit

Permalink
enhance performance of undo/redo actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jopohl committed May 12, 2017
1 parent e9f5856 commit 7b804ac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/urh/signalprocessing/ProtocolAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ def delete_messages(self, msg_start: int, msg_end: int, start: int, end: int, vi
for i in reversed(removable_msg_indices):
del self.messages[i]

return removable_msg_indices

def convert_index(self, index: int, from_view: int, to_view: int, decoded: bool, message_indx=-1) -> tuple:
"""
Konvertiert einen Index aus der einen Sicht (z.B. Bit) in eine andere (z.B. Hex)
Expand Down
34 changes: 22 additions & 12 deletions src/urh/ui/actions/DeleteBitsAndPauses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,37 @@ def __init__(self, proto_analyzer: ProtocolAnalyzer, start_message: int, end_mes
start: int, end: int, view: int, decoded: bool, subprotos=None):
super().__init__()

self.subprotos = [] if subprotos is None else subprotos
""":type: list of ProtocolAnalyzer """
self.sub_protocols = [] if subprotos is None else subprotos # type: list[ProtocolAnalyzer]
self.view = view
self.end = end
self.start = start
self.end_message = end_message
self.start_message = start_message
self.proto_analyzer = proto_analyzer
self.decoded = decoded
self.orig_messages = copy.deepcopy(self.proto_analyzer.messages)
self.subproto_hist = {} # for CFC
for subproto in self.subprotos:
self.subproto_hist[subproto] = copy.deepcopy(subproto.messages)
self.saved_messages = []
self.removed_message_indices = []
self.sub_protocol_history = {} # for CFC
for sub_protocol in self.sub_protocols:
self.sub_protocol_history[sub_protocol] = sub_protocol.messages


self.setText("Delete Bits")
self.setText("Delete")

def redo(self):
self.proto_analyzer.delete_messages(self.start_message, self.end_message, self.start, self.end, self.view, self.decoded)
self.saved_messages = copy.deepcopy(self.proto_analyzer.messages[self.start_message:self.end_message+1])
self.removed_message_indices = self.proto_analyzer.delete_messages(self.start_message, self.end_message,
self.start, self.end,
self.view, self.decoded)

def undo(self):
self.proto_analyzer.messages = self.orig_messages
for subproto in self.subproto_hist.keys():
subproto.messages = self.subproto_hist[subproto]
for i in reversed(range(self.start_message, self.end_message+1)):
if i in self.removed_message_indices:
self.proto_analyzer.messages.insert(i, self.saved_messages[i-self.start_message])
else:
self.proto_analyzer.messages[i] = self.saved_messages[i-self.start_message]

for sub_protocol in self.sub_protocol_history.keys():
sub_protocol.messages = self.sub_protocol_history[sub_protocol]

self.saved_messages.clear()
self.removed_message_indices.clear()
7 changes: 5 additions & 2 deletions src/urh/ui/actions/InsertBitsAndPauses.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ def __init__(self, proto_analyzer_container: ProtocolAnalyzerContainer, index: i
self.index = len(self.proto_analyzer_container.messages)

self.setText("Insert Bits at index {0:d}".format(self.index))
self.orig_messages = copy.deepcopy(self.proto_analyzer_container.messages)
self.num_messages = 0

def redo(self):
self.proto_analyzer_container.insert_protocol_analyzer(self.index, self.proto_analyzer)
self.num_messages += len(self.proto_analyzer.messages)

def undo(self):
self.proto_analyzer_container.messages = self.orig_messages
for i in reversed(range(self.index, self.index+self.num_messages)):
del self.proto_analyzer_container.messages[i]
self.num_messages = 0
7 changes: 5 additions & 2 deletions src/urh/ui/actions/InsertColumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ def __init__(self, proto_analyzer_container: ProtocolAnalyzerContainer, index: i
self.nbits = 1 if view == 0 else 4 if view == 1 else 8
self.rows = rows

self.orig_messages = copy.deepcopy(self.proto_analyzer_container.messages)
self.saved_messages = {}

self.setText("Insert column at {0:d}".format(index))

def redo(self):
for i in self.rows:
msg = self.proto_analyzer_container.messages[i]
self.saved_messages[i] = copy.deepcopy(msg)
for j in range(self.nbits):
msg.insert(self.index + j, False)

def undo(self):
self.proto_analyzer_container.messages = self.orig_messages
for i in self.rows:
self.proto_analyzer_container.messages[i] = self.saved_messages[i]
self.saved_messages.clear()

0 comments on commit 7b804ac

Please sign in to comment.