Do not store fit service and main frame on every command
This commit is contained in:
@@ -13,38 +13,36 @@ class GuiModuleSwapOrCloneCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, srcPosition, dstPosition, clone=False):
|
||||
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
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.internalHistory = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("{} Do()".format(self))
|
||||
|
||||
if self.clone:
|
||||
pyfalog.debug("Trying to clone module")
|
||||
if self.internal_history.Submit(CalcCloneLocalModuleCommand(self.fitID, self.srcPosition, self.dstPosition)):
|
||||
self.sFit.recalc(self.fitID) # clone needs a recalc
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
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.internal_history.Submit(CalcSwapLocalModuleCommand(self.fitID, self.srcPosition, self.dstPosition)):
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
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.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
for _ in self.internalHistory.Commands:
|
||||
self.internalHistory.Undo()
|
||||
|
||||
if self.clone:
|
||||
self.sFit.recalc(self.fitID)
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user