|
|
|
|
@ -629,16 +629,6 @@ def _remove_template_terminal_hints(doc, container):
|
|
|
|
|
return removed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _clear_group_contents(doc, group):
|
|
|
|
|
for child in list(getattr(group, "Group", []) or []):
|
|
|
|
|
child_name = getattr(child, "Name", "")
|
|
|
|
|
if child_name.startswith(TERMINAL_GROUP_PREFIX) or child_name.startswith(WIRE_GROUP_PREFIX):
|
|
|
|
|
continue
|
|
|
|
|
if getattr(child, "QetGroupKind", "").strip() in {GROUP_KIND_TERMINALS, GROUP_KIND_WIRES}:
|
|
|
|
|
continue
|
|
|
|
|
_remove_object_tree(doc, child)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _existing_group_objects(doc, group):
|
|
|
|
|
result = []
|
|
|
|
|
for child in list(getattr(group, "Group", []) or []):
|
|
|
|
|
@ -654,6 +644,19 @@ def _is_exchange_sidecar_group(obj):
|
|
|
|
|
return getattr(obj, "QetGroupKind", "").strip() in {GROUP_KIND_TERMINALS, GROUP_KIND_WIRES}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _existing_model_objects(doc, group):
|
|
|
|
|
return [
|
|
|
|
|
obj
|
|
|
|
|
for obj in _existing_group_objects(doc, group)
|
|
|
|
|
if not _is_exchange_sidecar_group(obj)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _remove_model_objects(doc, objects):
|
|
|
|
|
for obj in list(objects or []):
|
|
|
|
|
_remove_object_tree(doc, obj)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _keep_only_direct_model_children(device_group, direct_model_objects):
|
|
|
|
|
allowed_ids = {id(obj) for obj in direct_model_objects if obj is not None}
|
|
|
|
|
kept_children = []
|
|
|
|
|
@ -902,9 +905,12 @@ def _import_cabinet_model(doc, root_group, cabinet, report):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
project_uuid = getattr(root_group, "QetProjectUuid", "").strip()
|
|
|
|
|
existing_group = _find_cabinet_group(doc, _cabinet_instance_id(cabinet))
|
|
|
|
|
previous_path = ""
|
|
|
|
|
if existing_group is not None:
|
|
|
|
|
previous_path = getattr(existing_group, "QetCabinetResolvedScenePath", "").strip()
|
|
|
|
|
cabinet_group = _ensure_cabinet_model_group(doc, root_group, cabinet, project_uuid)
|
|
|
|
|
existing_model_objects = _existing_group_objects(doc, cabinet_group)
|
|
|
|
|
previous_path = getattr(cabinet_group, "QetCabinetResolvedScenePath", "").strip()
|
|
|
|
|
existing_model_objects = _existing_model_objects(doc, cabinet_group)
|
|
|
|
|
same_source = _normalized_path_key(previous_path) == _normalized_path_key(resolved_scene_path)
|
|
|
|
|
if existing_model_objects and same_source:
|
|
|
|
|
report.setdefault("cabinet_reused", 0)
|
|
|
|
|
@ -917,7 +923,6 @@ def _import_cabinet_model(doc, root_group, cabinet, report):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
had_existing_model = bool(existing_model_objects)
|
|
|
|
|
_clear_group_contents(doc, cabinet_group)
|
|
|
|
|
_ensure_string_property(
|
|
|
|
|
cabinet_group,
|
|
|
|
|
"QetCabinetResolvedScenePath",
|
|
|
|
|
@ -938,6 +943,7 @@ def _import_cabinet_model(doc, root_group, cabinet, report):
|
|
|
|
|
merge=False,
|
|
|
|
|
use_link_group=True,
|
|
|
|
|
)
|
|
|
|
|
_remove_model_objects(doc, existing_model_objects)
|
|
|
|
|
report["cabinet_imported"] += 1
|
|
|
|
|
if had_existing_model:
|
|
|
|
|
report.setdefault("cabinet_reimported", 0)
|
|
|
|
|
@ -947,6 +953,14 @@ def _import_cabinet_model(doc, root_group, cabinet, report):
|
|
|
|
|
report["cabinet_added"] += 1
|
|
|
|
|
_append_debug_log("DeviceImport cabinet import succeeded")
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
if had_existing_model:
|
|
|
|
|
_ensure_string_property(
|
|
|
|
|
cabinet_group,
|
|
|
|
|
"QetCabinetResolvedScenePath",
|
|
|
|
|
"QET Exchange",
|
|
|
|
|
"Resolved local cabinet scene path from QET exchange",
|
|
|
|
|
previous_path,
|
|
|
|
|
)
|
|
|
|
|
report["cabinet_skipped_import_error"] += 1
|
|
|
|
|
report["warnings"].append(
|
|
|
|
|
"机柜 3D 导入失败:{0}".format(exc)
|
|
|
|
|
@ -1039,6 +1053,9 @@ def import_devices_from_payload(payload, scene_path=""):
|
|
|
|
|
instance_id = existing_instance_id or _generate_instance_id(project_uuid, element_uuid)
|
|
|
|
|
report.setdefault("generated_instance_ids", 0)
|
|
|
|
|
report["generated_instance_ids"] += 1
|
|
|
|
|
previous_model_path = ""
|
|
|
|
|
if existing_group is not None:
|
|
|
|
|
previous_model_path = getattr(existing_group, "QetResolvedModelPath", "").strip()
|
|
|
|
|
device_group, created_now = _ensure_device_group(
|
|
|
|
|
doc,
|
|
|
|
|
root_group,
|
|
|
|
|
@ -1048,7 +1065,7 @@ def import_devices_from_payload(payload, scene_path=""):
|
|
|
|
|
display_tag,
|
|
|
|
|
index,
|
|
|
|
|
)
|
|
|
|
|
_clear_group_contents(doc, device_group)
|
|
|
|
|
existing_model_objects = _existing_model_objects(doc, device_group)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
_append_debug_log(
|
|
|
|
|
@ -1060,7 +1077,16 @@ def import_devices_from_payload(payload, scene_path=""):
|
|
|
|
|
_append_debug_log(
|
|
|
|
|
"DeviceImport import succeeded for element_uuid={0}".format(element_uuid)
|
|
|
|
|
)
|
|
|
|
|
_remove_model_objects(doc, existing_model_objects)
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
if existing_model_objects:
|
|
|
|
|
_ensure_string_property(
|
|
|
|
|
device_group,
|
|
|
|
|
"QetResolvedModelPath",
|
|
|
|
|
"QET Exchange",
|
|
|
|
|
"Resolved local model path from QET exchange",
|
|
|
|
|
previous_model_path,
|
|
|
|
|
)
|
|
|
|
|
report["skipped_import_error"] += 1
|
|
|
|
|
report["warnings"].append(
|
|
|
|
|
"{0} 导入失败:{1}".format(
|
|
|
|
|
|