Positionen von tunnel und Unterverteiler jeweils in einer Funktion zusammengefasst
This commit is contained in:
+49
-79
@@ -436,96 +436,68 @@ def get_subdistributor_positions_of_symbol(d_insert: dict, d_pos: dict) -> tuple
|
|||||||
|
|
||||||
return ld, id_, typ
|
return ld, id_, typ
|
||||||
|
|
||||||
def get_subdistributor_positions(msp, dist2sensors: dict) -> dict:
|
def get_subdistributor_positions_from_entities(entities, dist2sensors: dict) -> dict:
|
||||||
"""Hole alle Positionen der Unterverteiler !!UV-Positionen bereits 'Mitte-Mitte'!!"""
|
"""Ermittelt Unterverteiler-Positionen aus einer beliebigen Entity-Iterable.
|
||||||
ret = dict()
|
|
||||||
all_distributors = dist2sensors.keys()
|
|
||||||
all_layers = config.items('GetPos-Layer_Distributors')
|
|
||||||
for (layer, v) in all_layers:
|
|
||||||
for distname in all_distributors:
|
|
||||||
selectstr = f'MTEXT[layer=="{layer}"]'
|
|
||||||
for text in msp.query(selectstr):
|
|
||||||
match = re.search("-" + distname, text.dxf.text)
|
|
||||||
if match:
|
|
||||||
ret[distname] = (round(text.dxf.insert[0], 1), round(text.dxf.insert[1], 1))
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def get_subdistributor_positions_iter(dxf_path, dist2sensors: dict) -> dict:
|
Erwartet eine Iterable von DXF-Entities (z. B. aus `msp.query("MTEXT")` oder
|
||||||
"""Hole alle Positionen der Unterverteiler aus MTEXT-Objekten mithilfe von iterdxf."""
|
`iterdxf.modelspace(dxf_path)`) und filtert nach den in der Config erlaubten
|
||||||
|
Layern. Es werden beide bisher verwendeten Suchmuster in der MTEXT-Zeile
|
||||||
|
unterstützt ("-<distname>" und "+<distname>").
|
||||||
|
"""
|
||||||
ret = {}
|
ret = {}
|
||||||
all_distributors = dist2sensors.keys()
|
all_distributors = dist2sensors.keys()
|
||||||
all_layers = config.items('GetPos-Layer_Distributors')
|
allowed_layers = {layer for (layer, _) in config.items('GetPos-Layer_Distributors')}
|
||||||
|
|
||||||
for entity in iterdxf.modelspace(dxf_path):
|
for entity in entities:
|
||||||
if entity.dxftype() != "MTEXT":
|
if entity.dxftype() != "MTEXT":
|
||||||
continue
|
continue
|
||||||
entity_text = entity.dxf.text
|
layer = entity.dxf.layer
|
||||||
entity_layer = entity.dxf.layer
|
if layer not in allowed_layers:
|
||||||
|
continue
|
||||||
|
text = entity.dxf.text
|
||||||
insert_point = entity.dxf.insert
|
insert_point = entity.dxf.insert
|
||||||
|
|
||||||
for (layer_name, _) in all_layers:
|
for distname in all_distributors:
|
||||||
if entity_layer != layer_name:
|
if f"-{distname}" in text or f"+{distname}" in text:
|
||||||
continue
|
ret[distname] = (round(insert_point[0], 1), round(insert_point[1], 1))
|
||||||
for distname in all_distributors:
|
|
||||||
if f"+{distname}" in entity_text:
|
|
||||||
ret[distname] = (round(insert_point[0], 1), round(insert_point[1], 1))
|
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def get_tunnel_positions(msp) -> dict:
|
def get_tunnel_positions_from_entities(entities) -> dict:
|
||||||
"""Hole alle Positionen aller Tunnel Ein und Ausgänge."""
|
"""Ermittelt Tunnel-Ein/Ausgangs-Positionen aus einer beliebigen Entity-Iterable.
|
||||||
|
|
||||||
|
Erwartet eine Iterable von DXF-Entities (z. B. aus `msp.query("MTEXT")` oder
|
||||||
|
`iterdxf.modelspace(dxf_path)`) und filtert nach den in der Config erlaubten
|
||||||
|
Layern. Erkennt Tunnel anhand des Musters "TUNNEL<nr>-<laenge>" und sammelt
|
||||||
|
pro Tunnelname die gefundenen Positionen sowie die Länge.
|
||||||
|
"""
|
||||||
all_tunnels = dict()
|
all_tunnels = dict()
|
||||||
tunnel_length = dict()
|
tunnel_length = dict()
|
||||||
all_layers = config.items('GetPos-Layer_Tunnel')
|
allowed_layers = {layer for (layer, _) in config.items('GetPos-Layer_Tunnel')}
|
||||||
for (layer, v) in all_layers:
|
|
||||||
selectstr = f'MTEXT[layer=="{layer}"]'
|
|
||||||
for text in msp.query(selectstr):
|
|
||||||
txt = text.dxf.text
|
|
||||||
pattern = r"(TUNNEL\d+)-(\d+)"
|
|
||||||
match = re.search(pattern, txt)
|
|
||||||
if match:
|
|
||||||
pos = (round(text.dxf.insert[0], 1), round(text.dxf.insert[1], 1))
|
|
||||||
tunnelname = match.group(1)
|
|
||||||
laenge = match.group(2)
|
|
||||||
tunnel_length[tunnelname] = laenge
|
|
||||||
if tunnelname not in all_tunnels:
|
|
||||||
all_tunnels[tunnelname] = list()
|
|
||||||
all_tunnels[tunnelname].append(pos)
|
|
||||||
else:
|
|
||||||
all_tunnels[tunnelname].append(pos)
|
|
||||||
if len(all_tunnels.keys()) > 0:
|
|
||||||
all_tunnels['length'] = tunnel_length
|
|
||||||
return all_tunnels
|
|
||||||
|
|
||||||
def get_tunnel_positions_iter(dxf_path) -> dict:
|
for entity in entities:
|
||||||
"""Hole alle Positionen aller Tunnel Ein- und Ausgänge mithilfe von iterdxf."""
|
|
||||||
all_tunnels = dict()
|
|
||||||
tunnel_length = dict()
|
|
||||||
all_layers = config.items('GetPos-Layer_Tunnel')
|
|
||||||
|
|
||||||
for entity in iterdxf.modelspace(dxf_path):
|
|
||||||
if entity.dxftype() != "MTEXT":
|
if entity.dxftype() != "MTEXT":
|
||||||
continue
|
continue
|
||||||
|
if entity.dxf.layer not in allowed_layers:
|
||||||
|
continue
|
||||||
|
|
||||||
txt = entity.dxf.text
|
txt = entity.dxf.text
|
||||||
layer = entity.dxf.layer
|
|
||||||
insert = entity.dxf.insert
|
insert = entity.dxf.insert
|
||||||
|
|
||||||
for (layer_name, _) in all_layers:
|
pattern = r"(TUNNEL\d+)-(\d+)"
|
||||||
if layer != layer_name:
|
match = re.search(pattern, txt)
|
||||||
continue
|
if not match:
|
||||||
|
continue
|
||||||
|
|
||||||
pattern = r"(TUNNEL\d+)-(\d+)"
|
tunnelname = match.group(1)
|
||||||
match = re.search(pattern, txt)
|
laenge = match.group(2)
|
||||||
if match:
|
pos = (round(insert[0], 1), round(insert[1], 1))
|
||||||
tunnelname = match.group(1)
|
|
||||||
laenge = match.group(2)
|
if tunnelname not in all_tunnels:
|
||||||
pos = (round(insert[0], 1), round(insert[1], 1))
|
all_tunnels[tunnelname] = []
|
||||||
|
all_tunnels[tunnelname].append(pos)
|
||||||
|
tunnel_length[tunnelname] = laenge
|
||||||
|
|
||||||
if tunnelname not in all_tunnels:
|
|
||||||
all_tunnels[tunnelname] = []
|
|
||||||
all_tunnels[tunnelname].append(pos)
|
|
||||||
tunnel_length[tunnelname] = laenge
|
|
||||||
if len(tunnel_length.keys()) > 0:
|
if len(tunnel_length.keys()) > 0:
|
||||||
all_tunnels['length'] = tunnel_length
|
all_tunnels['length'] = tunnel_length
|
||||||
return all_tunnels
|
return all_tunnels
|
||||||
@@ -777,7 +749,7 @@ if __name__ == '__main__':
|
|||||||
output_results = dict()
|
output_results = dict()
|
||||||
|
|
||||||
if args.sensors:
|
if args.sensors:
|
||||||
# Sensoren auslesen
|
# Sensoren auslesen aus den Symbolen
|
||||||
if use_iter:
|
if use_iter:
|
||||||
all_inserts, all_positions = attribs_to_dicts(iterdxf.modelspace(dxf_path))
|
all_inserts, all_positions = attribs_to_dicts(iterdxf.modelspace(dxf_path))
|
||||||
else:
|
else:
|
||||||
@@ -803,25 +775,23 @@ if __name__ == '__main__':
|
|||||||
if args.console:
|
if args.console:
|
||||||
print(to_json(res_mappings))
|
print(to_json(res_mappings))
|
||||||
|
|
||||||
# Distributoren auslesen
|
# Distributoren auslesen (generisch über Entities)
|
||||||
if use_iter:
|
if use_iter:
|
||||||
res_dist = get_subdistributor_positions_iter(dxf_path, res_mappings)
|
entities = iterdxf.modelspace(dxf_path)
|
||||||
else:
|
else:
|
||||||
res_dist = get_subdistributor_positions(msp, res_mappings)
|
entities = msp.query('MTEXT')
|
||||||
|
res_dist = get_subdistributor_positions_from_entities(entities, res_mappings)
|
||||||
output_results['distributors'] = res_dist
|
output_results['distributors'] = res_dist
|
||||||
|
|
||||||
if args.console:
|
if args.console:
|
||||||
print(to_json(res_dist))
|
print(to_json(res_dist))
|
||||||
|
|
||||||
# Tunnel auslesen
|
# Tunnel auslesen (generisch über Entities)
|
||||||
if use_iter:
|
if use_iter:
|
||||||
res_tunnel = get_tunnel_positions_iter(dxf_path)
|
t_entities = iterdxf.modelspace(dxf_path)
|
||||||
else:
|
else:
|
||||||
res_tunnel = get_tunnel_positions(msp)
|
t_entities = msp.query('MTEXT')
|
||||||
|
res_tunnel = get_tunnel_positions_from_entities(t_entities)
|
||||||
output_results['tunnels'] = res_tunnel
|
output_results['tunnels'] = res_tunnel
|
||||||
|
|
||||||
if args.console:
|
if args.console:
|
||||||
print(to_json(res_tunnel))
|
print(to_json(res_tunnel))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user