Undo removal of subsystems properly

This commit is contained in:
DarkPhoenix
2019-04-30 02:03:32 +03:00
parent 161c4629cf
commit e9dffeadf6
4 changed files with 25 additions and 10 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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)

View File

@@ -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