Layer für Sensoren etc. werden aus Config gelesen. Sensoren und Verteiler werden auf einen Rutsch bestimmt

This commit is contained in:
2025-05-19 21:52:23 +02:00
parent 020fc556ec
commit 74ce767569
3 changed files with 53 additions and 25 deletions
+3 -5
View File
@@ -33,7 +33,6 @@
"--filename", "--filename",
"HundM.dxf", "HundM.dxf",
"--sensors", "--sensors",
"--dists",
"--rack", "--rack",
"--console", "--console",
"--write" "--write"
@@ -49,7 +48,6 @@
"--filename", "--filename",
"easy.dxf", "easy.dxf",
"--sensors", "--sensors",
"--dists",
"--rack", "--rack",
"--console", "--console",
"--write" "--write"
@@ -64,9 +62,9 @@
"args": [ "args": [
"--filename", "--filename",
"easy.dxf", "easy.dxf",
"-r", "--rack",
"-c", "--console",
"-w" "--write"
] ]
}, },
{ {
+19 -1
View File
@@ -5,10 +5,28 @@
AUSGANG AUSGANG
MOTOR MOTOR
[Pritsche] # Layernamen, auf denen Pritschen liegen
[Layer_Pritschen]
PRITSCHE_100-60-SCHRAFF PRITSCHE_100-60-SCHRAFF
PRITSCHE_200-60 PRITSCHE_200-60
0-0_ILS_PRITSCHE_200--60_storage\ Level\ 1
0-0_ILS_PRITSCHE_200--60_storage\ Level\ 2
0-0_ILS_PRITSCHE_200--60_Workstation
0-0_ILS_Pritsche_200-60_AMR
0-0_ILS_PRITSCHE_200-60_Highway
0-0_ILS_Pritsche_200-60_Inbound
0-0_Omniflo_Pritsche_200-60_Workstation-Outbound
[Layer_Busverteiler]
Busverteiler-Kennzeichnung
#0-0_ILS_Bereich-Busverteiler
0-0_ILS_Busverteiler-Kennzeichnung
0-0_ILS_UNTERVERTEILER
0-0_Omniflo_UNTERVERTEILER
UNTERVERTEILER
# Maße des zur genauen Bestimmung der Mitte
[Unterverteiler] [Unterverteiler]
Breite = 320 Breite = 320
Hoehe = 350 Hoehe = 350
+31 -19
View File
@@ -4,10 +4,10 @@ import ezdxf.document
from ezdxf import readfile from ezdxf import readfile
import os import os
import sys import sys
import math
import json import json
import re import re
from shapely import Point from shapely import Point
from itertools import combinations
""" """
@@ -82,7 +82,7 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace):
allIds[id] = ld allIds[id] = ld
return allIds return allIds
def create_mappings(positions:dict, distributors:dict) -> dict: def create_mappings(positions:dict) -> dict:
unterverteiler_pfad = "" unterverteiler_pfad = ""
dnamen = dict() dnamen = dict()
# sammle die Sensoren mit ihren zugehörigen Unterverteilern # sammle die Sensoren mit ihren zugehörigen Unterverteilern
@@ -103,7 +103,7 @@ def create_mappings(positions:dict, distributors:dict) -> dict:
uv2sensor[verteiler].append(sensorname) uv2sensor[verteiler].append(sensorname)
return uv2sensor return uv2sensor
def get_subdistributor_positions(msp): def get_subdistributor_positions(msp, dist2sensors):
"""hole alle Positionen der Unterverteiler !!UV-Positionen bereits "Mitte-Mitte"!! """hole alle Positionen der Unterverteiler !!UV-Positionen bereits "Mitte-Mitte"!!
""" """
# # Über alle Texte laufen # # Über alle Texte laufen
@@ -122,12 +122,21 @@ def get_subdistributor_positions(msp):
ret = dict() ret = dict()
# Alle Texte auf Layer "xy" # Alle Texte auf Layer "xy"
for text in msp.query('MTEXT[layer=="Busverteiler-Kennzeichnung"]'): all_distributors = dist2sensors.keys()
print(f"Text auf Layer 'Busverteiler-Kennzeichnung': {text.dxf.text}") all_layers = config.items('Layer_Busverteiler')
match = re.search(r"=A\d\++\w+-\w\+", text.dxf.text) for (layer,v) in all_layers:
if match: for distname in all_distributors:
nameUC = match.group(0) selectstr = f'MTEXT[layer=="{layer}"]'
ret[nameUC] = (round(text.dxf.insert[0],1), round(text.dxf.insert[1],1)) #nur x und y Koordinate in Json schreiben for text in msp.query(selectstr):
print(f"Text auf Layer 'Busverteiler-Kennzeichnung': {text.dxf.text}")
match = re.search("-"+distname, text.dxf.text)
if match:
ret[distname] = (round(text.dxf.insert[0],1), round(text.dxf.insert[1],1)) #nur x und y Koordinate in Json schreiben
# for mtext in msp.query("MTEXT"):
# print(f"Inhalt: {mtext.text}")
# print(f"Layer: {mtext.dxf.layer}")
# print(f"Einfügepunkt: {mtext.dxf.insert}")
# print("---")
return ret return ret
@@ -150,6 +159,8 @@ def get_rack_positions(msp):
ret = dict() ret = dict()
rack_counter = 1 #Zaehler für Rack Nummerierung rack_counter = 1 #Zaehler für Rack Nummerierung
all_layers = list(config.items('Layer_Pritschen'))
for e in msp.query('LWPOLYLINE[layer=="PRITSCHE_200-60"]'): for e in msp.query('LWPOLYLINE[layer=="PRITSCHE_200-60"]'):
#print_polyline(e) #print_polyline(e)
rack_key = f"Rack_{rack_counter}" rack_key = f"Rack_{rack_counter}"
@@ -187,8 +198,7 @@ def get_dxf_file(filepath):
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description='fetches the x/y positions from a dxf file', prog='getpositions') 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.dwg') parser.add_argument('-f', '--filename', action='store', required=True, default="ST_6300_Steuerungstestlayout1_neueBloecke.dwg", help='which file should be fetched', metavar='myfile.dwg')
parser.add_argument('-s', '--sensors', action='store_true', help='fetch all position of sensors, motors, actors') parser.add_argument('-s', '--sensors', action='store_true', help='fetch all position of sensors, motors, actors and subdistributors')
parser.add_argument('-d', '--dists', action='store_true', help='fetch all positions of all subdistributors')
parser.add_argument('-r', '--rack', action='store_true', help='fetch all positions of all cable racks') parser.add_argument('-r', '--rack', action='store_true', help='fetch all positions of all cable racks')
parser.add_argument('-w', '--write', action='store_true', help='write results into a json file') parser.add_argument('-w', '--write', action='store_true', help='write results into a json file')
parser.add_argument('-c', '--console', action='store_true', help='print results to output') parser.add_argument('-c', '--console', action='store_true', help='print results to output')
@@ -220,7 +230,9 @@ if __name__ == '__main__':
res_mappings = dict() res_mappings = dict()
if args.sensors or args.dists or args.rack: if args.sensors or args.dists or args.rack:
config = configparser.ConfigParser(allow_no_value=True) config = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
config.optionxform = lambda option: option # preserve case for letters
config.read(os.path.join(config_dir, "getpositions.cfg")) config.read(os.path.join(config_dir, "getpositions.cfg"))
output_results = dict() output_results = dict()
@@ -229,16 +241,16 @@ if __name__ == '__main__':
output_results['sensors'] = res_pos output_results['sensors'] = res_pos
if args.console: if args.console:
print(to_json(res_pos)) print(to_json(res_pos))
if args.dists:
res_dist = get_subdistributor_positions(msp) res_mappings = create_mappings(res_pos)
output_results['distributors'] = res_dist
if args.console:
print(to_json(res_dist))
if args.dists and args.sensors:
res_mappings = create_mappings(res_pos, res_dist)
output_results['mappings'] = res_mappings output_results['mappings'] = res_mappings
if args.console: if args.console:
print(to_json(res_mappings)) print(to_json(res_mappings))
res_dist = get_subdistributor_positions(msp, res_mappings)
output_results['distributors'] = res_dist
if args.console:
print(to_json(res_dist))
if args.rack: if args.rack:
res_rac = get_rack_positions(msp) res_rac = get_rack_positions(msp)
output_results['racks'] = res_rac output_results['racks'] = res_rac