Racks zeichnen: Dataclasses angelegt, Methode zum zeichnen + Beschriftung, excel ausgabe auf neue struktur angepasst

This commit is contained in:
2025-07-01 13:07:40 +02:00
parent 7c2e171f7d
commit 745b6df6de
+76 -3
View File
@@ -13,6 +13,8 @@ import configparser
import updateconfignames as uc import updateconfignames as uc
@dataclass @dataclass
class Point: class Point:
x: float x: float
@@ -43,6 +45,18 @@ class Error_Routing:
unterverteiler: str unterverteiler: str
sensoren: List[str] sensoren: List[str]
@dataclass
class Coordinate:
x: float
y: float
z: float
@dataclass
class RackGeometry:
length: float
coordinates: List[Coordinate]
@dataclass @dataclass
class Polylines: class Polylines:
kabel: List[Polyline] kabel: List[Polyline]
@@ -52,7 +66,7 @@ class Polylines:
errors_dists_not_in_layout: List[str] errors_dists_not_in_layout: List[str]
errors_sensors_not_in_layout: List[str] errors_sensors_not_in_layout: List[str]
errors_missing_attributes: Dict[str, 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): def add_polyline(msp, points:Polyline, dxf_attribs):
@@ -69,6 +83,7 @@ def new_dxf(plines, out_path):
draw_cables(plines, doc) draw_cables(plines, doc)
draw_sensors(plines, doc) draw_sensors(plines, doc)
draw_subdists(plines, doc) draw_subdists(plines, doc)
draw_racks(plines, doc)
doc.saveas(out_path) doc.saveas(out_path)
print("done") print("done")
@@ -116,6 +131,64 @@ def draw_cables(plines, doc):
# Polyline für Kabel zeichnen # Polyline für Kabel zeichnen
add_polyline(msp, pl, dxfattribs_cable) 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 !!! 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 ''' 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 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['A'].width = 18
ws.column_dimensions['B'].width = 15 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] classifier = rackname[0]
if classifier in ("t", "v", "c", "d"): if classifier in ("t", "v", "c", "d"):
continue continue
else: else:
ws.append([rackname, length]) ws.append([rackname, rack_geom.length])
def _create_error_sheets(wb, plines): def _create_error_sheets(wb, plines):
"""Erstellt die Arbeitsblätter für alle aufgetretenen Fehler.""" """Erstellt die Arbeitsblätter für alle aufgetretenen Fehler."""