extract_input_positions() geschieben, die von iter und normaler Version von get_input_positions() aufgerufen wird. Ausgabefiles (*_positions.json) bis auf kleine Reihenfolge-Unterschiede identisch. Ausgabe-Files nach Routing mit jeweiligem Eingabefile komplett identisch.

This commit is contained in:
2025-06-11 15:09:50 +02:00
parent 09d8bbd63a
commit 10d794e9ce
+36 -2
View File
@@ -112,6 +112,33 @@ def get_attributes_of_insert(insert):
return (ld, id, typ)
def extract_input_positions(insert_iterable) -> tuple:
allSensors = dict()
allCables = dict()
allunknowns = dict()
allSchaltschrank = dict()
for insert in insert_iterable:
if insert.dxftype() != 'INSERT':
continue
ld, id, typ = get_attributes_of_insert(insert)
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
elif typ == "Kabel":
allCables[id] = ld
elif typ == "Schaltschrankelement":
allSchaltschrank[id] = ld
else:
allunknowns[id] = ld
return allSensors, allCables
'''
def get_input_positions(msp: ezdxf.document.Drawing.modelspace)-> tuple:
"""hole alle Positionen der Eingänge !!Sensor Positionen erst nach Offsett-Addition "Mitte-Mitte"!!
"""
@@ -143,7 +170,11 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace)-> tuple:
allunknowns[id] = ld
return allSensors, allCables
'''
def get_input_positions(msp) -> tuple:
return extract_input_positions(msp.query('INSERT'))
'''
def get_input_positions_iter(dxf_path) -> tuple:
"""
Iterative Version für große DXF-Dateien mit iterdxf
@@ -174,6 +205,9 @@ def get_input_positions_iter(dxf_path) -> tuple:
allunknowns[id] = ld
return allSensors, allCables
'''
def get_input_positions_iter(dxf_path) -> tuple:
return extract_input_positions(iterdxf.modelspace(dxf_path))
def create_mappings(positions:dict) -> dict:
unterverteiler_pfad = ""
@@ -455,8 +489,8 @@ if __name__ == '__main__':
(dxf_path, dexists) = check_file_in_work(work_dir, filename)
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.")
doc = get_dxf_file(dxf_path)
msp = doc.modelspace()
use_iter = False
else:
@@ -486,7 +520,7 @@ if __name__ == '__main__':
res_sens, res_cables = get_input_positions(msp)
output_results['sensors'] = res_sens
output_results['cables'] = res_cables
#output_results['cables'] = res_cables
if args.console:
print(to_json(res_sens))