errorcollector für Fehler und Warnungen eingebaut.

This commit is contained in:
2026-01-26 16:48:50 +01:00
parent 657d0d99f7
commit b82c751ba9
+10 -7
View File
@@ -79,7 +79,7 @@ def read_config_layers(config_path: Path) -> list:
return layers
def extract_block_attributes(doc, insert) -> dict:
def extract_block_attributes(doc, insert, error_collector=None) -> dict:
"""
Extrahiert alle Attribute aus einem INSERT-Block.
Unterstützt zweistufige Blockstruktur:
@@ -89,6 +89,7 @@ def extract_block_attributes(doc, insert) -> dict:
Args:
doc: DXF-Dokument
insert: INSERT-Entity des äußeren Blocks
error_collector: Optional ErrorCollector für Warnungen
Returns:
Dictionary mit allen gefundenen Attributen
@@ -121,7 +122,9 @@ def extract_block_attributes(doc, insert) -> dict:
attributes[tag] = value
break # Nur das erste INSERT mit Attributen verwenden
except Exception as e:
print(f" Warnung: Fehler beim Extrahieren der Attribute aus Block: {e}")
error_msg = f"Fehler beim Extrahieren der Attribute aus Block '{insert.dxf.name}': {e}"
if error_collector:
error_collector.add_warnings({"attribute_extraction_error": error_msg})
return attributes
@@ -237,7 +240,7 @@ def point_in_polygon(point, polygon):
return inside
def find_symbols_in_boundary(doc, msp, boundary, target_layers, attributes):
def find_symbols_in_boundary(doc, msp, boundary, target_layers, attributes, error_collector=None):
"""
Findet alle Symbole (INSERT-Blöcke) innerhalb des angegebenen Bereichs auf den Ziel-Layern.
"""
@@ -261,7 +264,7 @@ def find_symbols_in_boundary(doc, msp, boundary, target_layers, attributes):
# Prüfe ob der Block Attribute hat (direkt oder in zweistufiger Struktur)
# Verwende extract_block_attributes um beides zu unterstützen
symbol_attribs = extract_block_attributes(doc, entity)
symbol_attribs = extract_block_attributes(doc, entity, error_collector)
if not symbol_attribs:
continue
@@ -461,7 +464,7 @@ def collect_and_group_renamer_blocks(doc, msp, renamer_layers, error_collector):
# Finde alle INSERT-Blöcke auf diesem Layer
for insert in msp.query(f'INSERT[layer=="{layer}"]'):
# Extrahiere Attribute (unterstützt zweistufige Blockstruktur)
attributes = extract_block_attributes(doc, insert)
attributes = extract_block_attributes(doc, insert, error_collector)
if not attributes:
print(f" Block ohne Attribute gefunden an Position {insert.dxf.insert}")
@@ -538,7 +541,7 @@ def process_renamer_groups(doc, msp, renamer_layers, renamer_groups, error_colle
for insert, boundary, attributes, is_rectangle in group_blocks:
# Finde Symbole innerhalb dieses Bereichs
symbols = find_symbols_in_boundary(doc, msp, boundary, renamer_layers, attributes)
symbols = find_symbols_in_boundary(doc, msp, boundary, renamer_layers, attributes, error_collector)
# Füge Symbole hinzu, aber nur wenn das Entity noch nicht gesehen wurde
for symbol in symbols:
@@ -615,7 +618,7 @@ def check_symbols_in_boundaries(doc, msp, renamer_groups, error_collector):
# Finde alle Symbole mit "@" im IO-Attribut
symbols_with_at = []
for entity in msp.query('INSERT'):
symbol_attribs = extract_block_attributes(doc, entity)
symbol_attribs = extract_block_attributes(doc, entity, error_collector)
if not symbol_attribs:
continue