From 065ae182e36a3b41c496cdcc83dd9a08071691a8 Mon Sep 17 00:00:00 2001 From: Zhaowenlong Date: Sat, 30 May 2026 16:50:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=9D=E7=95=99FreeCAD=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=B8=83=E7=BA=BF=E5=A4=B1=E8=B4=A5=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E6=97=A7=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Mod/FreeCADExchange/AutoRouting.py | 6 ++-- .../freecad_exchange_auto_routing_test.py | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Mod/FreeCADExchange/AutoRouting.py b/src/Mod/FreeCADExchange/AutoRouting.py index 5ec44c7..bba9eb4 100644 --- a/src/Mod/FreeCADExchange/AutoRouting.py +++ b/src/Mod/FreeCADExchange/AutoRouting.py @@ -1028,9 +1028,6 @@ def route_eplan_connection_between_terminals( if not project_uuid: raise AutoRoutingError("Project UUID is required for routing connections.") - if opts.get("replace_existing", True): - _remove_existing_routing_connections(doc, start_uuid, end_uuid, wire_uuid=wire_uuid) - route_data = build_network_route( start_terminal, end_terminal, @@ -1054,6 +1051,9 @@ def route_eplan_connection_between_terminals( collisions = detect_collisions(points, obstacles, ignored_segment_indices=ignored_collision_segments) status = "CollisionWarning" if collisions else "Routed" + if opts.get("replace_existing", True): + _remove_existing_routing_connections(doc, start_uuid, end_uuid, wire_uuid=wire_uuid) + wire_name = _unique_name(doc, _wire_object_name(start_terminal, end_terminal, wire_uuid)) wire = _create_wire_geometry(doc, wire_name, points) wire.Label = wire_label or wire_mark or wire_uuid or "QET Routed Connection" diff --git a/tests/python/freecad_exchange_auto_routing_test.py b/tests/python/freecad_exchange_auto_routing_test.py index 5a43b75..cb39904 100644 --- a/tests/python/freecad_exchange_auto_routing_test.py +++ b/tests/python/freecad_exchange_auto_routing_test.py @@ -362,6 +362,40 @@ class AutoRoutingTest(unittest.TestCase): self.assertEqual("terminal-start-new", routed_wires[0].QetStartTerminalUuid) self.assertEqual("terminal-end-new", routed_wires[0].QetEndTerminalUuid) + def test_eplan_connection_route_keeps_existing_wire_when_replacement_fails(self): + _install_fake_freecad() + terminal_objects, wiring_objects, routing_network, auto_routing = _reload_modules() + app = sys.modules["FreeCAD"] + doc = FakeDocument() + terminal_objects.ensure_root_group(doc, "project-1") + start = _terminal(doc, terminal_objects, "TerminalStart", "terminal-start", app.Vector(0, 0, 0)) + end = _terminal(doc, terminal_objects, "TerminalEnd", "terminal-end", app.Vector(100, 0, 0)) + routing_network.create_route_carrier( + doc, + [app.Vector(0, 0, 20), app.Vector(100, 0, 20)], + project_uuid="project-1", + kind="WireDuct", + ) + first = auto_routing.route_eplan_connection_between_terminals( + doc, + start, + end, + wire_uuid="wire-1", + )["wire"] + routing_network.clear_route_carriers(doc) + + with self.assertRaises(auto_routing.AutoRoutingError): + auto_routing.route_eplan_connection_between_terminals( + doc, + start, + end, + wire_uuid="wire-1", + ) + routed_wires = list(wiring_objects.iter_routed_wire_objects(doc)) + + self.assertEqual([first], routed_wires) + self.assertIsNotNone(doc.getObject(first.Name)) + def test_route_carrier_styles_make_generated_objects_distinguishable(self): _install_fake_freecad() terminal_objects, _wiring_objects, routing_network, _auto_routing = _reload_modules()