Files
kabellaengen/lib/symbol_frames.py
T

86 lines
2.8 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
symbol_frames.py - Funktionen zum Zeichnen von Symbol-Rahmen zur Visualisierung
Dieses Modul enthält wiederverwendbare Funktionen zum Zeichnen von Rahmen
um Symbole in DXF-Dateien, um deren berechnete Grenzen zu visualisieren.
"""
def draw_symbol_frames(doc, msp, symbols, symbol_width=1210, symbol_height=381, frame_layer="SYMBOL_FRAMES"):
"""
Zeichnet Rahmen um alle Symbole zur Visualisierung der Symbol-Grenzen.
Args:
doc: DXF-Dokument
msp: Modelspace
symbols: Liste von Symbol-Dictionaries mit 'entity', 'position', 'attributes'
symbol_width: Feste Breite des Symbols (Standard: 1210 für MA-Frame)
symbol_height: Feste Höhe des Symbols (Standard: 381)
frame_layer: Layer-Name für die Rahmen (Standard: "SYMBOL_FRAMES")
Returns:
Anzahl der gezeichneten Rahmen
"""
print("\n" + "="*60)
print("Zeichne Symbol-Rahmen zur Visualisierung")
print("="*60)
# Erstelle Layer falls nicht vorhanden
if frame_layer not in doc.layers:
doc.layers.add(frame_layer, color=3) # Farbe 3 = Grün
print(f" Layer '{frame_layer}' erstellt (Farbe: Grün)")
frame_count = 0
for symbol in symbols:
# Hole Position und Attribute
pos = symbol['position']
attribs = symbol['attributes']
# Hole IO-Attribut um die Zeichen-Anzahl zu bestimmen
io_value = attribs.get('IO', '')
if not io_value:
# Versuche andere Attribute als Fallback
for key in ['KENNZEICHNUNG', 'NAME']:
if key in attribs and attribs[key]:
io_value = attribs[key]
break
# Bestimme Dimensionen basierend auf Zeichen-Anzahl
# 6 Zeichen (MA-1@@) = 1210, 7 Zeichen (BG-1@@@) = 1410
char_count = len(str(io_value))
if char_count >= 7:
width = 1410 # Multi-Frame (BG/MB/POT)
else:
width = symbol_width # MA-Frame (Standard)
height = symbol_height
# Berechne Eckpunkte (Position = linke untere Ecke des Symbols)
# Symbol erstreckt sich von (x, y) nach rechts und nach oben
x_min = pos[0]
x_max = pos[0] + width
y_min = pos[1]
y_max = pos[1] + height
# Erstelle Rechteck als LWPOLYLINE
points = [
(x_min, y_min),
(x_max, y_min),
(x_max, y_max),
(x_min, y_max),
(x_min, y_min) # Schließe das Rechteck
]
msp.add_lwpolyline(points, dxfattribs={
'layer': frame_layer,
'color': 3, # Grün
'closed': True
})
frame_count += 1
print(f" {frame_count} Symbol-Rahmen gezeichnet")
return frame_count