[195b] Objekteinstellungen als natives Nebenfenster (Tauri), Spiegel-Store + Ops zurück

Unter Tauri öffnet T das Fenster „object-settings“ (wie Einstellungen/Ressourcen); Browser/Electron
behalten das schwebende Panel. Schlankste Lösung ohne Doppelspur: das Fenster lädt denselben Store als
Spiegel (Projekt per projectDelta + eigenes Kern-Dokument, Auswahl, aktive Ebene, Host-Wertfelder, Fokus
von T) und rendert unverändert ObjectSettingsPanel. Store-Änderungen rechnen dort ihre Ops auf dem Spiegel
und gehen über state/changeSink.ts ans Hauptfenster (applyChange, Undo je Änderung, coalesceKey bleibt);
Host-Handler per Proxy (remoteHost). Cmd+Z im Fenster wirkt auf den Verlauf des Hauptfensters.
Mehrfachwerte: Schraffur, Wandtyp/Dicke „gemischt“; Wandtyp gilt für alle gewählten Wände.
Nicht auf macOS gebaut/getestet (nur tsc/vitest im Linux-Container).
This commit is contained in:
Claude committed 2026-11-12 03:29:45 +00:00
1 parent 2119bbd51c
commit 2954a6d296
22 files changed
+790 -37

No files matched your search

+1
View File
@@ -63,6 +63,7 @@ const store = createStore<RootState>((api) => ({
export const useStore = store.useStore;
export const getState = store.getState;
export const setState = store.setState;
export const subscribe = store.subscribe;
// Aktive Ebene nach Projektänderungen absichern: Undo/Redo (oder jede andere Änderung) kann die
+22
View File
@@ -0,0 +1,22 @@
// [195b] Umleitung der Projekt-Änderungen eines Nebenfensters: Im nativen Fenster „Objekteinstellungen" läuft
// derselbe Store wie im Hauptfenster, aber nur als Spiegel (Leseansicht + eigenes Kern-Dokument, nachgeführt
// über die Sync-Brücke). Ist ein Abfluss gesetzt, wenden `applyChange`, `setProject`, Befehle und Griffe
// NICHTS lokal an: sie rechnen die Ops auf dem Spiegel (der dem Stand des Hauptfensters gleicht) und geben sie
// mit `coalesceKey` hierher ab; das Hauptfenster wendet sie per `applyChange` an (Prüfung, Undo je Änderung)
// und schickt den neuen Stand zurück. Im Hauptfenster ist kein Abfluss gesetzt (eine Abfrage, sonst nichts).
import type { CoreOp } from "../core/ops";
export type ChangeSink = (ops: readonly CoreOp[], coalesceKey: string | undefined) => void;
let sink: ChangeSink | null = null;
/** Abfluss setzen (`null` = wieder lokal anwenden). */
export function setChangeSink(next: ChangeSink | null): void {
sink = next;
}
/** Aktueller Abfluss oder `null` (Hauptfenster). */
export function changeSink(): ChangeSink | null {
return sink;
}
+24 -1
View File
@@ -1,7 +1,7 @@
// [195] Mehrfach-Werte: gleiche Werte → ein Wert, abweichende → leer (gemischt).
import { describe, expect, it } from "vitest";
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
import { commonValue, selectionAppearance, selectedCount } from "./mixedValues";
import { commonValue, selectionAppearance, selectionWallValues, selectedCount } from "./mixedValues";
import { EMPTY_SELECTION, mergeSelection } from "./selection";
describe("commonValue [195]", () => {
@@ -37,3 +37,26 @@ describe("selectionAppearance [195]", () => {
expect(selectedCount(sel)).toBe(1);
});
});
describe("Mehrfachwerte Füllung/Typ/Masse [195b]", () => {
const p = buildComplexSampleProject();
const [a, b] = p.walls;
const other = p.wallTypes.find((t) => t.id !== a.wallTypeId)!;
const same = { ...p, walls: p.walls.map((w) => (w.id === b.id ? { ...w, wallTypeId: a.wallTypeId } : w)) };
const sel = mergeSelection(EMPTY_SELECTION, { walls: [a.id, b.id] });
it("gleicher Wandtyp → ein Wert; anderer Typ → Typ gemischt", () => {
const v = selectionWallValues(same, sel);
expect(v.wallTypeId).toEqual({ value: a.wallTypeId, mixed: false });
expect(v.thickness.mixed).toBe(false);
const changed = { ...p, walls: p.walls.map((w) => (w.id === b.id ? { ...w, wallTypeId: other.id } : w)) };
expect(selectionWallValues(changed, sel).wallTypeId.mixed).toBe(true);
});
it("Schraffur: gleich → Wert, abweichend → gemischt", () => {
expect(selectionAppearance(same, sel).hatch.mixed).toBe(false);
const [h1, h2] = p.hatches.filter((x) => x.pattern !== "none");
const changed = { ...same, walls: same.walls.map((w) => (w.id === a.id ? { ...w, hatchId: h1.id } : w.id === b.id ? { ...w, hatchId: h2.id } : w)) };
expect(selectionAppearance(changed, sel).hatch.mixed).toBe(true);
});
});
+23 -1
View File
@@ -28,6 +28,8 @@ export interface SelectionAppearance {
count: number;
weightMm: Common<number>;
color: Common<string>;
/** [195b] Wirksame Schraffur (Ressourcen-id, "" = keine). */
hatch: Common<string>;
}
/** Zahl der gewählten Elemente (ohne Gruppen, Schnittlinien, Lage-Darstellung, Bäume). */
@@ -39,6 +41,7 @@ export function selectedCount(sel: Selection): number {
export function selectionAppearance(project: Project, sel: Selection): SelectionAppearance {
const weights: number[] = [];
const colors: string[] = [];
const hatches: string[] = [];
let n = 0;
for (const kind of STYLE_KINDS) {
for (const id of sel[kind]) {
@@ -47,7 +50,26 @@ export function selectionAppearance(project: Project, sel: Selection): Selection
if (!info) continue;
weights.push(info.weightMm);
colors.push(info.color);
hatches.push(info.effectiveHatchId ?? "");
}
}
return { count: selectedCount(sel), weightMm: commonValue(weights), color: commonValue(colors) };
return { count: selectedCount(sel), weightMm: commonValue(weights), color: commonValue(colors), hatch: commonValue(hatches) };
}
/** [195b] Wandtyp und Dicke über die gewählten Wände (Typ und Masse bei Mehrfachauswahl). */
export interface SelectionWallValues {
wallTypeId: Common<string>;
thickness: Common<number>;
}
export function selectionWallValues(project: Project, sel: Selection): SelectionWallValues {
const types: string[] = [];
const thick: number[] = [];
for (const id of sel.walls.slice(0, MAX_COMPARED)) {
const wall = deriveSelection(project, { walls: [id] })?.wall;
if (!wall) continue;
types.push(wall.wallTypeId);
thick.push(wall.thickness);
}
return { wallTypeId: commonValue(types), thickness: commonValue(thick) };
}
+7 -6
View File
@@ -1,9 +1,10 @@
// [195] Taste T (wie Archicad Cmd+T): das Fenster „Objekteinstellungen" öffnen (schwebendes Panel `object-settings`,
// folgt der Auswahl; Bereiche Objekt + Darstellung). Der passende Abschnitt des Bereichs Objekt wird aufgeklappt
// [195] Taste T (wie Archicad Cmd+T): das Fenster „Objekteinstellungen" öffnen (unter Tauri ein natives Nebenfenster,
// [195b] `native/objectSettingsWindow.ts`; sonst das schwebende Panel `object-settings`; folgt der Auswahl; Bereiche
// Objekt + Darstellung). Der passende Abschnitt des Bereichs Objekt wird aufgeklappt
// und fokussiert; ohne Auswahl die Voreinstellung des aktiven Werkzeugs (Wand/Decke: Typ des neuen Bauteils), sonst
// nichts. Die Zuordnung Auswahl → Abschnitt ist rein (`panels/objectInfo/groups.ts::objectSettingsTarget`).
import { objectSettingsTarget } from "../panels/objectInfo/groups";
import { objectSettingsTarget, type InfoGroupId } from "../panels/objectInfo/groups";
import { setSettingsArea } from "../panels/objectSettings/areaState";
import { expandAndFocusInfoGroup } from "../panels/objectInfo/infoGroupState";
import { getState } from "./appStore";
@@ -12,8 +13,8 @@ import { selectionInfoFor } from "./useSelectionInfo";
export interface ObjectSettingsDeps {
/** Aktives Werkzeug (React-State der App). */
activeTool: string;
/** Fenster Objekteinstellungen sichtbar machen (schwebend öffnen bzw. nach vorne holen). */
revealObjectSettings: () => void;
/** Fenster Objekteinstellungen sichtbar machen (öffnen bzw. nach vorne holen); `group` = aufzuklappender Abschnitt. */
revealObjectSettings: (group: InfoGroupId | null) => void;
}
/** Öffnet die Einstellungen; `false`, wenn es nichts zu öffnen gibt. */
@@ -28,7 +29,7 @@ export function openObjectSettings(deps: ObjectSettingsDeps): boolean {
if (!target) return false;
setSettingsArea("object");
if (target.group) expandAndFocusInfoGroup(target.group);
deps.revealObjectSettings();
deps.revealObjectSettings(target.group);
return true;
}
@@ -0,0 +1,28 @@
// [195b] Wandtyp bei Mehrfachauswahl: gilt für alle gewählten Wände, ein Undo-Schritt.
import { describe, expect, it } from "vitest";
import { getState, setState } from "../appStore";
import { buildComplexSampleProject } from "../../model/sampleProjectComplex";
import { EMPTY_SELECTION } from "../selection";
import { buildElementAttributesHost } from "./elementAttributesHost";
import type { FlatHostOpts } from "./types";
describe("onSetWallType [195b]", () => {
it("setzt den Typ aller gewählten Wände in einem Schritt", () => {
getState().loadProject(buildComplexSampleProject());
const [a, b] = getState().project.walls;
const target = getState().project.wallTypes.find((t) => t.id !== a.wallTypeId && t.id !== b.wallTypeId)!;
setState({ selection: { ...EMPTY_SELECTION, walls: [a.id, b.id] } });
const s = getState();
const host = buildElementAttributesHost({
applyChange: s.applyChange,
updateWall: s.updateWall,
selection: { kind: "wall", id: a.id },
} as unknown as FlatHostOpts) as { onSetWallType: (id: string) => void };
const depth = getState().undoDepth;
host.onSetWallType(target.id);
const walls = getState().project.walls;
expect(walls.find((w) => w.id === a.id)!.wallTypeId).toBe(target.id);
expect(walls.find((w) => w.id === b.id)!.wallTypeId).toBe(target.id);
expect(getState().undoDepth).toBe(depth + 1);
});
});
+7 -3
View File
@@ -3,7 +3,8 @@
// Handler wirkt nur bei passender Auswahl (`selection.kind`) und schreibt über die Projekt-Aktionen
// bzw. `applyChange`.
import { patchItem, removeRoofHole, setRoofEdge } from "../../core";
import { patchItem, patchItems, removeRoofHole, setRoofEdge } from "../../core";
import { getState } from "../appStore";
import type { FlatHostOpts, HostPart } from "./types";
export function buildElementAttributesHost(c: FlatHostOpts) {
@@ -46,8 +47,11 @@ export function buildElementAttributesHost(c: FlatHostOpts) {
if (selection?.kind === "ceiling") updateCeiling(selection.id, { edgeAtOutline: edgeAtOutline || undefined });
},
onSetWallType: (wallTypeId) => {
if (selection?.kind === "wall")
updateWall(selection.id, { wallTypeId });
if (selection?.kind !== "wall") return;
// [195b] Mehrfachauswahl: alle gewählten Wände bekommen den Typ (ein Undo-Schritt).
const ids = getState().selection.walls;
if (ids.length > 1) applyChange((p) => patchItems(p, "walls", ids, (w) => ({ ...w, wallTypeId })));
else updateWall(selection.id, { wallTypeId });
},
onSetWallThickness: (thickness) => {
if (selection?.kind === "wall")
+21 -3
View File
@@ -9,6 +9,7 @@
// RootState (siehe appStore.ts), wir greifen punktuell auf View-Felder zu.
import { applyOps } from "../core/ops";
import { changeSink } from "./changeSink";
import type { CoreOp } from "../core/ops";
import type { ProjectMutation } from "../core";
import { withDocument } from "../core";
@@ -557,12 +558,25 @@ export function createProjectSlice(
// von den paar bekannten Hochfrequenz-Aktionen (Grip-Drag & Co.) gesetzt — alle anderen Aktionen
// rufen ohne Key auf und pushen damit IMMER diskret. Das Projekt ändert sich NUR über Ops: der Kern
// prüft (NaN, doppelte ids), wendet an und zeichnet den Undo-Schritt auf ([K4] S3).
const setProject = (next: ProjectMutation, coalesceKey?: string) =>
next.coreReq ? applyCmd(next.coreReq, coalesceKey) : set((s) => commitOps(s, next.toOps(s.project), coalesceKey));
const setProject = (next: ProjectMutation, coalesceKey?: string) => {
if (forwarded(() => (next.coreReq ? storeDocument(get().project).cmdOps(next.coreReq) : next.toOps(get().project)), coalesceKey)) return;
if (next.coreReq) applyCmd(next.coreReq, coalesceKey);
else set((s) => commitOps(s, next.toOps(s.project), coalesceKey));
};
// [195b] Nebenfenster (`changeSink.ts`): Ops auf dem Spiegel rechnen und ans Hauptfenster abgeben statt anwenden.
const forwarded = (ops: () => readonly CoreOp[], coalesceKey: string | undefined): boolean => {
const sink = changeSink();
if (!sink) return false;
const list = ops();
if (list.length > 0) sink(list, coalesceKey);
return true;
};
// Befehl ([K4] S3, `commands.rs`): der Kern rechnet ihn auf dem Dokument und wendet ihn im selben
// Aufruf an (`cmdMutation`); Prüfung, Verlauf und Meldungen wie `commitOps`.
const applyCmd = (req: object, coalesceKey?: string) => {
if (forwarded(() => storeDocument(get().project).cmdOps(req), coalesceKey)) return;
let notice: string | undefined;
set((s) => {
const doc = storeDocument(s.project);
@@ -589,7 +603,10 @@ export function createProjectSlice(
const applyChange = (
ops: readonly CoreOp[] | ((p: Project) => readonly CoreOp[]),
coalesceKey?: string,
) => set((s) => commitOps(s, typeof ops === "function" ? ops(s.project) : ops, coalesceKey));
) => {
if (forwarded(() => (typeof ops === "function" ? ops(get().project) : ops), coalesceKey)) return;
set((s) => commitOps(s, typeof ops === "function" ? ops(s.project) : ops, coalesceKey));
};
// Hinweis aus dem Kern (i18n-Schlüssel) melden — derselbe höchstens alle 2 s (Griff-Zug: je Mausschritt).
let lastNotice = { key: "", at: 0 };
@@ -607,6 +624,7 @@ export function createProjectSlice(
// Griff-Änderung ([K4] S3): der Kern rechnet sie auf dem Dokument und wendet sie im selben Aufruf an
// (`grips.rs`, ein WASM-Aufruf je Mausschritt); Prüfung, Verlauf und Meldungen wie `commitOps`.
const applyGrip = (req: GripRequest, coalesceKey?: string) => {
if (forwarded(() => storeDocument(get().project).gripOps(req).ops, coalesceKey)) return;
let notice: string | undefined;
set((s) => {
const doc = storeDocument(s.project);