Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
Persist project workspace settings
This commit is contained in:
@@ -1603,6 +1603,13 @@ button {
|
||||
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 {
|
||||
stroke: rgba(31, 39, 46, 0.72);
|
||||
stroke-width: 1.15;
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
import { Clock3, FileUp, Grid3X3, HomeIcon, List, Plus, Search, Settings, SlidersHorizontal, Trash2, X } from "lucide-react";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
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 ViewMode = "grid" | "list";
|
||||
@@ -19,6 +20,8 @@ type DashboardProject = {
|
||||
thumbnailUrl?: string | null;
|
||||
thumbnailVersion?: number;
|
||||
revision?: number;
|
||||
workspace?: WorkplaneWorkspaceSettings;
|
||||
snapGrid?: GridSize;
|
||||
};
|
||||
|
||||
type StoredDashboardProject = Partial<DashboardProject> & {
|
||||
@@ -145,6 +148,8 @@ function readStoredProjects() {
|
||||
thumbnailUrl: typeof project.thumbnailUrl === "string" ? project.thumbnailUrl : null,
|
||||
thumbnailVersion: typeof project.thumbnailVersion === "number" ? project.thumbnailVersion : undefined,
|
||||
revision,
|
||||
workspace: normalizeWorkspaceSettings(project.workspace),
|
||||
snapGrid: normalizeSnapGrid(project.snapGrid),
|
||||
};
|
||||
});
|
||||
return { projects, legacyShapes };
|
||||
@@ -173,6 +178,8 @@ function mergeProjectForStorage(project: DashboardProject, storedProject?: Dashb
|
||||
thumbnailUrl: project.thumbnailUrl ?? storedProject.thumbnailUrl,
|
||||
thumbnailVersion: project.thumbnailVersion ?? storedProject.thumbnailVersion,
|
||||
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,
|
||||
thumbnailVersion: project.thumbnailVersion,
|
||||
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,
|
||||
accent: PROJECT_ACCENTS[index % PROJECT_ACCENTS.length],
|
||||
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 project = newProject(name ?? `Untitled design ${projects.length + 1}`, projects.length);
|
||||
setProjectShapesById((current) => ({
|
||||
@@ -511,6 +540,8 @@ export default function Home() {
|
||||
shapes: project.shapes,
|
||||
designShapes: projectShapesById[project.id]?.shapes.length ?? null,
|
||||
thumbnail: Boolean(project.thumbnailUrl),
|
||||
workspace: Boolean(project.workspace),
|
||||
snapGrid: project.snapGrid ?? null,
|
||||
}));
|
||||
|
||||
return (
|
||||
@@ -559,9 +590,12 @@ export default function Home() {
|
||||
<div className={view === "editor" ? "editor-stage active" : "editor-stage"} aria-hidden={view !== "editor"}>
|
||||
<SketchForgeEditor
|
||||
initialShapes={activeProjectShapeEntry?.shapes ?? []}
|
||||
initialSnap={activeProject?.snapGrid ?? DEFAULT_SNAP_GRID}
|
||||
initialWorkspace={activeProject?.workspace ?? DEFAULT_WORKPLANE_WORKSPACE}
|
||||
onHome={openDashboard}
|
||||
onProjectShapesChange={updateProjectShapes}
|
||||
onProjectSnapshot={updateProjectSnapshot}
|
||||
onProjectWorkspaceChange={updateProjectWorkspace}
|
||||
projectId={activeProjectId}
|
||||
projectRevision={activeProjectShapeEntry?.revision ?? activeProject?.revision ?? 0}
|
||||
/>
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
ToolbarVectorExportIcon,
|
||||
} from "./icons";
|
||||
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 ExportFormat = "stl" | "obj";
|
||||
@@ -4142,16 +4142,22 @@ function projectShapesFingerprint(shapes: WorkplaneShape[]) {
|
||||
|
||||
export function SketchForgeEditor({
|
||||
initialShapes = [],
|
||||
initialSnap,
|
||||
initialWorkspace,
|
||||
onHome,
|
||||
onProjectShapesChange,
|
||||
onProjectSnapshot,
|
||||
onProjectWorkspaceChange,
|
||||
projectId,
|
||||
projectRevision = 0,
|
||||
}: {
|
||||
initialShapes?: WorkplaneShape[];
|
||||
initialSnap?: GridSize;
|
||||
initialWorkspace?: WorkplaneWorkspaceSettings;
|
||||
onHome?: () => void;
|
||||
onProjectShapesChange?: (snapshot: { projectId: string; shapes: WorkplaneShape[] }) => void;
|
||||
onProjectSnapshot?: (snapshot: { image: string; projectId: string; shapes: number }) => void;
|
||||
onProjectWorkspaceChange?: (snapshot: { projectId: string; workspace: WorkplaneWorkspaceSettings; snap: GridSize }) => void;
|
||||
projectId?: string | null;
|
||||
projectRevision?: number;
|
||||
} = {}) {
|
||||
@@ -4333,6 +4339,16 @@ export function SketchForgeEditor({
|
||||
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(
|
||||
(next: WorkplaneShape[], nextSelection: string | string[] | null = selectedIds, message?: string) => {
|
||||
const canonicalNext = next.map(canonicalizeShape);
|
||||
@@ -5448,6 +5464,9 @@ export function SketchForgeEditor({
|
||||
mirrorReferenceShapes={shapes}
|
||||
placementElevation={placementElevation}
|
||||
workplaneMode={workplaneMode}
|
||||
initialSnap={initialSnap}
|
||||
initialWorkspace={initialWorkspace}
|
||||
workspaceSettingsKey={projectId ?? "local-workplane"}
|
||||
onAddShape={addShape}
|
||||
onAlignAnchorChange={chooseAlignAnchor}
|
||||
onAlignPreview={previewAlignSelection}
|
||||
@@ -5460,6 +5479,7 @@ export function SketchForgeEditor({
|
||||
onSetPlacementElevation={setPlacementWorkplane}
|
||||
onInteractionActiveChange={updateProjectInteractionActive}
|
||||
onUpdateShape={updateShape}
|
||||
onWorkspaceSettingsChange={updateProjectWorkspaceSettings}
|
||||
onWorkplaneModeChange={setWorkplaneMode}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,7 @@ import helvetikerBoldFontJson from "three/examples/fonts/helvetiker_bold.typefac
|
||||
import optimerBoldFontJson from "three/examples/fonts/optimer_bold.typeface.json";
|
||||
import { ToolbarHideSelectedIcon } from "@/components/icons";
|
||||
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 {
|
||||
TransformOverlay,
|
||||
getElevationMeasureKey,
|
||||
@@ -30,7 +31,7 @@ import {
|
||||
type TransformHandleKind,
|
||||
type TransformOverlayState,
|
||||
} 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 WORKPLANE_WIDTH = 200;
|
||||
@@ -39,20 +40,7 @@ const MIN_WORKSPACE_SIZE = 60;
|
||||
const MAX_WORKSPACE_SIZE = 2000;
|
||||
const MIN_GRID_BLOCK_SIZE = 1;
|
||||
const MAX_GRID_BLOCK_SIZE = 200;
|
||||
const DEFAULT_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 DEFAULT_WORKSPACE = DEFAULT_WORKPLANE_WORKSPACE;
|
||||
const workspaceSizePresets = [
|
||||
{ label: "200 x 200 mm", width: 200, depth: 200 },
|
||||
{ label: "300 x 300 mm", width: 300, depth: 300 },
|
||||
@@ -128,6 +116,9 @@ type WorkplaneViewportProps = {
|
||||
mirrorReferenceShapes: WorkplaneShape[];
|
||||
placementElevation: number;
|
||||
workplaneMode: boolean;
|
||||
initialSnap?: GridSize;
|
||||
initialWorkspace?: WorkplaneWorkspaceSettings;
|
||||
workspaceSettingsKey?: string | null;
|
||||
onAddShape: (shape: ShapeAsset, point?: { x: number; z: number; elevation?: number }) => void;
|
||||
onAlignAnchorChange: (id: string) => void;
|
||||
onAlignPreview: (axis: AlignAxis, target: AlignTarget) => void;
|
||||
@@ -140,10 +131,11 @@ type WorkplaneViewportProps = {
|
||||
onSetPlacementElevation: (elevation: number, source: "shape" | "base") => void;
|
||||
onInteractionActiveChange?: (active: boolean) => void;
|
||||
onUpdateShape: (id: string, patch: ShapeUpdatePatch) => void;
|
||||
onWorkspaceSettingsChange?: (settings: { workspace: WorkplaneWorkspaceSettings; snap: GridSize }) => void;
|
||||
onWorkplaneModeChange: (active: boolean) => void;
|
||||
};
|
||||
|
||||
type WorkspaceSettings = typeof DEFAULT_WORKSPACE;
|
||||
type WorkspaceSettings = WorkplaneWorkspaceSettings;
|
||||
|
||||
type ThreeState = {
|
||||
renderer: THREE.WebGLRenderer;
|
||||
@@ -875,6 +867,9 @@ export function WorkplaneViewport({
|
||||
mirrorReferenceShapes,
|
||||
placementElevation,
|
||||
workplaneMode,
|
||||
initialSnap,
|
||||
initialWorkspace,
|
||||
workspaceSettingsKey,
|
||||
onAddShape,
|
||||
onAlignAnchorChange,
|
||||
onAlignPreview,
|
||||
@@ -887,12 +882,13 @@ export function WorkplaneViewport({
|
||||
onSetPlacementElevation,
|
||||
onInteractionActiveChange,
|
||||
onUpdateShape,
|
||||
onWorkspaceSettingsChange,
|
||||
onWorkplaneModeChange,
|
||||
}: WorkplaneViewportProps) {
|
||||
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 [workspace, setWorkspace] = useState<WorkspaceSettings>(DEFAULT_WORKSPACE);
|
||||
const [workspace, setWorkspace] = useState<WorkspaceSettings>(() => normalizeWorkspaceSettings(initialWorkspace));
|
||||
const [transformOverlay, setTransformOverlay] = useState<TransformOverlayState | null>(null);
|
||||
const [alignOverlay, setAlignOverlay] = useState<AlignOverlayState | null>(null);
|
||||
const [mirrorOverlay, setMirrorOverlay] = useState<MirrorOverlayState | null>(null);
|
||||
@@ -918,6 +914,8 @@ export function WorkplaneViewport({
|
||||
const suppressNextLiftEditRef = useRef(false);
|
||||
const snapRef = useRef(snap);
|
||||
const workspaceRef = useRef(workspace);
|
||||
const workspaceSettingsKeyRef = useRef(workspaceSettingsKey ?? null);
|
||||
const lastWorkspaceSettingsSyncRef = useRef("");
|
||||
const viewCubeRef = useRef<HTMLDivElement | null>(null);
|
||||
const transformOverlayRef = useRef<TransformOverlayState | null>(null);
|
||||
const alignOverlayRef = useRef<AlignOverlayState | null>(null);
|
||||
@@ -940,6 +938,27 @@ export function WorkplaneViewport({
|
||||
const placementElevationRef = useRef(placementElevation);
|
||||
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(() => {
|
||||
const openWorkspaceSettings = () => setSettingsOpen(true);
|
||||
window.addEventListener("sketchforge:open-workspace-settings", openWorkspaceSettings);
|
||||
@@ -1033,6 +1052,10 @@ export function WorkplaneViewport({
|
||||
}
|
||||
}, [workspace]);
|
||||
|
||||
useEffect(() => {
|
||||
setSelectionHelpersVisible(threeRef.current, activeTransformKind !== "rotate");
|
||||
}, [activeTransformKind]);
|
||||
|
||||
useEffect(() => {
|
||||
const host = hostRef.current;
|
||||
if (!host) {
|
||||
@@ -1254,6 +1277,7 @@ export function WorkplaneViewport({
|
||||
}
|
||||
setActiveRotationWheel(kind === "rotate");
|
||||
setActiveTransformKind(kind);
|
||||
setSelectionHelpersVisible(state ?? null, kind !== "rotate");
|
||||
if (kind === "rotate") {
|
||||
setRotationWheelAxis(rotationAxis);
|
||||
setPinnedRotationWheelView(wheel && rotationPlane ? { axis: rotationAxis, wheel: { ...wheel }, plane: { ...rotationPlane } } : null);
|
||||
@@ -1501,6 +1525,7 @@ export function WorkplaneViewport({
|
||||
setPinnedRotationWheelView(null);
|
||||
setRotationReadout(null);
|
||||
if (threeRef.current) {
|
||||
setSelectionHelpersVisible(threeRef.current, true);
|
||||
threeRef.current.controls.enabled = true;
|
||||
}
|
||||
onInteractionActiveChange?.(false);
|
||||
@@ -1743,6 +1768,7 @@ export function WorkplaneViewport({
|
||||
}
|
||||
setActiveRotationWheel(handle.kind === "rotate");
|
||||
setActiveTransformKind(handle.kind);
|
||||
setSelectionHelpersVisible(state, handle.kind !== "rotate");
|
||||
if (handle.kind === "rotate") {
|
||||
setRotationWheelAxis(rotationAxis);
|
||||
setPinnedRotationWheelView(wheel && rotationPlane ? { axis: rotationAxis, wheel: { ...wheel }, plane: { ...rotationPlane } } : null);
|
||||
@@ -2001,6 +2027,7 @@ export function WorkplaneViewport({
|
||||
setActiveTransformKind(null);
|
||||
setRotationReadout(null);
|
||||
if (state) {
|
||||
setSelectionHelpersVisible(state, true);
|
||||
state.controls.enabled = true;
|
||||
}
|
||||
onInteractionActiveChange?.(false);
|
||||
@@ -2194,6 +2221,7 @@ export function WorkplaneViewport({
|
||||
editingRotation={editingRotation}
|
||||
rotationReadout={rotationReadout}
|
||||
showRotationWheel={activeRotationWheel}
|
||||
hideSelectionChrome={activeTransformKind === "rotate"}
|
||||
hideDimensionMarks={activeTransformKind === "scale"}
|
||||
rotationWheelAxis={rotationWheelAxis}
|
||||
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) {
|
||||
return cleanNearZero(value).toFixed(2);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ export function TransformOverlay({
|
||||
editingRotation,
|
||||
rotationReadout,
|
||||
showRotationWheel,
|
||||
hideSelectionChrome,
|
||||
hideDimensionMarks,
|
||||
rotationWheelAxis,
|
||||
pinnedRotationWheelView,
|
||||
@@ -74,7 +75,7 @@ export function TransformOverlay({
|
||||
const plane = pinnedWheel?.plane ?? box.rotationPlanes[rotationWheelAxis];
|
||||
const wheel = pinnedWheel?.wheel ?? box.rotationWheels[rotationWheelAxis] ?? box.rotationWheel;
|
||||
return (
|
||||
<div className="transform-overlay" aria-hidden="true">
|
||||
<div className={`transform-overlay ${hideSelectionChrome ? "hide-selection-chrome" : ""}`} aria-hidden="true">
|
||||
{showRotationWheel && wheel && plane ? (
|
||||
<svg
|
||||
className={`rotation-protractor-plane axis-${rotationWheelAxis}`}
|
||||
|
||||
@@ -84,6 +84,7 @@ export type TransformOverlayProps = {
|
||||
editingRotation: EditingRotation;
|
||||
rotationReadout: RotationReadout;
|
||||
showRotationWheel: boolean;
|
||||
hideSelectionChrome: boolean;
|
||||
hideDimensionMarks: boolean;
|
||||
rotationWheelAxis: RotationAxis;
|
||||
pinnedRotationWheelView: PinnedRotationWheelView | null;
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
@@ -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 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 AlignTarget = "min" | "center" | "max";
|
||||
export type AlignHandleStatus = {
|
||||
|
||||
Reference in New Issue
Block a user