Clean up for review

This commit is contained in:
Pierre Jacquier
2025-02-28 13:56:29 -05:00
parent d08f671ab3
commit 575844ff45
6 changed files with 22 additions and 33 deletions

View File

@ -230,22 +230,15 @@ export const sweepValidator = async ({
data, data,
}: { }: {
context: CommandBarContext context: CommandBarContext
data: { trajectory?: Selections; sectional?: boolean } data: { trajectory: Selections }
}): Promise<boolean | string> => { }): Promise<boolean | string> => {
console.log('sweepValidator', context, data) if (!isSelections(data.trajectory)) {
// Retrieve the sectional argument if it exists
const sectional = data.sectional ?? false
// Retrieve the parent path from the segment selection directly
const trajectoryArgument =
data.trajectory ?? context.argumentsToSubmit['trajectory']
if (!isSelections(trajectoryArgument)) {
console.log('Unable to sweep, selections are missing') console.log('Unable to sweep, selections are missing')
return 'Unable to sweep, selections are missing' return 'Unable to sweep, selections are missing'
} }
const trajectoryArtifact = trajectoryArgument.graphSelections[0].artifact // Retrieve the parent path from the segment selection directly
const trajectoryArtifact = data.trajectory.graphSelections[0].artifact
if (!trajectoryArtifact) { if (!trajectoryArtifact) {
return "Unable to sweep, couldn't find the trajectory artifact" return "Unable to sweep, couldn't find the trajectory artifact"
} }
@ -268,13 +261,13 @@ export const sweepValidator = async ({
const command = async () => { const command = async () => {
// TODO: second look on defaults here // TODO: second look on defaults here
const DEFAULT_TOLERANCE: Models['LengthUnit_type'] = 1e-7 const DEFAULT_TOLERANCE: Models['LengthUnit_type'] = 1e-7
const DEFAULT_SECTIONAL = false
const cmdArgs = { const cmdArgs = {
target, target,
trajectory, trajectory,
sectional, sectional: DEFAULT_SECTIONAL,
tolerance: DEFAULT_TOLERANCE, tolerance: DEFAULT_TOLERANCE,
} }
console.log(cmdArgs)
return await engineCommandManager.sendSceneCommand({ return await engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req', type: 'modeling_cmd_req',
cmd_id: uuidv4(), cmd_id: uuidv4(),

View File

@ -144,13 +144,6 @@ export type CommandArgumentConfig<
machineContext?: C machineContext?: C
) => OutputType) ) => OutputType)
defaultValueFromContext?: (context: C) => OutputType defaultValueFromContext?: (context: C) => OutputType
validation?: ({
data,
context,
}: {
data: any
context: CommandBarContext
}) => Promise<boolean | string>
} }
| { | {
inputType: 'selection' inputType: 'selection'
@ -264,13 +257,6 @@ export type CommandArgument<
commandBarContext: ContextFrom<typeof commandBarMachine>, commandBarContext: ContextFrom<typeof commandBarMachine>,
machineContext?: ContextFrom<T> machineContext?: ContextFrom<T>
) => OutputType) ) => OutputType)
validation?: ({
data,
context,
}: {
data: any
context: CommandBarContext
}) => Promise<boolean | string>
} }
| { | {
inputType: 'selection' inputType: 'selection'

View File

@ -178,7 +178,6 @@ export function buildCommandArgument<
options: arg.optionsFromContext options: arg.optionsFromContext
? arg.optionsFromContext(context) ? arg.optionsFromContext(context)
: arg.options, : arg.options,
validation: arg.validation,
} satisfies CommandArgument<O, T> & { inputType: 'options' } } satisfies CommandArgument<O, T> & { inputType: 'options' }
} else if (arg.inputType === 'selection') { } else if (arg.inputType === 'selection') {
return { return {

View File

@ -213,7 +213,7 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
} }
// We have to go a little roundabout to get from the original artifact // We have to go a little roundabout to get from the original artifact
// to the solid2DId that we need to pass to the Extrude command. // to the solid2DId that we need to pass to the Sweep command, just like Extrude.
const pathArtifact = getArtifactOfTypes( const pathArtifact = getArtifactOfTypes(
{ {
key: artifact.pathId, key: artifact.pathId,
@ -221,12 +221,15 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
}, },
engineCommandManager.artifactGraph engineCommandManager.artifactGraph
) )
if ( if (
err(pathArtifact) || err(pathArtifact) ||
pathArtifact.type !== 'path' || pathArtifact.type !== 'path' ||
!pathArtifact.solid2dId !pathArtifact.solid2dId
) ) {
return baseCommand return baseCommand
}
const targetArtifact = getArtifactOfTypes( const targetArtifact = getArtifactOfTypes(
{ {
key: pathArtifact.solid2dId, key: pathArtifact.solid2dId,
@ -234,6 +237,7 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
}, },
engineCommandManager.artifactGraph engineCommandManager.artifactGraph
) )
if (err(targetArtifact) || targetArtifact.type !== 'solid2d') { if (err(targetArtifact) || targetArtifact.type !== 'solid2d') {
return baseCommand return baseCommand
} }
@ -249,12 +253,14 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
} }
// Same roundabout but twice for 'path' aka trajectory: sketch -> path -> segment // Same roundabout but twice for 'path' aka trajectory: sketch -> path -> segment
if (!('path' in operation.labeledArgs) || !operation.labeledArgs.path) if (!('path' in operation.labeledArgs) || !operation.labeledArgs.path) {
return baseCommand return baseCommand
}
if (operation.labeledArgs.path.value.type !== 'Sketch') { if (operation.labeledArgs.path.value.type !== 'Sketch') {
return baseCommand return baseCommand
} }
const trajectoryPathArtifact = getArtifactOfTypes( const trajectoryPathArtifact = getArtifactOfTypes(
{ {
key: operation.labeledArgs.path.value.value.artifactId, key: operation.labeledArgs.path.value.value.artifactId,
@ -262,6 +268,7 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
}, },
engineCommandManager.artifactGraph engineCommandManager.artifactGraph
) )
if (err(trajectoryPathArtifact) || trajectoryPathArtifact.type !== 'path') { if (err(trajectoryPathArtifact) || trajectoryPathArtifact.type !== 'path') {
return baseCommand return baseCommand
} }
@ -273,6 +280,7 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
}, },
engineCommandManager.artifactGraph engineCommandManager.artifactGraph
) )
if (err(trajectoryArtifact) || trajectoryArtifact.type !== 'segment') { if (err(trajectoryArtifact) || trajectoryArtifact.type !== 'segment') {
return baseCommand return baseCommand
} }
@ -291,8 +299,10 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
if ( if (
!('sectional' in operation.labeledArgs) || !('sectional' in operation.labeledArgs) ||
!operation.labeledArgs.sectional !operation.labeledArgs.sectional
) ) {
return baseCommand return baseCommand
}
const sectional = const sectional =
codeManager.code.slice( codeManager.code.slice(
operation.labeledArgs.sectional.sourceRange[0], operation.labeledArgs.sectional.sourceRange[0],

View File

@ -296,7 +296,6 @@ export const commandBarMachine = setup({
context.currentArgument && context.currentArgument &&
context.selectedCommand && context.selectedCommand &&
(argConfig?.inputType === 'selection' || (argConfig?.inputType === 'selection' ||
argConfig?.inputType === 'options' ||
argConfig?.inputType === 'selectionMixed') && argConfig?.inputType === 'selectionMixed') &&
argConfig?.validation argConfig?.validation
) { ) {

View File

@ -1899,6 +1899,7 @@ export const modelingMachine = setup({
nodeToEdit, nodeToEdit,
'VariableDeclaration' 'VariableDeclaration'
) )
if (err(variableNode)) { if (err(variableNode)) {
console.error('Error extracting name') console.error('Error extracting name')
} else { } else {
@ -1951,6 +1952,7 @@ export const modelingMachine = setup({
variableName, variableName,
insertIndex, insertIndex,
}) })
const updatedAst = await kclManager.updateAst( const updatedAst = await kclManager.updateAst(
addResult.modifiedAst, addResult.modifiedAst,
true, true,