Created undo/redo command for module remove, along with reapplying some module-specific attributes (state, charge). Fixed a bug when trying to add a module that doesn't fit
This commit is contained in:
@@ -401,18 +401,10 @@ class FittingView(d.Display):
|
||||
|
||||
def removeModule(self, modules):
|
||||
"""Removes a list of modules from the fit"""
|
||||
sFit = Fit.getInstance()
|
||||
|
||||
if not isinstance(modules, list):
|
||||
modules = [modules]
|
||||
|
||||
positions = [mod.modPosition for mod in modules]
|
||||
result = sFit.removeModule(self.activeFitID, positions)
|
||||
|
||||
if result is not None:
|
||||
self.slotsChanged()
|
||||
ids = {mod.item.ID for mod in modules}
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.activeFitID, action="moddel", typeID=ids))
|
||||
self.mainFrame.command.Submit(cmd.FitModuleRemoveCommand(self.activeFitID, modules))
|
||||
|
||||
def addModule(self, x, y, srcIdx):
|
||||
"""Add a module from the market browser"""
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
from .moduleStateChange import FitModuleStateChangeCommand
|
||||
from.moduleAdd import FitModuleAddCommand
|
||||
from .moduleAdd import FitModuleAddCommand
|
||||
from .moduleRemove import FitModuleRemoveCommand
|
||||
@@ -7,8 +7,8 @@ from gui import globalEvents as GE
|
||||
|
||||
class FitModuleAddCommand(wx.Command):
|
||||
def __init__(self, fitID, itemID):
|
||||
# todo: instead of modules, needs to be positions. Dead objects are a thing
|
||||
wx.Command.__init__(self, True, "Module Add")
|
||||
# todo: evaluate mutaplasmid modules
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
@@ -16,6 +16,7 @@ class FitModuleAddCommand(wx.Command):
|
||||
self.new_position = None
|
||||
|
||||
def Do(self):
|
||||
# todo: figure how not to add this command to stack if module doesn't fit correctly.
|
||||
populate, self.new_position = self.sFit.appendModule(self.fitID, self.itemID)
|
||||
if populate is not None:
|
||||
# self.slotsChanged() # unsure how to handle this right now? Perhaps move this to the event itself?
|
||||
@@ -23,7 +24,8 @@ class FitModuleAddCommand(wx.Command):
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
# todo: self.slotsChanged()
|
||||
result = self.sFit.removeModule(self.fitID, [self.new_position])
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="moddel", typeID=self.itemID))
|
||||
if (self.new_position):
|
||||
# todo: self.slotsChanged()
|
||||
result = self.sFit.removeModule(self.fitID, [self.new_position])
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="moddel", typeID=self.itemID))
|
||||
return True
|
||||
|
||||
37
gui/fitCommands/moduleRemove.py
Normal file
37
gui/fitCommands/moduleRemove.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
ModuleInfoCache = namedtuple('ModuleInfoCache', ['modPosition', 'itemID', 'state', 'charge'])
|
||||
|
||||
class FitModuleRemoveCommand(wx.Command):
|
||||
def __init__(self, fitID, modules):
|
||||
# todo: evaluate mutaplasmid modules
|
||||
wx.Command.__init__(self, True, "Module Remove")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
self.modCache = [ModuleInfoCache(mod.modPosition, mod.item.ID, mod.state, mod.charge) for mod in modules]
|
||||
|
||||
def Do(self):
|
||||
self.sFit.getFit(self.fitID)
|
||||
result = self.sFit.removeModule(self.fitID, [mod.modPosition for mod in self.modCache])
|
||||
|
||||
if result is not None:
|
||||
# self.slotsChanged() # todo: fix
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="moddel", typeID=set([mod.itemID for mod in self.modCache])))
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
for mod in self.modCache:
|
||||
m = self.sFit.changeModule(self.fitID, mod.modPosition, mod.itemID, False)
|
||||
m.state = mod.state
|
||||
m.charge = mod.charge
|
||||
self.sFit.recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="modadd", typeID=set([mod.itemID for mod in self.modCache])))
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user