Move axes to std constants; move helix, revolve, and mirror2d to be declared in KCL (#6105)
Move axes to std constants; move helix, revolve, and mirror2d to be declated in KCL Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import type { Operation } from '@rust/kcl-lib/bindings/Operation'
|
||||
import type { OpKclValue } from '@rust/kcl-lib/bindings/OpKclValue'
|
||||
|
||||
import type { CustomIconName } from '@src/components/CustomIcon'
|
||||
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
|
||||
@ -61,7 +62,7 @@ const prepareToEditExtrude: PrepareToEditCallback =
|
||||
if (
|
||||
!artifact ||
|
||||
!('pathId' in artifact) ||
|
||||
operation.type !== 'StdLibCall'
|
||||
(operation.type !== 'StdLibCall' && operation.type !== 'KclStdLibCall')
|
||||
) {
|
||||
return baseCommand
|
||||
}
|
||||
@ -144,7 +145,7 @@ const prepareToEditEdgeTreatment: PrepareToEditCallback = async ({
|
||||
groupId: 'modeling',
|
||||
}
|
||||
if (
|
||||
operation.type !== 'StdLibCall' ||
|
||||
(operation.type !== 'StdLibCall' && operation.type !== 'KclStdLibCall') ||
|
||||
!operation.labeledArgs ||
|
||||
(!isChamfer && !isFillet)
|
||||
) {
|
||||
@ -255,7 +256,7 @@ const prepareToEditShell: PrepareToEditCallback =
|
||||
}
|
||||
|
||||
if (
|
||||
operation.type !== 'StdLibCall' ||
|
||||
(operation.type !== 'StdLibCall' && operation.type !== 'KclStdLibCall') ||
|
||||
!operation.labeledArgs ||
|
||||
!operation.unlabeledArg ||
|
||||
operation.unlabeledArg.value.type !== 'Solid' ||
|
||||
@ -365,7 +366,7 @@ const prepareToEditOffsetPlane: PrepareToEditCallback = async ({
|
||||
groupId: 'modeling',
|
||||
}
|
||||
if (
|
||||
operation.type !== 'StdLibCall' ||
|
||||
(operation.type !== 'StdLibCall' && operation.type !== 'KclStdLibCall') ||
|
||||
!operation.labeledArgs ||
|
||||
!operation.unlabeledArg ||
|
||||
!('offset' in operation.labeledArgs) ||
|
||||
@ -439,7 +440,7 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
|
||||
groupId: 'modeling',
|
||||
}
|
||||
if (
|
||||
operation.type !== 'StdLibCall' ||
|
||||
(operation.type !== 'StdLibCall' && operation.type !== 'KclStdLibCall') ||
|
||||
!operation.labeledArgs ||
|
||||
!operation.unlabeledArg ||
|
||||
!('sectional' in operation.labeledArgs) ||
|
||||
@ -447,7 +448,11 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
|
||||
) {
|
||||
return baseCommand
|
||||
}
|
||||
if (!artifact || !('pathId' in artifact) || operation.type !== 'StdLibCall') {
|
||||
if (
|
||||
!artifact ||
|
||||
!('pathId' in artifact) ||
|
||||
(operation.type !== 'StdLibCall' && operation.type !== 'KclStdLibCall')
|
||||
) {
|
||||
return baseCommand
|
||||
}
|
||||
|
||||
@ -567,12 +572,20 @@ const prepareToEditSweep: PrepareToEditCallback = async ({
|
||||
}
|
||||
}
|
||||
|
||||
const nonZero = (val: OpKclValue): number => {
|
||||
if (val.type === 'Number') {
|
||||
return val.value
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
const prepareToEditHelix: PrepareToEditCallback = async ({ operation }) => {
|
||||
const baseCommand = {
|
||||
name: 'Helix',
|
||||
groupId: 'modeling',
|
||||
}
|
||||
if (operation.type !== 'StdLibCall' || !operation.labeledArgs) {
|
||||
if (operation.type !== 'KclStdLibCall' || !operation.labeledArgs) {
|
||||
return { reason: 'Wrong operation type or arguments' }
|
||||
}
|
||||
|
||||
@ -592,10 +605,22 @@ const prepareToEditHelix: PrepareToEditCallback = async ({ operation }) => {
|
||||
if ('axis' in operation.labeledArgs && operation.labeledArgs.axis) {
|
||||
// axis options string or selection arg
|
||||
const axisValue = operation.labeledArgs.axis.value
|
||||
if (axisValue.type === 'String') {
|
||||
// default axis casee
|
||||
if (axisValue.type === 'Object') {
|
||||
// default axis case
|
||||
mode = 'Axis'
|
||||
axis = axisValue.value
|
||||
const direction = axisValue.value['direction']
|
||||
if (!direction || direction.type !== 'Array') {
|
||||
return { reason: 'No direction vector for axis' }
|
||||
}
|
||||
if (nonZero(direction.value[0])) {
|
||||
axis = 'X'
|
||||
} else if (nonZero(direction.value[1])) {
|
||||
axis = 'Y'
|
||||
} else if (nonZero(direction.value[2])) {
|
||||
axis = 'Z'
|
||||
} else {
|
||||
return { reason: 'Bad direction vector for axis' }
|
||||
}
|
||||
} else if (axisValue.type === 'TagIdentifier' && axisValue.artifact_id) {
|
||||
// segment case
|
||||
mode = 'Edge'
|
||||
@ -812,7 +837,7 @@ const prepareToEditRevolve: PrepareToEditCallback = async ({
|
||||
if (
|
||||
!artifact ||
|
||||
!('pathId' in artifact) ||
|
||||
operation.type !== 'StdLibCall' ||
|
||||
operation.type !== 'KclStdLibCall' ||
|
||||
!operation.labeledArgs
|
||||
) {
|
||||
return { reason: 'Wrong operation type or artifact' }
|
||||
@ -865,10 +890,20 @@ const prepareToEditRevolve: PrepareToEditCallback = async ({
|
||||
let axisOrEdge: 'Axis' | 'Edge' | undefined
|
||||
let axis: string | undefined
|
||||
let edge: Selections | undefined
|
||||
if (axisValue.type === 'String') {
|
||||
if (axisValue.type === 'Object') {
|
||||
// default axis casee
|
||||
axisOrEdge = 'Axis'
|
||||
axis = axisValue.value
|
||||
const direction = axisValue.value['direction']
|
||||
if (!direction || direction.type !== 'Array') {
|
||||
return { reason: 'No direction vector for axis' }
|
||||
}
|
||||
if (nonZero(direction.value[0])) {
|
||||
axis = 'X'
|
||||
} else if (nonZero(direction.value[1])) {
|
||||
axis = 'Y'
|
||||
} else {
|
||||
return { reason: 'Bad direction vector for axis' }
|
||||
}
|
||||
} else if (axisValue.type === 'TagIdentifier' && axisValue.artifact_id) {
|
||||
// segment case
|
||||
axisOrEdge = 'Edge'
|
||||
@ -1081,6 +1116,8 @@ export function getOperationLabel(op: Operation): string {
|
||||
switch (op.type) {
|
||||
case 'StdLibCall':
|
||||
return stdLibMap[op.name]?.label ?? op.name
|
||||
case 'KclStdLibCall':
|
||||
return stdLibMap[op.name]?.label ?? op.name
|
||||
case 'UserDefinedFunctionCall':
|
||||
return op.name ?? 'Anonymous custom function'
|
||||
case 'UserDefinedFunctionReturn':
|
||||
@ -1095,6 +1132,8 @@ export function getOperationIcon(op: Operation): CustomIconName {
|
||||
switch (op.type) {
|
||||
case 'StdLibCall':
|
||||
return stdLibMap[op.name]?.icon ?? 'questionMark'
|
||||
case 'KclStdLibCall':
|
||||
return stdLibMap[op.name]?.icon ?? 'questionMark'
|
||||
default:
|
||||
return 'make-variable'
|
||||
}
|
||||
@ -1189,7 +1228,7 @@ export async function enterEditFlow({
|
||||
operation,
|
||||
artifact,
|
||||
}: EnterEditFlowProps): Promise<Error | CommandBarMachineEvent> {
|
||||
if (operation.type !== 'StdLibCall') {
|
||||
if (operation.type !== 'StdLibCall' && operation.type !== 'KclStdLibCall') {
|
||||
return new Error(
|
||||
'Feature tree editing not yet supported for user-defined functions. Please edit in the code editor.'
|
||||
)
|
||||
@ -1228,7 +1267,7 @@ export async function enterAppearanceFlow({
|
||||
operation,
|
||||
artifact,
|
||||
}: EnterEditFlowProps): Promise<Error | CommandBarMachineEvent> {
|
||||
if (operation.type !== 'StdLibCall') {
|
||||
if (operation.type !== 'StdLibCall' && operation.type !== 'KclStdLibCall') {
|
||||
return new Error(
|
||||
'Appearance setting not yet supported for user-defined functions. Please edit in the code editor.'
|
||||
)
|
||||
|
Reference in New Issue
Block a user