Commit 82b0d4d2ffe2e63c1fafad4a350c7100a1572ea7
1 parent
ad49da8f
Exists in
master
and in
3 other branches
FIX: in some cases the undo was not recovering the previous state correctly
Showing
1 changed file
with
4 additions
and
16 deletions
Show diff stats
invesalius/data/mask.py
@@ -22,7 +22,6 @@ import plistlib | @@ -22,7 +22,6 @@ import plistlib | ||
22 | import random | 22 | import random |
23 | import shutil | 23 | import shutil |
24 | import tempfile | 24 | import tempfile |
25 | -import weakref | ||
26 | 25 | ||
27 | import numpy | 26 | import numpy |
28 | import vtk | 27 | import vtk |
@@ -71,29 +70,18 @@ class EditionHistoryNode(object): | @@ -71,29 +70,18 @@ class EditionHistoryNode(object): | ||
71 | class EditionHistory(object): | 70 | class EditionHistory(object): |
72 | def __init__(self, size=50): | 71 | def __init__(self, size=50): |
73 | self.history = [] | 72 | self.history = [] |
74 | - self._copies = weakref.WeakValueDictionary() | ||
75 | self.index = -1 | 73 | self.index = -1 |
76 | - self.size = size | 74 | + self.size = size * 2 |
77 | 75 | ||
78 | Publisher.sendMessage("Enable undo", False) | 76 | Publisher.sendMessage("Enable undo", False) |
79 | Publisher.sendMessage("Enable redo", False) | 77 | Publisher.sendMessage("Enable redo", False) |
80 | 78 | ||
81 | def new_node(self, index, orientation, array, p_array, clean): | 79 | def new_node(self, index, orientation, array, p_array, clean): |
82 | - try: | ||
83 | - p_node = self.history[self.index] | ||
84 | - except IndexError: | ||
85 | - p_node = None | ||
86 | - | ||
87 | - if self.index == -1 or (orientation != p_node.orientation or p_node.index != index): | ||
88 | - try: | ||
89 | - node = self._copies[(orientation, index)] | ||
90 | - except KeyError: | ||
91 | - node = EditionHistoryNode(index, orientation, p_array, clean) | ||
92 | - self._copies[(orientation, index)] = node | ||
93 | - self.add(node) | 80 | + # Saving the previous state, used to undo/redo correctly. |
81 | + p_node = EditionHistoryNode(index, orientation, p_array, clean) | ||
82 | + self.add(p_node) | ||
94 | 83 | ||
95 | node = EditionHistoryNode(index, orientation, array, clean) | 84 | node = EditionHistoryNode(index, orientation, array, clean) |
96 | - self._copies[(orientation, index)] = node | ||
97 | self.add(node) | 85 | self.add(node) |
98 | 86 | ||
99 | def add(self, node): | 87 | def add(self, node): |