Пример #1
0
class GuiRebaseItemsCommand(wx.Command):

    def __init__(self, fitID, rebaseMap):
        wx.Command.__init__(self, True, 'Rebase Items')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.rebaseMap = rebaseMap

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        for mod in fit.modules:
            if mod.itemID in self.rebaseMap:
                cmd = CalcRebaseItemCommand(
                    fitID=self.fitID,
                    containerName='modules',
                    position=mod.modPosition,
                    itemID=self.rebaseMap[mod.itemID],
                    commit=False)
                self.internalHistory.submit(cmd)
            if mod.chargeID in self.rebaseMap:
                cmd = CalcChangeModuleChargesCommand(
                    fitID=self.fitID,
                    projected=False,
                    chargeMap={mod.modPosition: self.rebaseMap[mod.chargeID]})
                self.internalHistory.submit(cmd)
        for containerName in ('drones', 'fighters', 'implants', 'boosters'):
            container = getattr(fit, containerName)
            for obj in container:
                if obj.itemID in self.rebaseMap:
                    cmd = CalcRebaseItemCommand(
                        fitID=self.fitID,
                        containerName=containerName,
                        position=container.index(obj),
                        itemID=self.rebaseMap[obj.itemID],
                        commit=False)
                    self.internalHistory.submit(cmd)
        # Need to process cargo separately as we want to merge items when needed,
        # e.g. FN iron and CN iron into single stack of CN iron
        for cargo in fit.cargo:
            if cargo.itemID in self.rebaseMap:
                amount = cargo.amount
                cmdRemove = CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=cargo.itemID, amount=amount))
                cmdAdd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.rebaseMap[cargo.itemID], amount=amount))
                self.internalHistory.submitBatch(cmdRemove, cmdAdd)
        eos.db.commit()
        sFit.recalc(fit)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return len(self.internalHistory) > 0

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.commit()
        Fit.getInstance().recalc(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #2
0
class GuiChangeLocalFighterMetaCommand(wx.Command):

    def __init__(self, fitID, position, newItemID):
        wx.Command.__init__(self, True, 'Change Local Fighter Meta')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.position = position
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        fighter = fit.fighters[self.position]
        if fighter.itemID == self.newItemID:
            return False
        info = FighterInfo.fromFighter(fighter)
        info.itemID = self.newItemID
        cmdRemove = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position)
        cmdAdd = CalcAddLocalFighterCommand(fitID=self.fitID, fighterInfo=info)
        success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
        sFit.recalc(fit)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        Fit.getInstance().recalc(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #3
0
class GuiChangeLocalDroneMetaCommand(wx.Command):
    def __init__(self, fitID, position, newItemID):
        wx.Command.__init__(self, True, 'Change Local Drone Meta')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.position = position
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        drone = fit.drones[self.position]
        if drone.itemID == self.newItemID:
            return False
        info = DroneInfo.fromDrone(drone)
        info.itemID = self.newItemID
        cmdRemove = CalcRemoveLocalDroneCommand(fitID=self.fitID,
                                                position=self.position,
                                                amount=math.inf)
        cmdAdd = CalcAddLocalDroneCommand(fitID=self.fitID,
                                          droneInfo=info,
                                          forceNewStack=True)
        success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
        sFit.recalc(fit)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        Fit.getInstance().recalc(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success
Пример #4
0
class GuiChangeCargoMetaCommand(wx.Command):

    def __init__(self, fitID, itemID, newItemID):
        wx.Command.__init__(self, True, 'Change Cargo Meta')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.itemID = itemID
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        cargo = next((c for c in fit.cargo if c.itemID == self.itemID), None)
        if cargo is None:
            return False
        if cargo.itemID == self.newItemID:
            return False
        amount = cargo.amount
        cmdRemove = CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf))
        cmdAdd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.newItemID, amount=amount))
        success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        Fit.getInstance().recalc(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #5
0
class GuiChangeProjectedModuleMetaCommand(wx.Command):
    def __init__(self, fitID, position, newItemID):
        wx.Command.__init__(self, True, 'Change Projected Module Meta')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.position = position
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        module = fit.projectedModules[self.position]
        if module.itemID == self.newItemID:
            return
        info = ModuleInfo.fromModule(module)
        info.itemID = self.newItemID
        cmdRemove = CalcRemoveProjectedModuleCommand(fitID=self.fitID,
                                                     position=self.position)
        cmdAdd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=info)
        success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
        sFit.recalc(fit)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        Fit.getInstance().recalc(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success
Пример #6
0
class GuiChangeProjectedFighterMetasCommand(wx.Command):

    def __init__(self, fitID, positions, newItemID):
        wx.Command.__init__(self, True, 'Change Projected Fighter Metas')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.positions = positions
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        results = []
        for position in sorted(self.positions, reverse=True):
            fighter = fit.projectedFighters[position]
            if fighter.itemID == self.newItemID:
                continue
            info = FighterInfo.fromFighter(fighter)
            info.itemID = self.newItemID
            cmdRemove = CalcRemoveProjectedFighterCommand(fitID=self.fitID, position=position, commit=False)
            cmdAdd = CalcAddProjectedFighterCommand(fitID=self.fitID, fighterInfo=info, commit=False)
            results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
        success = any(results)
        eos.db.commit()
        sFit.recalc(fit)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.commit()
        Fit.getInstance().recalc(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #7
0
class GuiAddCommandFitsCommand(wx.Command):

    def __init__(self, fitID, commandFitIDs):
        wx.Command.__init__(self, True, 'Add Command Fits')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.commandFitIDs = commandFitIDs

    def Do(self):
        commands = []
        for commandFitID in self.commandFitIDs:
            cmd = CalcAddCommandCommand(fitID=self.fitID, commandFitID=commandFitID)
            commands.append(cmd)
        if not commands:
            return False
        success = self.internalHistory.submitBatch(*commands)
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
        return success
Пример #8
0
class GuiConvertMutatedLocalDroneCommand(wx.Command):

    def __init__(self, fitID, position, mutaplasmid):
        wx.Command.__init__(self, True, 'Convert Local Drone to Mutated')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.position = position
        self.itemID = mutaplasmid.resultingItem.ID
        self.mutaplasmidID = mutaplasmid.ID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        try:
            drone = fit.drones[self.position]
        except IndexError:
            return False
        if drone.isMutated:
            return False
        info = DroneInfo(
            amount=drone.amount,
            amountActive=drone.amountActive,
            itemID=self.itemID,
            baseItemID=drone.item.ID,
            mutaplasmidID=self.mutaplasmidID,
            mutations={})
        cmdRemove = CalcRemoveLocalDroneCommand(
            fitID=self.fitID,
            position=self.position,
            amount=math.inf)
        cmdAdd = CalcAddLocalDroneCommand(
            fitID=self.fitID,
            droneInfo=info,
            forceNewStack=True,
            ignoreRestrictions=True)
        success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
        eos.db.flush()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
        return success
Пример #9
0
class GuiMergeLocalDroneStacksCommand(wx.Command):
    def __init__(self, fitID, srcPosition, dstPosition):
        wx.Command.__init__(self, True, 'Merge Local Drone Stacks')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.srcPosition = srcPosition
        self.dstPosition = dstPosition

    def Do(self):
        if self.srcPosition == self.dstPosition:
            return False
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        srcDrone = fit.drones[self.srcPosition]
        dstDrone = fit.drones[self.dstPosition]
        if srcDrone.itemID != dstDrone.itemID:
            return False
        srcAmount = srcDrone.amount
        commands = []
        commands.append(
            CalcChangeLocalDroneAmountCommand(fitID=self.fitID,
                                              position=self.dstPosition,
                                              amount=dstDrone.amount +
                                              srcAmount))
        commands.append(
            CalcRemoveLocalDroneCommand(fitID=self.fitID,
                                        position=self.srcPosition,
                                        amount=srcAmount))
        success = self.internalHistory.submitBatch(*commands)
        eos.db.flush()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitIDs=(self.fitID, )))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitIDs=(self.fitID, )))
        return success
Пример #10
0
class GuiChangeProjectedDroneMetasCommand(wx.Command):
    def __init__(self, fitID, itemIDs, newItemID):
        wx.Command.__init__(self, True, 'Change Projected Drone Metas')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.itemIDs = itemIDs
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        results = []
        for itemID in self.itemIDs:
            drone = next(
                (pd for pd in fit.projectedDrones if pd.itemID == itemID),
                None)
            if drone is None:
                continue
            if drone.itemID == self.newItemID:
                continue
            info = DroneInfo.fromDrone(drone)
            info.itemID = self.newItemID
            cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID,
                                                        itemID=itemID,
                                                        amount=math.inf,
                                                        commit=False)
            cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID,
                                                  droneInfo=info,
                                                  commit=False)
            results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
        success = any(results)
        eos.db.commit()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.commit()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success
Пример #11
0
class GuiChangeLocalDroneMetasCommand(wx.Command):

    def __init__(self, fitID, positions, newItemID):
        wx.Command.__init__(self, True, 'Change Local Drone Meta')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.positions = positions
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        results = []
        for position in sorted(self.positions, reverse=True):
            drone = fit.drones[position]
            if drone.itemID == self.newItemID:
                continue
            info = DroneInfo.fromDrone(drone)
            info.itemID = self.newItemID
            cmdRemove = CalcRemoveLocalDroneCommand(
                fitID=self.fitID,
                position=position,
                amount=math.inf)
            cmdAdd = CalcAddLocalDroneCommand(
                fitID=self.fitID,
                droneInfo=info,
                forceNewStack=True,
                ignoreRestrictions=True)
            results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
        success = any(results)
        eos.db.flush()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #12
0
class GuiChangeLocalDroneMetasCommand(wx.Command):

    def __init__(self, fitID, positions, newItemID):
        wx.Command.__init__(self, True, 'Change Local Drone Meta')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.positions = positions
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        results = []
        for position in sorted(self.positions, reverse=True):
            drone = fit.drones[position]
            if drone.itemID == self.newItemID:
                continue
            info = DroneInfo.fromDrone(drone)
            info.itemID = self.newItemID
            cmdRemove = CalcRemoveLocalDroneCommand(
                fitID=self.fitID,
                position=position,
                amount=math.inf,
                commit=False)
            cmdAdd = CalcAddLocalDroneCommand(
                fitID=self.fitID,
                droneInfo=info,
                forceNewStack=True,
                ignoreRestrictions=True,
                commit=False)
            results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
        success = any(results)
        eos.db.commit()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.commit()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #13
0
class GuiChangeProjectedModuleMetasCommand(wx.Command):
    def __init__(self, fitID, positions, newItemID):
        wx.Command.__init__(self, True, 'Change Projected Module Metas')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.positions = positions
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        results = []
        needRecalc = None
        for position in sorted(self.positions, reverse=True):
            module = fit.projectedModules[position]
            if module.itemID == self.newItemID:
                continue
            info = ModuleInfo.fromModule(module)
            info.itemID = self.newItemID
            cmdRemove = CalcRemoveProjectedModuleCommand(fitID=self.fitID,
                                                         position=position)
            cmdAdd = CalcAddProjectedModuleCommand(fitID=self.fitID,
                                                   modInfo=info)
            results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
            # Only last add command counts
            needRecalc = cmdAdd.needsGuiRecalc
        success = any(results)
        if needRecalc:
            eos.db.flush()
            sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitIDs=(self.fitID, )))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitIDs=(self.fitID, )))
        return success
Пример #14
0
class GuiSplitLocalDroneStackCommand(wx.Command):
    def __init__(self, fitID, position, amount):
        wx.Command.__init__(self, True, 'Split Local Drone Stack')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.position = position
        self.amount = amount

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        drone = fit.drones[self.position]
        if self.amount >= drone.amount:
            return False
        info = DroneInfo.fromDrone(drone)
        info.amount = self.amount
        info.amountActive = min(self.amount, info.amountActive)
        commands = []
        commands.append(
            CalcRemoveLocalDroneCommand(fitID=self.fitID,
                                        position=self.position,
                                        amount=self.amount,
                                        commit=False))
        commands.append(
            CalcAddLocalDroneCommand(fitID=self.fitID,
                                     droneInfo=info,
                                     forceNewStack=True,
                                     ignoreRestrictions=True,
                                     commit=False))
        success = self.internalHistory.submitBatch(*commands)
        eos.db.commit()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.commit()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success
Пример #15
0
class GuiSplitLocalDroneStackCommand(wx.Command):

    def __init__(self, fitID, position, amount):
        wx.Command.__init__(self, True, 'Split Local Drone Stack')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.position = position
        self.amount = amount

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        drone = fit.drones[self.position]
        if self.amount >= drone.amount:
            return False
        info = DroneInfo.fromDrone(drone)
        info.amount = self.amount
        info.amountActive = min(self.amount, info.amountActive)
        commands = []
        commands.append(CalcRemoveLocalDroneCommand(
            fitID=self.fitID,
            position=self.position,
            amount=self.amount))
        commands.append(CalcAddLocalDroneCommand(
            fitID=self.fitID,
            droneInfo=info,
            forceNewStack=True,
            ignoreRestrictions=True))
        success = self.internalHistory.submitBatch(*commands)
        eos.db.flush()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #16
0
class GuiMergeLocalDroneStacksCommand(wx.Command):

    def __init__(self, fitID, srcPosition, dstPosition):
        wx.Command.__init__(self, True, 'Merge Local Drone Stacks')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.srcPosition = srcPosition
        self.dstPosition = dstPosition

    def Do(self):
        if self.srcPosition == self.dstPosition:
            return False
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        srcDrone = fit.drones[self.srcPosition]
        dstDrone = fit.drones[self.dstPosition]
        if srcDrone.itemID != dstDrone.itemID:
            return False
        srcAmount = srcDrone.amount
        commands = []
        commands.append(CalcChangeLocalDroneAmountCommand(
            fitID=self.fitID,
            position=self.dstPosition,
            amount=dstDrone.amount + srcAmount))
        commands.append(CalcRemoveLocalDroneCommand(
            fitID=self.fitID,
            position=self.srcPosition,
            amount=srcAmount))
        success = self.internalHistory.submitBatch(*commands)
        eos.db.flush()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #17
0
class GuiChangeCargoMetaCommand(wx.Command):
    def __init__(self, fitID, itemIDs, newItemID):
        wx.Command.__init__(self, True, 'Change Cargo Meta')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.itemIDs = itemIDs
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        results = []
        for itemID in self.itemIDs:
            if itemID == self.newItemID:
                continue
            cargo = next((c for c in fit.cargo if c.itemID == itemID), None)
            if cargo is None:
                continue
            amount = cargo.amount
            cmdRemove = CalcRemoveCargoCommand(fitID=self.fitID,
                                               cargoInfo=CargoInfo(
                                                   itemID=itemID,
                                                   amount=math.inf),
                                               commit=False)
            cmdAdd = CalcAddCargoCommand(fitID=self.fitID,
                                         cargoInfo=CargoInfo(
                                             itemID=self.newItemID,
                                             amount=amount),
                                         commit=False)
            results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
        success = any(results)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success
Пример #18
0
class GuiChangeProjectedDroneMetasCommand(wx.Command):

    def __init__(self, fitID, itemIDs, newItemID):
        wx.Command.__init__(self, True, 'Change Projected Drone Metas')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.itemIDs = itemIDs
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        results = []
        for itemID in self.itemIDs:
            drone = next((pd for pd in fit.projectedDrones if pd.itemID == itemID), None)
            if drone is None:
                continue
            if drone.itemID == self.newItemID:
                continue
            info = DroneInfo.fromDrone(drone)
            info.itemID = self.newItemID
            cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID, itemID=itemID, amount=math.inf)
            cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=info)
            results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
        success = any(results)
        eos.db.flush()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #19
0
class GuiChangeProjectedModuleMetasCommand(wx.Command):

    def __init__(self, fitID, positions, newItemID):
        wx.Command.__init__(self, True, 'Change Projected Module Metas')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.positions = positions
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        results = []
        for position in sorted(self.positions, reverse=True):
            module = fit.projectedModules[position]
            if module.itemID == self.newItemID:
                continue
            info = ModuleInfo.fromModule(module)
            info.itemID = self.newItemID
            cmdRemove = CalcRemoveProjectedModuleCommand(fitID=self.fitID, position=position)
            cmdAdd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=info)
            results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
        success = any(results)
        eos.db.flush()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #20
0
class GuiChangeCargoMetasCommand(wx.Command):

    def __init__(self, fitID, itemIDs, newItemID):
        wx.Command.__init__(self, True, 'Change Cargo Metas')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.itemIDs = itemIDs
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        results = []
        for itemID in self.itemIDs:
            if itemID == self.newItemID:
                continue
            cargo = next((c for c in fit.cargo if c.itemID == itemID), None)
            if cargo is None:
                continue
            amount = cargo.amount
            cmdRemove = CalcRemoveCargoCommand(
                fitID=self.fitID,
                cargoInfo=CargoInfo(itemID=itemID, amount=math.inf))
            cmdAdd = CalcAddCargoCommand(
                fitID=self.fitID,
                cargoInfo=CargoInfo(itemID=self.newItemID, amount=amount))
            results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
        success = any(results)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #21
0
class GuiChangeProjectedDroneMetaCommand(wx.Command):
    def __init__(self, fitID, itemID, newItemID):
        wx.Command.__init__(self, True, 'Change Projected Drone Meta')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.itemID = itemID
        self.newItemID = newItemID

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        drone = next(
            (pd for pd in fit.projectedDrones if pd.itemID == self.itemID),
            None)
        if drone is None:
            return False
        if drone.itemID == self.newItemID:
            return False
        info = DroneInfo.fromDrone(drone)
        info.itemID = self.newItemID
        cmdRemove = CalcRemoveProjectedDroneCommand(fitID=self.fitID,
                                                    itemID=self.itemID,
                                                    amount=math.inf)
        cmdAdd = CalcAddProjectedDroneCommand(fitID=self.fitID, droneInfo=info)
        success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
        sFit.recalc(fit)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        Fit.getInstance().recalc(self.fitID)
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                     GE.FitChanged(fitID=self.fitID))
        return success
Пример #22
0
class GuiLocalModuleToCargoCommand(wx.Command):

    def __init__(self, fitID, modPosition, cargoItemID, copy):
        wx.Command.__init__(self, True, 'Local Module to Cargo')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.srcModPosition = modPosition
        self.dstCargoItemID = cargoItemID
        self.copy = copy
        self.removedModItemID = None
        self.addedModItemID = None
        self.savedRemovedDummies = None

    def Do(self):
        fit = Fit.getInstance().getFit(self.fitID)
        srcMod = fit.modules[self.srcModPosition]
        if srcMod.isEmpty:
            return False
        srcModItemID = srcMod.itemID
        dstCargo = next((c for c in fit.cargo if c.itemID == self.dstCargoItemID), None)
        success = False
        # Attempt to swap if we're moving our module onto a module in the cargo hold
        if not self.copy and dstCargo is not None and dstCargo.item.isModule:
            if srcModItemID == self.dstCargoItemID:
                return False
            srcModSlot = srcMod.slot
            newModInfo = ModuleInfo.fromModule(srcMod, unmutate=True)
            newModInfo.itemID = self.dstCargoItemID
            srcModChargeItemID = srcMod.chargeID
            srcModChargeAmount = srcMod.numCharges
            commands = []
            commands.append(CalcRemoveCargoCommand(
                fitID=self.fitID,
                cargoInfo=CargoInfo(itemID=self.dstCargoItemID, amount=1)))
            commands.append(CalcAddCargoCommand(
                fitID=self.fitID,
                # We cannot put mutated items to cargo, so use unmutated item ID
                cargoInfo=CargoInfo(itemID=ModuleInfo.fromModule(srcMod, unmutate=True).itemID, amount=1)))
            cmdReplace = CalcReplaceLocalModuleCommand(
                fitID=self.fitID,
                position=self.srcModPosition,
                newModInfo=newModInfo,
                unloadInvalidCharges=True)
            commands.append(cmdReplace)
            # Submit batch now because we need to have updated info on fit to keep going
            success = self.internalHistory.submitBatch(*commands)
            newMod = fit.modules[self.srcModPosition]
            # Process charge changes if module is moved to proper slot
            if newMod.slot == srcModSlot:
                # If we had to unload charge, add it to cargo
                if cmdReplace.unloadedCharge and srcModChargeItemID is not None:
                    cmdAddCargoCharge = CalcAddCargoCommand(
                        fitID=self.fitID,
                        cargoInfo=CargoInfo(itemID=srcModChargeItemID, amount=srcModChargeAmount))
                    success = self.internalHistory.submit(cmdAddCargoCharge)
                # If we did not unload charge and there still was a charge, see if amount differs and process it
                elif not cmdReplace.unloadedCharge and srcModChargeItemID is not None:
                    # How many extra charges do we need to take from cargo
                    extraChargeAmount = newMod.numCharges - srcModChargeAmount
                    if extraChargeAmount > 0:
                        cmdRemoveCargoExtraCharge = CalcRemoveCargoCommand(
                            fitID=self.fitID,
                            cargoInfo=CargoInfo(itemID=srcModChargeItemID, amount=extraChargeAmount))
                        # Do not check if operation was successful or not, we're okay if we have no such
                        # charges in cargo
                        self.internalHistory.submit(cmdRemoveCargoExtraCharge)
                    elif extraChargeAmount < 0:
                        cmdAddCargoExtraCharge = CalcAddCargoCommand(
                            fitID=self.fitID,
                            cargoInfo=CargoInfo(itemID=srcModChargeItemID, amount=abs(extraChargeAmount)))
                        success = self.internalHistory.submit(cmdAddCargoExtraCharge)
                if success:
                    # Store info to properly send events later
                    self.removedModItemID = srcModItemID
                    self.addedModItemID = self.dstCargoItemID
            # If drag happened to module which cannot be fit into current slot - consider it as failure
            else:
                success = False
            # And in case of any failures, cancel everything to try to do move instead
            if not success:
                self.internalHistory.undoAll()
        # Just dump module and its charges into cargo when copying or moving to cargo
        if not success:
            commands = []
            commands.append(CalcAddCargoCommand(
                fitID=self.fitID,
                cargoInfo=CargoInfo(itemID=ModuleInfo.fromModule(srcMod, unmutate=True).itemID, amount=1)))
            if srcMod.chargeID is not None:
                commands.append(CalcAddCargoCommand(
                    fitID=self.fitID,
                    cargoInfo=CargoInfo(itemID=srcMod.chargeID, amount=srcMod.numCharges)))
            if not self.copy:
                commands.append(CalcRemoveLocalModulesCommand(
                    fitID=self.fitID,
                    positions=[self.srcModPosition]))
            success = self.internalHistory.submitBatch(*commands)
        eos.db.flush()
        sFit = Fit.getInstance()
        sFit.recalc(self.fitID)
        self.savedRemovedDummies = sFit.fill(self.fitID)
        eos.db.commit()
        events = []
        if self.removedModItemID is not None:
            events.append(GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.removedModItemID))
        if self.addedModItemID is not None:
            events.append(GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.addedModItemID))
        if not events:
            events.append(GE.FitChanged(fitID=self.fitID))
        for event in events:
            wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
        return success

    def Undo(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        restoreRemovedDummies(fit, self.savedRemovedDummies)
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        events = []
        if self.addedModItemID is not None:
            events.append(GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.addedModItemID))
        if self.removedModItemID is not None:
            events.append(GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.removedModItemID))
        if not events:
            events.append(GE.FitChanged(fitID=self.fitID))
        for event in events:
            wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
        return success
Пример #23
0
class GuiChangeLocalModuleMetasCommand(wx.Command):
    def __init__(self, fitID, positions, newItemID):
        wx.Command.__init__(self, True, 'Change Local Module Metas')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.positions = positions
        self.newItemID = newItemID
        self.relacedItemIDs = None
        self.savedRemovedDummies = None

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        commands = []
        self.replacedItemIDs = set()
        for position in self.positions:
            module = fit.modules[position]
            if module.isEmpty:
                continue
            if module.itemID == self.newItemID:
                continue
            self.replacedItemIDs.add(module.itemID)
            info = ModuleInfo.fromModule(module)
            info.itemID = self.newItemID
            cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID,
                                                position=position,
                                                newModInfo=info,
                                                unloadInvalidCharges=True)
            commands.append(cmd)
        if not commands:
            return False
        success = self.internalHistory.submitBatch(*commands)
        eos.db.flush()
        sFit.recalc(self.fitID)
        self.savedRemovedDummies = sFit.fill(self.fitID)
        eos.db.commit()
        events = []
        if success and self.replacedItemIDs:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='moddel',
                              typeID=self.replacedItemIDs))
        if success:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='modadd',
                              typeID=self.newItemID))
        if not events:
            events.append(GE.FitChanged(fitID=self.fitID))
        for event in events:
            wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
        return success

    def Undo(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        restoreRemovedDummies(fit, self.savedRemovedDummies)
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        events = []
        if success:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='moddel',
                              typeID=self.newItemID))
        if success and self.replacedItemIDs:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='modadd',
                              typeID=self.replacedItemIDs))
        if not events:
            events.append(GE.FitChanged(fitID=self.fitID))
        for event in events:
            wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
        return success
Пример #24
0
class GuiCargoToLocalModuleCommand(wx.Command):
    """
    Moves cargo to the fitting window. If target is not empty, take whatever we take off and put
    into the cargo hold. If we copy, we do the same but do not remove the item from the cargo hold.
    """
    def __init__(self, fitID, cargoItemID, modPosition, copy):
        wx.Command.__init__(self, True, 'Cargo to Local Module')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.srcCargoItemID = cargoItemID
        self.dstModPosition = modPosition
        self.copy = copy
        self.removedModItemID = None
        self.addedModItemID = None

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        srcCargo = next(
            (c for c in fit.cargo if c.itemID == self.srcCargoItemID), None)
        if srcCargo is None:
            return
        dstMod = fit.modules[self.dstModPosition]
        # Moving/copying charge from cargo to fit
        if srcCargo.item.isCharge and not dstMod.isEmpty:
            newCargoChargeItemID = dstMod.chargeID
            newCargoChargeAmount = dstMod.numCharges
            newModChargeItemID = self.srcCargoItemID
            newModChargeAmount = dstMod.getNumCharges(srcCargo.item)
            if newCargoChargeItemID == newModChargeItemID:
                return False
            commands = []
            if not self.copy:
                commands.append(
                    CalcRemoveCargoCommand(fitID=self.fitID,
                                           cargoInfo=CargoInfo(
                                               itemID=newModChargeItemID,
                                               amount=newModChargeAmount),
                                           commit=False))
            if newCargoChargeItemID is not None:
                commands.append(
                    CalcAddCargoCommand(fitID=self.fitID,
                                        cargoInfo=CargoInfo(
                                            itemID=newCargoChargeItemID,
                                            amount=newCargoChargeAmount),
                                        commit=False))
            commands.append(
                CalcChangeModuleChargesCommand(
                    fitID=self.fitID,
                    projected=False,
                    chargeMap={dstMod.modPosition: self.srcCargoItemID},
                    commit=False))
            success = self.internalHistory.submitBatch(*commands)
        # Moving/copying/replacing module
        elif srcCargo.item.isModule:
            dstModItemID = dstMod.itemID
            dstModSlot = dstMod.slot
            if self.srcCargoItemID == dstModItemID:
                return False
            # To keep all old item properties, copy them over from old module
            newModInfo = ModuleInfo.fromModule(dstMod)
            newModInfo.itemID = self.srcCargoItemID
            if dstMod.isEmpty:
                newCargoModItemID = None
                dstModChargeItemID = None
                dstModChargeAmount = None
            else:
                # We cannot put mutated items to cargo, so use unmutated item ID
                newCargoModItemID = ModuleInfo.fromModule(dstMod,
                                                          unmutate=True).itemID
                dstModChargeItemID = dstMod.chargeID
                dstModChargeAmount = dstMod.numCharges
            commands = []
            # Keep cargo only in case we were copying
            if not self.copy:
                commands.append(
                    CalcRemoveCargoCommand(fitID=self.fitID,
                                           cargoInfo=CargoInfo(
                                               itemID=self.srcCargoItemID,
                                               amount=1),
                                           commit=False))
            # Add item to cargo only if we copied/moved to non-empty slot
            if newCargoModItemID is not None:
                commands.append(
                    CalcAddCargoCommand(
                        fitID=self.fitID,
                        cargoInfo=CargoInfo(itemID=newCargoModItemID,
                                            amount=1),
                        commit=False))
            cmdReplace = CalcReplaceLocalModuleCommand(
                fitID=self.fitID,
                position=self.dstModPosition,
                newModInfo=newModInfo,
                unloadInvalidCharges=True,
                commit=False)
            commands.append(cmdReplace)
            # Submit batch now because we need to have updated info on fit to keep going
            success = self.internalHistory.submitBatch(*commands)
            newMod = fit.modules[self.dstModPosition]
            # Bail if drag happened to slot to which module cannot be dragged, will undo later
            if newMod.slot != dstModSlot:
                success = False
            if success:
                # If we had to unload charge, add it to cargo
                if cmdReplace.unloadedCharge and dstModChargeItemID is not None:
                    cmdAddCargoCharge = CalcAddCargoCommand(
                        fitID=self.fitID,
                        cargoInfo=CargoInfo(itemID=dstModChargeItemID,
                                            amount=dstModChargeAmount),
                        commit=False)
                    success = self.internalHistory.submit(cmdAddCargoCharge)
                # If we did not unload charge and there still was a charge, see if amount differs and process it
                elif not cmdReplace.unloadedCharge and dstModChargeItemID is not None:
                    # How many extra charges do we need to take from cargo
                    extraChargeAmount = newMod.numCharges - dstModChargeAmount
                    if extraChargeAmount > 0:
                        cmdRemoveCargoExtraCharge = CalcRemoveCargoCommand(
                            fitID=self.fitID,
                            cargoInfo=CargoInfo(itemID=dstModChargeItemID,
                                                amount=extraChargeAmount),
                            commit=False)
                        # Do not check if operation was successful or not, we're okay if we have no such
                        # charges in cargo
                        self.internalHistory.submit(cmdRemoveCargoExtraCharge)
                    elif extraChargeAmount < 0:
                        cmdAddCargoExtraCharge = CalcAddCargoCommand(
                            fitID=self.fitID,
                            cargoInfo=CargoInfo(itemID=dstModChargeItemID,
                                                amount=abs(extraChargeAmount)),
                            commit=False)
                        success = self.internalHistory.submit(
                            cmdAddCargoExtraCharge)
            if success:
                # Store info to properly send events later
                self.removedModItemID = dstModItemID
                self.addedModItemID = self.srcCargoItemID
            else:
                self.internalHistory.undoAll()
        else:
            return False
        eos.db.commit()
        sFit.recalc(fit)
        events = []
        if self.removedModItemID is not None:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='moddel',
                              typeID=self.removedModItemID))
        if self.addedModItemID is not None:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='modadd',
                              typeID=self.addedModItemID))
        if not events:
            events.append(GE.FitChanged(fitID=self.fitID))
        for event in events:
            wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.commit()
        Fit.getInstance().recalc(self.fitID)
        events = []
        if self.addedModItemID is not None:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='moddel',
                              typeID=self.addedModItemID))
        if self.removedModItemID is not None:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='modadd',
                              typeID=self.removedModItemID))
        if not events:
            events.append(GE.FitChanged(fitID=self.fitID))
        for event in events:
            wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
        return success
Пример #25
0
class GuiRebaseItemsCommand(wx.Command):

    def __init__(self, fitID, rebaseMap):
        wx.Command.__init__(self, True, 'Rebase Items')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.rebaseMap = rebaseMap

    def Do(self):
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        for mod in fit.modules:
            if mod.itemID in self.rebaseMap:
                cmd = CalcRebaseItemCommand(
                    fitID=self.fitID,
                    containerName='modules',
                    position=fit.modules.index(mod),
                    itemID=self.rebaseMap[mod.itemID])
                self.internalHistory.submit(cmd)
            if mod.chargeID in self.rebaseMap:
                cmd = CalcChangeModuleChargesCommand(
                    fitID=self.fitID,
                    projected=False,
                    chargeMap={fit.modules.index(mod): self.rebaseMap[mod.chargeID]})
                self.internalHistory.submit(cmd)
        for containerName in ('drones', 'fighters', 'implants', 'boosters'):
            container = getattr(fit, containerName)
            for obj in container:
                if obj.itemID in self.rebaseMap:
                    cmd = CalcRebaseItemCommand(
                        fitID=self.fitID,
                        containerName=containerName,
                        position=container.index(obj),
                        itemID=self.rebaseMap[obj.itemID])
                    self.internalHistory.submit(cmd)
        # Need to process cargo separately as we want to merge items when needed,
        # e.g. FN iron and CN iron into single stack of CN iron
        for cargo in fit.cargo:
            if cargo.itemID in self.rebaseMap:
                amount = cargo.amount
                cmdRemove = CalcRemoveCargoCommand(
                    fitID=self.fitID,
                    cargoInfo=CargoInfo(itemID=cargo.itemID, amount=amount))
                cmdAdd = CalcAddCargoCommand(
                    fitID=self.fitID,
                    cargoInfo=CargoInfo(itemID=self.rebaseMap[cargo.itemID], amount=amount))
                self.internalHistory.submitBatch(cmdRemove, cmdAdd)
        eos.db.flush()
        sFit.recalc(fit)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return len(self.internalHistory) > 0

    def Undo(self):
        sFit = Fit.getInstance()
        success = self.internalHistory.undoAll()
        eos.db.flush()
        sFit.recalc(self.fitID)
        sFit.fill(self.fitID)
        eos.db.commit()
        wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
        return success
Пример #26
0
class GuiLocalModuleToCargoCommand(wx.Command):
    def __init__(self, fitID, modPosition, cargoItemID, copy):
        wx.Command.__init__(self, True, 'Local Module to Cargo')
        self.internalHistory = InternalCommandHistory()
        self.fitID = fitID
        self.srcModPosition = modPosition
        self.dstCargoItemID = cargoItemID
        self.copy = copy
        self.removedModItemID = None
        self.addedModItemID = None

    def Do(self):
        fit = Fit.getInstance().getFit(self.fitID)
        srcMod = fit.modules[self.srcModPosition]
        if srcMod.isEmpty:
            return False
        srcModItemID = srcMod.itemID
        dstCargo = next(
            (c for c in fit.cargo if c.itemID == self.dstCargoItemID), None)
        success = False
        # Attempt to swap if we're moving our module onto a module in the cargo hold
        if not self.copy and dstCargo is not None and dstCargo.item.isModule:
            if srcModItemID == self.dstCargoItemID:
                return False
            srcModSlot = srcMod.slot
            newModInfo = ModuleInfo.fromModule(srcMod, unmutate=True)
            newModInfo.itemID = self.dstCargoItemID
            srcModChargeItemID = srcMod.chargeID
            srcModChargeAmount = srcMod.numCharges
            commands = []
            commands.append(
                CalcRemoveCargoCommand(fitID=self.fitID,
                                       cargoInfo=CargoInfo(
                                           itemID=self.dstCargoItemID,
                                           amount=1),
                                       commit=False))
            commands.append(
                CalcAddCargoCommand(
                    fitID=self.fitID,
                    # We cannot put mutated items to cargo, so use unmutated item ID
                    cargoInfo=CargoInfo(itemID=ModuleInfo.fromModule(
                        srcMod, unmutate=True).itemID,
                                        amount=1),
                    commit=False))
            cmdReplace = CalcReplaceLocalModuleCommand(
                fitID=self.fitID,
                position=self.srcModPosition,
                newModInfo=newModInfo,
                unloadInvalidCharges=True,
                commit=False)
            commands.append(cmdReplace)
            # Submit batch now because we need to have updated info on fit to keep going
            success = self.internalHistory.submitBatch(*commands)
            newMod = fit.modules[self.srcModPosition]
            # Process charge changes if module is moved to proper slot
            if newMod.slot == srcModSlot:
                # If we had to unload charge, add it to cargo
                if cmdReplace.unloadedCharge and srcModChargeItemID is not None:
                    cmdAddCargoCharge = CalcAddCargoCommand(
                        fitID=self.fitID,
                        cargoInfo=CargoInfo(itemID=srcModChargeItemID,
                                            amount=srcModChargeAmount),
                        commit=False)
                    success = self.internalHistory.submit(cmdAddCargoCharge)
                # If we did not unload charge and there still was a charge, see if amount differs and process it
                elif not cmdReplace.unloadedCharge and srcModChargeItemID is not None:
                    # How many extra charges do we need to take from cargo
                    extraChargeAmount = newMod.numCharges - srcModChargeAmount
                    if extraChargeAmount > 0:
                        cmdRemoveCargoExtraCharge = CalcRemoveCargoCommand(
                            fitID=self.fitID,
                            cargoInfo=CargoInfo(itemID=srcModChargeItemID,
                                                amount=extraChargeAmount),
                            commit=False)
                        # Do not check if operation was successful or not, we're okay if we have no such
                        # charges in cargo
                        self.internalHistory.submit(cmdRemoveCargoExtraCharge)
                    elif extraChargeAmount < 0:
                        cmdAddCargoExtraCharge = CalcAddCargoCommand(
                            fitID=self.fitID,
                            cargoInfo=CargoInfo(itemID=srcModChargeItemID,
                                                amount=abs(extraChargeAmount)),
                            commit=False)
                        success = self.internalHistory.submit(
                            cmdAddCargoExtraCharge)
                if success:
                    # Store info to properly send events later
                    self.removedModItemID = srcModItemID
                    self.addedModItemID = self.dstCargoItemID
            # If drag happened to module which cannot be fit into current slot - consider it as failure
            else:
                success = False
            # And in case of any failures, cancel everything to try to do move instead
            if not success:
                self.internalHistory.undoAll()
        # Just dump module and its charges into cargo when copying or moving to cargo
        if not success:
            commands = []
            commands.append(
                CalcAddCargoCommand(fitID=self.fitID,
                                    cargoInfo=CargoInfo(
                                        itemID=ModuleInfo.fromModule(
                                            srcMod, unmutate=True).itemID,
                                        amount=1),
                                    commit=False))
            if srcMod.chargeID is not None:
                commands.append(
                    CalcAddCargoCommand(fitID=self.fitID,
                                        cargoInfo=CargoInfo(
                                            itemID=srcMod.chargeID,
                                            amount=srcMod.numCharges),
                                        commit=False))
            if not self.copy:
                commands.append(
                    CalcRemoveLocalModuleCommand(
                        fitID=self.fitID,
                        positions=[self.srcModPosition],
                        commit=False))
            success = self.internalHistory.submitBatch(*commands)
        eos.db.commit()
        Fit.getInstance().recalc(self.fitID)
        events = []
        if self.removedModItemID is not None:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='moddel',
                              typeID=self.removedModItemID))
        if self.addedModItemID is not None:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='modadd',
                              typeID=self.addedModItemID))
        if not events:
            events.append(GE.FitChanged(fitID=self.fitID))
        for event in events:
            wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
        return success

    def Undo(self):
        success = self.internalHistory.undoAll()
        eos.db.commit()
        Fit.getInstance().recalc(self.fitID)
        events = []
        if self.addedModItemID is not None:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='moddel',
                              typeID=self.addedModItemID))
        if self.removedModItemID is not None:
            events.append(
                GE.FitChanged(fitID=self.fitID,
                              action='modadd',
                              typeID=self.removedModItemID))
        if not events:
            events.append(GE.FitChanged(fitID=self.fitID))
        for event in events:
            wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
        return success