Compare commits

...

3 Commits

Author SHA1 Message Date
lertlmaier 2db7084d31 tool zum auslesen von Block attributen 2025-07-23 13:28:03 +02:00
lertlmaier 4340618a2a Transformation der Koordinaten.
Berücksictigung des Winkels aus Merkmalen
Mapping zur Zuordnung von RD-Namen zu Blocknamen aus Bibliothek-dxf
2025-07-23 13:27:48 +02:00
lertlmaier 8a295a674f dxf Datei mit Blöcken (Simon Hensch) hinzugefügt. test-csv mit Drehungs-Attribut in Json String 2025-07-23 13:26:25 +02:00
5 changed files with 445933 additions and 73 deletions
-20
View File
@@ -1,20 +0,0 @@
Elementnummer;TeileArt;TeileId;NachbarIds;Bezeichnung;Planquadrat;Merkmale
1;"ILS 2.0 Kreisel";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"shape_d76e250a-0a46-f6d0-df52-943ab572cc63,shape_ad62cba4-3a33-c4c5-944f-eac7abb7603e,shape_456bee3e-01e8-be9e-aa74-4265c1195bbe,shape_463bb635-b3b0-d4e9-c8b9-42be3b7219b7,shape_6d9bfe2c-d8b8-3ceb-bf26-bdacd0a40712,shape_1ca5b56e-7825-2852-d241-0562233b6310,shape_2f9fa13c-23d5-784d-da4c-8d1c7e313116,shape_fa451c64-e507-8932-d5da-7cc93476a176,shape_30127aba-263b-1ed5-c5cf-e27933594406,shape_641530a1-7396-8e83-3a50-1bc59a406a5e,shape_161f85cd-b1f4-0943-34b7-1d3b8134bcc0,shape_e8f52a47-c493-39ef-ddcb-78297d96944d,shape_24812b84-fd3b-6a44-0302-2d0fc169a6d9,shape_80ca3488-cc41-4caa-00cd-b3de9f5428e6,shape_8b856d97-b18b-6263-7c98-79d8b4ca679a,shape_67f8d19e-8857-1f5d-7d90-3a2a0a9da157";"Kreisel:1";"X:9174.15 Y:12039.11";{"Abstand (Kreiselachse A - Kreiselachse) in Meter":"20.265","Anzahl der Separatoren":"2","Anzahl der Scanner":"0","Anzahl der Rampen":"0","Höhe in m":"2"}
2;"ILS 2.0 Kreisel";"shape_8e75c773-8088-b286-9dc0-f601442d5e70";"shape_ad62cba4-3a33-c4c5-944f-eac7abb7603e";"Kreisel:2";"X:18174.14 Y:12004.13";{"Abstand (Kreiselachse A - Kreiselachse) in Meter":"20.265","Anzahl der Separatoren":"2","Anzahl der Scanner":"0","Anzahl der Rampen":"0","Höhe in m":"2"}
3;"ILS 2.0 Kreisel";"shape_d76e250a-0a46-f6d0-df52-943ab572cc63";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29,Weiche_Xg8Ledh-T0ejWPHluSM8tA";"Kreisel:3";"X:12474.15 Y:22171.59";{"Abstand (Kreiselachse A - Kreiselachse) in Meter":"5","Anzahl der Separatoren":"2","Anzahl der Scanner":"0","Anzahl der Rampen":"0","Höhe in m":"2"}
4;"ILS 2.0 Weiche";"Weiche_Xg8Ledh-T0ejWPHluSM8tA";"shape_d76e250a-0a46-f6d0-df52-943ab572cc63";" zw. Kreisel:3 und Kreisel:1";"X:9574.15 Y:22171.59";{"Weichenart":"Aktiv"}
5;"ILS 2.0 Gefällestrecke";"shape_ad62cba4-3a33-c4c5-944f-eac7abb7603e";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29,shape_8e75c773-8088-b286-9dc0-f601442d5e70";"";"X:13674.14 Y:20021.68";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
6;"ILS 2.0 Gefällestrecke";"shape_456bee3e-01e8-be9e-aa74-4265c1195bbe";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13624.15 Y:18421.59";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.1"}
7;"ILS 2.0 Gefällestrecke";"shape_30127aba-263b-1ed5-c5cf-e27933594406";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:12821.68";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
8;"ILS 2.0 Gefällestrecke";"shape_6d9bfe2c-d8b8-3ceb-bf26-bdacd0a40712";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:16021.66";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
9;"ILS 2.0 Gefällestrecke";"shape_463bb635-b3b0-d4e9-c8b9-42be3b7219b7";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:16821.71";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
10;"ILS 2.0 Gefällestrecke";"shape_1ca5b56e-7825-2852-d241-0562233b6310";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:15221.61";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
11;"ILS 2.0 Gefällestrecke";"shape_e8f52a47-c493-39ef-ddcb-78297d96944d";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:10421.53";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
12;"ILS 2.0 Gefällestrecke";"shape_161f85cd-b1f4-0943-34b7-1d3b8134bcc0";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:11221.58";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
13;"ILS 2.0 Gefällestrecke";"shape_641530a1-7396-8e83-3a50-1bc59a406a5e";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:12021.63";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
14;"ILS 2.0 Gefällestrecke";"shape_fa451c64-e507-8932-d5da-7cc93476a176";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:13621.51";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
15;"ILS 2.0 Gefällestrecke";"shape_2f9fa13c-23d5-784d-da4c-8d1c7e313116";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:14421.56";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
16;"ILS 2.0 Gefällestrecke";"shape_24812b84-fd3b-6a44-0302-2d0fc169a6d9";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13624.16 Y:17621.54";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.1"}
17;"ILS 2.0 Gefällestrecke";"shape_8b856d97-b18b-6263-7c98-79d8b4ca679a";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:8821.64";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
18;"ILS 2.0 Gefällestrecke";"shape_67f8d19e-8857-1f5d-7d90-3a2a0a9da157";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:8021.59";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
19;"ILS 2.0 Gefällestrecke";"shape_80ca3488-cc41-4caa-00cd-b3de9f5428e6";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";"";"X:13674.15 Y:9621.69";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2"}
Can't render this file because it contains an unexpected character in line 2 and column 792.
+445784
View File
File diff suppressed because it is too large Load Diff
+20
View File
@@ -0,0 +1,20 @@
Elementnummer;TeileArt;TeileId;NachbarIds;Bezeichnung;Planquadrat;Merkmale
1;"ILS 2.0 Kreisel";"shape_f81e5c4b-a976-a3c0-3304-d2b30da1ab29";1;"Kreisel:1";"X:9174.15 Y:12039.11";{"Abstand (Kreiselachse A - Kreiselachse) in Meter":"20.265","Drehung":90}
2;"ILS 2.0 Kreisel";"shape_8e75c773-8088-b286-9dc0-f601442d5e70";1;"Kreisel:2";"X:18174.14 Y:12004.13";{"Abstand (Kreiselachse A - Kreiselachse) in Meter":"20.265","Drehung":90}
3;"ILS 2.0 Kreisel";"shape_d76e250a-0a46-f6d0-df52-943ab572cc63";1;"Kreisel:3";"X:12474.15 Y:22171.59";{"Abstand (Kreiselachse A - Kreiselachse) in Meter":"5","Drehung":0}
4;"ILS 2.0 Weiche";"Weiche_Xg8Ledh-T0ejWPHluSM8tA";1;" zw. Kreisel:3 und Kreisel:1";"X:9574.15 Y:22171.59";{"Weichenart":"Aktiv","Drehung":0}
5;"ILS 2.0 Gefällestrecke";"shape_ad62cba4-3a33-c4c5-944f-eac7abb7603e";1;"";"X:13674.14 Y:20021.68";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
6;"ILS 2.0 Gefällestrecke";"shape_456bee3e-01e8-be9e-aa74-4265c1195bbe";1;"";"X:13624.15 Y:18421.59";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.1","Drehung":0}
7;"ILS 2.0 Gefällestrecke";"shape_30127aba-263b-1ed5-c5cf-e27933594406";1;"";"X:13674.15 Y:12821.68";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
8;"ILS 2.0 Gefällestrecke";"shape_6d9bfe2c-d8b8-3ceb-bf26-bdacd0a40712";1;"";"X:13674.15 Y:16021.66";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
9;"ILS 2.0 Gefällestrecke";"shape_463bb635-b3b0-d4e9-c8b9-42be3b7219b7";1;"";"X:13674.15 Y:16821.71";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
10;"ILS 2.0 Gefällestrecke";"shape_1ca5b56e-7825-2852-d241-0562233b6310";1;"";"X:13674.15 Y:15221.61";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
11;"ILS 2.0 Gefällestrecke";"shape_e8f52a47-c493-39ef-ddcb-78297d96944d";1;"";"X:13674.15 Y:10421.53";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
12;"ILS 2.0 Gefällestrecke";"shape_161f85cd-b1f4-0943-34b7-1d3b8134bcc0";1;"";"X:13674.15 Y:11221.58";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
13;"ILS 2.0 Gefällestrecke";"shape_641530a1-7396-8e83-3a50-1bc59a406a5e";1;"";"X:13674.15 Y:12021.63";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
14;"ILS 2.0 Gefällestrecke";"shape_fa451c64-e507-8932-d5da-7cc93476a176";1;"";"X:13674.15 Y:13621.51";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
15;"ILS 2.0 Gefällestrecke";"shape_2f9fa13c-23d5-784d-da4c-8d1c7e313116";1;"";"X:13674.15 Y:14421.56";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
16;"ILS 2.0 Gefällestrecke";"shape_24812b84-fd3b-6a44-0302-2d0fc169a6d9";1;"";"X:13624.16 Y:17621.54";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.1","Drehung":0}
17;"ILS 2.0 Gefällestrecke";"shape_8b856d97-b18b-6263-7c98-79d8b4ca679a";1;"";"X:13674.15 Y:8821.64";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
18;"ILS 2.0 Gefällestrecke";"shape_67f8d19e-8857-1f5d-7d90-3a2a0a9da157";1;"";"X:13674.15 Y:8021.59";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
19;"ILS 2.0 Gefällestrecke";"shape_80ca3488-cc41-4caa-00cd-b3de9f5428e6";1;"";"X:13674.15 Y:9621.69";{"Anzahl der Zusatzseparatoren":"1","Länge in Meter":"8.2","Drehung":0}
Can't render this file because it contains an unexpected character in line 2 and column 104.
+25
View File
@@ -0,0 +1,25 @@
import ezdxf
from pathlib import Path
def inspect_blocks(dxf_path):
doc = ezdxf.readfile(dxf_path)
print(f"Datei: {dxf_path}")
print("Gefundene Blöcke und Attribute:\n")
for block in doc.blocks:
if block.name.startswith('*'): # Überspringe anonyme/Standardblöcke
continue
print(f"Block: {block.name}")
attribs = [e for e in block if e.dxftype() == "ATTDEF"]
if attribs:
print(" Attribute:")
for att in attribs:
print(f" Tag: {att.dxf.tag}, Prompt: {att.dxf.prompt}")
else:
print(" (Keine Attribute)")
print("-" * 40)
if __name__ == "__main__":
dxf_file = "data/blocks.dxf"
inspect_blocks(dxf_file)
+104 -53
View File
@@ -14,6 +14,13 @@ import argparse
import configparser
import ezdxf
from pathlib import Path
import math
# --------------------------------------------------------- Mapping TeileArt → Blockname
BLOCKNAME_MAPPING = {
"ILS 2.0 Kreisel": ["SP8", "AN8"]
# Weitere Zuordnungen nach Bedarf
}
# --------------------------------------------------------- Konstante Parameter
ATTR_TAG = "TeileId" # Attributtag im Block
@@ -50,47 +57,83 @@ def import_block(block_name: str, from_doc, to_doc) -> None:
if block_name not in from_doc.blocks:
raise ValueError(f"Block '{block_name}' nicht in Bibliothek gefunden.")
src = from_doc.blocks[block_name]
tgt = to_doc.blocks.new(name=block_name, dxfattribs=src.dxf.attribs())
tgt = to_doc.blocks.new(name=block_name)
for ent in src:
tgt.add_entity(ent.copy())
def build_simple_shape(msp, teileart: str, x: float, y: float,
teile_id: str, merkmale: dict):
"""Erzeugt einfache Geometrien direkt im Modelspace."""
if teileart == "ILS 2.0 Kreisel":
abstand_m = merkmale.get(
"Abstand (Kreiselachse A - Kreiselachse) in Meter", "20"
).replace(",", ".")
try:
abstand = float(abstand_m) * 1000 # Meter → mm
except ValueError:
abstand = 20000 # Fallback 20m
def draw_kreisel_lines(msp, pos1, pos2):
"""Zeichnet tangentiale Linien zwischen zwei Kreiselblöcken, unabhängig vom Winkel."""
x1, y1 = pos1
x2, y2 = pos2
# Verbindungsvektor
dx = x2 - x1
dy = y2 - y1
# Länge
length = math.hypot(dx, dy)
if length == 0:
return # keine Linie bei identischen Punkten
# Normalenvektor (senkrecht, normiert, Länge = RADIUS)
nx = -dy / length * RADIUS
ny = dx / length * RADIUS
# Tangentialpunkte
p1a = (x1 + nx, y1 + ny)
p1b = (x1 - nx, y1 - ny)
p2a = (x2 + nx, y2 + ny)
p2b = (x2 - nx, y2 - ny)
# Linien zeichnen
msp.add_line(p1a, p2a)
msp.add_line(p1b, p2b)
cx1 = x - abstand / 2
cx2 = x + abstand / 2
def transform_coords(x: float, y: float, height: float) -> tuple[float, float]:
"""Transformiert Bildschirmkoordinaten (0,0 oben links) ins DXF-KoSy (0,0 unten links)."""
return x, height - y
# Zwei Kreise + tangentiale Verbindungs­linien
msp.add_circle((cx1, y), RADIUS)
msp.add_circle((cx2, y), RADIUS)
msp.add_line((cx1, y - RADIUS), (cx2, y - RADIUS))
msp.add_line((cx1, y + RADIUS), (cx2, y + RADIUS))
def handle_kreisel(msp, blocknames, teileid, merkmale, row, x, y, height, lib_doc, doc, verbose):
abstand_m = merkmale.get(
"Abstand (Kreiselachse A - Kreiselachse) in Meter", "20"
).replace(",", ".")
try:
abstand = float(abstand_m) * 1000 # Meter → mm
except ValueError:
abstand = 10000 # Fallback 10m
else:
raise NotImplementedError(f"Einfache Form '{teileart}' nicht implementiert.")
# Drehung (Winkel in Grad, Standard 0) aus Merkmale
try:
winkel = float(merkmale.get("Drehung", 0))
except (ValueError, TypeError):
winkel = 0.0
winkel_rad = math.radians(winkel)
def load_simple_types(cfg_path: Path) -> set[str]:
"""Lädt die Liste der einfachen TeileArtNamen aus .cfg."""
cfg = configparser.ConfigParser()
cfg.read(cfg_path)
names = cfg.get("simple_types", "shape_names", fallback="")
return {n.strip() for n in names.split(",") if n.strip()}
# Die Koordinaten (x, y) sind die Mitte zwischen den beiden Blöcken (bereits transformiert)
halbabstand = abstand / 2
dx = halbabstand * math.cos(winkel_rad)
dy = halbabstand * math.sin(winkel_rad)
pos1 = (x - dx, y - dy)
pos2 = (x + dx, y + dy)
positions = [pos1, pos2]
for blockname, pos in zip(blocknames, positions):
import_block(blockname, lib_doc, doc)
bref = msp.add_blockref(blockname, pos)
bref.add_auto_attribs({ATTR_TAG: teileid})
if verbose:
print(f"[INFO] Block '{blockname}' (CSV: 'ILS 2.0 Kreisel') → {teileid} "
f"({pos[0]:.1f}, {pos[1]:.1f})")
# Linien zeichnen
draw_kreisel_lines(msp, pos1, pos2)
def handle_standard(msp, blocknames, teileid, x, y, lib_doc, doc, verbose):
for blockname in blocknames:
import_block(blockname, lib_doc, doc)
bref = msp.add_blockref(blockname, (x, y))
bref.add_auto_attribs({ATTR_TAG: teileid})
if verbose:
print(f"[INFO] Block '{blockname}' (Standard) → {teileid} "
f"({x:.1f}, {y:.1f})")
# --------------------------------------------------------- Hauptfunktion
def main(csv_path: Path, lib_path: Path, cfg_path: Path,
output_path: Path, verbose=False):
simple_types = load_simple_types(cfg_path)
# Bibliothek nur laden, wenn Datei existiert
lib_doc = None
if lib_path.exists():
@@ -109,6 +152,22 @@ def main(csv_path: Path, lib_path: Path, cfg_path: Path,
msp = doc.modelspace()
# CSV einlesen
# Zuerst alle Y-Werte sammeln, um die Höhe zu bestimmen
y_values = []
with csv_path.open(newline="", encoding="utf-8") as fh:
reader = csv.DictReader(fh, delimiter=';')
for row in reader:
planquadrat = row["Planquadrat"]
try:
_, y = extract_coords(planquadrat)
y_values.append(y)
except Exception:
pass
if not y_values:
raise ValueError("Keine Y-Koordinaten in der CSV gefunden!")
height = max(y_values)
# Jetzt eigentliche Verarbeitung
with csv_path.open(newline="", encoding="utf-8") as fh:
reader = csv.DictReader(fh, delimiter=';')
for row in reader:
@@ -118,35 +177,27 @@ def main(csv_path: Path, lib_path: Path, cfg_path: Path,
merkmale = parse_merkmale(row.get("Merkmale", ""))
try:
x, y = extract_coords(planquadrat)
x_screen, y_screen = extract_coords(planquadrat)
x, y = transform_coords(x_screen, y_screen, height)
except Exception as e:
print(f"[WARN] {teileid}: {e}")
continue
# Einfache Form
if teileart in simple_types:
try:
build_simple_shape(msp, teileart, x, y, teileid, merkmale)
if verbose:
print(f"[INFO] Simple '{teileart}'{teileid} "
f"({x:.1f}, {y:.1f})")
except Exception as e:
print(f"[ERROR] Simple '{teileart}' ({teileid}): {e}")
# Blocknamen immer aus Mapping holen (ggf. Fallback auf Teileart)
blocknames = BLOCKNAME_MAPPING.get(teileart)
if not blocknames:
print(f"[WARN] Keine Blockzuordnung für TeileArt '{teileart}'. Überspringe '{teileid}'.")
continue
if isinstance(blocknames, str):
blocknames = [blocknames]
# Spezialfall: ILS 2.0 Kreisel
if teileart == "ILS 2.0 Kreisel":
handle_kreisel(msp, blocknames, teileid, merkmale, row, x, y, height, lib_doc, doc, verbose)
continue
# Komplexe Form (Block)
if not lib_doc:
print(f"[WARN] '{teileart}' benötigt Bibliothek, wird übersprungen.")
continue
try:
import_block(teileart, lib_doc, doc)
bref = msp.add_blockref(teileart, (x, y))
bref.add_auto_attribs({ATTR_TAG: teileid})
if verbose:
print(f"[INFO] Block '{teileart}'{teileid} "
f"({x:.1f}, {y:.1f})")
except Exception as e:
print(f"[ERROR] Block '{teileart}' ({teileid}): {e}")
# Standardfall
handle_standard(msp, blocknames, teileid, x, y, lib_doc, doc, verbose)
# DXF speichern
doc.saveas(output_path)
@@ -174,7 +225,7 @@ if __name__ == "__main__":
csv_path = Path(args.file)
cfg_path = Path(args.config) if args.config else config_dir / "shapes.cfg"
lib_path = Path(args.lib) if args.lib else data_dir / "bibliothek.dxf"
lib_path = Path(args.lib) if args.lib else data_dir / "blocks.dxf"
output_path = Path(args.output) if args.output else (work_dir / f"{csv_path.stem}.dxf")
main(csv_path, lib_path, cfg_path, output_path, verbose=args.verbose)