Skip to content
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
2 changes: 1 addition & 1 deletion src/lang/modifyAst/gdt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export function addDatumGdt({
* Deduplicates face expressions based on their string representation.
* This prevents creating multiple annotations for the same face.
*/
function deduplicateFaceExprs(facesExprs: Expr[]): Expr[] {
export function deduplicateFaceExprs(facesExprs: Expr[]): Expr[] {
const seen = new Set<string>()
const unique: Expr[] = []

Expand Down
56 changes: 52 additions & 4 deletions src/lang/modifyAst/sweeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from '@src/lang/std/artifactGraph'
import type {
ArtifactGraph,
Expr,
LabeledArg,
PathToNode,
Program,
Expand All @@ -39,6 +40,7 @@ import type { KclCommandValue } from '@src/lib/commandTypes'
import { KCL_DEFAULT_CONSTANT_PREFIXES } from '@src/lib/constants'
import { err } from '@src/lib/trap'
import type { Selections } from '@src/machines/modelingSharedTypes'
import { isFaceArtifact } from '@src/lang/modifyAst/faces'
import { getEdgeTagCall } from '@src/lang/modifyAst/edges'

export function addExtrude({
Expand Down Expand Up @@ -82,10 +84,56 @@ export function addExtrude({
const mNodeToEdit = structuredClone(nodeToEdit)

// 2. Prepare unlabeled and labeled arguments
// Map the sketches selection into a list of kcl expressions to be passed as unlabelled argument
const vars = getVariableExprsFromSelection(sketches, modifiedAst, mNodeToEdit)
if (err(vars)) {
return vars
// Filter to only include face selections
let vars:
| undefined
| {
exprs: Expr[]
pathIfPipe?: PathToNode
}
const faceSelections = sketches.graphSelections.filter((selection) =>
isFaceArtifact(selection.artifact)
)

if (faceSelections.length > 0) {
// Handle the face selection case (vs. regular sketches below)
const tagsExprs: Expr[] = []
for (const faceSelection of faceSelections) {
const tagResult = modifyAstWithTagsForSelection(
modifiedAst,
faceSelection,
artifactGraph
)
if (err(tagResult)) {
console.warn('Failed to add tag for face selection', tagResult)
continue
}

// Update the AST with the tagged version
modifiedAst = tagResult.modifiedAst

// Create expression from the first tag (faces have one tag)
tagsExprs.push(createLocalName(tagResult.tags[0]))
}

if (tagsExprs.length === 0) {
return new Error(
'No valid face expressions could be generated from selection'
)
}

vars = { exprs: tagsExprs }
} else {
// Map the sketches selection into a list of kcl expressions to be passed as unlabelled argument
const res = getVariableExprsFromSelection(
sketches,
modifiedAst,
mNodeToEdit
)
if (err(res)) {
return res
}
vars = res
}

// Extra labeled args expressions
Expand Down
2 changes: 1 addition & 1 deletion src/lib/commandBarConfigs/modelingCommandConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
sketches: {
inputType: 'selection',
displayName: 'Profiles',
selectionTypes: ['solid2d'],
selectionTypes: ['solid2d', 'cap', 'wall', 'edgeCut'],
multiple: true,
required: true,
hidden: (context) => Boolean(context.argumentsToSubmit.nodeToEdit),
Expand Down
Loading