diff --git a/src/Mod/FreeCADExchange/RoutingNetwork.py b/src/Mod/FreeCADExchange/RoutingNetwork.py index 84ac1cc..d38ef67 100644 --- a/src/Mod/FreeCADExchange/RoutingNetwork.py +++ b/src/Mod/FreeCADExchange/RoutingNetwork.py @@ -1767,14 +1767,26 @@ def create_wiring_cut_out_carriers_from_document(doc, project_uuid=""): """Create pass-through route carriers for wiring cut-out objects.""" created = [] for source in detect_wiring_cut_out_sources(doc): - if _live_source_carrier(doc, source) is not None: - continue bbox = _bound_box_from_object(source) if bbox is None: continue points = _wiring_cut_out_points_from_bbox(bbox) if len(points) < 2: continue + live_carrier = _live_source_carrier(doc, source) + if live_carrier is not None: + if _update_route_carrier( + live_carrier, + points, + project_uuid=project_uuid, + kind=ROUTE_CARRIER_KIND_WIRING_CUT_OUT, + ): + _mark_wiring_cut_out_source(source, live_carrier) + try: + doc.recompute() + except Exception: + pass + continue label = getattr(source, "Label", "") or getattr(source, "Name", "") or "Wiring Cut-Out" carrier = create_route_carrier( doc, diff --git a/tests/python/freecad_exchange_auto_routing_test.py b/tests/python/freecad_exchange_auto_routing_test.py index a554259..927880a 100644 --- a/tests/python/freecad_exchange_auto_routing_test.py +++ b/tests/python/freecad_exchange_auto_routing_test.py @@ -1140,6 +1140,32 @@ class AutoRoutingTest(unittest.TestCase): self.assertEqual(1, len(cut_out_carriers)) self.assertEqual("PassThrough", cut_out.QetRoutingObstacleMode) + def test_generate_routing_path_network_refreshes_wiring_cut_out_geometry(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"] + doc = FakeDocument() + app.ActiveDocument = doc + terminal_objects.ensure_root_group(doc, "project-1") + cut_out = doc.addObject("Part::Feature", "WiringCutoutA") + cut_out.Label = "Wiring Cut-Out A" + cut_out.Shape = FakeShape(FakeBoundBox(45, 55, -2, 2, 15, 25)) + + first = auto_routing_panel.AutoRoutingController().generate_routing_paths() + cut_out.Shape = FakeShape(FakeBoundBox(65, 75, -2, 2, 15, 25)) + second = auto_routing_panel.AutoRoutingController().generate_routing_paths() + cut_out_carriers = [ + carrier + for carrier in routing_network.collect_route_carriers(doc) + if getattr(carrier, "QetRouteCarrierKind", "") == "WiringCutOut" + ] + + self.assertEqual(1, first["wiring_cut_out_carriers"]) + self.assertEqual(0, second["wiring_cut_out_carriers"]) + self.assertEqual(1, len(cut_out_carriers)) + self.assertEqual([(70.0, -2.0, 20.0), (70.0, 2.0, 20.0)], [(p.x, p.y, p.z) for p in cut_out_carriers[0].Points]) + def test_check_routing_path_network_writes_diagnostic_for_unconnected_terminal(self): _install_fake_freecad() terminal_objects, _wiring_objects, routing_network, auto_routing = _reload_modules()