diff --git a/gui/fitDiffFrame.py b/gui/fitDiffFrame.py index 865d73b8c..2e2c45a3c 100644 --- a/gui/fitDiffFrame.py +++ b/gui/fitDiffFrame.py @@ -22,6 +22,7 @@ import wx from collections import Counter +from eos.const import FittingSlot from service.fit import Fit as svcFit from service.port.eft import exportEft, importEft, _importPrepare from service.const import PortEftOptions @@ -189,13 +190,33 @@ class FitDiffFrame(wx.Frame): fit1_modules = self.getModuleCounts(fit1) fit2_modules = self.getModuleCounts(fit2) - # Diff modules - only show items needed to add - all_module_types = set(fit1_modules.keys()) | set(fit2_modules.keys()) - for module_type in sorted(all_module_types): - count1 = fit1_modules.get(module_type, 0) - count2 = fit2_modules.get(module_type, 0) - if count2 > count1: - diffLines.append(f"{module_type} {count2 - count1}") + # Slot order + slotOrder = [ + FittingSlot.HIGH, + FittingSlot.MED, + FittingSlot.LOW, + FittingSlot.RIG, + FittingSlot.SUBSYSTEM, + FittingSlot.SERVICE, + ] + + # Diff modules by slot - only show items needed to add + for slot in slotOrder: + fit1_slot_modules = fit1_modules.get(slot, Counter()) + fit2_slot_modules = fit2_modules.get(slot, Counter()) + + all_module_types = set(fit1_slot_modules.keys()) | set(fit2_slot_modules.keys()) + slot_diff_lines = [] + for module_type in sorted(all_module_types): + count1 = fit1_slot_modules.get(module_type, 0) + count2 = fit2_slot_modules.get(module_type, 0) + if count2 > count1: + slot_diff_lines.append(f"{module_type} {count2 - count1}") + + if slot_diff_lines: + if diffLines: + diffLines.append("") + diffLines.extend(slot_diff_lines) # Get drone counts fit1_drones = self.getDroneCounts(fit1) @@ -247,18 +268,22 @@ class FitDiffFrame(wx.Frame): return diffLines def getModuleCounts(self, fit): - """Get a counter of module types for a fit. + """Get a counter of module types for a fit, grouped by slot type. + Returns a dict mapping FittingSlot -> Counter of module names. Position doesn't matter, just counts by module name. """ - counts = Counter() + counts_by_slot = {} for module in fit.modules: if module.isEmpty: continue + slot = module.slot + if slot not in counts_by_slot: + counts_by_slot[slot] = Counter() # Use item type name for comparison name = module.item.typeName if module.item else "" - counts[name] += 1 - return counts + counts_by_slot[slot][name] += 1 + return counts_by_slot def getDroneCounts(self, fit): """Get a counter of drone types for a fit."""