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

Class CalcAddCommandCommand

gui/fitCommands/calc/commandFit/add.py:11–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10
11class CalcAddCommandCommand(wx.Command):
12
13 def __init__(self, fitID, commandFitID, state=None):
14 wx.Command.__init__(self, True, 'Add Command Fit')
15 self.fitID = fitID
16 self.commandFitID = commandFitID
17 self.state = state
18
19 def Do(self):
20 pyfalog.debug('Doing addition of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
21 sFit = Fit.getInstance()
22 fit = sFit.getFit(self.fitID)
23 commandFit = sFit.getFit(self.commandFitID)
24
25 # Command fit could have been deleted if we are redoing
26 if commandFit is None:
27 pyfalog.debug('Command fit is not available')
28 return False
29 # Already commanding this ship
30 if commandFit in fit.commandFits:
31 pyfalog.debug('Command fit had been applied already')
32 return False
33 if commandFit.ID in fit.commandFitDict:
34 pyfalog.debug('Commanding fit is in command dict already')
35 return False
36 fit.commandFitDict[commandFit.ID] = commandFit
37 # This bit is required, see issue #83
38 eos.db.saveddata_session.flush()
39 eos.db.saveddata_session.refresh(commandFit)
40
41 if self.state is not None:
42 fitCommandInfo = commandFit.getCommandInfo(self.fitID)
43 if fitCommandInfo is None:
44 pyfalog.warning('Fit command info is not available')
45 self.Undo()
46 return False
47 fitCommandInfo.active = self.state
48
49 return True
50
51 def Undo(self):
52 pyfalog.debug('Undoing addition of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
53 # Can't find the command fit, it must have been deleted. Just skip, as deleted fit
54 # means that someone else just did exactly what we wanted to do
55 commandFit = Fit.getInstance().getFit(self.commandFitID)
56 if commandFit is None:
57 return True
58 from .remove import CalcRemoveCommandFitCommand
59 cmd = CalcRemoveCommandFitCommand(fitID=self.fitID, commandFitID=self.commandFitID)
60 return cmd.Do()

Callers 2

DoMethod · 0.90
UndoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected