Snapshot: Wand/Öffnung Multi-Surface-Select + Z-Drag + Brüstungs-Mitnahme
Stable working state after a long iteration session. The plugin now supports:
- Multi-Surface-Select für alle Element-Typen (Türen/Fenster/Treppen/Tragwerk)
- Wand-Z-Drag → unbound mode (UK/OK-Override, Wand vom Geschoss entkoppelt)
- Wand-Z-Drag nimmt verknüpfte Öffnungen mit (Brüstung += delta_z via Idle-Pfad)
- Öffnungs-XY-Drag snapt direktional auf Wand-Tangente
- Öffnungs-Z-Drag passt Brüstung an (Fenster sofort sync, Tür deferred)
- Wand-Delete kaskadiert Öffnungen (deferred via Idle, robust gegen _Rotate/_Move)
- Source-Cascade beim Öffnungs-Delete (deferred analog Wand-Kaskade)
- Listener-Cleanup robust gegen _reset_panels.py Reload (Refs in
_dossier_runtime_event_refs gespeichert, vor Re-Install deregistriert)
- _count_same_id_type filtert IsDeleted (verhindert Source-Duplikat-Bug bei Move)
- Frontend: Brüstungs-Slider für Tür ("Schwelle"), Flügel-Block nur bei Fenster
Plus aus früherer Phase dieser Session:
- Dossier-Launcher Auto-Load via Rhinos StartupCommands-XML
- Default-Pfad zeigt auf gebundeltes startup.py (out-of-the-box für neue User)
- Splash-Window beim Plugin-Load mit native macOS rounded corners
- Diverse Launcher-Verbesserungen (Brüstungs-Default, tauri.conf, capabilities)
Known issue: bei Multi-Select-Move mit vielen Sub-Volumen kann sporadisch
"Unable to transform" auftreten (Rhinos Move-Operation kollidiert mit Wand-
Regen). Tür-spezifischer Defer-Pfad mildert das, Fenster läuft sync.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+691
-2
@@ -1,4 +1,4 @@
|
||||
# ! python3
|
||||
#! python 3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
oberleiste.py
|
||||
@@ -33,6 +33,558 @@ def _run(cmd):
|
||||
print("[OBERLEISTE] RunScript-Fehler ({}): {}".format(cmd, ex))
|
||||
|
||||
|
||||
# --- Window-Layout-Management + App-Settings -------------------------------
|
||||
# Die Settings werden primaer vom Dossier-Launcher (Tauri-App) verwaltet, der
|
||||
# nach ~/Library/Application Support/ch.gabrielevarano.Dossier/dossier_settings.json
|
||||
# schreibt. Rhino liest hier nur. Fallback auf den alten RhinoPanel-Pfad fuer
|
||||
# bestehende Installationen.
|
||||
|
||||
import json as _json
|
||||
import subprocess as _subprocess
|
||||
|
||||
_LAUNCHER_DIR = os.path.expanduser(
|
||||
"~/Library/Application Support/ch.gabrielevarano.Dossier")
|
||||
_LAUNCHER_PATH = os.path.join(_LAUNCHER_DIR, "dossier_settings.json")
|
||||
|
||||
_LEGACY_DIR = os.path.expanduser(
|
||||
"~/Library/Application Support/RhinoPanel")
|
||||
_LEGACY_PATH = os.path.join(_LEGACY_DIR, "dossier_settings.json")
|
||||
|
||||
|
||||
def _settings_paths():
|
||||
"""Suchreihenfolge: Launcher zuerst, dann Legacy-RhinoPanel."""
|
||||
return (_LAUNCHER_PATH, _LEGACY_PATH)
|
||||
|
||||
|
||||
def _settings_load():
|
||||
"""Laedt App-Settings aus dem Launcher-JSON (oder Legacy-Path).
|
||||
Normalisiert Keys: Launcher nutzt `windowLayout`, Legacy `defaultLayout`."""
|
||||
for p in _settings_paths():
|
||||
try:
|
||||
if os.path.isfile(p):
|
||||
with open(p, "rb") as f:
|
||||
data = _json.loads(f.read().decode("utf-8"))
|
||||
if not isinstance(data, dict):
|
||||
continue
|
||||
# Normalize legacy keys -> launcher keys
|
||||
if "windowLayout" not in data and "defaultLayout" in data:
|
||||
data["windowLayout"] = data.get("defaultLayout") or ""
|
||||
return data
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] settings_load ({}):".format(p), ex)
|
||||
return {}
|
||||
|
||||
|
||||
def _settings_save(data):
|
||||
"""Schreibt in den Launcher-Pfad (primary). Legacy-Pfad wird nicht mehr
|
||||
beschrieben — der Launcher ist die Autoritaet."""
|
||||
try:
|
||||
if not os.path.isdir(_LAUNCHER_DIR):
|
||||
os.makedirs(_LAUNCHER_DIR)
|
||||
with open(_LAUNCHER_PATH, "wb") as f:
|
||||
f.write(_json.dumps(data, ensure_ascii=False, indent=2)
|
||||
.encode("utf-8"))
|
||||
return True
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] settings_save:", ex)
|
||||
return False
|
||||
|
||||
|
||||
def _hex_to_color(hex_str):
|
||||
"""`#RRGGBB` -> System.Drawing.Color. Liefert None bei ungueltigem Input."""
|
||||
if not hex_str or not isinstance(hex_str, str): return None
|
||||
s = hex_str.strip().lstrip("#")
|
||||
if len(s) == 3:
|
||||
s = "".join(c + c for c in s)
|
||||
if len(s) != 6: return None
|
||||
try:
|
||||
r = int(s[0:2], 16)
|
||||
g = int(s[2:4], 16)
|
||||
b = int(s[4:6], 16)
|
||||
import System.Drawing as _sd
|
||||
return _sd.Color.FromArgb(255, r, g, b)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
# Mapping Launcher-Key -> AppearanceSettings-Attribut. Ein Eintrag pro Farbe,
|
||||
# damit wir leicht erweitern/disablen koennen.
|
||||
_VIEWPORT_COLOR_ATTRS = (
|
||||
("background", "ViewportBackgroundColor"),
|
||||
("gridLine", "GridLineColor"),
|
||||
("gridMajor", "GridMajorLineColor"),
|
||||
("gridX", "GridXAxisLineColor"),
|
||||
("gridY", "GridYAxisLineColor"),
|
||||
("worldX", "WorldCoordIconXAxisColor"),
|
||||
("worldY", "WorldCoordIconYAxisColor"),
|
||||
("worldZ", "WorldCoordIconZAxisColor"),
|
||||
)
|
||||
|
||||
|
||||
def _apply_viewport_colors(cfg):
|
||||
"""Setzt App-Appearance-Settings aus der dossier_settings.json (viewportColors).
|
||||
Tolerant: nicht-existierende Felder werden uebersprungen, Plugin bricht
|
||||
nicht ab. Triggert ein Redraw aller Viewports am Ende."""
|
||||
colors = cfg.get("viewportColors") or {}
|
||||
if not isinstance(colors, dict) or not colors: return False
|
||||
try:
|
||||
appset = Rhino.ApplicationSettings.AppearanceSettings
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] AppearanceSettings nicht verfuegbar:", ex)
|
||||
return False
|
||||
applied = []
|
||||
for key, attr in _VIEWPORT_COLOR_ATTRS:
|
||||
hexv = colors.get(key)
|
||||
col = _hex_to_color(hexv) if hexv else None
|
||||
if col is None: continue
|
||||
try:
|
||||
setattr(appset, attr, col)
|
||||
applied.append(key)
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] view-color {} -> {}: {}".format(key, attr, ex))
|
||||
if applied:
|
||||
# Redraw aller Viewports damit die neuen Farben sofort sichtbar werden.
|
||||
try:
|
||||
for v in Rhino.RhinoDoc.ActiveDoc.Views: v.Redraw()
|
||||
except Exception: pass
|
||||
print("[OBERLEISTE] Viewport-Colors applied:", applied)
|
||||
return bool(applied)
|
||||
|
||||
|
||||
def _import_display_modes(paths):
|
||||
"""Importiert eine Liste von .ini-Pfaden via Rhino.Display API.
|
||||
Liefert die Anzahl erfolgreich importierter Modes."""
|
||||
if not paths: return 0
|
||||
count = 0
|
||||
try:
|
||||
DMD = Rhino.Display.DisplayModeDescription
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] DisplayModeDescription nicht verfuegbar:", ex)
|
||||
return 0
|
||||
for p in paths:
|
||||
try:
|
||||
if not os.path.isfile(p):
|
||||
print("[OBERLEISTE] Display-Mode-Pfad fehlt:", p); continue
|
||||
res = DMD.ImportFromFile(p)
|
||||
if res:
|
||||
count += 1
|
||||
print("[OBERLEISTE] Display-Mode importiert:", p)
|
||||
else:
|
||||
print("[OBERLEISTE] Display-Mode-Import lieferte False:", p)
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] Display-Mode-Import-Fehler ({}): {}".format(p, ex))
|
||||
if count:
|
||||
# Cache invalidieren damit das Display-Dropdown die Neuen aufnimmt.
|
||||
try:
|
||||
global _display_modes_cache
|
||||
_display_modes_cache = None
|
||||
except Exception: pass
|
||||
return count
|
||||
|
||||
|
||||
_THUMB_SIZE = (480, 320) # 3:2 — kompakt fuer Launcher-Cards
|
||||
|
||||
|
||||
def _save_thumbnail(doc):
|
||||
"""Rendert den aktiven Viewport in eine PNG-Datei neben der .3dm.
|
||||
Pfad: <doc.Path>.thumb.png — wird vom Launcher aufgegriffen."""
|
||||
try:
|
||||
if doc is None: return
|
||||
doc_path = doc.Path
|
||||
if not doc_path: return # noch-nicht-gespeichertes Doc
|
||||
view = doc.Views.ActiveView
|
||||
if view is None: return
|
||||
w, h = _THUMB_SIZE
|
||||
try:
|
||||
import System.Drawing as _sd
|
||||
size = _sd.Size(int(w), int(h))
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] thumb size:", ex); return
|
||||
try:
|
||||
bmp = view.CaptureToBitmap(size)
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] CaptureToBitmap:", ex); return
|
||||
if bmp is None: return
|
||||
thumb_path = doc_path + ".thumb.png"
|
||||
try:
|
||||
import System.Drawing.Imaging as _imaging
|
||||
bmp.Save(thumb_path, _imaging.ImageFormat.Png)
|
||||
print("[OBERLEISTE] Thumb gespeichert:", thumb_path)
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] Thumb-Save:", ex)
|
||||
finally:
|
||||
try: bmp.Dispose()
|
||||
except Exception: pass
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] _save_thumbnail Fehler:", ex)
|
||||
|
||||
|
||||
def _launch_dossier_app():
|
||||
"""Versucht den Dossier-Launcher (Tauri-App) zu oeffnen.
|
||||
Probiert mehrere Pfade — installiertes Bundle, Dev-Build, dann
|
||||
'open -a Dossier' als letzte Option."""
|
||||
candidates = [
|
||||
"/Applications/Dossier.app",
|
||||
os.path.expanduser("~/Applications/Dossier.app"),
|
||||
os.path.join(_HERE, "..", "launcher", "src-tauri", "target",
|
||||
"release", "bundle", "macos", "Dossier.app"),
|
||||
os.path.join(_HERE, "..", "launcher", "src-tauri", "target",
|
||||
"debug", "bundle", "macos", "Dossier.app"),
|
||||
]
|
||||
for c in candidates:
|
||||
ap = os.path.abspath(c)
|
||||
if os.path.isdir(ap):
|
||||
try:
|
||||
_subprocess.Popen(["open", ap])
|
||||
print("[OBERLEISTE] Dossier-Launcher gestartet:", ap)
|
||||
return True
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] open Dossier-App ({}):".format(ap), ex)
|
||||
# Letzter Versuch: per App-Name (sucht in /Applications)
|
||||
try:
|
||||
_subprocess.Popen(["open", "-a", "Dossier"])
|
||||
print("[OBERLEISTE] Dossier via 'open -a Dossier' gestartet")
|
||||
return True
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] open -a Dossier:", ex)
|
||||
return False
|
||||
|
||||
|
||||
def _extract_layout_name_from_xml(content):
|
||||
"""Liest den Display-Namen aus einer Mac-Rhino-Workspace-XML.
|
||||
Primaer: name="..." Attribut am Root-<RhinoUI>-Element.
|
||||
Fallback: <locale_1033>...</locale_1033>."""
|
||||
if not content: return None
|
||||
import re
|
||||
m = re.search(r'<RhinoUI\b[^>]*\bname="([^"]+)"', content)
|
||||
if m:
|
||||
name = m.group(1).strip()
|
||||
if name: return name
|
||||
m = re.search(r'<locale_1033>([^<]+)</locale_1033>', content)
|
||||
if m:
|
||||
name = m.group(1).strip()
|
||||
if name: return name
|
||||
return None
|
||||
|
||||
|
||||
def _list_window_layouts():
|
||||
"""Liefert die Namen aller gespeicherten Window-Layouts in Rhino.
|
||||
Mac Rhino 8 speichert Layouts als XML (Dateiname = GUID) in
|
||||
settings/Scheme__Default/workspaces/. Display-Namen liegen im
|
||||
name="..." Attribut der Root-RhinoUI-Tag.
|
||||
Probiert zusaetzlich die alte API + den .rwl-Pfad als Fallback."""
|
||||
out = []
|
||||
# 1) API-Wege (selten erfolgreich auf Mac)
|
||||
try:
|
||||
from Rhino import UI as _RUI
|
||||
for attr in ("LayoutNames", "GetLayoutNames", "MainWindowLayoutNames"):
|
||||
try:
|
||||
names = getattr(_RUI.WindowLayout, attr)()
|
||||
if names:
|
||||
for n in names:
|
||||
if n and n not in out: out.append(str(n))
|
||||
if out:
|
||||
print("[OBERLEISTE] Layouts via API.{}: {}".format(attr, out))
|
||||
return out
|
||||
except Exception: continue
|
||||
except Exception: pass
|
||||
|
||||
# 2) Mac-XML-Workspaces — der eigentliche Speicherort auf Mac Rhino 8.
|
||||
workspaces_dir = os.path.expanduser(
|
||||
"~/Library/Application Support/McNeel/Rhinoceros/8.0/"
|
||||
"settings/Scheme__Default/workspaces")
|
||||
try:
|
||||
if os.path.isdir(workspaces_dir):
|
||||
for fn in os.listdir(workspaces_dir):
|
||||
if not fn.lower().endswith(".xml"): continue
|
||||
fp = os.path.join(workspaces_dir, fn)
|
||||
try:
|
||||
with open(fp, "rb") as f:
|
||||
content = f.read().decode("utf-8", errors="replace")
|
||||
except Exception: continue
|
||||
name = _extract_layout_name_from_xml(content)
|
||||
if name and name not in out: out.append(name)
|
||||
if out:
|
||||
print("[OBERLEISTE] {} Layouts via XML gefunden".format(len(out)))
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] workspaces-scan:", ex)
|
||||
|
||||
# 3) Legacy .rwl-Pfade (Windows + ggf. aeltere Rhino-Versionen)
|
||||
candidate_dirs = [
|
||||
os.path.expanduser(
|
||||
"~/Library/Application Support/McNeel/Rhinoceros/8.0/UI/MainWindowLayouts"),
|
||||
os.path.expanduser(
|
||||
"~/Library/Application Support/McNeel/Rhinoceros/8.0/MainWindowLayouts"),
|
||||
os.path.expanduser(
|
||||
"~/Library/Application Support/McNeel/Rhinoceros/8.0/UI/Layouts"),
|
||||
os.path.expanduser(
|
||||
"~/AppData/Roaming/McNeel/Rhinoceros/8.0/UI/MainWindowLayouts"),
|
||||
]
|
||||
for d in candidate_dirs:
|
||||
try:
|
||||
if os.path.isdir(d):
|
||||
for fn in os.listdir(d):
|
||||
if fn.lower().endswith(".rwl"):
|
||||
name = os.path.splitext(fn)[0]
|
||||
if name and name not in out: out.append(name)
|
||||
except Exception: continue
|
||||
|
||||
if not out:
|
||||
print("[OBERLEISTE] Keine Layouts gefunden.")
|
||||
return out
|
||||
|
||||
|
||||
def _layout_name_to_guid(name):
|
||||
"""Sucht in den Workspace-XMLs den Eintrag, dessen Display-Name `name`
|
||||
entspricht und liefert die zugehoerige GUID (= Dateiname ohne .xml)."""
|
||||
if not name: return None
|
||||
workspaces_dir = os.path.expanduser(
|
||||
"~/Library/Application Support/McNeel/Rhinoceros/8.0/"
|
||||
"settings/Scheme__Default/workspaces")
|
||||
if not os.path.isdir(workspaces_dir): return None
|
||||
target = name.strip().lower()
|
||||
try:
|
||||
for fn in os.listdir(workspaces_dir):
|
||||
if not fn.lower().endswith(".xml"): continue
|
||||
fp = os.path.join(workspaces_dir, fn)
|
||||
try:
|
||||
with open(fp, "rb") as f:
|
||||
content = f.read().decode("utf-8", errors="replace")
|
||||
except Exception: continue
|
||||
xn = _extract_layout_name_from_xml(content)
|
||||
if xn and xn.strip().lower() == target:
|
||||
return os.path.splitext(fn)[0]
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] name_to_guid:", ex)
|
||||
return None
|
||||
|
||||
|
||||
def _apply_window_layout(name):
|
||||
"""Wendet ein benanntes Window-Layout an. Probiert mehrere Wege weil
|
||||
Mac Rhino 8 keine offizielle Python-API dafuer exponiert und die
|
||||
Scripted-Commands je nach Rhino-Version variieren. STOP on success —
|
||||
pruefen via RunScript-Return-Value oder via fehlerfreiem API-Call."""
|
||||
if not name:
|
||||
print("[OBERLEISTE] apply_window_layout: leerer Name")
|
||||
return False
|
||||
|
||||
guid = _layout_name_to_guid(name)
|
||||
print("[OBERLEISTE] apply_window_layout: name='{}' guid='{}'".format(
|
||||
name, guid))
|
||||
|
||||
# 1) Direkt ueber Rhino.UI-API per Reflection. Wir loggen WAS gefunden
|
||||
# wurde damit man bei Misserfolg sieht ob Klassen/Methoden ueberhaupt
|
||||
# existieren auf der jeweiligen Rhino-Version.
|
||||
try:
|
||||
from Rhino import UI as _RUI
|
||||
api_candidates = []
|
||||
for cls_name in ("WindowLayout", "WindowLayouts", "MainWindow", "Panels"):
|
||||
cls = getattr(_RUI, cls_name, None)
|
||||
if cls is None: continue
|
||||
for meth_name in ("Restore", "RestoreLayout", "Apply", "ApplyLayout",
|
||||
"Load", "LoadLayout", "SetActive", "SetActiveLayout"):
|
||||
meth = getattr(cls, meth_name, None)
|
||||
if meth is not None:
|
||||
api_candidates.append((cls_name, meth_name, meth))
|
||||
if api_candidates:
|
||||
print("[OBERLEISTE] API-Kandidaten gefunden:", len(api_candidates),
|
||||
[(c, m) for c, m, _ in api_candidates])
|
||||
else:
|
||||
print("[OBERLEISTE] Keine Rhino.UI-API-Kandidaten (Mac Rhino "
|
||||
"exposed das nicht statisch). Falle auf Scripted Commands.")
|
||||
# Args zum Probieren: GUID zuerst (falls vorhanden) dann Name.
|
||||
# Beide als 1-arg Tuple. Doppelte Klammern haben in der alten Version
|
||||
# zu mix von String/Tuple gefuehrt — hier sauber als Liste of Tuples.
|
||||
arg_variants = []
|
||||
if guid: arg_variants.append((guid,))
|
||||
arg_variants.append((name,))
|
||||
for cls_name, meth_name, meth in api_candidates:
|
||||
for arg in arg_variants:
|
||||
try:
|
||||
res = meth(*arg)
|
||||
print("[OBERLEISTE] apply via Rhino.UI.{}.{}({!r}) -> {}".format(
|
||||
cls_name, meth_name, arg[0], res))
|
||||
return True
|
||||
except Exception:
|
||||
continue
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] API-Path Fehler:", ex)
|
||||
|
||||
# 2) Scripted Rhino-Commands. STOP on success — RunScript liefert bool.
|
||||
# Beobachtung aus Mac Rhino 8 Logs: _-WindowLayout "<name>" _Enter wirft
|
||||
# KEINEN Error wenn das Layout greift; bei unbekanntem Namen kommt
|
||||
# "Window layout '<name>' not found.". RunScript() liefert True wenn
|
||||
# die Command-Engine die Zeile syntaktisch akzeptiert hat — das ist
|
||||
# nicht == "Layout applied", aber ein Hinweis. Wir kombinieren mit der
|
||||
# Beobachtung dass die naechste Command-Variante interpretiert wuerde
|
||||
# als Fortsetzung der vorigen (interactive prompt) — daher ESC vorab.
|
||||
def _try_cmd(cmd):
|
||||
try:
|
||||
# Vorab Eingabe-Buffer clearen — sonst landet die naechste
|
||||
# RunScript-Zeile als Antwort in einem evtl. offenen Prompt.
|
||||
try: Rhino.RhinoApp.SendKeystrokes("\x1b", False)
|
||||
except Exception: pass
|
||||
res = Rhino.RhinoApp.RunScript(cmd, False)
|
||||
print("[OBERLEISTE] RunScript({!r}) -> {}".format(cmd, res))
|
||||
return bool(res)
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] RunScript-Fehler ({}): {}".format(cmd, ex))
|
||||
return False
|
||||
|
||||
quoted = '"{}"'.format(name.replace('"', ''))
|
||||
# Reihenfolge: die wahrscheinlichste Mac-Variante zuerst.
|
||||
cmd_candidates = [
|
||||
'_-WindowLayout {} _Enter'.format(quoted),
|
||||
'_-SetActiveLayout {} _Enter'.format(quoted),
|
||||
'_-WindowLayout _Restore {} _Enter'.format(quoted),
|
||||
]
|
||||
for cmd in cmd_candidates:
|
||||
if _try_cmd(cmd):
|
||||
print("[OBERLEISTE] Command erfolgreich, Stop.")
|
||||
return True
|
||||
|
||||
print("[OBERLEISTE] apply_window_layout: kein Weg hat funktioniert. "
|
||||
"Wenn das Layout im Rhino-UI bekannt ist aber hier nicht greift, "
|
||||
"manuell via Window-Menue zu wechseln.")
|
||||
return False
|
||||
|
||||
|
||||
def open_settings_dialog():
|
||||
"""Oeffnet ein natives Eto-Forms-Fenster mit den Dossier-Einstellungen.
|
||||
Vorteil gegenueber HTML-Popover: sprengt die WebView-Bounds der Oberleiste
|
||||
(Popover wuerde abgeschnitten). Aktuell nur Window-Layout-Defaults; spaeter
|
||||
erweiterbar um weitere App-Settings oder Aufruf des Tauri-Launchers."""
|
||||
try:
|
||||
import Eto.Forms as _ef
|
||||
import Eto.Drawing as _ed
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] Eto-Import fehlgeschlagen:", ex); return
|
||||
|
||||
cfg = _settings_load()
|
||||
layouts = _list_window_layouts()
|
||||
|
||||
dlg = _ef.Form()
|
||||
dlg.Title = "Dossier — Einstellungen"
|
||||
try: dlg.ClientSize = _ed.Size(380, 220)
|
||||
except Exception: pass
|
||||
try: dlg.Padding = _ed.Padding(12)
|
||||
except Exception: pass
|
||||
try: dlg.Topmost = True
|
||||
except Exception: pass
|
||||
|
||||
# State (closures)
|
||||
state = {
|
||||
"defaultLayout": cfg.get("windowLayout") or cfg.get("defaultLayout") or "",
|
||||
"autoApply": bool(cfg.get("autoApplyLayout", False)),
|
||||
}
|
||||
|
||||
# --- Inhalt ---
|
||||
lbl_section = _ef.Label()
|
||||
lbl_section.Text = "FENSTER-LAYOUT"
|
||||
try:
|
||||
lbl_section.Font = _ed.Font(_ed.FontFamilies.Sans, 9,
|
||||
_ed.FontStyle.Bold)
|
||||
lbl_section.TextColor = _ed.Color.FromArgb(140, 140, 140, 255)
|
||||
except Exception: pass
|
||||
|
||||
# Dropdown
|
||||
lbl_default = _ef.Label()
|
||||
lbl_default.Text = "Standard:"
|
||||
combo = _ef.DropDown()
|
||||
items = ["— (keines)"] + list(layouts or [])
|
||||
for it in items: combo.Items.Add(it)
|
||||
sel = 0
|
||||
if state["defaultLayout"] in layouts:
|
||||
sel = 1 + layouts.index(state["defaultLayout"])
|
||||
combo.SelectedIndex = sel
|
||||
def _on_combo(s, e):
|
||||
idx = combo.SelectedIndex
|
||||
state["defaultLayout"] = "" if idx <= 0 else layouts[idx - 1]
|
||||
combo.SelectedIndexChanged += _on_combo
|
||||
|
||||
# Checkbox
|
||||
chk = _ef.CheckBox()
|
||||
chk.Text = "Beim Öffnen automatisch anwenden"
|
||||
chk.Checked = state["autoApply"]
|
||||
def _on_chk(s, e):
|
||||
state["autoApply"] = bool(chk.Checked)
|
||||
chk.CheckedChanged += _on_chk
|
||||
|
||||
# Buttons
|
||||
btn_apply = _ef.Button()
|
||||
btn_apply.Text = "Jetzt anwenden"
|
||||
def _on_apply(s, e):
|
||||
if state["defaultLayout"]:
|
||||
_apply_window_layout(state["defaultLayout"])
|
||||
btn_apply.Click += _on_apply
|
||||
|
||||
btn_save = _ef.Button()
|
||||
btn_save.Text = "Speichern"
|
||||
def _on_save(s, e):
|
||||
new_cfg = _settings_load()
|
||||
new_cfg["windowLayout"] = state["defaultLayout"]
|
||||
new_cfg["autoApplyLayout"] = state["autoApply"]
|
||||
# Legacy-Key entfernen damit Launcher und Rhino dieselbe Quelle haben
|
||||
new_cfg.pop("defaultLayout", None)
|
||||
_settings_save(new_cfg)
|
||||
# Oberleiste mit-informieren damit das React-State aktualisiert
|
||||
try:
|
||||
b = sc.sticky.get("oberleiste_bridge")
|
||||
if b is not None: b._send_settings_state()
|
||||
except Exception: pass
|
||||
try: dlg.Close()
|
||||
except Exception: pass
|
||||
btn_save.Click += _on_save
|
||||
|
||||
btn_close = _ef.Button()
|
||||
btn_close.Text = "Schliessen"
|
||||
def _on_close(s, e):
|
||||
try: dlg.Close()
|
||||
except Exception: pass
|
||||
btn_close.Click += _on_close
|
||||
|
||||
# Hinweis bei keinen Layouts
|
||||
hint = _ef.Label()
|
||||
if not layouts:
|
||||
hint.Text = ("Keine gespeicherten Layouts gefunden.\n"
|
||||
"In Rhino: Window → Window Layouts → Save…")
|
||||
try:
|
||||
hint.TextColor = _ed.Color.FromArgb(140, 140, 140, 255)
|
||||
hint.Font = _ed.Font(_ed.FontFamilies.Sans, 10,
|
||||
_ed.FontStyle.Italic)
|
||||
except Exception: pass
|
||||
|
||||
# --- Layout via StackLayout ---
|
||||
layout = _ef.DynamicLayout()
|
||||
try:
|
||||
layout.Padding = _ed.Padding(0)
|
||||
layout.Spacing = _ed.Size(6, 8)
|
||||
except Exception: pass
|
||||
layout.AddRow(lbl_section)
|
||||
layout.AddRow(lbl_default, combo)
|
||||
layout.AddRow(chk)
|
||||
layout.AddRow(btn_apply)
|
||||
if not layouts:
|
||||
layout.AddRow(hint)
|
||||
# Spacer
|
||||
layout.AddRow(None)
|
||||
# Save-Row rechtsbuendig
|
||||
btn_row = _ef.DynamicLayout()
|
||||
try: btn_row.Spacing = _ed.Size(6, 0)
|
||||
except Exception: pass
|
||||
btn_row.BeginHorizontal()
|
||||
btn_row.Add(None, True)
|
||||
btn_row.Add(btn_close)
|
||||
btn_row.Add(btn_save)
|
||||
btn_row.EndHorizontal()
|
||||
layout.AddRow(btn_row)
|
||||
|
||||
dlg.Content = layout
|
||||
try: dlg.Show()
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] Settings-Dialog Show:", ex)
|
||||
|
||||
|
||||
def _get_active_viewport_name():
|
||||
try:
|
||||
v = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView
|
||||
@@ -235,6 +787,25 @@ class OberleisteBridge(panel_base.BaseBridge):
|
||||
# nur die "—"-Option und wirkt wie ein toter Button.
|
||||
self._dm_sent = False
|
||||
self._commands_sent = False
|
||||
# Default-Window-Layout anwenden, wenn aktiviert und noch nicht in
|
||||
# dieser Session geschehen (sticky-flag verhindert Endlos-Schleifen
|
||||
# falls die Layout-Restoration unsere Panels neu mountet). Layout-Name
|
||||
# wird vom Launcher unter `windowLayout` geschrieben; Legacy-Key
|
||||
# `defaultLayout` wird in _settings_load() bereits normalisiert.
|
||||
try:
|
||||
cfg = _settings_load()
|
||||
if not sc.sticky.get("_dossier_layout_applied"):
|
||||
layout_name = cfg.get("windowLayout") or cfg.get("defaultLayout")
|
||||
if cfg.get("autoApplyLayout") and layout_name:
|
||||
sc.sticky["_dossier_layout_applied"] = True
|
||||
_apply_window_layout(layout_name)
|
||||
# Viewport-Colors einmalig pro Session auto-applien (wenn aktiviert)
|
||||
if (cfg.get("autoApplyViewColors") and
|
||||
not sc.sticky.get("_dossier_view_colors_applied")):
|
||||
if _apply_viewport_colors(cfg):
|
||||
sc.sticky["_dossier_view_colors_applied"] = True
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] auto-apply (layout/colors):", ex)
|
||||
self._send_state(force=True)
|
||||
|
||||
def handle(self, data):
|
||||
@@ -398,6 +969,40 @@ class OberleisteBridge(panel_base.BaseBridge):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# --- Settings + Window-Layout -----------------------------------
|
||||
elif t == "OPEN_SETTINGS":
|
||||
# Primaerweg: Dossier-Launcher (Tauri-App) oeffnen, dort lebt das
|
||||
# echte Settings-UI. Wenn der Launcher nicht installiert ist,
|
||||
# faellt es auf den Eto-Dialog zurueck.
|
||||
if not _launch_dossier_app():
|
||||
open_settings_dialog()
|
||||
elif t == "GET_SETTINGS":
|
||||
self._send_settings_state()
|
||||
elif t == "APPLY_LAYOUT":
|
||||
name = (p.get("name") or "").strip()
|
||||
if name: _apply_window_layout(name)
|
||||
elif t == "SAVE_LAYOUT_PREF":
|
||||
cfg = _settings_load()
|
||||
if "windowLayout" in p:
|
||||
cfg["windowLayout"] = (p.get("windowLayout") or "")
|
||||
elif "defaultLayout" in p:
|
||||
cfg["windowLayout"] = (p.get("defaultLayout") or "")
|
||||
if "autoApplyLayout" in p:
|
||||
cfg["autoApplyLayout"] = bool(p.get("autoApplyLayout"))
|
||||
_settings_save(cfg)
|
||||
self._send_settings_state()
|
||||
|
||||
def _send_settings_state(self):
|
||||
"""Schickt App-Settings + verfuegbare Window-Layouts an die UI."""
|
||||
cfg = _settings_load()
|
||||
layout_name = cfg.get("windowLayout") or cfg.get("defaultLayout") or ""
|
||||
self.send("SETTINGS_STATE", {
|
||||
"layouts": _list_window_layouts(),
|
||||
"windowLayout": layout_name,
|
||||
"defaultLayout": layout_name, # legacy alias
|
||||
"autoApplyLayout": bool(cfg.get("autoApplyLayout", False)),
|
||||
})
|
||||
|
||||
def _send_state(self, force=False):
|
||||
doc, vp = massstab._active_vp()
|
||||
info = massstab._compute_scale(doc, vp)
|
||||
@@ -460,6 +1065,77 @@ class OberleisteBridge(panel_base.BaseBridge):
|
||||
self._last_state_sig = sig
|
||||
self.send("STATE", info)
|
||||
|
||||
def _check_pending_launcher_signals(self):
|
||||
"""Pollt dossier_settings.json auf vom Launcher gesetzte Pending-Flags.
|
||||
Aktuell: pendingApplyLayout, pendingApplyViewColors,
|
||||
pendingImportDisplayModes. Loescht das jeweilige Flag nach
|
||||
Verarbeitung damit es nicht jeden Idle erneut feuert."""
|
||||
try:
|
||||
cfg = _settings_load()
|
||||
mutated = False
|
||||
|
||||
pend_layout = cfg.get("pendingApplyLayout")
|
||||
if isinstance(pend_layout, str) and pend_layout:
|
||||
print("[OBERLEISTE] pendingApplyLayout:", pend_layout)
|
||||
_apply_window_layout(pend_layout)
|
||||
cfg.pop("pendingApplyLayout", None)
|
||||
mutated = True
|
||||
|
||||
if cfg.get("pendingApplyViewColors"):
|
||||
if _apply_viewport_colors(cfg):
|
||||
print("[OBERLEISTE] pendingApplyViewColors: angewendet")
|
||||
cfg["pendingApplyViewColors"] = False
|
||||
mutated = True
|
||||
|
||||
modes = cfg.get("pendingImportDisplayModes") or []
|
||||
if isinstance(modes, list) and modes:
|
||||
n = _import_display_modes(modes)
|
||||
print("[OBERLEISTE] pendingImportDisplayModes: {} importiert".format(n))
|
||||
cfg["pendingImportDisplayModes"] = []
|
||||
mutated = True
|
||||
|
||||
if cfg.get("pendingExportEbenen"):
|
||||
# User hat im Launcher "Aus laufendem Rhino importieren"
|
||||
# geklickt — wir lesen die aktuelle Ebenen-Liste aus dem Doc
|
||||
# und schreiben sie als layerSchema zurueck.
|
||||
try:
|
||||
doc = Rhino.RhinoDoc.ActiveDoc
|
||||
raw = doc.Strings.GetValue("dossier_ebenen")
|
||||
if raw:
|
||||
ebenen = _json.loads(raw)
|
||||
clean = []
|
||||
for e in (ebenen or []):
|
||||
if not isinstance(e, dict): continue
|
||||
code = e.get("code")
|
||||
name = e.get("name")
|
||||
color = e.get("color")
|
||||
lw = e.get("lw")
|
||||
if not code or not name: continue
|
||||
if color is None or lw is None: continue
|
||||
clean.append({
|
||||
"code": str(code),
|
||||
"name": str(name),
|
||||
"color": str(color),
|
||||
"lw": float(lw),
|
||||
})
|
||||
if clean:
|
||||
cfg["layerSchema"] = clean
|
||||
print("[OBERLEISTE] Ebenen-Export: {} Sublayer "
|
||||
"ins Launcher-Schema geschrieben".format(len(clean)))
|
||||
else:
|
||||
print("[OBERLEISTE] Ebenen-Export: doc.Strings hatte "
|
||||
"keine gueltigen Ebenen")
|
||||
else:
|
||||
print("[OBERLEISTE] Ebenen-Export: doc.Strings ['dossier_ebenen'] leer")
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] Ebenen-Export Fehler:", ex)
|
||||
cfg["pendingExportEbenen"] = False
|
||||
mutated = True
|
||||
|
||||
if mutated: _settings_save(cfg)
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] check_pending_launcher_signals:", ex)
|
||||
|
||||
def tick_idle(self):
|
||||
# Command-Prompt aendert sich oft schnell -> separater Pfad: wenn sich
|
||||
# der Prompt seit letztem Tick geaendert hat, sofort pushen (ungedrosselt).
|
||||
@@ -474,6 +1150,8 @@ class OberleisteBridge(panel_base.BaseBridge):
|
||||
if self._idle_counter < massstab._IDLE_THROTTLE:
|
||||
return
|
||||
self._idle_counter = 0
|
||||
# Launcher-Signale pruefen (selten genug — gepollt im normalen Throttle).
|
||||
self._check_pending_launcher_signals()
|
||||
self._send_state(force=False)
|
||||
|
||||
|
||||
@@ -497,8 +1175,19 @@ def _install_listeners(bridge):
|
||||
try: b._send_state(force=True)
|
||||
except Exception: pass
|
||||
|
||||
def on_end_save(sender, e):
|
||||
# EndSaveDocument feuert nach erfolgreichem Save. e.Document gibt
|
||||
# uns den Doc. Wir generieren das Launcher-Thumbnail neben der .3dm.
|
||||
try:
|
||||
doc = getattr(e, "Document", None) or Rhino.RhinoDoc.ActiveDoc
|
||||
_save_thumbnail(doc)
|
||||
except Exception as ex:
|
||||
print("[OBERLEISTE] on_end_save:", ex)
|
||||
|
||||
Rhino.RhinoApp.Idle += on_idle
|
||||
Rhino.RhinoDoc.ActiveDocumentChanged += on_view_change
|
||||
try: Rhino.RhinoDoc.EndSaveDocument += on_end_save
|
||||
except Exception as ex: print("[OBERLEISTE] EndSaveDocument-Hook:", ex)
|
||||
sc.sticky[flag] = True
|
||||
print("[OBERLEISTE] Listener aktiv")
|
||||
|
||||
@@ -510,4 +1199,4 @@ def _bridge_factory():
|
||||
|
||||
|
||||
panel_base.register_and_open("oberleiste", "OBERLEISTE", PANEL_GUID_STR, _bridge_factory,
|
||||
icon_spec=("O", "#2f5d54"))
|
||||
icon_spec=("menu", "#2f5d54"))
|
||||
|
||||
Reference in New Issue
Block a user