Convert module swap to command pattern
This commit is contained in:
@@ -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