Convert module swap to command pattern
This commit is contained in:
@@ -468,13 +468,9 @@ class FittingView(d.Display):
|
||||
if mod1.slot != mod2.slot:
|
||||
return
|
||||
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
if getattr(mod2, "modPosition") is not None:
|
||||
if clone and mod2.isEmpty:
|
||||
sFit.cloneModule(self.mainFrame.getActiveFit(), srcIdx, mod2.modPosition)
|
||||
else:
|
||||
sFit.swapModules(self.mainFrame.getActiveFit(), srcIdx, mod2.modPosition)
|
||||
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit()))
|
||||
self.mainFrame.command.Submit(cmd.FitModuleSwapOrCloneCommand(fitID, srcIdx, mod2.modPosition, clone and mod2.isEmpty))
|
||||
else:
|
||||
pyfalog.error("Missing module position for: {0}", str(getattr(mod2, "ID", "Unknown")))
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .moduleStateChange import FitModuleStateChangeCommand
|
||||
from .moduleAdd import FitModuleAddCommand
|
||||
from .moduleRemove import FitModuleRemoveCommand
|
||||
from .moduleAddCharge import FitModuleAddChargeCommand
|
||||
from .moduleAddCharge import FitModuleAddChargeCommand
|
||||
from .moduleSwapOrClone import FitModuleSwapOrCloneCommand
|
||||
34
gui/fitCommands/moduleSwapOrClone.py
Normal file
34
gui/fitCommands/moduleSwapOrClone.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
|
||||
|
||||
class FitModuleSwapOrCloneCommand(wx.Command):
|
||||
def __init__(self, fitID, srcPosition, dstPosition, clone=False):
|
||||
# todo: instead of modules, needs to be positions. Dead objects are a thing
|
||||
wx.Command.__init__(self, True, "Module State Change")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
self.srcPosition = srcPosition
|
||||
self.dstPosition = dstPosition
|
||||
self.clone = clone
|
||||
|
||||
def Do(self):
|
||||
if self.clone:
|
||||
self.sFit.cloneModule(self.fitID, self.srcPosition, self.dstPosition)
|
||||
else:
|
||||
self.sFit.swapModules(self.fitID, self.srcPosition, self.dstPosition)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
if self.clone:
|
||||
# if we had cloned, the destinations was originally an empty slot, hence we can just remove the module
|
||||
self.sFit.removeModule(self.fitID, [self.dstPosition])
|
||||
else:
|
||||
self.sFit.swapModules(self.fitID, self.dstPosition, self.srcPosition)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
Reference in New Issue
Block a user