Add a module from the market browser (from dragging it)
(self, x, y, itemID)
| 431 | fitID=self.activeFitID, positions=positions)) |
| 432 | |
| 433 | def addModule(self, x, y, itemID): |
| 434 | """Add a module from the market browser (from dragging it)""" |
| 435 | fitID = self.mainFrame.getActiveFit() |
| 436 | item = Market.getInstance().getItem(itemID) |
| 437 | fit = Fit.getInstance().getFit(fitID) |
| 438 | dstRow, _ = self.HitTest((x, y)) |
| 439 | if dstRow == -1 or dstRow in self.blanks: |
| 440 | dstMod = None |
| 441 | else: |
| 442 | try: |
| 443 | dstMod = self.mods[dstRow] |
| 444 | except IndexError: |
| 445 | dstMod = None |
| 446 | if not isinstance(dstMod, Module): |
| 447 | dstMod = None |
| 448 | if dstMod not in fit.modules: |
| 449 | dstMod = None |
| 450 | dstPos = fit.modules.index(dstMod) if dstMod is not None else None |
| 451 | mstate = wx.GetMouseState() |
| 452 | # If we dropping on a module, try to replace, or add if replacement fails |
| 453 | if item.isModule and dstMod is not None and not dstMod.isEmpty: |
| 454 | positions = getSimilarModPositions(fit.modules, dstMod) if mstate.GetModifiers() == wx.MOD_ALT else [dstPos] |
| 455 | command = cmd.GuiReplaceLocalModuleCommand(fitID=fitID, itemID=itemID, positions=positions) |
| 456 | if not self.mainFrame.command.Submit(command): |
| 457 | if mstate.GetModifiers() == wx.MOD_ALT: |
| 458 | self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID)) |
| 459 | else: |
| 460 | self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID)) |
| 461 | elif item.isModule: |
| 462 | if mstate.GetModifiers() == wx.MOD_ALT: |
| 463 | self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID)) |
| 464 | elif dstPos is not None: |
| 465 | self.mainFrame.command.Submit(cmd.GuiReplaceLocalModuleCommand(fitID=fitID, itemID=itemID, positions=[dstPos])) |
| 466 | else: |
| 467 | self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID)) |
| 468 | elif item.isSubsystem: |
| 469 | self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID)) |
| 470 | elif item.isCharge: |
| 471 | failoverToAll = False |
| 472 | positionsAll = list(range(len(fit.modules))) |
| 473 | if dstMod is None or dstMod.isEmpty: |
| 474 | positions = positionsAll |
| 475 | elif mstate.GetModifiers() == wx.MOD_ALT: |
| 476 | positions = getSimilarModPositions(fit.modules, dstMod) |
| 477 | failoverToAll = True |
| 478 | else: |
| 479 | positions = [fit.modules.index(dstMod)] |
| 480 | if len(positions) > 0: |
| 481 | command = cmd.GuiChangeLocalModuleChargesCommand(fitID=fitID, positions=positions, chargeItemID=itemID) |
| 482 | if not self.mainFrame.command.Submit(command) and failoverToAll: |
| 483 | self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleChargesCommand( |
| 484 | fitID=fitID, positions=positionsAll, chargeItemID=itemID)) |
| 485 | |
| 486 | |
| 487 | def swapCargo(self, x, y, cargoItemID): |
no test coverage detected