Initial commit — Dossier Rhino 8 Plugin
OpenStudio-Suite Architektur-Plugin fuer Rhino 8 (Mac): - Smart-Elemente: Wand, Decke, Dach (Pult/Sattel/Walm/Mansarde), Oeffnungen (Fenster/Tueren mit Rahmen + Sims + Glas + Fluegel), Treppen (gerade · L · Wendel mit Schrittmass-Validierung) - Live-Previews mit Step-Lines + Soll-Range-Clamping - Bidirektionale Selection-Sync zwischen Source-Linie und Volume - Geschoss-/Ebenen-Verwaltung mit OKFF-Persistenz - Layouts mit PDF-Export - Ausschnitte / Massstab / Override-Regeln - Petrol-Gruen Theme (Rapport-konform) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,325 @@
|
||||
import React, { useEffect, useState, useMemo } from 'react'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { open as openDialog, save as saveDialog } from '@tauri-apps/plugin-dialog'
|
||||
|
||||
// Transitive Dependency-Aufloesung: gibt Set aller Module zurueck, die
|
||||
// aktiviert sein muessen, wenn `selected` aktiviert sind.
|
||||
function resolveDeps(selected, allModules) {
|
||||
const byId = Object.fromEntries(allModules.map(m => [m.id, m]))
|
||||
const out = new Set(selected)
|
||||
let changed = true
|
||||
while (changed) {
|
||||
changed = false
|
||||
for (const id of [...out]) {
|
||||
const m = byId[id]
|
||||
if (!m) continue
|
||||
for (const dep of (m.dependsOn || [])) {
|
||||
if (!out.has(dep)) { out.add(dep); changed = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Modul-IDs, die aktuell aktiv sind WEIL eine andere Auswahl sie braucht.
|
||||
function lockedBy(selected, allModules) {
|
||||
const byId = Object.fromEntries(allModules.map(m => [m.id, m]))
|
||||
const locked = new Set()
|
||||
for (const id of selected) {
|
||||
const m = byId[id]
|
||||
if (!m) continue
|
||||
for (const dep of (m.dependsOn || [])) {
|
||||
if (selected.has(dep) || selected.has(id)) locked.add(dep)
|
||||
}
|
||||
}
|
||||
return locked
|
||||
}
|
||||
|
||||
function formatRelative(iso) {
|
||||
if (!iso) return ''
|
||||
try {
|
||||
const d = new Date(iso)
|
||||
const now = new Date()
|
||||
const diff = (now - d) / 1000
|
||||
if (diff < 60) return 'vor wenigen Sek.'
|
||||
if (diff < 3600) return `vor ${Math.floor(diff/60)} Min.`
|
||||
if (diff < 86400) return `vor ${Math.floor(diff/3600)} h`
|
||||
if (diff < 86400 * 7) return `vor ${Math.floor(diff/86400)} Tagen`
|
||||
return d.toLocaleDateString('de-CH')
|
||||
} catch { return '' }
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [recent, setRecent] = useState([])
|
||||
const [modules, setModules] = useState([])
|
||||
const [dialog, setDialog] = useState(null) // null | { mode: 'new'|'edit', project? }
|
||||
const [settingsOpen, setSettingsOpen] = useState(false)
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
invoke('list_recent').then(setRecent).catch(console.error)
|
||||
invoke('read_modules_manifest').then(setModules).catch(console.error)
|
||||
}, [])
|
||||
|
||||
const refresh = () => invoke('list_recent').then(setRecent).catch(console.error)
|
||||
|
||||
const openProject = async (proj) => {
|
||||
if (busy) return
|
||||
setBusy(true)
|
||||
try {
|
||||
await invoke('open_rhino', { path3dm: proj.path })
|
||||
const next = recent.map(p =>
|
||||
p.path === proj.path ? { ...p, lastOpened: new Date().toISOString() } : p
|
||||
)
|
||||
await invoke('save_recent', { projects: next })
|
||||
setRecent(next)
|
||||
} catch (ex) {
|
||||
alert(`Rhino-Start fehlgeschlagen: ${ex}`)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const editProject = (proj) => {
|
||||
setDialog({ mode: 'edit', project: proj })
|
||||
}
|
||||
|
||||
const saveProject = async ({ name, path, modules: mods }) => {
|
||||
if (!path) { alert('Bitte eine .3dm-Datei auswaehlen.'); return }
|
||||
if (!name.trim()) { alert('Bitte einen Projekt-Namen angeben.'); return }
|
||||
try {
|
||||
await invoke('write_project_config', { path3dm: path, name: name.trim(), modules: mods })
|
||||
const others = recent.filter(p => p.path !== path)
|
||||
const next = [{ name: name.trim(), path, modules: mods,
|
||||
lastOpened: new Date().toISOString() }, ...others]
|
||||
await invoke('save_recent', { projects: next })
|
||||
setRecent(next)
|
||||
setDialog(null)
|
||||
} catch (ex) {
|
||||
alert(`Speichern fehlgeschlagen: ${ex}`)
|
||||
}
|
||||
}
|
||||
|
||||
const removeProject = async (proj) => {
|
||||
const next = recent.filter(p => p.path !== proj.path)
|
||||
await invoke('save_recent', { projects: next })
|
||||
setRecent(next)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<div className="topbar">
|
||||
<span className="brand">DOSSIER</span>
|
||||
<span className="version">0.1.0</span>
|
||||
<div className="spacer" />
|
||||
<button onClick={() => setDialog({ mode: 'new' })}>Neues Projekt</button>
|
||||
<button onClick={() => setSettingsOpen(true)} title="Einstellungen"
|
||||
style={{ padding: '6px 10px' }}>⚙</button>
|
||||
</div>
|
||||
|
||||
<div className="main">
|
||||
<h2 className="section-title">Kuerzlich geoeffnet</h2>
|
||||
{recent.length === 0 ? (
|
||||
<div className="empty">
|
||||
Noch keine Projekte. Klick „Neues Projekt" zum Starten.
|
||||
</div>
|
||||
) : (
|
||||
<div className="project-list">
|
||||
{recent.map(p => (
|
||||
<div key={p.path} className="project-card"
|
||||
onDoubleClick={() => openProject(p)}>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div className="name">{p.name}</div>
|
||||
<div className="path">{p.path}</div>
|
||||
</div>
|
||||
<div className="meta">
|
||||
{p.modules?.length || 0} Module · {formatRelative(p.lastOpened)}
|
||||
</div>
|
||||
<button onClick={() => editProject(p)}>Bearbeiten</button>
|
||||
<button className="primary" disabled={busy}
|
||||
onClick={() => openProject(p)}>
|
||||
Öffnen
|
||||
</button>
|
||||
<button onClick={() => removeProject(p)} title="Aus Liste entfernen">×</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{dialog && (
|
||||
<ProjectDialog
|
||||
mode={dialog.mode}
|
||||
project={dialog.project}
|
||||
modules={modules}
|
||||
onCancel={() => setDialog(null)}
|
||||
onSave={saveProject}
|
||||
/>
|
||||
)}
|
||||
{settingsOpen && (
|
||||
<SettingsDialog onClose={() => setSettingsOpen(false)} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SettingsDialog({ onClose }) {
|
||||
const [rhinoApp, setRhinoApp] = useState('')
|
||||
const [loaded, setLoaded] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
invoke('read_settings')
|
||||
.then(s => { setRhinoApp(s.rhinoApp || 'Rhinoceros 8'); setLoaded(true) })
|
||||
.catch(() => { setRhinoApp('Rhinoceros 8'); setLoaded(true) })
|
||||
}, [])
|
||||
|
||||
const pickRhino = async () => {
|
||||
// .app-Bundles sind technisch Ordner, macOS behandelt sie aber im File-Picker
|
||||
// als auswaehlbare Pakete, wenn der Extension-Filter "app" gesetzt ist.
|
||||
// directory:true wuerde stattdessen reinnavigieren — falsch.
|
||||
const sel = await openDialog({
|
||||
title: 'Rhino-App waehlen',
|
||||
filters: [{ name: 'Anwendung', extensions: ['app'] }],
|
||||
defaultPath: '/Applications',
|
||||
})
|
||||
if (typeof sel === 'string') setRhinoApp(sel)
|
||||
}
|
||||
|
||||
const useDefault = () => setRhinoApp('Rhinoceros 8')
|
||||
|
||||
const save = async () => {
|
||||
try {
|
||||
await invoke('save_settings', { settings: { rhinoApp: rhinoApp.trim() || 'Rhinoceros 8' } })
|
||||
onClose()
|
||||
} catch (ex) {
|
||||
alert(`Speichern fehlgeschlagen: ${ex}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (!loaded) return null
|
||||
|
||||
return (
|
||||
<div className="dialog-bg" onClick={(e) => { if (e.target === e.currentTarget) onClose() }}>
|
||||
<div className="dialog" style={{ width: 520 }}>
|
||||
<header>Einstellungen</header>
|
||||
<div className="body">
|
||||
<div className="row">
|
||||
<label>Rhino-Anwendung</label>
|
||||
<div className="file-picker">
|
||||
<input type="text" value={rhinoApp}
|
||||
onChange={e => setRhinoApp(e.target.value)}
|
||||
placeholder="Rhinoceros 8" />
|
||||
<button onClick={pickRhino}>Waehlen…</button>
|
||||
</div>
|
||||
<div style={{ fontSize: 11, color: 'var(--text-muted)', lineHeight: 1.5 }}>
|
||||
App-Name (in /Applications gesucht) oder absoluter Pfad zur .app.
|
||||
Beispiele:<br />
|
||||
<code style={{ fontFamily: 'var(--mono)' }}>Rhinoceros 8</code> · <code style={{ fontFamily: 'var(--mono)' }}>/Applications/Rhino 8.app</code> · <code style={{ fontFamily: 'var(--mono)' }}>/Applications/Rhino 8 WIP.app</code>
|
||||
<button onClick={useDefault} style={{ display: 'block', marginTop: 8, fontSize: 11 }}>
|
||||
Standard verwenden
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<button onClick={onClose}>Abbrechen</button>
|
||||
<button className="primary" onClick={save}>Speichern</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ProjectDialog({ mode, project, modules, onCancel, onSave }) {
|
||||
const [name, setName] = useState(project?.name || '')
|
||||
const [path, setPath] = useState(project?.path || '')
|
||||
const [picked, setPicked] = useState(new Set(project?.modules || ['ebenen', 'oberleiste']))
|
||||
|
||||
const effective = useMemo(() => resolveDeps(picked, modules), [picked, modules])
|
||||
const locked = useMemo(() => {
|
||||
// Module, die aktiv sind, aber NICHT direkt gewaehlt — also nur als Dep
|
||||
const out = new Set()
|
||||
for (const id of effective) {
|
||||
if (!picked.has(id)) out.add(id)
|
||||
}
|
||||
return out
|
||||
}, [picked, effective, modules])
|
||||
|
||||
const toggle = (id) => {
|
||||
if (locked.has(id)) return // nicht direkt abwaehlbar
|
||||
setPicked(prev => {
|
||||
const next = new Set(prev)
|
||||
if (next.has(id)) next.delete(id); else next.add(id)
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
const pickFile = async () => {
|
||||
const sel = mode === 'new'
|
||||
? await openDialog({
|
||||
title: '3dm-Datei auswaehlen',
|
||||
filters: [{ name: 'Rhino', extensions: ['3dm'] }],
|
||||
})
|
||||
: await openDialog({
|
||||
title: '3dm-Datei auswaehlen',
|
||||
filters: [{ name: 'Rhino', extensions: ['3dm'] }],
|
||||
})
|
||||
if (typeof sel === 'string') setPath(sel)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="dialog-bg" onClick={(e) => { if (e.target === e.currentTarget) onCancel() }}>
|
||||
<div className="dialog">
|
||||
<header>{mode === 'new' ? 'Neues Projekt' : 'Projekt bearbeiten'}</header>
|
||||
<div className="body">
|
||||
<div className="row">
|
||||
<label>Projekt-Name</label>
|
||||
<input type="text" value={name} onChange={e => setName(e.target.value)}
|
||||
placeholder="z.B. Wohnhaus Brunner" autoFocus />
|
||||
</div>
|
||||
<div className="row">
|
||||
<label>3dm-Datei</label>
|
||||
<div className="file-picker">
|
||||
<input type="text" value={path} readOnly
|
||||
placeholder="Pfad zur 3dm-Datei" />
|
||||
<button onClick={pickFile}>Waehlen…</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row">
|
||||
<label>Module ({[...effective].length} aktiv)</label>
|
||||
<div className="module-grid">
|
||||
{modules.map(m => {
|
||||
const isActive = effective.has(m.id)
|
||||
const isLocked = locked.has(m.id)
|
||||
return (
|
||||
<div
|
||||
key={m.id}
|
||||
className={`module-row ${isActive ? 'active' : ''} ${isLocked ? 'locked' : ''}`}
|
||||
onClick={() => toggle(m.id)}
|
||||
title={isLocked ? 'Wird von einem anderen Modul gebraucht' : ''}
|
||||
>
|
||||
<div className="check">{isActive ? (isLocked ? '🔒' : '✓') : ''}</div>
|
||||
<div className="info">
|
||||
<div className="name">{m.name}</div>
|
||||
<div className="desc">{m.description}</div>
|
||||
{(m.dependsOn || []).length > 0 && (
|
||||
<div className="dep">braucht: {m.dependsOn.join(', ')}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<button onClick={onCancel}>Abbrechen</button>
|
||||
<button className="primary"
|
||||
onClick={() => onSave({ name, path, modules: [...effective] })}>
|
||||
Speichern
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user