diff --git a/lib/create_example.py b/lib/create_example.py index 4b451fc..5a40896 100644 --- a/lib/create_example.py +++ b/lib/create_example.py @@ -286,6 +286,82 @@ class TestDataGenerator: return io_block + def create_pot_block(self): + """ + Erstellt den ILS_POT-Erdung Block mit allen Attribut-Definitionen + Basiert auf dem ILS_POT-Erdung Block aus Nummerierung_IO.dxf + + Returns: + Block-Definition + """ + block_name = 'ILS_POT-Erdung' + if block_name in self.doc.blocks: + return self.doc.blocks[block_name] + + # Erstelle neuen Block + pot_block = self.doc.blocks.new(block_name) + + # Hole Attribut-Definitionen aus pot_defaults (falls vorhanden) + if self.config and 'pot_defaults' in self.config: + pot_defaults = self.config['pot_defaults'] + attrib_configs = pot_defaults.get('attrib_defs', []) + else: + # Fallback: Hard-coded Attribute basierend auf Analyse von Nummerierung_IO.dxf + attrib_configs = [ + { + 'tag': 'REALE_POSITION', + 'insert': (0.0, 13.0, 0.0), + 'height': 100.0, + 'default': 'x', + 'layer': 'ILS_POT-Erdung', + 'invisible': False + }, + { + 'tag': 'NAME', + 'insert': (316.17, -179.49, 0.0), + 'height': 128.0, + 'default': 'POT-1@@@', + 'layer': 'ILS_POT-Erdung', + 'invisible': False + }, + { + 'tag': 'KENNZEICHNUNG', + 'insert': (0.0, -377.38, 0.0), + 'height': 128.0, + 'default': '=A01+UH00-X01', + 'layer': 'ILS_POT-Erdung', + 'invisible': True + } + ] + + # Füge alle Attribut-Definitionen hinzu + for attrib_def in attrib_configs: + # Berechne flags: Bit 0 = invisible + flags = 1 if attrib_def['invisible'] else 0 + + # Konvertiere insert-Liste zu Tupel falls nötig + insert_pos = attrib_def['insert'] + if isinstance(insert_pos, list): + insert_pos = tuple(insert_pos) + + pot_block.add_attdef( + tag=attrib_def['tag'], + insert=insert_pos, + text=attrib_def['default'], + dxfattribs={ + 'height': attrib_def['height'], + 'layer': attrib_def['layer'], + 'color': 256, # BYLAYER + 'style': 'textstyle3', + 'rotation': 0, + 'halign': 0, + 'valign': 0, + 'flags': flags + } + ) + + return pot_block + def save(self, output_dir=None): """Speichert das DXF-Dokument""" if output_dir is None: @@ -611,17 +687,12 @@ class TestDataGenerator: if self.config and 'test_scenes' in self.config and scene_name in self.config['test_scenes']: scene = self.config['test_scenes'][scene_name] if 'pot_groups' in scene and scene['pot_groups']: - print("POT-Symbole erkannt, lade ILS_POT-Erdung Block...") - # Lade POT-Block aus Referenzdatei - pot_reference_file = os.path.join(PROJECT, 'testdata', 'Nummerierung_IO.dxf') - if os.path.exists(pot_reference_file): - pot_block = self.load_block_from_file(pot_reference_file, 'ILS_POT-Erdung') - if pot_block: - print(f"POT-Block 'ILS_POT-Erdung' erfolgreich geladen") - else: - print(f"WARNUNG: POT-Block konnte nicht aus {pot_reference_file} geladen werden") + print("POT-Symbole erkannt, erstelle ILS_POT-Erdung Block...") + pot_block = self.create_pot_block() + if pot_block: + print(f"POT-Block 'ILS_POT-Erdung' erfolgreich erstellt") else: - print(f"WARNUNG: Referenzdatei {pot_reference_file} nicht gefunden") + print(f"WARNUNG: POT-Block konnte nicht erstellt werden") # Wenn Config geladen ist, verwende sie, ansonsten Hard-coded Defaults if self.config and 'test_scenes' in self.config and scene_name in self.config['test_scenes']: @@ -680,9 +751,12 @@ class TestDataGenerator: symbol_width = dimensions.get('width', 1210) symbol_height = dimensions.get('height', 381) - # Berechne Spacing + # Berechne Spacing: Verwende group['spacing'] falls angegeben, sonst symbol_width * spacing_factor if layout_type in ['horizontal', 'horizontal_offset']: - actual_spacing = symbol_width * spacing_factor + if 'spacing' in group and group['spacing'] > 0: + actual_spacing = group['spacing'] + else: + actual_spacing = symbol_width * spacing_factor else: actual_spacing = 0 @@ -729,9 +803,14 @@ class TestDataGenerator: dxfattribs={'layer': layer} ) - # Setze Attribute (dynamisch IO und BEZEICHNUNG) + # Setze Attribute (dynamisch IO/NAME und BEZEICHNUNG) attrib_values = attributes.copy() - attrib_values['IO'] = io_pattern + + # Für POT-Symbole: Setze NAME statt IO + if symbol_type == 'POT': + attrib_values['NAME'] = io_pattern + else: + attrib_values['IO'] = io_pattern # Setze BEZEICHNUNG nur wenn im Template vorhanden if 'BEZEICHNUNG' in attrib_values: