diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 8285356b4..03ae7a613 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -1026,6 +1026,16 @@ class Fit: 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 diff --git a/gui/fitCommands/calc/module/localAdd.py b/gui/fitCommands/calc/module/localAdd.py index 8c03526a9..26d7ff04f 100644 --- a/gui/fitCommands/calc/module/localAdd.py +++ b/gui/fitCommands/calc/module/localAdd.py @@ -67,7 +67,7 @@ class CalcAddLocalModuleCommand(wx.Command): 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) diff --git a/gui/fitCommands/calc/module/localRemove.py b/gui/fitCommands/calc/module/localRemove.py index 1b2fb13d9..a404d0f37 100644 --- a/gui/fitCommands/calc/module/localRemove.py +++ b/gui/fitCommands/calc/module/localRemove.py @@ -3,7 +3,7 @@ from logbook import Logger 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 @@ -12,14 +12,16 @@ pyfalog = Logger(__name__) 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)) @@ -40,6 +42,9 @@ class CalcRemoveLocalModulesCommand(wx.Command): 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 @@ -76,6 +81,7 @@ class CalcRemoveLocalModulesCommand(wx.Command): if not any(results): return False restoreCheckedStates(fit, self.savedStateCheckChanges) + restoreRemovedDummies(fit, self.savedTail) return True @property diff --git a/gui/fitCommands/helpers.py b/gui/fitCommands/helpers.py index cb2449cf8..23f775a5e 100644 --- a/gui/fitCommands/helpers.py +++ b/gui/fitCommands/helpers.py @@ -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]