diff --git a/applications/web/src/components/Arc.svelte b/applications/web/src/components/Arc.svelte
index 4836260c..92caafbd 100644
--- a/applications/web/src/components/Arc.svelte
+++ b/applications/web/src/components/Arc.svelte
@@ -5,15 +5,16 @@
import {T} from "@threlte/core"
import {flatten, arcToPoints, promoteTo3} from "shared/projectUtils"
import {currentlySelected, currentlyMousedOver, sketchTool} from "shared/stores"
- import type {EntityType, SketchPoint} from "shared/types"
+ import type {EntityType} from "shared/types"
import {isEntity} from "shared/typeGuards"
+ import type { Point2 } from "cadmium"
// @ts-ignore
const log = (function () { const context = "[Arc.svelte]"; const color="gray"; return Function.prototype.bind.call(console.log, console, `%c${context}`, `font-weight:bold;color:${color};`)})() // prettier-ignore
const type: EntityType = "arc"
- export let id: string, center: SketchPoint, start: SketchPoint, end: SketchPoint
+ export let id: string, center: Point2, start: Point2, end: Point2
export let dashedLineMaterial: LineMaterial,
dashedHoveredMaterial: LineMaterial,
@@ -26,9 +27,9 @@
$: selected = $currentlySelected.some(e => isEntity(e) && e.id === id && e.type === type) ? true : false
- const center2 = new Vector2(center.twoD.x, center.twoD.y)
- const start2 = new Vector2(start.twoD.x, start.twoD.y)
- const end2 = new Vector2(end.twoD.x, end.twoD.y)
+ const center2 = new Vector2(center.x, center.y)
+ const start2 = new Vector2(start.x, start.y)
+ const end2 = new Vector2(end.x, end.y)
const points = flatten(promoteTo3(arcToPoints(center2, start2, end2 /** implicit false */))) // defaulted false in function todo ask Matt
diff --git a/applications/web/src/components/Circle.svelte b/applications/web/src/components/Circle.svelte
index 7ddf02df..00cfcdde 100644
--- a/applications/web/src/components/Circle.svelte
+++ b/applications/web/src/components/Circle.svelte
@@ -4,14 +4,15 @@
import {T} from "@threlte/core"
import {flatten, circleToPoints, promoteTo3} from "shared/projectUtils"
import {currentlySelected, currentlyMousedOver, sketchTool} from "shared/stores"
- import type {CircleTuple, EntityType} from "shared/types"
+ import type {EntityType} from "shared/types"
+ import type { Point2 } from "cadmium"
// @ts-ignore
const log = (function () { const context = "[Circle.svelte]"; const color="gray"; return Function.prototype.bind.call(console.log, console, `%c${context}`, `font-weight:bold;color:${color};`)})() // prettier-ignore
const type: EntityType = "circle"
- export let id: string, center: CircleTuple["center"], radius: number
+ export let id: string, center: Point2, radius: number
// log("[props]", "id:", id, "center:", center, "radius:", radius)
@@ -26,7 +27,7 @@
$: selected = $currentlySelected.some(e => e.id === id && e.type === type) ? true : false
// array of x,y,z points
- const points = flatten(promoteTo3(circleToPoints(center.twoD, radius)))
+ const points = flatten(promoteTo3(circleToPoints(center, radius)))
const lineGeometry = new LineGeometry()
lineGeometry.setPositions(points)
diff --git a/applications/web/src/components/Line.svelte b/applications/web/src/components/Line.svelte
index 38e216f4..8edd368d 100644
--- a/applications/web/src/components/Line.svelte
+++ b/applications/web/src/components/Line.svelte
@@ -5,13 +5,14 @@
import {T} from "@threlte/core"
import {flatten, promoteTo3} from "shared/projectUtils"
import {currentlySelected, currentlyMousedOver, sketchTool} from "shared/stores"
- import type {EntityType, PointById} from "shared/types"
+ import type {EntityType} from "shared/types"
import {isEntity} from "shared/typeGuards"
+ import type { Point2 } from "cadmium"
// @ts-ignore
const log = (function () { const context = "[Line.svelte]"; const color="gray"; return Function.prototype.bind.call(console.log, console, `%c${context}`, `font-weight:bold;color:${color};`)})() // prettier-ignore
- export let id: string, start: PointById, end: PointById
+ export let id: string, start: Point2, end: Point2
export let dashedLineMaterial: LineMaterial,
dashedHoveredMaterial: LineMaterial,
@@ -23,19 +24,10 @@
const type: EntityType = "line"
let hovered = false
- $: selected = $currentlySelected.some(e => checkIsEntity(e) && e.id === id && e.type === type) ? true : false
-
- function checkIsEntity(e: unknown) {
- // log("[checkIsEntity]", isEntity(e), e)
- return isEntity(e)
- }
-
- // $: selected, log("[selected] an entity has been selected:", selected, "Line.id:", id)
- // prettier-ignore
- // $: $currentlySelected, ()=> {if (selected && !$currentlySelected.every((e) => isEntity(e))) log("ERROR [currentlySelected] are not all isEntity", $currentlySelected)}
+ $: selected = $currentlySelected.some(e => isEntity(e) && e.id === id && e.type === type) ? true : false
const points = flatten(
- promoteTo3([new Vector2(start.twoD.x, start.twoD.y), new Vector2(end.twoD.x, end.twoD.y)])
+ promoteTo3([new Vector2(start.x, start.y), new Vector2(end.x, end.y)])
)
const lineGeometry = new LineGeometry()
diff --git a/applications/web/src/components/PassiveSketch.svelte b/applications/web/src/components/PassiveSketch.svelte
index 216dafab..6f60e282 100644
--- a/applications/web/src/components/PassiveSketch.svelte
+++ b/applications/web/src/components/PassiveSketch.svelte
@@ -1,31 +1,34 @@
diff --git a/applications/web/src/components/tools/NewRectangle.svelte b/applications/web/src/components/tools/NewRectangle.svelte
index 87dc05cb..5e2db1fd 100644
--- a/applications/web/src/components/tools/NewRectangle.svelte
+++ b/applications/web/src/components/tools/NewRectangle.svelte
@@ -2,12 +2,13 @@
import {snapPoints, sketchTool, previewGeometry, currentlyMousedOver} from "shared/stores"
import {addRectangleBetweenPoints, addPointToSketch} from "shared/projectUtils"
import {Vector3} from "three"
- import type {IDictionary, PointLikeById, ProjectToPlane, SketchPoint} from "shared/types"
+ import type {IDictionary, PointLikeById, ProjectToPlane} from "shared/types"
+ import type { Point2 } from "cadmium"
// @ts-ignore
const log = (function () { const context = "[NewRectangleTool.svelte]"; const color="gray"; return Function.prototype.bind.call(console.log, console, `%c${context}`, `font-weight:bold;color:${color};`)})() // prettier-ignore
- export let pointsById: IDictionary, sketchIndex: string, active: boolean, projectToPlane: ProjectToPlane
+ export let pointsById: IDictionary, sketchIndex: string, active: boolean, projectToPlane: ProjectToPlane
let anchorPoint: PointLikeById | null = null
diff --git a/packages/cadmium/src/message/idwrap/mod.rs b/packages/cadmium/src/message/idwrap/mod.rs
index 8aa65532..21c09f40 100644
--- a/packages/cadmium/src/message/idwrap/mod.rs
+++ b/packages/cadmium/src/message/idwrap/mod.rs
@@ -66,8 +66,9 @@ where
if let Some(id) = id {
if let Some(hash) = hash {
crate::ID_MAP.with_borrow_mut(|m| m.insert(hash, id));
+ } else {
+ warn!("IDWrap::handle_project_message: IDWrap returned an ID, but no hash was found in the workbench history");
}
- warn!("IDWrap::handle_project_message: IDWrap returned an ID, but no hash was found in the workbench history");
}
// Return the step ID (hash) instead of the message handler returned ID
diff --git a/packages/shared/projectUtils.ts b/packages/shared/projectUtils.ts
index d0a06345..d3ffe8fe 100644
--- a/packages/shared/projectUtils.ts
+++ b/packages/shared/projectUtils.ts
@@ -76,6 +76,8 @@ export function sendWasmMessage(message: Message): MessageResult {
if (!result.success) {
throw new Error(`[sendWasmMessage] message failed: ${result.data}`)
+ } else {
+ workbenchIsStale.set(true)
}
return result
diff --git a/packages/shared/stepTypeGuards.ts b/packages/shared/stepTypeGuards.ts
index 4739e574..0b1f18a3 100644
--- a/packages/shared/stepTypeGuards.ts
+++ b/packages/shared/stepTypeGuards.ts
@@ -19,29 +19,29 @@ export function isSketchStep(step: Step): step is SketchStep {
// --- Sketch primitive operations ---
// Any primitive operation
-export type SketchPrimitiveStep = Step & {result: {Primitive: WrappedPrimitive}}
+export type SketchPrimitiveStep = Step & {result: StepResult & {Primitive: WrappedPrimitive}}
export function isSketchPrimitiveStep(step: Step): step is SketchPrimitiveStep {
return typeof step.result === "object" && "Primitive" in step.result
}
-export type SketchPointStep = SketchPrimitiveStep & {result: {Point2: Point2}, data: {SketchAddPoint: SketchAddPoint}}
+export type SketchPointStep = SketchPrimitiveStep & {result: {Primitive: {Point2: Point2}}, data: {SketchAddPoint: SketchAddPoint}}
export function isSketchPointStep(step: Step): step is SketchPointStep {
- return isSketchPrimitiveStep(step) && "SketchAddPoint" in step.data && "Point2" in step.result
+ return isSketchPrimitiveStep(step) && "SketchAddPoint" in step.data && "Point2" in step.result.Primitive
}
-export type SketchLineStep = SketchPrimitiveStep & {result: {Line2: Line2}, data: {SketchAddLine: SketchAddLine}}
+export type SketchLineStep = SketchPrimitiveStep & {result: {Primitive: {Line2: Line2}}, data: {SketchAddLine: SketchAddLine}}
export function isSketchLineStep(step: Step): step is SketchLineStep {
- return isSketchPrimitiveStep(step) && "SketchAddLine" in step.data && "Line2" in step.result
+ return isSketchPrimitiveStep(step) && "SketchAddLine" in step.data && "Line2" in step.result.Primitive
}
-export type SketchCircleStep = SketchPrimitiveStep & {result: {Circle2: Circle2}, data: {SketchAddCircle: SketchAddCircle}}
+export type SketchCircleStep = SketchPrimitiveStep & {result: {Primitive: {Circle2: Circle2}}, data: {SketchAddCircle: SketchAddCircle}}
export function isSketchCircleStep(step: Step): step is SketchCircleStep {
- return isSketchPrimitiveStep(step) && "SketchAddCircle" in step.data && "Circle2" in step.result
+ return isSketchPrimitiveStep(step) && "SketchAddCircle" in step.data && "Circle2" in step.result.Primitive
}
-export type SketchArcStep = SketchPrimitiveStep & {result: {Arc2: Arc2}, data: {SketchAddArc: SketchAddArc}}
+export type SketchArcStep = SketchPrimitiveStep & {result: {Primitive: {Arc2: Arc2}}, data: {SketchAddArc: SketchAddArc}}
export function isSketchArcStep(step: Step): step is SketchArcStep {
- return isSketchPrimitiveStep(step) && "SketchAddArc" in step.data && "Arc2" in step.result
+ return isSketchPrimitiveStep(step) && "SketchAddArc" in step.data && "Arc2" in step.result.Primitive
}
// --- Sketch compound operations ---
@@ -53,7 +53,7 @@ export function isSketchCompoundStep(step: Step): step is SketchCompoundStep {
// TODO: export rectangle
// export type SketchRectangleStep = SketchCompoundStep & {result: Rectangle, data: SketchAddRectangle}
// export function isSketchRectangleStep(step: Step): step is SketchRectangleStep {
-// return isSketchCompoundStep(step) && "SketchAddRectangle" in step.data && "Rectangle" in step.result
+// return isSketchCompoundStep(step) && "SketchAddRectangle" in step.data && "Rectangle" in step.result.Compound
// }
// --- Solid operations ---
diff --git a/packages/shared/stores.ts b/packages/shared/stores.ts
index 55e7b35c..ab78da6e 100644
--- a/packages/shared/stores.ts
+++ b/packages/shared/stores.ts
@@ -1,6 +1,6 @@
import {Solid, StepHash, Project as WasmProject, Workbench} from "cadmium"
import {writable} from "svelte/store"
-import type {MessageHistory, Project, Entity, EntityType, SnapEntity, PointLikeById, PreviewGeometry} from "./types"
+import type {MessageHistory, Project, Entity, EntityType, SnapEntity, PointLikeById, PreviewGeometry, Point2WithID} from "./types"
import {isArcEntity, isCircleEntity, isEntity, isFaceEntity, isLineEntity, isMeshFaceEntity, isPlaneEntity, isPoint3DEntity, isPointEntity} from "./typeGuards"
// prettier-ignore
@@ -18,7 +18,7 @@ export const workbenchIsStale = writable(false)
export const featureIndex = writable(1000)
export const extrusionFeatures = writable([])
-export const hiddenSketches = writable([])
+export const hiddenSketches = writable([])
export const sketchBeingEdited = writable(null)
export const sketchTool = writable("")
@@ -29,7 +29,7 @@ export const selectionMin = writable(0)
export const currentlyMousedOver = writable([])
export const currentlySelected = writable([])
-export const snapPoints = writable([])
+export const snapPoints = writable([])
export const previewGeometry = writable([])
export const messageHistory = writable([])
diff --git a/packages/shared/types.d.ts b/packages/shared/types.d.ts
index 7bf59124..099ce36f 100644
--- a/packages/shared/types.d.ts
+++ b/packages/shared/types.d.ts
@@ -1,11 +1,13 @@
-import { MessageResult, StepHash, Workbench } from "cadmium"
+import { MessageResult, Point2, StepHash, Workbench } from "cadmium"
import { Message } from "./cadmium-api"
import type { Vector2, Vector3, Vector2Like, Vector3Like } from "three"
-interface IDictionary {
+export interface IDictionary {
[id: string]: TValue
}
+export type Point2WithID = Point2 & { id?: StepHash }
+
type WithTarget = Event & { currentTarget: Target }
type SetCameraFocus = (goTo: Vector3Like, lookAt: Vector3Like, up: Vector3Like) => void
@@ -335,9 +337,9 @@ interface ExtrusionSketchData {
interface PreviewGeometry {
type: EntityType
- start?: PointLikeById
- end?: PointLikeById
- center?: PointLikeById
+ start?: Point2
+ end?: Point2
+ center?: Point2
radius?: number
x?: number
y?: number