Skip to content

Commit

Permalink
Add typescript functions for all messages
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Zervas <[email protected]>
  • Loading branch information
dzervas committed Jun 4, 2024
1 parent cb8357f commit 5dc4554
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
51 changes: 51 additions & 0 deletions packages/shared/cadmium-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Direction, IDType, Message, MessageResult, Mode, Plane, PlaneDescription, ProjectRename } from "cadmium";
import { sendWasmMessage } from "./projectUtils";

export function projectRename(new_name: string): MessageResult {
const message: Message = { ProjectRename: { new_name } }
return sendWasmMessage(message)
}
export function workbenchRename(workbench_id: IDType, new_name: string): MessageResult {
const message: Message = { WorkbenchRename: { id: workbench_id, inner: { new_name } } }
return sendWasmMessage(message)
}
export function workbenchPointAdd(workbench_id: IDType, x: number, y: number, z: number): MessageResult {
const message: Message = { WorkbenchPointAdd: { id: workbench_id, inner: { x, y, z } } }
return sendWasmMessage(message)
}
export function workbenchPlaneAdd(workbench_id: IDType, plane: Plane, width: number, height: number): MessageResult {
const message: Message = { WorkbenchPlaneAdd: { id: workbench_id, inner: { plane, width, height } } }
return sendWasmMessage(message)
}
export function workbenchSketchAdd(workbench_id: IDType, plane_description: PlaneDescription): MessageResult {
const message: Message = { WorkbenchSketchAdd: { id: workbench_id, inner: { plane_description } } }
return sendWasmMessage(message)
}
export function workbenchPointUpdate(workbench_id: IDType, point_id: IDType, x: number, y: number, z: number): MessageResult {
const message: Message = { WorkbenchPointUpdate: { id: workbench_id, inner: { id: point_id, inner: { x, y, z } } } }
return sendWasmMessage(message)
}
export function sketchAddPoint(workbench_id: IDType, sketch_id: IDType, x: number, y: number, z: number): MessageResult {
const message: Message = { SketchAddPoint: { id: workbench_id, inner: { id: sketch_id, inner: { x, y, z } } } }
return sendWasmMessage(message)
}
export function sketchAddArc(workbench_id: IDType, sketch_id: IDType, center: IDType, radius: number, clockwise: boolean, start_angle: number, end_angle: number): MessageResult {
const message: Message = { SketchAddArc: { id: workbench_id, inner: { id: sketch_id, inner: { center, radius, clockwise, start_angle, end_angle } } } }
return sendWasmMessage(message)
}
export function sketchAddCircle(workbench_id: IDType, sketch_id: IDType, center: IDType, radius: number): MessageResult {
const message: Message = { SketchAddCircle: { id: workbench_id, inner: { id: sketch_id, inner: { center, radius } } } }
return sendWasmMessage(message)
}
export function sketchAddLine(workbench_id: IDType, sketch_id: IDType, start: IDType, end: IDType): MessageResult {
const message: Message = { SketchAddLine: { id: workbench_id, inner: { id: sketch_id, inner: { start, end } } } }
return sendWasmMessage(message)
}
export function sketchDeletePrimitive(workbench_id: IDType, sketch_id: IDType, primitive_id: IDType): MessageResult {
const message: Message = { SketchDeletePrimitive: { id: workbench_id, inner: { id: sketch_id, inner: { id: primitive_id } } } }
return sendWasmMessage(message)
}
export function solidExtrusionAdd(workbench_id: IDType, sketch_id: IDType, faces: Face[], length: number, offset: number, direction: Direction, mode: Mode): MessageResult {
const message: Message = { SolidExtrusionAdd: { id: workbench_id, inner: { sketch_id, faces, length, offset, direction, mode } } }
return sendWasmMessage(message)
}
4 changes: 2 additions & 2 deletions packages/shared/projectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
WithTarget,
WorkBench
} from "./types"
import type { Realization as WasmRealization, Message, Primitive, StepData, Workbench } from "cadmium"
import type { Realization as WasmRealization, Message, Primitive, StepData, Workbench, MessageResult } from "cadmium"
import { isMessage } from "./typeGuards"
// import { isDevelopment } from "../+layout"

Expand Down Expand Up @@ -54,7 +54,7 @@ export function arraysEqual(a: any[], b: any[]) {
return true
}

function sendWasmMessage(message: Message) {
export function sendWasmMessage(message: Message): MessageResult {
let wp = get(wasmProject)
log("[sendWasmMessage] sending message:", message)
let result = wp.send_message(message)
Expand Down

0 comments on commit 5dc4554

Please sign in to comment.