From c97750a5939e28878bce41e99fb9360a95bf34c7 Mon Sep 17 00:00:00 2001 From: Ryan Holmes Date: Sat, 24 Nov 2018 21:38:50 -0500 Subject: [PATCH] Attempt to save the charge when changing module variations. Move caching of old module into Do function. Having it in `change_module` causes it to run even with the Undo command, whch causes funkiness --- gui/fitCommands/calc/fitReplaceModule.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gui/fitCommands/calc/fitReplaceModule.py b/gui/fitCommands/calc/fitReplaceModule.py index 19674df80..b7edf21b4 100644 --- a/gui/fitCommands/calc/fitReplaceModule.py +++ b/gui/fitCommands/calc/fitReplaceModule.py @@ -23,6 +23,13 @@ class FitReplaceModuleCommand(wx.Command): self.old_module = None def Do(self): + fit = eos.db.getFit(self.fitID) + + mod = fit.modules[self.position] + if not mod.isEmpty: + self.old_module = ModuleInfoCache(mod.modPosition, mod.item.ID, mod.state, mod.charge, mod.baseItemID, + mod.mutaplasmidID) + return self.change_module(self.fitID, self.position, self.itemID) def Undo(self): @@ -30,7 +37,6 @@ class FitReplaceModuleCommand(wx.Command): fit = eos.db.getFit(self.fitID) fit.modules.toDummy(self.position) return True - self.change_module(self.fitID, self.position, self.old_module.itemID) self.module.state = self.old_module.state self.module.charge = self.old_module.charge @@ -52,10 +58,7 @@ class FitReplaceModuleCommand(wx.Command): pyfalog.debug("Changing position of module from position ({0}) for fit ID: {1}", self.position, fitID) item = eos.db.getItem(itemID, eager=("attributes", "group.category")) - mod = fit.modules[self.position] - if not mod.isEmpty: - self.old_module = ModuleInfoCache(mod.modPosition, mod.item.ID, mod.state, mod.charge, mod.baseItemID, mod.mutaplasmidID) try: self.module = Module(item) @@ -75,6 +78,9 @@ class FitReplaceModuleCommand(wx.Command): if self.module.isValidState(State.ACTIVE): self.module.state = State.ACTIVE + if self.old_module.charge and self.module.isValidCharge(self.old_module.charge): + self.module.charge = self.old_module.charge + # Then, check states of all modules and change where needed. This will recalc if needed # self.checkStates(fit, m)