Block mit B wird nur gecheckt, wenn nicht auch IO vorhanden ist, damit die alten Modelle funktionieren

This commit is contained in:
2025-07-21 12:44:34 +02:00
parent 20a3cdf761
commit 244898547e
+13 -10
View File
@@ -7,11 +7,8 @@ import sys
from pathlib import Path
import ezdxf
import ezdxf.filemanagement
from ezdxf.addons import iterdxf
from shapely.geometry import Point
# Fix import for DXFStructureError
from ezdxf.lldxf.const import DXFStructureError
@@ -75,6 +72,7 @@ def get_attributes_of_insert(d_insert: dict, d_pos: dict) -> tuple[dict, str, st
pos = d_pos["IO"]
typ = get_type_of_name_cfg(d_insert["IO"])
# neuer Block: Enthält alles was nötig is
if "ARTINR" in d_insert and "SPS" in d_insert:
id_ = d_insert["IO"]+"@"+d_insert["SPS"]
ld["pos"] = (pos[0], pos[1])
@@ -108,7 +106,7 @@ def get_attributes_of_insert(d_insert: dict, d_pos: dict) -> tuple[dict, str, st
pos = d_pos["NAME"]
ld["pos"] = (pos[0], pos[1])
if "B" in d_insert:
if "B" in d_insert and "IO" not in d_insert:
attr_text = d_insert["B"]
typ = get_type_of_name_cfg(attr_text)
id_ = attr_text
@@ -227,11 +225,14 @@ def extract_input_positions(insert_iterable) -> tuple[dict, dict, dict, dict]:
ld, id_, typ = get_attributes_of_insert(insert, pos)
if typ == "Sensor":
# wenn NAME enthalten ist, dann ist das ein eindeutiger Bezeichner
# wenn NAME enthalten ist, z.B. bei Erdungslayouts, dann ist das ein eindeutiger Bezeichner
if "NAME" in ld:
all_sensors[id_] = ld
# neuer Block der alle nötigen Infos enthält
elif "IO" in ld and "ARTINR" in ld :
all_sensors[id_] = ld
# alle anderen Sachen werden dann aus mehreren Rahmen zusammen gesammelt
else:
# alle anderen Sachen werden dann aus mehreren Rahmen zusammen gesammelt
wp.add_block(id_, ld)
elif typ == "Kabel":
@@ -661,6 +662,11 @@ def check_environment_var(env_str: str) -> Path:
print(f"Umgebungsvariable {env_str} ist nicht gesetzt oder leer.")
exit()
def get_input_positions_combined(source: str, use_iter: bool) -> tuple[dict, dict, dict, dict]:
if use_iter:
return get_input_positions_iter(source)
else:
return get_input_positions(source)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='fetches the x/y positions from a dxf file', prog='getpositions')
@@ -727,10 +733,7 @@ if __name__ == '__main__':
if args.sensors:
# Sensoren auslesen
if use_iter:
res_sens, res_schaltschrank_elemente, res_double, missing_attribs = get_input_positions_iter(dxf_path)
else:
res_sens, res_schaltschrank_elemente, res_double, missing_attribs = get_input_positions(msp)
res_sens, res_schaltschrank_elemente, res_double, missing_attribs = get_input_positions_combined(dxf_path if use_iter else msp, use_iter)
if args.errors and len(res_double) > 0:
print("Duplicate blocks found. Writing errors-file.")