[130] Merge: Auswahl als ein Selection-Objekt statt 12 Felder (−728 Zeilen)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
29 files changed
+741
-1469
No files matched your search
@@ -59,8 +59,8 @@ describe("KI-Zugriff (App-Host)", () => {
|
||||
const wall = sampleProject.walls[0];
|
||||
const room = sampleProject.rooms![0];
|
||||
expect((await handleAiCall("select", { ids: [wall.id, room.id, "gibtsnicht"] })).isError).toBe(false);
|
||||
expect(getState().selectedWallIds).toEqual([wall.id]);
|
||||
expect(getState().selectedRoomIds).toEqual([room.id]);
|
||||
expect(getState().selection.walls).toEqual([wall.id]);
|
||||
expect(getState().selection.rooms).toEqual([room.id]);
|
||||
expect(JSON.parse(text(await handleAiCall("get_selection", {})))).toMatchObject({ walls: [wall.id], rooms: [room.id] });
|
||||
let fitted: { x: number; y: number }[] = [];
|
||||
setAiView({ fitBounds: (pts) => (fitted = pts) });
|
||||
|
||||
+20
-31
@@ -11,6 +11,7 @@ import { connectAiBridge, type AiBridgeStatus } from "../net/aiBridge";
|
||||
import { buildPlanPdf } from "../export/exportPdf";
|
||||
import { saveBinaryFile, saveTextFile } from "../native/saveFile";
|
||||
import { getState, setState } from "./appStore";
|
||||
import type { Selection, SelectionKind } from "./selection";
|
||||
|
||||
export interface AiLogEntry {
|
||||
at: number;
|
||||
@@ -103,32 +104,18 @@ export function setAiView(v: { fitBounds(pts: Vec2[]): void } | null): void {
|
||||
|
||||
// ── Host über den Store ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
type SelSetter = keyof Pick<
|
||||
ReturnType<typeof getState>,
|
||||
| "setSelectedWallIds"
|
||||
| "setSelectedDrawingIds"
|
||||
| "setSelectedCeilingIds"
|
||||
| "setSelectedOpeningIds"
|
||||
| "setSelectedStairIds"
|
||||
| "setSelectedRoomIds"
|
||||
| "setSelectedExtrudedSolidIds"
|
||||
| "setSelectedColumnIds"
|
||||
| "setSelectedRoofIds"
|
||||
| "setSelectedContextObjectIds"
|
||||
>;
|
||||
|
||||
/** Liste des Projekts → Auswahl-Kanal (Lesen, Setzen). */
|
||||
const CHANNELS: [keyof Project, string, SelSetter][] = [
|
||||
["walls", "selectedWallIds", "setSelectedWallIds"],
|
||||
["drawings2d", "selectedDrawingIds", "setSelectedDrawingIds"],
|
||||
["ceilings", "selectedCeilingIds", "setSelectedCeilingIds"],
|
||||
["openings", "selectedOpeningIds", "setSelectedOpeningIds"],
|
||||
["stairs", "selectedStairIds", "setSelectedStairIds"],
|
||||
["rooms", "selectedRoomIds", "setSelectedRoomIds"],
|
||||
["extrudedSolids", "selectedExtrudedSolidIds", "setSelectedExtrudedSolidIds"],
|
||||
["columns", "selectedColumnIds", "setSelectedColumnIds"],
|
||||
["roofs", "selectedRoofIds", "setSelectedRoofIds"],
|
||||
["context", "selectedContextObjectIds", "setSelectedContextObjectIds"],
|
||||
/** Liste des Projekts → Auswahl-Art. */
|
||||
const CHANNELS: [keyof Project, SelectionKind][] = [
|
||||
["walls", "walls"],
|
||||
["drawings2d", "drawings"],
|
||||
["ceilings", "ceilings"],
|
||||
["openings", "openings"],
|
||||
["stairs", "stairs"],
|
||||
["rooms", "rooms"],
|
||||
["extrudedSolids", "solids"],
|
||||
["columns", "columns"],
|
||||
["roofs", "roofs"],
|
||||
["context", "contextObjects"],
|
||||
];
|
||||
|
||||
type Ent = Record<string, unknown> & { id?: string };
|
||||
@@ -172,18 +159,20 @@ export const appHost: AiHost = {
|
||||
return getState().project === before ? "vom Kern abgelehnt" : null;
|
||||
},
|
||||
selection: () => {
|
||||
const s = getState() as unknown as Record<string, string[]>;
|
||||
return Object.fromEntries(CHANNELS.map(([k, sel]) => [k, s[sel] ?? []]).filter(([, ids]) => ids.length > 0));
|
||||
const sel = getState().selection;
|
||||
return Object.fromEntries(CHANNELS.map(([k, kind]) => [k, sel[kind]]).filter(([, ids]) => ids.length > 0));
|
||||
},
|
||||
select: (ids: string[]) => {
|
||||
const s = getState();
|
||||
const p = s.project;
|
||||
s.clearSelection();
|
||||
for (const [k, , set] of CHANNELS) {
|
||||
const patch: Partial<Selection> = {};
|
||||
for (const [k, kind] of CHANNELS) {
|
||||
const have = new Set(listOf(p, k).map((e) => e.id));
|
||||
const mine = ids.filter((id) => have.has(id));
|
||||
if (mine.length) s[set](mine);
|
||||
if (mine.length) patch[kind] = mine;
|
||||
}
|
||||
s.clearSelection();
|
||||
s.setSelection(patch);
|
||||
},
|
||||
zoomTo: (ids: string[]) => {
|
||||
const p = getState().project;
|
||||
|
||||
@@ -32,7 +32,7 @@ describe("deriveSelection — Kontext-Objekt", () => {
|
||||
},
|
||||
],
|
||||
} as unknown as Project;
|
||||
const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "CTX1");
|
||||
const sel = deriveSelection(project, { contextObjects: ["CTX1"] });
|
||||
expect(sel?.kind).toBe("contextObject");
|
||||
expect(sel?.id).toBe("CTX1");
|
||||
expect(sel?.bbox).toEqual({ minX: 0, minY: 0, maxX: 10, maxY: 6 });
|
||||
@@ -54,7 +54,7 @@ describe("deriveSelection — Kontext-Objekt", () => {
|
||||
},
|
||||
],
|
||||
} as unknown as Project;
|
||||
const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "CTX1");
|
||||
const sel = deriveSelection(project, { contextObjects: ["CTX1"] });
|
||||
// Bbox-Mittelpunkt (50,25) -> LV95 = origin + Mittelpunkt (origin = lv95 - model = lv95, model (0,0)).
|
||||
expect(sel?.contextObject?.lv95Center).toEqual({ e: 2600050, n: 1200025 });
|
||||
});
|
||||
@@ -73,7 +73,7 @@ describe("deriveSelection — Kontext-Objekt", () => {
|
||||
},
|
||||
],
|
||||
} as unknown as Project;
|
||||
const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "CTX1");
|
||||
const sel = deriveSelection(project, { contextObjects: ["CTX1"] });
|
||||
// Der Modellpunkt (500,300) IST der Anker -> muss exakt auf lv95 (2600000,1200000) zurückrechnen.
|
||||
expect(sel?.contextObject?.lv95Center).toEqual({ e: 2600000, n: 1200000 });
|
||||
});
|
||||
@@ -92,18 +92,18 @@ describe("deriveSelection — Kontext-Objekt", () => {
|
||||
},
|
||||
],
|
||||
} as unknown as Project;
|
||||
const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "CS1");
|
||||
const sel = deriveSelection(project, { contextObjects: ["CS1"] });
|
||||
expect(sel?.contextObject?.objType).toBe("contourSet");
|
||||
expect(sel?.bbox).toEqual({ minX: -5, minY: -3, maxX: 8, maxY: 2 });
|
||||
});
|
||||
|
||||
it("unbekannte Id -> null", () => {
|
||||
const project = { ...baseProject, context: [] } as unknown as Project;
|
||||
expect(deriveSelection(project, [], null, null, null, null, null, null, null, null, "does-not-exist")).toBeNull();
|
||||
expect(deriveSelection(project, { contextObjects: ["does-not-exist"] })).toBeNull();
|
||||
});
|
||||
|
||||
it("keine Kontext-Auswahl (null) -> fällt durch zu anderen Kanälen (hier auch leer -> null)", () => {
|
||||
const project = { ...baseProject, context: [] } as unknown as Project;
|
||||
expect(deriveSelection(project, [], null)).toBeNull();
|
||||
expect(deriveSelection(project, {})).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -53,7 +53,7 @@ function bench(n: number, fn: (i: number) => void, rounds = 3): number {
|
||||
}
|
||||
|
||||
const sel = (p: Project, k: { wall?: string; drawing?: string; roof?: string }) =>
|
||||
deriveSelection(p, k.wall ? [k.wall] : [], k.drawing ?? null, null, null, null, null, null, null, k.roof ?? null);
|
||||
deriveSelection(p, { walls: k.wall ? [k.wall] : [], drawings: k.drawing ? [k.drawing] : [], roofs: k.roof ? [k.roof] : [] });
|
||||
|
||||
describe("Messung Objekt-Info und Griffe, 3000 Wände + 20 000 Zeichnungen", () => {
|
||||
it("Objekt-Info, Griff-Schritte, Polylinien-Punkttyp", { timeout: 120000 }, () => {
|
||||
|
||||
@@ -11,6 +11,7 @@ import { applyOps } from "../core/ops";
|
||||
import type { CoreOp } from "../core/ops";
|
||||
import { useProjectActions } from "./useProjectActions";
|
||||
import { usePanelHostBase } from "./usePanelHostBase";
|
||||
import { EMPTY_SELECTION } from "./selection";
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
function capture<T>(f: () => T): T {
|
||||
@@ -126,7 +127,7 @@ function host(h: ReturnType<typeof holder>, selection: any) {
|
||||
viewType: "grundriss",
|
||||
selection,
|
||||
projectActions: stubObj({ snapshotLayerVisibility: () => ({}), snapshotDrawingVisibility: () => ({}), applyLayerVisibility: () => {}, applyDrawingVisibility: () => {} }),
|
||||
selectionState: stubObj({ selectedContextObjectIds: [] }),
|
||||
selectionState: stubObj({ selection: EMPTY_SELECTION }),
|
||||
toolState: stubObj({}),
|
||||
topBarState: stubObj({}),
|
||||
dialogState: stubObj({ setActiveLayoutId: () => {} }),
|
||||
|
||||
@@ -37,7 +37,7 @@ const project = {
|
||||
|
||||
describe("deriveSelection — Dach", () => {
|
||||
it("liefert eine Roof-Selection mit Form + abgeleiteten Werten", () => {
|
||||
const sel = deriveSelection(project, [], null, null, null, null, null, null, null, "RF1");
|
||||
const sel = deriveSelection(project, { roofs: ["RF1"] });
|
||||
expect(sel?.kind).toBe("roof");
|
||||
expect(sel?.roof?.shape).toBe("sattel");
|
||||
expect(sel?.roof?.pitchDeg).toBe(45);
|
||||
@@ -49,6 +49,6 @@ describe("deriveSelection — Dach", () => {
|
||||
});
|
||||
|
||||
it("ohne Dach-Auswahl kein Roof (null bei leerer Auswahl)", () => {
|
||||
expect(deriveSelection(project, [], null)).toBeNull();
|
||||
expect(deriveSelection(project, {})).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,115 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
EMPTY_SELECTION,
|
||||
clearKinds,
|
||||
emptySelection,
|
||||
fromIdLists,
|
||||
fromIds,
|
||||
hasTransformable,
|
||||
isEmpty,
|
||||
mergeSelection,
|
||||
primaryKind,
|
||||
single,
|
||||
toCommandSelection,
|
||||
toIdLists,
|
||||
toTransformSelection,
|
||||
} from "./selection";
|
||||
import { hasTransformSelection } from "../tools/transform";
|
||||
|
||||
describe("Selection", () => {
|
||||
it("leer: alle Arten leer, geteilt und eingefroren", () => {
|
||||
expect(emptySelection()).toBe(EMPTY_SELECTION);
|
||||
expect(isEmpty(EMPTY_SELECTION)).toBe(true);
|
||||
expect(primaryKind(EMPTY_SELECTION)).toBeNull();
|
||||
expect(() => (EMPTY_SELECTION.walls as string[]).push("x")).toThrow();
|
||||
});
|
||||
|
||||
it("fromIds / single / primaryKind", () => {
|
||||
const s = fromIds("walls", ["w1"]);
|
||||
expect(s.walls).toEqual(["w1"]);
|
||||
expect(s.drawings).toBe(EMPTY_SELECTION.drawings);
|
||||
expect(single(s, "walls")).toBe("w1");
|
||||
expect(single(fromIds("walls", ["a", "b"]), "walls")).toBeNull();
|
||||
expect(primaryKind(s)).toBe("walls");
|
||||
// 2D-Elemente haben Vorrang (wie die Objekt-Info)
|
||||
expect(primaryKind(mergeSelection(s, { drawings: ["d"] }))).toBe("drawings");
|
||||
});
|
||||
|
||||
it("isEmpty ohne Gruppen", () => {
|
||||
const g = fromIds("groups", ["g1"]);
|
||||
expect(isEmpty(g)).toBe(false);
|
||||
expect(isEmpty(g, { withGroups: false })).toBe(true);
|
||||
});
|
||||
|
||||
it("mergeSelection hält Referenzen stabil", () => {
|
||||
const a = fromIds("walls", ["w1", "w2"]);
|
||||
expect(mergeSelection(a, {})).toBe(a);
|
||||
expect(mergeSelection(a, { walls: ["w1", "w2"] })).toBe(a);
|
||||
expect(mergeSelection(a, { drawings: [] })).toBe(a);
|
||||
const b = mergeSelection(a, { ceilings: ["c"] });
|
||||
expect(b).not.toBe(a);
|
||||
expect(b.walls).toBe(a.walls);
|
||||
expect(b.ceilings).toEqual(["c"]);
|
||||
const c = mergeSelection(b, { ceilings: [] });
|
||||
expect(c.ceilings).toBe(EMPTY_SELECTION.ceilings);
|
||||
// Reihenfolge zählt
|
||||
expect(mergeSelection(a, { walls: ["w2", "w1"] }).walls).toEqual(["w2", "w1"]);
|
||||
});
|
||||
|
||||
it("clearKinds leert Element-Arten, Gruppen bleiben", () => {
|
||||
const s = mergeSelection(EMPTY_SELECTION, { walls: ["w"], groups: ["g"], sectionLines: ["l"] });
|
||||
const t = mergeSelection(s, clearKinds());
|
||||
expect(t.walls).toEqual([]);
|
||||
expect(t.sectionLines).toEqual([]);
|
||||
expect(t.groups).toEqual(["g"]);
|
||||
expect(mergeSelection(s, clearKinds("walls")).sectionLines).toEqual(["l"]);
|
||||
});
|
||||
|
||||
it("toCommandSelection / toTransformSelection: Einzel-Körper/Stütze nur bei genau einem", () => {
|
||||
const s = mergeSelection(EMPTY_SELECTION, {
|
||||
walls: ["w"],
|
||||
drawings: ["d"],
|
||||
solids: ["x1", "x2"],
|
||||
columns: ["c"],
|
||||
roofs: ["r"],
|
||||
});
|
||||
const c = toCommandSelection(s);
|
||||
expect(c).toEqual({
|
||||
wallIds: ["w"],
|
||||
drawingId: "d",
|
||||
drawingIds: ["d"],
|
||||
extrudedSolidId: null,
|
||||
columnId: "c",
|
||||
ceilingIds: [],
|
||||
roofIds: ["r"],
|
||||
stairIds: [],
|
||||
roomIds: [],
|
||||
});
|
||||
expect(toTransformSelection(s)).toEqual(c);
|
||||
});
|
||||
|
||||
it("hasTransformable = hasTransformSelection des Befehlskontexts", () => {
|
||||
const cases = [
|
||||
EMPTY_SELECTION,
|
||||
fromIds("walls", ["w"]),
|
||||
fromIds("drawings", ["a", "b"]),
|
||||
fromIds("solids", ["x"]),
|
||||
fromIds("solids", ["x", "y"]),
|
||||
fromIds("columns", ["c"]),
|
||||
fromIds("openings", ["o"]),
|
||||
fromIds("contextObjects", ["k"]),
|
||||
fromIds("rooms", ["r"]),
|
||||
];
|
||||
for (const s of cases) expect(hasTransformable(s)).toBe(hasTransformSelection(toCommandSelection(s)));
|
||||
});
|
||||
|
||||
it("toIdLists / fromIdLists", () => {
|
||||
const s = mergeSelection(EMPTY_SELECTION, { walls: ["w"], solids: ["x"], groups: ["g"] });
|
||||
const l = toIdLists(s);
|
||||
expect(l.wallIds).toBe(s.walls);
|
||||
expect(l.extrudedSolidIds).toEqual(["x"]);
|
||||
expect(l.groupIds).toEqual(["g"]);
|
||||
expect(fromIdLists({ wallIds: ["a"], roofIds: [] })).toEqual({ walls: ["a"], roofs: [] });
|
||||
expect(mergeSelection(EMPTY_SELECTION, fromIdLists(l))).toEqual(s);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,216 @@
|
||||
// Auswahl als EIN Wert ([130]): je Element-Art eine Menge von IDs. Ersetzt die
|
||||
// früheren zwölf `selected…Ids`-Felder im Store; alle Leser/Schreiber gehen über
|
||||
// diesen Typ und die Helfer hier (Abbildung auf Befehls-/Transformations-Auswahl,
|
||||
// Gruppen-Mitgliedschaft, BCF).
|
||||
//
|
||||
// Referenz-Stabilität ([121]): `mergeSelection` behält unveränderte Arrays (gleicher
|
||||
// Inhalt → alte Referenz) und liefert bei gar keiner Änderung das alte Objekt — so
|
||||
// rendern Komponenten, die `useStore(s => s.selection.walls)` lesen, nur bei echter
|
||||
// Änderung ihrer Art neu.
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch.
|
||||
|
||||
import type { CommandSelection } from "../commands/types";
|
||||
import type { TransformSelection } from "../tools/transform";
|
||||
import type { GroupMembership } from "../core";
|
||||
|
||||
/** Gewählte Elemente, je Art eine Menge (Reihenfolge = Wahl-Reihenfolge). */
|
||||
export interface Selection {
|
||||
walls: string[];
|
||||
/** 2D-Zeichenelemente. */
|
||||
drawings: string[];
|
||||
ceilings: string[];
|
||||
/** Fenster/Türen. */
|
||||
openings: string[];
|
||||
stairs: string[];
|
||||
rooms: string[];
|
||||
/** Extrudierte Körper (truck). */
|
||||
solids: string[];
|
||||
columns: string[];
|
||||
roofs: string[];
|
||||
/** Kontext-Objekte (importierte Gebäude/Terrain). */
|
||||
contextObjects: string[];
|
||||
/** Schnitt-/Ansichtslinien (DrawingLevel-Ids). */
|
||||
sectionLines: string[];
|
||||
/**
|
||||
* Gewählte Gruppen — rein informativ (Bounding-Box, Doppelklick-Ziel); die
|
||||
* Mitglieder stehen zusätzlich in den übrigen Arten (s. `groupActions.ts`).
|
||||
*/
|
||||
groups: string[];
|
||||
}
|
||||
|
||||
export type SelectionKind = keyof Selection;
|
||||
|
||||
/** Alle Arten; Reihenfolge = Vorrang für `primaryKind` (2D vor Wand, wie die Objekt-Info). */
|
||||
export const SELECTION_KINDS: readonly SelectionKind[] = [
|
||||
"drawings",
|
||||
"walls",
|
||||
"ceilings",
|
||||
"openings",
|
||||
"stairs",
|
||||
"rooms",
|
||||
"solids",
|
||||
"columns",
|
||||
"roofs",
|
||||
"contextObjects",
|
||||
"sectionLines",
|
||||
"groups",
|
||||
];
|
||||
|
||||
/** Alle Element-Arten ohne die Gruppen (die nur Begleit-Information sind). */
|
||||
export const ELEMENT_KINDS: readonly SelectionKind[] = SELECTION_KINDS.filter((k) => k !== "groups");
|
||||
|
||||
const NONE: string[] = Object.freeze([]) as unknown as string[];
|
||||
|
||||
/** Die leere Auswahl (geteilt, eingefroren — nie verändern). */
|
||||
export const EMPTY_SELECTION: Selection = Object.freeze(
|
||||
Object.fromEntries(SELECTION_KINDS.map((k) => [k, NONE])) as unknown as Selection,
|
||||
);
|
||||
|
||||
export function emptySelection(): Selection {
|
||||
return EMPTY_SELECTION;
|
||||
}
|
||||
|
||||
/** Nichts gewählt? `withGroups: false` ignoriert die (informativen) Gruppen. */
|
||||
export function isEmpty(sel: Selection, opts: { withGroups?: boolean } = {}): boolean {
|
||||
const kinds = opts.withGroups === false ? ELEMENT_KINDS : SELECTION_KINDS;
|
||||
return kinds.every((k) => sel[k].length === 0);
|
||||
}
|
||||
|
||||
/** Das eine gewählte Element einer Art (nur bei genau einem), sonst null. */
|
||||
export function single(sel: Selection, kind: SelectionKind): string | null {
|
||||
const ids = sel[kind];
|
||||
return ids.length === 1 ? ids[0] : null;
|
||||
}
|
||||
|
||||
/** Auswahl, die nur `ids` der Art `kind` enthält. */
|
||||
export function fromIds(kind: SelectionKind, ids: readonly string[]): Selection {
|
||||
return mergeSelection(EMPTY_SELECTION, { [kind]: [...ids] });
|
||||
}
|
||||
|
||||
/** Erste nicht-leere Art nach Vorrang (`SELECTION_KINDS`), null bei leerer Auswahl. */
|
||||
export function primaryKind(sel: Selection): SelectionKind | null {
|
||||
return SELECTION_KINDS.find((k) => sel[k].length > 0) ?? null;
|
||||
}
|
||||
|
||||
/** Patch, der die genannten Arten leert — ohne Angabe alle Element-Arten (Gruppen bleiben). */
|
||||
export function clearKinds(...kinds: SelectionKind[]): Partial<Selection> {
|
||||
const out: Partial<Selection> = {};
|
||||
for (const k of kinds.length ? kinds : ELEMENT_KINDS) out[k] = NONE;
|
||||
return out;
|
||||
}
|
||||
|
||||
const sameIds = (a: readonly string[], b: readonly string[]) =>
|
||||
a === b || (a.length === b.length && a.every((x, i) => x === b[i]));
|
||||
|
||||
/**
|
||||
* Führt einen Teil-Patch in die Auswahl ein. Arten mit gleichem Inhalt behalten
|
||||
* ihre alte Referenz, leere Arten die geteilte leere; ohne Änderung kommt `prev`
|
||||
* selbst zurück.
|
||||
*/
|
||||
export function mergeSelection(prev: Selection, patch: Partial<Selection>): Selection {
|
||||
let next: Selection | null = null;
|
||||
for (const k of SELECTION_KINDS) {
|
||||
const ids = patch[k];
|
||||
if (ids === undefined || sameIds(prev[k], ids)) continue;
|
||||
next ??= { ...prev };
|
||||
next[k] = ids.length === 0 ? NONE : ids;
|
||||
}
|
||||
return next ?? prev;
|
||||
}
|
||||
|
||||
/** Auswahl → Befehlskontext (Einzel-Körper/-Stütze nur bei genau einem Element, wie bisher). */
|
||||
export function toCommandSelection(sel: Selection): CommandSelection {
|
||||
return {
|
||||
wallIds: sel.walls,
|
||||
drawingId: single(sel, "drawings"),
|
||||
drawingIds: sel.drawings,
|
||||
extrudedSolidId: single(sel, "solids"),
|
||||
columnId: single(sel, "columns"),
|
||||
ceilingIds: sel.ceilings,
|
||||
roofIds: sel.roofs,
|
||||
stairIds: sel.stairs,
|
||||
roomIds: sel.rooms,
|
||||
};
|
||||
}
|
||||
|
||||
/** Auswahl → Transformations-Auswahl (gleiche Form wie der Befehlskontext). */
|
||||
export function toTransformSelection(sel: Selection): TransformSelection {
|
||||
return toCommandSelection(sel);
|
||||
}
|
||||
|
||||
/** Hat die Auswahl etwas Transformierbares (wie `hasTransformSelection` auf dem Befehlskontext)? */
|
||||
export function hasTransformable(sel: Selection): boolean {
|
||||
return (
|
||||
sel.walls.length > 0 ||
|
||||
sel.drawings.length > 0 ||
|
||||
single(sel, "solids") !== null ||
|
||||
single(sel, "columns") !== null ||
|
||||
sel.ceilings.length > 0 ||
|
||||
sel.roofs.length > 0 ||
|
||||
sel.stairs.length > 0 ||
|
||||
sel.rooms.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
/** Auswahl in der `…Ids`-Form (Gruppen-Mitgliedschaft, BCF, Sperr-Filter, Wahl-Speicher). */
|
||||
export interface SelectionIdLists {
|
||||
wallIds: string[];
|
||||
drawingIds: string[];
|
||||
ceilingIds: string[];
|
||||
openingIds: string[];
|
||||
stairIds: string[];
|
||||
roomIds: string[];
|
||||
extrudedSolidIds: string[];
|
||||
columnIds: string[];
|
||||
roofIds: string[];
|
||||
contextObjectIds: string[];
|
||||
sectionLineIds: string[];
|
||||
groupIds: string[];
|
||||
}
|
||||
|
||||
const ID_LIST_KEYS: [SelectionKind, keyof SelectionIdLists][] = [
|
||||
["walls", "wallIds"],
|
||||
["drawings", "drawingIds"],
|
||||
["ceilings", "ceilingIds"],
|
||||
["openings", "openingIds"],
|
||||
["stairs", "stairIds"],
|
||||
["rooms", "roomIds"],
|
||||
["solids", "extrudedSolidIds"],
|
||||
["columns", "columnIds"],
|
||||
["roofs", "roofIds"],
|
||||
["contextObjects", "contextObjectIds"],
|
||||
["sectionLines", "sectionLineIds"],
|
||||
["groups", "groupIds"],
|
||||
];
|
||||
|
||||
/** Auswahl → `…Ids`-Listen (passt strukturell auf `GroupMembership` und `BcfSelection`). */
|
||||
export function toIdLists(sel: Selection): SelectionIdLists {
|
||||
const out = {} as SelectionIdLists;
|
||||
for (const [k, key] of ID_LIST_KEYS) out[key] = sel[k];
|
||||
return out;
|
||||
}
|
||||
|
||||
/** `…Ids`-Listen (auch nur teilweise, z. B. `GroupMembership`) → Auswahl-Patch der vorhandenen Arten. */
|
||||
export function fromIdLists(lists: Partial<SelectionIdLists>): Partial<Selection> {
|
||||
const out: Partial<Selection> = {};
|
||||
for (const [k, key] of ID_LIST_KEYS) {
|
||||
const ids = lists[key];
|
||||
if (ids) out[k] = ids;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Auswahl → Gruppen-Mitgliedschaft (die acht gruppierbaren Arten). */
|
||||
export function toMembership(sel: Selection): GroupMembership {
|
||||
return {
|
||||
wallIds: sel.walls,
|
||||
drawingIds: sel.drawings,
|
||||
ceilingIds: sel.ceilings,
|
||||
roomIds: sel.rooms,
|
||||
stairIds: sel.stairs,
|
||||
columnIds: sel.columns,
|
||||
roofIds: sel.roofs,
|
||||
openingIds: sel.openings,
|
||||
};
|
||||
}
|
||||
@@ -45,7 +45,7 @@ describe("deriveSelection — Kontext-Objekt-Luftbild (ContextImage)", () => {
|
||||
filters: { saturation: 0.5, brightness: 1.1, contrast: 1, grayscale: 0.2 },
|
||||
},
|
||||
]);
|
||||
const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "IMG1");
|
||||
const sel = deriveSelection(project, { contextObjects: ["IMG1"] });
|
||||
expect(sel?.kind).toBe("contextObject");
|
||||
expect(sel?.isImage).toBe(true);
|
||||
expect(sel?.opacity).toBe(0.8);
|
||||
@@ -56,7 +56,7 @@ describe("deriveSelection — Kontext-Objekt-Luftbild (ContextImage)", () => {
|
||||
const project = projectWith([
|
||||
{ id: "IMG1", type: "image", name: "Luftbild", src: "x", min: { x: 0, y: 0 }, max: { x: 1, y: 1 } },
|
||||
]);
|
||||
const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "IMG1");
|
||||
const sel = deriveSelection(project, { contextObjects: ["IMG1"] });
|
||||
expect(sel?.opacity).toBe(1);
|
||||
expect(sel?.imageFilters).toBeUndefined();
|
||||
});
|
||||
@@ -65,7 +65,7 @@ describe("deriveSelection — Kontext-Objekt-Luftbild (ContextImage)", () => {
|
||||
const project = projectWith([
|
||||
{ id: "M1", type: "importedMesh", name: "Haus", positions: [0, 0, 0, 1, 0, 0, 0, 1, 0], indices: [0, 1, 2] },
|
||||
]);
|
||||
const sel = deriveSelection(project, [], null, null, null, null, null, null, null, null, "M1");
|
||||
const sel = deriveSelection(project, { contextObjects: ["M1"] });
|
||||
expect(sel?.isImage).toBeFalsy();
|
||||
expect(sel?.opacity).toBeUndefined();
|
||||
expect(sel?.imageFilters).toBeUndefined();
|
||||
|
||||
@@ -11,7 +11,7 @@ describe("deriveSelection (Kern)", () => {
|
||||
it("Wand: Typ-Liste, Geschosse, Länge, Volumen und UK/OK", () => {
|
||||
const p = base();
|
||||
const w = p.walls[0];
|
||||
const sel = deriveSelection(p, [w.id], null)!;
|
||||
const sel = deriveSelection(p, { walls: [w.id] })!;
|
||||
expect(sel.kind).toBe("wall");
|
||||
expect(sel.id).toBe(w.id);
|
||||
expect(sel.wall!.wallTypes.length).toBe(p.wallTypes.length);
|
||||
@@ -25,7 +25,7 @@ describe("deriveSelection (Kern)", () => {
|
||||
it("unbekannter Wandtyp bricht mit derselben Meldung ab wie bisher", () => {
|
||||
const p = base();
|
||||
p.walls[0] = { ...p.walls[0], wallTypeId: "fehlt" };
|
||||
expect(() => deriveSelection(p, [p.walls[0].id], null)).toThrow("Unbekannter Wandtyp: fehlt");
|
||||
expect(() => deriveSelection(p, { walls: [p.walls[0].id] })).toThrow("Unbekannter Wandtyp: fehlt");
|
||||
});
|
||||
|
||||
it("Zeichnung: offene Linie ohne Füllung, Rechteck mit Ebenen-Vorgaben", () => {
|
||||
@@ -36,15 +36,15 @@ describe("deriveSelection (Kern)", () => {
|
||||
{ id: "l", type: "drawing2d", levelId: lvl, categoryCode: code, geom: { shape: "line", a: { x: 0, y: 0 }, b: { x: 3, y: -2 } } },
|
||||
{ id: "r", type: "drawing2d", levelId: lvl, categoryCode: code, hatchId: "h", geom: { shape: "rect", min: { x: 1, y: 1 }, max: { x: 2, y: 4 } } },
|
||||
];
|
||||
const l = deriveSelection(p, [], "l")!;
|
||||
const l = deriveSelection(p, { drawings: ["l"] })!;
|
||||
expect(l.closed).toBe(false);
|
||||
expect(l.effectiveHatchId).toBeNull();
|
||||
expect(l.bbox).toEqual({ minX: 0, minY: -2, maxX: 3, maxY: 0 });
|
||||
const r = deriveSelection(p, [], "r")!;
|
||||
const r = deriveSelection(p, { drawings: ["r"] })!;
|
||||
expect(r.closed).toBe(true);
|
||||
expect(r.fillHatchId).toBe("h");
|
||||
expect(r.effectiveHatchId).toBe("h");
|
||||
expect(deriveSelection(p, [], "nix")).toBeNull();
|
||||
expect(deriveSelection(p, { drawings: ["nix"] })).toBeNull();
|
||||
});
|
||||
|
||||
it("Extrusion: Fläche im Kern, B-Rep-Beschreibung (truck) aus TS", () => {
|
||||
@@ -53,7 +53,7 @@ describe("deriveSelection (Kern)", () => {
|
||||
p.extrudedSolids = [
|
||||
{ id: "x", type: "extrudedSolid", levelId: lvl, points: [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 2, y: 3 }], height: 2 },
|
||||
];
|
||||
const sel = deriveSelection(p, [], null, null, null, null, null, "x")!;
|
||||
const sel = deriveSelection(p, { solids: ["x"] })!;
|
||||
expect(sel.extrudedSolid!.area).toBeCloseTo(3, 12);
|
||||
expect(sel.extrudedSolid!.spec).toMatchObject({ kind: "extrude", height: 2 });
|
||||
expect(Object.keys(sel.extrudedSolid!)).toEqual([
|
||||
@@ -72,7 +72,7 @@ describe("deriveSelection (Kern)", () => {
|
||||
});
|
||||
const edges = (r: Roof) => {
|
||||
// Neues Projekt-Objekt je Fall: der Kern gleicht über Referenzen ab.
|
||||
return deriveSelection({ ...p, roofs: [r] }, [], null, null, null, null, null, null, null, "R")!.roof!.edges;
|
||||
return deriveSelection({ ...p, roofs: [r] }, { roofs: ["R"] })!.roof!.edges;
|
||||
};
|
||||
const list = edges(roof({ holes: [rect(4, 2, 4, 4)] }));
|
||||
expect(list).toHaveLength(8);
|
||||
|
||||
+26
-35
@@ -17,6 +17,8 @@
|
||||
import { extrudedSolidSpec } from "../core";
|
||||
import type { SolidSpec } from "../engine/truckSolid";
|
||||
import { documentFor } from "../core/document";
|
||||
import { EMPTY_SELECTION, mergeSelection, single } from "./selection";
|
||||
import type { Selection } from "./selection";
|
||||
import type {
|
||||
AttributeSource,
|
||||
DimRef,
|
||||
@@ -358,7 +360,7 @@ export interface SelectionBBox {
|
||||
* EFFEKTIV aufgelöst (Override sonst Default), damit die Palette den real
|
||||
* gezeichneten Wert zeigt. `fillHatchId`/`closed` sind nur für Drawing2D sinnvoll.
|
||||
*/
|
||||
export interface Selection {
|
||||
export interface SelectionInfo {
|
||||
kind:
|
||||
| "wall"
|
||||
| "ceiling"
|
||||
@@ -411,7 +413,7 @@ export interface Selection {
|
||||
*/
|
||||
foreground?: string;
|
||||
/**
|
||||
* Stift-Kopplung von `foreground`, analog {@link Selection.colorPenId} —
|
||||
* Stift-Kopplung von `foreground`, analog {@link SelectionInfo.colorPenId} —
|
||||
* gesetzt bei Wand, Decke, Stütze und Drawing2D (dieselben `kind`s wie
|
||||
* `foreground` selbst).
|
||||
*/
|
||||
@@ -421,7 +423,7 @@ export interface Selection {
|
||||
* System". Nachfolger von `fillColor`; hat im Plan Vorrang.
|
||||
*/
|
||||
background?: string;
|
||||
/** Stift-Kopplung von `background`, analog {@link Selection.foregroundPenId}. */
|
||||
/** Stift-Kopplung von `background`, analog {@link SelectionInfo.foregroundPenId}. */
|
||||
backgroundPenId?: string;
|
||||
/**
|
||||
* Quelle des Vordergrunds, wenn `foreground` NICHT gesetzt ist ("layer" =
|
||||
@@ -429,7 +431,7 @@ export interface Selection {
|
||||
* Wand, Decke und geschlossener Drawing2D (wie `foreground`/`pocheEditable`).
|
||||
*/
|
||||
foregroundSource?: AttributeSource;
|
||||
/** Quelle des Hintergrunds, analog zu {@link Selection.foregroundSource}. */
|
||||
/** Quelle des Hintergrunds, analog zu {@link SelectionInfo.foregroundSource}. */
|
||||
backgroundSource?: AttributeSource;
|
||||
/**
|
||||
* RAW Strichstärke-Override (mm) DIESES Elements; `undefined` = kein Override
|
||||
@@ -449,9 +451,9 @@ export interface Selection {
|
||||
* `undefined` = kein Wert an keiner Stelle der Kette (echtes „Nach System").
|
||||
*/
|
||||
effectiveForeground?: string;
|
||||
/** Effektiv aufgelöster Hintergrund, analog zu {@link Selection.effectiveForeground}. */
|
||||
/** Effektiv aufgelöster Hintergrund, analog zu {@link SelectionInfo.effectiveForeground}. */
|
||||
effectiveBackground?: string;
|
||||
/** Effektiv aufgelöste Schraffur-ID, analog zu {@link Selection.effectiveForeground}. */
|
||||
/** Effektiv aufgelöste Schraffur-ID, analog zu {@link SelectionInfo.effectiveForeground}. */
|
||||
effectiveHatchId?: string | null;
|
||||
/** Ob die Form geschlossen ist (rect/circle/closed polyline) — nur Drawing2D. */
|
||||
closed?: boolean;
|
||||
@@ -539,45 +541,34 @@ const THROWN = /^Unbekannte[rs]? /;
|
||||
* Bauteil wirft wie bisher; ein Element, das das Kern-Modell nicht lesen kann,
|
||||
* ergibt `null` (mit Warnung).
|
||||
*/
|
||||
export function deriveSelection(
|
||||
project: Project,
|
||||
selectedWallIds: string[],
|
||||
selectedDrawingId: string | null,
|
||||
selectedCeilingId: string | null = null,
|
||||
selectedOpeningId: string | null = null,
|
||||
selectedStairId: string | null = null,
|
||||
selectedRoomId: string | null = null,
|
||||
selectedExtrudedSolidId: string | null = null,
|
||||
selectedColumnId: string | null = null,
|
||||
selectedRoofId: string | null = null,
|
||||
selectedContextObjectId: string | null = null,
|
||||
): Selection | null {
|
||||
export function deriveSelection(project: Project, selection: Partial<Selection>): SelectionInfo | null {
|
||||
const sel = mergeSelection(EMPTY_SELECTION, selection);
|
||||
const args = {
|
||||
wallIds: selectedWallIds,
|
||||
drawingId: selectedDrawingId,
|
||||
ceilingId: selectedCeilingId,
|
||||
openingId: selectedOpeningId,
|
||||
stairId: selectedStairId,
|
||||
roomId: selectedRoomId,
|
||||
extrudedSolidId: selectedExtrudedSolidId,
|
||||
columnId: selectedColumnId,
|
||||
roofId: selectedRoofId,
|
||||
contextObjectId: selectedContextObjectId,
|
||||
wallIds: sel.walls,
|
||||
drawingId: single(sel, "drawings"),
|
||||
ceilingId: single(sel, "ceilings"),
|
||||
openingId: single(sel, "openings"),
|
||||
stairId: single(sel, "stairs"),
|
||||
roomId: single(sel, "rooms"),
|
||||
extrudedSolidId: single(sel, "solids"),
|
||||
columnId: single(sel, "columns"),
|
||||
roofId: single(sel, "roofs"),
|
||||
contextObjectId: single(sel, "contextObjects"),
|
||||
};
|
||||
// Das Element sucht der Kern über den Positions-Index des Dokuments (keine lineare Suche).
|
||||
let sel: Selection | null;
|
||||
let info: SelectionInfo | null;
|
||||
try {
|
||||
sel = documentFor(project).queryRootMarked<Selection | null>("selectionInfo", JSON.stringify(args));
|
||||
info = documentFor(project).queryRootMarked<SelectionInfo | null>("selectionInfo", JSON.stringify(args));
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : String(e);
|
||||
if (THROWN.test(msg)) throw new Error(msg);
|
||||
console.warn("Objekt-Info:", msg);
|
||||
return null;
|
||||
}
|
||||
if (sel?.extrudedSolid) {
|
||||
const s = (project.extrudedSolids ?? []).find((x) => x.id === sel!.id);
|
||||
if (info?.extrudedSolid) {
|
||||
const s = (project.extrudedSolids ?? []).find((x) => x.id === info!.id);
|
||||
const floor = s && project.drawingLevels.find((z) => z.id === s.levelId);
|
||||
sel.extrudedSolid.spec = s && s.operation !== "subtract" ? extrudedSolidSpec(s, floor?.baseElevation ?? 0) : null;
|
||||
info.extrudedSolid.spec = s && s.operation !== "subtract" ? extrudedSolidSpec(s, floor?.baseElevation ?? 0) : null;
|
||||
}
|
||||
return sel;
|
||||
return info;
|
||||
}
|
||||
+20
-87
@@ -1,60 +1,27 @@
|
||||
// Auswahl-Slice: gewählte Wände (Menge) und das gewählte 2D-Zeichenelement.
|
||||
// Wand- und 2D-Auswahl schließen sich gegenseitig aus. Reiner Umzug aus
|
||||
// App.tsx. Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
// Auswahl-Slice: die Auswahl als EIN Wert (`Selection`, je Art eine Menge, [130])
|
||||
// plus der Isolations-Pfad der Gruppen. Bezeichner englisch, Kommentare deutsch.
|
||||
|
||||
import type { StoreApi } from "./store";
|
||||
import { EMPTY_SELECTION, mergeSelection } from "./selection";
|
||||
import type { Selection } from "./selection";
|
||||
|
||||
/** Felder, die diese Slice in den RootState beisteuert. */
|
||||
export interface SelectionSlice {
|
||||
// Gewählte Wände als MENGE von IDs (Marquee/Einzelauswahl).
|
||||
selectedWallIds: string[];
|
||||
// Gewählte 2D-Zeichenelemente als MENGE (Marquee/Mehrfach/Einzel) — getrennt
|
||||
// von der Wand-Auswahl. Einzel-Auswahl = Array der Länge 1.
|
||||
selectedDrawingIds: string[];
|
||||
// Gewählte Decken als MENGE von IDs — getrennt von Wand-/2D-Auswahl.
|
||||
selectedCeilingIds: string[];
|
||||
// Gewählte Öffnungen (Fenster/Türen) als MENGE von IDs — getrennt.
|
||||
selectedOpeningIds: string[];
|
||||
// Gewählte Treppen als MENGE von IDs — getrennt von den übrigen Kanälen.
|
||||
selectedStairIds: string[];
|
||||
// Gewählte Räume als MENGE von IDs — getrennt von den übrigen Kanälen.
|
||||
selectedRoomIds: string[];
|
||||
// Gewählte extrudierte Körper (truck-Integration) als MENGE von IDs — getrennt.
|
||||
selectedExtrudedSolidIds: string[];
|
||||
// Gewählte Stützen (Tragwerk) als MENGE von IDs — getrennt von den übrigen Kanälen.
|
||||
selectedColumnIds: string[];
|
||||
// Gewählte Dächer als MENGE von IDs — getrennt von den übrigen Kanälen.
|
||||
selectedRoofIds: string[];
|
||||
// Gewählte Kontext-Objekte (importierte Gebäude/Terrain) als MENGE von IDs.
|
||||
selectedContextObjectIds: string[];
|
||||
// Gewählte Schnitt-/Ansichtslinien (DrawingLevel-Ids) als MENGE von IDs —
|
||||
// getrennt von den übrigen Kanälen (Shift-Klick togglet, Cmd/Ctrl+A wählt alle).
|
||||
selectedSectionLineIds: string[];
|
||||
// Gewählte Gruppen (Vectorworks-artig) als MENGE von IDs — rein informativ/
|
||||
// fürs UI (Bounding-Box, Doppelklick-Ziel); die eigentlichen Mitglieder
|
||||
// stehen zusätzlich in den übrigen `selected…Ids`-Kanälen (Verschieben/
|
||||
// Löschen/etc. brauchen so keine Gruppen-Sonderbehandlung), s. `groupActions.ts`.
|
||||
selectedGroupIds: string[];
|
||||
/** Gewählte Elemente je Art. Komponenten lesen schmal: `useStore(s => s.selection.walls)`. */
|
||||
selection: Selection;
|
||||
// Isolations-Pfad (Vectorworks „Gruppe betreten"): Stapel der Gruppen-IDs,
|
||||
// in die per Doppelklick navigiert wurde — leer = nicht isoliert (normal),
|
||||
// letztes Element = die AKTIVE (innerste) Gruppe. Alles ausserhalb ihrer
|
||||
// transitiven Mitgliedschaft wird gedimmt/gesperrt (s. `groupActions.ts`).
|
||||
groupPath: string[];
|
||||
|
||||
setSelectedWallIds: (ids: string[]) => void;
|
||||
setSelectedDrawingIds: (ids: string[]) => void;
|
||||
setSelectedCeilingIds: (ids: string[]) => void;
|
||||
setSelectedOpeningIds: (ids: string[]) => void;
|
||||
setSelectedStairIds: (ids: string[]) => void;
|
||||
setSelectedRoomIds: (ids: string[]) => void;
|
||||
setSelectedExtrudedSolidIds: (ids: string[]) => void;
|
||||
setSelectedColumnIds: (ids: string[]) => void;
|
||||
setSelectedRoofIds: (ids: string[]) => void;
|
||||
setSelectedContextObjectIds: (ids: string[]) => void;
|
||||
setSelectedSectionLineIds: (ids: string[]) => void;
|
||||
setSelectedGroupIds: (ids: string[]) => void;
|
||||
/**
|
||||
* Ändert die genannten Arten (übrige bleiben). Gleicher Inhalt behält die alte
|
||||
* Referenz; ohne Änderung kein Benachrichtigen.
|
||||
*/
|
||||
setSelection: (patch: Partial<Selection> | ((s: Selection) => Partial<Selection>)) => void;
|
||||
setGroupPath: (path: string[]) => void;
|
||||
/** Auswahl (Wände + Decken + Öffnungen + Treppen + Dächer + 2D-Elemente) leeren. */
|
||||
/** Auswahl aller Arten (auch Gruppen) leeren. */
|
||||
clearSelection: () => void;
|
||||
}
|
||||
|
||||
@@ -63,50 +30,16 @@ export function createSelectionSlice(
|
||||
): SelectionSlice {
|
||||
const { set } = api;
|
||||
return {
|
||||
selectedWallIds: [],
|
||||
selectedDrawingIds: [],
|
||||
selectedCeilingIds: [],
|
||||
selectedOpeningIds: [],
|
||||
selectedStairIds: [],
|
||||
selectedRoomIds: [],
|
||||
selectedExtrudedSolidIds: [],
|
||||
selectedColumnIds: [],
|
||||
selectedRoofIds: [],
|
||||
selectedContextObjectIds: [],
|
||||
selectedSectionLineIds: [],
|
||||
selectedGroupIds: [],
|
||||
selection: EMPTY_SELECTION,
|
||||
groupPath: [],
|
||||
setSelectedWallIds: (ids) => set({ selectedWallIds: ids }),
|
||||
setSelectedDrawingIds: (ids) => set({ selectedDrawingIds: ids }),
|
||||
setSelectedCeilingIds: (ids) => set({ selectedCeilingIds: ids }),
|
||||
setSelectedOpeningIds: (ids) => set({ selectedOpeningIds: ids }),
|
||||
setSelectedStairIds: (ids) => set({ selectedStairIds: ids }),
|
||||
setSelectedRoomIds: (ids) => set({ selectedRoomIds: ids }),
|
||||
setSelectedExtrudedSolidIds: (ids) => set({ selectedExtrudedSolidIds: ids }),
|
||||
setSelectedColumnIds: (ids) => set({ selectedColumnIds: ids }),
|
||||
setSelectedRoofIds: (ids) => set({ selectedRoofIds: ids }),
|
||||
setSelectedContextObjectIds: (ids) => set({ selectedContextObjectIds: ids }),
|
||||
setSelectedSectionLineIds: (ids) => set({ selectedSectionLineIds: ids }),
|
||||
setSelectedGroupIds: (ids) => set({ selectedGroupIds: ids }),
|
||||
setSelection: (patch) =>
|
||||
set((s) => ({ selection: mergeSelection(s.selection, typeof patch === "function" ? patch(s.selection) : patch) })),
|
||||
setGroupPath: (path) => set({ groupPath: path }),
|
||||
// groupPath (Isolation) bleibt bewusst erhalten — Leerraum-Klick INNERHALB
|
||||
// einer betretenen Gruppe soll nur deren Auswahl leeren, nicht aus der
|
||||
// Gruppe hinauswerfen (Vectorworks-Verhalten). Verlassen ist ein
|
||||
// expliziter Schritt (Knopf/Escape, s. `useGroupHandlers.ts`).
|
||||
clearSelection: () =>
|
||||
set({
|
||||
selectedWallIds: [],
|
||||
selectedDrawingIds: [],
|
||||
selectedCeilingIds: [],
|
||||
selectedOpeningIds: [],
|
||||
selectedStairIds: [],
|
||||
selectedRoomIds: [],
|
||||
selectedExtrudedSolidIds: [],
|
||||
selectedColumnIds: [],
|
||||
selectedRoofIds: [],
|
||||
selectedContextObjectIds: [],
|
||||
selectedSectionLineIds: [],
|
||||
selectedGroupIds: [],
|
||||
// groupPath (Isolation) bleibt bewusst erhalten — Leerraum-Klick INNERHALB
|
||||
// einer betretenen Gruppe soll nur deren Auswahl leeren, nicht aus der
|
||||
// Gruppe hinauswerfen (Vectorworks-Verhalten). Verlassen ist ein
|
||||
// expliziter Schritt (Knopf/Escape, s. `useGroupHandlers.ts`).
|
||||
}),
|
||||
set((s) => ({ selection: mergeSelection(s.selection, EMPTY_SELECTION) })),
|
||||
};
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import { loadShortcutOverrides, saveShortcutOverrides, type ShortcutOverrides }
|
||||
import { useCommandKeys } from "./commandKeys";
|
||||
import { t } from "../i18n";
|
||||
import { getState } from "./appStore";
|
||||
import { clearKinds, toCommandSelection } from "./selection";
|
||||
import type { useSelectionState } from "./useSelectionState";
|
||||
import type { useContextMenuState } from "../menus/useContextMenuState";
|
||||
|
||||
@@ -57,30 +58,7 @@ export function useCommandEngineHost(opts: {
|
||||
activeWallTypeId: string;
|
||||
visibleCodes: Set<string>;
|
||||
snap: SnapSettings;
|
||||
sel: Pick<
|
||||
Sel,
|
||||
| "selectedWallIds"
|
||||
| "selectedDrawingId"
|
||||
| "selectedDrawingIds"
|
||||
| "selectedExtrudedSolidId"
|
||||
| "selectedColumnId"
|
||||
| "selectedCeilingIds"
|
||||
| "selectedRoofIds"
|
||||
| "selectedStairIds"
|
||||
| "selectedRoomIds"
|
||||
| "groupPath"
|
||||
| "setSelectedWallIds"
|
||||
| "setSelectedCeilingIds"
|
||||
| "setSelectedOpeningIds"
|
||||
| "setSelectedStairIds"
|
||||
| "setSelectedRoomIds"
|
||||
| "setSelectedExtrudedSolidIds"
|
||||
| "setSelectedColumnIds"
|
||||
| "setSelectedRoofIds"
|
||||
| "setSelectedContextObjectIds"
|
||||
| "setSelectedSectionLineIds"
|
||||
| "setSelectedDrawingId"
|
||||
>;
|
||||
sel: Pick<Sel, "selection" | "groupPath" | "setSelection">;
|
||||
setProject: (m: ProjectMutation) => void;
|
||||
setDraft: (d: ToolDraft | null) => void;
|
||||
notify: (msg: string, kind: "info" | "warning" | "error") => void;
|
||||
@@ -103,29 +81,7 @@ export function useCommandEngineHost(opts: {
|
||||
setEditTextId,
|
||||
setEditTextMinHeightM,
|
||||
} = opts;
|
||||
const {
|
||||
selectedWallIds,
|
||||
selectedDrawingId,
|
||||
selectedDrawingIds,
|
||||
selectedExtrudedSolidId,
|
||||
selectedColumnId,
|
||||
selectedCeilingIds,
|
||||
selectedRoofIds,
|
||||
selectedStairIds,
|
||||
selectedRoomIds,
|
||||
groupPath,
|
||||
setSelectedWallIds,
|
||||
setSelectedCeilingIds,
|
||||
setSelectedOpeningIds,
|
||||
setSelectedStairIds,
|
||||
setSelectedRoomIds,
|
||||
setSelectedExtrudedSolidIds,
|
||||
setSelectedColumnIds,
|
||||
setSelectedRoofIds,
|
||||
setSelectedContextObjectIds,
|
||||
setSelectedSectionLineIds,
|
||||
setSelectedDrawingId,
|
||||
} = opts.sel;
|
||||
const { selection, groupPath, setSelection } = opts.sel;
|
||||
// ── Command-Engine (Rhino-artiges Befehlssystem) ──────────────────────────
|
||||
// Eine stabile Engine-Instanz; alle Live-Werte (Kontext/Snap/visibleCodes)
|
||||
// liest der Host über einen jeweils aktualisierten `latest`-Ref, damit die
|
||||
@@ -141,15 +97,7 @@ export function useCommandEngineHost(opts: {
|
||||
activeWallTypeId,
|
||||
visibleCodes,
|
||||
snap,
|
||||
selectedWallIds,
|
||||
selectedDrawingId,
|
||||
selectedDrawingIds,
|
||||
selectedExtrudedSolidId,
|
||||
selectedColumnId,
|
||||
selectedCeilingIds,
|
||||
selectedRoofIds,
|
||||
selectedStairIds,
|
||||
selectedRoomIds,
|
||||
selection,
|
||||
groupPath,
|
||||
setProject,
|
||||
setDraft,
|
||||
@@ -162,15 +110,7 @@ export function useCommandEngineHost(opts: {
|
||||
activeWallTypeId,
|
||||
visibleCodes,
|
||||
snap,
|
||||
selectedWallIds,
|
||||
selectedDrawingId,
|
||||
selectedDrawingIds,
|
||||
selectedExtrudedSolidId,
|
||||
selectedColumnId,
|
||||
selectedCeilingIds,
|
||||
selectedRoofIds,
|
||||
selectedStairIds,
|
||||
selectedRoomIds,
|
||||
selection,
|
||||
groupPath,
|
||||
setProject,
|
||||
setDraft,
|
||||
@@ -193,17 +133,7 @@ export function useCommandEngineHost(opts: {
|
||||
// Befehl). Move/Copy/Offset operieren darauf.
|
||||
// Im Schnitt/in der Ansicht nur die 2D-Elemente der Ebene: Bauteile
|
||||
// leben im Grundriss-Raum, ein Schnitt-Delta wäre dort falsch.
|
||||
selection: sheetOnlySelection(c.activeLevel, {
|
||||
wallIds: c.selectedWallIds,
|
||||
drawingId: c.selectedDrawingId,
|
||||
drawingIds: c.selectedDrawingIds,
|
||||
extrudedSolidId: c.selectedExtrudedSolidId,
|
||||
columnId: c.selectedColumnId,
|
||||
ceilingIds: c.selectedCeilingIds,
|
||||
roofIds: c.selectedRoofIds,
|
||||
stairIds: c.selectedStairIds,
|
||||
roomIds: c.selectedRoomIds,
|
||||
}),
|
||||
selection: sheetOnlySelection(c.activeLevel, toCommandSelection(c.selection)),
|
||||
};
|
||||
},
|
||||
snap: (raw, draftPoints, mods) => {
|
||||
@@ -248,17 +178,7 @@ export function useCommandEngineHost(opts: {
|
||||
// onEditDrawingText (useMouseSelectionHandlers.ts), damit kein anderes
|
||||
// Element gleichzeitig markiert bleibt.
|
||||
focusDrawing: (id, minHeightM) => {
|
||||
setSelectedWallIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelectedDrawingId(id);
|
||||
setSelection({ ...clearKinds(), drawings: [id] });
|
||||
setEditTextMinHeightM(minHeightM ?? null);
|
||||
setEditTextId(id);
|
||||
},
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
import type { CommandLineHandle } from "../ui/CommandLine";
|
||||
import { useEvent } from "./useEvent";
|
||||
import type { useSelectionState } from "./useSelectionState";
|
||||
import type { Selection } from "./selection";
|
||||
import type { useProjectActions } from "./useProjectActions";
|
||||
|
||||
type Sel = ReturnType<typeof useSelectionState>;
|
||||
@@ -37,10 +38,7 @@ export function useGrip3dEditing(opts: {
|
||||
setDraft: (d: ToolDraft | null) => void;
|
||||
undo: () => void;
|
||||
commandLineRef: RefObject<CommandLineHandle>;
|
||||
selectedWallIds: string[];
|
||||
selectedDrawingIds: string[];
|
||||
selectedCeilingIds: string[];
|
||||
selectedRoofIds: string[];
|
||||
selection: Selection;
|
||||
updateRoof: Sel["updateRoof"];
|
||||
moveRoofGrip: Sel["moveRoofGrip"];
|
||||
moveRoofBy: Sel["moveRoofBy"];
|
||||
@@ -59,10 +57,7 @@ export function useGrip3dEditing(opts: {
|
||||
setDraft,
|
||||
undo,
|
||||
commandLineRef,
|
||||
selectedWallIds,
|
||||
selectedDrawingIds,
|
||||
selectedCeilingIds,
|
||||
selectedRoofIds,
|
||||
selection,
|
||||
updateRoof,
|
||||
moveRoofGrip,
|
||||
moveRoofBy,
|
||||
@@ -73,6 +68,7 @@ export function useGrip3dEditing(opts: {
|
||||
moveElementByOf,
|
||||
updateWall,
|
||||
} = opts;
|
||||
const { walls: selectedWallIds, drawings: selectedDrawingIds, ceilings: selectedCeilingIds, roofs: selectedRoofIds } = selection;
|
||||
// ── 3D-Editier-Griffe (direkt im Viewport3D) ──────────────────────────────
|
||||
// Genau EINE gewählte Wand (kein 2D-Element) bzw. genau EIN 2D-Element liefert
|
||||
// die Quelle der 3D-Griffe. Dieselben Store-Actions wie bei den Plan-Griffen
|
||||
|
||||
+14
-25
@@ -21,6 +21,8 @@ import { sheetOwnerOutlines } from "../tools/sheetSnapGeometry";
|
||||
import type { BodyTarget } from "../views/plan/PlanView";
|
||||
import type { CommandLineHandle } from "../ui/CommandLine";
|
||||
import type { CommandEngine } from "../commands/engine";
|
||||
import { single } from "./selection";
|
||||
import type { Selection } from "./selection";
|
||||
|
||||
export interface GripEditFieldsState {
|
||||
id: string;
|
||||
@@ -51,14 +53,8 @@ export function useGripEditing(opts: {
|
||||
/** [68] Einzeln gewählte Baugrube (Umriss-Ecken, Kanten, Sohlenhöhe als Griffe). */
|
||||
selectedExcavation?: Excavation | null;
|
||||
selectedRoom: Room | null;
|
||||
selectedOpeningId: string | null;
|
||||
selectedStairId: string | null;
|
||||
selectedRoomId: string | null;
|
||||
selectedCeilingId: string | null;
|
||||
selectedDrawingId: string | null;
|
||||
selectedWallId: string | null;
|
||||
selectedWallIds: string[];
|
||||
selectedDrawingIds: string[];
|
||||
/** Die Auswahl ([130]); Einzel-Elemente daraus wie in `useSelectionState`. */
|
||||
selection: Selection;
|
||||
levelId: string;
|
||||
/**
|
||||
* Ob Modell-Bauteile (Wand/Decke/Raum/Öffnung/Treppe) Griffe bekommen und per
|
||||
@@ -123,14 +119,7 @@ export function useGripEditing(opts: {
|
||||
selectedCeiling,
|
||||
selectedExcavation = null,
|
||||
selectedRoom,
|
||||
selectedOpeningId,
|
||||
selectedStairId,
|
||||
selectedRoomId,
|
||||
selectedCeilingId,
|
||||
selectedDrawingId,
|
||||
selectedWallId,
|
||||
selectedWallIds,
|
||||
selectedDrawingIds,
|
||||
selection,
|
||||
levelId,
|
||||
modelEditable = true,
|
||||
sheet = null,
|
||||
@@ -156,6 +145,13 @@ export function useGripEditing(opts: {
|
||||
moveCeilingBy,
|
||||
moveElementByOf,
|
||||
} = opts;
|
||||
const selectedOpeningId = single(selection, "openings");
|
||||
const selectedStairId = single(selection, "stairs");
|
||||
const selectedRoomId = single(selection, "rooms");
|
||||
const selectedCeilingId = single(selection, "ceilings");
|
||||
const selectedDrawingId = single(selection, "drawings");
|
||||
const selectedWallId = selection.walls[0] ?? null;
|
||||
const { walls: selectedWallIds, drawings: selectedDrawingIds } = selection;
|
||||
const groupChanges = opts.groupChanges ?? ((fn: () => void) => fn());
|
||||
|
||||
// Bewegpunkt (Move-Handle) einer Treppe: liegt auf der Treppe (Mitte des
|
||||
@@ -184,15 +180,8 @@ export function useGripEditing(opts: {
|
||||
// demselben Element kommen, nicht irgendeinem anderen der Mehrfachauswahl.
|
||||
const gripOwnerRange: [number, number][] = [];
|
||||
|
||||
// Bei Mehrfachauswahl fehlt `selectedDrawingIds` manchmal trotzdem (nur die
|
||||
// Einzel-ID `selectedDrawingId` gesetzt, s. useSelectionState-Konvention) —
|
||||
// derselbe Fallback wie an anderen Stellen im Projekt.
|
||||
const effectiveDrawingIds =
|
||||
selectedDrawingIds.length > 0
|
||||
? selectedDrawingIds
|
||||
: selectedDrawingId
|
||||
? [selectedDrawingId]
|
||||
: [];
|
||||
// Die Einzel-ID leitet sich aus der Menge ab ([130]) — die Menge genügt.
|
||||
const effectiveDrawingIds = selectedDrawingIds;
|
||||
|
||||
// Griff-Grenzen (s. gripLimits.ts): grosse Mehrfachauswahlen ohne Griffe, ein einzeln gewähltes
|
||||
// Element immer mit Griffen (Kataster-Parzellen mit tausenden Stützpunkten).
|
||||
|
||||
@@ -17,6 +17,8 @@ import { defaultImageSizeM, readImageFile } from "../io/imageAsset";
|
||||
import { rasterizePdfPages } from "../io/pdfImport";
|
||||
import { t } from "../i18n";
|
||||
import type { Vec2 } from "../model/types";
|
||||
import { clearKinds } from "./selection";
|
||||
import type { Selection } from "./selection";
|
||||
|
||||
/**
|
||||
* „Bild einfügen" (Werkzeug „image"): kein Klick-Platzieren (Datei-Auswahl ist
|
||||
@@ -35,17 +37,7 @@ export function useImageImportHandling(opts: {
|
||||
/** Änderung als Ops (Store `applyChange`): alle Bilder eines Einfügens = ein Undo-Schritt. */
|
||||
applyChange: (ops: readonly CoreOp[]) => void;
|
||||
notify: (message: string, kind?: NotifyKind) => void;
|
||||
setSelectedDrawingId: (id: string | null) => void;
|
||||
setSelectedWallIds: (ids: string[]) => void;
|
||||
setSelectedCeilingIds: (ids: string[]) => void;
|
||||
setSelectedOpeningIds: (ids: string[]) => void;
|
||||
setSelectedStairIds: (ids: string[]) => void;
|
||||
setSelectedRoomIds: (ids: string[]) => void;
|
||||
setSelectedExtrudedSolidIds: (ids: string[]) => void;
|
||||
setSelectedColumnIds: (ids: string[]) => void;
|
||||
setSelectedRoofIds: (ids: string[]) => void;
|
||||
setSelectedContextObjectIds: (ids: string[]) => void;
|
||||
setSelectedSectionLineIds: (ids: string[]) => void;
|
||||
setSelection: (patch: Partial<Selection>) => void;
|
||||
}): {
|
||||
insertImageDrawings: (assets: { src: string; naturalWidth: number; naturalHeight: number }[]) => void;
|
||||
onImageOrPdfFileChosen: (file: File) => void;
|
||||
@@ -56,17 +48,7 @@ export function useImageImportHandling(opts: {
|
||||
imagePlacement,
|
||||
applyChange,
|
||||
notify,
|
||||
setSelectedDrawingId,
|
||||
setSelectedWallIds,
|
||||
setSelectedCeilingIds,
|
||||
setSelectedOpeningIds,
|
||||
setSelectedStairIds,
|
||||
setSelectedRoomIds,
|
||||
setSelectedExtrudedSolidIds,
|
||||
setSelectedColumnIds,
|
||||
setSelectedRoofIds,
|
||||
setSelectedContextObjectIds,
|
||||
setSelectedSectionLineIds,
|
||||
setSelection,
|
||||
} = opts;
|
||||
|
||||
const insertImageDrawings = (
|
||||
@@ -82,17 +64,7 @@ export function useImageImportHandling(opts: {
|
||||
applyChange(addItems("drawings2d", drawings));
|
||||
const lastId = drawings.length ? drawings[drawings.length - 1].id : null;
|
||||
if (lastId) {
|
||||
setSelectedDrawingId(lastId);
|
||||
setSelectedWallIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelection({ ...clearKinds(), drawings: [lastId] });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import { differenceDrawings, intersectionDrawings, unionDrawings } from "../edit
|
||||
import type { BooleanResult } from "../editors/booleanOps";
|
||||
import { groupSelection, mergeMembership, ungroup, EMPTY_MEMBERSHIP } from "./groupActions";
|
||||
import type { GroupMembership } from "./groupActions";
|
||||
import { clearKinds, fromIdLists, isEmpty } from "./selection";
|
||||
import type { Selection } from "./selection";
|
||||
import {
|
||||
collectElementClipboard,
|
||||
isClipboardEmpty,
|
||||
@@ -251,28 +253,8 @@ export function useSelectAllAndDeleteShortcut(opts: {
|
||||
project: Project;
|
||||
activeLevelId: string;
|
||||
shortcutOverrides: ShortcutOverrides;
|
||||
selectedDrawingIds: string[];
|
||||
selectedWallIds: string[];
|
||||
selectedCeilingIds: string[];
|
||||
selectedOpeningIds: string[];
|
||||
selectedStairIds: string[];
|
||||
selectedRoomIds: string[];
|
||||
selectedExtrudedSolidIds: string[];
|
||||
selectedColumnIds: string[];
|
||||
selectedRoofIds: string[];
|
||||
selectedContextObjectIds: string[];
|
||||
selectedSectionLineIds: string[];
|
||||
setSelectedWallIds: (ids: string[]) => void;
|
||||
setSelectedDrawingIds: (ids: string[]) => void;
|
||||
setSelectedCeilingIds: (ids: string[]) => void;
|
||||
setSelectedOpeningIds: (ids: string[]) => void;
|
||||
setSelectedStairIds: (ids: string[]) => void;
|
||||
setSelectedRoomIds: (ids: string[]) => void;
|
||||
setSelectedExtrudedSolidIds: (ids: string[]) => void;
|
||||
setSelectedColumnIds: (ids: string[]) => void;
|
||||
setSelectedRoofIds: (ids: string[]) => void;
|
||||
setSelectedContextObjectIds: (ids: string[]) => void;
|
||||
setSelectedSectionLineIds: (ids: string[]) => void;
|
||||
selection: Selection;
|
||||
setSelection: (patch: Partial<Selection>) => void;
|
||||
hasSelectionToDelete: () => boolean;
|
||||
deleteSelection: () => void;
|
||||
}): void {
|
||||
@@ -282,16 +264,7 @@ export function useSelectAllAndDeleteShortcut(opts: {
|
||||
project,
|
||||
activeLevelId,
|
||||
shortcutOverrides,
|
||||
setSelectedWallIds,
|
||||
setSelectedDrawingIds,
|
||||
setSelectedCeilingIds,
|
||||
setSelectedOpeningIds,
|
||||
setSelectedStairIds,
|
||||
setSelectedRoomIds,
|
||||
setSelectedExtrudedSolidIds,
|
||||
setSelectedColumnIds,
|
||||
setSelectedRoofIds,
|
||||
setSelectedSectionLineIds,
|
||||
setSelection,
|
||||
hasSelectionToDelete,
|
||||
deleteSelection,
|
||||
} = opts;
|
||||
@@ -305,30 +278,8 @@ export function useSelectAllAndDeleteShortcut(opts: {
|
||||
if (e.key === "Escape" && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
||||
queueMicrotask(() => {
|
||||
if (e.defaultPrevented) return;
|
||||
const any =
|
||||
opts.selectedDrawingIds.length > 0 ||
|
||||
opts.selectedWallIds.length > 0 ||
|
||||
opts.selectedCeilingIds.length > 0 ||
|
||||
opts.selectedOpeningIds.length > 0 ||
|
||||
opts.selectedStairIds.length > 0 ||
|
||||
opts.selectedRoomIds.length > 0 ||
|
||||
opts.selectedExtrudedSolidIds.length > 0 ||
|
||||
opts.selectedColumnIds.length > 0 ||
|
||||
opts.selectedRoofIds.length > 0 ||
|
||||
opts.selectedContextObjectIds.length > 0 ||
|
||||
opts.selectedSectionLineIds.length > 0;
|
||||
if (!any) return;
|
||||
setSelectedWallIds([]);
|
||||
setSelectedDrawingIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
opts.setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
if (isEmpty(opts.selection, { withGroups: false })) return;
|
||||
setSelection(clearKinds());
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -391,16 +342,18 @@ export function useSelectAllAndDeleteShortcut(opts: {
|
||||
roofIds.length ||
|
||||
sectionLineIds.length
|
||||
) {
|
||||
setSelectedWallIds(wallIds);
|
||||
setSelectedDrawingIds(drawingIds);
|
||||
setSelectedCeilingIds(ceilingIds);
|
||||
setSelectedOpeningIds(openingIds);
|
||||
setSelectedStairIds(stairIds);
|
||||
setSelectedRoomIds(roomIds);
|
||||
setSelectedExtrudedSolidIds(extrudedSolidIds);
|
||||
setSelectedColumnIds(columnIds);
|
||||
setSelectedRoofIds(roofIds);
|
||||
setSelectedSectionLineIds(sectionLineIds);
|
||||
setSelection({
|
||||
walls: wallIds,
|
||||
drawings: drawingIds,
|
||||
ceilings: ceilingIds,
|
||||
openings: openingIds,
|
||||
stairs: stairIds,
|
||||
rooms: roomIds,
|
||||
solids: extrudedSolidIds,
|
||||
columns: columnIds,
|
||||
roofs: roofIds,
|
||||
sectionLines: sectionLineIds,
|
||||
});
|
||||
e.preventDefault();
|
||||
}
|
||||
return;
|
||||
@@ -423,17 +376,7 @@ export function useSelectAllAndDeleteShortcut(opts: {
|
||||
opts.activeTool,
|
||||
opts.transformActive,
|
||||
opts.shortcutOverrides,
|
||||
opts.selectedDrawingIds,
|
||||
opts.selectedWallIds,
|
||||
opts.selectedCeilingIds,
|
||||
opts.selectedOpeningIds,
|
||||
opts.selectedStairIds,
|
||||
opts.selectedRoomIds,
|
||||
opts.selectedExtrudedSolidIds,
|
||||
opts.selectedColumnIds,
|
||||
opts.selectedRoofIds,
|
||||
opts.selectedContextObjectIds,
|
||||
opts.selectedSectionLineIds,
|
||||
opts.selection,
|
||||
opts.project.walls,
|
||||
opts.project.drawings2d,
|
||||
opts.project.ceilings,
|
||||
@@ -460,8 +403,7 @@ export function useSplitJoinShortcut(
|
||||
selectedDrawingIds: string[],
|
||||
engine: CommandEngine,
|
||||
runSplit: (ids: string[]) => void,
|
||||
setSelectedDrawingIds: (ids: string[]) => void,
|
||||
setSelectedWallIds: (ids: string[]) => void,
|
||||
setSelection: (patch: Partial<Selection>) => void,
|
||||
overrides: ShortcutOverrides,
|
||||
): void {
|
||||
useEffect(() => {
|
||||
@@ -481,8 +423,7 @@ export function useSplitJoinShortcut(
|
||||
// Join: exakt derselbe Befehl wie „join" tippen (Sofort-Befehl, autoRun).
|
||||
// Nach dem Verbinden zeigt die alte Auswahl auf ersetzte IDs → aufräumen.
|
||||
engine.start("join");
|
||||
setSelectedDrawingIds([]);
|
||||
setSelectedWallIds([]);
|
||||
setSelection({ drawings: [], walls: [] });
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
@@ -519,17 +460,7 @@ export function useElementClipboardShortcut(
|
||||
activeLevelId: string,
|
||||
project: Project,
|
||||
applyChange: (ops: readonly CoreOp[] | ((p: Project) => readonly CoreOp[])) => void,
|
||||
setSelected: {
|
||||
wallIds: (ids: string[]) => void;
|
||||
drawingIds: (ids: string[]) => void;
|
||||
ceilingIds: (ids: string[]) => void;
|
||||
roofIds: (ids: string[]) => void;
|
||||
openingIds: (ids: string[]) => void;
|
||||
stairIds: (ids: string[]) => void;
|
||||
roomIds: (ids: string[]) => void;
|
||||
extrudedSolidIds: (ids: string[]) => void;
|
||||
columnIds: (ids: string[]) => void;
|
||||
},
|
||||
setSelection: (patch: Partial<Selection>) => void,
|
||||
overrides: ShortcutOverrides,
|
||||
): void {
|
||||
useEffect(() => {
|
||||
@@ -566,15 +497,7 @@ export function useElementClipboardShortcut(
|
||||
});
|
||||
const pastedIds = out.ids;
|
||||
if (!pastedIds) return;
|
||||
setSelected.wallIds(pastedIds.wallIds);
|
||||
setSelected.drawingIds(pastedIds.drawingIds);
|
||||
setSelected.ceilingIds(pastedIds.ceilingIds);
|
||||
setSelected.roofIds(pastedIds.roofIds);
|
||||
setSelected.openingIds(pastedIds.openingIds);
|
||||
setSelected.stairIds(pastedIds.stairIds);
|
||||
setSelected.roomIds(pastedIds.roomIds);
|
||||
setSelected.extrudedSolidIds(pastedIds.extrudedSolidIds);
|
||||
setSelected.columnIds(pastedIds.columnIds);
|
||||
setSelection(fromIdLists(pastedIds));
|
||||
};
|
||||
if (navigator.clipboard?.readText) {
|
||||
navigator.clipboard
|
||||
|
||||
@@ -15,6 +15,8 @@ import type { RichTextDoc } from "../text/richText";
|
||||
import { plainText } from "../text/richText";
|
||||
import { hitTestWall } from "../viewport/planHitTest";
|
||||
import type { useSelectionState } from "./useSelectionState";
|
||||
import { ELEMENT_KINDS, clearKinds, fromIdLists } from "./selection";
|
||||
import type { Selection, SelectionKind } from "./selection";
|
||||
import type { useContextMenuState } from "../menus/useContextMenuState";
|
||||
import {
|
||||
EMPTY_MEMBERSHIP,
|
||||
@@ -50,68 +52,14 @@ export function useMouseSelectionHandlers(opts: {
|
||||
* nur für Geschoss/Zeichnung) — sperrt Elemente einer nicht-aktiven,
|
||||
* überlagerten Ebene analog zum Kategorie-Sperren unten. */
|
||||
floorDisplay: CategoryDisplayResolver & DisplayResolver;
|
||||
selectionState: Pick<
|
||||
ReturnType<typeof useSelectionState>,
|
||||
| "selectedWallIds"
|
||||
| "setSelectedWallIds"
|
||||
| "selectedDrawingIds"
|
||||
| "setSelectedDrawingIds"
|
||||
| "setSelectedDrawingId"
|
||||
| "selectedCeilingIds"
|
||||
| "setSelectedCeilingIds"
|
||||
| "selectedOpeningIds"
|
||||
| "setSelectedOpeningIds"
|
||||
| "selectedStairIds"
|
||||
| "setSelectedStairIds"
|
||||
| "selectedRoomIds"
|
||||
| "setSelectedRoomIds"
|
||||
| "selectedExtrudedSolidIds"
|
||||
| "setSelectedExtrudedSolidIds"
|
||||
| "selectedColumnIds"
|
||||
| "setSelectedColumnIds"
|
||||
| "selectedRoofIds"
|
||||
| "setSelectedRoofIds"
|
||||
| "selectedContextObjectIds"
|
||||
| "setSelectedContextObjectIds"
|
||||
| "selectedSectionLineIds"
|
||||
| "setSelectedSectionLineIds"
|
||||
| "selectedGroupIds"
|
||||
| "setSelectedGroupIds"
|
||||
| "groupPath"
|
||||
>;
|
||||
selectionState: Pick<ReturnType<typeof useSelectionState>, "selection" | "setSelection" | "groupPath">;
|
||||
contextMenuState: Pick<
|
||||
ReturnType<typeof useContextMenuState>,
|
||||
"setMenu" | "setStampEditorRoomId" | "editTextId" | "setEditTextId" | "setEditTextMinHeightM"
|
||||
>;
|
||||
}) {
|
||||
const { project, setProject, activeLevelId, visibleCodes, categoryDisplay, floorDisplay, selectionState, contextMenuState } = opts;
|
||||
const {
|
||||
selectedWallIds,
|
||||
setSelectedWallIds,
|
||||
selectedDrawingIds,
|
||||
setSelectedDrawingIds,
|
||||
setSelectedDrawingId,
|
||||
selectedCeilingIds,
|
||||
setSelectedCeilingIds,
|
||||
selectedOpeningIds,
|
||||
setSelectedOpeningIds,
|
||||
selectedStairIds,
|
||||
setSelectedStairIds,
|
||||
selectedRoomIds,
|
||||
setSelectedRoomIds,
|
||||
selectedExtrudedSolidIds,
|
||||
setSelectedExtrudedSolidIds,
|
||||
selectedColumnIds,
|
||||
setSelectedColumnIds,
|
||||
selectedRoofIds,
|
||||
setSelectedRoofIds,
|
||||
selectedContextObjectIds,
|
||||
setSelectedContextObjectIds,
|
||||
selectedSectionLineIds,
|
||||
setSelectedSectionLineIds,
|
||||
setSelectedGroupIds,
|
||||
groupPath,
|
||||
} = selectionState;
|
||||
const { selection, setSelection, groupPath } = selectionState;
|
||||
const { setMenu, setStampEditorRoomId, editTextId, setEditTextId, setEditTextMinHeightM } = contextMenuState;
|
||||
|
||||
// ── Maus-Schema: Auswahl + Kontextmenü aus Grundriss / 3D ─────────────────
|
||||
@@ -120,34 +68,14 @@ export function useMouseSelectionHandlers(opts: {
|
||||
// Doppelklick auf einen Raum-Stempel: den Raum wählen + den Stempel-Editor
|
||||
// öffnen (Rich-Text-Popup).
|
||||
const onOpenStampEditor = (roomId: string) => {
|
||||
setSelectedRoomIds([roomId]);
|
||||
setSelectedWallIds([]);
|
||||
setSelectedDrawingId(null);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelection({ ...clearKinds(), rooms: [roomId] });
|
||||
setStampEditorRoomId(roomId);
|
||||
};
|
||||
// Doppelklick auf ein Text-2D-Element: selektieren + Inhalts-Editor öffnen.
|
||||
const onEditDrawingText = (drawingId: string) => {
|
||||
const d = project.drawings2d.find((x) => x.id === drawingId);
|
||||
if (!d || d.geom.shape !== "text") return;
|
||||
setSelectedDrawingId(drawingId);
|
||||
setSelectedWallIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelection({ ...clearKinds(), drawings: [drawingId] });
|
||||
// Bestehendes Element per Doppelklick: keine Rahmen-Mindesthöhe (nur bei
|
||||
// frisch aufgezogener Textspalte relevant, s. textbox.ts focusMinHeightM)
|
||||
// — sonst könnte eine vorige Textspalten-Erstellung hier nachwirken.
|
||||
@@ -265,19 +193,20 @@ export function useMouseSelectionHandlers(opts: {
|
||||
if (sel.shift) {
|
||||
// Je Art: Auswahl-Liste + Setter. `replaces` (Shift-Durchschalten) entfernt
|
||||
// zuerst das vorige Zwischenergebnis, bevor das neue Objekt umgeschaltet wird.
|
||||
// Shift-Art (PlanSelection) → Auswahl-Art.
|
||||
const channels = {
|
||||
section: [selectedSectionLineIds, setSelectedSectionLineIds],
|
||||
wall: [selectedWallIds, setSelectedWallIds],
|
||||
drawing: [selectedDrawingIds, setSelectedDrawingIds],
|
||||
ceiling: [selectedCeilingIds, setSelectedCeilingIds],
|
||||
opening: [selectedOpeningIds, setSelectedOpeningIds],
|
||||
stair: [selectedStairIds, setSelectedStairIds],
|
||||
room: [selectedRoomIds, setSelectedRoomIds],
|
||||
solid: [selectedExtrudedSolidIds, setSelectedExtrudedSolidIds],
|
||||
column: [selectedColumnIds, setSelectedColumnIds],
|
||||
roof: [selectedRoofIds, setSelectedRoofIds],
|
||||
context: [selectedContextObjectIds, setSelectedContextObjectIds],
|
||||
} as const;
|
||||
section: "sectionLines",
|
||||
wall: "walls",
|
||||
drawing: "drawings",
|
||||
ceiling: "ceilings",
|
||||
opening: "openings",
|
||||
stair: "stairs",
|
||||
room: "rooms",
|
||||
solid: "solids",
|
||||
column: "columns",
|
||||
roof: "roofs",
|
||||
context: "contextObjects",
|
||||
} as const satisfies Record<string, SelectionKind>;
|
||||
type Kind = keyof typeof channels;
|
||||
const target: { kind: Kind; id: string } | null = sel.sectionLineId
|
||||
? { kind: "section", id: sel.sectionLineId }
|
||||
@@ -304,16 +233,16 @@ export function useMouseSelectionHandlers(opts: {
|
||||
: null;
|
||||
const rep = sel.replaces;
|
||||
const base = (kind: Kind): string[] => {
|
||||
const list = channels[kind][0] as readonly string[];
|
||||
const list = selection[channels[kind]];
|
||||
return rep && rep.kind === kind ? list.filter((x) => x !== rep.id) : [...list];
|
||||
};
|
||||
if (rep && (!target || rep.kind !== target.kind)) channels[rep.kind][1](base(rep.kind));
|
||||
const patch: Partial<Selection> = {};
|
||||
if (rep && (!target || rep.kind !== target.kind)) patch[channels[rep.kind]] = base(rep.kind);
|
||||
if (target) {
|
||||
const list = base(target.kind);
|
||||
channels[target.kind][1](
|
||||
list.includes(target.id) ? list.filter((x) => x !== target.id) : [...list, target.id],
|
||||
);
|
||||
patch[channels[target.kind]] = list.includes(target.id) ? list.filter((x) => x !== target.id) : [...list, target.id];
|
||||
}
|
||||
setSelection(patch);
|
||||
return;
|
||||
}
|
||||
// Gruppen-Erweiterung: gehört das getroffene Element zu einer (im
|
||||
@@ -328,76 +257,37 @@ export function useMouseSelectionHandlers(opts: {
|
||||
groupPath,
|
||||
);
|
||||
if (groupIds.length > 0) {
|
||||
setSelectedWallIds(expanded.wallIds);
|
||||
setSelectedDrawingIds(expanded.drawingIds);
|
||||
setSelectedCeilingIds(expanded.ceilingIds);
|
||||
setSelectedOpeningIds(expanded.openingIds);
|
||||
setSelectedStairIds(expanded.stairIds);
|
||||
setSelectedRoomIds(expanded.roomIds);
|
||||
setSelectedColumnIds(expanded.columnIds);
|
||||
setSelectedRoofIds(expanded.roofIds);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelectedGroupIds(groupIds);
|
||||
setSelection({ ...clearKinds(), ...fromIdLists(expanded), groups: groupIds });
|
||||
return;
|
||||
}
|
||||
}
|
||||
setSelectedGroupIds([]);
|
||||
// Ohne Shift: ersetzen. Öffnung hat Vorrang (ihr Symbol liegt in der Lücke),
|
||||
// dann Wand, dann 2D-Element, dann Decke; sonst leeren. Die Kanäle schließen
|
||||
// sich gegenseitig aus.
|
||||
// Alle Kanäle ausser dem gewählten leeren — als Helfer, damit jeder Zweig
|
||||
// (inkl. des neuen Dach-Kanals) konsistent bleibt.
|
||||
const clearOthers = (keep: string) => {
|
||||
if (keep !== "wall") setSelectedWallIds([]);
|
||||
if (keep !== "drawing") setSelectedDrawingId(null);
|
||||
if (keep !== "ceiling") setSelectedCeilingIds([]);
|
||||
if (keep !== "opening") setSelectedOpeningIds([]);
|
||||
if (keep !== "stair") setSelectedStairIds([]);
|
||||
if (keep !== "room") setSelectedRoomIds([]);
|
||||
if (keep !== "extrudedSolid") setSelectedExtrudedSolidIds([]);
|
||||
if (keep !== "column") setSelectedColumnIds([]);
|
||||
if (keep !== "roof") setSelectedRoofIds([]);
|
||||
if (keep !== "contextObject") setSelectedContextObjectIds([]);
|
||||
if (keep !== "sectionLine") setSelectedSectionLineIds([]);
|
||||
};
|
||||
if (sel.sectionLineId) {
|
||||
setSelectedSectionLineIds([sel.sectionLineId]);
|
||||
clearOthers("sectionLine");
|
||||
} else if (sel.openingId) {
|
||||
setSelectedOpeningIds([sel.openingId]);
|
||||
clearOthers("opening");
|
||||
} else if (sel.wallId) {
|
||||
setSelectedWallIds([sel.wallId]);
|
||||
clearOthers("wall");
|
||||
} else if (sel.columnId) {
|
||||
setSelectedColumnIds([sel.columnId]);
|
||||
clearOthers("column");
|
||||
} else if (sel.drawingId) {
|
||||
setSelectedDrawingId(sel.drawingId);
|
||||
clearOthers("drawing");
|
||||
} else if (sel.extrudedSolidId) {
|
||||
setSelectedExtrudedSolidIds([sel.extrudedSolidId]);
|
||||
clearOthers("extrudedSolid");
|
||||
} else if (sel.ceilingId) {
|
||||
setSelectedCeilingIds([sel.ceilingId]);
|
||||
clearOthers("ceiling");
|
||||
} else if (sel.stairId) {
|
||||
setSelectedStairIds([sel.stairId]);
|
||||
clearOthers("stair");
|
||||
} else if (sel.roomId) {
|
||||
setSelectedRoomIds([sel.roomId]);
|
||||
clearOthers("room");
|
||||
} else if (sel.roofId) {
|
||||
setSelectedRoofIds([sel.roofId]);
|
||||
clearOthers("roof");
|
||||
} else if (sel.contextObjectId) {
|
||||
setSelectedContextObjectIds([sel.contextObjectId]);
|
||||
clearOthers("contextObject");
|
||||
} else {
|
||||
clearOthers("");
|
||||
}
|
||||
// dann Wand, dann 2D-Element, dann Decke; sonst leeren. Die Arten schließen
|
||||
// sich gegenseitig aus (alle anderen und die Gruppen werden geleert).
|
||||
const one: [SelectionKind, string] | null = sel.sectionLineId
|
||||
? ["sectionLines", sel.sectionLineId]
|
||||
: sel.openingId
|
||||
? ["openings", sel.openingId]
|
||||
: sel.wallId
|
||||
? ["walls", sel.wallId]
|
||||
: sel.columnId
|
||||
? ["columns", sel.columnId]
|
||||
: sel.drawingId
|
||||
? ["drawings", sel.drawingId]
|
||||
: sel.extrudedSolidId
|
||||
? ["solids", sel.extrudedSolidId]
|
||||
: sel.ceilingId
|
||||
? ["ceilings", sel.ceilingId]
|
||||
: sel.stairId
|
||||
? ["stairs", sel.stairId]
|
||||
: sel.roomId
|
||||
? ["rooms", sel.roomId]
|
||||
: sel.roofId
|
||||
? ["roofs", sel.roofId]
|
||||
: sel.contextObjectId
|
||||
? ["contextObjects", sel.contextObjectId]
|
||||
: null;
|
||||
setSelection({ ...clearKinds(), groups: [], ...(one ? { [one[0]]: [one[1]] } : {}) });
|
||||
};
|
||||
// Links-Drag (Marquee) im Grundriss: die getroffene Wand-MENGE übernehmen
|
||||
// (nach CAD-Konvention von PlanView bestimmt). Ersetzt die bisherige Auswahl.
|
||||
@@ -433,22 +323,19 @@ export function useMouseSelectionHandlers(opts: {
|
||||
// Gruppen-Erweiterung: jedes getroffene Element, das zu einer sichtbaren
|
||||
// Gruppe gehört, zieht deren ganze (transitive) Mitgliedschaft nach.
|
||||
const { expanded, groupIds } = expandToGroups(project, filtered, groupPath);
|
||||
setSelectedWallIds(expanded.wallIds);
|
||||
setSelectedDrawingIds(expanded.drawingIds);
|
||||
setSelectedCeilingIds(expanded.ceilingIds);
|
||||
setSelectedStairIds(expanded.stairIds);
|
||||
setSelectedRoomIds(expanded.roomIds);
|
||||
setSelectedGroupIds(groupIds);
|
||||
// Öffnungen/Extrusionen/Stützen/Dächer/Kontext-Objekte sind (noch) nicht
|
||||
// Teil des Marquee (Nutzer-Report betraf nur Decken/Räume/Treppen; Stütze/
|
||||
// Dach liessen sich mit derselben `marqueeHitByField`-Mechanik ergänzen,
|
||||
// falls gewünscht) → beim Aufziehen abwählen.
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelection({
|
||||
...clearKinds(),
|
||||
walls: expanded.wallIds,
|
||||
drawings: expanded.drawingIds,
|
||||
ceilings: expanded.ceilingIds,
|
||||
stairs: expanded.stairIds,
|
||||
rooms: expanded.roomIds,
|
||||
groups: groupIds,
|
||||
});
|
||||
};
|
||||
// Rechts-Klick im Grundriss: Wand-Kontextmenü. Trifft der Klick eine Wand, die
|
||||
// NICHT bereits in der Auswahl ist, wird die Auswahl auf sie gesetzt (damit die
|
||||
@@ -460,7 +347,7 @@ export function useMouseSelectionHandlers(opts: {
|
||||
model: Vec2;
|
||||
}) => {
|
||||
const wallId = hitTestWall(project, activeLevelId, visibleCodes, info.model);
|
||||
if (wallId && !selectedWallIds.includes(wallId)) setSelectedWallIds([wallId]);
|
||||
if (wallId && !selection.walls.includes(wallId)) setSelection({ walls: [wallId] });
|
||||
setMenu({ kind: "plan", x: info.clientX, y: info.clientY, wallId, model: info.model });
|
||||
};
|
||||
// Links-KLICK im Nordstern-3D-Viewport (WASM, TS-Raycast): getroffenes Bauteil
|
||||
@@ -471,114 +358,39 @@ export function useMouseSelectionHandlers(opts: {
|
||||
// Leertreffer (kein Bauteil) → alle Selektionen leeren.
|
||||
const onViewport3dPick = (hit: Pick3dHit, additive: boolean) => {
|
||||
if (!hit) {
|
||||
setSelectedWallIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedDrawingId(null);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelection(clearKinds());
|
||||
return;
|
||||
}
|
||||
// Öffnung (Fenster/Tür), Treppe, Kontext-Objekt, 2D-Element und Dach ersetzen
|
||||
// die Auswahl exklusiv; nur Wände und Decken unterstützen additive
|
||||
// Mehrfachauswahl (wie bisher; ein 2D-Treffer wählt auch mit Shift nur sich).
|
||||
if (hit.kind === "contextObject") {
|
||||
setSelectedContextObjectIds([hit.id]);
|
||||
setSelectedWallIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedDrawingId(null);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelection({ ...clearKinds(), contextObjects: [hit.id] });
|
||||
return;
|
||||
}
|
||||
// Öffnung (Fenster/Tür) und Treppe sind jetzt auch im WASM-Viewport pickbar
|
||||
// (raycast3d/pickGeometry). Jede Art ersetzt die Auswahl exklusiv; nur Wände
|
||||
// unterstützen additive Mehrfachauswahl (wie bisher).
|
||||
if (hit.kind === "opening") {
|
||||
setSelectedOpeningIds([hit.id]);
|
||||
setSelectedWallIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedDrawingId(null);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelection({ ...clearKinds(), openings: [hit.id] });
|
||||
return;
|
||||
}
|
||||
if (hit.kind === "drawing") {
|
||||
setSelectedDrawingIds(
|
||||
additive ? Array.from(new Set([...selectedDrawingIds, hit.id])) : [hit.id],
|
||||
);
|
||||
setSelectedDrawingId(hit.id);
|
||||
setSelectedWallIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelection({ ...clearKinds(), drawings: [hit.id] });
|
||||
return;
|
||||
}
|
||||
if (hit.kind === "stair") {
|
||||
setSelectedStairIds([hit.id]);
|
||||
setSelectedWallIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedDrawingId(null);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
setSelection({ ...clearKinds(), stairs: [hit.id] });
|
||||
return;
|
||||
}
|
||||
if (hit.kind === "roof") {
|
||||
setSelectedRoofIds([hit.id]);
|
||||
setSelectedWallIds([]);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedDrawingId(null);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
// Schnittlinien bleiben hier (wie bisher) gewählt.
|
||||
setSelection({ ...clearKinds(...ELEMENT_KINDS.filter((k) => k !== "sectionLines")), roofs: [hit.id] });
|
||||
return;
|
||||
}
|
||||
if (hit.kind === "wall") {
|
||||
setSelectedWallIds(
|
||||
additive ? Array.from(new Set([...selectedWallIds, hit.id])) : [hit.id],
|
||||
);
|
||||
setSelectedCeilingIds([]);
|
||||
} else {
|
||||
setSelectedCeilingIds(
|
||||
additive ? Array.from(new Set([...selectedCeilingIds, hit.id])) : [hit.id],
|
||||
);
|
||||
setSelectedWallIds([]);
|
||||
}
|
||||
setSelectedDrawingId(null);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
const add = (ids: string[]) => (additive ? Array.from(new Set([...ids, hit.id])) : [hit.id]);
|
||||
setSelection(
|
||||
hit.kind === "wall"
|
||||
? { ...clearKinds(), walls: add(selection.walls) }
|
||||
: { ...clearKinds(), ceilings: add(selection.ceilings) },
|
||||
);
|
||||
};
|
||||
return {
|
||||
onOpenStampEditor,
|
||||
|
||||
@@ -18,7 +18,9 @@ import type { ViewType } from "../model/viewTypes";
|
||||
import type { TransformSelection } from "../tools/transform";
|
||||
import type { PlanViewHandle } from "../views/plan/PlanView";
|
||||
import type { PanelHostValue } from "../panels/host";
|
||||
import type { Selection } from "./selectionInfo";
|
||||
import type { SelectionInfo } from "./selectionInfo";
|
||||
import { clearKinds } from "./selection";
|
||||
import type { SelectionKind } from "./selection";
|
||||
import type { EngineView } from "../commands/engine";
|
||||
import type { ScheduleKind } from "../export/exportSchedule";
|
||||
import type { TabId as ResourceTabId } from "../ui/ResourceManager";
|
||||
@@ -128,7 +130,7 @@ export function usePanelHostBase(opts: {
|
||||
openResources: (tab?: ResourceTabId) => void;
|
||||
dxfInputRef: RefObject<HTMLInputElement | null>;
|
||||
planViewRef: RefObject<PlanViewHandle | null>;
|
||||
selection: Selection | null;
|
||||
selection: SelectionInfo | null;
|
||||
projectActions: Pick<
|
||||
ReturnType<typeof useProjectActions>,
|
||||
| "toggleLevelVisible"
|
||||
@@ -192,19 +194,8 @@ export function usePanelHostBase(opts: {
|
||||
selectionState: Pick<
|
||||
ReturnType<typeof useSelectionState>,
|
||||
| "updateRoof"
|
||||
| "setSelectedWallIds"
|
||||
| "setSelectedDrawingId"
|
||||
| "selectedContextObjectIds"
|
||||
| "setSelectedCeilingIds"
|
||||
| "setSelectedOpeningIds"
|
||||
| "setSelectedStairIds"
|
||||
| "setSelectedRoomIds"
|
||||
| "setSelectedExtrudedSolidIds"
|
||||
| "setSelectedColumnIds"
|
||||
| "setSelectedRoofIds"
|
||||
| "setSelectedContextObjectIds"
|
||||
| "setSelection"
|
||||
| "selectedSectionLineId"
|
||||
| "setSelectedSectionLineIds"
|
||||
| "section3dCutId"
|
||||
>;
|
||||
toolState: Pick<
|
||||
@@ -316,19 +307,8 @@ export function usePanelHostBase(opts: {
|
||||
} = projectActions;
|
||||
const {
|
||||
updateRoof,
|
||||
setSelectedWallIds,
|
||||
setSelectedDrawingId,
|
||||
selectedContextObjectIds,
|
||||
setSelectedCeilingIds,
|
||||
setSelectedOpeningIds,
|
||||
setSelectedStairIds,
|
||||
setSelectedRoomIds,
|
||||
setSelectedExtrudedSolidIds,
|
||||
setSelectedColumnIds,
|
||||
setSelectedRoofIds,
|
||||
setSelectedContextObjectIds,
|
||||
setSelection,
|
||||
selectedSectionLineId,
|
||||
setSelectedSectionLineIds,
|
||||
section3dCutId,
|
||||
} = selectionState;
|
||||
const { activeTool, activeWallTypeId, setActiveWallTypeId, activeCategoryCode, setActiveCategoryCode, snap, setSnap } =
|
||||
@@ -1115,7 +1095,6 @@ export function usePanelHostBase(opts: {
|
||||
},
|
||||
// ── Site-/Kontext-Schicht ──────────────────────────────────────────────
|
||||
contextObjects: project.context ?? [],
|
||||
selectedContextObjectIds,
|
||||
onAddContextObjects: addContextObjectsAndFit,
|
||||
onRemoveContextObject: removeContextObject,
|
||||
onRemoveContextObjects: removeContextObjects,
|
||||
@@ -1135,44 +1114,20 @@ export function usePanelHostBase(opts: {
|
||||
opts?: { zoom?: boolean },
|
||||
) => {
|
||||
const applySelection = () => {
|
||||
setSelectedWallIds([]);
|
||||
setSelectedDrawingId(null);
|
||||
setSelectedCeilingIds([]);
|
||||
setSelectedOpeningIds([]);
|
||||
setSelectedStairIds([]);
|
||||
setSelectedRoomIds([]);
|
||||
setSelectedExtrudedSolidIds([]);
|
||||
setSelectedColumnIds([]);
|
||||
setSelectedRoofIds([]);
|
||||
setSelectedContextObjectIds([]);
|
||||
setSelectedSectionLineIds([]);
|
||||
switch (kind) {
|
||||
case "Wand":
|
||||
setSelectedWallIds([id]);
|
||||
break;
|
||||
case "Decke":
|
||||
setSelectedCeilingIds([id]);
|
||||
break;
|
||||
case "Fenster":
|
||||
case "Öffnung":
|
||||
setSelectedOpeningIds([id]);
|
||||
break;
|
||||
case "Treppe":
|
||||
setSelectedStairIds([id]);
|
||||
break;
|
||||
case "Extrusion":
|
||||
setSelectedExtrudedSolidIds([id]);
|
||||
break;
|
||||
case "Dach":
|
||||
setSelectedRoofIds([id]);
|
||||
break;
|
||||
case "Stütze":
|
||||
setSelectedColumnIds([id]);
|
||||
break;
|
||||
default:
|
||||
// z. B. Legacy-„Tür"-Datensätze (project.doors) — kein Auswahl-Kanal.
|
||||
return;
|
||||
}
|
||||
const kindOf: Partial<Record<ScheduleKind, SelectionKind>> = {
|
||||
Wand: "walls",
|
||||
Decke: "ceilings",
|
||||
Fenster: "openings",
|
||||
Öffnung: "openings",
|
||||
Treppe: "stairs",
|
||||
Extrusion: "solids",
|
||||
Dach: "roofs",
|
||||
Stütze: "columns",
|
||||
};
|
||||
const k = kindOf[kind];
|
||||
setSelection({ ...clearKinds(), ...(k ? { [k]: [id] } : {}) });
|
||||
// z. B. Legacy-„Tür"-Datensätze (project.doors) — kein Auswahl-Kanal.
|
||||
if (!k) return;
|
||||
if (opts?.zoom) requestAnimationFrame(() => planViewRef.current?.fit());
|
||||
};
|
||||
if (floorId && floorId !== activeLevelId) {
|
||||
@@ -1534,7 +1489,6 @@ export function usePanelHostBase(opts: {
|
||||
section3dCutId,
|
||||
onToggleSection3dCut,
|
||||
selectedViewSnapshotId,
|
||||
selectedContextObjectIds,
|
||||
]);
|
||||
|
||||
return baseHost;
|
||||
|
||||
@@ -12,122 +12,48 @@
|
||||
import { useState } from "react";
|
||||
import { useStore } from "./appStore";
|
||||
import type { ElementClipboard } from "../editors/elementClipboard";
|
||||
import { single } from "./selection";
|
||||
|
||||
export function useSelectionState() {
|
||||
const selectedWallIds = useStore((s) => s.selectedWallIds);
|
||||
const setSelectedWallIds = useStore((s) => s.setSelectedWallIds);
|
||||
// 2D-Auswahl ist jetzt eine MENGE (Marquee/Mehrfach). Für die bestehende
|
||||
// Einzel-Element-Maschinerie (Grips, Edit, Attribute, Object-Info) wird lokal
|
||||
// der „eine" gewählte Zeichnungs-ID abgeleitet (nur bei genau einem Element);
|
||||
// `setSelectedDrawingId` bleibt als bequeme Einzel-Setter-Hülle erhalten.
|
||||
const selectedDrawingIds = useStore((s) => s.selectedDrawingIds);
|
||||
const setSelectedDrawingIds = useStore((s) => s.setSelectedDrawingIds);
|
||||
const selectedDrawingId =
|
||||
selectedDrawingIds.length === 1 ? selectedDrawingIds[0] : null;
|
||||
const setSelectedDrawingId = (id: string | null) =>
|
||||
setSelectedDrawingIds(id ? [id] : []);
|
||||
// Die ganze Auswahl (je Art eine Menge, [130]); App liest sie vollständig, die
|
||||
// Einzel-Element-Maschinerie (Grips, Edit, Attribute, Object-Info) bekommt je Art
|
||||
// das „eine" gewählte Element (nur bei genau einem).
|
||||
const selection = useStore((s) => s.selection);
|
||||
const setSelection = useStore((s) => s.setSelection);
|
||||
const clearSelection = useStore((s) => s.clearSelection);
|
||||
// Zwischenablage für ALLE Bauteil-Arten (Ctrl/Cmd+C/V) — Wand/Decke/Dach/
|
||||
// Öffnung/Treppe/Raum/Extrusion/Stütze + 2D-Zeichenelemente, s.
|
||||
// `editors/elementClipboard.ts`. Kopiert die GEWÄHLTEN Elemente tief;
|
||||
// Einfügen legt Klone mit neuen IDs auf dem AKTIVEN Geschoss an — so lässt
|
||||
// sich z. B. importiertes Mobiliar über Geschosse hinweg wiederverwenden.
|
||||
const [elementClipboard, setElementClipboard] = useState<ElementClipboard | null>(null);
|
||||
// Bequemer Einzel-Selektor (erste gewählte Wand).
|
||||
const selectedWallId = selectedWallIds[0] ?? null;
|
||||
// Decken-Auswahl (MENGE); für die Einzel-Element-Maschinerie der „eine"
|
||||
// gewählte (bei genau einem Element).
|
||||
const selectedCeilingIds = useStore((s) => s.selectedCeilingIds);
|
||||
const setSelectedCeilingIds = useStore((s) => s.setSelectedCeilingIds);
|
||||
const selectedCeilingId =
|
||||
selectedCeilingIds.length === 1 ? selectedCeilingIds[0] : null;
|
||||
// Dach-Auswahl (MENGE); Einzel-Element bei genau einem gewählten Dach.
|
||||
const selectedRoofIds = useStore((s) => s.selectedRoofIds);
|
||||
const setSelectedRoofIds = useStore((s) => s.setSelectedRoofIds);
|
||||
const selectedRoofId = selectedRoofIds.length === 1 ? selectedRoofIds[0] : null;
|
||||
// Schnitt-/Ansichtslinien-Auswahl (MENGE); Einzel-Element bei genau einer
|
||||
// gewählten Linie (Attribut-/Patch-Logik bleibt darauf zugeschnitten).
|
||||
const selectedSectionLineIds = useStore((s) => s.selectedSectionLineIds);
|
||||
const setSelectedSectionLineIds = useStore((s) => s.setSelectedSectionLineIds);
|
||||
const selectedSectionLineId =
|
||||
selectedSectionLineIds.length === 1 ? selectedSectionLineIds[0] : null;
|
||||
// Welche Schnittlinie treibt den 3D-Live-Schnitt (reiner Ansichts-Zustand,
|
||||
// unabhängig von der Auswahl — der Schnitt bleibt beim Klick woanders aktiv).
|
||||
const [section3dCutId, setSection3dCutId] = useState<string | null>(null);
|
||||
const updateRoof = useStore((s) => s.updateRoof);
|
||||
const moveRoofGrip = useStore((s) => s.moveRoofGrip);
|
||||
const moveRoofBy = useStore((s) => s.moveRoofBy);
|
||||
const selectedOpeningIds = useStore((s) => s.selectedOpeningIds);
|
||||
const setSelectedOpeningIds = useStore((s) => s.setSelectedOpeningIds);
|
||||
const selectedOpeningId =
|
||||
selectedOpeningIds.length === 1 ? selectedOpeningIds[0] : null;
|
||||
const selectedStairIds = useStore((s) => s.selectedStairIds);
|
||||
const setSelectedStairIds = useStore((s) => s.setSelectedStairIds);
|
||||
const selectedStairId =
|
||||
selectedStairIds.length === 1 ? selectedStairIds[0] : null;
|
||||
const selectedRoomIds = useStore((s) => s.selectedRoomIds);
|
||||
const setSelectedRoomIds = useStore((s) => s.setSelectedRoomIds);
|
||||
const selectedRoomId =
|
||||
selectedRoomIds.length === 1 ? selectedRoomIds[0] : null;
|
||||
const selectedExtrudedSolidIds = useStore((s) => s.selectedExtrudedSolidIds);
|
||||
const setSelectedExtrudedSolidIds = useStore((s) => s.setSelectedExtrudedSolidIds);
|
||||
const selectedExtrudedSolidId =
|
||||
selectedExtrudedSolidIds.length === 1 ? selectedExtrudedSolidIds[0] : null;
|
||||
const selectedColumnIds = useStore((s) => s.selectedColumnIds);
|
||||
const setSelectedColumnIds = useStore((s) => s.setSelectedColumnIds);
|
||||
const selectedColumnId =
|
||||
selectedColumnIds.length === 1 ? selectedColumnIds[0] : null;
|
||||
const selectedContextObjectIds = useStore((s) => s.selectedContextObjectIds);
|
||||
const setSelectedContextObjectIds = useStore((s) => s.setSelectedContextObjectIds);
|
||||
// Gruppen (Vectorworks-artig): gewählte Gruppen-IDs + Isolations-Pfad
|
||||
// ("Gruppe betreten"), s. `groupActions.ts`.
|
||||
const selectedGroupIds = useStore((s) => s.selectedGroupIds);
|
||||
const setSelectedGroupIds = useStore((s) => s.setSelectedGroupIds);
|
||||
// Gruppen (Vectorworks-artig): Isolations-Pfad ("Gruppe betreten"), s. `groupActions.ts`.
|
||||
const groupPath = useStore((s) => s.groupPath);
|
||||
const setGroupPath = useStore((s) => s.setGroupPath);
|
||||
|
||||
return {
|
||||
selectedWallIds,
|
||||
setSelectedWallIds,
|
||||
selectedDrawingIds,
|
||||
setSelectedDrawingIds,
|
||||
selectedDrawingId,
|
||||
setSelectedDrawingId,
|
||||
selection,
|
||||
setSelection,
|
||||
clearSelection,
|
||||
// Bequemer Einzel-Selektor (erste gewählte Wand).
|
||||
selectedWallId: selection.walls[0] ?? null,
|
||||
selectedDrawingId: single(selection, "drawings"),
|
||||
selectedCeilingId: single(selection, "ceilings"),
|
||||
selectedSectionLineId: single(selection, "sectionLines"),
|
||||
selectedRoomId: single(selection, "rooms"),
|
||||
elementClipboard,
|
||||
setElementClipboard,
|
||||
selectedWallId,
|
||||
selectedCeilingIds,
|
||||
setSelectedCeilingIds,
|
||||
selectedCeilingId,
|
||||
selectedRoofIds,
|
||||
setSelectedRoofIds,
|
||||
selectedRoofId,
|
||||
selectedSectionLineIds,
|
||||
setSelectedSectionLineIds,
|
||||
selectedSectionLineId,
|
||||
section3dCutId,
|
||||
setSection3dCutId,
|
||||
updateRoof,
|
||||
moveRoofGrip,
|
||||
moveRoofBy,
|
||||
selectedOpeningIds,
|
||||
setSelectedOpeningIds,
|
||||
selectedOpeningId,
|
||||
selectedStairIds,
|
||||
setSelectedStairIds,
|
||||
selectedStairId,
|
||||
selectedRoomIds,
|
||||
setSelectedRoomIds,
|
||||
selectedRoomId,
|
||||
selectedExtrudedSolidIds,
|
||||
setSelectedExtrudedSolidIds,
|
||||
selectedExtrudedSolidId,
|
||||
selectedColumnIds,
|
||||
setSelectedColumnIds,
|
||||
selectedColumnId,
|
||||
selectedContextObjectIds,
|
||||
setSelectedContextObjectIds,
|
||||
selectedGroupIds,
|
||||
setSelectedGroupIds,
|
||||
groupPath,
|
||||
setGroupPath,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user