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

Class CalcRemoveLocalModulesCommand

gui/fitCommands/calc/module/localRemove.py:13–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12
13class CalcRemoveLocalModulesCommand(wx.Command):
14
15 def __init__(self, fitID, positions, recalc=True, clearTail=False):
16 wx.Command.__init__(self, True, 'Remove Module')
17 self.fitID = fitID
18 self.positions = positions
19 self.recalc = recalc
20 self.clearTail = clearTail
21 self.savedSubInfos = None
22 self.savedModInfos = None
23 self.savedStateCheckChanges = None
24 self.savedTail = None
25
26 def Do(self):
27 pyfalog.debug('Doing removal of local modules from positions {} on fit {}'.format(self.positions, self.fitID))
28 sFit = Fit.getInstance()
29 fit = sFit.getFit(self.fitID)
30
31 self.savedSubInfos = {}
32 self.savedModInfos = {}
33 for position in self.positions:
34 mod = fit.modules[position]
35 if not mod.isEmpty:
36 if mod.slot == FittingSlot.SUBSYSTEM:
37 self.savedSubInfos[position] = ModuleInfo.fromModule(mod)
38 else:
39 self.savedModInfos[position] = ModuleInfo.fromModule(mod)
40 fit.modules.free(position)
41
42 if len(self.savedSubInfos) == 0 and len(self.savedModInfos) == 0:
43 return False
44
45 if self.clearTail:
46 self.savedTail = fit.clearTail()
47
48 if self.recalc:
49 # Need to flush because checkStates sometimes relies on module->fit
50 # relationship via .owner attribute, which is handled by SQLAlchemy
51 eos.db.flush()
52 sFit.recalc(fit)
53 self.savedStateCheckChanges = sFit.checkStates(fit, None)
54 return True
55
56 def Undo(self):
57 pyfalog.debug('Undoing removal of local modules {} on fit {}'.format(self.savedModInfos, self.fitID))
58 sFit = Fit.getInstance()
59 fit = sFit.getFit(self.fitID)
60 results = []
61 from .localReplace import CalcReplaceLocalModuleCommand
62 # Restore subsystems 1st
63 if len(self.savedSubInfos) > 0:
64 for position, modInfo in self.savedSubInfos.items():
65 cmd = CalcReplaceLocalModuleCommand(
66 fitID=self.fitID,
67 position=position,
68 newModInfo=modInfo,
69 ignoreRestrictions=True,
70 recalc=False)

Callers 7

getT2MwdSpeedMethod · 0.90
DoMethod · 0.90
DoMethod · 0.90
DoMethod · 0.90
UndoMethod · 0.85
UndoMethod · 0.85
UndoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected