Commit 82b0d4d2ffe2e63c1fafad4a350c7100a1572ea7

Authored by tfmoraes
1 parent ad49da8f

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 22 import random
23 23 import shutil
24 24 import tempfile
25   -import weakref
26 25  
27 26 import numpy
28 27 import vtk
... ... @@ -71,29 +70,18 @@ class EditionHistoryNode(object):
71 70 class EditionHistory(object):
72 71 def __init__(self, size=50):
73 72 self.history = []
74   - self._copies = weakref.WeakValueDictionary()
75 73 self.index = -1
76   - self.size = size
  74 + self.size = size * 2
77 75  
78 76 Publisher.sendMessage("Enable undo", False)
79 77 Publisher.sendMessage("Enable redo", False)
80 78  
81 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 84 node = EditionHistoryNode(index, orientation, array, clean)
96   - self._copies[(orientation, index)] = node
97 85 self.add(node)
98 86  
99 87 def add(self, node):
... ...