Restore removed dummies on all commands which can deal with t3c subsystems

This commit is contained in:
DarkPhoenix
2019-04-30 13:50:10 +03:00
parent fa2bceaff9
commit 63a599ca85
13 changed files with 71 additions and 43 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, restoreRemovedDummies
from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates
from service.fit import Fit
@@ -19,7 +19,6 @@ class CalcRemoveLocalModulesCommand(wx.Command):
self.commit = commit
self.savedSubInfos = None
self.savedModInfos = None
self.savedRemovedDummies = None
self.savedStateCheckChanges = None
def Do(self):
@@ -44,7 +43,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()
self.savedRemovedDummies = sFit.recalc(fit)
sFit.recalc(fit)
self.savedStateCheckChanges = sFit.checkStates(fit, None)
if self.commit:
eos.db.commit()
@@ -70,7 +69,6 @@ class CalcRemoveLocalModulesCommand(wx.Command):
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, restoreRemovedDummies, stateLimit
from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates, stateLimit
from service.fit import Fit
@@ -21,7 +21,6 @@ class CalcReplaceLocalModuleCommand(wx.Command):
self.unloadInvalidCharges = unloadInvalidCharges
self.commit = commit
self.savedStateCheckChanges = None
self.savedRemovedDummies = None
self.unloadedCharge = None
def Do(self):
@@ -62,7 +61,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()
self.savedRemovedDummies = sFit.recalc(fit)
sFit.recalc(fit)
self.savedStateCheckChanges = sFit.checkStates(fit, newMod)
if self.commit:
eos.db.commit()
@@ -97,7 +96,6 @@ 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

@@ -3,7 +3,7 @@ import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.localAdd import CalcAddLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo, restoreRemovedDummies
from service.fit import Fit
@@ -14,13 +14,14 @@ class GuiAddLocalModuleCommand(wx.Command):
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.itemID = itemID
self.savedRemovedDummies = None
def Do(self):
cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID))
success = self.internalHistory.submit(cmd)
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID)
@@ -29,8 +30,10 @@ class GuiAddLocalModuleCommand(wx.Command):
return success
def Undo(self):
success = self.internalHistory.undoAll()
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
wx.PostEvent(

View File

@@ -4,7 +4,7 @@ import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.localReplace import CalcReplaceLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo, restoreRemovedDummies
from service.fit import Fit
@@ -17,6 +17,7 @@ class GuiChangeLocalModuleMetasCommand(wx.Command):
self.positions = positions
self.newItemID = newItemID
self.relacedItemIDs = None
self.savedRemovedDummies = None
def Do(self):
sFit = Fit.getInstance()
@@ -44,7 +45,7 @@ class GuiChangeLocalModuleMetasCommand(wx.Command):
success = self.internalHistory.submitBatch(*commands)
eos.db.commit()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
events = []
if success and self.replacedItemIDs:
events.append(GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.replacedItemIDs))
@@ -57,9 +58,11 @@ class GuiChangeLocalModuleMetasCommand(wx.Command):
return success
def Undo(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
eos.db.commit()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
events = []

View File

@@ -3,7 +3,7 @@ import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.localChangeStates import CalcChangeLocalModuleStatesCommand
from gui.fitCommands.helpers import InternalCommandHistory
from gui.fitCommands.helpers import InternalCommandHistory, restoreRemovedDummies
from service.fit import Fit
@@ -16,6 +16,7 @@ class GuiChangeLocalModuleStatesCommand(wx.Command):
self.mainPosition = mainPosition
self.positions = positions
self.click = click
self.savedRemovedDummies = None
def Do(self):
cmd = CalcChangeLocalModuleStatesCommand(
@@ -26,13 +27,15 @@ class GuiChangeLocalModuleStatesCommand(wx.Command):
success = self.internalHistory.submit(cmd)
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))

View File

@@ -3,7 +3,7 @@ import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.localClone import CalcCloneLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory
from gui.fitCommands.helpers import InternalCommandHistory, restoreRemovedDummies
from service.fit import Fit
@@ -16,6 +16,7 @@ class GuiCloneLocalModuleCommand(wx.Command):
self.srcPosition = srcPosition
self.dstPosition = dstPosition
self.savedItemID = None
self.savedRemovedDummies = None
def Do(self):
if self.srcPosition == self.dstPosition:
@@ -25,7 +26,7 @@ class GuiCloneLocalModuleCommand(wx.Command):
success = self.internalHistory.submit(cmd)
fit = sFit.getFit(self.fitID)
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
self.savedItemID = fit.modules[self.srcPosition].itemID
if success and self.savedItemID is not None:
event = GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.savedItemID)
@@ -35,8 +36,10 @@ class GuiCloneLocalModuleCommand(wx.Command):
return success
def Undo(self):
success = self.internalHistory.undoAll()
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
if success and self.savedItemID is not None:

View File

@@ -4,7 +4,7 @@ import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.localAdd import CalcAddLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo, restoreRemovedDummies
from service.fit import Fit
@@ -15,6 +15,7 @@ class GuiFillWithNewLocalModulesCommand(wx.Command):
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.itemID = itemID
self.savedRemovedDummies = None
def Do(self):
info = ModuleInfo(itemID=self.itemID)
@@ -27,7 +28,7 @@ class GuiFillWithNewLocalModulesCommand(wx.Command):
eos.db.commit()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
success = added_modules > 0
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
@@ -37,9 +38,11 @@ class GuiFillWithNewLocalModulesCommand(wx.Command):
return success
def Undo(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
eos.db.commit()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
wx.PostEvent(

View File

@@ -4,7 +4,7 @@ import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.localAdd import CalcAddLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo, restoreRemovedDummies
from service.fit import Fit
@@ -16,6 +16,7 @@ class GuiFillWithClonedLocalModulesCommand(wx.Command):
self.fitID = fitID
self.position = position
self.savedItemID = None
self.savedRemovedDummies = None
def Do(self):
sFit = Fit.getInstance()
@@ -31,7 +32,7 @@ class GuiFillWithClonedLocalModulesCommand(wx.Command):
added_modules += 1
eos.db.commit()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
success = added_modules > 0
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
@@ -41,9 +42,11 @@ class GuiFillWithClonedLocalModulesCommand(wx.Command):
return success
def Undo(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
eos.db.commit()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
wx.PostEvent(

View File

@@ -3,7 +3,7 @@ import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.localAdd import CalcAddLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo, restoreRemovedDummies
from service.fit import Fit
@@ -18,21 +18,24 @@ class GuiImportLocalMutatedModuleCommand(wx.Command):
baseItemID=baseItem.ID,
mutaplasmidID=mutaplasmid.ID,
mutations=mutations)
self.savedRemovedDummies = None
def Do(self):
cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=self.newModInfo)
success = self.internalHistory.submit(cmd)
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.newModInfo.itemID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
wx.PostEvent(

View File

@@ -3,7 +3,7 @@ import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.localRemove import CalcRemoveLocalModulesCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from gui.fitCommands.helpers import InternalCommandHistory, restoreRemovedDummies
from service.fit import Fit
@@ -15,6 +15,7 @@ class GuiRemoveLocalModuleCommand(wx.Command):
self.fitID = fitID
self.positions = positions
self.savedTypeIDs = None
self.savedRemovedDummies = None
def Do(self):
sFit = Fit.getInstance()
@@ -23,7 +24,7 @@ class GuiRemoveLocalModuleCommand(wx.Command):
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=self.positions)
success = self.internalHistory.submit(cmd)
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.savedTypeIDs)
@@ -32,8 +33,10 @@ class GuiRemoveLocalModuleCommand(wx.Command):
return success
def Undo(self):
success = self.internalHistory.undoAll()
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
wx.PostEvent(

View File

@@ -3,9 +3,8 @@ import wx
import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.localAdd import CalcAddLocalModuleCommand
from gui.fitCommands.calc.module.localReplace import CalcReplaceLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo, restoreRemovedDummies
from service.fit import Fit
@@ -17,6 +16,7 @@ class GuiReplaceLocalModuleCommand(wx.Command):
self.fitID = fitID
self.itemID = itemID
self.positions = positions
self.savedRemovedDummies = None
def Do(self):
results = []
@@ -27,7 +27,7 @@ class GuiReplaceLocalModuleCommand(wx.Command):
eos.db.commit()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID)
@@ -36,9 +36,11 @@ class GuiReplaceLocalModuleCommand(wx.Command):
return success
def Undo(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
eos.db.commit()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
wx.PostEvent(

View File

@@ -7,7 +7,7 @@ from gui.fitCommands.calc.cargo.add import CalcAddCargoCommand
from gui.fitCommands.calc.cargo.remove import CalcRemoveCargoCommand
from gui.fitCommands.calc.module.changeCharges import CalcChangeModuleChargesCommand
from gui.fitCommands.calc.module.localReplace import CalcReplaceLocalModuleCommand
from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory, ModuleInfo
from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory, ModuleInfo, restoreRemovedDummies
from service.fit import Fit
@@ -26,13 +26,14 @@ class GuiCargoToLocalModuleCommand(wx.Command):
self.copy = copy
self.removedModItemID = None
self.addedModItemID = None
self.savedRemovedDummies = None
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
srcCargo = next((c for c in fit.cargo if c.itemID == self.srcCargoItemID), None)
if srcCargo is None:
return
return False
dstMod = fit.modules[self.dstModPosition]
# Moving/copying charge from cargo to fit
if srcCargo.item.isCharge and not dstMod.isEmpty:
@@ -139,7 +140,7 @@ class GuiCargoToLocalModuleCommand(wx.Command):
return False
eos.db.commit()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
events = []
if self.removedModItemID is not None:
events.append(GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.removedModItemID))
@@ -152,9 +153,11 @@ class GuiCargoToLocalModuleCommand(wx.Command):
return success
def Undo(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
eos.db.commit()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
events = []

View File

@@ -7,7 +7,7 @@ from gui.fitCommands.calc.cargo.add import CalcAddCargoCommand
from gui.fitCommands.calc.cargo.remove import CalcRemoveCargoCommand
from gui.fitCommands.calc.module.localRemove import CalcRemoveLocalModulesCommand
from gui.fitCommands.calc.module.localReplace import CalcReplaceLocalModuleCommand
from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory, ModuleInfo
from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory, ModuleInfo, restoreRemovedDummies
from service.fit import Fit
@@ -22,6 +22,7 @@ class GuiLocalModuleToCargoCommand(wx.Command):
self.copy = copy
self.removedModItemID = None
self.addedModItemID = None
self.savedRemovedDummies = None
def Do(self):
fit = Fit.getInstance().getFit(self.fitID)
@@ -118,7 +119,7 @@ class GuiLocalModuleToCargoCommand(wx.Command):
eos.db.commit()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
self.savedRemovedDummies = sFit.fill(self.fitID)
events = []
if self.removedModItemID is not None:
events.append(GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.removedModItemID))
@@ -131,9 +132,11 @@ class GuiLocalModuleToCargoCommand(wx.Command):
return success
def Undo(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
restoreRemovedDummies(fit, self.savedRemovedDummies)
success = self.internalHistory.undoAll()
eos.db.commit()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)
sFit.fill(self.fitID)
events = []