Rework local module GUI commands

This commit is contained in:
DarkPhoenix
2019-04-14 22:47:00 +03:00
parent cc8575b275
commit 0b49bf201f
30 changed files with 375 additions and 418 deletions

View File

@@ -26,7 +26,7 @@ class FillWithModule(ContextMenu):
fitID = self.mainFrame.getActiveFit()
if srcContext == "fittingModule":
self.mainFrame.command.Submit(cmd.GuiFillWithModuleCommand(fitID, selection[0].itemID))
self.mainFrame.command.Submit(cmd.GuiFillWithModulesCommand(fitID, selection[0].itemID))
return # the command takes care of the PostEvent
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))

View File

@@ -37,10 +37,10 @@ class ItemRemove(ContextMenu):
if srcContext == "fittingModule":
modules = [module for module in selection if module is not None]
self.mainFrame.command.Submit(cmd.GuiModuleRemoveCommand(fitID, modules))
self.mainFrame.command.Submit(cmd.GuiRemoveModuleCommand(fitID, modules))
return # the command takes care of the PostEvent
elif srcContext in ("fittingCharge", "projectedCharge"):
self.mainFrame.command.Submit(cmd.GuiModuleAddChargeCommand(fitID, None, selection))
self.mainFrame.command.Submit(cmd.GuiChangeModuleChargesCommand(fitID, None, selection))
return
elif srcContext == "droneItem":
self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, fit.drones.index(selection[0]), 1))

View File

@@ -228,7 +228,7 @@ class ModuleAmmoPicker(ContextMenu):
return
fitID = self.mainFrame.getActiveFit()
self.mainFrame.command.Submit(cmd.GuiModuleAddChargeCommand(fitID, charge.ID if charge is not None else None, self.modules))
self.mainFrame.command.Submit(cmd.GuiChangeModuleChargesCommand(fitID, charge.ID if charge is not None else None, self.modules))
ModuleAmmoPicker.register()

View File

@@ -38,7 +38,7 @@ class ModuleGlobalAmmoPicker(ModuleAmmoPicker):
if mod.itemID == selectedModule.itemID:
allModules.append(mod)
self.mainFrame.command.Submit(cmd.GuiModuleAddChargeCommand(fitID, charge.ID if charge is not None else None, allModules))
self.mainFrame.command.Submit(cmd.GuiChangeModuleChargesCommand(fitID, charge.ID if charge is not None else None, allModules))
def display(self, srcContext, selection):
if not self.settings.get('moduleGlobalAmmoPicker'):

View File

@@ -3,7 +3,7 @@ import wx
import gui.globalEvents as GE
import gui.mainFrame
from gui.fitCommands import GuiMutaConvertCommand, GuiMutaRevertCommand
from gui.fitCommands import GuiConvertMutatedModuleCommand, GuiRevertMutatedModuleCommand
from gui.contextMenu import ContextMenu
from service.fit import Fit
from service.settings import ContextMenuSettings
@@ -58,14 +58,14 @@ class MutaplasmidCM(ContextMenu):
def handleMenu(self, event):
mutaplasmid, mod = self.eventIDs[event.Id]
self.mainFrame.command.Submit(GuiMutaConvertCommand(
self.mainFrame.command.Submit(GuiConvertMutatedModuleCommand(
fitID=self.mainFrame.getActiveFit(),
position=mod.modPosition,
mutaplasmid=mutaplasmid))
def activate(self, fullContext, selection, i):
mod = selection[0]
self.mainFrame.command.Submit(GuiMutaRevertCommand(
self.mainFrame.command.Submit(GuiRevertMutatedModuleCommand(
fitID=self.mainFrame.getActiveFit(),
position=mod.modPosition))

View File

@@ -24,7 +24,7 @@ class SpoolUp(ContextMenu):
return False
self.mod = selection[0]
self.context = srcContext
# self.context = srcContext
return self.mod.item.group.name in ("Precursor Weapon", "Mutadaptive Remote Armor Repairer")
@@ -75,12 +75,11 @@ class SpoolUp(ContextMenu):
spoolAmount = self.cycleMap[event.Id]
else:
return
self.mainFrame.command.Submit(cmd.GuiSetSpoolupCommand(
self.mainFrame.command.Submit(cmd.GuiChangeModuleSpoolCommand(
fitID=self.mainFrame.getActiveFit(),
position=self.mod.modPosition,
spoolType=spoolType,
spoolAmount=spoolAmount,
context=self.context))
spoolAmount=spoolAmount))
SpoolUp.register()

View File

@@ -369,9 +369,9 @@ class FittingView(d.Display):
sel = self.GetNextSelected(sel)
if len(modules) > 0:
self.mainFrame.command.Submit(cmd.GuiModuleAddChargeCommand(fitID, itemID, modules))
self.mainFrame.command.Submit(cmd.GuiChangeModuleChargesCommand(fitID, itemID, modules))
else:
self.mainFrame.command.Submit(cmd.GuiModuleAddCommand(fitID, itemID))
self.mainFrame.command.Submit(cmd.GuiAddModuleCommand(fitID, itemID))
event.Skip()
@@ -393,7 +393,7 @@ class FittingView(d.Display):
if not isinstance(modules, list):
modules = [modules]
self.mainFrame.command.Submit(cmd.GuiModuleRemoveCommand(self.activeFitID, modules))
self.mainFrame.command.Submit(cmd.GuiRemoveModuleCommand(self.activeFitID, modules))
def addModule(self, x, y, itemID):
"""Add a module from the market browser (from dragging it)"""
@@ -405,7 +405,7 @@ class FittingView(d.Display):
if not isinstance(mod, Module): # make sure we're not adding something to a T3D Mode
return
self.mainFrame.command.Submit(cmd.GuiModuleAddCommand(fitID, itemID, self.mods[dstRow].modPosition))
self.mainFrame.command.Submit(cmd.GuiAddModuleCommand(fitID, itemID, self.mods[dstRow].modPosition))
def swapCargo(self, x, y, srcIdx):
"""Swap a module from cargo to fitting window"""
@@ -610,8 +610,11 @@ class FittingView(d.Display):
ctrl = event.cmdDown or event.middleIsDown
click = "ctrl" if ctrl is True else "right" if event.GetButton() == 3 else "left"
self.mainFrame.command.Submit(cmd.GuiModuleStateChangeCommand(
fitID, self.mods[self.GetItemData(row)].modPosition, [mod.modPosition for mod in mods], click))
self.mainFrame.command.Submit(cmd.GuiChangeModuleStatesCommand(
fitID=fitID,
mainPosition=self.mods[self.GetItemData(row)].modPosition,
positions=[mod.modPosition for mod in mods],
click=click))
# update state tooltip
tooltip = self.activeColumns[col].getToolTip(self.mods[self.GetItemData(row)])

View File

@@ -17,29 +17,29 @@ from .fighter.add import GuiAddFighterCommand
from .fighter.changeAmount import GuiChangeFighterAmountCommand
from .fighter.remove import GuiRemoveFighterCommand
from .fighter.toggleState import GuiToggleFighterCommand
from .guiAddCharge import GuiModuleAddChargeCommand
from .guiAddModule import GuiModuleAddCommand
from .guiAddProjected import GuiAddProjectedCommand
from .guiCargoToModule import GuiCargoToModuleCommand
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQtyCommand
from .guiChangeProjectedFighterAmount import GuiChangeProjectedFighterAmountCommand
from .guiChangeProjectedFitQty import GuiChangeProjectedFitQtyCommand
from .guiFillWithModule import GuiFillWithModuleCommand
from .guiFitRename import GuiFitRenameCommand
from .guiImportMutatedModule import GuiImportMutatedModuleCommand
from .guiMetaSwap import GuiMetaSwapCommand
from .guiModuleToCargo import GuiModuleToCargoCommand
from .guiMutaConvert import GuiMutaConvertCommand
from .guiMutaRevert import GuiMutaRevertCommand
from .guiRebaseItems import GuiRebaseItemsCommand
from .guiRemoveModule import GuiModuleRemoveCommand
from .guiRemoveProjected import GuiRemoveProjectedCommand
from .guiSetMode import GuiSetModeCommand
from .guiSetSpoolup import GuiSetSpoolupCommand
from .guiSwapCloneModule import GuiModuleSwapOrCloneCommand
from .guiToggleModuleState import GuiModuleStateChangeCommand
from .guiToggleProjected import GuiToggleProjectedCommand
from .implant.add import GuiAddImplantCommand
from .implant.changeLocation import GuiChangeImplantLocationCommand
from .implant.remove import GuiRemoveImplantCommand
from .implant.toggleState import GuiToggleImplantStateCommand
from .module.add import GuiAddModuleCommand
from .module.changeCharges import GuiChangeModuleChargesCommand
from .module.changeSpool import GuiChangeModuleSpoolCommand
from .module.changeStates import GuiChangeModuleStatesCommand
from .module.fill import GuiFillWithModulesCommand
from .module.mutatedConvert import GuiConvertMutatedModuleCommand
from .module.mutatedImport import GuiImportMutatedModuleCommand
from .module.mutatedRevert import GuiRevertMutatedModuleCommand
from .module.remove import GuiRemoveModuleCommand

View File

@@ -11,11 +11,11 @@ pyfalog = Logger(__name__)
class CalcChangeModuleChargesCommand(wx.Command):
def __init__(self, fitID, chargeMap, projected=False):
def __init__(self, fitID, projected, chargeMap):
wx.Command.__init__(self, True, 'Change Module Charges')
self.fitID = fitID
self.chargeMap = chargeMap
self.projected = projected
self.chargeMap = chargeMap
self.savedChargeMap = None
def Do(self):
@@ -50,5 +50,5 @@ class CalcChangeModuleChargesCommand(wx.Command):
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, chargeMap=self.savedChargeMap, projected=self.projected)
cmd = CalcChangeModuleChargesCommand(fitID=self.fitID, projected=self.projected, chargeMap=self.savedChargeMap)
return cmd.Do()

View File

@@ -10,13 +10,13 @@ pyfalog = Logger(__name__)
class CalcChangeModuleSpoolCommand(wx.Command):
def __init__(self, fitID, position, spoolType, spoolAmount, projected=False):
def __init__(self, fitID, projected, position, spoolType, spoolAmount):
wx.Command.__init__(self, True, 'Change Module Spool')
self.fitID = fitID
self.projected = projected
self.position = position
self.spoolType = spoolType
self.spoolAmount = spoolAmount
self.projected = projected
self.savedSpoolType = None
self.savedSpoolAmount = None
@@ -41,8 +41,8 @@ class CalcChangeModuleSpoolCommand(wx.Command):
pyfalog.debug('Undoing change of module spoolup at position {} to {} type {} amount on fit {}'.format(self.position, self.spoolType, self.spoolAmount, self.fitID))
cmd = CalcChangeModuleSpoolCommand(
fitID=self.fitID,
projected=self.projected,
position=self.position,
spoolType=self.savedSpoolType,
spoolAmount=self.savedSpoolAmount,
projected=self.projected)
spoolAmount=self.savedSpoolAmount)
return cmd.Do()

View File

@@ -1,75 +0,0 @@
import wx
from logbook import Logger
import gui.mainFrame
from service.market import Market
from service.fit import Fit
from gui import globalEvents as GE
from gui.fitCommands.helpers import ModuleInfo
from .calcCommands.module.localAdd import CalcAddLocalModuleCommand
from .calcCommands.module.localReplace import CalcReplaceLocalModuleCommand
from .calcCommands.module.changeCharges import CalcChangeModuleChargesCommand
pyfalog = Logger(__name__)
class GuiModuleAddCommand(wx.Command):
def __init__(self, fitID, itemID, position=None):
"""
Handles adding an item, usually a module, to the Fitting Window.
:param fitID: The fit ID that we are modifying
:param itemID: The item that is to be added to the Fitting View. If this turns out to be a charge, we attempt to
set the charge on the underlying module (requires position)
:param position: Optional. The position in fit.modules that we are attempting to set the item to
"""
wx.Command.__init__(self, True, 'Module Add')
self.fitID = fitID
self.itemID = itemID
self.position = position
self.internalHistory = wx.CommandProcessor()
def Do(self):
pyfalog.debug("{} Do()".format(self))
success = False
item = Market.getInstance().getItem(self.itemID)
# Charge
if item.isCharge and self.position is not None:
pyfalog.debug("Trying to add a charge")
success = self.internalHistory.Submit(CalcChangeModuleChargesCommand(self.fitID, {self.position: self.itemID}))
if not success:
pyfalog.debug(" Failed")
return False # if it's a charge item and this failed, nothing more we can try.
# Module to position
elif self.position is not None:
pyfalog.debug("Trying to add a module to a specific position")
success = self.internalHistory.Submit(CalcReplaceLocalModuleCommand(
fitID=self.fitID,
position=self.position,
newModInfo=ModuleInfo(itemID=self.itemID)))
if not success:
pyfalog.debug(" Failed")
# something went wrong with trying to fit the module into specific location, attempt to append it
self.position = None
# Module without position
if self.position is None:
pyfalog.debug("Trying to append a module")
success = self.internalHistory.Submit(CalcAddLocalModuleCommand(
fitID=self.fitID,
newModInfo=ModuleInfo(itemID=self.itemID)))
if success:
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action="modadd", typeID=self.itemID))
return True
return False
def Undo(self):
pyfalog.debug("{} Undo()".format(self))
for _ in self.internalHistory.Commands:
self.internalHistory.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action="moddel", typeID=self.itemID))
return True

View File

@@ -38,7 +38,7 @@ class GuiCargoToModuleCommand(wx.Command):
# We're trying to move a charge from cargo to a slot. Use SetCharge command (don't respect move vs copy)
if sFit.isAmmo(cargo.itemID):
result = self.internalHistory.Submit(CalcChangeModuleChargesCommand(self.fitID, {module.modPosition: cargo.itemID}))
result = self.internalHistory.Submit(CalcChangeModuleChargesCommand(self.fitID, False, {module.modPosition: cargo.itemID}))
else:
pyfalog.debug("Moving cargo item to module for fit ID: {0}", self.fitID)

View File

@@ -1,50 +0,0 @@
import wx
from logbook import Logger
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.helpers import ModuleInfo
from service.fit import Fit
from .calcCommands.module.localAdd import CalcAddLocalModuleCommand
pyfalog = Logger(__name__)
class GuiFillWithModuleCommand(wx.Command):
def __init__(self, fitID, itemID, position=None):
"""
Handles adding an item, usually a module, to the Fitting Window.
:param fitID: The fit ID that we are modifying
:param itemID: The item that is to be added to the Fitting View. If this turns out to be a charge, we attempt to
set the charge on the underlying module (requires position)
:param position: Optional. The position in fit.modules that we are attempting to set the item to
"""
wx.Command.__init__(self, True, "Module Fill: {}".format(itemID))
self.fitID = fitID
self.itemID = itemID
self.internalHistory = wx.CommandProcessor()
self.position = position
self.old_mod = None
def Do(self):
pyfalog.debug("{} Do()".format(self))
pyfalog.debug("Trying to append a module")
added_modules = 0
while self.internalHistory.Submit(CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID))):
added_modules += 1
if added_modules > 0:
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action="modadd", typeID=self.itemID))
return True
return False
def Undo(self):
pyfalog.debug("{} Undo()".format(self))
for _ in self.internalHistory.Commands:
self.internalHistory.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action="moddel", typeID=self.itemID))
return True

View File

@@ -1,41 +0,0 @@
import wx
from logbook import Logger
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.helpers import ModuleInfo
from service.fit import Fit
from .calcCommands.module.localAdd import CalcAddLocalModuleCommand
pyfalog = Logger(__name__)
class GuiImportMutatedModuleCommand(wx.Command):
def __init__(self, fitID, baseItem, mutaplasmid, mutations):
wx.Command.__init__(self, True, "Mutated Module Import: {} {} {}".format(baseItem, mutaplasmid, mutations))
self.internalHistory = wx.CommandProcessor()
self.fitID = fitID
self.newModInfo = ModuleInfo(
itemID=mutaplasmid.resultingItem.ID,
baseItemID=baseItem.ID,
mutaplasmidID=mutaplasmid.ID,
mutations=mutations)
def Do(self):
pyfalog.debug("{} Do()".format(self))
if self.internalHistory.Submit(CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=self.newModInfo)):
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action="modadd"))
return True
return False
def Undo(self):
pyfalog.debug("{} Undo()".format(self))
for _ in self.internalHistory.Commands:
self.internalHistory.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action="moddel"))
return True

View File

@@ -1,52 +0,0 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.helpers import ModuleInfo
from service.fit import Fit
from .calcCommands.module.localReplace import CalcReplaceLocalModuleCommand
class GuiMutaConvertCommand(wx.Command):
def __init__(self, fitID, position, mutaplasmid):
wx.Command.__init__(self, True, "Convert Item to Mutated")
self.internalHistory = wx.CommandProcessor()
self.fitID = fitID
self.position = position
self.mutaplasmid = mutaplasmid
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
oldMod = fit.modules[self.position]
if oldMod.isEmpty:
return False
if oldMod.isMutated:
return False
success = self.internalHistory.Submit(CalcReplaceLocalModuleCommand(
fitID=self.fitID,
position=self.position,
newModInfo=ModuleInfo(
itemID=self.mutaplasmid.resultingItem.ID,
baseItemID=oldMod.item.ID,
mutaplasmidID=self.mutaplasmid.ID,
mutations={},
chargeID=oldMod.chargeID,
state=oldMod.state,
spoolType=oldMod.spoolType,
spoolAmount=oldMod.spoolAmount)))
if not success:
return False
sFit.recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
def Undo(self):
for _ in self.internalHistory.Commands:
self.internalHistory.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True

View File

@@ -1,48 +0,0 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.helpers import ModuleInfo
from service.fit import Fit
from .calcCommands.module.localReplace import CalcReplaceLocalModuleCommand
class GuiMutaRevertCommand(wx.Command):
def __init__(self, fitID, position):
wx.Command.__init__(self, True, "Convert Item to Normal")
self.internalHistory = wx.CommandProcessor()
self.fitID = fitID
self.position = position
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
oldMod = fit.modules[self.position]
if oldMod.isEmpty:
return False
if not oldMod.isMutated:
return False
success = self.internalHistory.Submit(CalcReplaceLocalModuleCommand(
fitID=self.fitID,
position=self.position,
newModInfo=ModuleInfo(
itemID=oldMod.baseItemID,
chargeID=oldMod.chargeID,
state=oldMod.state,
spoolType=oldMod.spoolType,
spoolAmount=oldMod.spoolAmount)))
if not success:
return False
sFit.recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
def Undo(self):
for _ in self.internalHistory.Commands:
self.internalHistory.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True

View File

@@ -27,7 +27,7 @@ class GuiRebaseItemsCommand(wx.Command):
if mod.itemID in self.rebaseMap:
self.internalHistory.submit(CalcRebaseItemCommand(fitID=self.fitID, containerName="modules", position=mod.modPosition, itemID=self.rebaseMap[mod.itemID], commit=False))
if mod.chargeID in self.rebaseMap:
self.internalHistory.submit(CalcChangeModuleChargesCommand(fitID=self.fitID, chargeMap={mod.modPosition: self.rebaseMap[mod.chargeID]}))
self.internalHistory.submit(CalcChangeModuleChargesCommand(fitID=self.fitID, projected=False, chargeMap={mod.modPosition: self.rebaseMap[mod.chargeID]}))
for containerName in ("drones", "fighters", "implants", "boosters"):
container = getattr(fit, containerName)
for obj in container:

View File

@@ -1,37 +0,0 @@
import wx
from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .helpers import ModuleInfo
from .calcCommands.module.localRemove import CalcRemoveLocalModuleCommand
class GuiModuleRemoveCommand(wx.Command):
def __init__(self, fitID, modules):
"""
Handles removing modules from fit.modules,
:param fitID: The fit ID that we are modifying
:param modules: A list of Module objects that we are attempting to remove.
"""
wx.Command.__init__(self, True, "Module Remove")
self.fitID = fitID
self.modCache = {mod.modPosition: ModuleInfo.fromModule(mod) for mod in modules if not mod.isEmpty}
self.internalHistory = wx.CommandProcessor()
def Do(self):
success = self.internalHistory.Submit(CalcRemoveLocalModuleCommand(self.fitID, [pos for pos in self.modCache]))
if success:
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action="moddel", typeID=set([mod.itemID for mod in self.modCache.values()])))
return True
return False
def Undo(self):
for _ in self.internalHistory.Commands:
self.internalHistory.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action="modadd", typeID=set([mod.itemID for mod in self.modCache.values()])))
return True

View File

@@ -1,38 +0,0 @@
import wx
from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .calcCommands.module.changeSpool import CalcChangeModuleSpoolCommand
class GuiSetSpoolupCommand(wx.Command):
def __init__(self, fitID, position, spoolType, spoolAmount, context):
wx.Command.__init__(self, True, "Booster Add")
self.internalHistory = wx.CommandProcessor()
self.fitID = fitID
self.position = position
self.spoolType = spoolType
self.spoolupAmount = spoolAmount
self.context = context
def Do(self):
if self.internalHistory.Submit(CalcChangeModuleSpoolCommand(
fitID=self.fitID,
position=self.position,
spoolType=self.spoolType,
spoolAmount=self.spoolupAmount,
projected=True if self.context == 'projectedModule' else False
)):
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
return False
def Undo(self):
for _ in self.internalHistory.Commands:
self.internalHistory.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True

View File

@@ -1,31 +0,0 @@
import wx
from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .calcCommands.module.localChangeStates import CalcChangeLocalModuleStatesCommand
class GuiModuleStateChangeCommand(wx.Command):
def __init__(self, fitID, baseMod, modules, click):
# todo: instead of modules, needs to be positions. Dead objects are a thing
wx.Command.__init__(self, True, "Module State Change")
self.fitID = fitID
self.baseMod = baseMod
self.modules = modules
self.click = click
self.internalHistory = wx.CommandProcessor()
def Do(self):
if self.internalHistory.Submit(CalcChangeLocalModuleStatesCommand(self.fitID, self.baseMod, self.modules, self.click)):
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
return False
def Undo(self):
for _ in self.internalHistory.Commands:
self.internalHistory.Undo()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True

View File

View File

@@ -0,0 +1,54 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calcCommands.module.changeCharges import CalcChangeModuleChargesCommand
from gui.fitCommands.calcCommands.module.localAdd import CalcAddLocalModuleCommand
from gui.fitCommands.calcCommands.module.localReplace import CalcReplaceLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
from service.market import Market
class GuiAddModuleCommand(wx.Command):
def __init__(self, fitID, itemID, position=None):
wx.Command.__init__(self, True, 'Add Module')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.itemID = itemID
self.position = position
def Do(self):
position = self.position
success = False
item = Market.getInstance().getItem(self.itemID)
# Charge
if item.isCharge and position is not None:
cmd = CalcChangeModuleChargesCommand(fitID=self.fitID, projected=False, chargeMap={position: self.itemID})
success = self.internalHistory.submit(cmd)
if not success:
return False
# Module to position
elif position is not None:
cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=ModuleInfo(itemID=self.itemID))
success = self.internalHistory.submit(cmd)
# Something went wrong with trying to fit the module into specific location,
# keep going to append it instead
if not success:
position = None
# Module without position
if position is None:
cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID))
success = self.internalHistory.submit(cmd)
if not success:
return False
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID))
return True
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.itemID))
return success

View File

@@ -1,30 +1,31 @@
import wx
from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .calcCommands.module.changeCharges import CalcChangeModuleChargesCommand
from gui.fitCommands.calcCommands.module.changeCharges import CalcChangeModuleChargesCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiModuleAddChargeCommand(wx.Command):
class GuiChangeModuleChargesCommand(wx.Command):
def __init__(self, fitID, itemID, modules):
wx.Command.__init__(self, True, "Module Charge Add")
self.internalHistory = wx.CommandProcessor()
wx.Command.__init__(self, True, 'Change Module Charges')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.itemID = itemID
self.positions = [mod.modPosition for mod in modules]
self.projected = modules[0].isProjected
def Do(self):
if self.internalHistory.Submit(CalcChangeModuleChargesCommand(self.fitID, {p: self.itemID for p in self.positions}, self.projected)):
cmd = CalcChangeModuleChargesCommand(fitID=self.fitID, projected=False, chargeMap={p: self.itemID for p in self.positions})
if self.internalHistory.submit(cmd):
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
return False
def Undo(self):
for _ in self.internalHistory.Commands:
self.internalHistory.Undo()
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
return success

View File

@@ -0,0 +1,37 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calcCommands.module.changeSpool import CalcChangeModuleSpoolCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiChangeModuleSpoolCommand(wx.Command):
def __init__(self, fitID, position, spoolType, spoolAmount):
wx.Command.__init__(self, True, 'Change Module Spool')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.spoolType = spoolType
self.spoolAmount = spoolAmount
def Do(self):
cmd = CalcChangeModuleSpoolCommand(
fitID=self.fitID,
projected=False,
position=self.position,
spoolType=self.spoolType,
spoolAmount=self.spoolAmount)
if self.internalHistory.submit(cmd):
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
return False
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,36 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calcCommands.module.localChangeStates import CalcChangeLocalModuleStatesCommand
from gui.fitCommands.helpers import InternalCommandHistory
from service.fit import Fit
class GuiChangeModuleStatesCommand(wx.Command):
def __init__(self, fitID, mainPosition, positions, click):
wx.Command.__init__(self, True, 'Change Module States')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.mainPosition = mainPosition
self.positions = positions
self.click = click
def Do(self):
cmd = CalcChangeLocalModuleStatesCommand(
fitID=self.fitID,
mainPosition=self.mainPosition,
positions=self.positions,
click=self.click)
if self.internalHistory.submit(cmd):
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
return False
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,32 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calcCommands.module.localAdd import CalcAddLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
class GuiFillWithModulesCommand(wx.Command):
def __init__(self, fitID, itemID):
wx.Command.__init__(self, True, 'Fill with Modules')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.itemID = itemID
def Do(self):
added_modules = 0
while self.internalHistory.submit(CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID))):
added_modules += 1
if added_modules > 0:
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID))
return True
return False
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.itemID))
return success

View File

@@ -0,0 +1,50 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calcCommands.module.localReplace import CalcReplaceLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
class GuiConvertMutatedModuleCommand(wx.Command):
def __init__(self, fitID, position, mutaplasmid):
wx.Command.__init__(self, True, 'Convert Module to Mutated')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.itemID = mutaplasmid.resultingItem.ID
self.mutaplasmidID = mutaplasmid.ID
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
mod = fit.modules[self.position]
if mod.isEmpty:
return False
if mod.isMutated:
return False
cmd = CalcReplaceLocalModuleCommand(
fitID=self.fitID,
position=self.position,
newModInfo=ModuleInfo(
itemID=self.itemID,
baseItemID=mod.item.ID,
mutaplasmidID=self.mutaplasmidID,
mutations={},
chargeID=mod.chargeID,
state=mod.state,
spoolType=mod.spoolType,
spoolAmount=mod.spoolAmount))
if self.internalHistory.submit(cmd):
sFit.recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
return False
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,38 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calcCommands.module.localAdd import CalcAddLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
class GuiImportMutatedModuleCommand(wx.Command):
def __init__(self, fitID, baseItem, mutaplasmid, mutations):
wx.Command.__init__(self, True, 'Import Mutated Module')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.newModInfo = ModuleInfo(
itemID=mutaplasmid.resultingItem.ID,
baseItemID=baseItem.ID,
mutaplasmidID=mutaplasmid.ID,
mutations=mutations)
def Do(self):
cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=self.newModInfo)
if self.internalHistory.submit(cmd):
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.newModInfo.itemID))
return True
return False
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.newModInfo.itemID))
return success

View File

@@ -0,0 +1,45 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calcCommands.module.localReplace import CalcReplaceLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
class GuiRevertMutatedModuleCommand(wx.Command):
def __init__(self, fitID, position):
wx.Command.__init__(self, True, 'Revert Module from Mutated')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
mod = fit.modules[self.position]
if mod.isEmpty:
return False
if not mod.isMutated:
return False
cmd = CalcReplaceLocalModuleCommand(
fitID=self.fitID,
position=self.position,
newModInfo=ModuleInfo(
itemID=mod.baseItemID,
chargeID=mod.chargeID,
state=mod.state,
spoolType=mod.spoolType,
spoolAmount=mod.spoolAmount))
if self.internalHistory.submit(cmd):
sFit.recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
return False
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,34 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calcCommands.module.localRemove import CalcRemoveLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
class GuiRemoveModuleCommand(wx.Command):
def __init__(self, fitID, modules):
wx.Command.__init__(self, True, 'Remove Module')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.modCache = {mod.modPosition: ModuleInfo.fromModule(mod) for mod in modules if not mod.isEmpty}
def Do(self):
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[pos for pos in self.modCache])
if self.internalHistory.submit(cmd):
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='moddel', typeID=set([mod.itemID for mod in self.modCache.values()])))
return True
return False
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=set([mod.itemID for mod in self.modCache.values()])))
return success