Persist project workspace settings

This commit is contained in:
Formsmith
2026-06-13 10:26:40 +03:00
parent f1d914e2c3
commit 7457c94581
8 changed files with 193 additions and 21 deletions
+7
View File
@@ -1603,6 +1603,13 @@ button {
pointer-events: none; pointer-events: none;
} }
.transform-overlay.hide-selection-chrome .transform-guides,
.transform-overlay.hide-selection-chrome .dimension-label,
.transform-overlay.hide-selection-chrome .transform-handle,
.transform-overlay.hide-selection-chrome .rotate-handle {
opacity: 0;
}
.transform-guides line { .transform-guides line {
stroke: rgba(31, 39, 46, 0.72); stroke: rgba(31, 39, 46, 0.72);
stroke-width: 1.15; stroke-width: 1.15;
+35 -1
View File
@@ -3,7 +3,8 @@
import { Clock3, FileUp, Grid3X3, HomeIcon, List, Plus, Search, Settings, SlidersHorizontal, Trash2, X } from "lucide-react"; import { Clock3, FileUp, Grid3X3, HomeIcon, List, Plus, Search, Settings, SlidersHorizontal, Trash2, X } from "lucide-react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { SketchForgeEditor, importedShapeFromStl } from "@/components/SketchForgeEditor"; import { SketchForgeEditor, importedShapeFromStl } from "@/components/SketchForgeEditor";
import type { WorkplaneShape } from "@/types/sketchforge"; import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE, normalizeSnapGrid, normalizeWorkspaceSettings } from "@/lib/workplaneSettings";
import type { GridSize, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
type AppView = "dashboard" | "editor"; type AppView = "dashboard" | "editor";
type ViewMode = "grid" | "list"; type ViewMode = "grid" | "list";
@@ -19,6 +20,8 @@ type DashboardProject = {
thumbnailUrl?: string | null; thumbnailUrl?: string | null;
thumbnailVersion?: number; thumbnailVersion?: number;
revision?: number; revision?: number;
workspace?: WorkplaneWorkspaceSettings;
snapGrid?: GridSize;
}; };
type StoredDashboardProject = Partial<DashboardProject> & { type StoredDashboardProject = Partial<DashboardProject> & {
@@ -145,6 +148,8 @@ function readStoredProjects() {
thumbnailUrl: typeof project.thumbnailUrl === "string" ? project.thumbnailUrl : null, thumbnailUrl: typeof project.thumbnailUrl === "string" ? project.thumbnailUrl : null,
thumbnailVersion: typeof project.thumbnailVersion === "number" ? project.thumbnailVersion : undefined, thumbnailVersion: typeof project.thumbnailVersion === "number" ? project.thumbnailVersion : undefined,
revision, revision,
workspace: normalizeWorkspaceSettings(project.workspace),
snapGrid: normalizeSnapGrid(project.snapGrid),
}; };
}); });
return { projects, legacyShapes }; return { projects, legacyShapes };
@@ -173,6 +178,8 @@ function mergeProjectForStorage(project: DashboardProject, storedProject?: Dashb
thumbnailUrl: project.thumbnailUrl ?? storedProject.thumbnailUrl, thumbnailUrl: project.thumbnailUrl ?? storedProject.thumbnailUrl,
thumbnailVersion: project.thumbnailVersion ?? storedProject.thumbnailVersion, thumbnailVersion: project.thumbnailVersion ?? storedProject.thumbnailVersion,
updatedAt: Math.max(project.updatedAt, storedProject.updatedAt), updatedAt: Math.max(project.updatedAt, storedProject.updatedAt),
workspace: project.workspace ?? storedProject.workspace,
snapGrid: project.snapGrid ?? storedProject.snapGrid,
}; };
} }
@@ -187,6 +194,8 @@ function projectForStorage(project: DashboardProject): DashboardProject {
thumbnailUrl: project.thumbnailUrl ?? null, thumbnailUrl: project.thumbnailUrl ?? null,
thumbnailVersion: project.thumbnailVersion, thumbnailVersion: project.thumbnailVersion,
revision: project.revision, revision: project.revision,
workspace: normalizeWorkspaceSettings(project.workspace),
snapGrid: normalizeSnapGrid(project.snapGrid),
}; };
} }
@@ -206,6 +215,8 @@ function newProject(name: string, index: number, shapeCount = 0): DashboardProje
shapes: shapeCount, shapes: shapeCount,
accent: PROJECT_ACCENTS[index % PROJECT_ACCENTS.length], accent: PROJECT_ACCENTS[index % PROJECT_ACCENTS.length],
revision: now, revision: now,
workspace: DEFAULT_WORKPLANE_WORKSPACE,
snapGrid: DEFAULT_SNAP_GRID,
}; };
} }
@@ -423,6 +434,24 @@ export default function Home() {
}); });
}, []); }, []);
const updateProjectWorkspace = useCallback((snapshot: { projectId: string; workspace: WorkplaneWorkspaceSettings; snap: GridSize }) => {
const version = Date.now();
const workspace = normalizeWorkspaceSettings(snapshot.workspace);
const snapGrid = normalizeSnapGrid(snapshot.snap);
setProjects((current) =>
current.map((project) =>
project.id === snapshot.projectId
? {
...project,
workspace,
snapGrid,
updatedAt: version,
}
: project,
),
);
}, []);
const createAndOpenProject = (name?: string) => { const createAndOpenProject = (name?: string) => {
const project = newProject(name ?? `Untitled design ${projects.length + 1}`, projects.length); const project = newProject(name ?? `Untitled design ${projects.length + 1}`, projects.length);
setProjectShapesById((current) => ({ setProjectShapesById((current) => ({
@@ -511,6 +540,8 @@ export default function Home() {
shapes: project.shapes, shapes: project.shapes,
designShapes: projectShapesById[project.id]?.shapes.length ?? null, designShapes: projectShapesById[project.id]?.shapes.length ?? null,
thumbnail: Boolean(project.thumbnailUrl), thumbnail: Boolean(project.thumbnailUrl),
workspace: Boolean(project.workspace),
snapGrid: project.snapGrid ?? null,
})); }));
return ( return (
@@ -559,9 +590,12 @@ export default function Home() {
<div className={view === "editor" ? "editor-stage active" : "editor-stage"} aria-hidden={view !== "editor"}> <div className={view === "editor" ? "editor-stage active" : "editor-stage"} aria-hidden={view !== "editor"}>
<SketchForgeEditor <SketchForgeEditor
initialShapes={activeProjectShapeEntry?.shapes ?? []} initialShapes={activeProjectShapeEntry?.shapes ?? []}
initialSnap={activeProject?.snapGrid ?? DEFAULT_SNAP_GRID}
initialWorkspace={activeProject?.workspace ?? DEFAULT_WORKPLANE_WORKSPACE}
onHome={openDashboard} onHome={openDashboard}
onProjectShapesChange={updateProjectShapes} onProjectShapesChange={updateProjectShapes}
onProjectSnapshot={updateProjectSnapshot} onProjectSnapshot={updateProjectSnapshot}
onProjectWorkspaceChange={updateProjectWorkspace}
projectId={activeProjectId} projectId={activeProjectId}
projectRevision={activeProjectShapeEntry?.revision ?? activeProject?.revision ?? 0} projectRevision={activeProjectShapeEntry?.revision ?? activeProject?.revision ?? 0}
/> />
+21 -1
View File
@@ -42,7 +42,7 @@ import {
ToolbarVectorExportIcon, ToolbarVectorExportIcon,
} from "./icons"; } from "./icons";
import { WorkplaneViewport } from "./WorkplaneViewport"; import { WorkplaneViewport } from "./WorkplaneViewport";
import type { AlignAxis, AlignHandleStatus, AlignTarget, ShapeAsset, WorkplaneShape } from "@/types/sketchforge"; import type { AlignAxis, AlignHandleStatus, AlignTarget, GridSize, ShapeAsset, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
type TopPanel = "import" | "export" | "builder" | "tips" | "profile" | "settings" | null; type TopPanel = "import" | "export" | "builder" | "tips" | "profile" | "settings" | null;
type ExportFormat = "stl" | "obj"; type ExportFormat = "stl" | "obj";
@@ -4142,16 +4142,22 @@ function projectShapesFingerprint(shapes: WorkplaneShape[]) {
export function SketchForgeEditor({ export function SketchForgeEditor({
initialShapes = [], initialShapes = [],
initialSnap,
initialWorkspace,
onHome, onHome,
onProjectShapesChange, onProjectShapesChange,
onProjectSnapshot, onProjectSnapshot,
onProjectWorkspaceChange,
projectId, projectId,
projectRevision = 0, projectRevision = 0,
}: { }: {
initialShapes?: WorkplaneShape[]; initialShapes?: WorkplaneShape[];
initialSnap?: GridSize;
initialWorkspace?: WorkplaneWorkspaceSettings;
onHome?: () => void; onHome?: () => void;
onProjectShapesChange?: (snapshot: { projectId: string; shapes: WorkplaneShape[] }) => void; onProjectShapesChange?: (snapshot: { projectId: string; shapes: WorkplaneShape[] }) => void;
onProjectSnapshot?: (snapshot: { image: string; projectId: string; shapes: number }) => void; onProjectSnapshot?: (snapshot: { image: string; projectId: string; shapes: number }) => void;
onProjectWorkspaceChange?: (snapshot: { projectId: string; workspace: WorkplaneWorkspaceSettings; snap: GridSize }) => void;
projectId?: string | null; projectId?: string | null;
projectRevision?: number; projectRevision?: number;
} = {}) { } = {}) {
@@ -4333,6 +4339,16 @@ export function SketchForgeEditor({
setProjectInteractionActive((current) => (current === active ? current : active)); setProjectInteractionActive((current) => (current === active ? current : active));
}, []); }, []);
const updateProjectWorkspaceSettings = useCallback(
(settings: { workspace: WorkplaneWorkspaceSettings; snap: GridSize }) => {
if (!projectId || !onProjectWorkspaceChange) {
return;
}
onProjectWorkspaceChange({ projectId, ...settings });
},
[onProjectWorkspaceChange, projectId],
);
const commitShapes = useCallback( const commitShapes = useCallback(
(next: WorkplaneShape[], nextSelection: string | string[] | null = selectedIds, message?: string) => { (next: WorkplaneShape[], nextSelection: string | string[] | null = selectedIds, message?: string) => {
const canonicalNext = next.map(canonicalizeShape); const canonicalNext = next.map(canonicalizeShape);
@@ -5448,6 +5464,9 @@ export function SketchForgeEditor({
mirrorReferenceShapes={shapes} mirrorReferenceShapes={shapes}
placementElevation={placementElevation} placementElevation={placementElevation}
workplaneMode={workplaneMode} workplaneMode={workplaneMode}
initialSnap={initialSnap}
initialWorkspace={initialWorkspace}
workspaceSettingsKey={projectId ?? "local-workplane"}
onAddShape={addShape} onAddShape={addShape}
onAlignAnchorChange={chooseAlignAnchor} onAlignAnchorChange={chooseAlignAnchor}
onAlignPreview={previewAlignSelection} onAlignPreview={previewAlignSelection}
@@ -5460,6 +5479,7 @@ export function SketchForgeEditor({
onSetPlacementElevation={setPlacementWorkplane} onSetPlacementElevation={setPlacementWorkplane}
onInteractionActiveChange={updateProjectInteractionActive} onInteractionActiveChange={updateProjectInteractionActive}
onUpdateShape={updateShape} onUpdateShape={updateShape}
onWorkspaceSettingsChange={updateProjectWorkspaceSettings}
onWorkplaneModeChange={setWorkplaneMode} onWorkplaneModeChange={setWorkplaneMode}
/> />
</div> </div>
+54 -18
View File
@@ -15,6 +15,7 @@ import helvetikerBoldFontJson from "three/examples/fonts/helvetiker_bold.typefac
import optimerBoldFontJson from "three/examples/fonts/optimer_bold.typeface.json"; import optimerBoldFontJson from "three/examples/fonts/optimer_bold.typeface.json";
import { ToolbarHideSelectedIcon } from "@/components/icons"; import { ToolbarHideSelectedIcon } from "@/components/icons";
import { AlignOverlay, MirrorOverlay, type AlignOverlayState, type MirrorOverlayState } from "@/components/workplane/ActionOverlays"; import { AlignOverlay, MirrorOverlay, type AlignOverlayState, type MirrorOverlayState } from "@/components/workplane/ActionOverlays";
import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE, normalizeSnapGrid, normalizeWorkspaceSettings, workplaneSettingsFingerprint } from "@/lib/workplaneSettings";
import { import {
TransformOverlay, TransformOverlay,
getElevationMeasureKey, getElevationMeasureKey,
@@ -30,7 +31,7 @@ import {
type TransformHandleKind, type TransformHandleKind,
type TransformOverlayState, type TransformOverlayState,
} from "@/components/workplane/TransformOverlay"; } from "@/components/workplane/TransformOverlay";
import type { AlignAxis, AlignHandleStatus, AlignTarget, GridSize, ShapeAsset, WorkplaneShape } from "@/types/sketchforge"; import type { AlignAxis, AlignHandleStatus, AlignTarget, GridSize, ShapeAsset, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
const gridSizes: GridSize[] = ["Off", "0.1 mm", "0.25 mm", "0.5 mm", "1.0 mm", "2.0 mm", "5.0 mm", "Brick"]; const gridSizes: GridSize[] = ["Off", "0.1 mm", "0.25 mm", "0.5 mm", "1.0 mm", "2.0 mm", "5.0 mm", "Brick"];
const WORKPLANE_WIDTH = 200; const WORKPLANE_WIDTH = 200;
@@ -39,20 +40,7 @@ const MIN_WORKSPACE_SIZE = 60;
const MAX_WORKSPACE_SIZE = 2000; const MAX_WORKSPACE_SIZE = 2000;
const MIN_GRID_BLOCK_SIZE = 1; const MIN_GRID_BLOCK_SIZE = 1;
const MAX_GRID_BLOCK_SIZE = 200; const MAX_GRID_BLOCK_SIZE = 200;
const DEFAULT_WORKSPACE = { const DEFAULT_WORKSPACE = DEFAULT_WORKPLANE_WORKSPACE;
width: 200,
depth: 200,
sizePreset: "200 x 200 mm",
gridBlockSize: 5,
gridBlockPreset: "5 mm",
background: "#f8fbfc",
showShadows: true,
showGrid: true,
cruiseShapes: true,
zoomSpeed: 5,
units: "Metric (Default)",
scale: "1:1 (millimeters)",
};
const workspaceSizePresets = [ const workspaceSizePresets = [
{ label: "200 x 200 mm", width: 200, depth: 200 }, { label: "200 x 200 mm", width: 200, depth: 200 },
{ label: "300 x 300 mm", width: 300, depth: 300 }, { label: "300 x 300 mm", width: 300, depth: 300 },
@@ -128,6 +116,9 @@ type WorkplaneViewportProps = {
mirrorReferenceShapes: WorkplaneShape[]; mirrorReferenceShapes: WorkplaneShape[];
placementElevation: number; placementElevation: number;
workplaneMode: boolean; workplaneMode: boolean;
initialSnap?: GridSize;
initialWorkspace?: WorkplaneWorkspaceSettings;
workspaceSettingsKey?: string | null;
onAddShape: (shape: ShapeAsset, point?: { x: number; z: number; elevation?: number }) => void; onAddShape: (shape: ShapeAsset, point?: { x: number; z: number; elevation?: number }) => void;
onAlignAnchorChange: (id: string) => void; onAlignAnchorChange: (id: string) => void;
onAlignPreview: (axis: AlignAxis, target: AlignTarget) => void; onAlignPreview: (axis: AlignAxis, target: AlignTarget) => void;
@@ -140,10 +131,11 @@ type WorkplaneViewportProps = {
onSetPlacementElevation: (elevation: number, source: "shape" | "base") => void; onSetPlacementElevation: (elevation: number, source: "shape" | "base") => void;
onInteractionActiveChange?: (active: boolean) => void; onInteractionActiveChange?: (active: boolean) => void;
onUpdateShape: (id: string, patch: ShapeUpdatePatch) => void; onUpdateShape: (id: string, patch: ShapeUpdatePatch) => void;
onWorkspaceSettingsChange?: (settings: { workspace: WorkplaneWorkspaceSettings; snap: GridSize }) => void;
onWorkplaneModeChange: (active: boolean) => void; onWorkplaneModeChange: (active: boolean) => void;
}; };
type WorkspaceSettings = typeof DEFAULT_WORKSPACE; type WorkspaceSettings = WorkplaneWorkspaceSettings;
type ThreeState = { type ThreeState = {
renderer: THREE.WebGLRenderer; renderer: THREE.WebGLRenderer;
@@ -875,6 +867,9 @@ export function WorkplaneViewport({
mirrorReferenceShapes, mirrorReferenceShapes,
placementElevation, placementElevation,
workplaneMode, workplaneMode,
initialSnap,
initialWorkspace,
workspaceSettingsKey,
onAddShape, onAddShape,
onAlignAnchorChange, onAlignAnchorChange,
onAlignPreview, onAlignPreview,
@@ -887,12 +882,13 @@ export function WorkplaneViewport({
onSetPlacementElevation, onSetPlacementElevation,
onInteractionActiveChange, onInteractionActiveChange,
onUpdateShape, onUpdateShape,
onWorkspaceSettingsChange,
onWorkplaneModeChange, onWorkplaneModeChange,
}: WorkplaneViewportProps) { }: WorkplaneViewportProps) {
const [snapOpen, setSnapOpen] = useState(false); const [snapOpen, setSnapOpen] = useState(false);
const [snap, setSnap] = useState<GridSize>("1.0 mm"); const [snap, setSnap] = useState<GridSize>(() => normalizeSnapGrid(initialSnap, DEFAULT_SNAP_GRID));
const [settingsOpen, setSettingsOpen] = useState(false); const [settingsOpen, setSettingsOpen] = useState(false);
const [workspace, setWorkspace] = useState<WorkspaceSettings>(DEFAULT_WORKSPACE); const [workspace, setWorkspace] = useState<WorkspaceSettings>(() => normalizeWorkspaceSettings(initialWorkspace));
const [transformOverlay, setTransformOverlay] = useState<TransformOverlayState | null>(null); const [transformOverlay, setTransformOverlay] = useState<TransformOverlayState | null>(null);
const [alignOverlay, setAlignOverlay] = useState<AlignOverlayState | null>(null); const [alignOverlay, setAlignOverlay] = useState<AlignOverlayState | null>(null);
const [mirrorOverlay, setMirrorOverlay] = useState<MirrorOverlayState | null>(null); const [mirrorOverlay, setMirrorOverlay] = useState<MirrorOverlayState | null>(null);
@@ -918,6 +914,8 @@ export function WorkplaneViewport({
const suppressNextLiftEditRef = useRef(false); const suppressNextLiftEditRef = useRef(false);
const snapRef = useRef(snap); const snapRef = useRef(snap);
const workspaceRef = useRef(workspace); const workspaceRef = useRef(workspace);
const workspaceSettingsKeyRef = useRef(workspaceSettingsKey ?? null);
const lastWorkspaceSettingsSyncRef = useRef("");
const viewCubeRef = useRef<HTMLDivElement | null>(null); const viewCubeRef = useRef<HTMLDivElement | null>(null);
const transformOverlayRef = useRef<TransformOverlayState | null>(null); const transformOverlayRef = useRef<TransformOverlayState | null>(null);
const alignOverlayRef = useRef<AlignOverlayState | null>(null); const alignOverlayRef = useRef<AlignOverlayState | null>(null);
@@ -940,6 +938,27 @@ export function WorkplaneViewport({
const placementElevationRef = useRef(placementElevation); const placementElevationRef = useRef(placementElevation);
const workplaneModeRef = useRef(workplaneMode); const workplaneModeRef = useRef(workplaneMode);
useEffect(() => {
const nextKey = workspaceSettingsKey ?? null;
if (workspaceSettingsKeyRef.current !== nextKey) {
workspaceSettingsKeyRef.current = nextKey;
lastWorkspaceSettingsSyncRef.current = "";
}
setSnap(normalizeSnapGrid(initialSnap, DEFAULT_SNAP_GRID));
setWorkspace(normalizeWorkspaceSettings(initialWorkspace));
}, [initialSnap, initialWorkspace, workspaceSettingsKey]);
useEffect(() => {
const normalizedWorkspace = normalizeWorkspaceSettings(workspace);
const normalizedSnap = normalizeSnapGrid(snap, DEFAULT_SNAP_GRID);
const fingerprint = workplaneSettingsFingerprint(normalizedWorkspace, normalizedSnap);
if (lastWorkspaceSettingsSyncRef.current === fingerprint) {
return;
}
lastWorkspaceSettingsSyncRef.current = fingerprint;
onWorkspaceSettingsChange?.({ workspace: normalizedWorkspace, snap: normalizedSnap });
}, [onWorkspaceSettingsChange, snap, workspace]);
useEffect(() => { useEffect(() => {
const openWorkspaceSettings = () => setSettingsOpen(true); const openWorkspaceSettings = () => setSettingsOpen(true);
window.addEventListener("sketchforge:open-workspace-settings", openWorkspaceSettings); window.addEventListener("sketchforge:open-workspace-settings", openWorkspaceSettings);
@@ -1033,6 +1052,10 @@ export function WorkplaneViewport({
} }
}, [workspace]); }, [workspace]);
useEffect(() => {
setSelectionHelpersVisible(threeRef.current, activeTransformKind !== "rotate");
}, [activeTransformKind]);
useEffect(() => { useEffect(() => {
const host = hostRef.current; const host = hostRef.current;
if (!host) { if (!host) {
@@ -1254,6 +1277,7 @@ export function WorkplaneViewport({
} }
setActiveRotationWheel(kind === "rotate"); setActiveRotationWheel(kind === "rotate");
setActiveTransformKind(kind); setActiveTransformKind(kind);
setSelectionHelpersVisible(state ?? null, kind !== "rotate");
if (kind === "rotate") { if (kind === "rotate") {
setRotationWheelAxis(rotationAxis); setRotationWheelAxis(rotationAxis);
setPinnedRotationWheelView(wheel && rotationPlane ? { axis: rotationAxis, wheel: { ...wheel }, plane: { ...rotationPlane } } : null); setPinnedRotationWheelView(wheel && rotationPlane ? { axis: rotationAxis, wheel: { ...wheel }, plane: { ...rotationPlane } } : null);
@@ -1501,6 +1525,7 @@ export function WorkplaneViewport({
setPinnedRotationWheelView(null); setPinnedRotationWheelView(null);
setRotationReadout(null); setRotationReadout(null);
if (threeRef.current) { if (threeRef.current) {
setSelectionHelpersVisible(threeRef.current, true);
threeRef.current.controls.enabled = true; threeRef.current.controls.enabled = true;
} }
onInteractionActiveChange?.(false); onInteractionActiveChange?.(false);
@@ -1743,6 +1768,7 @@ export function WorkplaneViewport({
} }
setActiveRotationWheel(handle.kind === "rotate"); setActiveRotationWheel(handle.kind === "rotate");
setActiveTransformKind(handle.kind); setActiveTransformKind(handle.kind);
setSelectionHelpersVisible(state, handle.kind !== "rotate");
if (handle.kind === "rotate") { if (handle.kind === "rotate") {
setRotationWheelAxis(rotationAxis); setRotationWheelAxis(rotationAxis);
setPinnedRotationWheelView(wheel && rotationPlane ? { axis: rotationAxis, wheel: { ...wheel }, plane: { ...rotationPlane } } : null); setPinnedRotationWheelView(wheel && rotationPlane ? { axis: rotationAxis, wheel: { ...wheel }, plane: { ...rotationPlane } } : null);
@@ -2001,6 +2027,7 @@ export function WorkplaneViewport({
setActiveTransformKind(null); setActiveTransformKind(null);
setRotationReadout(null); setRotationReadout(null);
if (state) { if (state) {
setSelectionHelpersVisible(state, true);
state.controls.enabled = true; state.controls.enabled = true;
} }
onInteractionActiveChange?.(false); onInteractionActiveChange?.(false);
@@ -2194,6 +2221,7 @@ export function WorkplaneViewport({
editingRotation={editingRotation} editingRotation={editingRotation}
rotationReadout={rotationReadout} rotationReadout={rotationReadout}
showRotationWheel={activeRotationWheel} showRotationWheel={activeRotationWheel}
hideSelectionChrome={activeTransformKind === "rotate"}
hideDimensionMarks={activeTransformKind === "scale"} hideDimensionMarks={activeTransformKind === "scale"}
rotationWheelAxis={rotationWheelAxis} rotationWheelAxis={rotationWheelAxis}
pinnedRotationWheelView={pinnedRotationWheelView} pinnedRotationWheelView={pinnedRotationWheelView}
@@ -3157,6 +3185,14 @@ function rebuildSelectionHelpers(state: ThreeState | null, shapes: WorkplaneShap
}); });
} }
function setSelectionHelpersVisible(state: ThreeState | null, visible: boolean) {
if (!state || state.helperLayer.visible === visible) {
return;
}
state.helperLayer.visible = visible;
state.needsRender = true;
}
function formatMeasure(value: number) { function formatMeasure(value: number) {
return cleanNearZero(value).toFixed(2); return cleanNearZero(value).toFixed(2);
} }
@@ -28,6 +28,7 @@ export function TransformOverlay({
editingRotation, editingRotation,
rotationReadout, rotationReadout,
showRotationWheel, showRotationWheel,
hideSelectionChrome,
hideDimensionMarks, hideDimensionMarks,
rotationWheelAxis, rotationWheelAxis,
pinnedRotationWheelView, pinnedRotationWheelView,
@@ -74,7 +75,7 @@ export function TransformOverlay({
const plane = pinnedWheel?.plane ?? box.rotationPlanes[rotationWheelAxis]; const plane = pinnedWheel?.plane ?? box.rotationPlanes[rotationWheelAxis];
const wheel = pinnedWheel?.wheel ?? box.rotationWheels[rotationWheelAxis] ?? box.rotationWheel; const wheel = pinnedWheel?.wheel ?? box.rotationWheels[rotationWheelAxis] ?? box.rotationWheel;
return ( return (
<div className="transform-overlay" aria-hidden="true"> <div className={`transform-overlay ${hideSelectionChrome ? "hide-selection-chrome" : ""}`} aria-hidden="true">
{showRotationWheel && wheel && plane ? ( {showRotationWheel && wheel && plane ? (
<svg <svg
className={`rotation-protractor-plane axis-${rotationWheelAxis}`} className={`rotation-protractor-plane axis-${rotationWheelAxis}`}
@@ -84,6 +84,7 @@ export type TransformOverlayProps = {
editingRotation: EditingRotation; editingRotation: EditingRotation;
rotationReadout: RotationReadout; rotationReadout: RotationReadout;
showRotationWheel: boolean; showRotationWheel: boolean;
hideSelectionChrome: boolean;
hideDimensionMarks: boolean; hideDimensionMarks: boolean;
rotationWheelAxis: RotationAxis; rotationWheelAxis: RotationAxis;
pinnedRotationWheelView: PinnedRotationWheelView | null; pinnedRotationWheelView: PinnedRotationWheelView | null;
+58
View File
@@ -0,0 +1,58 @@
import type { GridSize, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
export const DEFAULT_SNAP_GRID: GridSize = "1.0 mm";
export const DEFAULT_WORKPLANE_WORKSPACE: WorkplaneWorkspaceSettings = {
width: 200,
depth: 200,
sizePreset: "200 x 200 mm",
gridBlockSize: 5,
gridBlockPreset: "5 mm",
background: "#f8fbfc",
showShadows: true,
showGrid: true,
cruiseShapes: true,
zoomSpeed: 5,
units: "Metric (Default)",
scale: "1:1 (millimeters)",
};
const snapGridOptions: GridSize[] = ["Off", "0.1 mm", "0.25 mm", "0.5 mm", "1.0 mm", "2.0 mm", "5.0 mm", "Brick"];
function numberOrDefault(value: unknown, fallback: number) {
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
}
function stringOrDefault(value: unknown, fallback: string) {
return typeof value === "string" && value.trim() ? value : fallback;
}
function booleanOrDefault(value: unknown, fallback: boolean) {
return typeof value === "boolean" ? value : fallback;
}
export function normalizeSnapGrid(value: unknown, fallback: GridSize = DEFAULT_SNAP_GRID): GridSize {
return snapGridOptions.includes(value as GridSize) ? (value as GridSize) : fallback;
}
export function normalizeWorkspaceSettings(value: unknown, fallback: WorkplaneWorkspaceSettings = DEFAULT_WORKPLANE_WORKSPACE): WorkplaneWorkspaceSettings {
const candidate = value && typeof value === "object" ? (value as Partial<WorkplaneWorkspaceSettings>) : {};
return {
width: numberOrDefault(candidate.width, fallback.width),
depth: numberOrDefault(candidate.depth, fallback.depth),
sizePreset: stringOrDefault(candidate.sizePreset, fallback.sizePreset),
gridBlockSize: numberOrDefault(candidate.gridBlockSize, fallback.gridBlockSize),
gridBlockPreset: stringOrDefault(candidate.gridBlockPreset, fallback.gridBlockPreset),
background: stringOrDefault(candidate.background, fallback.background),
showShadows: booleanOrDefault(candidate.showShadows, fallback.showShadows),
showGrid: booleanOrDefault(candidate.showGrid, fallback.showGrid),
cruiseShapes: booleanOrDefault(candidate.cruiseShapes, fallback.cruiseShapes),
zoomSpeed: numberOrDefault(candidate.zoomSpeed, fallback.zoomSpeed),
units: stringOrDefault(candidate.units, fallback.units),
scale: stringOrDefault(candidate.scale, fallback.scale),
};
}
export function workplaneSettingsFingerprint(workspace: WorkplaneWorkspaceSettings, snapGrid: GridSize) {
return JSON.stringify({ workspace, snapGrid });
}
+15
View File
@@ -31,6 +31,21 @@ export type ShapeAsset = {
export type GridSize = "Off" | "0.1 mm" | "0.25 mm" | "0.5 mm" | "1.0 mm" | "2.0 mm" | "5.0 mm" | "Brick"; export type GridSize = "Off" | "0.1 mm" | "0.25 mm" | "0.5 mm" | "1.0 mm" | "2.0 mm" | "5.0 mm" | "Brick";
export type WorkplaneWorkspaceSettings = {
width: number;
depth: number;
sizePreset: string;
gridBlockSize: number;
gridBlockPreset: string;
background: string;
showShadows: boolean;
showGrid: boolean;
cruiseShapes: boolean;
zoomSpeed: number;
units: string;
scale: string;
};
export type AlignAxis = "x" | "y" | "z"; export type AlignAxis = "x" | "y" | "z";
export type AlignTarget = "min" | "center" | "max"; export type AlignTarget = "min" | "center" | "max";
export type AlignHandleStatus = { export type AlignHandleStatus = {