|
|
|
|
@ -58,12 +58,6 @@ def _project_uuid_for_document(doc):
|
|
|
|
|
return project_uuid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _local_terminal_uuid(instance_id, element_uuid, slot_name):
|
|
|
|
|
owner = (instance_id or "").strip() or (element_uuid or "").strip() or "device"
|
|
|
|
|
slot = (slot_name or "").strip() or "slot"
|
|
|
|
|
return "local:{0}:{1}".format(owner, slot)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _existing_terminal_by_slot(terminal_group):
|
|
|
|
|
result = {}
|
|
|
|
|
for obj in TerminalObjects.collect_terminal_objects(terminal_group):
|
|
|
|
|
@ -73,6 +67,18 @@ def _existing_terminal_by_slot(terminal_group):
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _is_qet_bound_terminal(obj):
|
|
|
|
|
terminal_uuid = getattr(obj, "QetTerminalUuid", "").strip()
|
|
|
|
|
binding_mode = getattr(obj, "QetTerminalBindingMode", "").strip().lower()
|
|
|
|
|
if not terminal_uuid:
|
|
|
|
|
return False
|
|
|
|
|
if TerminalObjects.is_local_terminal_uuid(terminal_uuid):
|
|
|
|
|
return False
|
|
|
|
|
if binding_mode == TerminalObjects.TERMINAL_BINDING_MODE_LOCAL:
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _terminal_group_for_device(doc, device_group, project_uuid):
|
|
|
|
|
instance_id = getattr(device_group, "QetInstanceId", "").strip()
|
|
|
|
|
return TerminalObjects.ensure_terminal_group(
|
|
|
|
|
@ -138,6 +144,7 @@ def ensure_engineering_terminals_for_device(doc, device_group):
|
|
|
|
|
"created_terminals": 0,
|
|
|
|
|
"updated_terminals": 0,
|
|
|
|
|
"skipped_slots": 0,
|
|
|
|
|
"skipped_unbound_slots": 0,
|
|
|
|
|
"skipped_devices_without_template_slots": 0,
|
|
|
|
|
"local_terminals": 0,
|
|
|
|
|
"warnings": [],
|
|
|
|
|
@ -161,17 +168,26 @@ def ensure_engineering_terminals_for_device(doc, device_group):
|
|
|
|
|
|
|
|
|
|
terminal_obj = existing_by_slot.get(slot_name)
|
|
|
|
|
if terminal_obj is None:
|
|
|
|
|
terminal_obj = TerminalObjects.create_lcs_object(
|
|
|
|
|
doc,
|
|
|
|
|
"QETTerminal_{0}_{1}".format(
|
|
|
|
|
TerminalObjects.safe_token(instance_id or element_uuid),
|
|
|
|
|
TerminalObjects.safe_token(slot_name),
|
|
|
|
|
),
|
|
|
|
|
placement=_slot_placement(slot),
|
|
|
|
|
label=_slot_label(slot, slot_name),
|
|
|
|
|
report["skipped_unbound_slots"] += 1
|
|
|
|
|
report["warnings"].append(
|
|
|
|
|
"设备 {0} 的模板槽位 {1} 没有 QET 端子绑定,未生成本地工程端子。".format(
|
|
|
|
|
getattr(device_group, "Label", "") or getattr(device_group, "Name", ""),
|
|
|
|
|
slot_name,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
_debug(report["warnings"][-1])
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if not _is_qet_bound_terminal(terminal_obj):
|
|
|
|
|
report["local_terminals"] += 1
|
|
|
|
|
report["warnings"].append(
|
|
|
|
|
"设备 {0} 的模板槽位 {1} 已存在本地端子,已保留但不作为 QET 工程端子更新。".format(
|
|
|
|
|
getattr(device_group, "Label", "") or getattr(device_group, "Name", ""),
|
|
|
|
|
slot_name,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
terminal_group.addObject(terminal_obj)
|
|
|
|
|
report["created_terminals"] += 1
|
|
|
|
|
_debug(report["warnings"][-1])
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
terminal_obj.Placement = _slot_placement(slot)
|
|
|
|
|
@ -180,10 +196,6 @@ def ensure_engineering_terminals_for_device(doc, device_group):
|
|
|
|
|
report["updated_terminals"] += 1
|
|
|
|
|
|
|
|
|
|
terminal_uuid = getattr(terminal_obj, "QetTerminalUuid", "").strip()
|
|
|
|
|
if not terminal_uuid:
|
|
|
|
|
terminal_uuid = _local_terminal_uuid(instance_id, element_uuid, slot_name)
|
|
|
|
|
if TerminalObjects.is_local_terminal_uuid(terminal_uuid):
|
|
|
|
|
report["local_terminals"] += 1
|
|
|
|
|
|
|
|
|
|
TerminalObjects.set_terminal_semantics(
|
|
|
|
|
terminal_obj,
|
|
|
|
|
@ -254,6 +266,7 @@ def ensure_engineering_terminals_for_selection_or_all(doc=None):
|
|
|
|
|
"skipped_devices_without_template_slots": sum(
|
|
|
|
|
item.get("skipped_devices_without_template_slots", 0) for item in reports
|
|
|
|
|
),
|
|
|
|
|
"skipped_unbound_slots": sum(item.get("skipped_unbound_slots", 0) for item in reports),
|
|
|
|
|
"local_terminals": sum(item.get("local_terminals", 0) for item in reports),
|
|
|
|
|
"warnings": [
|
|
|
|
|
warning
|
|
|
|
|
@ -362,10 +375,11 @@ class CommandCreateEngineeringTerminals:
|
|
|
|
|
report = ensure_engineering_terminals_for_selection_or_all(App.ActiveDocument)
|
|
|
|
|
try:
|
|
|
|
|
App.Console.PrintMessage(
|
|
|
|
|
"[FreeCADExchange] 工程端子生成完成:设备 {0} 个,新增 {1} 个,更新 {2} 个,本地端子 {3} 个,跳过无模板设备 {4} 个。\n".format(
|
|
|
|
|
"[FreeCADExchange] 工程端子生成完成:设备 {0} 个,新增 {1} 个,更新 {2} 个,跳过未绑定槽位 {3} 个,已有本地端子 {4} 个,跳过无模板设备 {5} 个。\n".format(
|
|
|
|
|
report["devices"],
|
|
|
|
|
report["created_terminals"],
|
|
|
|
|
report["updated_terminals"],
|
|
|
|
|
report["skipped_unbound_slots"],
|
|
|
|
|
report["local_terminals"],
|
|
|
|
|
report["skipped_devices_without_template_slots"],
|
|
|
|
|
)
|
|
|
|
|
|