diff --git a/src/Mod/FreeCADExchange/RoutingNetwork.py b/src/Mod/FreeCADExchange/RoutingNetwork.py index 64216ce..0a27f19 100644 --- a/src/Mod/FreeCADExchange/RoutingNetwork.py +++ b/src/Mod/FreeCADExchange/RoutingNetwork.py @@ -1916,6 +1916,8 @@ def create_wire_duct_carriers_from_selection( """Create WireDuct centerline carriers from selected duct-like solids.""" created = [] for index, source in enumerate(_wire_duct_sources_from_selection(selection_ex), start=1): + if _live_source_carrier(doc, source) is not None: + continue bbox = _bound_box_from_object(source) if bbox is None: continue diff --git a/tests/python/freecad_exchange_auto_routing_test.py b/tests/python/freecad_exchange_auto_routing_test.py index 9205f12..74fb726 100644 --- a/tests/python/freecad_exchange_auto_routing_test.py +++ b/tests/python/freecad_exchange_auto_routing_test.py @@ -916,6 +916,37 @@ class AutoRoutingTest(unittest.TestCase): self.assertEqual(1, result["wire_duct_carriers"]) self.assertEqual("selection", result["source_mode"]) + def test_generate_routing_paths_does_not_duplicate_selected_wire_duct_carriers(self): + _install_fake_freecad() + terminal_objects, _wiring_objects, routing_network, _auto_routing = _reload_modules() + auto_routing_panel = importlib.import_module("AutoRoutingPanel") + app = sys.modules["FreeCAD"] + gui = sys.modules["FreeCADGui"] + doc = FakeDocument() + app.ActiveDocument = doc + terminal_objects.ensure_root_group(doc, "project-1") + duct = doc.addObject("Part::Feature", "UnlabeledLongDuct") + duct.Shape = FakeShape(FakeBoundBox(0, 160, -10, 10, 0, 20)) + gui.Selection = types.SimpleNamespace( + getSelection=lambda: [], + getSelectionEx=lambda: [FakeSelectionItem(obj=duct)], + ) + + first = auto_routing_panel.AutoRoutingController().generate_routing_paths() + second = auto_routing_panel.AutoRoutingController().generate_routing_paths() + carriers = routing_network.collect_route_carriers(doc) + + self.assertEqual(1, first["selected_wire_duct_carriers"]) + self.assertEqual(0, second["selected_wire_duct_carriers"]) + self.assertEqual( + 1, + len([item for item in carriers if item.QetRouteCarrierKind == "WireDuct"]), + ) + self.assertEqual( + 2, + len([item for item in carriers if item.QetRouteCarrierKind == "WireDuctOpenEnd"]), + ) + def test_prepare_layout_space_uses_whole_document_not_selected_face_workflow(self): _install_fake_freecad() terminal_objects, _wiring_objects, _routing_network, _auto_routing = _reload_modules()