export_csv.py und omniflo_utils.py bereinigt und korrigiert
lib/export_csv.py:
- CSV-Header vereinfacht: NachbarIds, Planquadrat und rotation-Spalten
entfernt (nicht im Sivas-Format benoetigt). Anzahl-Spalte auf festen
Wert 1 gesetzt.
- format_planquadrat() entfernt (war unused nach Header-Aenderung).
- process_blocks(): elem_nr startet bei 0 statt -1 (erster Block war
mit Nummer -1 ausgegeben worden).
- build_bogen_merkmale(), build_weiche_merkmale(): KurvenWinkel und
Radius werden jetzt explizit als float() gecastet, um sicherzustellen
dass JSON-Werte aus dem Katalog als Zahl und nicht als String landen.
- Felder nachbarids, planquadrat, rotation aus den item-Dicts entfernt.
lib/omniflo_utils.py:
- import_element_as_block(): prueft jetzt zuerst ob eine Block-
definition mit dem Zielnamen in der Quelldatei existiert (erzeugt
durch set_attributs.py). Falls ja, wird diese direkt importiert
statt des gesamten Modelspace. Das verhindert doppelte Entities wenn
set_attributs.py die Geometrie bereits in einen Block gefasst hat.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+6
-30
@@ -63,8 +63,8 @@ def get_drehung(block):
|
||||
|
||||
def build_bogen_merkmale(block, eintrag):
|
||||
return {
|
||||
"Kurvenwinkel": eintrag.get("KurvenWinkel", 0),
|
||||
"Radius": eintrag.get("Radius", 0),
|
||||
"Kurvenwinkel": float(eintrag.get("KurvenWinkel", 0)),
|
||||
"Radius": float(eintrag.get("Radius", 0)),
|
||||
"Höhe": get_hoehe(block),
|
||||
"Drehung": get_drehung(block),
|
||||
"SivasNummer": str(eintrag.get("Sivasnr", ""))
|
||||
@@ -76,7 +76,7 @@ def build_weiche_merkmale(block, eintrag):
|
||||
return {
|
||||
"Weichentyp": wt,
|
||||
"Richtung": str(eintrag.get("KurvenRichtung", "")),
|
||||
"Weichenwinkel": eintrag.get("KurvenWinkel", 0),
|
||||
"Weichenwinkel": float(eintrag.get("KurvenWinkel", 0)),
|
||||
"Höhe": get_hoehe(block),
|
||||
"Drehung": get_drehung(block),
|
||||
"Antrieb Kurve": eintrag.get("SivasnrTEF") is not None,
|
||||
@@ -129,23 +129,13 @@ def build_kreisel_merkmale(block):
|
||||
SKIP_BLOCKS = {"K1", "K2", "K3", "K4", "KS_EIN", "KS_AUS"}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Planquadrat aus Block-Koordinaten
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def format_planquadrat(block):
|
||||
x = block.get("x", 0.0)
|
||||
y = block.get("y", 0.0)
|
||||
return f"X:{x:.2f} Y:{y:.2f}"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Bloecke verarbeiten (einfache Liste, keine Summierung)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def process_blocks(blocks, lookup):
|
||||
items = []
|
||||
elem_nr = -1
|
||||
elem_nr = 0
|
||||
bogen_count = 0
|
||||
weiche_count = {}
|
||||
gerade_count = 0
|
||||
@@ -169,10 +159,7 @@ def process_blocks(blocks, lookup):
|
||||
"nr": elem_nr,
|
||||
"teileart": "Omniflo Kurve",
|
||||
"teileid": shape_id,
|
||||
"nachbarids": "",
|
||||
"bezeichnung": f"OFBogen :{bogen_count}",
|
||||
"planquadrat": format_planquadrat(block),
|
||||
"rotation": block.get("rotation", 0.0),
|
||||
"merkmale": build_bogen_merkmale(block, eintrag),
|
||||
})
|
||||
|
||||
@@ -183,10 +170,7 @@ def process_blocks(blocks, lookup):
|
||||
"nr": elem_nr,
|
||||
"teileart": "Omniflo Weiche",
|
||||
"teileid": shape_id,
|
||||
"nachbarids": "",
|
||||
"bezeichnung": f"OFWeiche :{weiche_count[wt]}",
|
||||
"planquadrat": format_planquadrat(block),
|
||||
"rotation": block.get("rotation", 0.0),
|
||||
"merkmale": build_weiche_merkmale(block, eintrag),
|
||||
})
|
||||
continue
|
||||
@@ -199,10 +183,7 @@ def process_blocks(blocks, lookup):
|
||||
"nr": elem_nr,
|
||||
"teileart": "Omniflo Gerade",
|
||||
"teileid": generate_shape_id(),
|
||||
"nachbarids": "",
|
||||
"bezeichnung": f"OFGerade :{gerade_count}",
|
||||
"planquadrat": format_planquadrat(block),
|
||||
"rotation": block.get("rotation", 0.0),
|
||||
"merkmale": build_gerade_merkmale(block),
|
||||
})
|
||||
continue
|
||||
@@ -215,10 +196,7 @@ def process_blocks(blocks, lookup):
|
||||
"nr": elem_nr,
|
||||
"teileart": "ILS 2.0 Kreisel",
|
||||
"teileid": generate_shape_id(),
|
||||
"nachbarids": "",
|
||||
"bezeichnung": f"Kreisel :{kreisel_count}",
|
||||
"planquadrat": format_planquadrat(block),
|
||||
"rotation": block.get("rotation", 0.0),
|
||||
"merkmale": build_kreisel_merkmale(block),
|
||||
})
|
||||
continue
|
||||
@@ -236,10 +214,8 @@ def format_csv_line(item):
|
||||
f'{item["nr"]}'
|
||||
f';"{item["teileart"]}"'
|
||||
f';"{item["teileid"]}"'
|
||||
f';{item["nachbarids"]}'
|
||||
f';"{item["bezeichnung"]}"'
|
||||
f';"{item["planquadrat"]}"'
|
||||
f';'
|
||||
f';1'
|
||||
f';{merkmale_json}'
|
||||
)
|
||||
|
||||
@@ -271,7 +247,7 @@ def main():
|
||||
|
||||
items = process_blocks(blocks, lookup)
|
||||
|
||||
header = "Elementnummer;TeileArt;TeileId;NachbarIds;Bezeichnung;Planquadrat;rotation;Merkmale"
|
||||
header = "Elementnummer;TeileArt;TeileId;Bezeichnung;Anzahl;Merkmale"
|
||||
with open(output_csv, "w", encoding="utf-8") as f:
|
||||
f.write(header + "\n")
|
||||
for item in items:
|
||||
|
||||
Reference in New Issue
Block a user