From 66502ae505a1cc7eb1101176a380a235da5a4fb0 Mon Sep 17 00:00:00 2001 From: Zhaowenlong Date: Mon, 1 Jun 2026 10:14:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=B7=E6=96=B0=E6=94=AF=E6=92=91?= =?UTF-8?q?=E9=9D=A2=E5=B8=83=E7=BA=BF=E7=BD=91=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Mod/FreeCADExchange/RoutingNetwork.py | 21 +++++++++- .../freecad_exchange_auto_routing_test.py | 38 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/Mod/FreeCADExchange/RoutingNetwork.py b/src/Mod/FreeCADExchange/RoutingNetwork.py index 1bc4109..84ac1cc 100644 --- a/src/Mod/FreeCADExchange/RoutingNetwork.py +++ b/src/Mod/FreeCADExchange/RoutingNetwork.py @@ -1574,6 +1574,7 @@ def _mark_support_surface_source(source, carriers): "Generated route carrier for this source", getattr(carriers[0], "Name", ""), ) + _remember_source_carriers(source, carriers) except Exception: pass @@ -1797,8 +1798,6 @@ def create_surface_carriers_from_document( """Auto-detect thin support panels and create low-priority RoutingRange grids.""" created = [] for source in detect_support_surface_sources(doc): - if _live_source_carrier(doc, source) is not None: - continue bbox = _bound_box_from_object(source) if bbox is None: continue @@ -1809,6 +1808,24 @@ def create_surface_carriers_from_document( offset=offset, margin=margin, ) + live_carriers = _live_source_carriers(doc, source) + if live_carriers: + updated = [] + for carrier, points in zip(live_carriers, grids): + if _update_route_carrier( + carrier, + points, + project_uuid=project_uuid, + kind=ROUTE_CARRIER_KIND_ROUTING_RANGE, + ): + updated.append(carrier) + if updated: + _mark_support_surface_source(source, updated) + try: + doc.recompute() + except Exception: + pass + continue source_created = [] label = getattr(source, "Label", "") or getattr(source, "Name", "") or "Support Surface" for index, points in enumerate(grids, start=1): diff --git a/tests/python/freecad_exchange_auto_routing_test.py b/tests/python/freecad_exchange_auto_routing_test.py index 327b2b4..a554259 100644 --- a/tests/python/freecad_exchange_auto_routing_test.py +++ b/tests/python/freecad_exchange_auto_routing_test.py @@ -851,6 +851,44 @@ class AutoRoutingTest(unittest.TestCase): self.assertFalse(hasattr(cabinet, "QetRoutingSourceKind")) self.assertFalse(hasattr(duct, "QetRoutingSourceKind")) + def test_auto_detect_support_surface_refreshes_routing_range_geometry(self): + _install_fake_freecad() + terminal_objects, _wiring_objects, routing_network, _auto_routing = _reload_modules() + doc = FakeDocument() + terminal_objects.ensure_root_group(doc, "project-1") + panel = doc.addObject("Part::Feature", "MountingPlateA") + panel.Label = "安装板A" + panel.Shape = FakeShape(FakeBoundBox(0, 120, 0, 5, 0, 100)) + + created = routing_network.create_surface_carriers_from_document( + doc, + project_uuid="project-1", + spacing=60.0, + offset=5.0, + margin=0.0, + ) + panel.Shape = FakeShape(FakeBoundBox(20, 140, 0, 5, 0, 100)) + created_again = routing_network.create_surface_carriers_from_document( + doc, + project_uuid="project-1", + spacing=60.0, + offset=5.0, + margin=0.0, + ) + carriers = routing_network.collect_route_carriers(doc) + x_values = [ + point.x + for carrier in carriers + if getattr(carrier, "QetRouteCarrierKind", "") == "RoutingRange" + for point in carrier.Points + ] + + self.assertEqual(6, len(created)) + self.assertEqual(0, len(created_again)) + self.assertEqual(6, len([carrier for carrier in carriers if carrier.QetRouteCarrierKind == "RoutingRange"])) + self.assertEqual(20.0, min(x_values)) + self.assertEqual(140.0, max(x_values)) + def test_eplan_connection_route_can_use_auto_detected_support_surface(self): _install_fake_freecad() terminal_objects, _wiring_objects, routing_network, auto_routing = _reload_modules()