utils enthält jetzt generelle Routinen der verschiedenen Programme. create_example refactored. utils wird jetzt entsprechend überall importiert
This commit is contained in:
+306
-135
@@ -3,7 +3,10 @@ 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
|
||||
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
|
||||
)
|
||||
from symbol_frames import draw_symbol_frames
|
||||
|
||||
|
||||
@@ -80,56 +83,6 @@ def read_config_layers(config_path: Path) -> list:
|
||||
return layers
|
||||
|
||||
|
||||
def extract_block_attributes(doc, insert, error_collector=None) -> dict:
|
||||
"""
|
||||
Extrahiert alle Attribute aus einem INSERT-Block.
|
||||
Unterstützt zweistufige Blockstruktur:
|
||||
- Äußerer Block enthält LWPOLYLINE und INSERT zu Attribut-Block
|
||||
- Innerer Attribut-Block enthält die eigentlichen Attribute
|
||||
|
||||
Args:
|
||||
doc: DXF-Dokument
|
||||
insert: INSERT-Entity des äußeren Blocks
|
||||
error_collector: Optional ErrorCollector für Warnungen
|
||||
|
||||
Returns:
|
||||
Dictionary mit allen gefundenen Attributen
|
||||
"""
|
||||
attributes = {}
|
||||
if insert.dxftype() != 'INSERT':
|
||||
return attributes
|
||||
|
||||
# Prüfe zuerst ob der Block direkt Attribute hat (alte Struktur)
|
||||
# Sammle alle direkten Attribute
|
||||
direct_attribs = list(insert.attribs)
|
||||
if direct_attribs:
|
||||
for attrib in direct_attribs:
|
||||
tag = attrib.dxf.tag
|
||||
value = attrib.dxf.text
|
||||
attributes[tag] = value
|
||||
return attributes
|
||||
|
||||
# Neue zweistufige Struktur: Suche im Block nach einem INSERT mit Attributen
|
||||
try:
|
||||
block_layout = doc.blocks.get(insert.dxf.name)
|
||||
for entity in block_layout:
|
||||
if entity.dxftype() == 'INSERT':
|
||||
inner_attribs = list(entity.attribs)
|
||||
if inner_attribs:
|
||||
# Gefunden: innerer Block mit Attributen
|
||||
for attrib in inner_attribs:
|
||||
tag = attrib.dxf.tag
|
||||
value = attrib.dxf.text
|
||||
attributes[tag] = value
|
||||
break # Nur das erste INSERT mit Attributen verwenden
|
||||
except Exception as 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
|
||||
|
||||
|
||||
def is_rectangle_polyline(points):
|
||||
"""
|
||||
Prüft, ob eine Liste von Punkten ein Rechteck darstellt.
|
||||
@@ -374,6 +327,26 @@ def enumerate_symbols(symbols, attributes):
|
||||
return renamed
|
||||
|
||||
|
||||
def get_layer_names_from_attributes(attributes):
|
||||
"""
|
||||
Extrahiert alle LAYER_NAME Attribute aus einem Renamer-Block.
|
||||
|
||||
Args:
|
||||
attributes: Dictionary mit Block-Attributen
|
||||
|
||||
Returns:
|
||||
Liste der Layer-Namen (z.B. ['ILS_Eingang', 'ILS_Ausgang'])
|
||||
"""
|
||||
layer_names = []
|
||||
if "LAYER_NAME" in attributes and attributes["LAYER_NAME"]:
|
||||
layer_names.append(attributes["LAYER_NAME"])
|
||||
for i in range(1, 4):
|
||||
layer_key = f"LAYER_NAME{i}"
|
||||
if layer_key in attributes and attributes[layer_key]:
|
||||
layer_names.append(attributes[layer_key])
|
||||
return layer_names
|
||||
|
||||
|
||||
def get_renamer_config_key(attributes):
|
||||
"""
|
||||
Erstellt einen eindeutigen Schlüssel für die Renamer-Block-Konfiguration.
|
||||
@@ -516,11 +489,153 @@ def collect_and_group_renamer_blocks(doc, msp, renamer_layers, error_collector):
|
||||
|
||||
return renamer_groups
|
||||
|
||||
|
||||
def find_template_symbols_in_geometry(doc, msp, group_blocks, error_collector):
|
||||
"""
|
||||
Findet alle Symbole mit '@' die geometrisch in den Renamer-Bereichen liegen,
|
||||
unabhängig vom Layer.
|
||||
|
||||
Args:
|
||||
doc: DXF-Dokument
|
||||
msp: Modelspace
|
||||
group_blocks: Liste von (insert, boundary, attributes, is_rectangle) Tupeln
|
||||
error_collector: ErrorCollector für Fehlerbehandlung
|
||||
|
||||
Returns:
|
||||
Liste von Dictionaries mit 'layer', 'position', 'io' für jedes gefundene Symbol
|
||||
"""
|
||||
symbols_in_geometry = []
|
||||
for insert, boundary, attributes, is_rectangle in group_blocks:
|
||||
for entity in msp.query('INSERT'):
|
||||
symbol_attribs = extract_block_attributes(doc, entity, error_collector)
|
||||
if not symbol_attribs:
|
||||
continue
|
||||
|
||||
# Prüfe ob irgendein Attribut "@" enthält
|
||||
has_template = any('@' in str(value) for value in symbol_attribs.values())
|
||||
|
||||
if has_template:
|
||||
pos = entity.dxf.insert
|
||||
point = (pos[0], pos[1])
|
||||
if point_in_polygon(point, boundary):
|
||||
symbols_in_geometry.append({
|
||||
'layer': entity.dxf.layer,
|
||||
'position': point,
|
||||
'io': symbol_attribs.get('IO', 'N/A')
|
||||
})
|
||||
return symbols_in_geometry
|
||||
|
||||
|
||||
def create_no_symbols_found_error_message(block_name, direction, layer_names, group_blocks,
|
||||
doc, msp, error_collector):
|
||||
"""
|
||||
Erstellt eine detaillierte Fehlermeldung wenn keine Symbole in einem Renamer-Bereich gefunden wurden.
|
||||
|
||||
Args:
|
||||
block_name: Name des Renamer-Blocks
|
||||
direction: DIRECTION-Attribut
|
||||
layer_names: Liste der erwarteten Layer-Namen
|
||||
group_blocks: Liste von (insert, boundary, attributes, is_rectangle) Tupeln
|
||||
doc: DXF-Dokument
|
||||
msp: Modelspace
|
||||
error_collector: ErrorCollector für Fehlerbehandlung
|
||||
|
||||
Returns:
|
||||
Fehlermeldungs-String
|
||||
"""
|
||||
renamer_positions = [f"({insert.dxf.insert[0]:.1f}, {insert.dxf.insert[1]:.1f})"
|
||||
for insert, _, _, _ in group_blocks]
|
||||
|
||||
# Prüfe ob es Symbole mit @ gibt, die geometrisch im Bereich liegen (egal auf welchem Layer)
|
||||
symbols_in_geometry = find_template_symbols_in_geometry(doc, msp, group_blocks, error_collector)
|
||||
|
||||
# Erstelle Fehlermeldung basierend auf gefundenen Symbolen
|
||||
if symbols_in_geometry and not layer_names:
|
||||
# Es gibt Symbole im Bereich, aber keine LAYER_NAME Attribute definiert
|
||||
return (
|
||||
f"Renamer-Block-Gruppe '{block_name}' (DIRECTION: {direction}) "
|
||||
f"hat keine passenden Symbole gefunden. "
|
||||
f"Es wurden {len(symbols_in_geometry)} Symbol(e) mit '@' geometrisch im Bereich gefunden, "
|
||||
f"aber der Renamer-Block hat KEINE LAYER_NAME Attribute (LAYER_NAME1, LAYER_NAME2, LAYER_NAME3) definiert. "
|
||||
f"Ohne diese Attribute können Symbole nicht zugeordnet werden. "
|
||||
f"Renamer-Blöcke an Positionen: {', '.join(renamer_positions)}"
|
||||
)
|
||||
elif symbols_in_geometry and layer_names:
|
||||
# Es gibt Symbole im Bereich, aber sie sind auf falschen Layern
|
||||
found_layers = set(s['layer'] for s in symbols_in_geometry)
|
||||
return (
|
||||
f"Renamer-Block-Gruppe '{block_name}' (DIRECTION: {direction}) "
|
||||
f"hat keine passenden Symbole gefunden. "
|
||||
f"Es wurden {len(symbols_in_geometry)} Symbol(e) mit '@' geometrisch im Bereich gefunden, "
|
||||
f"aber diese sind auf Layer: {', '.join(found_layers)}. "
|
||||
f"Erwartet werden Layer: {', '.join(layer_names)}. "
|
||||
f"Prüfen Sie die LAYER_NAME Attribute im Renamer-Block. "
|
||||
f"Renamer-Blöcke an Positionen: {', '.join(renamer_positions)}"
|
||||
)
|
||||
else:
|
||||
# Keine Symbole im Bereich gefunden (weder geometrisch noch auf richtigen Layern)
|
||||
return (
|
||||
f"Renamer-Block-Gruppe '{block_name}' (DIRECTION: {direction}) "
|
||||
f"hat keine passenden Symbole gefunden. "
|
||||
f"Gesucht auf Layer: {', '.join(layer_names) if layer_names else 'N/A'}. "
|
||||
f"Renamer-Blöcke an Positionen: {', '.join(renamer_positions)}"
|
||||
)
|
||||
|
||||
|
||||
def collect_symbols_from_group(doc, msp, renamer_layers, group_blocks, block_name, error_collector):
|
||||
"""
|
||||
Sammelt alle Symbole aus allen Boundaries einer Renamer-Gruppe.
|
||||
Prüft auf Duplikate (Symbole in mehreren Bereichen).
|
||||
|
||||
Args:
|
||||
doc: DXF-Dokument
|
||||
msp: Modelspace
|
||||
renamer_layers: Layer auf denen nach Renamer-Blöcken gesucht wird
|
||||
group_blocks: Liste von (insert, boundary, attributes, is_rectangle) Tupeln
|
||||
block_name: Name des Renamer-Blocks (für Fehlermeldungen)
|
||||
error_collector: ErrorCollector für Fehlerbehandlung
|
||||
|
||||
Returns:
|
||||
Liste aller eindeutigen Symbole
|
||||
"""
|
||||
all_symbols = []
|
||||
seen_entities = {} # {entity_id: (symbol, [list of renamer block positions])}
|
||||
|
||||
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, error_collector)
|
||||
|
||||
# Füge Symbole hinzu, aber nur wenn das Entity noch nicht gesehen wurde
|
||||
for symbol in symbols:
|
||||
entity_id = id(symbol['entity']) # Eindeutige ID des Entity-Objekts
|
||||
renamer_pos = insert.dxf.insert
|
||||
|
||||
if entity_id not in seen_entities:
|
||||
seen_entities[entity_id] = (symbol, [renamer_pos])
|
||||
all_symbols.append(symbol)
|
||||
else:
|
||||
# Symbol wurde bereits in einem anderen Bereich gefunden - Fehler
|
||||
existing_symbol, existing_positions = seen_entities[entity_id]
|
||||
existing_positions.append(renamer_pos)
|
||||
symbol_pos = symbol['position']
|
||||
io_value = symbol['attributes'].get('IO', 'N/A')
|
||||
error_msg = (
|
||||
f"Symbol an Position ({symbol_pos[0]:.1f}, {symbol_pos[1]:.1f}) "
|
||||
f"mit IO='{io_value}' liegt in mehreren Renamer-Bereichen der Gruppe '{block_name}'. "
|
||||
f"Gefunden in Renamer-Blöcken an Positionen: "
|
||||
f"{', '.join([f'({p[0]:.1f}, {p[1]:.1f})' for p in existing_positions])}"
|
||||
)
|
||||
print(f" FEHLER: {error_msg}")
|
||||
error_collector.add_errors({"symbol_in_multiple_boundaries": error_msg})
|
||||
|
||||
return all_symbols
|
||||
|
||||
|
||||
def process_renamer_groups(doc, msp, renamer_layers, renamer_groups, error_collector):
|
||||
"""
|
||||
Zweiter Pass: Verarbeitet jede Renamer-Block-Gruppe.
|
||||
Sammelt Symbole, sortiert sie und nummeriert sie.
|
||||
|
||||
|
||||
Returns:
|
||||
Liste aller umbenannten Symbole
|
||||
"""
|
||||
@@ -538,55 +653,15 @@ def process_renamer_groups(doc, msp, renamer_layers, renamer_groups, error_colle
|
||||
print(f"\n Verarbeite Gruppe: {block_name} ({len(group_blocks)} Renamer-Blöcke)")
|
||||
|
||||
# Sammle Symbole aus ALLEN Boundaries dieser Gruppe
|
||||
all_symbols = []
|
||||
seen_entities = {} # {entity_id: (symbol, [list of renamer block positions])}
|
||||
|
||||
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, error_collector)
|
||||
|
||||
# Füge Symbole hinzu, aber nur wenn das Entity noch nicht gesehen wurde
|
||||
for symbol in symbols:
|
||||
entity_id = id(symbol['entity']) # Eindeutige ID des Entity-Objekts
|
||||
renamer_pos = insert.dxf.insert
|
||||
|
||||
if entity_id not in seen_entities:
|
||||
seen_entities[entity_id] = (symbol, [renamer_pos])
|
||||
all_symbols.append(symbol)
|
||||
else:
|
||||
# Symbol wurde bereits in einem anderen Bereich gefunden - Fehler
|
||||
existing_symbol, existing_positions = seen_entities[entity_id]
|
||||
existing_positions.append(renamer_pos)
|
||||
symbol_pos = symbol['position']
|
||||
io_value = symbol['attributes'].get('IO', 'N/A')
|
||||
error_msg = (
|
||||
f"Symbol an Position ({symbol_pos[0]:.1f}, {symbol_pos[1]:.1f}) "
|
||||
f"mit IO='{io_value}' liegt in mehreren Renamer-Bereichen der Gruppe '{block_name}'. "
|
||||
f"Gefunden in Renamer-Blöcken an Positionen: "
|
||||
f"{', '.join([f'({p[0]:.1f}, {p[1]:.1f})' for p in existing_positions])}"
|
||||
)
|
||||
print(f" FEHLER: {error_msg}")
|
||||
error_collector.add_errors({"symbol_in_multiple_boundaries": error_msg})
|
||||
all_symbols = collect_symbols_from_group(doc, msp, renamer_layers, group_blocks, block_name, error_collector)
|
||||
|
||||
print(f" Gesamt {len(all_symbols)} eindeutige Template-Symbole aus {len(group_blocks)} Blöcken")
|
||||
|
||||
if not all_symbols:
|
||||
# Fehlermeldung: Keine Symbole gefunden
|
||||
layer_names = []
|
||||
for i in range(1, 4):
|
||||
layer_key = f"LAYER_NAME{i}"
|
||||
if layer_key in reference_attributes and reference_attributes[layer_key]:
|
||||
layer_names.append(reference_attributes[layer_key])
|
||||
if "LAYER_NAME" in reference_attributes and reference_attributes["LAYER_NAME"]:
|
||||
layer_names.append(reference_attributes["LAYER_NAME"])
|
||||
|
||||
renamer_positions = [f"({insert.dxf.insert[0]:.1f}, {insert.dxf.insert[1]:.1f})"
|
||||
for insert, _, _, _ in group_blocks]
|
||||
error_msg = (
|
||||
f"Renamer-Block-Gruppe '{block_name}' (DIRECTION: {direction}) "
|
||||
f"hat keine passenden Symbole gefunden. "
|
||||
f"Gesucht auf Layer: {', '.join(layer_names) if layer_names else 'N/A'}. "
|
||||
f"Renamer-Blöcke an Positionen: {', '.join(renamer_positions)}"
|
||||
layer_names = get_layer_names_from_attributes(reference_attributes)
|
||||
error_msg = create_no_symbols_found_error_message(
|
||||
block_name, direction, layer_names, group_blocks, doc, msp, error_collector
|
||||
)
|
||||
print(f" FEHLER: {error_msg}")
|
||||
error_collector.add_errors({"no_symbols_found": error_msg})
|
||||
@@ -603,27 +678,25 @@ def process_renamer_groups(doc, msp, renamer_layers, renamer_groups, error_colle
|
||||
|
||||
return all_renamed
|
||||
|
||||
def check_symbols_in_boundaries(doc, msp, renamer_groups, error_collector):
|
||||
|
||||
def find_symbols_with_at_in_io(doc, msp, error_collector):
|
||||
"""
|
||||
Dritter Pass: Prüft ob alle Symbole mit "@" im IO in einem Renamer-Bereich liegen.
|
||||
Findet alle Symbole mit "@" im IO-Attribut.
|
||||
|
||||
Args:
|
||||
doc: DXF-Dokument
|
||||
msp: Modelspace
|
||||
error_collector: ErrorCollector für Fehlerbehandlung
|
||||
|
||||
Returns:
|
||||
Liste von Dictionaries mit Symbol-Informationen
|
||||
"""
|
||||
print("\n" + "="*60)
|
||||
print("Prüfe ob alle Symbole mit '@' im IO in einem Renamer-Bereich liegen")
|
||||
print("="*60)
|
||||
|
||||
# Sammle alle Renamer-Boundaries
|
||||
all_boundaries = []
|
||||
for group_blocks in renamer_groups.values():
|
||||
for insert, boundary, attributes, is_rectangle in group_blocks:
|
||||
all_boundaries.append((boundary, attributes))
|
||||
|
||||
# Finde alle Symbole mit "@" im IO-Attribut
|
||||
symbols_with_at = []
|
||||
for entity in msp.query('INSERT'):
|
||||
symbol_attribs = extract_block_attributes(doc, entity, error_collector)
|
||||
if not symbol_attribs:
|
||||
continue
|
||||
|
||||
|
||||
# Prüfe ob IO-Attribut "@" enthält
|
||||
io_value = symbol_attribs.get('IO', '')
|
||||
if '@' in str(io_value):
|
||||
@@ -636,32 +709,120 @@ def check_symbols_in_boundaries(doc, msp, renamer_groups, error_collector):
|
||||
'layer': entity.dxf.layer,
|
||||
'io': io_value
|
||||
})
|
||||
|
||||
return symbols_with_at
|
||||
|
||||
|
||||
def check_symbol_in_boundary(symbol, boundary, attributes, renamer_pos):
|
||||
"""
|
||||
Prüft ob ein Symbol geometrisch und vom Layer her in einem Renamer-Bereich liegt.
|
||||
|
||||
Args:
|
||||
symbol: Dictionary mit Symbol-Informationen
|
||||
boundary: Polygon-Punkte des Renamer-Bereichs
|
||||
attributes: Attribute des Renamer-Blocks
|
||||
renamer_pos: Position des Renamer-Blocks
|
||||
|
||||
Returns:
|
||||
Tuple (in_boundary, wrong_layer_info):
|
||||
- in_boundary: True wenn Symbol geometrisch und vom Layer her im Bereich liegt
|
||||
- wrong_layer_info: Dictionary mit Fehlerinformationen wenn Layer falsch ist, sonst None
|
||||
"""
|
||||
# Prüfe ob Symbol geometrisch innerhalb des Bereichs liegt
|
||||
if not point_in_polygon(symbol['position'], boundary):
|
||||
return False, None
|
||||
|
||||
# Symbol liegt geometrisch im Bereich - prüfe Layer
|
||||
search_layers = get_layer_names_from_attributes(attributes)
|
||||
|
||||
if symbol['layer'] in search_layers:
|
||||
# Layer passt auch - alles OK
|
||||
return True, None
|
||||
else:
|
||||
# Symbol liegt geometrisch im Bereich, aber Layer passt nicht
|
||||
block_name = attributes.get('NAME', attributes.get('NAME1', 'UNKNOWN'))
|
||||
wrong_layer_info = {
|
||||
'block_name': block_name,
|
||||
'renamer_pos': renamer_pos,
|
||||
'expected_layers': search_layers,
|
||||
'attributes': attributes
|
||||
}
|
||||
return False, wrong_layer_info
|
||||
|
||||
|
||||
def create_wrong_layer_warning(symbol, wrong_layer_info):
|
||||
"""
|
||||
Erstellt eine Warnung wenn ein Symbol im Bereich liegt, aber der Layer nicht passt.
|
||||
|
||||
Args:
|
||||
symbol: Dictionary mit Symbol-Informationen
|
||||
wrong_layer_info: Dictionary mit Fehlerinformationen
|
||||
|
||||
Returns:
|
||||
Warnmeldungs-String
|
||||
"""
|
||||
if wrong_layer_info['expected_layers']:
|
||||
return (
|
||||
f"Symbol an Position ({symbol['position'][0]:.1f}, {symbol['position'][1]:.1f}) "
|
||||
f"mit IO='{symbol['io']}' liegt geometrisch im Renamer-Bereich '{wrong_layer_info['block_name']}' "
|
||||
f"(Renamer-Position: ({wrong_layer_info['renamer_pos'][0]:.1f}, {wrong_layer_info['renamer_pos'][1]:.1f})), "
|
||||
f"aber das Symbol ist auf Layer '{symbol['layer']}', erwartet wird: {', '.join(wrong_layer_info['expected_layers'])}. "
|
||||
f"Prüfen Sie die LAYER_NAME Attribute im Renamer-Block."
|
||||
)
|
||||
else:
|
||||
return (
|
||||
f"Symbol an Position ({symbol['position'][0]:.1f}, {symbol['position'][1]:.1f}) "
|
||||
f"mit IO='{symbol['io']}' liegt geometrisch im Renamer-Bereich '{wrong_layer_info['block_name']}' "
|
||||
f"(Renamer-Position: ({wrong_layer_info['renamer_pos'][0]:.1f}, {wrong_layer_info['renamer_pos'][1]:.1f})), "
|
||||
f"aber der Renamer-Block hat KEINE LAYER_NAME Attribute definiert. "
|
||||
f"Symbole können nur gefunden werden, wenn LAYER_NAME1/LAYER_NAME2/LAYER_NAME3 Attribute gesetzt sind."
|
||||
)
|
||||
|
||||
|
||||
def check_symbols_in_boundaries(doc, msp, renamer_groups, error_collector):
|
||||
"""
|
||||
Dritter Pass: Prüft ob alle Symbole mit "@" im IO in einem Renamer-Bereich liegen.
|
||||
"""
|
||||
print("\n" + "="*60)
|
||||
print("Prüfe ob alle Symbole mit '@' im IO in einem Renamer-Bereich liegen")
|
||||
print("="*60)
|
||||
|
||||
# Sammle alle Renamer-Boundaries
|
||||
all_boundaries = []
|
||||
for group_blocks in renamer_groups.values():
|
||||
for insert, boundary, attributes, is_rectangle in group_blocks:
|
||||
all_boundaries.append((boundary, attributes, insert.dxf.insert))
|
||||
|
||||
# Finde alle Symbole mit "@" im IO-Attribut
|
||||
symbols_with_at = find_symbols_with_at_in_io(doc, msp, error_collector)
|
||||
|
||||
# Prüfe für jedes Symbol, ob es in mindestens einem Renamer-Bereich liegt
|
||||
symbols_not_in_any_boundary = []
|
||||
for symbol in symbols_with_at:
|
||||
in_any_boundary = False
|
||||
for boundary, attributes in all_boundaries:
|
||||
# Prüfe ob Symbol auf dem richtigen Layer ist
|
||||
search_layers = []
|
||||
for i in range(1, 4):
|
||||
layer_key = f"LAYER_NAME{i}"
|
||||
if layer_key in attributes and attributes[layer_key]:
|
||||
search_layers.append(attributes[layer_key])
|
||||
if "LAYER_NAME" in attributes and attributes["LAYER_NAME"]:
|
||||
search_layers.append(attributes["LAYER_NAME"])
|
||||
|
||||
if symbol['layer'] not in search_layers:
|
||||
continue
|
||||
|
||||
# Prüfe ob Symbol innerhalb des Bereichs liegt
|
||||
if point_in_polygon(symbol['position'], boundary):
|
||||
wrong_layer_info = None
|
||||
|
||||
for boundary, attributes, renamer_pos in all_boundaries:
|
||||
is_in_boundary, layer_info = check_symbol_in_boundary(symbol, boundary, attributes, renamer_pos)
|
||||
|
||||
if is_in_boundary:
|
||||
# Layer passt auch - alles OK
|
||||
in_any_boundary = True
|
||||
break
|
||||
|
||||
elif layer_info is not None:
|
||||
# Symbol liegt geometrisch im Bereich, aber Layer passt nicht
|
||||
wrong_layer_info = layer_info
|
||||
|
||||
if not in_any_boundary:
|
||||
symbols_not_in_any_boundary.append(symbol)
|
||||
|
||||
if wrong_layer_info:
|
||||
# Warnung: Symbol liegt geometrisch im Bereich, aber Layer stimmt nicht
|
||||
warning_msg = create_wrong_layer_warning(symbol, wrong_layer_info)
|
||||
print(f" WARNUNG: {warning_msg}")
|
||||
error_collector.add_warnings({"symbol_wrong_layer": warning_msg})
|
||||
# NICHT als Fehler hinzufügen - Warnung reicht aus
|
||||
else:
|
||||
# Fehler: Symbol liegt weder geometrisch noch vom Layer her in einem Renamer-Bereich
|
||||
symbols_not_in_any_boundary.append(symbol)
|
||||
|
||||
# Melde Fehler für Symbole, die in keinem Bereich liegen
|
||||
if symbols_not_in_any_boundary:
|
||||
for symbol in symbols_not_in_any_boundary:
|
||||
@@ -768,7 +929,7 @@ if __name__ == '__main__':
|
||||
)
|
||||
parser.add_argument('-f', '--filename', action='store', required=True, help='DXF-Datei die verarbeitet werden soll', metavar='myfile.dxf')
|
||||
parser.add_argument('-e', '--errorfile', action='store', required=False, help='JSON-Datei für Fehler und Warnungen', metavar='errors.json')
|
||||
parser.add_argument('-w', '--write', action='store', help='Schreibe Ergebnisse der Nummerierung in eine JSON-Datei')
|
||||
parser.add_argument('-i', '--info', action='store', help='Schreibe Ergebnisse der Nummerierung in eine JSON-Datei')
|
||||
parser.add_argument('-d', '--dryrun', action='store_true', help='Symbole nicht in der DXF-Datei überschreiben, nur Ausgabe auf Konsole')
|
||||
parser.add_argument('--show_symbol_frames', action='store_true', help='Zeichne Rahmen um jedes Symbol, um die Grenze des Symbols zu visualisieren')
|
||||
|
||||
@@ -844,22 +1005,32 @@ if __name__ == '__main__':
|
||||
print("\nDry-run Modus: DXF-Datei wurde nicht überschrieben")
|
||||
|
||||
# Schreibe JSON-Ausgabe wenn gewünscht
|
||||
if args.write:
|
||||
if args.info:
|
||||
output_data = {
|
||||
'renamed_symbols': renamed_symbols,
|
||||
'total_count': len(renamed_symbols)
|
||||
}
|
||||
output_path = Path(args.write)
|
||||
output_path = Path(args.info)
|
||||
write_json_file(output_data, output_path.parent, output_path.name)
|
||||
print(f"Ergebnisse in JSON gespeichert: {args.write}")
|
||||
print(f"Ergebnisse in JSON gespeichert: {args.info}")
|
||||
|
||||
# Schreibe Fehler-Datei nur wenn Fehler oder Warnungen vorhanden sind
|
||||
if error_collector.has_errors_or_warnings():
|
||||
if args.errorfile:
|
||||
error_data = error_collector.get_all_issues()
|
||||
error_path = Path(args.errorfile)
|
||||
write_json_file(error_data, error_path.parent, error_path.name)
|
||||
print(f"Fehler/Warnungen gespeichert: {args.errorfile}")
|
||||
|
||||
# Wenn nur ein Dateiname ohne Pfad angegeben wurde, speichere im work-Ordner
|
||||
if error_path.parent == Path('.'):
|
||||
output_dir = dxf_path.parent
|
||||
output_filename = error_path.name
|
||||
else:
|
||||
# Absoluter oder relativer Pfad mit Verzeichnis angegeben
|
||||
output_dir = error_path.parent
|
||||
output_filename = error_path.name
|
||||
|
||||
write_json_file(error_data, output_dir, output_filename)
|
||||
print(f"Fehler/Warnungen gespeichert: {output_dir / output_filename}")
|
||||
else:
|
||||
# Keine explizite Fehlerdatei angegeben, generiere eine basierend auf Input-Datei
|
||||
error_filename = f"{dxf_path.stem}_errors.json"
|
||||
|
||||
Reference in New Issue
Block a user