symbol_frames.py in utils integriert
This commit is contained in:
@@ -14,7 +14,7 @@ import json
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import ezdxf
|
import ezdxf
|
||||||
|
|
||||||
from symbol_frames import draw_symbol_frames
|
from utils import draw_symbol_frames
|
||||||
|
|
||||||
# Umgebungsvariablen
|
# Umgebungsvariablen
|
||||||
PROJECT = os.getenv('PROJECT', Path(__file__).parent.parent.absolute())
|
PROJECT = os.getenv('PROJECT', Path(__file__).parent.parent.absolute())
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ from pathlib import Path
|
|||||||
from error_collector import ErrorCollector, write_json_file
|
from error_collector import ErrorCollector, write_json_file
|
||||||
from utils import (
|
from utils import (
|
||||||
check_environment_var, check_file_in_work, dxf_is_binary, get_dxf_file,
|
check_environment_var, check_file_in_work, dxf_is_binary, get_dxf_file,
|
||||||
extract_insert_attributes_with_doc as extract_block_attributes
|
extract_insert_attributes_with_doc as extract_block_attributes,
|
||||||
|
draw_symbol_frames
|
||||||
)
|
)
|
||||||
from symbol_frames import draw_symbol_frames
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
#!/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
|
|
||||||
@@ -469,6 +469,83 @@ def add_blockref_with_attributes(msp, block_name: str, insert_point: tuple,
|
|||||||
return blockref
|
return blockref
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def query_entities_by_layer(msp, entity_type: str = None, layers: list = None,
|
def query_entities_by_layer(msp, entity_type: str = None, layers: list = None,
|
||||||
exclude_layers: list = None):
|
exclude_layers: list = None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user