Rework projected removal command to be able to handle multi-selection

This commit is contained in:
DarkPhoenix
2019-04-27 23:27:16 +03:00
parent e865c9a399
commit e39f9ffecf
17 changed files with 180 additions and 229 deletions

View File

@@ -82,7 +82,7 @@ class ProjectedView(d.Display):
self.mainFrame.Bind(GE.FIT_CHANGED, self.fitChanged)
self.Bind(wx.EVT_LEFT_DOWN, self.click)
self.Bind(wx.EVT_RIGHT_DOWN, self.click)
self.Bind(wx.EVT_LEFT_DCLICK, self.remove)
self.Bind(wx.EVT_LEFT_DCLICK, self.onLeftDoubleClick)
self.Bind(wx.EVT_KEY_UP, self.kbEvent)
self.droneView = gui.builtinAdditionPanes.droneView.DroneView
@@ -124,24 +124,8 @@ class ProjectedView(d.Display):
if row != -1:
fitID = self.mainFrame.getActiveFit()
thing = self.get(row)
if isinstance(thing, es_Fit):
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFitCommand(
fitID=fitID, projectedFitID=thing.ID, amount=math.inf))
elif isinstance(thing, es_Module):
fit = Fit.getInstance().getFit(fitID)
if thing in fit.projectedModules:
position = fit.projectedModules.index(thing)
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedModuleCommand(
fitID=fitID, position=position))
elif isinstance(thing, es_Drone):
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedDroneCommand(
fitID=fitID, itemID=thing.itemID, amount=math.inf))
elif isinstance(thing, es_Fighter):
fit = Fit.getInstance().getFit(fitID)
if thing in fit.projectedFighters:
position = fit.projectedFighters.index(thing)
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFighterCommand(
fitID=fitID, position=position))
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand(
fitID=fitID, items=[thing], amount=math.inf))
def handleDrag(self, type, fitID):
# Those are drags coming from pyfa sources, NOT builtin wx drags
@@ -328,32 +312,12 @@ class ProjectedView(d.Display):
if menu is not None:
self.PopupMenu(menu)
def remove(self, event):
def onLeftDoubleClick(self, event):
row, _ = self.HitTest(event.Position)
if row != -1:
col = self.getColumn(event.Position)
if col != self.getColIndex(State):
fitID = self.mainFrame.getActiveFit()
thing = self.get(row)
if isinstance(thing, es_Fit):
amount = math.inf if wx.GetMouseState().GetModifiers() == wx.MOD_ALT else 1
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFitCommand(
fitID=fitID, projectedFitID=thing.ID, amount=amount))
elif isinstance(thing, es_Module):
fit = Fit.getInstance().getFit(fitID)
if thing in fit.projectedModules:
position = fit.projectedModules.index(thing)
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedModuleCommand(
fitID=fitID, position=position))
elif isinstance(thing, es_Drone):
mstate = wx.GetMouseState()
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedDroneCommand(
fitID=fitID,
itemID=thing.itemID,
amount=math.inf if mstate.GetModifiers() == wx.MOD_ALT else 1))
elif isinstance(thing, es_Fighter):
fit = Fit.getInstance().getFit(fitID)
if thing in fit.projectedFighters:
position = fit.projectedFighters.index(thing)
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFighterCommand(
fitID=fitID, position=position))
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand(
fitID=self.mainFrame.getActiveFit(),
items=[self.get(row)],
amount=math.inf if wx.GetMouseState().GetModifiers() == wx.MOD_ALT else 1))

View File

@@ -45,10 +45,10 @@ class RemoveItem(ContextMenuCombined):
'implantItem': self.__handleImplant,
'boosterItem': self.__handleBooster,
'cargoItem': self.__handleCargo,
'projectedFit': self.__handleProjectedFit,
'projectedModule': self.__handleProjectedModule,
'projectedDrone': self.__handleProjectedDrone,
'projectedFighter': self.__handleProjectedFighter,
'projectedFit': self.__handleProjectedItem,
'projectedModule': self.__handleProjectedItem,
'projectedDrone': self.__handleProjectedItem,
'projectedFighter': self.__handleProjectedItem,
'commandFit': self.__handleCommandFit}
srcContext = fullContext[0]
handler = handlerMap.get(srcContext)
@@ -119,31 +119,11 @@ class RemoveItem(ContextMenuCombined):
self.mainFrame.command.Submit(cmd.GuiRemoveCargosCommand(
fitID=fitID, itemIDs=itemIDs))
def __handleProjectedFit(self, mainItem, selection):
fitID = self.mainFrame.getActiveFit()
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFitCommand(
fitID=fitID, projectedFitID=mainItem.ID, amount=math.inf))
def __handleProjectedModule(self, mainItem, selection):
def __handleProjectedItem(self, mainItem, selection):
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
if mainItem in fit.projectedModules:
position = fit.projectedModules.index(mainItem)
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedModuleCommand(
fitID=fitID, position=position))
def __handleProjectedDrone(self, mainItem, selection):
fitID = self.mainFrame.getActiveFit()
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedDroneCommand(
fitID=fitID, itemID=mainItem.itemID, amount=math.inf))
def __handleProjectedFighter(self, mainItem, selection):
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
if mainItem in fit.projectedFighters:
position = fit.projectedFighters.index(mainItem)
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedFighterCommand(
fitID=fitID, position=position))
self.mainFrame.command.Submit(cmd.GuiRemoveProjectedItemsCommand(
fitID=fitID, items=[mainItem], amount=math.inf))
def __handleCommandFit(self, mainItem, selection):
fitID = self.mainFrame.getActiveFit()

View File

@@ -50,22 +50,19 @@ from .gui.localModuleCargo.localModuleToCargo import GuiLocalModuleToCargoComman
from .gui.projectedDrone.add import GuiAddProjectedDroneCommand
from .gui.projectedDrone.changeAmount import GuiChangeProjectedDroneAmountCommand
from .gui.projectedDrone.changeMeta import GuiChangeProjectedDroneMetaCommand
from .gui.projectedDrone.remove import GuiRemoveProjectedDroneCommand
from .gui.projectedDrone.toggleState import GuiToggleProjectedDroneStateCommand
from .gui.projectedFighter.abilityToggleState import GuiToggleProjectedFighterAbilityStateCommand
from .gui.projectedFighter.add import GuiAddProjectedFighterCommand
from .gui.projectedFighter.changeAmount import GuiChangeProjectedFighterAmountCommand
from .gui.projectedFighter.changeMeta import GuiChangeProjectedFighterMetaCommand
from .gui.projectedFighter.remove import GuiRemoveProjectedFighterCommand
from .gui.projectedFighter.toggleStates import GuiToggleProjectedFighterStatesCommand
from .gui.projectedFit.add import GuiAddProjectedFitCommand
from .gui.projectedFit.changeAmount import GuiChangeProjectedFitAmountCommand
from .gui.projectedFit.remove import GuiRemoveProjectedFitCommand
from .gui.projectedFit.toggleState import GuiToggleProjectedFitStateCommand
from .gui.projectedModule.add import GuiAddProjectedModuleCommand
from .gui.projectedModule.changeCharges import GuiChangeProjectedModuleChargesCommand
from .gui.projectedModule.changeMeta import GuiChangeProjectedModuleMetaCommand
from .gui.projectedModule.changeSpool import GuiChangeProjectedModuleSpoolCommand
from .gui.projectedModule.changeState import GuiChangeProjectedModuleStateCommand
from .gui.projectedModule.remove import GuiRemoveProjectedModuleCommand
from .gui.projectedRemove import GuiRemoveProjectedItemsCommand
from .gui.shipModeChange import GuiChangeShipModeCommand

View File

@@ -14,10 +14,11 @@ pyfalog = Logger(__name__)
class CalcAddProjectedDroneCommand(wx.Command):
def __init__(self, fitID, droneInfo):
def __init__(self, fitID, droneInfo, commit=True):
wx.Command.__init__(self, True, 'Add Projected Drone')
self.fitID = fitID
self.droneInfo = droneInfo
self.commit = commit
self.savedDroneInfo = None
def Do(self):
@@ -32,7 +33,8 @@ class CalcAddProjectedDroneCommand(wx.Command):
drone.amount += self.droneInfo.amount
if drone.amountActive > 0:
drone.amountActive += self.droneInfo.amount
eos.db.commit()
if self.commit:
eos.db.commit()
return True
# Making new stack
drone = self.droneInfo.toDrone()
@@ -45,9 +47,11 @@ class CalcAddProjectedDroneCommand(wx.Command):
fit.projectedDrones.append(drone)
except HandledListActionError:
pyfalog.warning('Failed to append to list')
eos.db.commit()
if self.commit:
eos.db.commit()
return False
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
@@ -61,8 +65,14 @@ class CalcAddProjectedDroneCommand(wx.Command):
return False
drone.amount = self.savedDroneInfo.amount
drone.amountActive = self.savedDroneInfo.amountActive
if self.commit:
eos.db.commit()
return True
# Removing previously added stack
from .projectedRemove import CalcRemoveProjectedDroneCommand
cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=self.droneInfo.itemID, amount=math.inf)
cmd = CalcRemoveProjectedDroneCommand(
fitID=self.fitID,
itemID=self.droneInfo.itemID,
amount=math.inf,
commit=self.commit)
return cmd.Do()

View File

@@ -11,11 +11,12 @@ pyfalog = Logger(__name__)
class CalcRemoveProjectedDroneCommand(wx.Command):
def __init__(self, fitID, itemID, amount):
def __init__(self, fitID, itemID, amount, commit=True):
wx.Command.__init__(self, True, 'Remove Projected Drone')
self.fitID = fitID
self.itemID = itemID
self.amountToRemove = amount
self.commit = commit
self.savedDroneInfo = None
def Do(self):
@@ -33,7 +34,8 @@ class CalcRemoveProjectedDroneCommand(wx.Command):
else:
if drone.amountActive > 0:
drone.amountActive = min(drone.amountActive, drone.amount)
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
@@ -44,8 +46,10 @@ class CalcRemoveProjectedDroneCommand(wx.Command):
if drone is not None:
drone.amount = self.savedDroneInfo.amount
drone.amountActive = self.savedDroneInfo.amountActive
if self.commit:
eos.db.commit()
return True
# Make new stack
from .projectedAdd import CalcAddProjectedDroneCommand
cmd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=self.savedDroneInfo)
cmd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=self.savedDroneInfo, commit=self.commit)
return cmd.Do()

View File

@@ -11,11 +11,12 @@ pyfalog = Logger(__name__)
class CalcAddProjectedFighterCommand(wx.Command):
def __init__(self, fitID, fighterInfo, position=None):
def __init__(self, fitID, fighterInfo, position=None, commit=True):
wx.Command.__init__(self, True, 'Add Projected Fighter')
self.fitID = fitID
self.fighterInfo = fighterInfo
self.position = position
self.commit = commit
def Do(self):
pyfalog.debug('Doing addition of projected fighter {} onto: {}'.format(self.fighterInfo, self.fitID))
@@ -27,20 +28,23 @@ class CalcAddProjectedFighterCommand(wx.Command):
try:
fit.projectedFighters.insert(self.position, fighter)
except HandledListActionError:
eos.db.commit()
if self.commit:
eos.db.commit()
return False
else:
try:
fit.projectedFighters.append(fighter)
except HandledListActionError:
eos.db.commit()
if self.commit:
eos.db.commit()
return False
self.position = fit.projectedFighters.index(fighter)
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
pyfalog.debug('Undoing addition of projected fighter {} onto: {}'.format(self.fighterInfo, self.fitID))
from .projectedRemove import CalcRemoveProjectedFighterCommand
cmd = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=self.position)
cmd = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=self.position, commit=self.commit)
return cmd.Do()

View File

@@ -11,10 +11,11 @@ pyfalog = Logger(__name__)
class CalcRemoveProjectedFighterCommand(wx.Command):
def __init__(self, fitID, position):
def __init__(self, fitID, position, commit=True):
wx.Command.__init__(self, True, 'Add Projected Fighter')
self.fitID = fitID
self.position = position
self.commit = commit
self.savedFighterInfo = None
def Do(self):
@@ -23,11 +24,12 @@ class CalcRemoveProjectedFighterCommand(wx.Command):
fighter = fit.projectedFighters[self.position]
self.savedFighterInfo = FighterInfo.fromFighter(fighter)
fit.projectedFighters.remove(fighter)
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
pyfalog.debug('Undoing removal of projected fighter at position {} from fit {}'.format(self.position, self.fitID))
from .projectedAdd import CalcAddProjectedFighterCommand
cmd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=self.savedFighterInfo)
cmd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=self.savedFighterInfo, commit=self.commit)
return cmd.Do()

View File

@@ -12,11 +12,12 @@ pyfalog = Logger(__name__)
class CalcAddProjectedModuleCommand(wx.Command):
def __init__(self, fitID, modInfo, position=None):
def __init__(self, fitID, modInfo, position=None, commit=True):
wx.Command.__init__(self, True)
self.fitID = fitID
self.newModInfo = modInfo
self.newPosition = position
self.commit = commit
self.oldModInfo = None
self.oldPosition = None
@@ -36,24 +37,34 @@ class CalcAddProjectedModuleCommand(wx.Command):
try:
fit.projectedModules.insert(self.newPosition, newMod)
except HandledListActionError:
eos.db.commit()
if self.commit:
eos.db.commit()
return False
else:
try:
fit.projectedModules.append(newMod)
except HandledListActionError:
eos.db.commit()
if self.commit:
eos.db.commit()
return False
self.newPosition = fit.projectedModules.index(newMod)
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
pyfalog.debug('Undoing addition of projected module {} onto: {}'.format(self.newModInfo, self.fitID))
if self.oldPosition is not None and self.oldModInfo is not None:
cmd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=self.oldModInfo, position=self.oldPosition)
cmd = CalcAddProjectedModuleCommand(
fitID=self.fitID,
modInfo=self.oldModInfo,
position=self.oldPosition,
commit=self.commit)
return cmd.Do()
from .projectedRemove import CalcRemoveProjectedModuleCommand
cmd = CalcRemoveProjectedModuleCommand(self.fitID, self.newPosition)
cmd = CalcRemoveProjectedModuleCommand(
fitID=self.fitID,
position=self.newPosition,
commit=self.commit)
return cmd.Do()

View File

@@ -11,10 +11,11 @@ pyfalog = Logger(__name__)
class CalcRemoveProjectedModuleCommand(wx.Command):
def __init__(self, fitID, position):
def __init__(self, fitID, position, commit=True):
wx.Command.__init__(self, True)
self.fitID = fitID
self.position = position
self.commit = commit
self.savedModInfo = None
def Do(self):
@@ -23,11 +24,16 @@ class CalcRemoveProjectedModuleCommand(wx.Command):
mod = fit.projectedModules[self.position]
self.savedModInfo = ModuleInfo.fromModule(mod)
del fit.projectedModules[self.position]
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
pyfalog.debug('Undoing removal of projected module {} on fit {}'.format(self.savedModInfo, self.fitID))
from .projectedAdd import CalcAddProjectedModuleCommand
cmd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=self.savedModInfo, position=self.position)
cmd = CalcAddProjectedModuleCommand(
fitID=self.fitID,
modInfo=self.savedModInfo,
position=self.position,
commit=self.commit)
return cmd.Do()

View File

@@ -10,12 +10,13 @@ pyfalog = Logger(__name__)
class CalcAddProjectedFitCommand(wx.Command):
def __init__(self, fitID, projectedFitID, amount, state=None):
def __init__(self, fitID, projectedFitID, amount, state=None, commit=True):
wx.Command.__init__(self, True, 'Add Projected Fit')
self.fitID = fitID
self.projectedFitID = projectedFitID
self.amount = amount
self.state = state
self.commit = commit
self.changeAmountCommand = None
def Do(self):
@@ -34,7 +35,11 @@ class CalcAddProjectedFitCommand(wx.Command):
if projectedFit in fit.projectedFits and projectedFit.ID in fit.projectedFitDict:
from .changeAmount import CalcChangeProjectedFitAmountCommand
self.changeAmountCommand = CalcChangeProjectedFitAmountCommand(
fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount, relative=True)
fitID=self.fitID,
projectedFitID=self.projectedFitID,
amount=self.amount,
relative=True,
commit=self.commit)
return self.changeAmountCommand.Do()
else:
self.changeAmountCommand = None
@@ -55,7 +60,8 @@ class CalcAddProjectedFitCommand(wx.Command):
if self.state is not None:
projectionInfo.active = self.state
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
@@ -68,5 +74,9 @@ class CalcAddProjectedFitCommand(wx.Command):
if projectedFit is None:
return True
from .remove import CalcRemoveProjectedFitCommand
cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount)
cmd = CalcRemoveProjectedFitCommand(
fitID=self.fitID,
projectedFitID=self.projectedFitID,
amount=self.amount,
commit=self.commit)
return cmd.Do()

View File

@@ -10,12 +10,13 @@ pyfalog = Logger(__name__)
class CalcChangeProjectedFitAmountCommand(wx.Command):
def __init__(self, fitID, projectedFitID, amount, relative=False):
def __init__(self, fitID, projectedFitID, amount, relative=False, commit=True):
wx.Command.__init__(self, True, 'Change Projected Fit Amount')
self.fitID = fitID
self.projectedFitID = projectedFitID
self.amount = amount
self.relative = relative
self.commit = commit
self.savedAmount = None
def Do(self):
@@ -39,10 +40,15 @@ class CalcChangeProjectedFitAmountCommand(wx.Command):
if confinedAmount == self.savedAmount:
return False
projectionInfo.amount = confinedAmount
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
pyfalog.debug('Undoing change of projected fit {} amount to {} for fit {}'.format(self.projectedFitID, self.amount, self.fitID))
cmd = CalcChangeProjectedFitAmountCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.savedAmount)
cmd = CalcChangeProjectedFitAmountCommand(
fitID=self.fitID,
projectedFitID=self.projectedFitID,
amount=self.savedAmount,
commit=self.commit)
return cmd.Do()

View File

@@ -10,11 +10,12 @@ pyfalog = Logger(__name__)
class CalcRemoveProjectedFitCommand(wx.Command):
def __init__(self, fitID, projectedFitID, amount):
def __init__(self, fitID, projectedFitID, amount, commit=True):
wx.Command.__init__(self, True, 'Add Projected Fit')
self.fitID = fitID
self.projectedFitID = projectedFitID
self.amount = amount
self.commit = commit
self.savedState = None
self.savedAmount = None
self.changeAmountCommand = None
@@ -43,7 +44,10 @@ class CalcRemoveProjectedFitCommand(wx.Command):
if remainingAmount > 0:
from .changeAmount import CalcChangeProjectedFitAmountCommand
self.changeAmountCommand = CalcChangeProjectedFitAmountCommand(
fitID=self.fitID, projectedFitID=self.projectedFitID, amount=remainingAmount)
fitID=self.fitID,
projectedFitID=self.projectedFitID,
amount=remainingAmount,
commit=self.commit)
return self.changeAmountCommand.Do()
else:
self.changeAmountCommand = None
@@ -51,7 +55,8 @@ class CalcRemoveProjectedFitCommand(wx.Command):
pyfalog.warning('Unable to find projected fit in projected dict')
return False
del fit.projectedFitDict[projectedFit.ID]
eos.db.commit()
if self.commit:
eos.db.commit()
return True
def Undo(self):
@@ -63,5 +68,6 @@ class CalcRemoveProjectedFitCommand(wx.Command):
fitID=self.fitID,
projectedFitID=self.projectedFitID,
amount=self.savedAmount,
state=self.savedState)
state=self.savedState,
commit=self.commit)
return cmd.Do()

View File

@@ -1,30 +0,0 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.drone.projectedRemove import CalcRemoveProjectedDroneCommand
from gui.fitCommands.helpers import DroneInfo, InternalCommandHistory
from service.fit import Fit
class GuiRemoveProjectedDroneCommand(wx.Command):
def __init__(self, fitID, itemID, amount):
wx.Command.__init__(self, True, 'Remove Projected Drone')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.itemID = itemID
self.amount = amount
def Do(self):
cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=self.itemID, amount=self.amount)
success = self.internalHistory.submit(cmd)
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -1,29 +0,0 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.fighter.projectedRemove import CalcRemoveProjectedFighterCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiRemoveProjectedFighterCommand(wx.Command):
def __init__(self, fitID, position):
wx.Command.__init__(self, True, 'Remove Projected Fighter')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
def Do(self):
cmd = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=self.position)
success = self.internalHistory.submit(cmd)
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -1,30 +0,0 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.projectedFit.remove import CalcRemoveProjectedFitCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiRemoveProjectedFitCommand(wx.Command):
def __init__(self, fitID, projectedFitID, amount):
wx.Command.__init__(self, True, 'Remove Projected Fit')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.projectedFitID = projectedFitID
self.amount = amount
def Do(self):
cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=self.projectedFitID, amount=self.amount)
success = self.internalHistory.submit(cmd)
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -1,29 +0,0 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.projectedRemove import CalcRemoveProjectedModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiRemoveProjectedModuleCommand(wx.Command):
def __init__(self, fitID, position):
wx.Command.__init__(self, True, 'Remove Projected Module')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
def Do(self):
cmd = CalcRemoveProjectedModuleCommand(fitID=self.fitID, position=self.position)
success = self.internalHistory.submit(cmd)
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -0,0 +1,69 @@
import math
import wx
import eos.db
import gui.mainFrame
from eos.saveddata.drone import Drone as EosDrone
from eos.saveddata.fighter import Fighter as EosFighter
from eos.saveddata.fit import Fit as EosFit
from eos.saveddata.module import Module as EosModule
from gui import globalEvents as GE
from gui.fitCommands.calc.drone.projectedRemove import CalcRemoveProjectedDroneCommand
from gui.fitCommands.calc.fighter.projectedRemove import CalcRemoveProjectedFighterCommand
from gui.fitCommands.calc.module.projectedRemove import CalcRemoveProjectedModuleCommand
from gui.fitCommands.calc.projectedFit.remove import CalcRemoveProjectedFitCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiRemoveProjectedItemsCommand(wx.Command):
def __init__(self, fitID, items, amount):
wx.Command.__init__(self, True, 'Remove Projected Items')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.amount = amount
self.pModPositions = []
self.pDroneItemIDs = []
self.pFighterPositions = []
self.pFitIDs = []
fit = Fit.getInstance().getFit(fitID)
for item in items:
if isinstance(item, EosModule):
if item in fit.projectedModules:
self.pModPositions.append(fit.projectedModules.index(item))
elif isinstance(item, EosDrone):
self.pDroneItemIDs.append(item.itemID)
elif isinstance(item, EosFighter):
if item in fit.projectedFighters:
self.pFighterPositions.append(fit.projectedFighters.index(item))
elif isinstance(item, EosFit):
self.pFitIDs.append(item.ID)
def Do(self):
results = []
for pModPosition in sorted(self.pModPositions, reverse=True):
cmd = CalcRemoveProjectedModuleCommand(fitID=self.fitID, position=pModPosition, commit=False)
results.append(self.internalHistory.submit(cmd))
for pDroneItemID in self.pDroneItemIDs:
cmd = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=pDroneItemID, amount=self.amount, commit=False)
results.append(self.internalHistory.submit(cmd))
for pFighterPosition in self.pFighterPositions:
cmd = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=pFighterPosition, commit=False)
results.append(self.internalHistory.submit(cmd))
for pFitID in self.pFitIDs:
cmd = CalcRemoveProjectedFitCommand(fitID=self.fitID, projectedFitID=pFitID, amount=self.amount, commit=False)
results.append(self.internalHistory.submit(cmd))
success = any(results)
eos.db.commit()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
eos.db.commit()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success