diff --git a/src/Mod/FreeCADExchange/WiringImport.py b/src/Mod/FreeCADExchange/WiringImport.py index 47080a9..b9c9eef 100644 --- a/src/Mod/FreeCADExchange/WiringImport.py +++ b/src/Mod/FreeCADExchange/WiringImport.py @@ -25,6 +25,16 @@ def _bool_value(item, field_name): return bool(item.get(field_name, False)) +def _int_text_value(item, field_name): + value = item.get(field_name, "") + if value is None: + return "" + try: + return str(int(value)).strip() + except Exception: + return str(value).strip() + + def _conductor_uuids(item): values = item.get("conductor_uuids", []) if not isinstance(values, list): @@ -92,6 +102,7 @@ def _normalize_wire_entry(item, index, device_labels=None): "group_uuid": _string_value(item, "group_uuid"), "wire_mark": wire_mark, "wire_mark_is_manual": _bool_value(item, "wire_mark_is_manual"), + "wire_style_id": _int_text_value(item, "wire_style_id"), "start_element_uuid": start_element_uuid, "start_terminal_uuid": start_terminal_uuid, "start_instance_id": _string_value(item, "start_instance_id"), @@ -179,6 +190,7 @@ def _ensure_string_property(obj, prop_name, value, description="QET wire task pr def _set_task_extra_properties(task, entry): _ensure_string_property(task, "QetStartElementUuid", entry["start_element_uuid"]) _ensure_string_property(task, "QetEndElementUuid", entry["end_element_uuid"]) + _ensure_string_property(task, "QetWireStyleId", entry["wire_style_id"]) _ensure_string_property(task, "QetStartTerminalDisplay", entry["start_terminal_display"]) _ensure_string_property(task, "QetEndTerminalDisplay", entry["end_terminal_display"]) _ensure_string_property(task, "QetStartDeviceLabel", entry["start_device_label"]) diff --git a/tests/python/freecad_exchange_wiring_import_test.py b/tests/python/freecad_exchange_wiring_import_test.py index da4f3bd..7036e00 100644 --- a/tests/python/freecad_exchange_wiring_import_test.py +++ b/tests/python/freecad_exchange_wiring_import_test.py @@ -106,6 +106,44 @@ def _reload_modules(): class WiringImportTest(unittest.TestCase): + def test_import_wire_tasks_preserves_auto_routing_metadata(self): + _install_fake_freecad() + terminal_objects, _wiring_objects, wiring_import = _reload_modules() + doc = FakeDocument() + terminal_objects.ensure_root_group(doc, "project-1") + payload = { + "project_uuid": "project-1", + "wires": [ + { + "wire_id": "wire-1", + "wire_label": "W1", + "wire_mark": "N4111", + "wire_mark_is_manual": True, + "wire_style_id": 42, + "net_uuid": "net-1", + "group_uuid": "group-1", + "start_element_uuid": "device-a", + "start_instance_id": "instance-a", + "start_terminal_uuid": "terminal-a", + "start_terminal_display": "A1", + "end_element_uuid": "device-b", + "end_instance_id": "instance-b", + "end_terminal_uuid": "terminal-b", + "end_terminal_display": "B1", + } + ], + } + + report = wiring_import.import_wire_tasks_from_payload(payload, doc) + task = doc.getObject("QETWiring_01_Tasks").Group[0] + + self.assertEqual(1, report["imported_tasks"]) + self.assertEqual("42", task.QetWireStyleId) + self.assertEqual("instance-a", task.QetStartInstanceId) + self.assertEqual("instance-b", task.QetEndInstanceId) + self.assertEqual("A1", task.QetStartTerminalDisplay) + self.assertEqual("B1", task.QetEndTerminalDisplay) + def test_import_wire_tasks_creates_and_updates_qet_tasks(self): _install_fake_freecad() terminal_objects, _wiring_objects, wiring_import = _reload_modules()