Rework cargo to module command

This commit is contained in:
DarkPhoenix
2019-04-16 01:41:19 +03:00
parent a270dc44d2
commit 64bba0cfdb
13 changed files with 174 additions and 116 deletions

View File

@@ -11,11 +11,12 @@ pyfalog = Logger(__name__)
class CalcChangeModuleChargesCommand(wx.Command):
def __init__(self, fitID, projected, chargeMap):
def __init__(self, fitID, projected, chargeMap, commit=True):
wx.Command.__init__(self, True, 'Change Module Charges')
self.fitID = fitID
self.projected = projected
self.chargeMap = chargeMap
self.commit = commit
self.savedChargeMap = None
def Do(self):
@@ -43,12 +44,17 @@ class CalcChangeModuleChargesCommand(wx.Command):
self.savedChargeMap[position] = mod.chargeID
changes = True
mod.charge = chargeItem
if changes:
if not changes:
return False
if self.commit:
eos.db.commit()
return True
return False
return True
def Undo(self):
pyfalog.debug('Undoing change of module charges according to map {} on fit {}'.format(self.chargeMap, self.fitID))
cmd = CalcChangeModuleChargesCommand(fitID=self.fitID, projected=self.projected, chargeMap=self.savedChargeMap)
cmd = CalcChangeModuleChargesCommand(
fitID=self.fitID,
projected=self.projected,
chargeMap=self.savedChargeMap,
commit=self.commit)
return cmd.Do()

View File

@@ -63,7 +63,7 @@ class CalcReplaceLocalModuleCommand(wx.Command):
# Remove if there was no module
if self.oldModInfo is None:
from .localRemove import CalcRemoveLocalModuleCommand
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.position])
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.position], commit=self.commit)
return cmd.Do()
# Replace if there was
sFit = Fit.getInstance()