MCPcopy Create free account
hub / github.com/pyfa-org/Pyfa / CalcSwapLocalModuleCommand

Class CalcSwapLocalModuleCommand

gui/fitCommands/calc/module/localSwap.py:10–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class CalcSwapLocalModuleCommand(wx.Command):
11
12 def __init__(self, fitID, position1, position2):
13 wx.Command.__init__(self, True, 'Swap Modules')
14 self.fitID = fitID
15 self.position1 = position1
16 self.position2 = position2
17
18 def Do(self):
19 pyfalog.debug('Doing swapping between {} and {} for fit {}'.format(self.position1, self.position2, self.fitID))
20 self.__swap(self.fitID, self.position1, self.position2)
21 return True
22
23 def Undo(self):
24 self.__swap(self.fitID, self.position2, self.position1)
25 pyfalog.debug('Undoing swapping between {} and {} for fit {}'.format(self.position1, self.position2, self.fitID))
26 return True
27
28 def __swap(self, fitID, position1, position2):
29 fit = Fit.getInstance().getFit(fitID)
30 mod1 = fit.modules[position1]
31 mod2 = fit.modules[position2]
32 fit.modules.free(position1)
33 fit.modules.free(position2)
34 fit.modules.replace(position2, mod1)
35 if len(fit.modules) <= position2 or fit.modules[position2] is not mod1:
36 fit.modules.replace(position1, mod1)
37 fit.modules.replace(position2, mod2)
38 return False
39 fit.modules.replace(position1, mod2)
40 if len(fit.modules) <= position1 or fit.modules[position1] is not mod2:
41 fit.modules.free(position2)
42 fit.modules.replace(position1, mod1)
43 fit.modules.replace(position2, mod2)
44 return False
45 return True

Callers 1

DoMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected