Save secondary state changes and restore them on undo

This commit is contained in:
DarkPhoenix
2019-04-16 14:48:25 +03:00
parent 30b12b04e8
commit fbf3cace10
21 changed files with 92 additions and 49 deletions

View File

@@ -3,7 +3,7 @@ from logbook import Logger
import eos.db
from eos.exception import HandledListActionError
from gui.fitCommands.helpers import stateLimit
from gui.fitCommands.helpers import restoreCheckedStates, stateLimit
from service.fit import Fit
@@ -16,9 +16,10 @@ class CalcAddLocalModuleCommand(wx.Command):
wx.Command.__init__(self, True, 'Add Module')
self.fitID = fitID
self.newModInfo = newModInfo
self.commit = commit
self.savedPosition = None
self.subsystemCmd = None
self.commit = commit
self.savedStateCheckChanges = None
def Do(self):
pyfalog.debug('Doing addition of local module {} to fit {}'.format(self.newModInfo, self.fitID))
@@ -50,8 +51,8 @@ class CalcAddLocalModuleCommand(wx.Command):
eos.db.commit()
return False
self.savedPosition = newMod.modPosition
sFit.recalc(self.fitID)
sFit.checkStates(fit, newMod)
sFit.recalc(fit)
self.savedStateCheckChanges = sFit.checkStates(fit, newMod)
if self.commit:
eos.db.commit()
return True
@@ -65,4 +66,7 @@ class CalcAddLocalModuleCommand(wx.Command):
if self.savedPosition is None:
return False
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.savedPosition], commit=self.commit)
return cmd.Do()
if not cmd.Do():
return False
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
return True

View File

@@ -3,6 +3,7 @@ from logbook import Logger
import eos.db
from eos.saveddata.module import Module
from gui.fitCommands.helpers import restoreCheckedStates
from service.fit import Fit
@@ -18,6 +19,7 @@ class CalcChangeLocalModuleStatesCommand(wx.Command):
self.positions = positions
self.click = click
self.savedStates = {}
self.savedStateCheckChanges = None
def Do(self):
pyfalog.debug('Doing change of local module states at position {}/{} to click {} on fit {}'.format(self.mainPosition, self.positions, self.click, self.fitID))
@@ -44,8 +46,8 @@ class CalcChangeLocalModuleStatesCommand(wx.Command):
mod.state = proposedState
if not changed:
return False
sFit.recalc(self.fitID)
sFit.checkStates(fit, mainMod)
sFit.recalc(fit)
self.savedStateCheckChanges = sFit.checkStates(fit, mainMod)
eos.db.commit()
return True
@@ -56,4 +58,6 @@ class CalcChangeLocalModuleStatesCommand(wx.Command):
mod = fit.modules[position]
pyfalog.debug('Reverting {} to state {} for fit ID {}'.format(mod, state, self.fitID))
mod.state = state
restoreCheckedStates(fit, self.savedStateCheckChanges)
eos.db.commit()
return True

View File

@@ -5,6 +5,7 @@ from logbook import Logger
import eos.db
from eos.exception import HandledListActionError
from gui.fitCommands.helpers import restoreCheckedStates
from service.fit import Fit
@@ -18,6 +19,7 @@ class CalcCloneLocalModuleCommand(wx.Command):
self.fitID = fitID
self.srcPosition = srcPosition
self.dstPosition = dstPosition
self.savedStateCheckChanges = None
def Do(self):
pyfalog.debug('Doing cloning of local module from position {} to position {} for fit ID {}'.format(self.srcPosition, self.dstPosition, self.fitID))
@@ -36,8 +38,8 @@ class CalcCloneLocalModuleCommand(wx.Command):
pyfalog.warning('Failed to replace module')
eos.db.commit()
return False
sFit.recalc(self.fitID)
sFit.checkStates(fit, copyMod)
sFit.recalc(fit)
self.savedStateCheckChanges = sFit.checkStates(fit, copyMod)
eos.db.commit()
return True
@@ -45,4 +47,7 @@ class CalcCloneLocalModuleCommand(wx.Command):
pyfalog.debug('Undoing cloning of local module from position {} to position {} for fit ID {}'.format(self.srcPosition, self.dstPosition, self.fitID))
from .localRemove import CalcRemoveLocalModuleCommand
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.dstPosition])
return cmd.Do()
if not cmd.Do():
return False
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
return True

View File

@@ -2,7 +2,7 @@ import wx
from logbook import Logger
import eos.db
from gui.fitCommands.helpers import ModuleInfo
from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates
from service.fit import Fit
@@ -17,6 +17,7 @@ class CalcRemoveLocalModuleCommand(wx.Command):
self.positions = positions
self.savedModInfos = {}
self.commit = commit
self.savedStateCheckChanges = None
def Do(self):
pyfalog.debug('Doing removal of local modules from positions {} on fit {}'.format(self.positions, self.fitID))
@@ -29,7 +30,8 @@ class CalcRemoveLocalModuleCommand(wx.Command):
self.savedModInfos[position] = ModuleInfo.fromModule(mod)
fit.modules.free(position)
sFit.checkStates(fit, None)
sFit.recalc(fit)
self.savedStateCheckChanges = sFit.checkStates(fit, None)
if self.commit:
eos.db.commit()
# If no modules were removed, report that command was not completed
@@ -42,6 +44,9 @@ class CalcRemoveLocalModuleCommand(wx.Command):
for position, modInfo in self.savedModInfos.items():
cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=modInfo, commit=False)
results.append(cmd.Do())
if not any(results):
return False
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
if self.commit:
eos.db.commit()
return any(results)
return True

View File

@@ -3,7 +3,7 @@ from logbook import Logger
import eos.db
from eos.exception import HandledListActionError
from gui.fitCommands.helpers import ModuleInfo, stateLimit
from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates, stateLimit
from service.fit import Fit
@@ -20,6 +20,7 @@ class CalcReplaceLocalModuleCommand(wx.Command):
self.oldModInfo = None
self.unloadInvalidCharges = unloadInvalidCharges
self.commit = commit
self.savedStateCheckChanges = None
self.unloadedCharge = None
def Do(self):
@@ -56,22 +57,26 @@ class CalcReplaceLocalModuleCommand(wx.Command):
pyfalog.warning('Failed to replace in list')
self.Undo()
return False
sFit.recalc(self.fitID)
sFit.checkStates(fit, newMod)
sFit.recalc(fit)
self.savedStateCheckChanges = sFit.checkStates(fit, newMod)
if self.commit:
eos.db.commit()
return True
def Undo(self):
pyfalog.debug('Undoing replacement of local module at position {} to {} on fit {}'.format(self.newModInfo, self.position, self.fitID))
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
# Remove if there was no module
if self.oldModInfo is None:
from .localRemove import CalcRemoveLocalModuleCommand
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.position], commit=self.commit)
return cmd.Do()
if not cmd.Do():
return False
sFit.recalc(fit)
restoreCheckedStates(fit, self.savedStateCheckChanges)
return True
# Replace if there was
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
oldMod = self.oldModInfo.toModule()
if oldMod is None:
return False
@@ -87,8 +92,8 @@ class CalcReplaceLocalModuleCommand(wx.Command):
pyfalog.warning('Failed to replace in list')
self.Do()
return False
sFit.recalc(self.fitID)
sFit.checkStates(fit, oldMod)
sFit.recalc(fit)
restoreCheckedStates(fit, self.savedStateCheckChanges)
if self.commit:
eos.db.commit()
return True