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

Method Do

gui/fitCommands/calc/module/localAdd.py:22–60  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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))

Callers

nothing calls this directly

Calls 12

UndoMethod · 0.95
activeStateLimitFunction · 0.90
getFitMethod · 0.80
toModuleMethod · 0.80
flushMethod · 0.80
recalcMethod · 0.80
checkStatesMethod · 0.80
getInstanceMethod · 0.45
getModifiedItemAttrMethod · 0.45
appendMethod · 0.45
fitsMethod · 0.45

Tested by

no test coverage detected