2026-04-04 20:07:17 +02:00
|
|
|
import type { WhiteboxSelectionMode } from "./whitebox-selection-mode";
|
|
|
|
|
import type { BoxEdgeId, BoxFaceId, BoxVertexId } from "../document/brushes";
|
2026-03-31 02:33:18 +02:00
|
|
|
|
2026-03-31 01:29:35 +02:00
|
|
|
export type EditorSelection =
|
|
|
|
|
| { kind: "none" }
|
|
|
|
|
| { kind: "brushes"; ids: string[] }
|
2026-03-31 02:33:18 +02:00
|
|
|
| { kind: "brushFace"; brushId: string; faceId: BoxFaceId }
|
2026-04-04 20:07:17 +02:00
|
|
|
| { kind: "brushEdge"; brushId: string; edgeId: BoxEdgeId }
|
|
|
|
|
| { kind: "brushVertex"; brushId: string; vertexId: BoxVertexId }
|
2026-04-13 21:21:40 +02:00
|
|
|
| { kind: "paths"; ids: string[] }
|
2026-04-13 22:24:31 +02:00
|
|
|
| { kind: "pathPoint"; pathId: string; pointId: string }
|
2026-03-31 01:29:35 +02:00
|
|
|
| { kind: "entities"; ids: string[] }
|
|
|
|
|
| { kind: "modelInstances"; ids: string[] };
|
2026-03-31 02:02:34 +02:00
|
|
|
|
|
|
|
|
export function cloneEditorSelection(selection: EditorSelection): EditorSelection {
|
|
|
|
|
if (selection.kind === "none") {
|
|
|
|
|
return {
|
|
|
|
|
kind: "none"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:33:18 +02:00
|
|
|
if (selection.kind === "brushFace") {
|
|
|
|
|
return {
|
|
|
|
|
kind: "brushFace",
|
|
|
|
|
brushId: selection.brushId,
|
|
|
|
|
faceId: selection.faceId
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-04 20:07:17 +02:00
|
|
|
if (selection.kind === "brushEdge") {
|
|
|
|
|
return {
|
|
|
|
|
kind: "brushEdge",
|
|
|
|
|
brushId: selection.brushId,
|
|
|
|
|
edgeId: selection.edgeId
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (selection.kind === "brushVertex") {
|
|
|
|
|
return {
|
|
|
|
|
kind: "brushVertex",
|
|
|
|
|
brushId: selection.brushId,
|
|
|
|
|
vertexId: selection.vertexId
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 22:24:31 +02:00
|
|
|
if (selection.kind === "pathPoint") {
|
|
|
|
|
return {
|
|
|
|
|
kind: "pathPoint",
|
|
|
|
|
pathId: selection.pathId,
|
|
|
|
|
pointId: selection.pointId
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:02:34 +02:00
|
|
|
return {
|
|
|
|
|
kind: selection.kind,
|
|
|
|
|
ids: [...selection.ids]
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 02:09:14 +02:00
|
|
|
export function areEditorSelectionsEqual(left: EditorSelection, right: EditorSelection): boolean {
|
|
|
|
|
if (left.kind !== right.kind) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (left.kind) {
|
|
|
|
|
case "none":
|
|
|
|
|
return true;
|
|
|
|
|
case "brushFace":
|
|
|
|
|
return right.kind === "brushFace" && left.brushId === right.brushId && left.faceId === right.faceId;
|
2026-04-04 20:07:17 +02:00
|
|
|
case "brushEdge":
|
|
|
|
|
return right.kind === "brushEdge" && left.brushId === right.brushId && left.edgeId === right.edgeId;
|
|
|
|
|
case "brushVertex":
|
|
|
|
|
return right.kind === "brushVertex" && left.brushId === right.brushId && left.vertexId === right.vertexId;
|
2026-04-13 22:24:31 +02:00
|
|
|
case "pathPoint":
|
|
|
|
|
return right.kind === "pathPoint" && left.pathId === right.pathId && left.pointId === right.pointId;
|
2026-04-03 02:09:14 +02:00
|
|
|
case "brushes":
|
2026-04-13 21:21:40 +02:00
|
|
|
case "paths":
|
2026-04-03 02:09:14 +02:00
|
|
|
case "entities":
|
|
|
|
|
case "modelInstances":
|
|
|
|
|
return right.kind === left.kind && left.ids.length === right.ids.length && left.ids.every((id, index) => id === right.ids[index]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:02:34 +02:00
|
|
|
export function getSingleSelectedBrushId(selection: EditorSelection): string | null {
|
2026-04-04 20:07:17 +02:00
|
|
|
if (selection.kind === "brushFace" || selection.kind === "brushEdge" || selection.kind === "brushVertex") {
|
2026-03-31 02:33:18 +02:00
|
|
|
return selection.brushId;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:02:34 +02:00
|
|
|
if (selection.kind !== "brushes" || selection.ids.length !== 1) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return selection.ids[0];
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:33:18 +02:00
|
|
|
export function getSelectedBrushFaceId(selection: EditorSelection): BoxFaceId | null {
|
|
|
|
|
if (selection.kind !== "brushFace") {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return selection.faceId;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-04 20:07:17 +02:00
|
|
|
export function getSelectedBrushEdgeId(selection: EditorSelection): BoxEdgeId | null {
|
|
|
|
|
if (selection.kind !== "brushEdge") {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return selection.edgeId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getSelectedBrushVertexId(selection: EditorSelection): BoxVertexId | null {
|
|
|
|
|
if (selection.kind !== "brushVertex") {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return selection.vertexId;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 03:00:38 +02:00
|
|
|
export function getSingleSelectedEntityId(selection: EditorSelection): string | null {
|
|
|
|
|
if (selection.kind !== "entities" || selection.ids.length !== 1) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return selection.ids[0];
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 21:21:40 +02:00
|
|
|
export function getSingleSelectedPathId(selection: EditorSelection): string | null {
|
|
|
|
|
if (selection.kind !== "paths" || selection.ids.length !== 1) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return selection.ids[0];
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 22:24:31 +02:00
|
|
|
export function getSingleSelectedPathPoint(selection: EditorSelection): { pathId: string; pointId: string } | null {
|
|
|
|
|
if (selection.kind !== "pathPoint") {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
pathId: selection.pathId,
|
|
|
|
|
pointId: selection.pointId
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getSingleSelectedPathOwnerId(selection: EditorSelection): string | null {
|
|
|
|
|
if (selection.kind === "pathPoint") {
|
|
|
|
|
return selection.pathId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return getSingleSelectedPathId(selection);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 17:36:43 +02:00
|
|
|
export function getSingleSelectedModelInstanceId(selection: EditorSelection): string | null {
|
|
|
|
|
if (selection.kind !== "modelInstances" || selection.ids.length !== 1) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return selection.ids[0];
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 02:02:34 +02:00
|
|
|
export function isBrushSelected(selection: EditorSelection, brushId: string): boolean {
|
2026-03-31 02:33:18 +02:00
|
|
|
return (
|
|
|
|
|
(selection.kind === "brushes" && selection.ids.includes(brushId)) ||
|
2026-04-04 20:07:17 +02:00
|
|
|
((selection.kind === "brushFace" || selection.kind === "brushEdge" || selection.kind === "brushVertex") &&
|
|
|
|
|
selection.brushId === brushId)
|
2026-03-31 02:33:18 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isBrushFaceSelected(selection: EditorSelection, brushId: string, faceId: BoxFaceId): boolean {
|
|
|
|
|
return selection.kind === "brushFace" && selection.brushId === brushId && selection.faceId === faceId;
|
2026-03-31 02:02:34 +02:00
|
|
|
}
|
2026-03-31 17:36:43 +02:00
|
|
|
|
2026-04-04 20:07:17 +02:00
|
|
|
export function isBrushEdgeSelected(selection: EditorSelection, brushId: string, edgeId: BoxEdgeId): boolean {
|
|
|
|
|
return selection.kind === "brushEdge" && selection.brushId === brushId && selection.edgeId === edgeId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isBrushVertexSelected(selection: EditorSelection, brushId: string, vertexId: BoxVertexId): boolean {
|
|
|
|
|
return selection.kind === "brushVertex" && selection.brushId === brushId && selection.vertexId === vertexId;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 17:36:43 +02:00
|
|
|
export function isModelInstanceSelected(selection: EditorSelection, modelInstanceId: string): boolean {
|
|
|
|
|
return selection.kind === "modelInstances" && selection.ids.includes(modelInstanceId);
|
|
|
|
|
}
|
2026-04-04 20:07:17 +02:00
|
|
|
|
2026-04-13 21:21:40 +02:00
|
|
|
export function isPathSelected(selection: EditorSelection, pathId: string): boolean {
|
2026-04-13 22:24:31 +02:00
|
|
|
return (
|
|
|
|
|
(selection.kind === "paths" && selection.ids.includes(pathId)) ||
|
|
|
|
|
(selection.kind === "pathPoint" && selection.pathId === pathId)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isPathPointSelected(selection: EditorSelection, pathId: string, pointId: string): boolean {
|
|
|
|
|
return selection.kind === "pathPoint" && selection.pathId === pathId && selection.pointId === pointId;
|
2026-04-13 21:21:40 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-04 20:07:17 +02:00
|
|
|
export function normalizeSelectionForWhiteboxSelectionMode(selection: EditorSelection, mode: WhiteboxSelectionMode): EditorSelection {
|
|
|
|
|
switch (selection.kind) {
|
|
|
|
|
case "brushFace":
|
|
|
|
|
return mode === "face"
|
|
|
|
|
? selection
|
|
|
|
|
: {
|
|
|
|
|
kind: "brushes",
|
|
|
|
|
ids: [selection.brushId]
|
|
|
|
|
};
|
|
|
|
|
case "brushEdge":
|
|
|
|
|
return mode === "edge"
|
|
|
|
|
? selection
|
|
|
|
|
: {
|
|
|
|
|
kind: "brushes",
|
|
|
|
|
ids: [selection.brushId]
|
|
|
|
|
};
|
|
|
|
|
case "brushVertex":
|
|
|
|
|
return mode === "vertex"
|
|
|
|
|
? selection
|
|
|
|
|
: {
|
|
|
|
|
kind: "brushes",
|
|
|
|
|
ids: [selection.brushId]
|
|
|
|
|
};
|
|
|
|
|
default:
|
|
|
|
|
return selection;
|
|
|
|
|
}
|
|
|
|
|
}
|