From 745b6df6def78e39714533b3b7dd817ec13fbec3 Mon Sep 17 00:00:00 2001 From: lertlmaier Date: Tue, 1 Jul 2025 13:07:40 +0200 Subject: [PATCH] Racks zeichnen: Dataclasses angelegt, Methode zum zeichnen + Beschriftung, excel ausgabe auf neue struktur angepasst --- lib/drawdxf.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/lib/drawdxf.py b/lib/drawdxf.py index 838508a..20201cf 100644 --- a/lib/drawdxf.py +++ b/lib/drawdxf.py @@ -13,6 +13,8 @@ import configparser import updateconfignames as uc + + @dataclass class Point: x: float @@ -43,6 +45,18 @@ class Error_Routing: unterverteiler: str sensoren: List[str] +@dataclass +class Coordinate: + x: float + y: float + z: float + +@dataclass +class RackGeometry: + length: float + coordinates: List[Coordinate] + + @dataclass class Polylines: kabel: List[Polyline] @@ -52,7 +66,7 @@ class Polylines: errors_dists_not_in_layout: List[str] errors_sensors_not_in_layout: List[str] errors_missing_attributes: Dict[str, str] - rack_lengths: Dict[str, float] = field(default_factory = dict) + rack_geometry: Dict[str, RackGeometry] = field(default_factory=dict) def add_polyline(msp, points:Polyline, dxf_attribs): @@ -69,6 +83,7 @@ def new_dxf(plines, out_path): draw_cables(plines, doc) draw_sensors(plines, doc) draw_subdists(plines, doc) + draw_racks(plines, doc) doc.saveas(out_path) print("done") @@ -116,6 +131,64 @@ def draw_cables(plines, doc): # Polyline für Kabel zeichnen add_polyline(msp, pl, dxfattribs_cable) +def draw_racks(plines, doc): + msp = doc.modelspace() + timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M") + rack_layer = f"racks_{timestamp}" + + # Rack-Layer anlegen (Farbe 3 = grün z.B.) + if rack_layer not in doc.layers: + doc.layers.add(name=rack_layer, color=3, lineweight=200) # lineweight für Dicke + + dxfattribs_rack = { + "layer": rack_layer, + "color": 3, + "lineweight": 200 # Lineweight (in 1/100 mm) + } + + for rack_name, rack_geom in plines.rack_geometry.items(): + classifier = rack_name[0] + + if classifier in ("t", "v", "c", "d"): + continue + + coords = [(pt.x, pt.y, pt.z) for pt in rack_geom.coordinates] + if not coords: + continue + + polyline = msp.add_polyline3d(coords, dxfattribs=dxfattribs_rack) + + if coords: + x, y, z = coords[0] # Get the first coordinate for text placement + + # Orientierung bestimmen (horizontal oder vertikal) + if len(coords) >= 2: + x2, y2, _ = coords[1] + dx = x2 - x + dy = y2 - y + + is_vertical = abs(dy) > abs(dx) + else: + is_vertical = False # Standard: horizontal + + # Text platzieren + text_entity = msp.add_text( + rack_name, + dxfattribs={ + "layer": rack_layer, + "height": 75, + "color": 3, + "rotation": 90 if is_vertical else 0, + } + ) + + # Offset definieren + offset_x = -50 if is_vertical else 50 + offset_y = 100 if is_vertical else 50 + + text_entity.set_placement((x + offset_x, y + offset_y)) + + def find_close_key(pos2sensors, x, y, tolerance=10): # !!! Toleranz nicht in Config !!! ''' Funktion überprüft ob Sensoren nahezu identisch an der gleichen Stelle liegen und legt sie in diesem fall aufeinander Wird benötigt, um zusammengehörige Sensoren gestaffelt auf dxf zu zeichen @@ -411,12 +484,12 @@ def _create_rack_lengths_sheet(ws, plines): ws.column_dimensions['A'].width = 18 ws.column_dimensions['B'].width = 15 - for rackname, length in plines.rack_lengths.items(): + for rackname, rack_geom in plines.rack_geometry.items(): classifier = rackname[0] if classifier in ("t", "v", "c", "d"): continue else: - ws.append([rackname, length]) + ws.append([rackname, rack_geom.length]) def _create_error_sheets(wb, plines): """Erstellt die Arbeitsblätter für alle aufgetretenen Fehler."""