Skip to content

Commit

Permalink
Fix undo for fill with module (which was caused by module add command…
Browse files Browse the repository at this point in the history
… not being undone properly in case of failure)
  • Loading branch information
DarkFenX committed Apr 20, 2020
1 parent 98579c7 commit f17cf9b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
10 changes: 10 additions & 0 deletions eos/saveddata/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,16 @@ def unfill(self):
if mod.isEmpty:
del self.modules[i]

def clearTail(self):
tailPositions = {}
for mod in reversed(self.modules):
if not mod.isEmpty:
break
tailPositions[self.modules.index(mod)] = mod.slot
for pos in reversed(tailPositions):
self.modules.remove(self.modules[pos])
return tailPositions

@property
def modCount(self):
x = 0
Expand Down
2 changes: 1 addition & 1 deletion gui/fitCommands/calc/module/localAdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def Undo(self):
if self.savedPosition is None:
return False
from .localRemove import CalcRemoveLocalModulesCommand
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.savedPosition], recalc=False)
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.savedPosition], recalc=False, clearTail=True)
if not cmd.Do():
return False
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
Expand Down
10 changes: 8 additions & 2 deletions gui/fitCommands/calc/module/localRemove.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import eos.db
from eos.const import FittingSlot
from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates
from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates, restoreRemovedDummies
from service.fit import Fit


Expand All @@ -12,14 +12,16 @@

class CalcRemoveLocalModulesCommand(wx.Command):

def __init__(self, fitID, positions, recalc=True):
def __init__(self, fitID, positions, recalc=True, clearTail=False):
wx.Command.__init__(self, True, 'Remove Module')
self.fitID = fitID
self.positions = positions
self.recalc = recalc
self.clearTail = clearTail
self.savedSubInfos = None
self.savedModInfos = None
self.savedStateCheckChanges = None
self.savedTail = None

def Do(self):
pyfalog.debug('Doing removal of local modules from positions {} on fit {}'.format(self.positions, self.fitID))
Expand All @@ -40,6 +42,9 @@ def Do(self):
if len(self.savedSubInfos) == 0 and len(self.savedModInfos) == 0:
return False

if self.clearTail:
self.savedTail = fit.clearTail()

if self.recalc:
# Need to flush because checkStates sometimes relies on module->fit
# relationship via .owner attribute, which is handled by SQLAlchemy
Expand Down Expand Up @@ -76,6 +81,7 @@ def Undo(self):
if not any(results):
return False
restoreCheckedStates(fit, self.savedStateCheckChanges)
restoreRemovedDummies(fit, self.savedTail)
return True

@property
Expand Down
2 changes: 2 additions & 0 deletions gui/fitCommands/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ def restoreCheckedStates(fit, stateInfo, ignoreModPoss=()):


def restoreRemovedDummies(fit, dummyInfo):
if dummyInfo is None:
return
# Need this to properly undo the case when removal of subsystems removes dummy slots
for position in sorted(dummyInfo):
slot = dummyInfo[position]
Expand Down

0 comments on commit f17cf9b

Please sign in to comment.