Optimierung der Funktion get_shape_cfg zur Verarbeitung von Offsets und Rotationen für Symbole. Vereinfachung des Codes durch Verwendung von Schleifen zur dynamischen Erfassung von Offset- und Rotationswerten aus der Konfiguration. Rückgabe der Symbole als Liste von Dictionaries mit korrekten Offset- und Rotationswerten.

This commit is contained in:
2025-07-24 13:26:39 +02:00
parent aa07e3852a
commit 340952299e
+18 -24
View File
@@ -27,33 +27,27 @@ def get_shape_cfg(teileart, cfg_path):
# Blöcke
items = parser.get(section, "items", fallback="").replace('"', '').split(",")
blocks = [item.strip() for item in items if item.strip()]
# Offsets und Rotationen (optional)
offset1 = parser.get(section, "offset_symb1", fallback="0,0")
offset2 = parser.get(section, "offset_symb2", fallback="0,0")
rot1 = parser.get(section, "rot_symb1", fallback="0.0")
rot2 = parser.get(section, "rot_symb2", fallback="0.0")
offsets = []
for off in (offset1, offset2):
try:
ox, oy = [float(x) for x in off.split(",")]
offsets.append((ox, oy))
except Exception:
offsets.append((0.0, 0.0))
rots = []
for rot in (rot1, rot2):
try:
rots.append(float(rot))
except Exception:
rots.append(0.0)
# Baue Liste von Dicts
symbols = []
for i, name in enumerate(blocks):
sym = {
# Offset
offset_key = f"offset_symb{i+1}"
offset_str = parser.get(section, offset_key, fallback="0,0")
try:
ox, oy = [float(x) for x in offset_str.split(",")]
except Exception:
ox, oy = 0.0, 0.0
# Rotation
rot_key = f"rot_symb{i+1}"
rot_str = parser.get(section, rot_key, fallback="0.0")
try:
rot = float(rot_str)
except Exception:
rot = 0.0
symbols.append({
"name": name,
"offset": offsets[i] if i < len(offsets) else (0.0, 0.0),
"rotation": rots[i] if i < len(rots) else 0.0
}
symbols.append(sym)
"offset": (ox, oy),
"rotation": rot
})
return symbols
# --------------------------------------------------------- Konstante Parameter