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,
}: {
context: CommandBarContext
data: { trajectory?: Selections; sectional?: boolean }
data: { trajectory: Selections }
}): Promise<boolean | string> => {
console.log('sweepValidator', context, data)
// 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)) {
if (!isSelections(data.trajectory)) {
console.log('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) {
return "Unable to sweep, couldn't find the trajectory artifact"
}
@ -268,13 +261,13 @@ export const sweepValidator = async ({
const command = async () => {
// TODO: second look on defaults here
const DEFAULT_TOLERANCE: Models['LengthUnit_type'] = 1e-7
const DEFAULT_SECTIONAL = false
const cmdArgs = {
target,
trajectory,
sectional,
sectional: DEFAULT_SECTIONAL,
tolerance: DEFAULT_TOLERANCE,
}
console.log(cmdArgs)
return await engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),

View File

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

View File

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

View File

@ -213,7 +213,7 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
}
// 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(
{
key: artifact.pathId,
@ -221,12 +221,15 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
},
engineCommandManager.artifactGraph
)
if (
err(pathArtifact) ||
pathArtifact.type !== 'path' ||
!pathArtifact.solid2dId
)
) {
return baseCommand
}
const targetArtifact = getArtifactOfTypes(
{
key: pathArtifact.solid2dId,
@ -234,6 +237,7 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
},
engineCommandManager.artifactGraph
)
if (err(targetArtifact) || targetArtifact.type !== 'solid2d') {
return baseCommand
}
@ -249,12 +253,14 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
}
// 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
}
if (operation.labeledArgs.path.value.type !== 'Sketch') {
return baseCommand
}
const trajectoryPathArtifact = getArtifactOfTypes(
{
key: operation.labeledArgs.path.value.value.artifactId,
@ -262,6 +268,7 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
},
engineCommandManager.artifactGraph
)
if (err(trajectoryPathArtifact) || trajectoryPathArtifact.type !== 'path') {
return baseCommand
}
@ -273,6 +280,7 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
},
engineCommandManager.artifactGraph
)
if (err(trajectoryArtifact) || trajectoryArtifact.type !== 'segment') {
return baseCommand
}
@ -291,8 +299,10 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
if (
!('sectional' in operation.labeledArgs) ||
!operation.labeledArgs.sectional
)
) {
return baseCommand
}
const sectional =
codeManager.code.slice(
operation.labeledArgs.sectional.sourceRange[0],

View File

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

View File

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