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:
@@ -303,6 +303,10 @@ _PROJECT_SETTINGS_DEFAULTS = {
|
||||
"schnittDepthBack": 8.0,
|
||||
"schnittHeightMin": -1.0,
|
||||
"schnittHeightMax": 12.0,
|
||||
# Arbeitseinheit. DOSSIER-Default ist Meter (Architektur-Standard).
|
||||
# Beim Doc-Open prueft startup.py ob doc.ModelUnitSystem dem hier
|
||||
# entspricht — sonst Dialog mit "Umstellen"-Option.
|
||||
"unit": "meters", # "meters" | "millimeters" | "centimeters"
|
||||
},
|
||||
"materials": [],
|
||||
"project": {
|
||||
@@ -319,6 +323,44 @@ _PROJECT_SETTINGS_DEFAULTS = {
|
||||
}
|
||||
|
||||
|
||||
# Mapping Setting-String → Rhino.UnitSystem Enum (lazy import vermeidet
|
||||
# Bootstrap-Problem wenn Rhino.dll noch nicht da ist)
|
||||
_UNIT_STRING_TO_ENUM = None
|
||||
|
||||
|
||||
def _unit_string_to_enum():
|
||||
global _UNIT_STRING_TO_ENUM
|
||||
if _UNIT_STRING_TO_ENUM is not None:
|
||||
return _UNIT_STRING_TO_ENUM
|
||||
try:
|
||||
import Rhino
|
||||
_UNIT_STRING_TO_ENUM = {
|
||||
"meters": Rhino.UnitSystem.Meters,
|
||||
"millimeters": Rhino.UnitSystem.Millimeters,
|
||||
"centimeters": Rhino.UnitSystem.Centimeters,
|
||||
}
|
||||
except Exception:
|
||||
_UNIT_STRING_TO_ENUM = {}
|
||||
return _UNIT_STRING_TO_ENUM
|
||||
|
||||
|
||||
def get_project_unit(doc):
|
||||
"""Liefert die Arbeitseinheit aus den Project-Settings als String
|
||||
('meters'|'millimeters'|'centimeters'). Default 'meters'.
|
||||
"""
|
||||
ps = load_project_settings(doc) or {}
|
||||
d = ps.get("defaults") or {}
|
||||
u = (d.get("unit") or "meters").lower()
|
||||
if u not in ("meters", "millimeters", "centimeters"):
|
||||
u = "meters"
|
||||
return u
|
||||
|
||||
|
||||
def get_project_unit_enum(doc):
|
||||
"""Wie get_project_unit, aber als Rhino.UnitSystem Enum."""
|
||||
return _unit_string_to_enum().get(get_project_unit(doc))
|
||||
|
||||
|
||||
def _normalize_project_meta(p):
|
||||
"""Garantiert das project-Schema. Strings werden gestripped, mum als
|
||||
float (default 0.0 wenn nicht parsebar)."""
|
||||
|
||||
Reference in New Issue
Block a user