Omniflo Einträge von Verbindern und Bögen für Weichen Ergänzt

This commit is contained in:
2026-06-11 11:15:13 +02:00
parent a2d6571ab9
commit e4564be24c
4 changed files with 268 additions and 12 deletions
+77 -8
View File
@@ -36,6 +36,7 @@ def load_config(cfg_path):
{
"bogen": [("BESCHR", "ProfilTyp"), ("ARTINR", "Sivasnr"), ...],
"weiche": [("BESCHR", "ProfilTyp"), ...],
"layer": {"bogen": "OF Boegen A-2", "weiche_90": "Weiche 90 Grad A-2", ...},
}
"""
config = configparser.ConfigParser()
@@ -44,14 +45,65 @@ def load_config(cfg_path):
result = {}
for section in config.sections():
attrs = []
for tag, source in config.items(section):
attrs.append((tag, source.strip()))
result[section] = attrs
if section == "layer":
# Layer-Sektion als einfaches Dict speichern
layer_map = {}
for key, val in config.items(section):
val = val.strip()
if val.startswith('"') and val.endswith('"'):
val = val[1:-1]
layer_map[key] = val
result["layer"] = layer_map
else:
attrs = []
for tag, source in config.items(section):
attrs.append((tag, source.strip()))
result[section] = attrs
return result
KOMBI_TYPEN = {"Deltaweiche", "Sternweiche", "Dreifachweiche"}
def get_layer_for_entry(typ, json_entry, layer_map):
"""
Bestimmt den Layer-Namen anhand von Elementtyp und JSON-Daten.
Gibt den Layer-String zurueck oder "" wenn kein Mapping vorhanden.
"""
if not layer_map:
return ""
if typ == "bogen":
return layer_map.get("bogen", "")
# Weiche: Kategorie anhand KurvenWinkel und WeichenTyp bestimmen
winkel = json_entry.get("KurvenWinkel", 0)
weichentyp = json_entry.get("WeichenTyp", "")
# Weichenkombinationen (Deltaweiche, Sternweiche, Dreifachweiche)
if weichentyp in KOMBI_TYPEN:
return layer_map.get("weichenkombination", "")
# Weichenkoerper (KurvenWinkel = 22.5)
if winkel == 22.5:
return layer_map.get("weichenkoerper", "")
# Weiche 90 Grad
if winkel == 90:
return layer_map.get("weiche_90", "")
# Weiche 45 Grad
if winkel == 45:
return layer_map.get("weiche_45", "")
# Weichenbatterien / Parallel (KurvenWinkel = 0)
if winkel == 0:
return layer_map.get("weichenbatterie", "")
return ""
def resolve_value(source, json_entry, sivasnr):
"""
Loest einen Quell-Ausdruck aus der Config auf:
@@ -105,13 +157,15 @@ ATTDEF_HEIGHT = 5.0
ATTDEF_LAYER = "ATTRIB"
def add_attdefs_to_dxf(dxf_path, output_path, attr_defs, json_entry, sivasnr):
def add_attdefs_to_dxf(dxf_path, output_path, attr_defs, json_entry, sivasnr,
layer_value=""):
"""
Oeffnet eine DXF-Datei, fuegt ATTDEF-Entities in den Modelspace ein
und speichert das Ergebnis.
attr_defs: Liste von (TAG, source_expression) aus der Config
json_entry: Dict mit den JSON-Daten fuer dieses Element
layer_value: Layer-Name aus [layer]-Sektion (wird als LAYER-ATTDEF gesetzt)
"""
doc = ezdxf.readfile(dxf_path)
msp = doc.modelspace()
@@ -125,9 +179,15 @@ def add_attdefs_to_dxf(dxf_path, output_path, attr_defs, json_entry, sivasnr):
for e in existing:
msp.delete_entity(e)
# Alle ATTDEFs sammeln: Config-Attribute + LAYER aus [layer]-Sektion
all_defs = list(attr_defs)
if layer_value:
all_defs.append(("LAYER", f'"{layer_value}"'))
# ATTDEFs hinzufuegen
y_pos = ATTDEF_START_Y
for tag, source in attr_defs:
count = 0
for tag, source in all_defs:
default_value = resolve_value(source, json_entry, sivasnr)
prompt = tag
@@ -143,9 +203,10 @@ def add_attdefs_to_dxf(dxf_path, output_path, attr_defs, json_entry, sivasnr):
},
)
y_pos += ATTDEF_SPACING
count += 1
doc.saveas(output_path)
return len(attr_defs)
return count
# ---------------------------------------------------------------------------
@@ -157,7 +218,11 @@ def process_all(data_dir, cfg_path, results_dir, single_nr=None, dry_run=False):
# Config laden
attr_config = load_config(cfg_path)
layer_map = attr_config.pop("layer", {})
print(f"[attradd] Config geladen: {list(attr_config.keys())}")
if layer_map:
print(f" [layer] {len(layer_map)} Zuordnungen: "
f"{', '.join(f'{k}={v}' for k, v in layer_map.items())}")
for section, attrs in attr_config.items():
tags = [a[0] for a in attrs]
print(f" [{section}] Attribute: {', '.join(tags)}")
@@ -197,18 +262,22 @@ def process_all(data_dir, cfg_path, results_dir, single_nr=None, dry_run=False):
continue
attr_defs = attr_config[typ]
layer_value = get_layer_for_entry(typ, entry, layer_map)
output_path = os.path.join(out_dir, dxf_name)
if dry_run:
values = {tag: resolve_value(src, entry, sivasnr)
for tag, src in attr_defs}
if layer_value:
values["LAYER"] = layer_value
print(f" [DRY] {sivasnr} ({typ}): {values}")
processed += 1
continue
try:
count = add_attdefs_to_dxf(dxf_path, output_path, attr_defs,
entry, sivasnr)
entry, sivasnr,
layer_value=layer_value)
processed += 1
print(f" OK: {sivasnr} ({typ}) -> {count} Attribute -> {output_path}")
except Exception as e: