Refactor wire element handling and improve MOVE enabling logic in SCL parser
This commit is contained in:
parent
0f1d00da1b
commit
e4a15be080
|
@ -157,7 +157,7 @@ def parse_siemens_lad_to_scl(xml_file, debug=True):
|
||||||
debug_print(f"No FlgNet found for network {i+1}", debug)
|
debug_print(f"No FlgNet found for network {i+1}", debug)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get FlgNet namespace - THIS IS THE KEY FIX
|
# Get FlgNet namespace
|
||||||
flgnet_ns = {}
|
flgnet_ns = {}
|
||||||
if flg_net.nsmap:
|
if flg_net.nsmap:
|
||||||
debug_print(f"FlgNet has its own namespace: {flg_net.nsmap}", debug)
|
debug_print(f"FlgNet has its own namespace: {flg_net.nsmap}", debug)
|
||||||
|
@ -208,6 +208,18 @@ def parse_siemens_lad_to_scl(xml_file, debug=True):
|
||||||
|
|
||||||
debug_print(f"Successfully found Parts and Wires elements", debug)
|
debug_print(f"Successfully found Parts and Wires elements", debug)
|
||||||
|
|
||||||
|
# Get all wire elements
|
||||||
|
wire_elements = []
|
||||||
|
wire_elements.extend(wires.findall("Wire"))
|
||||||
|
if flgnet_ns:
|
||||||
|
wire_elements.extend(wires.findall("flg:Wire", namespaces=flgnet_ns))
|
||||||
|
|
||||||
|
# Try XPath with any namespace
|
||||||
|
if not wire_elements:
|
||||||
|
for child in wires:
|
||||||
|
if child.tag.endswith("Wire"):
|
||||||
|
wire_elements.append(child)
|
||||||
|
|
||||||
# Process function calls (CALL instructions)
|
# Process function calls (CALL instructions)
|
||||||
call_elements = []
|
call_elements = []
|
||||||
# Try both direct and with namespace
|
# Try both direct and with namespace
|
||||||
|
@ -252,19 +264,6 @@ def parse_siemens_lad_to_scl(xml_file, debug=True):
|
||||||
# Check if this call is connected to a powerrail (unconditional execution)
|
# Check if this call is connected to a powerrail (unconditional execution)
|
||||||
is_enabled = False
|
is_enabled = False
|
||||||
|
|
||||||
wire_elements = []
|
|
||||||
wire_elements.extend(wires.findall("Wire"))
|
|
||||||
if flgnet_ns:
|
|
||||||
wire_elements.extend(
|
|
||||||
wires.findall("flg:Wire", namespaces=flgnet_ns)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Try XPath with any namespace
|
|
||||||
if not wire_elements:
|
|
||||||
for child in wires:
|
|
||||||
if child.tag.endswith("Wire"):
|
|
||||||
wire_elements.append(child)
|
|
||||||
|
|
||||||
for wire in wire_elements:
|
for wire in wire_elements:
|
||||||
# Check if wire has a powerrail source
|
# Check if wire has a powerrail source
|
||||||
powerrail = wire.find("Powerrail") or (
|
powerrail = wire.find("Powerrail") or (
|
||||||
|
@ -338,38 +337,32 @@ def parse_siemens_lad_to_scl(xml_file, debug=True):
|
||||||
|
|
||||||
# Check if MOVE is directly enabled
|
# Check if MOVE is directly enabled
|
||||||
is_enabled = False
|
is_enabled = False
|
||||||
for wire in wire_elements:
|
|
||||||
powerrail = wire.find("Powerrail") or (
|
|
||||||
wire.find("flg:Powerrail", namespaces=flgnet_ns)
|
|
||||||
if flgnet_ns
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
|
|
||||||
# Try XPath with any namespace
|
# Debug all wires to find the one connected to this move
|
||||||
if powerrail is None:
|
for wire_idx, wire in enumerate(wire_elements):
|
||||||
|
debug_print(f"Checking wire {wire_idx} for MOVE {move_uid}", debug)
|
||||||
|
|
||||||
|
# Check for powerrail
|
||||||
|
powerrail = None
|
||||||
for child in wire:
|
for child in wire:
|
||||||
if child.tag.endswith("Powerrail"):
|
if child.tag.endswith("Powerrail"):
|
||||||
powerrail = child
|
powerrail = child
|
||||||
|
debug_print(f" Found powerrail in wire {wire_idx}", debug)
|
||||||
break
|
break
|
||||||
|
|
||||||
if powerrail is None:
|
if powerrail is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
name_con = wire.find(f"NameCon[@UId='{move_uid}'][@Name='en']") or (
|
# Check for connection to this move
|
||||||
wire.find(
|
name_con = None
|
||||||
f"flg:NameCon[@UId='{move_uid}'][@Name='en']",
|
|
||||||
namespaces=flgnet_ns,
|
|
||||||
)
|
|
||||||
if flgnet_ns
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
|
|
||||||
# Try XPath with any namespace
|
|
||||||
if name_con is None:
|
|
||||||
for child in wire:
|
for child in wire:
|
||||||
|
if child.tag.endswith("NameCon"):
|
||||||
|
debug_print(
|
||||||
|
f" Found NameCon: UId={child.get('UId')}, Name={child.get('Name')}",
|
||||||
|
debug,
|
||||||
|
)
|
||||||
if (
|
if (
|
||||||
child.tag.endswith("NameCon")
|
child.get("UId") == move_uid
|
||||||
and child.get("UId") == move_uid
|
|
||||||
and child.get("Name") == "en"
|
and child.get("Name") == "en"
|
||||||
):
|
):
|
||||||
name_con = child
|
name_con = child
|
||||||
|
@ -377,7 +370,31 @@ def parse_siemens_lad_to_scl(xml_file, debug=True):
|
||||||
|
|
||||||
if name_con is not None:
|
if name_con is not None:
|
||||||
is_enabled = True
|
is_enabled = True
|
||||||
debug_print("MOVE is directly enabled by powerrail", debug)
|
debug_print(
|
||||||
|
f"MOVE with UId {move_uid} is directly enabled by powerrail in wire {wire_idx}",
|
||||||
|
debug,
|
||||||
|
)
|
||||||
|
break
|
||||||
|
|
||||||
|
if not is_enabled:
|
||||||
|
debug_print(
|
||||||
|
f"MOVE with UId {move_uid} is not directly enabled, trying alternative search",
|
||||||
|
debug,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Try a more direct XML search
|
||||||
|
for wire in wire_elements:
|
||||||
|
wire_str = etree.tostring(wire).decode("utf-8")
|
||||||
|
if (
|
||||||
|
f'UId="{move_uid}"' in wire_str
|
||||||
|
and 'Name="en"' in wire_str
|
||||||
|
and "<Powerrail" in wire_str
|
||||||
|
):
|
||||||
|
is_enabled = True
|
||||||
|
debug_print(
|
||||||
|
f"Found MOVE {move_uid} enabled by powerrail using string search",
|
||||||
|
debug,
|
||||||
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
if not is_enabled:
|
if not is_enabled:
|
||||||
|
@ -435,7 +452,8 @@ def parse_siemens_lad_to_scl(xml_file, debug=True):
|
||||||
if source_uid:
|
if source_uid:
|
||||||
source_access = parts.find(f"Access[@UId='{source_uid}']") or (
|
source_access = parts.find(f"Access[@UId='{source_uid}']") or (
|
||||||
parts.find(
|
parts.find(
|
||||||
f"flg:Access[@UId='{source_uid}']", namespaces=flgnet_ns
|
f"flg:Access[@UId='{source_uid}']",
|
||||||
|
namespaces=flgnet_ns,
|
||||||
)
|
)
|
||||||
if flgnet_ns
|
if flgnet_ns
|
||||||
else None
|
else None
|
||||||
|
@ -596,7 +614,8 @@ def parse_siemens_lad_to_scl(xml_file, debug=True):
|
||||||
if dest_uid:
|
if dest_uid:
|
||||||
dest_access = parts.find(f"Access[@UId='{dest_uid}']") or (
|
dest_access = parts.find(f"Access[@UId='{dest_uid}']") or (
|
||||||
parts.find(
|
parts.find(
|
||||||
f"flg:Access[@UId='{dest_uid}']", namespaces=flgnet_ns
|
f"flg:Access[@UId='{dest_uid}']",
|
||||||
|
namespaces=flgnet_ns,
|
||||||
)
|
)
|
||||||
if flgnet_ns
|
if flgnet_ns
|
||||||
else None
|
else None
|
||||||
|
|
Loading…
Reference in New Issue