diff --git a/docs/FreeCAD 3D自动布线设计方案.md b/docs/FreeCAD 3D自动布线设计方案.md index 10e1b22..8d6ab5b 100644 --- a/docs/FreeCAD 3D自动布线设计方案.md +++ b/docs/FreeCAD 3D自动布线设计方案.md @@ -374,7 +374,7 @@ QetWiringCutOutBridgeExtensionMm = 20.0 如果多条导线共用同一路径并触发 lane 偏移,批量报告会显示最大 lane 编号和 lane 间距。这个值用于确认当前结果是否只是完全重叠的导线,还是已经按共路情况做了可视错位;它仍然是显示层偏移,不等于真实线槽截面排布或填充率计算。 -当最大并行线数超过 route track 中记录的路径最小容量时,批量报告会给出容量提示。这个提示只基于 `QetRouteCarrierCapacity` 和当前 lane 情况,用于暴露“可能容量不足”的调试线索,不等同于按线径、截面积和线槽填充率计算的工程容量校核。 +当单条路线的最大并行线数超过该路线 route track 中记录的路径最小容量时,批量报告会给出容量提示。这个提示只基于 `QetRouteCarrierCapacity` 和当前 lane 情况,用于暴露“可能容量不足”的调试线索,不等同于按线径、截面积和线槽填充率计算的工程容量校核。 ### 5.3 布线连接功能 diff --git a/src/Mod/FreeCADExchange/AutoRouting.py b/src/Mod/FreeCADExchange/AutoRouting.py index 114586e..f908e84 100644 --- a/src/Mod/FreeCADExchange/AutoRouting.py +++ b/src/Mod/FreeCADExchange/AutoRouting.py @@ -1796,24 +1796,27 @@ def _route_track_min_capacity(route_track): return min(capacities) -def _route_capacity_pressure_summary(report, lane_summary): - if not lane_summary: - return {} - max_parallel_wires = int(lane_summary.get("max_lane_index", 0) or 0) + 1 - min_capacity = None +def _route_capacity_pressure_summary(report): + pressure = {} for route in report.get("routes", []) or []: if not isinstance(route, dict): continue + lane = route.get("lane", {}) + if not isinstance(lane, dict): + continue + try: + max_parallel_wires = int(lane.get("index", 0) or 0) + 1 + except Exception: + max_parallel_wires = 1 route_capacity = _route_track_min_capacity(route.get("route_track", {})) - if route_capacity is None: + if route_capacity is None or max_parallel_wires <= route_capacity: continue - min_capacity = route_capacity if min_capacity is None else min(min_capacity, route_capacity) - if min_capacity is None or max_parallel_wires <= min_capacity: - return {} - return { - "max_parallel_wires": max_parallel_wires, - "min_capacity": min_capacity, - } + if not pressure or max_parallel_wires > pressure.get("max_parallel_wires", 0): + pressure = { + "max_parallel_wires": max_parallel_wires, + "min_capacity": route_capacity, + } + return pressure def format_eplan_connection_route_report(report): @@ -1873,7 +1876,7 @@ def format_eplan_connection_route_report(report): lane_summary.get("max_lane_index", 0), float(lane_summary.get("spacing_mm", 0.0) or 0.0), ) - capacity_pressure = _route_capacity_pressure_summary(report, lane_summary) + capacity_pressure = _route_capacity_pressure_summary(report) if capacity_pressure: message += "\n容量提示:最大并行线数 {0},路径最小容量 {1}。".format( capacity_pressure.get("max_parallel_wires", 0), diff --git a/tests/python/freecad_exchange_auto_routing_test.py b/tests/python/freecad_exchange_auto_routing_test.py index 6a1757b..aacca32 100644 --- a/tests/python/freecad_exchange_auto_routing_test.py +++ b/tests/python/freecad_exchange_auto_routing_test.py @@ -2271,6 +2271,37 @@ class AutoRoutingTest(unittest.TestCase): self.assertIn("容量提示:最大并行线数 3,路径最小容量 2。", message) + def test_route_report_capacity_pressure_is_checked_per_route(self): + _install_fake_freecad() + _terminal_objects, _wiring_objects, _routing_network, auto_routing = _reload_modules() + report = { + "routed": 2, + "collision_warnings": 0, + "skipped_missing_terminal": 0, + "routes": [ + { + "lane": {"index": 2, "spacing_mm": 10.0}, + "route_track": { + "segments": [ + {"carrier": {"kind": "WireDuct", "capacity": 4}}, + ] + }, + }, + { + "lane": {"index": 0, "spacing_mm": 10.0}, + "route_track": { + "segments": [ + {"carrier": {"kind": "WireDuct", "capacity": 1}}, + ] + }, + }, + ], + } + + message = auto_routing.format_eplan_connection_route_report(report) + + self.assertNotIn("容量提示", message) + def test_route_eplan_connections_report_keeps_route_identity_and_diagnostics(self): _install_fake_freecad() terminal_objects, _wiring_objects, routing_network, auto_routing = _reload_modules()