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