diff --git a/lib/getpositions.py b/lib/getpositions.py index 77774f6..213ca64 100644 --- a/lib/getpositions.py +++ b/lib/getpositions.py @@ -48,7 +48,6 @@ def get_type_of_name(name): DropKeys = [ "FC", # Motorschutzschalter "PF", # Leuchtmelder - "SF", "DI", # Feedback vom Gerät "QA", # Hauptschütz "SF" # Drucktaster @@ -115,6 +114,8 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace)-> tuple: """ allSensors = dict() allCables = dict() + allunknowns = dict() + allSchaltschrank = dict() # Über alle Blockreferenzen (INSERT) im Modelspace laufen for insert in msp.query('INSERT'): @@ -124,23 +125,25 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace)-> tuple: ld, id, typ = get_attributes_of_insert(insert) - # Nur wenn eine ID vorhanden ist, und eine gültige Position existiert + # Verarbeite je nach Typ if typ == "Sensor": if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2: if id in allSensors: - allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos" + allSensors[id] = merge_two_dicts(allSensors[id], ld) else: allSensors[id] = ld elif typ == "Kabel": allCables[id] = ld + elif typ == "Schaltschrankelement": + allSchaltschrank[id] = ld else: - # Falls das Objekt ein Teil des Schaltschranks o.ä ist, dann nichts merken - pass + allunknowns[id] = ld + return allSensors, allCables def get_input_positions_iter(dxf_path) -> tuple: """ - Iterative Version für große DXF-Dateien mit iterdxf (kein Context Manager!). + Iterative Version für große DXF-Dateien mit iterdxf """ allSensors = dict() allCables = dict() @@ -155,18 +158,17 @@ def get_input_positions_iter(dxf_path) -> tuple: # Nur wenn eine ID vorhanden ist, und eine gültige Position existiert if typ == "Sensor": - if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2: - if id in allSensors: - allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos" - else: - allSensors[id] = ld + #if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2: + if id in allSensors: + allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos" + else: + allSensors[id] = ld elif typ == "Kabel": allCables[id] = ld elif typ == "Schaltschrankelement": allSchaltschrank[id] = ld else: allunknowns[id] = ld - # Falls das Objekt ein Teil des Schaltschranks o.ä ist, dann nichts merken return allSensors, allCables @@ -447,14 +449,14 @@ if __name__ == '__main__': filename = args.filename (dxf_path, dexists) = check_file_in_work(work_dir, filename) - - zeitanfang = time.time() if dxf_is_binary(dxf_path): # Wenn dxf eine binary ist, dann komplett parsen und modelspace anlegen doc = get_dxf_file(dxf_path) + print("Given .dxf-file is binary dxf. Proceeding to read file. Watch RAM-usage.") msp = doc.modelspace() use_iter = False else: + print("Given .dxf-file is ASCII-dxf. Proceeding to user iterative functions. Process may take longer.") use_iter = True res_sens = dict() @@ -530,8 +532,6 @@ if __name__ == '__main__': res_not_found = check_existance(res_mappings, res_dist, res_sens) output_results["not_found"] = res_not_found write_results(to_json(output_results), work_dir, f"{basename}.json") - zeitende = time.time() - print(zeitende-zeitanfang) else: parser.print_help()