diff --git a/src/Mod/FreeCADExchange/AutoRouting.py b/src/Mod/FreeCADExchange/AutoRouting.py index 5f15cc1..caab10e 100644 --- a/src/Mod/FreeCADExchange/AutoRouting.py +++ b/src/Mod/FreeCADExchange/AutoRouting.py @@ -1354,6 +1354,23 @@ def route_eplan_connections_from_payload(doc, payload, options=None, prepared_la return report +def _missing_endpoint_label(sample, side): + terminal_uuid = str(sample.get("{0}_terminal_uuid".format(side), "") or "").strip() + element_uuid = str(sample.get("{0}_element_uuid".format(side), "") or "").strip() + terminal_display = str(sample.get("{0}_terminal_display".format(side), "") or "").strip() + if element_uuid and terminal_display: + label = "{0}/{1}".format(element_uuid, terminal_display) + elif terminal_display: + label = terminal_display + elif element_uuid: + label = element_uuid + else: + return terminal_uuid + if terminal_uuid and terminal_uuid != label: + return "{0} ({1})".format(label, terminal_uuid) + return label + + def format_eplan_connection_route_report(report): message = "批量生成布线连接完成:routed={0}, collision_warnings={1}, missing_terminals={2}".format( report.get("routed", 0), @@ -1441,8 +1458,8 @@ def format_eplan_connection_route_report(report): sample = (report.get("missing_endpoint_samples") or [None])[0] if sample: message += "\n缺失示例:{0} -> {1}".format( - sample.get("start_terminal_uuid", ""), - sample.get("end_terminal_uuid", ""), + _missing_endpoint_label(sample, "start"), + _missing_endpoint_label(sample, "end"), ) return message diff --git a/tests/python/freecad_exchange_auto_routing_test.py b/tests/python/freecad_exchange_auto_routing_test.py index c7c6dde..be90d14 100644 --- a/tests/python/freecad_exchange_auto_routing_test.py +++ b/tests/python/freecad_exchange_auto_routing_test.py @@ -1825,6 +1825,29 @@ class AutoRoutingTest(unittest.TestCase): self.assertIn("首个错误:没有可用的线槽/路由路径网络", message) self.assertIn("缺失示例:terminal-a -> terminal-b", message) + def test_route_eplan_connections_report_includes_readable_missing_endpoint_labels(self): + _install_fake_freecad() + _terminal_objects, _wiring_objects, _routing_network, auto_routing = _reload_modules() + report = { + "routed": 0, + "collision_warnings": 0, + "skipped_missing_terminal": 1, + "missing_endpoint_samples": [ + { + "start_terminal_uuid": "terminal-a", + "start_element_uuid": "device-a", + "start_terminal_display": "A1", + "end_terminal_uuid": "terminal-b", + "end_element_uuid": "device-b", + "end_terminal_display": "B1", + } + ], + } + + message = auto_routing.format_eplan_connection_route_report(report) + + self.assertIn("缺失示例:device-a/A1 (terminal-a) -> device-b/B1 (terminal-b)", message) + def test_route_eplan_connections_report_calls_out_clearance_collision_kind(self): _install_fake_freecad() _terminal_objects, _wiring_objects, _routing_network, auto_routing = _reload_modules()