diff --git a/gui/builtinAdditionPanes/commandView.py b/gui/builtinAdditionPanes/commandView.py index 52cda66cb..d05e4fe8c 100644 --- a/gui/builtinAdditionPanes/commandView.py +++ b/gui/builtinAdditionPanes/commandView.py @@ -103,18 +103,13 @@ class CommandView(d.Display): sFit = Fit.getInstance() row = self.GetFirstSelected() if row != -1: - sFit.removeCommand(fitID, self.get(row)) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + self.mainFrame.command.Submit(cmd.GuiRemoveCommandCommand(fitID, self.get(row).ID)) def handleDrag(self, type, fitID): # Those are drags coming from pyfa sources, NOT builtin wx drags if type == "fit": activeFit = self.mainFrame.getActiveFit() if activeFit: - # sFit = Fit.getInstance() - # draggedFit = sFit.getFit(fitID) - # sFit.addCommandFit(activeFit, draggedFit) - # wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=activeFit)) self.mainFrame.command.Submit(cmd.GuiAddCommandCommand(activeFit, fitID)) def startDrag(self, event): @@ -191,9 +186,7 @@ class CommandView(d.Display): col = self.getColumn(event.Position) if col == self.getColIndex(State): fitID = self.mainFrame.getActiveFit() - sFit = Fit.getInstance() - sFit.toggleCommandFit(fitID, item) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + self.mainFrame.command.Submit(cmd.GuiToggleCommandCommand(fitID, item.ID)) def scheduleMenu(self, event): event.Skip() @@ -228,5 +221,4 @@ class CommandView(d.Display): sFit = Fit.getInstance() thing = self.get(row) if thing: # thing doesn't exist if it's the dummy value - sFit.removeCommand(fitID, thing) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + self.mainFrame.command.Submit(cmd.GuiRemoveCommandCommand(fitID, thing.ID)) diff --git a/gui/builtinAdditionPanes/projectedView.py b/gui/builtinAdditionPanes/projectedView.py index 24ca11f3a..4cb18abd8 100644 --- a/gui/builtinAdditionPanes/projectedView.py +++ b/gui/builtinAdditionPanes/projectedView.py @@ -32,6 +32,7 @@ from gui.contextMenu import ContextMenu from gui.utils.staticHelpers import DragDropHelper from service.fit import Fit from service.market import Market +import gui.fitCommands as cmd pyfalog = Logger(__name__) @@ -100,6 +101,7 @@ class ProjectedView(d.Display): data[1] is typeID or index of data we want to manipulate """ sFit = Fit.getInstance() + fitID = self.mainFrame.getActiveFit() fit = sFit.getFit(self.mainFrame.getActiveFit()) if data[0] == "projected": @@ -109,12 +111,14 @@ class ProjectedView(d.Display): dstRow, _ = self.HitTest((x, y)) # Gather module information to get position module = fit.modules[int(data[1])] - sFit.project(fit.ID, module) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fit.ID)) + self.mainFrame.command.Submit(cmd.GuiAddProjectedCommand(fitID, module.itemID, 'item')) + # sFit.project(fit.ID, module) + # wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fit.ID)) elif data[0] == "market": - sFit = Fit.getInstance() - sFit.project(fit.ID, int(data[1])) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fit.ID)) + # sFit = Fit.getInstance() + self.mainFrame.command.Submit(cmd.GuiAddProjectedCommand(fitID, int(data[1]), 'item')) + # sFit.project(fit.ID, int(data[1])) + # wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fit.ID)) def kbEvent(self, event): keycode = event.GetKeyCode() @@ -131,10 +135,7 @@ class ProjectedView(d.Display): if type == "fit": activeFit = self.mainFrame.getActiveFit() if activeFit: - sFit = Fit.getInstance() - draggedFit = sFit.getFit(fitID) - sFit.project(activeFit, draggedFit) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=activeFit)) + self.mainFrame.command.Submit(cmd.GuiAddProjectedCommand(activeFit, fitID, 'fit')) def startDrag(self, event): row = event.GetIndex() diff --git a/gui/builtinContextMenus/commandFits.py b/gui/builtinContextMenus/commandFits.py index 936dd0cc0..d2dd7ec94 100644 --- a/gui/builtinContextMenus/commandFits.py +++ b/gui/builtinContextMenus/commandFits.py @@ -7,7 +7,7 @@ import gui.mainFrame import gui.globalEvents as GE from gui.contextMenu import ContextMenu from service.settings import ContextMenuSettings - +import gui.fitCommands as cmd class CommandFits(ContextMenu): # Get list of items that define a command fit @@ -99,9 +99,7 @@ class CommandFits(ContextMenu): sFit = Fit.getInstance() fitID = self.mainFrame.getActiveFit() - - sFit.addCommandFit(fitID, fit) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + self.mainFrame.command.Submit(cmd.GuiAddCommandCommand(fitID, fit.ID)) CommandFits.populateFits(None) diff --git a/gui/builtinContextMenus/itemRemove.py b/gui/builtinContextMenus/itemRemove.py index 60a0d36d1..d075eba2e 100644 --- a/gui/builtinContextMenus/itemRemove.py +++ b/gui/builtinContextMenus/itemRemove.py @@ -56,8 +56,8 @@ class ItemRemove(ContextMenu): elif srcContext in ("projectedFit", "projectedModule", "projectedDrone", "projectedFighter"): sFit.removeProjected(fitID, selection[0]) elif srcContext == "commandFit": - sFit.removeCommand(fitID, selection[0]) - + self.mainFrame.command.Submit(cmd.GuiRemoveCommandCommand(fitID, selection[0].ID)) + return wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) diff --git a/gui/builtinContextMenus/project.py b/gui/builtinContextMenus/project.py index f06c29152..dbfa16724 100644 --- a/gui/builtinContextMenus/project.py +++ b/gui/builtinContextMenus/project.py @@ -5,7 +5,7 @@ import gui.globalEvents as GE import wx from service.fit import Fit from service.settings import ContextMenuSettings - +import gui.fitCommands as cmd class Project(ContextMenu): def __init__(self): @@ -35,10 +35,12 @@ class Project(ContextMenu): def activate(self, fullContext, selection, i): sFit = Fit.getInstance() fitID = self.mainFrame.getActiveFit() - trigger = sFit.project(fitID, selection[0]) - if trigger: - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) - self.mainFrame.additionsPane.select("Projected") + self.mainFrame.command.Submit(cmd.GuiAddProjectedCommand(fitID, selection[0].ID, 'item')) + + # trigger = sFit.project(fitID, selection[0]) + # if trigger: + # wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + # self.mainFrame.additionsPane.select("Projected") Project.register() diff --git a/gui/builtinContextMenus/tabbedFits.py b/gui/builtinContextMenus/tabbedFits.py index c55a90b35..689622c3b 100644 --- a/gui/builtinContextMenus/tabbedFits.py +++ b/gui/builtinContextMenus/tabbedFits.py @@ -8,7 +8,7 @@ import gui.mainFrame import gui.globalEvents as GE from gui.contextMenu import ContextMenu from gui.builtinViews.emptyView import BlankPage - +import gui.fitCommands as cmd class TabbedFits(ContextMenu): def __init__(self): @@ -51,17 +51,14 @@ class TabbedFits(ContextMenu): return m def handleSelection(self, event): - sFit = Fit.getInstance() fitID = self.mainFrame.getActiveFit() fit = self.fitLookup[event.Id] if self.context == 'commandView': - sFit.addCommandFit(fitID, fit) + self.mainFrame.command.Submit(cmd.GuiAddCommandCommand(fitID, fit.ID)) elif self.context == 'projected': - sFit.project(fitID, fit) - - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + self.mainFrame.command.Submit(cmd.GuiAddProjectedCommand(fitID, fit.ID, 'fit')) TabbedFits.register() diff --git a/gui/builtinContextMenus/whProjector.py b/gui/builtinContextMenus/whProjector.py index ac0bd5c1b..1ec8252e8 100644 --- a/gui/builtinContextMenus/whProjector.py +++ b/gui/builtinContextMenus/whProjector.py @@ -8,7 +8,7 @@ from service.fit import Fit from service.settings import ContextMenuSettings from itertools import chain import re - +import gui.fitCommands as cmd class WhProjector(ContextMenu): @@ -87,10 +87,8 @@ class WhProjector(ContextMenu): event.Skip() return - sFit = Fit.getInstance() fitID = self.mainFrame.getActiveFit() - sFit.project(fitID, swObj) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + self.mainFrame.command.Submit(cmd.GuiAddProjectedCommand(fitID, swObj.ID, 'item')) def buildMenu(self, data, local_menu, rootMenu, msw): for swType in sorted(data): diff --git a/gui/builtinShipBrowser/fitItem.py b/gui/builtinShipBrowser/fitItem.py index 99cb9e0bb..58aa0f553 100644 --- a/gui/builtinShipBrowser/fitItem.py +++ b/gui/builtinShipBrowser/fitItem.py @@ -17,7 +17,7 @@ from .events import ImportSelected, SearchSelected, FitSelected, BoosterListUpda from gui.bitmap_loader import BitmapLoader from gui.builtinShipBrowser.pfBitmapFrame import PFBitmapFrame from service.fit import Fit - +import gui.fitCommands as cmd pyfalog = Logger(__name__) @@ -202,18 +202,14 @@ class FitItem(SFItem.SFBrowserItem): if activeFit: sFit = Fit.getInstance() projectedFit = sFit.getFit(self.fitID) - sFit.project(activeFit, projectedFit) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=activeFit)) - self.mainFrame.additionsPane.select("Projected") + if self.mainFrame.command.Submit(cmd.GuiAddProjectedCommand(activeFit, projectedFit.ID, 'fit')): + self.mainFrame.additionsPane.select("Projected") def OnAddCommandFit(self, event): activeFit = self.mainFrame.getActiveFit() if activeFit: - sFit = Fit.getInstance() - commandFit = sFit.getFit(self.fitID) - sFit.addCommandFit(activeFit, commandFit) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=activeFit)) - self.mainFrame.additionsPane.select("Command") + if self.mainFrame.command.Submit(cmd.GuiAddCommandCommand(activeFit, self.fitID)): + self.mainFrame.additionsPane.select("Command") def OnMouseCaptureLost(self, event): """ Destroy drag information (GH issue #479)""" diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index 7e16fecbb..f253af60c 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -12,3 +12,5 @@ from .guiRemoveBooster import GuiRemoveBoosterCommand from .guiAddCommand import GuiAddCommandCommand from .guiRemoveCommand import GuiRemoveCommandCommand from .guiSetMode import GuiSetModeCommand +from .guiToggleCommand import GuiToggleCommandCommand +from .guiAddProjected import GuiAddProjectedCommand \ No newline at end of file diff --git a/gui/fitCommands/calc/fitAddProjectedModule.py b/gui/fitCommands/calc/fitAddProjectedModule.py new file mode 100644 index 000000000..bf9ebf6c2 --- /dev/null +++ b/gui/fitCommands/calc/fitAddProjectedModule.py @@ -0,0 +1,49 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +#from .helpers import ModuleInfoCache +from eos.saveddata.module import Module, State +import eos.db +from logbook import Logger +from eos.saveddata.module import Module +from eos.saveddata.drone import Drone +from eos.saveddata.fighter import Fighter +pyfalog = Logger(__name__) + + +class FitAddProjectedModuleCommand(wx.Command): + """" + from sFit.project + """ + def __init__(self, fitID, itemID): + wx.Command.__init__(self, True) + self.fitID = fitID + self.itemID = itemID + self.new_index = None + + def Do(self): + pyfalog.debug("Projecting fit ({0}) onto: {1}", self.fitID, self.itemID) + fit = eos.db.getFit(self.fitID) + item = eos.db.getItem(self.itemID, eager=("attributes", "group.category")) + + try: + module = Module(item) + except ValueError: + return False + + module.state = State.ACTIVE + if not module.canHaveState(module.state, fit): + module.state = State.OFFLINE + fit.projectedModules.append(module) + + eos.db.commit() + self.new_index = fit.projectedModules.index(module) + return True + + def Undo(self): + from gui.fitCommands.calc.fitRemoveProjectedModule import FitRemoveProjectedModuleCommand # avoids circular import + cmd = FitRemoveProjectedModuleCommand(self.fitID, self.new_index) + cmd.Do() + return True diff --git a/gui/fitCommands/calc/fitRemoveProjectedModule.py b/gui/fitCommands/calc/fitRemoveProjectedModule.py new file mode 100644 index 000000000..ffb398006 --- /dev/null +++ b/gui/fitCommands/calc/fitRemoveProjectedModule.py @@ -0,0 +1,39 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +#from .helpers import ModuleInfoCache +from eos.saveddata.module import Module, State +import eos.db +from logbook import Logger +from eos.saveddata.module import Module +from eos.saveddata.drone import Drone +from eos.saveddata.fighter import Fighter +pyfalog = Logger(__name__) + + +class FitRemoveProjectedModuleCommand(wx.Command): + """" + from sFit.project + """ + def __init__(self, fitID, position): + wx.Command.__init__(self, True) + self.fitID = fitID + self.position = position + self.removed_item = None + + def Do(self): + pyfalog.debug("Removing ({0}) onto: {1}", self.fitID, self.position) + fit = eos.db.getFit(self.fitID) + self.removed_item = fit.projectedModules[self.position].itemID + del fit.projectedModules[self.position] + + eos.db.commit() + return True + + def Undo(self): + from gui.fitCommands.calc.fitAddProjectedModule import FitAddProjectedModuleCommand + cmd = FitAddProjectedModuleCommand(self.fitID, self.removed_item) + cmd.Do() + return True diff --git a/gui/fitCommands/calc/fitToggleCommand.py b/gui/fitCommands/calc/fitToggleCommand.py new file mode 100644 index 000000000..c8adc87ac --- /dev/null +++ b/gui/fitCommands/calc/fitToggleCommand.py @@ -0,0 +1,42 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +#from .helpers import ModuleInfoCache +from eos.saveddata.module import Module, State +import eos.db +from logbook import Logger +pyfalog = Logger(__name__) +from eos.saveddata.implant import Implant + +class FitToggleCommandCommand(wx.Command): + """" + from sFit.toggleCommandFit + """ + def __init__(self, fitID, commandFitId): + wx.Command.__init__(self, True, "Cargo add") + self.fitID = fitID + self.commandFitID = commandFitId + + def Do(self): + pyfalog.debug("Toggle command fit ({0}) for: {1}", self.commandFitID, self.fitID) + commandFit = eos.db.getFit(self.commandFitID) + + if not commandFit: + pyfalog.debug(" -- Command fit not found, deleted?") + return False + + commandInfo = commandFit.getCommandInfo(self.fitID) + + if not commandInfo: + pyfalog.debug(" -- Command fit info not found, deleted?") + return False + + commandInfo.active = not commandInfo.active + eos.db.commit() + return True + + def Undo(self): + cmd = FitToggleCommandCommand(self.fitID, self.commandFitID) + return cmd.Do() diff --git a/gui/fitCommands/guiAddCommand.py b/gui/fitCommands/guiAddCommand.py index 995bc545a..a46da244e 100644 --- a/gui/fitCommands/guiAddCommand.py +++ b/gui/fitCommands/guiAddCommand.py @@ -18,12 +18,14 @@ class GuiAddCommandCommand(wx.Command): def Do(self): if self.internal_history.Submit(self.cmd): wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + self.sFit.recalc(self.fitID) return True return False def Undo(self): - for x in self.internal_history.Commands: + for _ in self.internal_history.Commands: self.internal_history.Undo() + self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiAddProjected.py b/gui/fitCommands/guiAddProjected.py new file mode 100644 index 000000000..e483fb84f --- /dev/null +++ b/gui/fitCommands/guiAddProjected.py @@ -0,0 +1,71 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +from eos.saveddata.module import Module +from .calc.fitAddProjectedModule import FitAddProjectedModuleCommand +from logbook import Logger +import eos.db +pyfalog = Logger(__name__) + + +class GuiAddProjectedCommand(wx.Command): + def __init__(self, fitID, id, type='item'): + wx.Command.__init__(self, True, "Projected Add") + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.sFit = Fit.getInstance() + self.internal_history = wx.CommandProcessor() + self.fitID = fitID + self.id = id + self.type = type + + def Do(self): + result = False + # since we can project various types, we need to switch of the fit command. We can't do this switch easily in + # the fit command since each type might have a different kind of undo, easier to split it out + if self.type == 'item': + item = eos.db.getItem(self.id, eager=("attributes", "group.category")) + + if item.category.name == "Drone": + # @todo: this may need to be reworked once we visit drone commands + pyfalog.warn("DRONE PROJECTION NOT IMPLEMENTED") + # drone = None + # for d in fit.projectedDrones.find(item): + # if d is None or d.amountActive == d.amount or d.amount >= 5: + # drone = d + # break + # + # if drone is None: + # drone = Drone(item) + # fit.projectedDrones.append(drone) + # + # drone.amount += 1 + elif item.category.name == "Fighter": + pyfalog.warn("FIGHTER PROJECTION NOT IMPLEMENTED") + # fighter = Fighter(item) + # fit.projectedFighters.append(fighter) + elif item.group.name in Module.SYSTEM_GROUPS: + pyfalog.warn("WH PROJECTION NOT IMPLEMENTED") + # module = Module(item) + # module.state = State.ONLINE + # fit.projectedModules.append(module) + else: + # attempt a regular module projection + result = self.internal_history.Submit(FitAddProjectedModuleCommand(self.fitID, self.id)) + elif self.type == 'fit': + pyfalog.warn("FIT PROJECTION NOT IMPLEMENTED") + + if result: + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + return True + return False + + def Undo(self): + for _ in self.internal_history.Commands: + self.internal_history.Undo() + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + return True + diff --git a/gui/fitCommands/guiRemoveCommand.py b/gui/fitCommands/guiRemoveCommand.py index d2c13c749..d01abce08 100644 --- a/gui/fitCommands/guiRemoveCommand.py +++ b/gui/fitCommands/guiRemoveCommand.py @@ -17,13 +17,15 @@ class GuiRemoveCommandCommand(wx.Command): def Do(self): if self.internal_history.Submit(self.cmd): + self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True return False def Undo(self): - for x in self.internal_history.Commands: + for _ in self.internal_history.Commands: self.internal_history.Undo() + self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiToggleCommand.py b/gui/fitCommands/guiToggleCommand.py new file mode 100644 index 000000000..b7f07ed78 --- /dev/null +++ b/gui/fitCommands/guiToggleCommand.py @@ -0,0 +1,31 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE +from .calc.fitToggleCommand import FitToggleCommandCommand + +class GuiToggleCommandCommand(wx.Command): + def __init__(self, fitID, commandFitID): + wx.Command.__init__(self, True, "") + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.sFit = Fit.getInstance() + self.internal_history = wx.CommandProcessor() + self.fitID = fitID + # can set his up no to not have to set variables on our object + self.cmd = FitToggleCommandCommand(fitID, commandFitID) + + def Do(self): + if self.internal_history.Submit(self.cmd): + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + return True + return False + + def Undo(self): + for _ in self.internal_history.Commands: + self.internal_history.Undo() + self.sFit.recalc(self.fitID) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) + return True + diff --git a/service/fit.py b/service/fit.py index d581ff07f..4916df143 100644 --- a/service/fit.py +++ b/service/fit.py @@ -397,6 +397,7 @@ class Fit(object): self.recalc(fit) return True + @deprecated def project(self, fitID, thing): pyfalog.debug("Projecting fit ({0}) onto: {1}", fitID, thing) if fitID is None: @@ -496,6 +497,7 @@ class Fit(object): eos.db.commit() self.recalc(fit) + @deprecated def toggleCommandFit(self, fitID, thing): pyfalog.debug("Toggle command fit ({0}) for: {1}", fitID, thing) fit = eos.db.getFit(fitID)