Rework clone/swap modules
This commit is contained in:
@@ -446,11 +446,14 @@ class FittingView(d.Display):
|
||||
if mod1.slot != mod2.slot:
|
||||
return
|
||||
|
||||
clone = mstate.CmdDown() and mod2.isEmpty
|
||||
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
if getattr(mod2, "modPosition") is not None:
|
||||
self.mainFrame.command.Submit(cmd.GuiModuleSwapOrCloneCommand(fitID, srcIdx, mod2.modPosition, clone))
|
||||
if mstate.CmdDown() and mod2.isEmpty:
|
||||
self.mainFrame.command.Submit(cmd.GuiCloneLocalModuleCommand(
|
||||
fitID=fitID, srcPosition=srcIdx, dstPosition=mod2.modPosition))
|
||||
elif not mstate.CmdDown():
|
||||
self.mainFrame.command.Submit(cmd.GuiSwapLocalModulesCommand(
|
||||
fitID=fitID, position1=srcIdx, position2=mod2.modPosition))
|
||||
else:
|
||||
pyfalog.error("Missing module position for: {0}", str(getattr(mod2, "ID", "Unknown")))
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ from .gui.commandFit.toggleState import GuiToggleCommandFitStateCommand
|
||||
from .gui.fitRename import GuiRenameFitCommand
|
||||
from .gui.guiCargoToModule import GuiCargoToModuleCommand
|
||||
from .gui.guiModuleToCargo import GuiModuleToCargoCommand
|
||||
from .gui.guiSwapCloneModule import GuiModuleSwapOrCloneCommand
|
||||
from .gui.implant.add import GuiAddImplantCommand
|
||||
from .gui.implant.changeLocation import GuiChangeImplantLocationCommand
|
||||
from .gui.implant.changeMeta import GuiChangeImplantMetaCommand
|
||||
@@ -36,11 +35,13 @@ from .gui.localModule.changeCharges import GuiChangeLocalModuleChargesCommand
|
||||
from .gui.localModule.changeMetas import GuiChangeLocalModuleMetasCommand
|
||||
from .gui.localModule.changeSpool import GuiChangeLocalModuleSpoolCommand
|
||||
from .gui.localModule.changeStates import GuiChangeLocalModuleStatesCommand
|
||||
from .gui.localModule.clone import GuiCloneLocalModuleCommand
|
||||
from .gui.localModule.fill import GuiFillWithLocalModulesCommand
|
||||
from .gui.localModule.mutatedConvert import GuiConvertMutatedLocalModuleCommand
|
||||
from .gui.localModule.mutatedImport import GuiImportLocalMutatedModuleCommand
|
||||
from .gui.localModule.mutatedRevert import GuiRevertMutatedLocalModuleCommand
|
||||
from .gui.localModule.remove import GuiRemoveLocalModuleCommand
|
||||
from .gui.localModule.swap import GuiSwapLocalModulesCommand
|
||||
from .gui.projectedDrone.add import GuiAddProjectedDroneCommand
|
||||
from .gui.projectedDrone.changeAmount import GuiChangeProjectedDroneAmountCommand
|
||||
from .gui.projectedDrone.changeMeta import GuiChangeProjectedDroneMetaCommand
|
||||
|
||||
@@ -18,7 +18,6 @@ class CalcCloneLocalModuleCommand(wx.Command):
|
||||
self.fitID = fitID
|
||||
self.srcPosition = srcPosition
|
||||
self.dstPosition = dstPosition
|
||||
self.dstModInfo = 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))
|
||||
|
||||
@@ -27,24 +27,26 @@ class CalcSwapLocalModuleCommand(wx.Command):
|
||||
pyfalog.debug('Undoing swapping between {} and {} for fit {}'.format(self.position1, self.position2, self.fitID))
|
||||
return True
|
||||
|
||||
def __swap(self, fitID, srcPosition, dstPosition):
|
||||
def __swap(self, fitID, position1, position2):
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
srcMod = fit.modules[srcPosition]
|
||||
dstMod = fit.modules[dstPosition]
|
||||
fit.modules.free(srcPosition)
|
||||
fit.modules.free(dstPosition)
|
||||
mod1 = fit.modules[position1]
|
||||
mod2 = fit.modules[position2]
|
||||
fit.modules.free(position1)
|
||||
fit.modules.free(position2)
|
||||
try:
|
||||
fit.modules.replace(dstPosition, srcMod)
|
||||
fit.modules.replace(position2, mod1)
|
||||
except HandledListActionError:
|
||||
fit.modules.replace(srcPosition, srcMod)
|
||||
fit.modules.replace(dstPosition, dstMod)
|
||||
fit.modules.replace(position1, mod1)
|
||||
fit.modules.replace(position2, mod2)
|
||||
eos.db.commit()
|
||||
return False
|
||||
try:
|
||||
fit.modules.replace(srcPosition, dstMod)
|
||||
fit.modules.replace(position1, mod2)
|
||||
except HandledListActionError:
|
||||
fit.modules.free(dstPosition)
|
||||
fit.modules.replace(srcPosition, srcMod)
|
||||
fit.modules.replace(dstPosition, dstMod)
|
||||
fit.modules.free(position2)
|
||||
fit.modules.replace(position1, mod1)
|
||||
fit.modules.replace(position2, mod2)
|
||||
eos.db.commit()
|
||||
return False
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.module.localSwap import CalcSwapLocalModuleCommand
|
||||
from gui.fitCommands.calc.module.localClone import CalcCloneLocalModuleCommand
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class GuiModuleSwapOrCloneCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, srcPosition, dstPosition, clone=False):
|
||||
wx.Command.__init__(self, True, "Module State Change")
|
||||
self.fitID = fitID
|
||||
self.srcPosition = srcPosition
|
||||
self.dstPosition = dstPosition
|
||||
self.clone = clone
|
||||
self.internalHistory = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("{} Do()".format(self))
|
||||
|
||||
if self.clone:
|
||||
pyfalog.debug("Trying to clone module")
|
||||
if self.internalHistory.Submit(CalcCloneLocalModuleCommand(self.fitID, self.srcPosition, self.dstPosition)):
|
||||
Fit.getInstance().recalc(self.fitID) # clone needs a recalc
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
else:
|
||||
pyfalog.debug("Trying to Swap module")
|
||||
if self.internalHistory.Submit(CalcSwapLocalModuleCommand(self.fitID, self.srcPosition, self.dstPosition)):
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug("{} Undo()".format(self))
|
||||
for _ in self.internalHistory.Commands:
|
||||
self.internalHistory.Undo()
|
||||
|
||||
if self.clone:
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
@@ -29,7 +29,7 @@ class GuiAddLocalModuleCommand(wx.Command):
|
||||
success = self.internalHistory.submit(cmd)
|
||||
if not success:
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID))
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return False
|
||||
# Module to position
|
||||
elif position is not None:
|
||||
@@ -43,11 +43,15 @@ class GuiAddLocalModuleCommand(wx.Command):
|
||||
cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID))
|
||||
success = self.internalHistory.submit(cmd)
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID))
|
||||
wx.PostEvent(
|
||||
gui.mainFrame.MainFrame.getInstance(),
|
||||
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID) if success else 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, action='moddel', typeID=self.itemID))
|
||||
wx.PostEvent(
|
||||
gui.mainFrame.MainFrame.getInstance(),
|
||||
GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.itemID) if success else GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
43
gui/fitCommands/gui/localModule/clone.py
Normal file
43
gui/fitCommands/gui/localModule/clone.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import wx
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.module.localClone import CalcCloneLocalModuleCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiCloneLocalModuleCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, srcPosition, dstPosition):
|
||||
wx.Command.__init__(self, True, 'Clone Local Module')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.srcPosition = srcPosition
|
||||
self.dstPosition = dstPosition
|
||||
self.savedItemID = None
|
||||
|
||||
def Do(self):
|
||||
if self.srcPosition == self.dstPosition:
|
||||
return False
|
||||
sFit = Fit.getInstance()
|
||||
cmd = CalcCloneLocalModuleCommand(fitID=self.fitID, srcPosition=self.srcPosition, dstPosition=self.dstPosition)
|
||||
success = self.internalHistory.submit(cmd)
|
||||
sFit.recalc(self.fitID)
|
||||
self.savedItemID = sFit.getFit(self.fitID).modules[self.srcPosition].itemID
|
||||
if success and self.savedItemID is not None:
|
||||
event = GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.savedItemID)
|
||||
else:
|
||||
event = GE.FitChanged(fitID=self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
|
||||
return success
|
||||
|
||||
def Undo(self):
|
||||
success = self.internalHistory.undoAll()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
if success and self.savedItemID is not None:
|
||||
event = GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.savedItemID)
|
||||
else:
|
||||
event = GE.FitChanged(fitID=self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
|
||||
return success
|
||||
@@ -25,12 +25,17 @@ class GuiFillWithLocalModulesCommand(wx.Command):
|
||||
added_modules += 1
|
||||
eos.db.commit()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID))
|
||||
return added_modules > 0
|
||||
success = added_modules > 0
|
||||
wx.PostEvent(
|
||||
gui.mainFrame.MainFrame.getInstance(),
|
||||
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID) if success else 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, action='moddel', typeID=self.itemID))
|
||||
wx.PostEvent(
|
||||
gui.mainFrame.MainFrame.getInstance(),
|
||||
GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.itemID) if success else GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
@@ -21,7 +21,7 @@ class GuiRemoveLocalModuleCommand(wx.Command):
|
||||
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()])))
|
||||
GE.FitChanged(fitID=self.fitID, action='moddel', typeID={mod.itemID for mod in self.modCache.values()}) if success else GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
def Undo(self):
|
||||
@@ -29,5 +29,5 @@ class GuiRemoveLocalModuleCommand(wx.Command):
|
||||
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()])))
|
||||
GE.FitChanged(fitID=self.fitID, action='modadd', typeID={mod.itemID for mod in self.modCache.values()}) if success else GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
29
gui/fitCommands/gui/localModule/swap.py
Normal file
29
gui/fitCommands/gui/localModule/swap.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import wx
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.module.localSwap import CalcSwapLocalModuleCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
|
||||
|
||||
class GuiSwapLocalModulesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position1, position2):
|
||||
wx.Command.__init__(self, True, 'Swap Local Modules')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position1 = position1
|
||||
self.position2 = position2
|
||||
|
||||
def Do(self):
|
||||
if self.position1 == self.position2:
|
||||
return False
|
||||
cmd = CalcSwapLocalModuleCommand(fitID=self.fitID, position1=self.position1, position2=self.position2)
|
||||
success = self.internalHistory.submit(cmd)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
def Undo(self):
|
||||
success = self.internalHistory.undoAll()
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
Reference in New Issue
Block a user