From ffba29b41b34e938f56b95bed4d3aac092b1f72c Mon Sep 17 00:00:00 2001 From: mistangl Date: Thu, 11 Sep 2025 19:06:22 +0200 Subject: [PATCH] =?UTF-8?q?get=5Finput=5Fpositions=20im=20INterface=20ver?= =?UTF-8?q?=C3=A4ndert,=20dass=20eine=20allgemeine=20Funktion=20darunter?= =?UTF-8?q?=20abgeleitet=20werden=20konnte.=20So=20k=C3=B6nnen=20nun=20auc?= =?UTF-8?q?h=20alle=20Symbole/inserts=20in=20der=20Hauptmethode=20aufgeruf?= =?UTF-8?q?en=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/getpositions.py | 50 +++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/getpositions.py b/lib/getpositions.py index 93dc033..c75d506 100644 --- a/lib/getpositions.py +++ b/lib/getpositions.py @@ -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.")