MCPcopy Index your code
hub / github.com/pyfa-org/Pyfa / CalcAddLocalModuleCommand

Class CalcAddLocalModuleCommand

gui/fitCommands/calc/module/localAdd.py:12–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class CalcAddLocalModuleCommand(wx.Command):
13
14 def __init__(self, fitID, newModInfo):
15 wx.Command.__init__(self, True, 'Add Module')
16 self.fitID = fitID
17 self.newModInfo = newModInfo
18 self.savedPosition = None
19 self.subsystemCmd = None
20 self.savedStateCheckChanges = None
21
22 def Do(self):
23 pyfalog.debug('Doing addition of local module {} to fit {}'.format(self.newModInfo, self.fitID))
24 sFit = Fit.getInstance()
25 fit = sFit.getFit(self.fitID)
26
27 newMod = self.newModInfo.toModule(fallbackState=activeStateLimit(self.newModInfo.itemID))
28 if newMod is None:
29 return False
30
31 # If subsystem and we need to replace, run the replace command instead and bypass the rest of this command
32 if newMod.item.category.name == 'Subsystem':
33 for oldMod in fit.modules:
34 if oldMod.getModifiedItemAttr('subSystemSlot') == newMod.getModifiedItemAttr('subSystemSlot') and newMod.slot == oldMod.slot:
35 if oldMod.itemID == self.newModInfo.itemID:
36 return False
37 from .localReplace import CalcReplaceLocalModuleCommand
38 self.subsystemCmd = CalcReplaceLocalModuleCommand(
39 fitID=self.fitID,
40 position=fit.modules.index(oldMod),
41 newModInfo=self.newModInfo)
42 return self.subsystemCmd.Do()
43 fit.modules.append(newMod)
44 if newMod not in fit.modules:
45 pyfalog.warning('Failed to append to list')
46 return False
47 self.savedPosition = fit.modules.index(newMod)
48 # Need to flush because checkStates sometimes relies on module->fit
49 # relationship via .owner attribute, which is handled by SQLAlchemy
50 eos.db.flush()
51 sFit.recalc(fit)
52 # fits() sometimes relies on recalculated on-item attributes, such as fax cap
53 # booster limitation, so we have to check it after recalculating and remove the
54 # module if the check has failed
55 if not newMod.fits(fit):
56 pyfalog.warning('Module does not fit')
57 self.Undo()
58 return False
59 self.savedStateCheckChanges = sFit.checkStates(fit, newMod)
60 return True
61
62 def Undo(self):
63 pyfalog.debug('Undoing addition of local module {} to fit {}'.format(self.newModInfo, self.fitID))
64 # We added a subsystem module, which actually ran the replace command. Run the undo for that guy instead
65 if self.subsystemCmd is not None:
66 return self.subsystemCmd.Undo()
67 if self.savedPosition is None:
68 return False
69 from .localRemove import CalcRemoveLocalModulesCommand

Callers 5

getT2MwdSpeedMethod · 0.90
DoMethod · 0.90
DoMethod · 0.90
DoMethod · 0.90
DoMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected