Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Shell dry-run validation with thickness arg #5118

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/lib/commandBarConfigs/modelingCommandConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,12 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
selectionTypes: ['cap', 'wall'],
multiple: true,
required: true,
validation: shellValidator,
},
thickness: {
inputType: 'kcl',
defaultValue: KCL_DEFAULT_LENGTH,
required: true,
// TODO: add dry-run validation on thickness param
validation: shellValidator,
},
},
},
Expand Down
18 changes: 11 additions & 7 deletions src/lib/commandBarConfigs/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { engineCommandManager } from 'lib/singletons'
import { uuidv4 } from 'lib/utils'
import { CommandBarContext } from 'machines/commandBarMachine'
import { Selections } from 'lib/selections'
import { KclCommandValue } from 'lib/commandTypes'

export const disableDryRunWithRetry = async (numberOfRetries = 3) => {
for (let tries = 0; tries < numberOfRetries; tries++) {
Expand Down Expand Up @@ -155,16 +156,21 @@ export const loftValidator = async ({
}

export const shellValidator = async ({
context,
data,
}: {
data: { selection: Selections }
context: CommandBarContext
data: { thickness: KclCommandValue }
}): Promise<boolean | string> => {
if (!isSelections(data.selection)) {
const thicknessArg = data.thickness
const selectionArg = context.argumentsToSubmit['selection'] as Selections
if (!isSelections(selectionArg)) {
return 'Unable to shell, selections are missing'
}

// No validation on the faces, filtering is done upstream and we have the dry run validation just below
const face_ids = data.selection.graphSelections.flatMap((s) =>
// No validation on the args, filtering is done upstream and we have the dry run validation just below
const shell_thickness = Number(thicknessArg.valueCalculated)
const face_ids = selectionArg.graphSelections.flatMap((s) =>
s.artifact ? s.artifact.id : []
)

Expand All @@ -181,14 +187,12 @@ export const shellValidator = async ({
}

const shellCommand = async () => {
// TODO: figure out something better than an arbitrarily small value
const DEFAULT_THICKNESS: Models['LengthUnit_type'] = 1e-9
const DEFAULT_HOLLOW = false
const cmdArgs = {
face_ids,
object_id,
shell_thickness,
hollow: DEFAULT_HOLLOW,
shell_thickness: DEFAULT_THICKNESS,
}
return await engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
Expand Down
14 changes: 14 additions & 0 deletions src/lib/commandTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ export type CommandArgumentConfig<
commandBarContext: ContextFrom<typeof commandBarMachine>,
machineContext?: C
) => string)
validation?: ({
data,
context,
}: {
data: any
context: CommandBarContext
}) => Promise<boolean | string>
}
| {
inputType: 'string'
Expand Down Expand Up @@ -267,6 +274,13 @@ export type CommandArgument<
commandBarContext: ContextFrom<typeof commandBarMachine>,
machineContext?: ContextFrom<T>
) => string)
validation?: ({
data,
context,
}: {
data: any
context: CommandBarContext
}) => Promise<boolean | string>
}
| {
inputType: 'string'
Expand Down
1 change: 1 addition & 0 deletions src/lib/createMachineCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export function buildCommandArgument<
createVariableByDefault: arg.createVariableByDefault,
variableName: arg.variableName,
defaultValue: arg.defaultValue,
validation: arg.validation,
...baseCommandArgument,
} satisfies CommandArgument<O, T> & { inputType: 'kcl' }
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/machines/commandBarMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ export const commandBarMachine = setup({
if (
context.currentArgument &&
context.selectedCommand &&
argConfig?.inputType === 'selection' &&
(argConfig?.inputType === 'selection' ||
argConfig?.inputType === 'kcl') &&
argConfig?.validation
) {
argConfig
Expand Down
Loading