From e9dffeadf6cdbcef5d813355619a999e98b74975 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 30 Apr 2019 02:03:32 +0300 Subject: [PATCH] Undo removal of subsystems properly --- gui/fitCommands/calc/module/localRemove.py | 12 +++++++----- gui/fitCommands/calc/module/localReplace.py | 9 ++++++--- gui/fitCommands/helpers.py | 7 +++++++ service/fit.py | 7 +++++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/gui/fitCommands/calc/module/localRemove.py b/gui/fitCommands/calc/module/localRemove.py index 211f6f0e7..276534d82 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 @@ -19,6 +19,7 @@ class CalcRemoveLocalModulesCommand(wx.Command): self.commit = commit self.savedSubInfos = None self.savedModInfos = None + self.savedRemovedDummies = None self.savedStateCheckChanges = None def Do(self): @@ -43,7 +44,7 @@ class CalcRemoveLocalModulesCommand(wx.Command): # Need to flush because checkStates sometimes relies on module->fit # relationship via .owner attribute, which is handled by SQLAlchemy eos.db.flush() - sFit.recalc(fit) + self.savedRemovedDummies = sFit.recalc(fit) self.savedStateCheckChanges = sFit.checkStates(fit, None) if self.commit: eos.db.commit() @@ -60,15 +61,16 @@ class CalcRemoveLocalModulesCommand(wx.Command): if len(self.savedSubInfos) > 0: for position, modInfo in self.savedSubInfos.items(): cmd = CalcReplaceLocalModuleCommand( - fitID=self.fitID, position=position, newModInfo=modInfo, commit=False) + fitID=self.fitID, position=position, newModInfo=modInfo, commit=False, fill=False) results.append(cmd.Do()) - sFit.recalc(fit) + sFit.recalc(fit, fill=False) for position, modInfo in self.savedModInfos.items(): cmd = CalcReplaceLocalModuleCommand( - fitID=self.fitID, position=position, newModInfo=modInfo, commit=False) + fitID=self.fitID, position=position, newModInfo=modInfo, commit=False, fill=False) results.append(cmd.Do()) if not any(results): return False + restoreRemovedDummies(fit, self.savedRemovedDummies) restoreCheckedStates(fit, self.savedStateCheckChanges) if self.commit: eos.db.commit() diff --git a/gui/fitCommands/calc/module/localReplace.py b/gui/fitCommands/calc/module/localReplace.py index bac71c0c2..7a8f5f1d1 100644 --- a/gui/fitCommands/calc/module/localReplace.py +++ b/gui/fitCommands/calc/module/localReplace.py @@ -3,7 +3,7 @@ from logbook import Logger import eos.db from eos.exception import HandledListActionError -from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates, stateLimit +from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates, restoreRemovedDummies, stateLimit from service.fit import Fit @@ -12,7 +12,7 @@ pyfalog = Logger(__name__) class CalcReplaceLocalModuleCommand(wx.Command): - def __init__(self, fitID, position, newModInfo, unloadInvalidCharges=False, commit=True): + def __init__(self, fitID, position, newModInfo, unloadInvalidCharges=False, commit=True, fill=True): wx.Command.__init__(self, True, 'Replace Module') self.fitID = fitID self.position = position @@ -20,7 +20,9 @@ class CalcReplaceLocalModuleCommand(wx.Command): self.oldModInfo = None self.unloadInvalidCharges = unloadInvalidCharges self.commit = commit + self.fill = fill self.savedStateCheckChanges = None + self.savedRemovedDummies = None self.unloadedCharge = None def Do(self): @@ -61,7 +63,7 @@ class CalcReplaceLocalModuleCommand(wx.Command): # Need to flush because checkStates sometimes relies on module->fit # relationship via .owner attribute, which is handled by SQLAlchemy eos.db.flush() - sFit.recalc(fit) + self.savedRemovedDummies = sFit.recalc(fit, fill=self.fill) self.savedStateCheckChanges = sFit.checkStates(fit, newMod) if self.commit: eos.db.commit() @@ -96,6 +98,7 @@ class CalcReplaceLocalModuleCommand(wx.Command): pyfalog.warning('Failed to replace in list') self.Do() return False + restoreRemovedDummies(fit, self.savedRemovedDummies) restoreCheckedStates(fit, self.savedStateCheckChanges) if self.commit: eos.db.commit() diff --git a/gui/fitCommands/helpers.py b/gui/fitCommands/helpers.py index 2410e0c0f..fc620ab23 100644 --- a/gui/fitCommands/helpers.py +++ b/gui/fitCommands/helpers.py @@ -346,6 +346,13 @@ def restoreCheckedStates(fit, stateInfo, ignoreModPoss=()): fit.projectedDrones[pos].amountActive = amountActive +def restoreRemovedDummies(fit, dummyInfo): + # Need this to properly undo the case when removal of subsystems removes dummy slots + for position in sorted(dummyInfo): + slot = dummyInfo[position] + fit.modules.insert(position, Module.buildEmpty(slot)) + + def getSimilarModPositions(mods, mainMod): sMkt = Market.getInstance() mainGroupID = getattr(sMkt.getGroupByItem(mainMod.item), 'ID', None) diff --git a/service/fit.py b/service/fit.py index 67b745402..5e9b8cb1c 100644 --- a/service/fit.py +++ b/service/fit.py @@ -470,7 +470,7 @@ class Fit(FitDeprecated): eos.db.commit() self.recalc(fit) - def recalc(self, fit): + def recalc(self, fit, fill=True): if isinstance(fit, int): fit = self.getFit(fit) start_time = time() @@ -480,6 +480,9 @@ class Fit(FitDeprecated): fit.clear() fit.calculateModifiedAttributes() - removedDummies = fit.fill() + if fill: + removedDummies = fit.fill() + else: + removedDummies = {} pyfalog.info("=" * 10 + "recalc time: " + str(time() - start_time) + "=" * 10) return removedDummies