Removed projected modules now keep their state for undoing
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import wx
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
from eos.saveddata.module import Module
|
||||
|
||||
import eos.db
|
||||
from eos.const import FittingModuleState
|
||||
from eos.saveddata.module import Module
|
||||
from gui.fitCommands.helpers import ModuleInfoCache
|
||||
from service.fit import Fit
|
||||
from service.market import Market
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
@@ -10,35 +16,79 @@ class FitAddProjectedModuleCommand(wx.Command):
|
||||
""""
|
||||
from sFit.project
|
||||
"""
|
||||
def __init__(self, fitID, itemID):
|
||||
def __init__(self, fitID, newItemID, newBaseItemID, newMutaplasmidID, newMutations, newState, newChargeID, newPosition):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.new_index = None
|
||||
self.newItemID = newItemID
|
||||
self.newBaseItemID = newBaseItemID
|
||||
self.newMutaplasmidID = newMutaplasmidID
|
||||
self.newMutations = newMutations
|
||||
self.newState = newState
|
||||
self.newChargeID = newChargeID
|
||||
self.newPosition = newPosition
|
||||
self.oldModuleInfo = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Projecting fit ({0}) onto: {1}", self.fitID, self.itemID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
item = eos.db.getItem(self.itemID, eager=("attributes", "group.category"))
|
||||
|
||||
try:
|
||||
module = Module(item)
|
||||
if not module.item.isType("projected"):
|
||||
return False
|
||||
except ValueError:
|
||||
pyfalog.debug("Projecting fit ({0}) onto: {1}", self.fitID, self.newItemID)
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
mod = self.makeModule(self.newItemID, self.newBaseItemID, self.newMutaplasmidID, self.newMutations, self.newState, self.newChargeID)
|
||||
if mod is None:
|
||||
return False
|
||||
|
||||
module.state = FittingModuleState.ACTIVE
|
||||
if not module.canHaveState(module.state, fit):
|
||||
module.state = FittingModuleState.OFFLINE
|
||||
fit.projectedModules.append(module)
|
||||
if not mod.canHaveState(mod.state, fit):
|
||||
mod.state = FittingModuleState.OFFLINE
|
||||
|
||||
oldItemID, oldBaseItemID, oldMutaplasmidID, oldMutations, oldState, oldChargeID, oldPosition = fit.projectedModules.makeRoom(mod)
|
||||
if oldItemID is not None:
|
||||
self.oldModuleInfo = ModuleInfoCache(oldPosition, oldItemID, oldState, oldChargeID, oldBaseItemID, oldMutaplasmidID, oldMutations)
|
||||
|
||||
if self.newPosition is not None:
|
||||
fit.projectedModules.append(self.newPosition, mod)
|
||||
else:
|
||||
fit.projectedModules.append(mod)
|
||||
self.newPosition = fit.projectedModules.index(mod)
|
||||
|
||||
eos.db.commit()
|
||||
self.new_index = fit.projectedModules.index(module)
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from gui.fitCommands.calc.fitRemoveProjectedModule import FitRemoveProjectedModuleCommand # avoids circular import
|
||||
cmd = FitRemoveProjectedModuleCommand(self.fitID, self.new_index)
|
||||
cmd = FitRemoveProjectedModuleCommand(self.fitID, self.newPosition)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
def makeModule(self, itemID, baseItemID, mutaplasmidID, mutations, state, chargeID):
|
||||
mkt = Market.getInstance()
|
||||
|
||||
item = mkt.getItem(itemID, eager=("attributes", "group.category"))
|
||||
if baseItemID and mutaplasmidID:
|
||||
baseItem = mkt.getItem(baseItemID, eager=("attributes", "group.category"))
|
||||
mutaplasmid = eos.db.getDynamicItem(mutaplasmidID)
|
||||
else:
|
||||
baseItem = None
|
||||
mutaplasmid = None
|
||||
try:
|
||||
mod = Module(item, baseItem, mutaplasmid)
|
||||
except ValueError:
|
||||
pyfalog.warning("Invalid item: {0}", itemID)
|
||||
return None
|
||||
|
||||
for attrID, mutator in mod.mutators.items():
|
||||
if attrID in mutations:
|
||||
mutator.value = mutations[attrID]
|
||||
|
||||
if state is not None:
|
||||
if not mod.isValidState(state):
|
||||
return None
|
||||
mod.state = state
|
||||
else:
|
||||
desiredState = FittingModuleState.ACTIVE
|
||||
if mod.isValidState(desiredState):
|
||||
mod.state = desiredState
|
||||
|
||||
if chargeID is not None:
|
||||
charge = mkt.getItem(chargeID)
|
||||
if charge is not None:
|
||||
mod.charge = charge
|
||||
|
||||
return mod
|
||||
|
||||
Reference in New Issue
Block a user