// Dock-Panel „BCF-Themen": Koordinations-Themen im BIM Collaboration Format (2.1/3.0) von Solibri, // BIMcollab, Revit, ArchiCAD. Datei öffnen, Themenliste mit Status, Klick zeigt Beschreibung, // Kommentare und Snapshot und wählt die betroffenen Bauteile im Modell aus (Zuordnung über die // IFC-GlobalId, dieselbe Ableitung wie im IFC-Export: `io/bcfMatch.ts`). Kommentar hinzufügen, // Status ändern, neues Thema aus der Auswahl, als .bcfzip speichern. // // Die Themen gehören nicht zum Projekt (eigene Datei, `bcfSession.ts`). Kamera und Schnittebene // eines Viewpoints setzt die Kamera-Brücke des 3D-Viewports (`viewport/cameraBridge.ts`, Umrechnung // samt LV95-Versatz in `bcfView.ts`); neue Themen und Kommentare nehmen die aktuelle Kamera plus // Schnappschuss als Viewpoint auf. Ohne offenen WASM-3D-Viewport (kein 3D, nativer macOS-Pfad) // bleibt es bei Anzeige und Auswahl. // // Bezeichner englisch, UI-Text deutsch/englisch über t(). import { useMemo, useRef } from "react"; import { t } from "../i18n"; import { usePanelHost } from "./host"; import { getState, useStore } from "../state/appStore"; import { fromIdLists, toIdLists } from "../state/selection"; import { saveBinaryFile } from "../native/saveFile"; import { BCF_STATUSES, addComment, addTopic, emptyBcf, newTopic, parseBcf, setTopicStatus, writeBcf, type BcfCamera, type BcfFile, type BcfTopic, type BcfViewpoint, type BcfVersion, } from "../io/bcf"; import { bcfSelectionSize, emptyBcfSelection, resolveGuids, selectionToGuids, viewpointGuids, type BcfSelection, } from "../io/bcfMatch"; import { fileioLoaded, loadFileio } from "../engine/fileioWasm"; import { projectGeoOrigin } from "../core"; import { captureSnapshot, getCamera, setCamera, setSection, viewportAvailable } from "../viewport/cameraBridge"; import { firstViewpointWithCamera, sectionFromBcfClipping, viewCameraFromBcf, viewpointForTopic } from "./bcfView"; import { setBcfSession, useBcfSession } from "./bcfSession"; const AUTHOR_KEY = "dossier.bcf.author"; function readAuthor(): string { try { return localStorage.getItem(AUTHOR_KEY) ?? ""; } catch { return ""; } } function writeAuthor(v: string): void { try { localStorage.setItem(AUTHOR_KEY, v); } catch { /* ohne Speicher: nur für diese Sitzung */ } } function uuid(): string { if (typeof crypto !== "undefined" && "randomUUID" in crypto) return crypto.randomUUID(); const h = (n: number) => Math.floor(Math.random() * 16 ** n).toString(16).padStart(n, "0"); return `${h(8)}-${h(4)}-4${h(3)}-a${h(3)}-${h(12)}`; } /** Auswahl des Modells in die Kanäle des Stores übernehmen (ersetzt die bisherige Auswahl). */ function applySelection(sel: BcfSelection): void { const s = getState(); s.clearSelection(); s.setSelection(fromIdLists(sel)); } function currentSelection(): BcfSelection { const l = toIdLists(getState().selection); const out = emptyBcfSelection(); for (const k of Object.keys(out) as (keyof BcfSelection)[]) out[k] = l[k]; return out; } const f1 = (n: number) => n.toLocaleString("de-CH", { maximumFractionDigits: 1 }); function cameraText(c: BcfCamera): string { const p = { x: f1(c.position[0]), y: f1(c.position[1]), z: f1(c.position[2]) }; return c.kind === "orthogonal" ? t("bcf.camera.orthogonal", p) : t("bcf.camera.perspective", { ...p, fov: f1(c.fieldOfView) }); } export function BcfPanel() { const host = usePanelHost(); const notify = useStore((s) => s.notify); const session = useBcfSession(); const inputRef = useRef(null); const authorRef = useRef(null); const commentRef = useRef(null); const attachRef = useRef(null); const { file, selectedGuid } = session; const topic = file?.topics.find((x) => x.guid === selectedGuid) ?? null; const author = () => authorRef.current?.value.trim() || "Dossier"; const now = () => new Date().toISOString(); const update = (next: BcfFile) => setBcfSession({ file: next, dirty: true }); const openFile = async (f: File) => { try { const parsed = await parseBcf(new Uint8Array(await f.arrayBuffer())); setBcfSession({ file: parsed, fileName: f.name, dirty: false, selectedGuid: null, version: parsed.version === "3.0" ? "3.0" : "2.1" }); } catch (e) { notify(t("bcf.openFailed", { error: e instanceof Error ? e.message : String(e) }), "error"); } }; /** Kamera, Schnittebene und Bauteile eines Viewpoints im Modell zeigen. */ const showViewpoint = (vp: BcfViewpoint | null, topicGuids: string[]) => { const origin = projectGeoOrigin(host.project); if (vp?.camera || (vp && vp.clippingPlanes.length > 0)) { if (!viewportAvailable()) { notify(t("bcf.noViewport"), "warning"); } else { if (vp.camera) { const vc = viewCameraFromBcf(vp.camera, origin, getCamera()?.aspect ?? 1); if (vc && setCamera(vc, { animate: true })) notify(t("bcf.cameraSet"), "info"); else notify(t("bcf.cameraFailed"), "warning"); } // Schnitt: die erste senkrechte Ebene wird live gesetzt; ohne Ebenen fällt ein früherer Schnitt weg. const planes = vp.clippingPlanes; const live = planes.map((c) => sectionFromBcfClipping(c, origin)).find((x) => x !== null) ?? null; setSection(live); if (live) notify(t("bcf.sectionSet"), "info"); else if (planes.length > 0) notify(t("bcf.sectionTilted"), "warning"); } } else if (vp && viewportAvailable()) { setSection(null); } const guids = vp ? viewpointGuids(vp) : topicGuids; if (guids.length === 0) return; // GlobalIds brauchen das Format-Modul (Rust-Hash); nach dem Öffnen ist es geladen. void loadFileio().then(() => { const { selection } = resolveGuids(host.project, guids); const found = bcfSelectionSize(selection); applySelection(selection); notify(t("bcf.components", { found, total: guids.length }), found > 0 ? "info" : "warning"); }); }; const selectTopic = (tp: BcfTopic) => { setBcfSession({ selectedGuid: tp.guid }); // Kamera/Schnitt vom ersten Viewpoint mit Kamera, sonst vom ersten überhaupt; die Auswahl // gilt dem ganzen Thema (alle Viewpoints). const topicGuids = [...new Set(tp.viewpoints.flatMap(viewpointGuids))]; const vp = firstViewpointWithCamera(tp) ?? tp.viewpoints[0] ?? null; showViewpoint(vp, topicGuids); }; /** Neuer Viewpoint aus Auswahl + aktueller Kamera + Schnappschuss. */ const captureViewpoint = async (): Promise => { await loadFileio(); const sel = currentSelection(); const guids = bcfSelectionSize(sel) > 0 ? selectionToGuids(host.project, sel) : []; const camera = getCamera(); const png = camera ? await captureSnapshot() : null; if (camera && !png) notify(t("bcf.noSnapshot"), "info"); return viewpointForTopic({ guid: uuid(), ifcGuids: guids, camera, snapshotPng: png, origin: projectGeoOrigin(host.project) }); }; const save = async () => { if (!file) return; try { const bytes = await writeBcf(file, session.version); const name = session.fileName.replace(/\.(bcf|bcfzip|zip)$/i, "") || host.project.name || "themen"; if (await saveBinaryFile(bytes, `${name}.bcfzip`, "application/zip")) { setBcfSession({ dirty: false, fileName: `${name}.bcfzip` }); notify(t("bcf.saved"), "info"); } } catch (e) { notify(t("bcf.saveFailed", { error: e instanceof Error ? e.message : String(e) }), "error"); } }; const createFromSelection = async () => { const sel = currentSelection(); if (bcfSelectionSize(sel) === 0) { notify(t("bcf.needSelection"), "warning"); return; } const vp = await captureViewpoint(); const topicGuid = uuid(); const tp = newTopic({ guid: topicGuid, title: t("bcf.defaultTitle"), author: author(), now: now(), viewpoints: vp.selection.length > 0 || vp.camera ? [vp] : [], }); const base = file ?? emptyBcf(host.project.id, host.project.name ?? ""); setBcfSession({ file: addTopic(base, tp), dirty: true, selectedGuid: topicGuid }); }; /** Aktuelle 3D-Ansicht (Kamera + Bild + Auswahl) als weiteren Viewpoint ans gewählte Thema hängen. */ const addViewpointToTopic = async () => { if (!file || !topic) return; if (!viewportAvailable()) { notify(t("bcf.noViewport"), "warning"); return; } const vp = await captureViewpoint(); update({ ...file, topics: file.topics.map((x) => (x.guid === topic.guid ? { ...x, viewpoints: [...x.viewpoints, vp], modifiedDate: now(), modifiedAuthor: author() } : x)) }); }; const submitComment = async () => { const el = commentRef.current; if (!file || !topic || !el || el.value.trim() === "") return; const text = el.value.trim(); // Optional die aktuelle 3D-Ansicht als Viewpoint des Kommentars. let vp: BcfViewpoint | null = null; if (attachRef.current?.checked && viewportAvailable()) vp = await captureViewpoint(); const withVp = vp && (vp.camera || vp.selection.length > 0) ? vp : null; const next = addComment(file, topic.guid, { guid: uuid(), date: now(), author: author(), comment: text, viewpointGuid: withVp?.guid ?? "", modifiedDate: "", modifiedAuthor: "" }); update(withVp ? { ...next, topics: next.topics.map((x) => (x.guid === topic.guid ? { ...x, viewpoints: [...x.viewpoints, withVp] } : x)) } : next); el.value = ""; }; const retitle = (title: string) => { if (!file || !topic) return; update({ ...file, topics: file.topics.map((x) => (x.guid === topic.guid ? { ...x, title, modifiedDate: now(), modifiedAuthor: author() } : x)) }); }; const clipping = topic?.viewpoints.flatMap((v) => v.clippingPlanes) ?? []; const camera = topic?.viewpoints.find((v) => v.camera)?.camera ?? null; const topicGuids = topic ? [...new Set(topic.viewpoints.flatMap(viewpointGuids))] : []; const project = host.project; const foundCount = useMemo( () => (topicGuids.length > 0 && fileioLoaded() ? bcfSelectionSize(resolveGuids(project, topicGuids).selection) : 0), // eslint-disable-next-line react-hooks/exhaustive-deps [project, topic], ); return (
{ const f = e.target.files?.[0]; e.target.value = ""; if (f) void openFile(f); }} />
{!file &&
{t("bcf.empty")}
} {file &&
{t("bcf.fileInfo", { name: session.fileName || "–", version: file.version, n: file.topics.length })}
} {file && file.topics.length === 0 &&
{t("bcf.noTopics")}
}
    {file?.topics.map((tp) => (
  • ))}
{file && topic && (
retitle(e.target.value)} aria-label={t("bcf.defaultTitle")} />
{topic.topicType &&
{t("bcf.type")}{topic.topicType}
} {topic.priority &&
{t("bcf.priority")}{topic.priority}
} {topic.assignedTo &&
{t("bcf.assignedTo")}{topic.assignedTo}
} {topic.dueDate &&
{t("bcf.dueDate")}{topic.dueDate.slice(0, 10)}
} {topic.labels.length > 0 &&
{t("bcf.labels")}{topic.labels.join(", ")}
}
{topic.description &&
{topic.description}
} {topic.viewpoints.length > 0 && ( <>
{t("bcf.viewpoints")}
{topic.viewpoints.map((vp, i) => ( ))}
)} {camera &&
{t("bcf.camera")}: {cameraText(camera)}
} {clipping.length > 0 && (
{t("bcf.clipping")}:{" "} {clipping.map((c) => t("bcf.clipping.item", { x: f1(c.location[0]), y: f1(c.location[1]), z: f1(c.location[2]), dx: f1(c.direction[0]), dy: f1(c.direction[1]), dz: f1(c.direction[2]) })).join("; ")}
)}
{topicGuids.length > 0 ? t("bcf.components", { found: foundCount, total: topicGuids.length }) : t("bcf.components.none")}
{topicGuids.length > 0 && }
{t("bcf.comments")}
{topic.comments.map((c) => (
{c.author} · {c.date.slice(0, 16).replace("T", " ")}
{c.comment}
))}