More tweaks to existing commands

This commit is contained in:
blitzmann
2018-08-03 01:08:33 -04:00
parent 36b158637c
commit c84c79c917
5 changed files with 36 additions and 24 deletions

View File

@@ -4,11 +4,14 @@ from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.fitSwapModule import FitSwapModuleCommand
from .calc.fitCloneModule import FitCloneModduleCommand
from .calc.fitCloneModule import FitCloneModuleCommand
from logbook import Logger
pyfalog = Logger(__name__)
class GuiModuleSwapOrCloneCommand(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()
@@ -19,17 +22,24 @@ class GuiModuleSwapOrCloneCommand(wx.Command):
self.internal_history = wx.CommandProcessor()
def Do(self):
result = None
if self.clone:
result = self.internal_history.Submit(FitCloneModduleCommand(self.fitID, self.srcPosition, self.dstPosition))
else:
result = self.internal_history.Submit(FitSwapModuleCommand(self.fitID, self.srcPosition, self.dstPosition))
pyfalog.debug("{} Do()".format(self))
if result:
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return result
if self.clone:
pyfalog.debug("Trying to clone module")
if self.internal_history.Submit(FitCloneModuleCommand(self.fitID, self.srcPosition, self.dstPosition)):
self.sFit.recalc(self.fitID) # clone needs a recalc
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True
else:
pyfalog.debug("Trying to Swap module")
if self.internal_history.Submit(FitSwapModuleCommand(self.fitID, self.srcPosition, self.dstPosition)):
wx.PostEvent(self.mainFrame, 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()
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))