get_input_positions im INterface verändert, dass eine allgemeine Funktion darunter abgeleitet werden konnte. So können nun auch alle Symbole/inserts in der Hauptmethode aufgerufen werden

This commit is contained in:
2025-09-11 19:06:22 +02:00
parent 032527e4aa
commit ffba29b41b
+35 -15
View File
@@ -193,7 +193,7 @@ class CompareBuffer:
l.append(b)
return l
def extract_input_positions(insert_iterable) -> tuple[dict, dict, dict, dict]:
def extract_input_positions(all_inserts, all_positions) -> tuple[dict, dict, dict, dict]:
"""
Extracts and organizes input positions from an iterable of inserts.
@@ -219,7 +219,6 @@ def extract_input_positions(insert_iterable) -> tuple[dict, dict, dict, dict]:
all_unknowns = list()
wp = CompareBuffer()
all_inserts, all_positions = attribs_to_dicts(insert_iterable)
for insert, pos in zip(all_inserts, all_positions):
ld, id_, typ = get_attributes_of_insert(insert, pos)
@@ -366,12 +365,6 @@ def attribs_to_dicts(insert_iterable) -> tuple[list, list]:
all_positions.append(positions)
return all_inserts, all_positions
def get_input_positions(msp) -> tuple[dict, dict, dict, dict]:
return extract_input_positions(msp.query('INSERT'))
def get_input_positions_iter(dxf_path) -> tuple[dict, dict, dict, dict]:
return extract_input_positions(iterdxf.modelspace(dxf_path))
def create_mappings(positions: dict) -> tuple[dict, dict]:
unterverteiler_pfad = ""
dnamen = dict()
@@ -414,6 +407,35 @@ def create_mappings(positions: dict) -> tuple[dict, dict]:
return (uv2sensor, warnings)
def get_subdistributor_positions_of_symbol(d_insert: dict, d_pos: dict) -> tuple[dict, str, str]:
"""
Diese Funktion schaut nach den aktuell definierten Attributen in den Blöcken
die ID aus dem Eintrag unter "NAME"
"""
id_ = ""
ld = d_insert
typ = 'unknown'
# die neueren Bläcke heissen nicht IO, sondern haben einen Namen
if "NAME" in d_insert:
typ = get_type_of_name_cfg(d_insert["NAME"])
id_ = d_insert["NAME"]
pos = d_pos["NAME"]
ld["pos"] = (pos[0], pos[1])
if "REALE_POSITION" in d_insert and d_insert["REALE_POSITION"] == 'x':
pos = d_pos["REALE_POSITION"]
# Hoehe und Breite von "x" addieren, um Mittelpunkt zu finden
breite_marker = config.getfloat("GetPos-Geom-Sensor", "Breite")
hoehe_marker = config.getfloat("GetPos-Geom-Sensor", "Hoehe")
midx = pos[0] + breite_marker * 0.5
midy = pos[1] + hoehe_marker * 0.5
ld["pos"] = (round(midx, 1), round(midy, 1))
return ld, id_, typ
def get_subdistributor_positions(msp, dist2sensors: dict) -> dict:
"""Hole alle Positionen der Unterverteiler !!UV-Positionen bereits 'Mitte-Mitte'!!"""
ret = dict()
@@ -691,12 +713,6 @@ 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')
parser.add_argument('-f', '--filename', action='store', required=True, default="ST_6300_Steuerungstestlayout1_neueBloecke.dwg", help='which file should be fetched', metavar='myfile.dxf')
@@ -762,7 +778,11 @@ if __name__ == '__main__':
if args.sensors:
# Sensoren auslesen
res_sens, res_schaltschrank_elemente, res_double, missing_attribs = get_input_positions_combined(dxf_path if use_iter else msp, use_iter)
if use_iter:
all_inserts, all_positions = attribs_to_dicts(iterdxf.modelspace(dxf_path))
else:
all_inserts, all_positions = attribs_to_dicts(msp)
res_sens, res_schaltschrank_elemente, res_double, missing_attribs = extract_input_positions(all_inserts, all_positions)
if args.errors and len(res_double) > 0:
print("Duplicate blocks found. Writing errors-file.")