diff --git a/src/urh/signalprocessing/ProtocolAnalyzer.py b/src/urh/signalprocessing/ProtocolAnalyzer.py index 4a5ec35f5f..cd27783e5d 100644 --- a/src/urh/signalprocessing/ProtocolAnalyzer.py +++ b/src/urh/signalprocessing/ProtocolAnalyzer.py @@ -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) diff --git a/src/urh/ui/actions/DeleteBitsAndPauses.py b/src/urh/ui/actions/DeleteBitsAndPauses.py index 2b457eaaf5..1747395f9d 100644 --- a/src/urh/ui/actions/DeleteBitsAndPauses.py +++ b/src/urh/ui/actions/DeleteBitsAndPauses.py @@ -10,8 +10,7 @@ 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 @@ -19,18 +18,29 @@ def __init__(self, proto_analyzer: ProtocolAnalyzer, start_message: int, end_mes 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() diff --git a/src/urh/ui/actions/InsertBitsAndPauses.py b/src/urh/ui/actions/InsertBitsAndPauses.py index d555a329d0..cf8c2fef34 100644 --- a/src/urh/ui/actions/InsertBitsAndPauses.py +++ b/src/urh/ui/actions/InsertBitsAndPauses.py @@ -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 diff --git a/src/urh/ui/actions/InsertColumn.py b/src/urh/ui/actions/InsertColumn.py index 1dcbda1a0a..33c5559bab 100644 --- a/src/urh/ui/actions/InsertColumn.py +++ b/src/urh/ui/actions/InsertColumn.py @@ -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 \ No newline at end of file + for i in self.rows: + self.proto_analyzer_container.messages[i] = self.saved_messages[i] + self.saved_messages.clear()