errorcollector für Fehler und Warnungen eingebaut.
This commit is contained in:
+10
-7
@@ -79,7 +79,7 @@ def read_config_layers(config_path: Path) -> list:
|
|||||||
return layers
|
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.
|
Extrahiert alle Attribute aus einem INSERT-Block.
|
||||||
Unterstützt zweistufige Blockstruktur:
|
Unterstützt zweistufige Blockstruktur:
|
||||||
@@ -89,6 +89,7 @@ def extract_block_attributes(doc, insert) -> dict:
|
|||||||
Args:
|
Args:
|
||||||
doc: DXF-Dokument
|
doc: DXF-Dokument
|
||||||
insert: INSERT-Entity des äußeren Blocks
|
insert: INSERT-Entity des äußeren Blocks
|
||||||
|
error_collector: Optional ErrorCollector für Warnungen
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dictionary mit allen gefundenen Attributen
|
Dictionary mit allen gefundenen Attributen
|
||||||
@@ -121,7 +122,9 @@ def extract_block_attributes(doc, insert) -> dict:
|
|||||||
attributes[tag] = value
|
attributes[tag] = value
|
||||||
break # Nur das erste INSERT mit Attributen verwenden
|
break # Nur das erste INSERT mit Attributen verwenden
|
||||||
except Exception as e:
|
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
|
return attributes
|
||||||
|
|
||||||
@@ -237,7 +240,7 @@ def point_in_polygon(point, polygon):
|
|||||||
return inside
|
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.
|
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)
|
# Prüfe ob der Block Attribute hat (direkt oder in zweistufiger Struktur)
|
||||||
# Verwende extract_block_attributes um beides zu unterstützen
|
# 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:
|
if not symbol_attribs:
|
||||||
continue
|
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
|
# Finde alle INSERT-Blöcke auf diesem Layer
|
||||||
for insert in msp.query(f'INSERT[layer=="{layer}"]'):
|
for insert in msp.query(f'INSERT[layer=="{layer}"]'):
|
||||||
# Extrahiere Attribute (unterstützt zweistufige Blockstruktur)
|
# Extrahiere Attribute (unterstützt zweistufige Blockstruktur)
|
||||||
attributes = extract_block_attributes(doc, insert)
|
attributes = extract_block_attributes(doc, insert, error_collector)
|
||||||
|
|
||||||
if not attributes:
|
if not attributes:
|
||||||
print(f" Block ohne Attribute gefunden an Position {insert.dxf.insert}")
|
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:
|
for insert, boundary, attributes, is_rectangle in group_blocks:
|
||||||
# Finde Symbole innerhalb dieses Bereichs
|
# 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
|
# Füge Symbole hinzu, aber nur wenn das Entity noch nicht gesehen wurde
|
||||||
for symbol in symbols:
|
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
|
# Finde alle Symbole mit "@" im IO-Attribut
|
||||||
symbols_with_at = []
|
symbols_with_at = []
|
||||||
for entity in msp.query('INSERT'):
|
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:
|
if not symbol_attribs:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user