|
|
|
|
@ -43,6 +43,39 @@ def _normalize_terminal_entry(item, index):
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _payload_device_lookup(payload):
|
|
|
|
|
by_element_uuid = set()
|
|
|
|
|
by_instance_id = set()
|
|
|
|
|
|
|
|
|
|
for item in payload.get("devices", []) or []:
|
|
|
|
|
if not isinstance(item, dict):
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
element_uuid = (item.get("element_uuid") or "").strip()
|
|
|
|
|
instance_id = (item.get("instance_id") or "").strip()
|
|
|
|
|
|
|
|
|
|
if element_uuid:
|
|
|
|
|
by_element_uuid.add(element_uuid)
|
|
|
|
|
if instance_id:
|
|
|
|
|
by_instance_id.add(instance_id)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"element_uuids": by_element_uuid,
|
|
|
|
|
"instance_ids": by_instance_id,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _terminal_belongs_to_payload_devices(entry, device_lookup):
|
|
|
|
|
instance_id = entry["instance_id"]
|
|
|
|
|
element_uuid = entry["element_uuid"]
|
|
|
|
|
|
|
|
|
|
if instance_id and instance_id in device_lookup["instance_ids"]:
|
|
|
|
|
return True
|
|
|
|
|
if element_uuid and element_uuid in device_lookup["element_uuids"]:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _ensure_visible(obj):
|
|
|
|
|
try:
|
|
|
|
|
if getattr(obj, "ViewObject", None) is not None:
|
|
|
|
|
@ -179,6 +212,8 @@ def import_terminals_from_payload(payload, scene_path=""):
|
|
|
|
|
if not isinstance(terminal_entries, list):
|
|
|
|
|
raise TerminalImportError("Field 'terminals' must be a list.")
|
|
|
|
|
|
|
|
|
|
device_lookup = _payload_device_lookup(payload)
|
|
|
|
|
|
|
|
|
|
report = {
|
|
|
|
|
"document_name": doc.Name,
|
|
|
|
|
"scene_path": scene_path or "",
|
|
|
|
|
@ -190,6 +225,7 @@ def import_terminals_from_payload(payload, scene_path=""):
|
|
|
|
|
"reused_template_hints": 0,
|
|
|
|
|
"skipped_missing_device": 0,
|
|
|
|
|
"skipped_invalid_entry": 0,
|
|
|
|
|
"skipped_unmatched_parent": 0,
|
|
|
|
|
"warnings": [],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -203,6 +239,10 @@ def import_terminals_from_payload(payload, scene_path=""):
|
|
|
|
|
report["warnings"].append(str(exc))
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if not _terminal_belongs_to_payload_devices(entry, device_lookup):
|
|
|
|
|
report["skipped_unmatched_parent"] += 1
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
device_group = _locate_device_group(doc, entry)
|
|
|
|
|
if device_group is None:
|
|
|
|
|
report["skipped_missing_device"] += 1
|
|
|
|
|
@ -316,10 +356,11 @@ def import_terminals_from_payload(payload, scene_path=""):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
_append_debug_log(
|
|
|
|
|
"TerminalImport finished: imported={0}, updated={1}, removed={2}".format(
|
|
|
|
|
"TerminalImport finished: imported={0}, updated={1}, removed={2}, skipped_unmatched_parent={3}".format(
|
|
|
|
|
report["imported_terminals"],
|
|
|
|
|
report["updated_terminals"],
|
|
|
|
|
report["removed_terminals"],
|
|
|
|
|
report["skipped_unmatched_parent"],
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
return report
|
|
|
|
|
|