Convert module swap / clone to fit / gui commands
This commit is contained in:
49
gui/fitCommands/fitCloneModule.py
Normal file
49
gui/fitCommands/fitCloneModule.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
#from .helpers import ModuleInfoCache
|
||||
from eos.saveddata.module import Module, State
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
import copy
|
||||
|
||||
class FitCloneModduleCommand(wx.Command):
|
||||
"""
|
||||
Clone a module from src to dst
|
||||
This will overwrite dst! Checking for empty module must be
|
||||
done at a higher level
|
||||
|
||||
from sFit.cloneModule
|
||||
"""
|
||||
def __init__(self, fitID, src, dst):
|
||||
wx.Command.__init__(self, True, "Module Clone")
|
||||
self.fitID = fitID
|
||||
self.src = src
|
||||
self.dst = dst
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Cloning modules from source ({0}) to destination ({1}) for fit ID: {1}", self.src, self.dst, self.fitID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
# Gather modules
|
||||
srcMod = fit.modules[self.src]
|
||||
dstMod = fit.modules[self.dst] # should be a placeholder module
|
||||
|
||||
new = copy.deepcopy(srcMod)
|
||||
new.owner = fit
|
||||
if new.fits(fit):
|
||||
# insert copy if module meets hardpoint restrictions
|
||||
fit.modules.remove(dstMod)
|
||||
fit.modules.insert(self.dst, new)
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
from .fitRemoveModule import FitRemoveModuleCommand # Avoid circular import
|
||||
cmd = FitRemoveModuleCommand(self.fitID, [self.dst])
|
||||
cmd.Do()
|
||||
return True
|
||||
Reference in New Issue
Block a user