From fdf975e661320b2471dae3913d667873a26663a2 Mon Sep 17 00:00:00 2001 From: mistangl Date: Fri, 30 Jan 2026 15:53:47 +0100 Subject: [PATCH] symbol_frames.py in utils integriert --- lib/create_example.py | 2 +- lib/create_numbers.py | 4 +- lib/symbol_frames.py | 85 ------------------------------------------- lib/utils.py | 77 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 88 deletions(-) delete mode 100644 lib/symbol_frames.py diff --git a/lib/create_example.py b/lib/create_example.py index 58df837..8c087aa 100644 --- a/lib/create_example.py +++ b/lib/create_example.py @@ -14,7 +14,7 @@ import json from pathlib import Path import ezdxf -from symbol_frames import draw_symbol_frames +from utils import draw_symbol_frames # Umgebungsvariablen PROJECT = os.getenv('PROJECT', Path(__file__).parent.parent.absolute()) diff --git a/lib/create_numbers.py b/lib/create_numbers.py index 0f5b12c..7c2bb89 100644 --- a/lib/create_numbers.py +++ b/lib/create_numbers.py @@ -5,9 +5,9 @@ from pathlib import Path from error_collector import ErrorCollector, write_json_file from utils import ( 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 """ diff --git a/lib/symbol_frames.py b/lib/symbol_frames.py deleted file mode 100644 index 9d82657..0000000 --- a/lib/symbol_frames.py +++ /dev/null @@ -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 diff --git a/lib/utils.py b/lib/utils.py index 7f614d7..9b7c43c 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -469,6 +469,83 @@ def add_blockref_with_attributes(msp, block_name: str, insert_point: tuple, 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, exclude_layers: list = None): """