Add bidirectionalLength
This commit is contained in:
		| @ -37,12 +37,14 @@ export function addExtrude({ | ||||
|   ast, | ||||
|   sketches, | ||||
|   length, | ||||
|   bidirectionalLength, | ||||
|   symmetric, | ||||
|   nodeToEdit, | ||||
| }: { | ||||
|   ast: Node<Program> | ||||
|   sketches: Selections | ||||
|   length: KclCommandValue | ||||
|   bidirectionalLength?: KclCommandValue | ||||
|   symmetric?: boolean | ||||
|   nodeToEdit?: PathToNode | ||||
| }): | ||||
| @ -66,6 +68,14 @@ export function addExtrude({ | ||||
|   } | ||||
|  | ||||
|   // Extra labeled args expressions | ||||
|   const bidirectionalLengthExpr = bidirectionalLength | ||||
|     ? [ | ||||
|         createLabeledArg( | ||||
|           'bidirectionalLength', | ||||
|           valueOrVariable(bidirectionalLength) | ||||
|         ), | ||||
|       ] | ||||
|     : [] | ||||
|   const symmetricExpr = symmetric | ||||
|     ? [createLabeledArg('symmetric', createLiteral(symmetric))] | ||||
|     : [] | ||||
| @ -73,6 +83,7 @@ export function addExtrude({ | ||||
|   const sketchesExpr = createSketchExpression(sketchesExprList) | ||||
|   const call = createCallExpressionStdLibKw('extrude', sketchesExpr, [ | ||||
|     createLabeledArg('length', valueOrVariable(length)), | ||||
|     ...bidirectionalLengthExpr, | ||||
|     ...symmetricExpr, | ||||
|   ]) | ||||
|  | ||||
| @ -80,6 +91,17 @@ export function addExtrude({ | ||||
|   if ('variableName' in length && length.variableName) { | ||||
|     insertVariableAndOffsetPathToNode(length, modifiedAst, nodeToEdit) | ||||
|   } | ||||
|   if ( | ||||
|     bidirectionalLength && | ||||
|     'variableName' in bidirectionalLength && | ||||
|     bidirectionalLength.variableName | ||||
|   ) { | ||||
|     insertVariableAndOffsetPathToNode( | ||||
|       bidirectionalLength, | ||||
|       modifiedAst, | ||||
|       nodeToEdit | ||||
|     ) | ||||
|   } | ||||
|  | ||||
|   // 3. If edit, we assign the new function call declaration to the existing node, | ||||
|   // otherwise just push to the end | ||||
|  | ||||
| @ -61,7 +61,7 @@ export type ModelingCommandSchema = { | ||||
|     sketches: Selections | ||||
|     length: KclCommandValue | ||||
|     symmetric?: boolean | ||||
|     // bidirectionalLength?: KclCommandValue | ||||
|     bidirectionalLength?: KclCommandValue | ||||
|   } | ||||
|   Sweep: { | ||||
|     // Enables editing workflow | ||||
| @ -405,13 +405,12 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< | ||||
|           { name: 'True', value: true }, | ||||
|         ], | ||||
|       }, | ||||
|       // bidirectionalLength: { | ||||
|       //   inputType: 'kcl', | ||||
|       //   defaultValue: KCL_DEFAULT_LENGTH, | ||||
|       //   skip: true, | ||||
|       //   hidden: false, | ||||
|       //   required: false, | ||||
|       // }, | ||||
|       bidirectionalLength: { | ||||
|         inputType: 'kcl', | ||||
|         defaultValue: KCL_DEFAULT_LENGTH, | ||||
|         skip: true, | ||||
|         required: false, | ||||
|       }, | ||||
|     }, | ||||
|   }, | ||||
|   Sweep: { | ||||
|  | ||||
| @ -20,12 +20,13 @@ import { | ||||
|   type Program, | ||||
|   pathToNodeFromRustNodePath, | ||||
|   type VariableDeclaration, | ||||
|   type ParseResult, | ||||
| } from '@src/lang/wasm' | ||||
| import type { | ||||
|   HelixModes, | ||||
|   ModelingCommandSchema, | ||||
| } from '@src/lib/commandBarConfigs/modelingCommandConfig' | ||||
| import type { KclExpression } from '@src/lib/commandTypes' | ||||
| import type { KclCommandValue, KclExpression } from '@src/lib/commandTypes' | ||||
| import { | ||||
|   stringToKclExpression, | ||||
|   retrieveArgFromPipedCallExpression, | ||||
| @ -95,7 +96,27 @@ const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => { | ||||
|     return { reason: "Couldn't retrieve length argument" } | ||||
|   } | ||||
|  | ||||
|   // symmetric argument from a string to a KCL expression | ||||
|   // bidirectionalLength argument from a string to a KCL expression | ||||
|   let bidirectionalLength: KclCommandValue | Error | ParseResult | undefined | ||||
|   if ( | ||||
|     'bidirectionalLength' in operation.labeledArgs && | ||||
|     operation.labeledArgs.bidirectionalLength | ||||
|   ) { | ||||
|     bidirectionalLength = await stringToKclExpression( | ||||
|       codeManager.code.slice( | ||||
|         operation.labeledArgs.bidirectionalLength.sourceRange[0], | ||||
|         operation.labeledArgs.bidirectionalLength.sourceRange[1] | ||||
|       ) | ||||
|     ) | ||||
|   } | ||||
|   if ( | ||||
|     err(bidirectionalLength) || | ||||
|     (bidirectionalLength && 'errors' in bidirectionalLength) | ||||
|   ) { | ||||
|     return { reason: "Couldn't retrieve bidirectionalLength argument" } | ||||
|   } | ||||
|  | ||||
|   // symmetric argument from a string to boolean | ||||
|   let symmetric: boolean | undefined | ||||
|   if ('symmetric' in operation.labeledArgs && operation.labeledArgs.symmetric) { | ||||
|     symmetric = | ||||
| @ -111,6 +132,7 @@ const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => { | ||||
|   const argDefaultValues: ModelingCommandSchema['Extrude'] = { | ||||
|     sketches, | ||||
|     length, | ||||
|     bidirectionalLength, | ||||
|     symmetric, | ||||
|     nodeToEdit: pathToNodeFromRustNodePath(operation.nodePath), | ||||
|   } | ||||
|  | ||||
| @ -2429,12 +2429,14 @@ export const modelingMachine = setup({ | ||||
|           return Promise.reject(new Error(NO_INPUT_PROVIDED_MESSAGE)) | ||||
|         } | ||||
|  | ||||
|         const { nodeToEdit, sketches, length, symmetric } = input | ||||
|         const { nodeToEdit, sketches, length, bidirectionalLength, symmetric } = | ||||
|           input | ||||
|         const { ast } = kclManager | ||||
|         const astResult = addExtrude({ | ||||
|           ast, | ||||
|           sketches, | ||||
|           length, | ||||
|           bidirectionalLength, | ||||
|           symmetric, | ||||
|           nodeToEdit, | ||||
|         }) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user