From 4a415afea84c2c56705f1328eaf1404e7de07016 Mon Sep 17 00:00:00 2001 From: mistangl Date: Fri, 12 Sep 2025 13:24:54 +0200 Subject: [PATCH] Unterverteiler werden aus Konfig geladen und erkannt. --- cfg/BMK.cfg | 6 +++--- lib/getpositions.py | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/cfg/BMK.cfg b/cfg/BMK.cfg index 3dac207..610aa7b 100644 --- a/cfg/BMK.cfg +++ b/cfg/BMK.cfg @@ -28,9 +28,9 @@ QA [Cabinet-Pattern] -A\d\d+UH00 -A\d\d+UC\d\d\d -UC\d\d\d\d +A\d\d\+(UH00) +A\d\d\+(UC\d\d\d) +\+(UC\d\d\d\d) diff --git a/lib/getpositions.py b/lib/getpositions.py index 946fe1a..6b8f39f 100644 --- a/lib/getpositions.py +++ b/lib/getpositions.py @@ -48,18 +48,21 @@ def get_type_of_name_cfg(name: str) -> str: return "unknown" -def matches_cabinet_pattern(name: str) -> bool: +def matches_cabinet_pattern(name: str) -> [bool, str]: """Check if the given name matches any Cabinet-Pattern from BMK.cfg""" if not config_BMK.has_section("Cabinet-Pattern"): - return False + return (False, "") patterns = [pattern for pattern, _ in config_BMK.items("Cabinet-Pattern")] for pattern in patterns: - if re.match(pattern, name): - return True + + m = re.search(pattern, name) + if m: + res = m.group(1) + return (True, res) - return False + return (False, "") def get_attributes_of_insert(d_insert: dict, d_pos: dict) -> tuple[dict, str, str]: @@ -459,11 +462,11 @@ def get_subdistributor_positions_from_symbols(all_inserts:list, all_positions:li ld, id_ = get_subdistributor_position_of_symbol(insert, pos) # Check if id_ matches Cabinet-Pattern from BMK.cfg - if not matches_cabinet_pattern(id_): + (matches, res) = matches_cabinet_pattern(id_) + if not matches: continue - if f"-{id_}" in dist2sensors or f"+{id_}" in dist2sensors: - # Fix: use ld["pos"] instead of undefined insert_point + if res in dist2sensors: ret[id_] = ld["pos"] return ret @@ -813,8 +816,11 @@ if __name__ == '__main__': entities = iterdxf.modelspace(dxf_path) else: entities = msp.query('MTEXT') - res_dist = get_subdistributor_positions_from_entities(entities, res_mappings) - new_res_dist = get_subdistributor_positions_from_symbols(all_inserts, all_positions, res_mappings) + # die Infos aus den Texten (alter Stil) + res_dist = get_subdistributor_positions_from_entities(entities, res_mappings) + # die Infos aus den Blöcken + symbol_dists = get_subdistributor_positions_from_symbols(all_inserts, all_positions, res_mappings) + res_dist = merge_two_dicts(res_dist, symbol_dists) output_results['distributors'] = res_dist if args.console: print(to_json(res_dist))