示例#1
0
    def Do(self):
        pyfalog.debug('Doing removal of local modules from positions {} on fit {}'.format(self.positions, self.fitID))
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)

        self.savedSubInfos = {}
        self.savedModInfos = {}
        for position in self.positions:
            mod = fit.modules[position]
            if not mod.isEmpty:
                if mod.slot == FittingSlot.SUBSYSTEM:
                    self.savedSubInfos[position] = ModuleInfo.fromModule(mod)
                else:
                    self.savedModInfos[position] = ModuleInfo.fromModule(mod)
                fit.modules.free(position)

        if len(self.savedSubInfos) == 0 and len(self.savedModInfos) == 0:
            return False

        # Need to flush because checkStates sometimes relies on module->fit
        # relationship via .owner attribute, which is handled by SQLAlchemy
        eos.db.flush()
        sFit.recalc(fit)
        self.savedStateCheckChanges = sFit.checkStates(fit, None)
        # If no modules were removed, report that command was not completed
        return True
示例#2
0
    def Do(self):
        pyfalog.debug('Doing removal of projected module from position {} on fit {}'.format(self.position, self.fitID))
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        mod = fit.projectedModules[self.position]
        self.savedModInfo = ModuleInfo.fromModule(mod)
        del fit.projectedModules[self.position]

        # Need to flush because checkStates sometimes relies on module->fit
        # relationship via .owner attribute, which is handled by SQLAlchemy
        eos.db.flush()
        sFit.recalc(fit)
        self.savedStateCheckChanges = sFit.checkStates(fit, None)
        return True
示例#3
0
    def makeRoom(self, proj):
        if proj.isExclusiveSystemEffect:
            # remove other system effects - only 1 per fit plz
            mod = self.currentSystemEffect

            if mod:
                pyfalog.info("System effect occupied with {0}, removing it to make space for {1}".format(mod.item.name, proj.item.name))
                position = self.index(mod)
                # We need to pack up this info, so whatever...
                from gui.fitCommands.helpers import ModuleInfo
                modInfo = ModuleInfo.fromModule(mod)
                self.remove(mod)
                return position, modInfo
        return None, None
示例#4
0
    def Do(self):
        pyfalog.debug(
            'Doing removal of projected module from position {} on fit {}'.
            format(self.position, self.fitID))
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)
        mod = fit.projectedModules[self.position]
        self.savedModInfo = ModuleInfo.fromModule(mod)
        del fit.projectedModules[self.position]

        # Need to flush because checkStates sometimes relies on module->fit
        # relationship via .owner attribute, which is handled by SQLAlchemy
        eos.db.flush()
        sFit.recalc(fit)
        self.savedStateCheckChanges = sFit.checkStates(fit, None)
        return True
示例#5
0
    def makeRoom(self, proj):
        if proj.isExclusiveSystemEffect:
            # remove other system effects - only 1 per fit plz
            mod = self.currentSystemEffect

            if mod:
                pyfalog.info(
                    "System effect occupied with {0}, removing it to make space for {1}"
                    .format(mod.item.name, proj.item.name))
                position = self.index(mod)
                # We need to pack up this info, so whatever...
                from gui.fitCommands.helpers import ModuleInfo
                modInfo = ModuleInfo.fromModule(mod)
                self.remove(mod)
                return position, modInfo
        return None, None
示例#6
0
文件: efs.py 项目: AlanAu/Pyfa
    def getT2MwdSpeed(fit, sFit):
        fitID = fit.ID
        propID = None
        shipHasMedSlots = fit.ship.getModifiedItemAttr("medSlots") > 0
        shipPower = fit.ship.getModifiedItemAttr("powerOutput")
        # Monitors have a 99% reduction to prop mod power requirements
        if fit.ship.name == "Monitor":
            shipPower *= 100
        rigSize = fit.ship.getModifiedItemAttr("rigSize")
        if not shipHasMedSlots:
            return None

        filterVal = Item.groupID == getGroup("Propulsion Module").ID
        propMods = gamedata_session.query(Item).options().filter(
            filterVal).all()
        mapPropData = lambda propName: \
                      next(map(lambda propMod: {"id": propMod.typeID, "powerReq": propMod.attributes["power"].value},
                               (filter(lambda mod: mod.name == propName, propMods))))
        mwd5mn = mapPropData("5MN Microwarpdrive II")
        mwd50mn = mapPropData("50MN Microwarpdrive II")
        mwd500mn = mapPropData("500MN Microwarpdrive II")
        mwd50000mn = mapPropData("50000MN Microwarpdrive II")
        if rigSize == PortEftRigSize.SMALL or rigSize is None:
            propID = mwd5mn["id"] if shipPower > mwd5mn["powerReq"] else None
        elif rigSize == PortEftRigSize.MEDIUM:
            propID = mwd50mn[
                "id"] if shipPower > mwd50mn["powerReq"] else mwd5mn["id"]
        elif rigSize == PortEftRigSize.LARGE:
            propID = mwd500mn[
                "id"] if shipPower > mwd500mn["powerReq"] else mwd50mn["id"]
        elif rigSize == PortEftRigSize.CAPITAL:
            propID = mwd50000mn[
                "id"] if shipPower > mwd50000mn["powerReq"] else mwd500mn["id"]

        if propID is None:
            return None
        CalcAddLocalModuleCommand(fitID, ModuleInfo(itemID=propID)).Do()
        sFit.recalc(fit)
        fit = eos.db.getFit(fitID)
        mwdPropSpeed = fit.maxSpeed
        mwdPosition = list(
            filter(lambda mod: mod.item and mod.item.ID == propID,
                   fit.modules))[0].position
        CalcRemoveLocalModulesCommand(fitID, [mwdPosition]).Do()
        sFit.recalc(fit)
        fit = eos.db.getFit(fitID)
        return mwdPropSpeed
示例#7
0
 def Do(self):
     pyfalog.debug(
         'Doing replacement of local module at position {} to {} on fit {}'.
         format(self.position, self.newModInfo, self.fitID))
     self.unloadedCharge = False
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     oldMod = fit.modules[self.position]
     if not oldMod.isEmpty:
         self.oldModInfo = ModuleInfo.fromModule(oldMod)
     if self.newModInfo == self.oldModInfo:
         return False
     newMod = self.newModInfo.toModule(
         fallbackState=stateLimit(self.newModInfo.itemID))
     if newMod is None:
         return False
     if newMod.slot != oldMod.slot:
         return False
     # Dummy it out in case the next bit fails
     fit.modules.free(self.position)
     if not newMod.fits(fit):
         pyfalog.warning('Module does not fit')
         self.Undo()
         return False
     if not newMod.isValidCharge(newMod.charge):
         if self.unloadInvalidCharges:
             newMod.charge = None
             self.unloadedCharge = True
         else:
             pyfalog.warning('Invalid charge')
             self.Undo()
             return False
     try:
         fit.modules.replace(self.position, newMod)
     except HandledListActionError:
         pyfalog.warning('Failed to replace in list')
         self.Undo()
         return False
     # Need to flush because checkStates sometimes relies on module->fit
     # relationship via .owner attribute, which is handled by SQLAlchemy
     eos.db.flush()
     sFit.recalc(fit)
     self.savedStateCheckChanges = sFit.checkStates(fit, newMod)
     if self.commit:
         eos.db.commit()
     return True
示例#8
0
文件: add.py 项目: bsmr/pyfa-org-Pyfa
 def Do(self):
     cmd = CalcAddLocalModuleCommand(
         fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID))
     success = self.internalHistory.submit(cmd)
     Market.getInstance().storeRecentlyUsed(self.itemID)
     sFit = Fit.getInstance()
     if cmd.needsGuiRecalc:
         eos.db.flush()
         sFit.recalc(self.fitID)
     self.savedRemovedDummies = sFit.fill(self.fitID)
     eos.db.commit()
     wx.PostEvent(
         gui.mainFrame.MainFrame.getInstance(),
         GE.FitChanged(
             fitIDs=(self.fitID, ), action='modadd', typeID=self.itemID)
         if success else GE.FitChanged(fitIDs=(self.fitID, )))
     return success
示例#9
0
 def Do(self):
     results = []
     for position in self.positions:
         cmd = CalcReplaceLocalModuleCommand(
             fitID=self.fitID,
             position=position,
             newModInfo=ModuleInfo(itemID=self.itemID),
             commit=False)
         results.append(self.internalHistory.submit(cmd))
     success = any(results)
     eos.db.commit()
     Fit.getInstance().recalc(self.fitID)
     wx.PostEvent(
         gui.mainFrame.MainFrame.getInstance(),
         GE.FitChanged(
             fitID=self.fitID, action='modadd', typeID=self.itemID)
         if success else GE.FitChanged(fitID=self.fitID))
     return success
示例#10
0
    def Do(self):
        pyfalog.debug(
            'Doing removal of local modules from positions {} on fit {}'.
            format(self.positions, self.fitID))
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)

        for position in self.positions:
            mod = fit.modules[position]
            if not mod.isEmpty:
                self.savedModInfos[position] = ModuleInfo.fromModule(mod)
                fit.modules.free(position)

        sFit.recalc(fit)
        self.savedStateCheckChanges = sFit.checkStates(fit, None)
        if self.commit:
            eos.db.commit()
        # If no modules were removed, report that command was not completed
        return len(self.savedModInfos) > 0
示例#11
0
 def Do(self):
     added_modules = 0
     while True:
         cmd = CalcAddLocalModuleCommand(
             fitID=self.fitID,
             newModInfo=ModuleInfo(itemID=self.itemID),
             commit=False)
         if not self.internalHistory.submit(cmd):
             break
         added_modules += 1
     eos.db.commit()
     Fit.getInstance().recalc(self.fitID)
     success = added_modules > 0
     wx.PostEvent(
         gui.mainFrame.MainFrame.getInstance(),
         GE.FitChanged(
             fitID=self.fitID, action='modadd', typeID=self.itemID)
         if success else GE.FitChanged(fitID=self.fitID))
     return success
示例#12
0
 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, commit=False)
         cmdAdd = CalcAddProjectedModuleCommand(fitID=self.fitID, modInfo=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
示例#13
0
 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)
     if commands[-1].needsGuiRecalc:
         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(fitIDs=(self.fitID, ),
                           action='moddel',
                           typeID=self.replacedItemIDs))
     if success:
         events.append(
             GE.FitChanged(fitIDs=(self.fitID, ),
                           action='modadd',
                           typeID=self.newItemID))
     if not events:
         events.append(GE.FitChanged(fitIDs=(self.fitID, )))
     for event in events:
         wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
     return success
示例#14
0
 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
示例#15
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     mod = fit.modules[self.position]
     if mod.isEmpty:
         return False
     if not mod.isMutated:
         return False
     cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID,
                                         position=self.position,
                                         newModInfo=ModuleInfo(
                                             itemID=mod.baseItemID,
                                             chargeID=mod.chargeID,
                                             state=mod.state,
                                             spoolType=mod.spoolType,
                                             spoolAmount=mod.spoolAmount))
     success = self.internalHistory.submit(cmd)
     sFit.recalc(fit)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitID=self.fitID))
     return success
示例#16
0
 def Do(self):
     pyfalog.debug('Doing replacement of local module at position {} to {} on fit {}'.format(self.position, self.newModInfo, self.fitID))
     self.unloadedCharge = False
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     oldMod = fit.modules[self.position]
     if not oldMod.isEmpty:
         self.oldModInfo = ModuleInfo.fromModule(oldMod)
     if self.newModInfo == self.oldModInfo:
         return False
     newMod = self.newModInfo.toModule(fallbackState=activeStateLimit(self.newModInfo.itemID))
     if newMod is None:
         return False
     if newMod.slot != oldMod.slot:
         return False
     # Dummy it out in case the next bit fails
     fit.modules.free(self.position)
     if not self.ignoreRestrictions and not newMod.fits(fit):
         pyfalog.warning('Module does not fit')
         self.Undo()
         return False
     if not self.ignoreRestrictions and not newMod.isValidCharge(newMod.charge):
         if self.unloadInvalidCharges:
             newMod.charge = None
             self.unloadedCharge = True
         else:
             pyfalog.warning('Invalid charge')
             self.Undo()
             return False
     fit.modules.replace(self.position, newMod)
     if newMod not in fit.modules:
         pyfalog.warning('Failed to replace in list')
         self.Undo()
         return False
     # Need to flush because checkStates sometimes relies on module->fit
     # relationship via .owner attribute, which is handled by SQLAlchemy
     eos.db.flush()
     sFit.recalc(fit)
     self.savedStateCheckChanges = sFit.checkStates(fit, newMod)
     return True
示例#17
0
    def Do(self):
        pyfalog.debug(
            'Doing removal of local modules from positions {} on fit {}'.
            format(self.positions, self.fitID))
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.fitID)

        for position in self.positions:
            mod = fit.modules[position]
            if not mod.isEmpty:
                self.savedModInfos[position] = ModuleInfo.fromModule(mod)
                fit.modules.free(position)

        # Need to flush because checkStates sometimes relies on module->fit
        # relationship via .owner attribute, which is handled by SQLAlchemy
        eos.db.flush()
        sFit.recalc(fit)
        self.savedStateCheckChanges = sFit.checkStates(fit, None)
        if self.commit:
            eos.db.commit()
        # If no modules were removed, report that command was not completed
        return len(self.savedModInfos) > 0
示例#18
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     mod = fit.modules[self.position]
     self.savedItemID = mod.itemID
     info = ModuleInfo.fromModule(mod)
     added_modules = 0
     while True:
         cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=info)
         if not self.internalHistory.submit(cmd):
             break
         added_modules += 1
     eos.db.flush()
     sFit.recalc(self.fitID)
     self.savedRemovedDummies = sFit.fill(self.fitID)
     eos.db.commit()
     success = added_modules > 0
     wx.PostEvent(
         gui.mainFrame.MainFrame.getInstance(),
         GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.savedItemID)
         if success else
         GE.FitChanged(fitID=self.fitID))
     return success
示例#19
0
文件: fill.py 项目: SirAngel029/Pyfa
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     mod = fit.modules[self.position]
     self.savedItemID = mod.itemID
     info = ModuleInfo.fromModule(mod)
     added_modules = 0
     while True:
         cmd = CalcAddLocalModuleCommand(fitID=self.fitID,
                                         newModInfo=info,
                                         commit=False)
         if not self.internalHistory.submit(cmd):
             break
         added_modules += 1
     eos.db.commit()
     sFit.recalc(self.fitID)
     success = added_modules > 0
     wx.PostEvent(
         gui.mainFrame.MainFrame.getInstance(),
         GE.FitChanged(
             fitID=self.fitID, action='modadd', typeID=self.savedItemID)
         if success else GE.FitChanged(fitID=self.fitID))
     return success
示例#20
0
 def Do(self):
     info = ModuleInfo(itemID=self.itemID)
     added_modules = 0
     while True:
         cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=info)
         if not self.internalHistory.submit(cmd):
             break
         added_modules += 1
     Market.getInstance().storeRecentlyUsed(self.itemID)
     sFit = Fit.getInstance()
     # Only last command decides if we need to recalc here or not
     if cmd.needsGuiRecalc:
         eos.db.flush()
         sFit.recalc(self.fitID)
     self.savedRemovedDummies = sFit.fill(self.fitID)
     eos.db.commit()
     success = added_modules > 0
     wx.PostEvent(
         gui.mainFrame.MainFrame.getInstance(),
         GE.FitChanged(
             fitIDs=(self.fitID, ), action='modadd', typeID=self.itemID)
         if success else GE.FitChanged(fitIDs=(self.fitID, )))
     return success
示例#21
0
 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
示例#22
0
 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
示例#23
0
 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