Rework how effect-blocking modules (scram) work to properly support undoing
This commit is contained in:
@@ -10027,16 +10027,16 @@ class Effect3380(BaseEffect):
|
||||
|
||||
@staticmethod
|
||||
def handler(fit, module, context):
|
||||
|
||||
if 'projected' in context:
|
||||
fit.ship.increaseItemAttr('warpScrambleStatus', module.getModifiedItemAttr('warpScrambleStrength'))
|
||||
if module.charge is not None and module.charge.ID == 45010:
|
||||
for mod in fit.modules:
|
||||
if not mod.isEmpty and mod.item.requiresSkill('High Speed Maneuvering') and mod.state > FittingModuleState.ONLINE:
|
||||
mod.state = FittingModuleState.ONLINE
|
||||
if not mod.isEmpty and mod.item.requiresSkill('Micro Jump Drive Operation') and mod.state > FittingModuleState.ONLINE:
|
||||
mod.state = FittingModuleState.ONLINE
|
||||
if module.charge is not None:
|
||||
if module.charge.ID in (29003, 45010):
|
||||
fit.ship.increaseItemAttr('warpScrambleStatus', module.getModifiedItemAttr('warpScrambleStrength'))
|
||||
if module.charge.ID == 45010:
|
||||
fit.modules.filteredItemIncrease(
|
||||
lambda mod: mod.item.requiresSkill('High Speed Maneuvering') or mod.item.requiresSkill('Micro Jump Drive Operation'),
|
||||
'activationBlocked', 1)
|
||||
else:
|
||||
fit.ship.forceItemAttr('disallowAssistance', 1)
|
||||
if module.charge is None:
|
||||
fit.ship.boostItemAttr('mass', module.getModifiedItemAttr('massBonusPercentage'))
|
||||
fit.ship.boostItemAttr('signatureRadius', module.getModifiedItemAttr('signatureRadiusBonus'))
|
||||
@@ -10045,8 +10045,6 @@ class Effect3380(BaseEffect):
|
||||
fit.modules.filteredItemBoost(lambda mod: mod.item.group.name == 'Propulsion Module',
|
||||
'speedFactor', module.getModifiedItemAttr('speedFactorBonus'))
|
||||
|
||||
fit.ship.forceItemAttr('disallowAssistance', 1)
|
||||
|
||||
|
||||
class Effect3392(BaseEffect):
|
||||
"""
|
||||
@@ -23394,16 +23392,9 @@ class Effect5934(BaseEffect):
|
||||
return
|
||||
|
||||
fit.ship.increaseItemAttr('warpScrambleStatus', module.getModifiedItemAttr('warpScrambleStrength'))
|
||||
|
||||
# this is such a dirty hack
|
||||
for mod in fit.modules:
|
||||
if not mod.isEmpty and mod.state > FittingModuleState.ONLINE and (
|
||||
mod.item.requiresSkill('Micro Jump Drive Operation') or
|
||||
mod.item.requiresSkill('High Speed Maneuvering')
|
||||
):
|
||||
mod.state = FittingModuleState.ONLINE
|
||||
if not mod.isEmpty and mod.item.requiresSkill('Micro Jump Drive Operation') and mod.state > FittingModuleState.ONLINE:
|
||||
mod.state = FittingModuleState.ONLINE
|
||||
fit.modules.filteredItemIncrease(
|
||||
lambda mod: mod.item.requiresSkill('High Speed Maneuvering') or mod.item.requiresSkill('Micro Jump Drive Operation'),
|
||||
'activationBlocked', module.getModifiedItemAttr('activationBlockedStrenght'))
|
||||
|
||||
|
||||
class Effect5938(BaseEffect):
|
||||
@@ -25292,12 +25283,9 @@ class Effect6222(BaseEffect):
|
||||
def handler(fit, module, context):
|
||||
if 'projected' in context:
|
||||
fit.ship.increaseItemAttr('warpScrambleStatus', module.getModifiedItemAttr('warpScrambleStrength'))
|
||||
if module.charge is not None and module.charge.ID == 47336:
|
||||
for mod in fit.modules:
|
||||
if not mod.isEmpty and mod.item.requiresSkill('High Speed Maneuvering') and mod.state > FittingModuleState.ONLINE:
|
||||
mod.state = FittingModuleState.ONLINE
|
||||
if not mod.isEmpty and mod.item.requiresSkill('Micro Jump Drive Operation') and mod.state > FittingModuleState.ONLINE:
|
||||
mod.state = FittingModuleState.ONLINE
|
||||
fit.modules.filteredItemIncrease(
|
||||
lambda mod: mod.item.requiresSkill('High Speed Maneuvering') or mod.item.requiresSkill('Micro Jump Drive Operation'),
|
||||
'activationBlocked', module.getModifiedItemAttr('activationBlockedStrenght'))
|
||||
|
||||
|
||||
class Effect6230(BaseEffect):
|
||||
@@ -34149,6 +34137,7 @@ class Effect7026(BaseEffect):
|
||||
@staticmethod
|
||||
def handler(fit, src, context, *args, **kwargs):
|
||||
src.boostItemAttr('maxRange', src.getModifiedChargeAttr('warpScrambleRangeBonus'))
|
||||
src.forceItemAttr('activationBlockedStrenght', src.getModifiedChargeAttr('activationBlockedStrenght'))
|
||||
|
||||
|
||||
class Effect7027(BaseEffect):
|
||||
|
||||
@@ -601,7 +601,7 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
|
||||
# Check if we're within bounds
|
||||
if state < -1 or state > 2:
|
||||
return False
|
||||
elif state >= FittingModuleState.ACTIVE and not self.item.isType("active"):
|
||||
elif state >= FittingModuleState.ACTIVE and (not self.item.isType("active") or self.getModifiedItemAttr('activationBlocked') > 0):
|
||||
return False
|
||||
elif state == FittingModuleState.OVERHEATED and not self.item.isType("overheat"):
|
||||
return False
|
||||
@@ -771,28 +771,26 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
|
||||
context = ("module",)
|
||||
projected = False
|
||||
|
||||
# if gang:
|
||||
# context += ("commandRun",)
|
||||
|
||||
if self.charge is not None:
|
||||
# fix for #82 and it's regression #106
|
||||
if not projected or (self.projected and not forceProjected) or gang:
|
||||
for effect in self.charge.effects.values():
|
||||
if effect.runTime == runTime and \
|
||||
effect.activeByDefault and \
|
||||
(effect.isType("offline") or
|
||||
(effect.isType("passive") and self.state >= FittingModuleState.ONLINE) or
|
||||
(effect.isType("active") and self.state >= FittingModuleState.ACTIVE)) and \
|
||||
(not gang or (gang and effect.isType("gang"))):
|
||||
|
||||
chargeContext = ("moduleCharge",)
|
||||
# For gang effects, we pass in the effect itself as an argument. However, to avoid going through
|
||||
# all the effect files and defining this argument, do a simple try/catch here and be done with it.
|
||||
if (
|
||||
effect.runTime == runTime and
|
||||
effect.activeByDefault and (
|
||||
effect.isType("offline") or
|
||||
(effect.isType("passive") and self.state >= FittingModuleState.ONLINE) or
|
||||
(effect.isType("active") and self.state >= FittingModuleState.ACTIVE)) and
|
||||
(not gang or (gang and effect.isType("gang")))
|
||||
):
|
||||
contexts = ("moduleCharge",)
|
||||
# For gang effects, we pass in the effect itself as an argument. However, to avoid going through all
|
||||
# the effect definitions and defining this argument, do a simple try/catch here and be done with it.
|
||||
# @todo: possibly fix this
|
||||
try:
|
||||
effect.handler(fit, self, chargeContext, effect=effect)
|
||||
effect.handler(fit, self, contexts, effect=effect)
|
||||
except:
|
||||
effect.handler(fit, self, chargeContext)
|
||||
effect.handler(fit, self, contexts)
|
||||
|
||||
if self.item:
|
||||
if self.state >= FittingModuleState.OVERHEATED:
|
||||
|
||||
@@ -35,12 +35,11 @@ class ProjectItem(ContextMenuSingle):
|
||||
|
||||
def activate(self, fullContext, mainItem, i):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
category = mainItem.category.name
|
||||
if category == 'Module':
|
||||
if mainItem.isModule:
|
||||
success = self.mainFrame.command.Submit(cmd.GuiAddProjectedModuleCommand(fitID=fitID, itemID=mainItem.ID))
|
||||
elif category == 'Drone':
|
||||
elif mainItem.isDrone:
|
||||
success = self.mainFrame.command.Submit(cmd.GuiAddProjectedDroneCommand(fitID=fitID, itemID=mainItem.ID))
|
||||
elif category == 'Fighter':
|
||||
elif mainItem.isFighter:
|
||||
success = self.mainFrame.command.Submit(cmd.GuiAddProjectedFighterCommand(fitID=fitID, itemID=mainItem.ID))
|
||||
else:
|
||||
success = False
|
||||
|
||||
@@ -680,20 +680,20 @@ class FittingView(d.Display):
|
||||
change State
|
||||
"""
|
||||
|
||||
row, _, col = self.HitTestSubItem(event.Position)
|
||||
clickedRow, _, col = self.HitTestSubItem(event.Position)
|
||||
|
||||
# only do State column and ignore invalid rows
|
||||
if row != -1 and row not in self.blanks and col == self.getColIndex(State):
|
||||
sel = []
|
||||
curr = self.GetFirstSelected()
|
||||
if clickedRow != -1 and clickedRow not in self.blanks and col == self.getColIndex(State):
|
||||
selectedRows = []
|
||||
currentRow = self.GetFirstSelected()
|
||||
|
||||
while curr != -1 and row not in self.blanks:
|
||||
sel.append(curr)
|
||||
curr = self.GetNextSelected(curr)
|
||||
while currentRow != -1 and clickedRow not in self.blanks:
|
||||
selectedRows.append(currentRow)
|
||||
currentRow = self.GetNextSelected(currentRow)
|
||||
|
||||
if row not in sel:
|
||||
if clickedRow not in selectedRows:
|
||||
try:
|
||||
selectedMods = [self.mods[row]]
|
||||
selectedMods = [self.mods[clickedRow]]
|
||||
except IndexError:
|
||||
return
|
||||
else:
|
||||
@@ -702,7 +702,7 @@ class FittingView(d.Display):
|
||||
click = "ctrl" if event.GetModifiers() == wx.MOD_CONTROL or event.middleIsDown else "right" if event.GetButton() == 3 else "left"
|
||||
|
||||
try:
|
||||
mainMod = self.mods[row]
|
||||
mainMod = self.mods[clickedRow]
|
||||
except IndexError:
|
||||
return
|
||||
if mainMod.isEmpty:
|
||||
@@ -726,7 +726,7 @@ class FittingView(d.Display):
|
||||
click=click))
|
||||
|
||||
# update state tooltip
|
||||
tooltip = self.activeColumns[col].getToolTip(self.mods[row])
|
||||
tooltip = self.activeColumns[col].getToolTip(self.mods[clickedRow])
|
||||
if tooltip:
|
||||
self.SetToolTip(tooltip)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from gui.fitCommands.helpers import restoreCheckedStates
|
||||
from service.fit import Fit
|
||||
from service.market import Market
|
||||
|
||||
@@ -18,10 +19,12 @@ class CalcChangeModuleChargesCommand(wx.Command):
|
||||
self.chargeMap = chargeMap
|
||||
self.commit = commit
|
||||
self.savedChargeMap = None
|
||||
self.savedStateCheckChanges = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing change of module charges according to map {} on fit {}'.format(self.chargeMap, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.fitID)
|
||||
container = fit.modules if not self.projected else fit.projectedModules
|
||||
changes = False
|
||||
self.savedChargeMap = {}
|
||||
@@ -46,6 +49,8 @@ class CalcChangeModuleChargesCommand(wx.Command):
|
||||
mod.charge = chargeItem
|
||||
if not changes:
|
||||
return False
|
||||
sFit.recalc(fit)
|
||||
self.savedStateCheckChanges = sFit.checkStates(fit, None)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
@@ -57,4 +62,7 @@ class CalcChangeModuleChargesCommand(wx.Command):
|
||||
projected=self.projected,
|
||||
chargeMap=self.savedChargeMap,
|
||||
commit=self.commit)
|
||||
return cmd.Do()
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
return True
|
||||
|
||||
@@ -41,9 +41,17 @@ class CalcAddLocalModuleCommand(wx.Command):
|
||||
fitID=self.fitID,
|
||||
position=fit.modules.index(oldMod),
|
||||
newModInfo=self.newModInfo,
|
||||
commit=self.commit)
|
||||
return self.subsystemCmd.Do()
|
||||
|
||||
commit=False)
|
||||
if not self.subsystemCmd.Do():
|
||||
return False
|
||||
# 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.savedStateCheckChanges = sFit.checkStates(fit, newMod)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
if not newMod.fits(fit):
|
||||
pyfalog.warning('Module does not fit')
|
||||
return False
|
||||
@@ -68,12 +76,19 @@ class CalcAddLocalModuleCommand(wx.Command):
|
||||
pyfalog.debug('Undoing addition of local module {} to fit {}'.format(self.newModInfo, self.fitID))
|
||||
# We added a subsystem module, which actually ran the replace command. Run the undo for that guy instead
|
||||
if self.subsystemCmd is not None:
|
||||
return self.subsystemCmd.Undo()
|
||||
if not self.subsystemCmd.Undo():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
if self.savedPosition is None:
|
||||
return False
|
||||
from .localRemove import CalcRemoveLocalModulesCommand
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.savedPosition], commit=self.commit)
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.savedPosition], commit=False)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
@@ -49,9 +49,6 @@ class CalcChangeLocalModuleStatesCommand(wx.Command):
|
||||
changed = True
|
||||
if not changed:
|
||||
return False
|
||||
# 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.savedStateCheckChanges = sFit.checkStates(fit, mainMod)
|
||||
eos.db.commit()
|
||||
|
||||
@@ -48,8 +48,9 @@ class CalcCloneLocalModuleCommand(wx.Command):
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing cloning of local module from position {} to position {} for fit ID {}'.format(self.srcPosition, self.dstPosition, self.fitID))
|
||||
from .localRemove import CalcRemoveLocalModulesCommand
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.dstPosition])
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.dstPosition], commit=False)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
@@ -31,6 +31,9 @@ class CalcRemoveLocalModulesCommand(wx.Command):
|
||||
self.savedModInfos[position] = ModuleInfo.fromModule(mod)
|
||||
fit.modules.free(position)
|
||||
|
||||
if len(self.savedModInfos) == 0:
|
||||
return False
|
||||
|
||||
# Need to flush because checkStates sometimes relies on module->fit
|
||||
# relationship via .owner attribute, which is handled by SQLAlchemy
|
||||
eos.db.flush()
|
||||
@@ -39,7 +42,7 @@ class CalcRemoveLocalModulesCommand(wx.Command):
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
# If no modules were removed, report that command was not completed
|
||||
return len(self.savedModInfos) > 0
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing removal of local modules {} on fit {}'.format(self.savedModInfos, self.fitID))
|
||||
@@ -47,7 +50,8 @@ class CalcRemoveLocalModulesCommand(wx.Command):
|
||||
from .localReplace import CalcReplaceLocalModuleCommand
|
||||
for position, modInfo in self.savedModInfos.items():
|
||||
# Do not commit in any case to not worsen performance, we will commit later anyway
|
||||
cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=modInfo, commit=False)
|
||||
cmd = CalcReplaceLocalModuleCommand(
|
||||
fitID=self.fitID, position=position, newModInfo=modInfo, commit=False)
|
||||
results.append(cmd.Do())
|
||||
if not any(results):
|
||||
return False
|
||||
|
||||
@@ -74,11 +74,12 @@ class CalcReplaceLocalModuleCommand(wx.Command):
|
||||
# Remove if there was no module
|
||||
if self.oldModInfo is None:
|
||||
from .localRemove import CalcRemoveLocalModulesCommand
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.position], commit=self.commit)
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.position], commit=False)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
sFit.recalc(fit)
|
||||
restoreCheckedStates(fit, self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
# Replace if there was
|
||||
oldMod = self.oldModInfo.toModule()
|
||||
@@ -95,7 +96,6 @@ class CalcReplaceLocalModuleCommand(wx.Command):
|
||||
pyfalog.warning('Failed to replace in list')
|
||||
self.Do()
|
||||
return False
|
||||
sFit.recalc(fit)
|
||||
restoreCheckedStates(fit, self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
|
||||
@@ -4,6 +4,7 @@ from logbook import Logger
|
||||
import eos.db
|
||||
from eos.const import FittingModuleState
|
||||
from eos.exception import HandledListActionError
|
||||
from gui.fitCommands.helpers import restoreCheckedStates
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
@@ -20,6 +21,7 @@ class CalcAddProjectedModuleCommand(wx.Command):
|
||||
self.commit = commit
|
||||
self.oldModInfo = None
|
||||
self.oldPosition = None
|
||||
self.savedStateCheckChanges = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing addition of projected module {} onto: {}'.format(self.newModInfo, self.fitID))
|
||||
@@ -27,7 +29,8 @@ class CalcAddProjectedModuleCommand(wx.Command):
|
||||
if newMod is None:
|
||||
return False
|
||||
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.fitID)
|
||||
if not newMod.canHaveState(newMod.state, projectedOnto=fit):
|
||||
newMod.state = FittingModuleState.OFFLINE
|
||||
if not newMod.isValidCharge(newMod.charge):
|
||||
@@ -50,6 +53,11 @@ class CalcAddProjectedModuleCommand(wx.Command):
|
||||
return False
|
||||
self.newPosition = fit.projectedModules.index(newMod)
|
||||
|
||||
# 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.savedStateCheckChanges = sFit.checkStates(fit, newMod)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
@@ -61,11 +69,21 @@ class CalcAddProjectedModuleCommand(wx.Command):
|
||||
fitID=self.fitID,
|
||||
modInfo=self.oldModInfo,
|
||||
position=self.oldPosition,
|
||||
commit=self.commit)
|
||||
return cmd.Do()
|
||||
commit=False)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
from .projectedRemove import CalcRemoveProjectedModuleCommand
|
||||
cmd = CalcRemoveProjectedModuleCommand(
|
||||
fitID=self.fitID,
|
||||
position=self.newPosition,
|
||||
commit=self.commit)
|
||||
return cmd.Do()
|
||||
commit=False)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
@@ -2,9 +2,9 @@ import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from eos.const import FittingModuleState
|
||||
from eos.saveddata.module import Module
|
||||
from gui.fitCommands.helpers import restoreCheckedStates
|
||||
from eos.const import FittingModuleState
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
@@ -45,9 +45,6 @@ class CalcChangeProjectedModuleStatesCommand(wx.Command):
|
||||
changed = True
|
||||
if not changed:
|
||||
return False
|
||||
# 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.savedStateCheckChanges = sFit.checkStates(fit, None)
|
||||
if self.commit:
|
||||
|
||||
@@ -2,8 +2,8 @@ import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates
|
||||
from service.fit import Fit
|
||||
from gui.fitCommands.helpers import ModuleInfo
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
@@ -17,13 +17,21 @@ class CalcRemoveProjectedModuleCommand(wx.Command):
|
||||
self.position = position
|
||||
self.commit = commit
|
||||
self.savedModInfo = None
|
||||
self.savedStateCheckChanges = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing removal of projected module from position {} on fit {}'.format(self.position, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.fitID)
|
||||
mod = fit.projectedModules[self.position]
|
||||
self.savedModInfo = ModuleInfo.fromModule(mod)
|
||||
del fit.projectedModules[self.position]
|
||||
|
||||
# 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.savedStateCheckChanges = sFit.checkStates(fit, None)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
@@ -35,5 +43,10 @@ class CalcRemoveProjectedModuleCommand(wx.Command):
|
||||
fitID=self.fitID,
|
||||
modInfo=self.savedModInfo,
|
||||
position=self.position,
|
||||
commit=self.commit)
|
||||
return cmd.Do()
|
||||
commit=False)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
@@ -2,6 +2,7 @@ import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from gui.fitCommands.helpers import restoreCheckedStates
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
@@ -18,6 +19,7 @@ class CalcAddProjectedFitCommand(wx.Command):
|
||||
self.state = state
|
||||
self.commit = commit
|
||||
self.changeAmountCommand = None
|
||||
self.savedStateCheckChanges = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing addition of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
|
||||
@@ -39,8 +41,14 @@ class CalcAddProjectedFitCommand(wx.Command):
|
||||
projectedFitID=self.projectedFitID,
|
||||
amount=self.amount,
|
||||
relative=True,
|
||||
commit=self.commit)
|
||||
return self.changeAmountCommand.Do()
|
||||
commit=False)
|
||||
if not self.changeAmountCommand.Do():
|
||||
return False
|
||||
sFit.recalc(fit)
|
||||
self.savedStateCheckChanges = sFit.checkStates(fit, None)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
else:
|
||||
self.changeAmountCommand = None
|
||||
|
||||
@@ -60,6 +68,8 @@ class CalcAddProjectedFitCommand(wx.Command):
|
||||
if self.state is not None:
|
||||
projectionInfo.active = self.state
|
||||
|
||||
sFit.recalc(fit)
|
||||
self.savedStateCheckChanges = sFit.checkStates(fit, None)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
@@ -67,16 +77,25 @@ class CalcAddProjectedFitCommand(wx.Command):
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing addition of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
|
||||
if self.changeAmountCommand is not None:
|
||||
return self.changeAmountCommand.Undo()
|
||||
if not self.changeAmountCommand.Undo():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
# Can't find the projected fit, it must have been deleted. Just skip, as deleted fit
|
||||
# means that someone else just did exactly what we wanted to do
|
||||
projectedFit = Fit.getInstance().getFit(self.projectedFitID, projected=True)
|
||||
if projectedFit is None:
|
||||
return True
|
||||
from .remove import CalcRemoveProjectedFitCommand
|
||||
cmd = CalcRemoveProjectedFitCommand(
|
||||
fitID=self.fitID,
|
||||
projectedFitID=self.projectedFitID,
|
||||
amount=self.amount,
|
||||
commit=self.commit)
|
||||
return cmd.Do()
|
||||
if projectedFit is not None:
|
||||
from .remove import CalcRemoveProjectedFitCommand
|
||||
cmd = CalcRemoveProjectedFitCommand(
|
||||
fitID=self.fitID,
|
||||
projectedFitID=self.projectedFitID,
|
||||
amount=self.amount,
|
||||
commit=False)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
@@ -2,6 +2,7 @@ import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from gui.fitCommands.helpers import restoreCheckedStates
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
@@ -17,11 +18,13 @@ class CalcChangeProjectedFitStateCommand(wx.Command):
|
||||
self.state = state
|
||||
self.commit = commit
|
||||
self.savedState = None
|
||||
self.savedStateCheckChanges = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing changing of projected fit {} state to {} for fit {}'.format(
|
||||
self.projectedFitID, self.state, self.fitID))
|
||||
projectedFit = Fit.getInstance().getFit(self.projectedFitID, projected=True)
|
||||
sFit = Fit.getInstance()
|
||||
projectedFit = sFit.getFit(self.projectedFitID, projected=True)
|
||||
# Projected fit could have been deleted if we are redoing
|
||||
if projectedFit is None:
|
||||
pyfalog.debug('Projected fit is not available')
|
||||
@@ -37,6 +40,9 @@ class CalcChangeProjectedFitStateCommand(wx.Command):
|
||||
|
||||
projectionInfo.active = self.state
|
||||
|
||||
fit = sFit.getFit(self.fitID)
|
||||
sFit.recalc(fit)
|
||||
self.savedStateCheckChanges = sFit.checkStates(fit, None)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
@@ -48,5 +54,10 @@ class CalcChangeProjectedFitStateCommand(wx.Command):
|
||||
fitID=self.fitID,
|
||||
projectedFitID=self.projectedFitID,
|
||||
state=self.savedState,
|
||||
commit=self.commit)
|
||||
return cmd.Do()
|
||||
commit=False)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
@@ -2,6 +2,7 @@ import wx
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from gui.fitCommands.helpers import restoreCheckedStates
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
@@ -19,6 +20,7 @@ class CalcRemoveProjectedFitCommand(wx.Command):
|
||||
self.savedState = None
|
||||
self.savedAmount = None
|
||||
self.changeAmountCommand = None
|
||||
self.savedStateCheckChanges = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing removal of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
|
||||
@@ -47,14 +49,22 @@ class CalcRemoveProjectedFitCommand(wx.Command):
|
||||
fitID=self.fitID,
|
||||
projectedFitID=self.projectedFitID,
|
||||
amount=remainingAmount,
|
||||
commit=self.commit)
|
||||
return self.changeAmountCommand.Do()
|
||||
commit=False)
|
||||
if not self.changeAmountCommand.Do():
|
||||
return False
|
||||
sFit.recalc(fit)
|
||||
self.savedStateCheckChanges = sFit.checkStates(fit, None)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
else:
|
||||
self.changeAmountCommand = None
|
||||
if projectedFit.ID not in fit.projectedFitDict:
|
||||
pyfalog.warning('Unable to find projected fit in projected dict')
|
||||
return False
|
||||
del fit.projectedFitDict[projectedFit.ID]
|
||||
sFit.recalc(fit)
|
||||
self.savedStateCheckChanges = sFit.checkStates(fit, None)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
@@ -62,12 +72,22 @@ class CalcRemoveProjectedFitCommand(wx.Command):
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing removal of projected fit {} for fit {}'.format(self.projectedFitID, self.fitID))
|
||||
if self.changeAmountCommand is not None:
|
||||
return self.changeAmountCommand.Undo()
|
||||
if not self.changeAmountCommand.Undo():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
from .add import CalcAddProjectedFitCommand
|
||||
cmd = CalcAddProjectedFitCommand(
|
||||
fitID=self.fitID,
|
||||
projectedFitID=self.projectedFitID,
|
||||
amount=self.savedAmount,
|
||||
state=self.savedState,
|
||||
commit=self.commit)
|
||||
return cmd.Do()
|
||||
commit=False)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user