From 41a6ddd769041bc91055d72e7586047bf035215b Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Fri, 21 Jun 2024 19:57:29 -0700 Subject: [PATCH] updates Signed-off-by: Jess Frazelle updates Signed-off-by: Jess Frazelle more Signed-off-by: Jess Frazelle --- src/clientSideScene/sceneEntities.ts | 4 -- src/components/ModelingMachineProvider.tsx | 1 + src/lang/modifyAst.ts | 58 +++++++++++++++------- src/lib/constants.ts | 2 + src/wasm-lib/kcl-test-server/Cargo.toml | 4 +- 5 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/clientSideScene/sceneEntities.ts b/src/clientSideScene/sceneEntities.ts index 591bd59f39..efb59e52a6 100644 --- a/src/clientSideScene/sceneEntities.ts +++ b/src/clientSideScene/sceneEntities.ts @@ -1394,7 +1394,6 @@ export class SceneEntities { streamDimensions ) let _entity_id = entity_id - console.log('things', _entity_id, rest) if (!_entity_id) return if ( engineCommandManager.defaultPlanes?.xy === _entity_id || @@ -1423,7 +1422,6 @@ export class SceneEntities { .sub(sceneInfra.camControls.target) if (engineCommandManager.defaultPlanes?.xy === _entity_id) { - console.log('XY') zAxis = [0, 0, 1] yAxis = [0, 1, 0] if (camVector.z < 0) { @@ -1431,7 +1429,6 @@ export class SceneEntities { _entity_id = engineCommandManager.defaultPlanes?.negXy || '' } } else if (engineCommandManager.defaultPlanes?.yz === _entity_id) { - console.log('YZ') zAxis = [1, 0, 0] yAxis = [0, 0, 1] if (camVector.x < 0) { @@ -1439,7 +1436,6 @@ export class SceneEntities { _entity_id = engineCommandManager.defaultPlanes?.negYz || '' } } else if (engineCommandManager.defaultPlanes?.xz === _entity_id) { - console.log('XZ') zAxis = [0, 1, 0] yAxis = [0, 0, 1] _entity_id = engineCommandManager.defaultPlanes?.negXz || '' diff --git a/src/components/ModelingMachineProvider.tsx b/src/components/ModelingMachineProvider.tsx index af08b6c633..f956df9982 100644 --- a/src/components/ModelingMachineProvider.tsx +++ b/src/components/ModelingMachineProvider.tsx @@ -506,6 +506,7 @@ export const ModelingMachineProvider = ({ }) }, 'animate-to-face': async (_, { data }) => { + console.log('animate-to-face', data) if (data.type === 'extrudeFace') { const { modifiedAst, pathToNode: pathToNewSketchNode } = sketchOnExtrudedFace( diff --git a/src/lang/modifyAst.ts b/src/lang/modifyAst.ts index 10be1300fc..8c5d52a02a 100644 --- a/src/lang/modifyAst.ts +++ b/src/lang/modifyAst.ts @@ -43,15 +43,27 @@ export function startSketchOnDefault( name = '' ): { modifiedAst: Program; id: string; pathToNode: PathToNode } { const _node = { ...node } - const _name = - name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH) + const surfaceName = + name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SURFACE) const startSketchOn = createCallExpressionStdLib('startSketchOn', [ createLiteral(axis), ]) - const variableDeclaration = createVariableDeclaration(_name, startSketchOn) - _node.body = [...node.body, variableDeclaration] + const surfaceVariableDeclaration = createVariableDeclaration( + surfaceName, + startSketchOn + ) + _node.body = [..._node.body, surfaceVariableDeclaration] + + // Create the variable for the sketch. + const sketchName = + name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH) + const sketchVariableDeclaration = createVariableDeclaration( + sketchName, + createIdentifier(surfaceName) + ) + _node.body = [..._node.body, sketchVariableDeclaration] const sketchIndex = _node.body.length - 1 let pathToNode: PathToNode = [ @@ -64,7 +76,7 @@ export function startSketchOnDefault( return { modifiedAst: _node, - id: _name, + id: sketchName, pathToNode, } } @@ -333,10 +345,11 @@ export function sketchOnExtrudedFace( cap: 'none' | 'start' | 'end' = 'none' ): { modifiedAst: Program; pathToNode: PathToNode } { let _node = { ...node } - const newSketchName = findUniqueName( + const newSurfaceName = findUniqueName( node, - KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH + KCL_DEFAULT_CONSTANT_PREFIXES.SURFACE ) + const { node: oldSketchNode } = getNodeFromPath( _node, sketchPathToNode, @@ -372,8 +385,8 @@ export function sketchOnExtrudedFace( _tag = cap.toUpperCase() } - const newSketch = createVariableDeclaration( - newSketchName, + const newSurface = createVariableDeclaration( + newSurfaceName, createCallExpressionStdLib('startSketchOn', [ createIdentifier(extrudeName ? extrudeName : oldSketchName), createLiteral(_tag), @@ -381,22 +394,33 @@ export function sketchOnExtrudedFace( 'const' ) - const expressionIndex = Math.max( - sketchPathToNode[1][0] as number, - extrudePathToNode[1][0] as number + console.log('sketchPathToNode', sketchPathToNode) + console.log('extrudePathToNode', extrudePathToNode) + _node.body = [..._node.body, newSurface] + + // Create the variable for the sketch. + const newSketchName = findUniqueName( + node, + KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH + ) + const sketchVariableDeclaration = createVariableDeclaration( + newSketchName, + createIdentifier(newSurfaceName) ) - _node.body.splice(expressionIndex + 1, 0, newSketch) - const newpathToNode: PathToNode = [ + _node.body = [..._node.body, sketchVariableDeclaration] + const sketchIndex = _node.body.length - 1 + + let newPathToNode: PathToNode = [ ['body', ''], - [expressionIndex + 1, 'index'], + [sketchIndex, 'index'], ['declarations', 'VariableDeclaration'], - [0, 'index'], + ['0', 'index'], ['init', 'VariableDeclarator'], ] return { modifiedAst: _node, - pathToNode: newpathToNode, + pathToNode: newPathToNode, } } diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 0e4c8ab197..901b208a13 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -49,6 +49,8 @@ export const ONBOARDING_PROJECT_NAME = 'Tutorial Project $nn' * These are used to generate unique names for new objects. * */ export const KCL_DEFAULT_CONSTANT_PREFIXES = { + SURFACE: 'surface', + PROFILE: 'profile', SKETCH: 'sketch', EXTRUDE: 'extrude', } as const diff --git a/src/wasm-lib/kcl-test-server/Cargo.toml b/src/wasm-lib/kcl-test-server/Cargo.toml index 35d87cfdfb..c8ffdd12f0 100644 --- a/src/wasm-lib/kcl-test-server/Cargo.toml +++ b/src/wasm-lib/kcl-test-server/Cargo.toml @@ -1,12 +1,14 @@ [package] name = "kcl-test-server" +description = "A test server for KCL" version = "0.1.0" edition = "2021" +license = "MIT" [dependencies] anyhow = "1.0.86" hyper = { version = "0.14.29", features = ["server"] } -kcl-lib = { path = "../kcl" } +kcl-lib = { version = "0.1.62", path = "../kcl" } pico-args = "0.5.0" serde = { version = "1.0.203", features = ["derive"] } serde_json = "1.0.117"