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",
"HundM.dxf",
"--sensors",
"--dists",
"--rack",
"--console",
"--write"
@@ -49,7 +48,6 @@
"--filename",
"easy.dxf",
"--sensors",
"--dists",
"--rack",
"--console",
"--write"
@@ -64,9 +62,9 @@
"args": [
"--filename",
"easy.dxf",
"-r",
"-c",
"-w"
"--rack",
"--console",
"--write"
]
},
{
+19 -1
View File
@@ -5,10 +5,28 @@
AUSGANG
MOTOR
[Pritsche]
# Layernamen, auf denen Pritschen liegen
[Layer_Pritschen]
PRITSCHE_100-60-SCHRAFF
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]
Breite = 320
Hoehe = 350
+31 -19
View File
@@ -4,10 +4,10 @@ import ezdxf.document
from ezdxf import readfile
import os
import sys
import math
import json
import re
from shapely import Point
from itertools import combinations
"""
@@ -82,7 +82,7 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace):
allIds[id] = ld
return allIds
def create_mappings(positions:dict, distributors:dict) -> dict:
def create_mappings(positions:dict) -> dict:
unterverteiler_pfad = ""
dnamen = dict()
# sammle die Sensoren mit ihren zugehörigen Unterverteilern
@@ -103,7 +103,7 @@ def create_mappings(positions:dict, distributors:dict) -> dict:
uv2sensor[verteiler].append(sensorname)
return uv2sensor
def get_subdistributor_positions(msp):
def get_subdistributor_positions(msp, dist2sensors):
"""hole alle Positionen der Unterverteiler !!UV-Positionen bereits "Mitte-Mitte"!!
"""
# # Über alle Texte laufen
@@ -122,12 +122,21 @@ def get_subdistributor_positions(msp):
ret = dict()
# Alle Texte auf Layer "xy"
for text in msp.query('MTEXT[layer=="Busverteiler-Kennzeichnung"]'):
print(f"Text auf Layer 'Busverteiler-Kennzeichnung': {text.dxf.text}")
match = re.search(r"=A\d\++\w+-\w\+", text.dxf.text)
if match:
nameUC = match.group(0)
ret[nameUC] = (round(text.dxf.insert[0],1), round(text.dxf.insert[1],1)) #nur x und y Koordinate in Json schreiben
all_distributors = dist2sensors.keys()
all_layers = config.items('Layer_Busverteiler')
for (layer,v) in all_layers:
for distname in all_distributors:
selectstr = f'MTEXT[layer=="{layer}"]'
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
@@ -150,6 +159,8 @@ def get_rack_positions(msp):
ret = dict()
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"]'):
#print_polyline(e)
rack_key = f"Rack_{rack_counter}"
@@ -187,8 +198,7 @@ def get_dxf_file(filepath):
if __name__ == '__main__':
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('-s', '--sensors', action='store_true', help='fetch all position of sensors, motors, actors')
parser.add_argument('-d', '--dists', action='store_true', help='fetch all positions of all subdistributors')
parser.add_argument('-s', '--sensors', action='store_true', help='fetch all position of sensors, motors, actors and subdistributors')
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('-c', '--console', action='store_true', help='print results to output')
@@ -220,7 +230,9 @@ if __name__ == '__main__':
res_mappings = dict()
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"))
output_results = dict()
@@ -229,16 +241,16 @@ if __name__ == '__main__':
output_results['sensors'] = res_pos
if args.console:
print(to_json(res_pos))
if args.dists:
res_dist = get_subdistributor_positions(msp)
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)
res_mappings = create_mappings(res_pos)
output_results['mappings'] = res_mappings
if args.console:
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:
res_rac = get_rack_positions(msp)
output_results['racks'] = res_rac