Change to shared prepareToEdit function
This commit is contained in:
@ -1573,7 +1573,7 @@ sketch002 = startSketchOn(XZ)
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test(`Fillet point-and-click`, async ({
|
test(`Fillet point-and-click add`, async ({
|
||||||
context,
|
context,
|
||||||
page,
|
page,
|
||||||
homePage,
|
homePage,
|
||||||
@ -2130,7 +2130,7 @@ extrude001 = extrude(profile001, length = 5)
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test(`Chamfer point-and-click`, async ({
|
test(`Chamfer point-and-click add`, async ({
|
||||||
context,
|
context,
|
||||||
page,
|
page,
|
||||||
homePage,
|
homePage,
|
||||||
|
|||||||
@ -122,22 +122,25 @@ const prepareToEditExtrude: PrepareToEditCallback =
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gather up the argument values for the Fillet command
|
* Gather up the argument values for the Chamfer or Fillet command
|
||||||
* to be used in the command bar edit flow.
|
* to be used in the command bar edit flow.
|
||||||
*/
|
*/
|
||||||
const prepareToEditChamfer: PrepareToEditCallback = async ({
|
const prepareToEditEdgeTreatment: PrepareToEditCallback = async ({
|
||||||
operation,
|
operation,
|
||||||
artifact,
|
artifact,
|
||||||
}) => {
|
}) => {
|
||||||
|
const isChamfer =
|
||||||
|
artifact?.type === 'edgeCut' && artifact.subType === 'chamfer'
|
||||||
|
const isFillet = artifact?.type === 'edgeCut' && artifact.subType === 'fillet'
|
||||||
const baseCommand = {
|
const baseCommand = {
|
||||||
name: 'Chamfer',
|
name: isChamfer ? 'Chamfer' : 'Fillet',
|
||||||
groupId: 'modeling',
|
groupId: 'modeling',
|
||||||
}
|
}
|
||||||
if (operation.type !== 'StdLibCall' || !operation.labeledArgs) {
|
if (
|
||||||
return baseCommand
|
operation.type !== 'StdLibCall' ||
|
||||||
}
|
!operation.labeledArgs ||
|
||||||
|
(!isChamfer && !isFillet)
|
||||||
if (artifact?.type !== 'edgeCut' || artifact.subType !== 'chamfer') {
|
) {
|
||||||
return baseCommand
|
return baseCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,122 +174,66 @@ const prepareToEditChamfer: PrepareToEditCallback = async ({
|
|||||||
return baseCommand
|
return baseCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the radius argument from a string to a KCL expression
|
const selection = {
|
||||||
const legnthResult = await stringToKclExpression(
|
graphSelections: [
|
||||||
|
{
|
||||||
|
artifact: edgeArtifact,
|
||||||
|
codeRef: edgeCodeRef,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
otherSelections: [],
|
||||||
|
}
|
||||||
|
console.log('selection', selection)
|
||||||
|
|
||||||
|
// Assemble the default argument values for the Fillet command,
|
||||||
|
// with `nodeToEdit` set, which will let the Fillet actor know
|
||||||
|
// to edit the node that corresponds to the StdLibCall.
|
||||||
|
const nodeToEdit = getNodePathFromSourceRange(
|
||||||
|
kclManager.ast,
|
||||||
|
sourceRangeFromRust(operation.sourceRange)
|
||||||
|
)
|
||||||
|
let argDefaultValues:
|
||||||
|
| ModelingCommandSchema['Chamfer']
|
||||||
|
| ModelingCommandSchema['Fillet']
|
||||||
|
| undefined
|
||||||
|
|
||||||
|
if (isChamfer) {
|
||||||
|
// Convert the length argument from a string to a KCL expression
|
||||||
|
const length = await stringToKclExpression(
|
||||||
codeManager.code.slice(
|
codeManager.code.slice(
|
||||||
operation.labeledArgs?.['length']?.sourceRange[0],
|
operation.labeledArgs?.['length']?.sourceRange[0],
|
||||||
operation.labeledArgs?.['length']?.sourceRange[1]
|
operation.labeledArgs?.['length']?.sourceRange[1]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (err(legnthResult) || 'errors' in legnthResult) {
|
if (err(length) || 'errors' in length) {
|
||||||
return baseCommand
|
return baseCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assemble the default argument values for the Fillet command,
|
argDefaultValues = {
|
||||||
// with `nodeToEdit` set, which will let the Fillet actor know
|
selection,
|
||||||
// to edit the node that corresponds to the StdLibCall.
|
length,
|
||||||
const argDefaultValues: ModelingCommandSchema['Chamfer'] = {
|
nodeToEdit,
|
||||||
selection: {
|
|
||||||
graphSelections: [
|
|
||||||
{
|
|
||||||
artifact: edgeArtifact,
|
|
||||||
codeRef: edgeCodeRef,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
otherSelections: [],
|
|
||||||
},
|
|
||||||
length: legnthResult,
|
|
||||||
nodeToEdit: getNodePathFromSourceRange(
|
|
||||||
kclManager.ast,
|
|
||||||
sourceRangeFromRust(operation.sourceRange)
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
return {
|
} else if (isFillet) {
|
||||||
...baseCommand,
|
const radius = await stringToKclExpression(
|
||||||
argDefaultValues,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gather up the argument values for the Fillet command
|
|
||||||
* to be used in the command bar edit flow.
|
|
||||||
*/
|
|
||||||
const prepareToEditFillet: PrepareToEditCallback = async ({
|
|
||||||
operation,
|
|
||||||
artifact,
|
|
||||||
}) => {
|
|
||||||
const baseCommand = {
|
|
||||||
name: 'Fillet',
|
|
||||||
groupId: 'modeling',
|
|
||||||
}
|
|
||||||
if (operation.type !== 'StdLibCall' || !operation.labeledArgs) {
|
|
||||||
return baseCommand
|
|
||||||
}
|
|
||||||
|
|
||||||
if (artifact?.type !== 'edgeCut' || artifact.subType !== 'fillet') {
|
|
||||||
return baseCommand
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recreate the selection argument (artiface and codeRef) from what we have
|
|
||||||
const edgeArtifact = getArtifactOfTypes(
|
|
||||||
{
|
|
||||||
key: artifact.consumedEdgeId,
|
|
||||||
types: ['segment', 'sweepEdge'],
|
|
||||||
},
|
|
||||||
engineCommandManager.artifactGraph
|
|
||||||
)
|
|
||||||
if (err(edgeArtifact)) {
|
|
||||||
return baseCommand
|
|
||||||
}
|
|
||||||
|
|
||||||
let edgeCodeRef: CodeRef | undefined
|
|
||||||
if (edgeArtifact.type === 'segment') {
|
|
||||||
edgeCodeRef = edgeArtifact.codeRef
|
|
||||||
} else if (edgeArtifact.type === 'sweepEdge') {
|
|
||||||
// Little round about to the sketch to get the coderef
|
|
||||||
const correspondingSegmentArtifact = getArtifactOfTypes(
|
|
||||||
{
|
|
||||||
key: edgeArtifact.segId,
|
|
||||||
types: ['segment'],
|
|
||||||
},
|
|
||||||
engineCommandManager.artifactGraph
|
|
||||||
)
|
|
||||||
if (err(correspondingSegmentArtifact)) return baseCommand
|
|
||||||
edgeCodeRef = correspondingSegmentArtifact.codeRef
|
|
||||||
} else {
|
|
||||||
return baseCommand
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert the radius argument from a string to a KCL expression
|
|
||||||
const radiusResult = await stringToKclExpression(
|
|
||||||
codeManager.code.slice(
|
codeManager.code.slice(
|
||||||
operation.labeledArgs?.['radius']?.sourceRange[0],
|
operation.labeledArgs?.['radius']?.sourceRange[0],
|
||||||
operation.labeledArgs?.['radius']?.sourceRange[1]
|
operation.labeledArgs?.['radius']?.sourceRange[1]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (err(radiusResult) || 'errors' in radiusResult) {
|
if (err(radius) || 'errors' in radius) {
|
||||||
return baseCommand
|
return baseCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assemble the default argument values for the Fillet command,
|
argDefaultValues = {
|
||||||
// with `nodeToEdit` set, which will let the Fillet actor know
|
selection,
|
||||||
// to edit the node that corresponds to the StdLibCall.
|
radius,
|
||||||
const argDefaultValues: ModelingCommandSchema['Fillet'] = {
|
nodeToEdit,
|
||||||
selection: {
|
|
||||||
graphSelections: [
|
|
||||||
{
|
|
||||||
artifact: edgeArtifact,
|
|
||||||
codeRef: edgeCodeRef,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
otherSelections: [],
|
|
||||||
},
|
|
||||||
radius: radiusResult,
|
|
||||||
nodeToEdit: getNodePathFromSourceRange(
|
|
||||||
kclManager.ast,
|
|
||||||
sourceRangeFromRust(operation.sourceRange)
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return baseCommand
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...baseCommand,
|
...baseCommand,
|
||||||
argDefaultValues,
|
argDefaultValues,
|
||||||
@ -732,7 +679,7 @@ export const stdLibMap: Record<string, StdLibCallInfo> = {
|
|||||||
chamfer: {
|
chamfer: {
|
||||||
label: 'Chamfer',
|
label: 'Chamfer',
|
||||||
icon: 'chamfer3d',
|
icon: 'chamfer3d',
|
||||||
prepareToEdit: prepareToEditChamfer,
|
prepareToEdit: prepareToEditEdgeTreatment,
|
||||||
// modelingEvent: 'Chamfer',
|
// modelingEvent: 'Chamfer',
|
||||||
},
|
},
|
||||||
extrude: {
|
extrude: {
|
||||||
@ -744,7 +691,7 @@ export const stdLibMap: Record<string, StdLibCallInfo> = {
|
|||||||
fillet: {
|
fillet: {
|
||||||
label: 'Fillet',
|
label: 'Fillet',
|
||||||
icon: 'fillet3d',
|
icon: 'fillet3d',
|
||||||
prepareToEdit: prepareToEditFillet,
|
prepareToEdit: prepareToEditEdgeTreatment,
|
||||||
},
|
},
|
||||||
helix: {
|
helix: {
|
||||||
label: 'Helix',
|
label: 'Helix',
|
||||||
|
|||||||
Reference in New Issue
Block a user