Generate module list. This also injects dummy modules to visually separate racks. These modules are only known to the display, and not the backend, so it's safe.
(self)
| 538 | fitID=self.activeFitID, position1=srcIdx, position2=mod2Position)) |
| 539 | |
| 540 | def generateMods(self): |
| 541 | """ |
| 542 | Generate module list. |
| 543 | |
| 544 | This also injects dummy modules to visually separate racks. These modules are only |
| 545 | known to the display, and not the backend, so it's safe. |
| 546 | """ |
| 547 | |
| 548 | sFit = Fit.getInstance() |
| 549 | fit = sFit.getFit(self.activeFitID) |
| 550 | |
| 551 | slotOrder = [ |
| 552 | FittingSlot.SUBSYSTEM, |
| 553 | FittingSlot.HIGH, |
| 554 | FittingSlot.MED, |
| 555 | FittingSlot.LOW, |
| 556 | FittingSlot.RIG, |
| 557 | FittingSlot.SERVICE |
| 558 | ] |
| 559 | |
| 560 | if fit is not None: |
| 561 | self.mods = [mod for mod in fit.modules if mod is not None] |
| 562 | |
| 563 | def _get_sort_key(mod): |
| 564 | slot = getattr(mod, "slot", None) |
| 565 | try: |
| 566 | slot_index = slotOrder.index(slot) |
| 567 | except ValueError: |
| 568 | # During rapid fit switches we may briefly see transient modules |
| 569 | # with unresolved slot references; keep UI stable by sorting them last. |
| 570 | slot_index = len(slotOrder) |
| 571 | return slot_index, getattr(mod, "position", 0) |
| 572 | |
| 573 | self.mods.sort(key=_get_sort_key) |
| 574 | |
| 575 | # Blanks is a list of indexes that mark non-module positions (such |
| 576 | # as Racks and tactical Modes. This allows us to skip over common |
| 577 | # module operations such as swapping, removing, copying, etc. that |
| 578 | # would otherwise cause complications |
| 579 | self.blanks = [] # preliminary markers where blanks will be inserted |
| 580 | |
| 581 | if sFit.serviceFittingOptions["rackSlots"]: |
| 582 | # flag to know when to add blanks, based on previous slot |
| 583 | if sFit.serviceFittingOptions["rackLabels"] or len(self.mods) == 0: |
| 584 | slotDivider = None |
| 585 | else: |
| 586 | slotDivider = self.mods[0].slot |
| 587 | |
| 588 | # first loop finds where slot dividers must go before modifying self.mods |
| 589 | for i, mod in enumerate(self.mods): |
| 590 | if mod.slot != slotDivider: |
| 591 | slotDivider = mod.slot |
| 592 | self.blanks.append((i, slotDivider)) # where and what |
| 593 | |
| 594 | # second loop modifies self.mods, rewrites self.blanks to represent actual index of blanks |
| 595 | for i, (x, slot) in enumerate(self.blanks): |
| 596 | self.blanks[i] = x + i # modify blanks with actual index |
| 597 | self.mods.insert(x + i, Rack.buildRack(slot, sum(m.slot == slot for m in self.mods))) |