diff --git a/lib/getpositions.py b/lib/getpositions.py index 09e83e1..4015d09 100644 --- a/lib/getpositions.py +++ b/lib/getpositions.py @@ -80,9 +80,20 @@ def get_type_of_name_cfg(name): return "unknown" def get_attributes_of_insert(insert): - ''' - Hier in Zukunft weniger Abfragen: IO und B und Reale_Position wird überflüssig wenn jeder Sensor nur noch eiun Block mit allen Attributen! - ''' + """ + Diese Funktion schaut nach den aktuell definierten Attributen in den Blöcken + + Bei den Sensoren in den alten Layouts gibt zwei immer übereinanderliegende Blöcke mit den Attributen: + - A, B (z.B. MA0062), C, ARTINR (z.B. 790902001), BESCHR (E-Teile für SEW Motor ASE1..), MENGE, POSITION, ... + - IO (z.B. MA0062), ID , VERW (z.B. CV-M0062_0,75), BEZEICHNUNG (Motor MA0062), KENNZEICHNUNG (z.B.=A01+UH01-KF1DQ04), ... + Die Adresse für das Routing kommt aus "KENNZEICHNUNG", während die Sivas Nummer aus "ARTINR" geholt werden muss + Einmal wird B zur ID, beim anderen IO + + Erdungssymbole erhalten die ID aus dem Eintrag unter "NAME" + + Hier in Zukunft weniger Abfragen: IO und B und Reale_Position wird überflüssig wenn jeder Sensor nur noch ein Block mit allen Attributen! + + """ id = "" ld = dict() typ = 'unknown' @@ -127,10 +138,23 @@ def get_attributes_of_insert(insert): return (ld, id, typ) +def check_double_ids(ld, id, allSensors): + if id in allSensors and "NAME" in ld: + return True + if id in allSensors and "B" in ld and "B" in allSensors[id]: + return True + if id in allSensors and "IO" in ld and "IO" in allSensors[id]: + return True + return False + + + + def extract_input_positions(insert_iterable) -> tuple: allSensors = dict() allCables = dict() allunknowns = dict() + doubleIds = list() allSchaltschrank = dict() for insert in insert_iterable: @@ -142,7 +166,14 @@ def extract_input_positions(insert_iterable) -> tuple: 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" + is_double = check_double_ids(ld, id, allSensors) + if not is_double: + allSensors[id] = merge_two_dicts(allSensors[id], ld) #Kombiniert alle infos aus dxf und "pos" + else: + # gib aus wo sich beide gleichlautenden Elemente auf der Zeichnung befinden + doubleIds.append((id, allSensors[id]["pos"]) ) + doubleIds.append((id, ld["pos"]) ) + else: allSensors[id] = ld elif typ == "Kabel": @@ -152,7 +183,7 @@ def extract_input_positions(insert_iterable) -> tuple: else: allunknowns[id] = ld - return allSensors, allCables + return allSensors, doubleIds def get_input_positions(msp) -> tuple: return extract_input_positions(msp.query('INSERT')) @@ -266,7 +297,8 @@ def get_tunnel_positions(msp): allTunnels[tunnelname].append(pos) else: allTunnels[tunnelname].append(pos) - allTunnels['length'] = tunnel_length + if len(allTunnels.keys()) > 0: + allTunnels['length'] = tunnel_length return allTunnels def get_tunnel_positions_iter(dxf_path): @@ -299,8 +331,8 @@ def get_tunnel_positions_iter(dxf_path): allTunnels[tunnelname] = [] allTunnels[tunnelname].append(pos) tunnel_length[tunnelname] = laenge - - allTunnels['length'] = tunnel_length + if len(tunnel_length.keys()) > 0: + allTunnels['length'] = tunnel_length return allTunnels # helper function @@ -490,6 +522,7 @@ if __name__ == '__main__': parser.add_argument('-r', '--rack', action='store_true', help='fetch all positions of all cable racks') parser.add_argument('-w', '--write', action='store', help='write results into a json file') parser.add_argument('-c', '--console', action='store_true', help='print results to output') + parser.add_argument('-e', '--errors', action='store', help='write an error file in case of double defined items in layout') parser.add_argument('-n', '--scan', action='store_true', help='print all layer of racs, distributes and equiment not empty') args = parser.parse_args() @@ -548,9 +581,16 @@ if __name__ == '__main__': if args.sensors: # Sensoren auslesen if use_iter: - res_sens, res_cables = get_input_positions_iter(dxf_path) + res_sens, res_double = get_input_positions_iter(dxf_path) else: - res_sens, res_cables = get_input_positions(msp) + res_sens, res_double = get_input_positions(msp) + + if args.errors and len(res_double) > 0: + err_ids = set() + for item in res_double: + err_ids.add(item[0]) + write_results(to_json(list(err_ids)), work_dir, args.errors) + output_results['sensors'] = res_sens #output_results['cables'] = res_cables @@ -603,6 +643,7 @@ if __name__ == '__main__': res_not_found = check_existance(res_mappings, res_dist, res_sens) res_not_found["missing_attributes"] = warnings output_results["not_found"] = res_not_found + output_results["double_ids"] = res_double write_results(to_json(output_results), work_dir, f"{basename}.json") else: diff --git a/work/easy.dwg b/work/easy.dwg new file mode 100644 index 0000000..70295a7 Binary files /dev/null and b/work/easy.dwg differ