feat: SketchUp klasik arayuzu, kisayollar, VCB olcu kutusu ve YakNet 3B bilesen havuzu
Build and Push Docker Images / build (push) Canceled after 0s
CI / Typecheck and unit tests (push) Canceled after 0s

This commit is contained in:
Enes Yakıştır
2026-11-10 19:13:46 +03:00
parent e7b6db9db6
commit dc09b61779
16 changed files with 6655 additions and 488 deletions
+87
View File
@@ -0,0 +1,87 @@
import { describe, expect, it } from "vitest";
import { detachComponentInstance, instantiateComponentShapes } from "@/lib/cloudComponents";
import type { WorkplaneShape } from "@/types/sketchforge";
function makeSampleShape(overrides: Partial<WorkplaneShape> = {}): WorkplaneShape {
return {
id: "orig-1",
name: "Ahşap Kolon",
kind: "box",
color: "#b45309",
x: 50,
z: 30,
elevation: 10,
width: 20,
depth: 20,
height: 100,
size: 20,
rotation: 0,
texture: "wood",
componentDefId: "comp-kolon",
componentName: "Ahşap Kolon",
...overrides,
};
}
describe("YakNet 3B Cloud Components — Instantiation & Make Unique", () => {
it("instantiates multi-part components as a rigid centered unit with unique IDs", () => {
const leg1 = makeSampleShape({ id: "leg-1", x: 40, z: 20, elevation: 0, width: 10, depth: 10, height: 40 });
const leg2 = makeSampleShape({ id: "leg-2", x: 80, z: 20, elevation: 0, width: 10, depth: 10, height: 40 });
const top = makeSampleShape({ id: "top-1", x: 60, z: 20, elevation: 40, width: 60, depth: 30, height: 6 });
let seq = 0;
const placed = instantiateComponentShapes([leg1, leg2, top], {
componentDefId: "yaknet-masa-01",
componentName: "Çalışma Masası",
targetOffset: { x: 0, z: 0, elevation: 5 },
createId: (prefix) => `${prefix}-${++seq}`,
});
expect(placed).toHaveLength(3);
expect(new Set(placed.map((s) => s.id)).size).toBe(3);
// Relative distances preserved while center aligns on (0, 0) and base on y=5
expect(placed[0].x).toBe(-20);
expect(placed[1].x).toBe(20);
expect(placed[2].x).toBe(0);
expect(placed[0].elevation).toBe(5);
expect(placed[2].elevation).toBe(45);
expect(placed.every((s) => s.componentDefId === "yaknet-masa-01")).toBe(true);
expect(placed.every((s) => s.componentName === "Çalışma Masası")).toBe(true);
});
it("deep-clones groupedShapes and sketchProfile so instances do not share mutable nested references", () => {
const child = makeSampleShape({ id: "child-1" });
const parent = makeSampleShape({
id: "parent-1",
groupedShapes: [child],
sketchProfile: {
points: [{ id: "p1", x: 0, z: 0, mode: "corner" }],
segments: [{ id: "s1", startPointId: "p1", endPointId: "p1", kind: "line" }],
},
});
let seq = 0;
const [inst] = instantiateComponentShapes([parent], {
createId: (prefix) => `${prefix}-${++seq}`,
});
expect(inst.id).not.toBe(parent.id);
expect(inst.groupedShapes?.[0].id).not.toBe(child.id);
expect(inst.sketchProfile?.points[0]).not.toBe(parent.sketchProfile?.points[0]);
});
it("detaches selected component instances cleanly on Make Unique", () => {
const a = makeSampleShape({ id: "win-1", componentDefId: "comp-win", componentName: "Pencere" });
const b = makeSampleShape({ id: "win-2", x: 90, componentDefId: "comp-win", componentName: "Pencere" });
const plain = makeSampleShape({ id: "wall-1", componentDefId: undefined, componentName: undefined });
const detached = detachComponentInstance([a, b, plain], ["win-2"], () => "compdef-unique-1");
expect(detached[0].componentDefId).toBe("comp-win");
expect(detached[0].componentName).toBe("Pencere");
expect(detached[1].componentDefId).toBe("compdef-unique-1");
expect(detached[1].componentName).toBe("Pencere (Benzersiz)");
expect(detached[2].componentDefId).toBeUndefined();
});
});
+120
View File
@@ -0,0 +1,120 @@
import { describe, expect, it } from "vitest";
import {
DEFAULT_SKETCHUP_PREFS,
SKETCHUP_TOOLS,
mapToolToCursorMode,
normalizeSketchUpPrefs,
parseVcbInput,
} from "@/lib/sketchupInterface";
describe("SketchUp Classic Interface — VCB Parser, Prefs & Tool Mapping", () => {
it("parses linear/polar array repeat multipliers (*5, x5, 5x, 5*)", () => {
expect(parseVcbInput("*5")).toEqual({ kind: "array-multiply", count: 5 });
expect(parseVcbInput("x8")).toEqual({ kind: "array-multiply", count: 8 });
expect(parseVcbInput("4x")).toEqual({ kind: "array-multiply", count: 4 });
expect(parseVcbInput("3*")).toEqual({ kind: "array-multiply", count: 3 });
});
it("parses equidistant array division (/N)", () => {
expect(parseVcbInput("/4")).toEqual({ kind: "array-divide", count: 4 });
expect(parseVcbInput("/ 12")).toEqual({ kind: "array-divide", count: 12 });
expect(parseVcbInput("/0")).toEqual({ kind: "invalid", raw: "/0" });
});
it("parses 2D and 3D dimensions with semicolons, x, and comma+space", () => {
expect(parseVcbInput("100;50")).toEqual({
kind: "dimensions-2d",
width: 100,
depth: 50,
});
expect(parseVcbInput("100,5;60,25")).toEqual({
kind: "dimensions-2d",
width: 100.5,
depth: 60.25,
});
expect(parseVcbInput("120;80;35")).toEqual({
kind: "dimensions-3d",
width: 120,
depth: 80,
height: 35,
});
expect(parseVcbInput("45x90x15")).toEqual({
kind: "dimensions-3d",
width: 45,
depth: 90,
height: 15,
});
expect(parseVcbInput("100, 60")).toEqual({
kind: "dimensions-2d",
width: 100,
depth: 60,
});
});
it("distinguishes decimal commas (12,5) from comma 2D pairs based on tool context", () => {
expect(parseVcbInput("12,5", { prefer2dDimensions: false })).toEqual({
kind: "single-number",
value: 12.5,
});
expect(parseVcbInput("100,60", { prefer2dDimensions: true })).toEqual({
kind: "dimensions-2d",
width: 100,
depth: 60,
});
});
it("parses angles and length unit conversions (mm, cm, m)", () => {
expect(parseVcbInput("45°")).toEqual({ kind: "angle", degrees: 45 });
expect(parseVcbInput("-22.5deg")).toEqual({ kind: "angle", degrees: -22.5 });
expect(parseVcbInput("2.5m")).toEqual({ kind: "single-number", value: 2500 });
expect(parseVcbInput("50cm")).toEqual({ kind: "single-number", value: 500 });
expect(parseVcbInput("-15mm")).toEqual({ kind: "single-number", value: -15 });
});
it("handles empty and invalid inputs cleanly", () => {
expect(parseVcbInput(" ")).toEqual({ kind: "empty" });
expect(parseVcbInput("abc")).toEqual({ kind: "invalid", raw: "abc" });
expect(parseVcbInput("10;0")).toEqual({ kind: "invalid", raw: "10;0" });
});
it("maps SketchUp tool IDs to viewport cursor modes", () => {
expect(mapToolToCursorMode("orbit")).toBe("orbit");
expect(mapToolToCursorMode("pan")).toBe("pan");
expect(mapToolToCursorMode("zoom")).toBe("zoom");
expect(mapToolToCursorMode("eraser")).toBe("eraser");
expect(mapToolToCursorMode("rectangle")).toBe("rectangle");
expect(mapToolToCursorMode("circle")).toBe("circle");
expect(mapToolToCursorMode("polygon")).toBe("polygon");
expect(mapToolToCursorMode("push-pull")).toBe("push-pull");
expect(mapToolToCursorMode("move")).toBe("move");
expect(mapToolToCursorMode("zoom-extents")).toBe("select");
expect(Object.keys(SKETCHUP_TOOLS).length).toBeGreaterThanOrEqual(25);
});
it("normalizes user workspace prefs safely with defaults on corrupt data", () => {
expect(normalizeSketchUpPrefs(null)).toEqual(DEFAULT_SKETCHUP_PREFS);
expect(normalizeSketchUpPrefs("invalid")).toEqual(DEFAULT_SKETCHUP_PREFS);
const normalized = normalizeSketchUpPrefs({
layoutMode: "compact-modern",
keymapProfile: "snapcad-standard",
showLeftToolset: false,
showDefaultTray: true,
showSecondaryRibbon: true,
skyGroundEnabled: true,
backEdgesEnabled: true,
openTraySections: ["styles", "unknown-section", "components", "styles"],
});
expect(normalized).toEqual({
layoutMode: "compact-modern",
keymapProfile: "snapcad-standard",
showLeftToolset: false,
showDefaultTray: true,
showSecondaryRibbon: true,
skyGroundEnabled: true,
backEdgesEnabled: true,
openTraySections: ["styles", "components"],
});
});
});