Merge branch 'main' of http://gitea.schoenenberger.de/mistangl/kabellaengen
This commit is contained in:
@@ -83,6 +83,7 @@ def new_dxf(plines, out_path):
|
||||
out_path (str): Der Pfad, unter dem die neue DXF-Datei gespeichert wird.
|
||||
"""
|
||||
doc = ezdxf.new('R2018', setup=True)
|
||||
doc.header['$INSUNITS'] = 4 # Millimeter
|
||||
draw_cables(plines, doc)
|
||||
draw_sensors(plines, doc)
|
||||
draw_subdists(plines, doc)
|
||||
|
||||
+52
-35
@@ -7,11 +7,8 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
import ezdxf
|
||||
import ezdxf.filemanagement
|
||||
from ezdxf.addons import iterdxf
|
||||
from shapely.geometry import Point
|
||||
|
||||
# Fix import for DXFStructureError
|
||||
from ezdxf.lldxf.const import DXFStructureError
|
||||
|
||||
|
||||
@@ -70,6 +67,38 @@ def get_attributes_of_insert(d_insert: dict, d_pos: dict) -> tuple[dict, str, st
|
||||
ld = d_insert
|
||||
typ = 'unknown'
|
||||
|
||||
# die neueren Bläcke heissen nicht IO, sondern haben einen Namen
|
||||
if "IO" in d_insert:
|
||||
pos = d_pos["IO"]
|
||||
typ = get_type_of_name_cfg(d_insert["IO"])
|
||||
|
||||
# neuer Block: Enthält alles was nötig is
|
||||
if "ARTINR" in d_insert and "SPS" in d_insert:
|
||||
id_ = d_insert["IO"]+"@"+d_insert["SPS"]
|
||||
ld["pos"] = (pos[0], pos[1])
|
||||
|
||||
if "REALE_POSITION" in d_insert and d_insert["REALE_POSITION"] == 'x':
|
||||
pos = d_pos["REALE_POSITION"]
|
||||
|
||||
else:
|
||||
|
||||
id_ = d_insert["IO"]
|
||||
# Sensoren werden später gemerged mit den anderen Blöcken des Rahmens mit A,B,C, usw
|
||||
if "SPS" in d_insert and typ != "Sensor":
|
||||
id_ = id_+"@"+d_insert["SPS"]
|
||||
|
||||
if "REALE_POSITION" in d_insert and d_insert["REALE_POSITION"] == 'x':
|
||||
pos = d_pos["REALE_POSITION"]
|
||||
|
||||
# Hoehe und Breite von "x" addieren, um Mittelpunkt zu finden
|
||||
breite_marker = config.getfloat("GetPos-Geom-Sensor", "Breite")
|
||||
hoehe_marker = config.getfloat("GetPos-Geom-Sensor", "Hoehe")
|
||||
midx = pos[0] + breite_marker * 0.5
|
||||
midy = pos[1] + hoehe_marker * 0.5
|
||||
ld["pos"] = (round(midx, 1), round(midy, 1))
|
||||
else:
|
||||
ld["pos"] = (pos[0], pos[1])
|
||||
|
||||
# die neueren Bläcke heissen nicht IO, sondern haben einen Namen
|
||||
if "NAME" in d_insert:
|
||||
typ = get_type_of_name_cfg(d_insert["NAME"])
|
||||
@@ -77,28 +106,7 @@ def get_attributes_of_insert(d_insert: dict, d_pos: dict) -> tuple[dict, str, st
|
||||
pos = d_pos["NAME"]
|
||||
ld["pos"] = (pos[0], pos[1])
|
||||
|
||||
if "IO" in d_insert:
|
||||
attr_text = d_insert["IO"]
|
||||
typ = get_type_of_name_cfg(attr_text)
|
||||
id_ = d_insert["IO"]
|
||||
# Sensoren werden später gemerged mit den anderen Blöcken des Rahmens mit A,B,C, usw
|
||||
if "SPS" in d_insert and typ != "Sensor":
|
||||
id_ = id_+"@"+d_insert["SPS"]
|
||||
pos = d_pos["IO"]
|
||||
|
||||
if "REALE_POSITION" in d_insert and d_insert["REALE_POSITION"] == 'x':
|
||||
pos = d_pos["REALE_POSITION"]
|
||||
|
||||
# Hoehe und Breite von "x" addieren, um Mittelpunkt zu finden
|
||||
breite_marker = config.getfloat("GetPos-Geom-Sensor", "Breite")
|
||||
hoehe_marker = config.getfloat("GetPos-Geom-Sensor", "Hoehe")
|
||||
midx = pos[0] + breite_marker * 0.5
|
||||
midy = pos[1] + hoehe_marker * 0.5
|
||||
ld["pos"] = (round(midx, 1), round(midy, 1))
|
||||
else:
|
||||
ld["pos"] = (pos[0], pos[1])
|
||||
|
||||
if "B" in d_insert:
|
||||
if "B" in d_insert and "IO" not in d_insert:
|
||||
attr_text = d_insert["B"]
|
||||
typ = get_type_of_name_cfg(attr_text)
|
||||
id_ = attr_text
|
||||
@@ -217,11 +225,14 @@ def extract_input_positions(insert_iterable) -> tuple[dict, dict, dict, dict]:
|
||||
ld, id_, typ = get_attributes_of_insert(insert, pos)
|
||||
|
||||
if typ == "Sensor":
|
||||
# wenn NAME enthalten ist, dann ist das ein eindeutiger Bezeichner
|
||||
# wenn NAME enthalten ist, z.B. bei Erdungslayouts, dann ist das ein eindeutiger Bezeichner
|
||||
if "NAME" in ld:
|
||||
all_sensors[id_] = ld
|
||||
# neuer Block der alle nötigen Infos enthält
|
||||
elif "IO" in ld and "ARTINR" in ld :
|
||||
all_sensors[id_] = ld
|
||||
# alle anderen Sachen werden dann aus mehreren Rahmen zusammen gesammelt
|
||||
else:
|
||||
# alle anderen Sachen werden dann aus mehreren Rahmen zusammen gesammelt
|
||||
wp.add_block(id_, ld)
|
||||
|
||||
elif typ == "Kabel":
|
||||
@@ -362,9 +373,13 @@ def create_mappings(positions: dict) -> tuple[dict, dict]:
|
||||
# Pfad zur Karte splitten. Dieser hat z.B. den Inhalt "=AH01+UH02-KF1FDI7"
|
||||
matches = re.findall(r'[^\-+=]+', unterverteiler_pfad.lstrip('='))
|
||||
if matches:
|
||||
anlage = matches[0]
|
||||
verteiler = matches[1]
|
||||
karte = matches[2]
|
||||
if len(matches) == 3:
|
||||
anlage = matches[0]
|
||||
verteiler = matches[1]
|
||||
karte = matches[2]
|
||||
else:
|
||||
warnings[sensorname] = f"Ungültiger Pfad in Kennzeichnung: {unterverteiler_pfad}: +, - oder = fehlen an entsprechender Stelle"
|
||||
|
||||
else:
|
||||
warnings[sensorname] = f"Ungültiger Pfad in Kennzeichnung: {unterverteiler_pfad}"
|
||||
continue
|
||||
@@ -414,7 +429,7 @@ def get_subdistributor_positions_iter(dxf_path, dist2sensors: dict) -> dict:
|
||||
if entity_layer != layer_name:
|
||||
continue
|
||||
for distname in all_distributors:
|
||||
if f"-{distname}" in entity_text:
|
||||
if f"+{distname}" in entity_text:
|
||||
ret[distname] = (round(insert_point[0], 1), round(insert_point[1], 1))
|
||||
|
||||
return ret
|
||||
@@ -651,6 +666,11 @@ def check_environment_var(env_str: str) -> Path:
|
||||
print(f"Umgebungsvariable {env_str} ist nicht gesetzt oder leer.")
|
||||
exit()
|
||||
|
||||
def get_input_positions_combined(source: str, use_iter: bool) -> tuple[dict, dict, dict, dict]:
|
||||
if use_iter:
|
||||
return get_input_positions_iter(source)
|
||||
else:
|
||||
return get_input_positions(source)
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='fetches the x/y positions from a dxf file', prog='getpositions')
|
||||
@@ -717,10 +737,7 @@ if __name__ == '__main__':
|
||||
|
||||
if args.sensors:
|
||||
# Sensoren auslesen
|
||||
if use_iter:
|
||||
res_sens, res_schaltschrank_elemente, res_double, missing_attribs = get_input_positions_iter(dxf_path)
|
||||
else:
|
||||
res_sens, res_schaltschrank_elemente, res_double, missing_attribs = get_input_positions(msp)
|
||||
res_sens, res_schaltschrank_elemente, res_double, missing_attribs = get_input_positions_combined(dxf_path if use_iter else msp, use_iter)
|
||||
|
||||
if args.errors and len(res_double) > 0:
|
||||
print("Duplicate blocks found. Writing errors-file.")
|
||||
|
||||
+31
-1
@@ -14,6 +14,10 @@ import shapely
|
||||
# Globale Variable, die in main aufgerufen wird und steuert ob Graphen in unittests gezeichnet werden
|
||||
draw = False
|
||||
class PointSorter:
|
||||
''' Klasse, die Punkte sortiert.
|
||||
Die Punkte werden in der Liste self.points gespeichert.
|
||||
Die Punkte werden sortiert nach x- und y-Koordinate.
|
||||
'''
|
||||
def __init__(self):
|
||||
self.points = []
|
||||
|
||||
@@ -34,6 +38,9 @@ def to_json(d, pretty: bool = True) -> str:
|
||||
return json.dumps(d, indent=2 if pretty else None, default=str) #ensure_ascii false für darstellung von "ue"
|
||||
|
||||
class NodeIDs():
|
||||
''' Klasse, die Punkte verwaltet und NodeIDs zu Punkten zuordnet.
|
||||
Die NodeIDs sind ganze Zahlen, die die Position der Punkte in der Liste self.points repräsentieren.
|
||||
'''
|
||||
def __init__(self, points=[]):
|
||||
self._counter = 0
|
||||
self._cord2id = dict()
|
||||
@@ -41,6 +48,8 @@ class NodeIDs():
|
||||
self.add_points(points)
|
||||
|
||||
def add_point(self, point:Point):
|
||||
''' Fügt den Punkt unter einer neuen NodeId hinzu.
|
||||
'''
|
||||
if self.point_exists(point):
|
||||
return True
|
||||
self._counter += 1
|
||||
@@ -78,6 +87,9 @@ class NodeIDs():
|
||||
return len(self._cord2id.keys())
|
||||
|
||||
def get_points(self, nids:list[int]) -> list[Point]:
|
||||
''' Gibt zu einer Liste von NodeIDs die zugehörigen Punkte zurück.
|
||||
Die Punkte werden in der gleichen Reihenfolge wie die NodeIDs zurückgegeben.
|
||||
'''
|
||||
ret = list()
|
||||
for n in nids:
|
||||
c = self.get_point(n)
|
||||
@@ -87,6 +99,9 @@ class NodeIDs():
|
||||
def show(self):
|
||||
return self._id2cord
|
||||
class RackIDs():
|
||||
''' Klasse, die Racks verwaltet und Rack-Racks und Rack-Equipment miteinander verbindet.
|
||||
Die Racks werden als Linien in den STR-Baum eingefügt.
|
||||
'''
|
||||
def __init__(self, tol_snap = 200.0):
|
||||
self._point2rack = dict()
|
||||
self._rack2begend = dict()
|
||||
@@ -96,12 +111,18 @@ class RackIDs():
|
||||
self._rack_tree = None
|
||||
|
||||
def add_rack(self, beg:Point, end:Point, name:str):
|
||||
''' Fügt einen Rack hinzu.
|
||||
Fügt die Anfangs- und Endpunkte des Racks zu den Racks hinzu.
|
||||
'''
|
||||
self.add_point_to_rack(beg, name)
|
||||
self.add_point_to_rack(end, name)
|
||||
|
||||
self._rack2begend[name] = (beg, end) # Anfangs und Endpunkte zu Rack Namen merken
|
||||
|
||||
def add_racks(self, racks:dict):
|
||||
''' Fügt Racks hinzu.
|
||||
Fügt die Anfangs- und Endpunkte der Racks zu den Racks hinzu.
|
||||
'''
|
||||
for name,v in racks.items():
|
||||
if len(v) == 2:
|
||||
self.add_rack(v[0], v[1], name)
|
||||
@@ -151,6 +172,9 @@ class RackIDs():
|
||||
return ret_sorted
|
||||
|
||||
def _build_rack_strtree(self):
|
||||
''' Erzeugt einen STR-Baum aus den Racks.
|
||||
Die Racks werden als Linien in den STR-Baum eingefügt.
|
||||
'''
|
||||
self._rack_lines = []
|
||||
self._rack_map = {}
|
||||
for r_name, pts in self.get_racks_borders().items():
|
||||
@@ -160,6 +184,9 @@ class RackIDs():
|
||||
self._rack_tree = STRtree(self._rack_lines)
|
||||
|
||||
def join_racks_str(self):
|
||||
''' Verbindet Racks miteinander.
|
||||
Die Racks werden als Linien in den STR-Baum eingefügt.
|
||||
'''
|
||||
if self._rack_tree is None:
|
||||
self._build_rack_strtree()
|
||||
|
||||
@@ -192,7 +219,10 @@ class RackIDs():
|
||||
connrackname = f"c-{rnames[l2]}-{rnames[l1]}"
|
||||
self.add_rack(pt, snap_point, connrackname)
|
||||
|
||||
def rack_is_horizontal(self, name):
|
||||
def rack_is_horizontal(self, name):
|
||||
''' Gibt True zurück, wenn der Rack horizontal ist.
|
||||
False, wenn der Rack vertikal ist.
|
||||
'''
|
||||
[pa, pe] = self._rack2begend[name]
|
||||
if pa.y == pe.y:
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user