[185] Navigation wie Archicad: Geschosswechsel behält Zoom, Cmd+5/6 Geschoss, Cmd+3/4 Auswahl im 3D

Grundriss: Geschosse teilen den Einpass-Schlüssel (planFitKey, PlanView fitKey), Wechsel behält
Ausschnitt und Massstab exakt. Cmd/Ctrl+5/6 Geschoss tiefer/höher im Grundriss- und 3D-Reiter.
Cmd/Ctrl+3 zeigt nur die Auswahl im 3D (Reiter „3D · Auswahl“, Kamera passt ein; ohne Auswahl alles),
Cmd/Ctrl+4 blendet die Auswahl im 3D aus. Zustand rein UI (state/view3dFilter.ts). Kern:
model3d::ElementSelection im ClassFilter (only/hideIds für Teile, Cache, Pick). Kürzel umbelegbar,
natives Menü Ansicht. PlanViewHandle.pxPerMeter liest die aktuelle viewBox.
This commit is contained in:
Claude committed 2026-11-11 19:39:51 +00:00
1 parent a6c302a91d
commit 5530089eea
29 files changed
+717 -42

No files matched your search

+1
View File
@@ -66,6 +66,7 @@ in `ProjectSync`.
| `viewTemplates.ts` | Ansichtsvorlagen als Ops |
| `viewSnapshots.ts`, `viewSnapshotFolders.ts`, `viewTabs.ts` | Ausschnitte, ihre Ordner, Zeichnungs-Reiter (mit dem Projekt als `uiState.viewTabs` gesichert, [136]); Reiter-Arten und Navigations-Regeln ([182]) |
| `tabNavigation.ts` | Navigator/Grundriss-/3D-Knöpfe/Layouts wählen den passenden Reiter (`openLevel`, `switchViewType`, `openLayoutTab`, [182]) |
| `view3dFilter.ts` | 3D-Element-Filter ([185], rein UI): „Auswahl in 3D zeigen" (Cmd/Ctrl+3) und temporär ausgeblendete Elemente (Cmd/Ctrl+4); Geschoss-Kürzel Cmd/Ctrl+5/6 in `tabNavigation.ts` |
| `groupActions.ts` | Gruppen erzeugen, auflösen, betreten |
| `exportScope.ts`, `objectLock.ts` | Export „nur Auswahl"; Objekt-Sperre |
| `autosave.ts`, `projectStore.ts`, `recentProjects.ts`, `startupGuard.ts` | Autosave und Wiederherstellen, IndexedDB, zuletzt geöffnet, Start-Protokoll |
+12 -2
View File
@@ -48,7 +48,11 @@ export type ShortcutId =
| "toolCeiling"
| "toolWindow"
| "toolDoor"
| "toolRoom";
| "toolRoom"
| "floorDown"
| "floorUp"
| "showSelection3d"
| "hideSelection3d";
export type ShortcutCategory =
| "general"
@@ -57,7 +61,8 @@ export type ShortcutCategory =
| "boolean"
| "transform"
| "group"
| "tools";
| "tools"
| "navigation";
export interface ShortcutDef {
id: ShortcutId;
@@ -204,6 +209,11 @@ export const SHORTCUT_DEFS: ShortcutDef[] = [
defaultCombo: "0",
bareKeyOnly: true,
},
// [185] Navigation wie Archicad.
{ id: "floorDown", category: "navigation", labelKey: "shortcut.floorDown", defaultCombo: "mod+5" },
{ id: "floorUp", category: "navigation", labelKey: "shortcut.floorUp", defaultCombo: "mod+6" },
{ id: "showSelection3d", category: "navigation", labelKey: "shortcut.showSelection3d", defaultCombo: "mod+3" },
{ id: "hideSelection3d", category: "navigation", labelKey: "shortcut.hideSelection3d", defaultCombo: "mod+4" },
];
const DEFS_BY_ID = new Map<ShortcutId, ShortcutDef>(SHORTCUT_DEFS.map((d) => [d.id, d]));
+3
View File
@@ -72,6 +72,7 @@ import { createHistorySlice, historyPatch, labelCommit, storeDocument } from "./
import type { HistorySlice } from "./historySlice";
import { opsLabel } from "./historyLabels";
import { resetViewTabs, restoreViewTabsFromProject } from "./viewTabs";
import { resetView3dFilter } from "./view3dFilter";
import type { NotifyKind } from "./notifySlice";
/** Felder, die diese Slice in den RootState beisteuert. */
@@ -658,6 +659,7 @@ export function createProjectSlice(
doc.load(next);
set({ project: next, projectEpoch: get().projectEpoch + 1, ...historyPatch(doc) });
resetViewTabs(); // [136] neues Projekt: ein Reiter mit der aktuellen Ansicht
resetView3dFilter(); // [185] keine 3D-Element-Auswahl aus dem vorigen Projekt
},
openProjectFile: (text) => {
@@ -666,6 +668,7 @@ export function createProjectSlice(
if (r.ok) {
set({ project: r.project, projectEpoch: get().projectEpoch + 1, ...historyPatch(doc) });
restoreViewTabsFromProject(r.project); // [136] gesicherte Reiter, sonst ein Reiter
resetView3dFilter(); // [185]
}
return r;
},
+28 -2
View File
@@ -6,12 +6,15 @@ import type { ViewType } from "../model/viewTypes";
import { sheetLevelOf } from "../model/layoutModel";
import { getState } from "./appStore";
import type { ViewSnapshotState } from "./viewSnapshots";
import { getViewStateBridge, getViewTabs, navigateToLevel, setViewTabs, switchViewKind, type TabNav } from "./viewTabs";
import { getViewStateBridge, getViewTabs, navigateToLevel, setViewTabs, stepFloor, switchViewKind, type TabNav } from "./viewTabs";
import { getView3dFilter, hideSelection3d, selectionIds3d, setView3dFilter, showSelection3d } from "./view3dFilter";
import { clearKinds } from "./selection";
function run(nav: (live: ViewSnapshotState) => TabNav): void {
function run(nav: (live: ViewSnapshotState) => TabNav | null): void {
const bridge = getViewStateBridge();
if (!bridge) return;
const r = nav(bridge.live());
if (!r) return;
setViewTabs(r.next);
if (r.setLevel) {
// Gleicher Reiter: nur das Geschoss wechselt, die Art (Grundriss/3D) bleibt.
@@ -39,3 +42,26 @@ export function openLayoutTab(layoutId: string): void {
const sheet = sheetLevelOf(getState().project, layoutId);
if (sheet) openLevel(sheet.id);
}
/** [185] Cmd/Ctrl+5 (−1) bzw. Cmd/Ctrl+6 (+1): im Grundriss-/3D-Reiter ein Geschoss tiefer/höher (Zoom bleibt). */
export function stepActiveFloor(dir: 1 | -1): void {
run((live) => stepFloor(getViewTabs(), live, getState().project.drawingLevels, dir));
}
/**
* [185] Cmd/Ctrl+3 „Auswahl in 3D zeigen": mit Auswahl zeigt der 3D-Reiter nur diese (Titel „3D · Auswahl"), ohne
* Auswahl wieder alles; wechselt in den 3D-Reiter bzw. öffnet ihn, die Kamera passt sich ein.
*/
export function showSelectionIn3d(): void {
setView3dFilter(showSelection3d(getView3dFilter(), selectionIds3d(getState().selection)));
switchViewType("perspektive");
}
/** [185] Cmd/Ctrl+4: gewählte Elemente im 3D temporär ausblenden (nicht anwählbar, kein Undo-Schritt); Auswahl leeren. */
export function hideSelectionIn3d(): void {
const st = getState();
const ids = selectionIds3d(st.selection);
if (!ids.length) return;
setView3dFilter(hideSelection3d(getView3dFilter(), ids));
st.setSelection(clearKinds("walls", "ceilings", "openings", "stairs", "solids", "columns", "roofs", "contextObjects", "trees", "drawings", "groups"));
}
+28 -1
View File
@@ -5,7 +5,9 @@
import { core, coreEpoch, coreReady } from "../engine/coreWasm";
import { getState } from "./appStore";
import { storeDocument } from "./historySlice";
import { computeSection, generatePlan, generateSectionPlan } from "../core";
import { computeSection, generatePlan, generateSectionPlan, pickGeometry, projectToModel3d } from "../core";
import { getViewStateBridge } from "./viewTabs";
import { getView3dFilter, toFilter3d } from "./view3dFilter";
declare global {
interface Window {
@@ -37,6 +39,10 @@ declare global {
modelView: () => string | undefined;
/** [173] Schnitt der aktiven Ebene (1:50, Detailgrad der Anzeige): Zahl der Wand-Schnittflächen und ihre Fläche (m²). */
sectionWalls: () => Promise<{ n: number; area: number }>;
/** [185] Darstellungszustand der Plan-Ansicht: aktive Ebene, Bildmitte (Modell-m), Zoom (px/m), Massstab. */
viewCamera: () => { levelId: string; center: { x: number; y: number } | null; pxPerMeter: number | null; scale: number };
/** [185] 3D-Element-Filter (Store) und die Wand-ids des 3D-Modells bzw. der Pick-Geometrie mit ihm. */
view3d: () => { only: string[] | null; hidden: string[]; walls: string[]; pickWalls: string[] };
};
}
}
@@ -90,6 +96,27 @@ export function installTestHooks(): void {
const area = (pts: { x: number; y: number }[]) => Math.abs(pts.reduce((a, p, i) => a + p.x * pts[(i + 1) % pts.length].y - pts[(i + 1) % pts.length].x * p.y, 0)) / 2;
return { n: polys.length, area: polys.reduce((a, q) => a + (q.kind === "polygon" ? area(q.pts) : 0), 0) };
},
viewCamera: () => {
const st = getViewStateBridge()?.live();
return {
levelId: getState().activeLevelId,
center: st?.cameraCenter ?? null,
pxPerMeter: st?.cameraPxPerMeter ?? null,
scale: getState().scaleDenominator,
};
},
view3d: () => {
const f = getView3dFilter();
const p = getState().project;
const hide = toFilter3d(f, []);
const uniq = (ids: string[]) => [...new Set(ids)].sort();
return {
only: f.only,
hidden: f.hidden,
walls: uniq(projectToModel3d(p, { hide }).walls.map((w) => w.wallId)),
pickWalls: uniq(pickGeometry(p, 0, hide).walls.map((w) => w.wallId)),
};
},
selected: () => ({ drawings: [...getState().selection.drawings], groups: [...getState().selection.groups], all: JSON.stringify(getState().selection) }),
};
}
+29
View File
@@ -32,6 +32,7 @@ import {
import type { ElementClipboard, ElementSelectionIds, PastedIds } from "../editors/elementClipboard";
import { parseClipboardText, serializeClipboardText } from "../editors/elementClipboardSerialize";
import { matchesShortcut, type ShortcutId, type ShortcutOverrides } from "./keyboardShortcuts";
import { hideSelectionIn3d, showSelectionIn3d, stepActiveFloor } from "./tabNavigation";
const isEditableTarget = (e: KeyboardEvent): boolean => {
const el = e.target as HTMLElement | null;
@@ -643,3 +644,31 @@ export function useGroupShortcut(
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentSelection, selectedGroupIds, overrides]);
}
/**
* [185] Navigation wie Archicad: Cmd/Ctrl+5 Geschoss tiefer, Cmd/Ctrl+6 höher (Grundriss- und 3D-Reiter, Zoom
* bleibt), Cmd/Ctrl+3 Auswahl in 3D zeigen (ohne Auswahl: alles), Cmd/Ctrl+4 Auswahl im 3D ausblenden. Unter Tauri
* fängt das native Menü dieselben Kürzel ab (`native/appMenu.ts`).
*/
export function useViewNavigationShortcuts(overrides: ShortcutOverrides): void {
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
// Die (oft fokussierte) Befehlszeile tippt keine Cmd/Ctrl-Ziffern: dort gelten die Kürzel.
if (isEditableTarget(e) && !(e.target as HTMLElement).classList.contains("cmdline-input")) return;
const fn = matchesShortcut(e, "floorDown", overrides)
? () => stepActiveFloor(-1)
: matchesShortcut(e, "floorUp", overrides)
? () => stepActiveFloor(1)
: matchesShortcut(e, "showSelection3d", overrides)
? showSelectionIn3d
: matchesShortcut(e, "hideSelection3d", overrides)
? hideSelectionIn3d
: null;
if (!fn) return;
e.preventDefault();
fn();
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [overrides]);
}
+4
View File
@@ -17,6 +17,7 @@ import { t } from "../i18n";
import { getState, type RootState } from "./appStore";
import { openMeshFileDialog } from "./meshImportStore";
import { openPointCloudFileDialog } from "./pointCloudStore";
import { hideSelectionIn3d, showSelectionIn3d, stepActiveFloor } from "./tabNavigation";
import type { useDialogState } from "./useDialogState";
import type { useProjectFileActions } from "./useProjectFileActions";
import type { useTopBarState } from "./useTopBarState";
@@ -156,6 +157,9 @@ export function useNativeMenu(opts: {
onViewType: setViewType,
onView3d: setView3d,
onReferenceLines: setReferenceLines,
onFloorStep: stepActiveFloor,
onShowSelection3d: showSelectionIn3d,
onHideSelection3d: hideSelectionIn3d,
onToggleResources: () => toggleResources(),
onOpenSettings: () => openSettings(),
onOpenPanel: (panelId) => setLayout((l) => revealPanel(l, panelId)),
+3
View File
@@ -30,6 +30,7 @@ import {
useSelectAllAndDeleteShortcut,
useSplitJoinShortcut,
useTransformShortcuts,
useViewNavigationShortcuts,
} from "./useKeyboardShortcuts";
import { TRANSFORM_COMMANDS } from "./useToolInput";
import { getState, type RootState } from "./appStore";
@@ -304,6 +305,8 @@ export function useSelectionCommands(opts: {
applyGroupSelection,
shortcutOverrides,
);
// [185] Cmd/Ctrl+3/4/5/6: Auswahl in 3D zeigen/ausblenden, Geschoss tiefer/höher.
useViewNavigationShortcuts(shortcutOverrides);
// Doppelklick auf ein gruppiertes Element → Gruppe betreten (Isolation):
// alles ausserhalb wird gedimmt/gesperrt gerendert (s. viewportContent.tsx/
+59
View File
@@ -0,0 +1,59 @@
import { describe, expect, it } from "vitest";
import { fromIdLists, EMPTY_SELECTION, mergeSelection } from "./selection";
import {
NO_VIEW3D_FILTER,
getView3dFilter,
hideSelection3d,
isSelectionMode,
resetView3dFilter,
selectionIds3d,
setView3dFilter,
showSelection3d,
toFilter3d,
} from "./view3dFilter";
describe("3D-Element-Filter [185]", () => {
it("selectionIds3d: nur Arten, die im 3D vorkommen, ohne Doppel", () => {
const sel = mergeSelection(EMPTY_SELECTION, {
...fromIdLists({ wallIds: ["w1", "w2"], openingIds: ["o1"] }),
rooms: ["r1"],
sectionLines: ["s1"],
groups: ["g1"],
drawings: ["w1"],
});
expect(selectionIds3d(sel)).toEqual(["w1", "w2", "o1"]);
});
it("Cmd+3 mit Auswahl: nur diese, Ausgeblendetes vergessen, Kamera einpassen; ohne Auswahl: alles", () => {
const hidden = hideSelection3d(NO_VIEW3D_FILTER, ["x"]);
const a = showSelection3d(hidden, ["w1", "w1", "o1"]);
expect(a).toMatchObject({ only: ["w1", "o1"], hidden: [] });
expect(isSelectionMode(a)).toBe(true);
expect(a.fitSeq).toBe(hidden.fitSeq + 1);
const b = showSelection3d(a, []);
expect(b).toMatchObject({ only: null, hidden: [] });
expect(isSelectionMode(b)).toBe(false);
expect(b.fitSeq).toBe(a.fitSeq + 1);
});
it("Cmd+4: blendet zusätzlich aus, im Auswahl-Modus auch; ohne ids unverändert", () => {
const a = hideSelection3d(NO_VIEW3D_FILTER, ["w1"]);
expect(a).toMatchObject({ only: null, hidden: ["w1"], fitSeq: 0 });
expect(hideSelection3d(a, ["w1"])).toBe(a);
expect(hideSelection3d(a, [])).toBe(a);
const b = hideSelection3d(showSelection3d(a, ["w2", "w3"]), ["w3"]);
expect(b).toMatchObject({ only: ["w2", "w3"], hidden: ["w3"] });
});
it("toFilter3d: Klassen plus Element-Auswahl für den Kern", () => {
expect(toFilter3d(NO_VIEW3D_FILTER, ["31"])).toEqual({ hide: ["31"], only: null, hideIds: [] });
expect(toFilter3d(showSelection3d(NO_VIEW3D_FILTER, ["w1"]), [])).toEqual({ hide: [], only: ["w1"], hideIds: [] });
});
it("Store: setzen und beim Projektwechsel zurücksetzen", () => {
setView3dFilter(showSelection3d(NO_VIEW3D_FILTER, ["w1"]));
expect(isSelectionMode(getView3dFilter())).toBe(true);
resetView3dFilter();
expect(getView3dFilter()).toBe(NO_VIEW3D_FILTER);
});
});
+85
View File
@@ -0,0 +1,85 @@
// [185] Element-Filter der 3D-Ansicht wie Archicad: „Auswahl in 3D zeigen" (Cmd/Ctrl+3) zeigt nur die gewählten
// Elemente, Cmd/Ctrl+4 blendet die gewählten temporär aus; Cmd/Ctrl+3 ohne Auswahl zeigt wieder alles.
//
// Reiner UI-Zustand (nicht im Projekt, kein Op, kein Undo-Schritt), wirkt zusätzlich zum Klassen-Filter ([180]):
// der Kern blendet die Elemente in Teilen und Pick aus (`model3d::ElementSelection`, Text `{"only", "hideIds"}`).
// Ein neu geladenes Projekt beginnt ohne Filter (`resetView3dFilter`).
//
// Pure Funktionen + ein kleiner externer Store (Muster viewTabs.ts).
import { useSyncExternalStore } from "react";
import type { Filter3d } from "../core";
import type { Selection, SelectionKind } from "./selection";
export interface View3dFilter {
/** Nur diese Element-ids zeigen; `null` = alle. */
only: string[] | null;
/** Temporär ausgeblendete Element-ids. */
hidden: string[];
/** Zählt die Anfragen „Kamera auf das Gezeigte einpassen" (der 3D-Viewport passt bei jeder Änderung ein). */
fitSeq: number;
}
export const NO_VIEW3D_FILTER: View3dFilter = Object.freeze({ only: null, hidden: [], fitSeq: 0 }) as View3dFilter;
/** Element-Arten, die im 3D vorkommen (Räume, Schnittlinien, Lage-Darstellung und Gruppen nicht). */
const KINDS_3D: readonly SelectionKind[] = ["walls", "ceilings", "openings", "stairs", "solids", "columns", "roofs", "contextObjects", "trees", "drawings"];
/** Element-ids der Auswahl, die im 3D vorkommen (ohne Doppel, in Wahl-Reihenfolge). */
export function selectionIds3d(sel: Selection): string[] {
return [...new Set(KINDS_3D.flatMap((k) => sel[k]))];
}
/** Ist der Auswahl-Modus („3D · Auswahl") aktiv? */
export function isSelectionMode(f: View3dFilter): boolean {
return f.only !== null;
}
/**
* Cmd/Ctrl+3: mit Auswahl nur diese zeigen (ausgeblendete werden vergessen), ohne Auswahl alles zeigen. Beide Male
* passt der 3D-Viewport die Kamera ein.
*/
export function showSelection3d(f: View3dFilter, ids: readonly string[]): View3dFilter {
return ids.length ? { only: [...new Set(ids)], hidden: [], fitSeq: f.fitSeq + 1 } : { only: null, hidden: [], fitSeq: f.fitSeq + 1 };
}
/** Cmd/Ctrl+4: die Elemente `ids` zusätzlich ausblenden (Kamera bleibt). Ohne ids unverändert. */
export function hideSelection3d(f: View3dFilter, ids: readonly string[]): View3dFilter {
if (!ids.length) return f;
const hidden = [...new Set([...f.hidden, ...ids])];
return hidden.length === f.hidden.length ? f : { ...f, hidden };
}
/** Filter für die 3D-Abfragen: Klassen-Codes `hide` plus Element-Auswahl (Kern `ClassFilter::from_text`). */
export function toFilter3d(f: View3dFilter, hide: readonly string[]): Filter3d {
return { hide, only: f.only, hideIds: f.hidden };
}
// ── Store ───────────────────────────────────────────────────────────────────
let current: View3dFilter = NO_VIEW3D_FILTER;
const listeners = new Set<() => void>();
export function getView3dFilter(): View3dFilter {
return current;
}
export function setView3dFilter(next: View3dFilter): void {
if (next === current) return;
current = next;
for (const l of listeners) l();
}
/** Neues/geöffnetes Projekt: keine Element-Auswahl im 3D. */
export function resetView3dFilter(): void {
setView3dFilter(NO_VIEW3D_FILTER);
}
function subscribe(l: () => void): () => void {
listeners.add(l);
return () => listeners.delete(l);
}
export function useView3dFilter(): View3dFilter {
return useSyncExternalStore(subscribe, getView3dFilter, getView3dFilter);
}
+40
View File
@@ -14,6 +14,9 @@ import {
navigateToLevel,
switchViewKind,
tabKindOf,
adjacentFloorId,
planFitKey,
stepFloor,
isPlanKindActive,
openTab,
restoreViewTabs,
@@ -299,3 +302,40 @@ describe("Reiter-Arten und Navigation [182]", () => {
expect(n.apply).toMatchObject({ viewType: "grundriss", activeLevelId: "eg" });
});
});
describe("Geschoss-Navigation wie Archicad [185]", () => {
// Liste absichtlich nicht nach Höhe sortiert: UG unten, DG oben.
const levels = [
{ id: "eg", kind: "floor" as const, baseElevation: 0 },
{ id: "sec", kind: "section" as const },
{ id: "dg", kind: "floor" as const, baseElevation: 6 },
{ id: "og", kind: "floor" as const, baseElevation: 3 },
{ id: "ug", kind: "floor" as const, baseElevation: -3 },
];
const live = (activeLevelId: string, viewType: "grundriss" | "perspektive" = "grundriss"): ViewSnapshotState =>
({ ...st(activeLevelId), viewType, cameraCenter: { x: 1, y: 2 }, cameraPxPerMeter: 40 }) as ViewSnapshotState;
it("adjacentFloorId: nach Höhe, am Rand null, Nicht-Geschoss null", () => {
expect(adjacentFloorId(levels, "eg", 1)).toBe("og");
expect(adjacentFloorId(levels, "og", 1)).toBe("dg");
expect(adjacentFloorId(levels, "dg", 1)).toBeNull();
expect(adjacentFloorId(levels, "eg", -1)).toBe("ug");
expect(adjacentFloorId(levels, "ug", -1)).toBeNull();
expect(adjacentFloorId(levels, "sec", 1)).toBeNull();
});
it("stepFloor: Grundriss und 3D bleiben im Reiter, Schnitt tut nichts", () => {
const s = initialTabs();
expect(stepFloor(s, live("eg"), levels, 1)).toEqual({ next: s, apply: null, setLevel: "og" });
expect(stepFloor(s, live("eg", "perspektive"), levels, -1)).toEqual({ next: s, apply: null, setLevel: "ug" });
expect(stepFloor(s, live("dg"), levels, 1)).toBeNull();
expect(stepFloor(s, live("sec"), levels, 1)).toBeNull();
});
it("planFitKey: Geschosse teilen den Schlüssel (Zoom bleibt), andere Ebenen und neues Projekt passen ein", () => {
expect(planFitKey(levels[0], 1)).toBe(planFitKey(levels[3], 1));
expect(planFitKey(levels[0], 1)).not.toBe(planFitKey(levels[0], 2));
expect(planFitKey(levels[1], 1)).not.toBe(planFitKey(levels[0], 1));
expect(planFitKey({ id: "x", kind: "drawing" }, 1)).not.toBe(planFitKey({ id: "y", kind: "drawing" }, 1));
});
});
+46
View File
@@ -223,6 +223,52 @@ export function switchViewKind(
return openNew(stored, noCamera({ ...live, viewType: want, activeLevelId: levelId }));
}
/**
* [185] Nächstes Geschoss über (`dir` = +1, Cmd/Ctrl+6) bzw. unter (−1, Cmd/Ctrl+5) dem aktiven, nach Höhe
* (`baseElevation`, gleich hoch: Reihenfolge der Liste). `null` am obersten/untersten Geschoss oder wenn die aktive
* Ebene kein Geschoss ist.
*/
export function adjacentFloorId(
levels: readonly Pick<DrawingLevel, "id" | "kind" | "baseElevation">[],
activeId: string,
dir: 1 | -1,
): string | null {
const floors = levels
.map((l, i) => ({ l, i }))
.filter(({ l }) => l.kind === "floor")
.sort((a, b) => (a.l.baseElevation ?? 0) - (b.l.baseElevation ?? 0) || a.i - b.i)
.map(({ l }) => l.id);
const at = floors.indexOf(activeId);
if (at < 0) return null;
return floors[at + dir] ?? null;
}
/**
* [185] Cmd/Ctrl+5 (`dir` −1) bzw. Cmd/Ctrl+6 (+1): im Grundriss- oder 3D-Reiter ein Geschoss tiefer/höher, im
* selben Reiter (Art, Zoom und Ausschnitt bleiben). Sonst (Schnitt, Ansicht, Zeichnung; oberstes/unterstes
* Geschoss) `null`.
*/
export function stepFloor(
s: ViewTabsState,
live: ViewSnapshotState,
levels: readonly Pick<DrawingLevel, "id" | "kind" | "baseElevation">[],
dir: 1 | -1,
): TabNav | null {
const kind = tabKindOf(live, levels);
if (kind !== "plan" && kind !== "3d") return null;
const id = adjacentFloorId(levels, live.activeLevelId, dir);
return id ? navigateToLevel(s, live, levels, id) : null;
}
/**
* [185] Schlüssel, bei dessen Wechsel die Plan-Ansicht neu einpasst. Geschosse teilen sich einen: der Wechsel in ein
* anderes Geschoss im selben Reiter behält Zoom und Ausschnitt exakt (wie Archicad); Schnitt, Ansicht, Zeichnung und
* ein neu geladenes Projekt (`epoch`) passen ein.
*/
export function planFitKey(level: Pick<DrawingLevel, "id" | "kind">, epoch: number): string {
return `${level.kind === "floor" ? "floors" : `level:${level.id}`}#${epoch}`;
}
/** Verbindet den aktiven Reiter mit einem Ausschnitt (Klick im Panel / Speichern). */
export function linkActiveTab(s: ViewTabsState, snapshotId: string): ViewTabsState {
return {