Arbeitseinheit als Project-Setting + Doc-Open-Check
Statt jeden Wert im Code zu konvertieren wird sichergestellt dass das
Doc in der gewuenschten Unit ist:
- defaults.unit ('meters'|'millimeters'|'centimeters') in
dossier_project_settings, Default 'meters'
- ProjectSettings-Dialog "Voreinstellungen" Tab: neue Sektion
"Arbeitseinheit" mit Toggle-Group fuer m/cm/mm
- get_project_unit() + get_project_unit_enum() Helper in rhinopanel
- startup._check_doc_unit() prueft beim Doc-Open ob ModelUnitSystem
matched — bei Mismatch Eto-MessageBox "Doc auf X umstellen?"
- "Yes" ruft _-Units _Model _<Unit> _Yes (Geometrie wird mit-skaliert)
- "No" setzt doc.Strings-Flag dossier_unit_checked → keine erneute Frage
- Check laeuft beim _on_doc_opened-Hook + initial fuer aktives Doc
Vorgehen ist deutlich sauberer als der vor-revert unit-aware Code
(135 Zeilen Konvertierungslogik vs 80 Zeilen Check+Convert).
This commit is contained in:
@@ -141,6 +141,74 @@ def _assign_default_display_modes(doc):
|
||||
print("[STARTUP] view-modes: {} Viewport(s) gesetzt".format(n_set))
|
||||
|
||||
|
||||
_DOC_FLAG_UNIT_CHECKED = "dossier_unit_checked"
|
||||
|
||||
|
||||
def _check_doc_unit(doc):
|
||||
"""Prueft ob doc.ModelUnitSystem der DOSSIER-Project-Setting-Arbeitseinheit
|
||||
entspricht. Bei Mismatch: Modal-Dialog mit "Umstellen" / "Spaeter"-Option.
|
||||
|
||||
Idempotent pro Doc via doc.Strings-Flag — wird nur EINMAL pro Doc gefragt.
|
||||
Wenn User "Spaeter" waehlt, fragt DOSSIER beim selben Doc nicht mehr (Flag
|
||||
bleibt gesetzt). Fuer erneute Frage: doc.Strings-Key loeschen.
|
||||
"""
|
||||
if doc is None: return
|
||||
try:
|
||||
if doc.Strings.GetValue(_DOC_FLAG_UNIT_CHECKED) == "1":
|
||||
return
|
||||
except Exception: pass
|
||||
try:
|
||||
import rhinopanel
|
||||
target_unit_str = rhinopanel.get_project_unit(doc)
|
||||
target_unit_enum = rhinopanel.get_project_unit_enum(doc)
|
||||
except Exception as ex:
|
||||
print("[STARTUP] unit-check: project-setting lesen:", ex)
|
||||
return
|
||||
if target_unit_enum is None: return
|
||||
try:
|
||||
current = doc.ModelUnitSystem
|
||||
except Exception:
|
||||
return
|
||||
if current == target_unit_enum:
|
||||
# Schon passend → einmalig Flag setzen, beim naechsten Open kein Check
|
||||
try: doc.Strings.SetString(_DOC_FLAG_UNIT_CHECKED, "1")
|
||||
except Exception: pass
|
||||
return
|
||||
# Mismatch — Dialog zeigen
|
||||
try:
|
||||
import Eto.Forms as ef
|
||||
msg = ("Dieses Doc ist in '{}'.\n"
|
||||
"DOSSIER-Projekteinstellung: '{}'.\n\n"
|
||||
"Doc auf '{}' umstellen?\n"
|
||||
"(Bestehende Geometrie wird skaliert)").format(
|
||||
str(current), target_unit_str, target_unit_str)
|
||||
result = ef.MessageBox.Show(
|
||||
msg, "DOSSIER — Arbeitseinheit",
|
||||
ef.MessageBoxButtons.YesNo,
|
||||
ef.MessageBoxType.Question)
|
||||
try:
|
||||
doc.Strings.SetString(_DOC_FLAG_UNIT_CHECKED, "1")
|
||||
except Exception: pass
|
||||
if str(result).lower().endswith("yes"):
|
||||
# _-Units _<unit> _Yes konvertiert Geometrie automatisch mit
|
||||
unit_cmd = {"meters": "_Meters",
|
||||
"millimeters": "_Millimeters",
|
||||
"centimeters": "_Centimeters"}.get(target_unit_str)
|
||||
if unit_cmd:
|
||||
try:
|
||||
Rhino.RhinoApp.RunScript(
|
||||
"_-Units _Model {} _Yes _EnterEnd".format(unit_cmd),
|
||||
False)
|
||||
print("[STARTUP] Doc auf {} umgestellt (Geometrie skaliert)".format(
|
||||
target_unit_str))
|
||||
except Exception as ex:
|
||||
print("[STARTUP] unit-convert RunScript:", ex)
|
||||
else:
|
||||
print("[STARTUP] User hat Unit-Umstellung verweigert — Doc bleibt {}".format(current))
|
||||
except Exception as ex:
|
||||
print("[STARTUP] unit-check dialog:", ex)
|
||||
|
||||
|
||||
def _on_doc_opened(sender, e):
|
||||
"""Greift bei jedem geoeffneten Doc nach Rhino-Start. Migration ist
|
||||
idempotent (Flag in doc.Strings)."""
|
||||
@@ -149,6 +217,7 @@ def _on_doc_opened(sender, e):
|
||||
import panel_base
|
||||
panel_base.migrate_to_dossier(doc)
|
||||
_assign_default_display_modes(doc)
|
||||
_check_doc_unit(doc)
|
||||
except Exception as ex:
|
||||
print("[STARTUP] _on_doc_opened:", ex)
|
||||
|
||||
@@ -212,6 +281,12 @@ def _load_all(sender, e):
|
||||
_assign_default_display_modes(Rhino.RhinoDoc.ActiveDoc)
|
||||
except Exception as ex:
|
||||
print("[STARTUP] view-modes assign:", ex)
|
||||
# Unit-Check fuer das beim Start aktive Doc — fragt einmal pro Doc
|
||||
# wenn doc.ModelUnitSystem != Project-Setting
|
||||
try:
|
||||
_check_doc_unit(Rhino.RhinoDoc.ActiveDoc)
|
||||
except Exception as ex:
|
||||
print("[STARTUP] unit-check active doc:", ex)
|
||||
# DOSSIERUI Window-Layout — Hinweis fuer manuelles Laden
|
||||
_hint_dossier_ui()
|
||||
# Startup-Timing-Summary 3 Sekunden spaeter (nachdem alle async Idle-
|
||||
|
||||
Reference in New Issue
Block a user