From af660af3390c166f640c71e46bb261c12e1d5e01 Mon Sep 17 00:00:00 2001 From: Zhaowenlong Date: Sat, 30 May 2026 17:11:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=B8=83=E7=BA=BF=E6=9B=BF=E6=8D=A2=E5=A4=B1=E8=B4=A5=E5=9B=9E?= =?UTF-8?q?=E6=BB=9A?= 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 | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/Mod/FreeCADExchange/AutoRouting.py b/src/Mod/FreeCADExchange/AutoRouting.py index fce56d0..9437829 100644 --- a/src/Mod/FreeCADExchange/AutoRouting.py +++ b/src/Mod/FreeCADExchange/AutoRouting.py @@ -1115,7 +1115,11 @@ def route_eplan_connection_between_terminals( raise if existing_replacements: - _remove_routing_connection_objects(doc, existing_replacements) + removed_existing = _remove_routing_connection_objects(doc, existing_replacements) + if removed_existing != len(existing_replacements): + if wire is not None: + _remove_routing_connection_objects(doc, [wire]) + raise AutoRoutingError("Failed to replace existing routed connection.") try: doc.recompute() diff --git a/tests/python/freecad_exchange_auto_routing_test.py b/tests/python/freecad_exchange_auto_routing_test.py index f22aca8..bc77a15 100644 --- a/tests/python/freecad_exchange_auto_routing_test.py +++ b/tests/python/freecad_exchange_auto_routing_test.py @@ -504,6 +504,49 @@ class AutoRoutingTest(unittest.TestCase): self.assertEqual([first], routed_wires) self.assertEqual(0, len([obj for obj in doc.Objects if obj.Name == "Wire"])) + def test_eplan_connection_route_keeps_existing_wire_when_old_replacement_removal_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"] + original_remove = auto_routing._remove_routing_connection_objects + + def failing_remove(target_doc, objects): + if first in list(objects or []): + return 0 + return original_remove(target_doc, objects) + + auto_routing._remove_routing_connection_objects = failing_remove + try: + with self.assertRaises(auto_routing.AutoRoutingError): + auto_routing.route_eplan_connection_between_terminals( + doc, + start, + end, + wire_uuid="wire-1", + ) + finally: + auto_routing._remove_routing_connection_objects = original_remove + + routed_wires = list(wiring_objects.iter_routed_wire_objects(doc)) + + self.assertEqual([first], routed_wires) + def test_route_carrier_styles_make_generated_objects_distinguishable(self): _install_fake_freecad() terminal_objects, _wiring_objects, routing_network, _auto_routing = _reload_modules()