clean up create call back double function stuff

This commit is contained in:
Kurt Hutten Irev-Dev
2024-09-10 01:08:57 +10:00
parent 99ffc82ffa
commit 25080e9895
12 changed files with 700 additions and 775 deletions

View File

@ -10,10 +10,10 @@ import {
transformSecondarySketchLinesTagFirst,
getTransformInfos,
PathToNodeMap,
TransformInfo,
} from '../../lang/std/sketchcombos'
import { kclManager } from 'lib/singletons'
import { err } from 'lib/trap'
import { TransformInfo } from 'lang/std/stdTypes'
export function equalAngleInfo({
selectionRanges,

View File

@ -10,8 +10,8 @@ import {
transformSecondarySketchLinesTagFirst,
getTransformInfos,
PathToNodeMap,
TransformInfo,
} from '../../lang/std/sketchcombos'
import { TransformInfo } from 'lang/std/stdTypes'
import { kclManager } from 'lib/singletons'
import { err } from 'lib/trap'

View File

@ -9,8 +9,8 @@ import {
PathToNodeMap,
getTransformInfos,
transformAstSketchLines,
TransformInfo,
} from '../../lang/std/sketchcombos'
import { TransformInfo } from 'lang/std/stdTypes'
import { kclManager } from 'lib/singletons'
import { err } from 'lib/trap'

View File

@ -11,8 +11,8 @@ import {
transformSecondarySketchLinesTagFirst,
getTransformInfos,
PathToNodeMap,
TransformInfo,
} from '../../lang/std/sketchcombos'
import { TransformInfo } from 'lang/std/stdTypes'
import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal'
import { createVariableDeclaration } from '../../lang/modifyAst'
import { removeDoubleNegatives } from '../AvailableVarsHelpers'

View File

@ -9,8 +9,8 @@ import {
PathToNodeMap,
getRemoveConstraintsTransforms,
transformAstSketchLines,
TransformInfo,
} from '../../lang/std/sketchcombos'
import { TransformInfo } from 'lang/std/stdTypes'
import { kclManager } from 'lib/singletons'
import { err } from 'lib/trap'

View File

@ -9,8 +9,8 @@ import {
getTransformInfos,
transformAstSketchLines,
PathToNodeMap,
TransformInfo,
} from '../../lang/std/sketchcombos'
import { TransformInfo } from 'lang/std/stdTypes'
import {
SetAngleLengthModal,
createSetAngleLengthModal,

View File

@ -10,8 +10,8 @@ import {
transformSecondarySketchLinesTagFirst,
getTransformInfos,
PathToNodeMap,
TransformInfo,
} from '../../lang/std/sketchcombos'
import { TransformInfo } from 'lang/std/stdTypes'
import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal'
import { createVariableDeclaration } from '../../lang/modifyAst'
import { removeDoubleNegatives } from '../AvailableVarsHelpers'

View File

@ -9,8 +9,8 @@ import {
transformSecondarySketchLinesTagFirst,
getTransformInfos,
PathToNodeMap,
TransformInfo,
} from '../../lang/std/sketchcombos'
import { TransformInfo } from 'lang/std/stdTypes'
import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal'
import { createLiteral, createVariableDeclaration } from '../../lang/modifyAst'
import { removeDoubleNegatives } from '../AvailableVarsHelpers'

View File

@ -9,8 +9,8 @@ import {
PathToNodeMap,
getTransformInfos,
transformAstSketchLines,
TransformInfo,
} from '../../lang/std/sketchcombos'
import { TransformInfo } from 'lang/std/stdTypes'
import {
SetAngleLengthModal,
createSetAngleLengthModal,

View File

@ -28,7 +28,6 @@ import { createPipeExpression, splitPathAtPipeExpression } from '../modifyAst'
import {
SketchLineHelper,
TransformCallback,
ConstrainInfo,
ArrayItemInput,
ObjectPropertyInput,
@ -36,6 +35,8 @@ import {
AddTagInfo,
SegmentInputs,
SimplifiedArgDetails,
RawArgs,
CreateStdLibSketchCallExpr,
} from 'lang/std/stdTypes'
import {
@ -321,23 +322,20 @@ export const lineTo: SketchLineHelper = {
])
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
if (replaceExisting && createCallback) {
const { callExp, valueUsedInTransform } = createCallback(
[
{
type: 'arrayItem',
index: 0,
argType: 'xAbsolute',
expr: createLiteral(roundOff(to[0], 2)),
},
{
type: 'arrayItem',
index: 1,
argType: 'yAbsolute',
expr: createLiteral(roundOff(to[1], 2)),
},
],
referencedSegment
)
const { callExp, valueUsedInTransform } = createCallback([
{
type: 'arrayItem',
index: 0,
argType: 'xAbsolute',
expr: createLiteral(roundOff(to[0], 2)),
},
{
type: 'arrayItem',
index: 1,
argType: 'yAbsolute',
expr: createLiteral(roundOff(to[1], 2)),
},
])
pipe.body[callIndex] = callExp
return {
modifiedAst: _node,
@ -441,23 +439,20 @@ export const line: SketchLineHelper = {
if (replaceExisting && createCallback && pipe.type !== 'CallExpression') {
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
const { callExp, valueUsedInTransform } = createCallback(
[
{
type: 'arrayItem',
index: 0,
argType: 'xRelative',
expr: createLiteral(roundOff(to[0] - from[0], 2)),
},
{
type: 'arrayItem',
index: 1,
argType: 'yRelative',
expr: createLiteral(roundOff(to[1] - from[1], 2)),
},
],
referencedSegment
)
const { callExp, valueUsedInTransform } = createCallback([
{
type: 'arrayItem',
index: 0,
argType: 'xRelative',
expr: createLiteral(roundOff(to[0] - from[0], 2)),
},
{
type: 'arrayItem',
index: 1,
argType: 'yRelative',
expr: createLiteral(roundOff(to[1] - from[1], 2)),
},
])
pipe.body[callIndex] = callExp
return {
modifiedAst: _node,
@ -842,23 +837,20 @@ export const tangentialArcTo: SketchLineHelper = {
if (replaceExisting && createCallback && pipe.type !== 'CallExpression') {
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
const { callExp, valueUsedInTransform } = createCallback(
[
{
type: 'arrayItem',
index: 0,
argType: 'xRelative',
expr: toX,
},
{
type: 'arrayItem',
index: 1,
argType: 'yAbsolute',
expr: toY,
},
],
referencedSegment
)
const { callExp, valueUsedInTransform } = createCallback([
{
type: 'arrayItem',
index: 0,
argType: 'xRelative',
expr: toX,
},
{
type: 'arrayItem',
index: 1,
argType: 'yAbsolute',
expr: toY,
},
])
pipe.body[callIndex] = callExp
return {
modifiedAst: _node,
@ -1154,25 +1146,22 @@ export const angledLine: SketchLineHelper = {
if (replaceExisting && createCallback) {
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
const { callExp, valueUsedInTransform } = createCallback(
[
{
type: 'arrayOrObjItem',
index: 0,
key: 'angle',
argType: 'angle',
expr: newAngleVal,
},
{
type: 'arrayOrObjItem',
index: 1,
key: 'length',
argType: 'length',
expr: newLengthVal,
},
],
referencedSegment
)
const { callExp, valueUsedInTransform } = createCallback([
{
type: 'arrayOrObjItem',
index: 0,
key: 'angle',
argType: 'angle',
expr: newAngleVal,
},
{
type: 'arrayOrObjItem',
index: 1,
key: 'length',
argType: 'length',
expr: newLengthVal,
},
])
pipe.body[callIndex] = callExp
return {
modifiedAst: _node,
@ -1471,25 +1460,22 @@ export const angledLineToX: SketchLineHelper = {
const angle = createLiteral(roundOff(getAngle(from, to), 0))
const xArg = createLiteral(roundOff(to[0], 2))
if (replaceExisting && createCallback) {
const { callExp, valueUsedInTransform } = createCallback(
[
{
type: 'arrayOrObjItem',
index: 0,
key: 'angle',
argType: 'angle',
expr: angle,
},
{
type: 'arrayOrObjItem',
index: 1,
key: 'to',
argType: 'xAbsolute',
expr: xArg,
},
],
referencedSegment
)
const { callExp, valueUsedInTransform } = createCallback([
{
type: 'arrayOrObjItem',
index: 0,
key: 'angle',
argType: 'angle',
expr: angle,
},
{
type: 'arrayOrObjItem',
index: 1,
key: 'to',
argType: 'xAbsolute',
expr: xArg,
},
])
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
pipe.body[callIndex] = callExp
return {
@ -1575,25 +1561,22 @@ export const angledLineToY: SketchLineHelper = {
const yArg = createLiteral(roundOff(to[1], 2))
if (replaceExisting && createCallback) {
const { callExp, valueUsedInTransform } = createCallback(
[
{
type: 'arrayOrObjItem',
index: 0,
key: 'angle',
argType: 'angle',
expr: angle,
},
{
type: 'arrayOrObjItem',
index: 1,
key: 'to',
argType: 'yAbsolute',
expr: yArg,
},
],
referencedSegment
)
const { callExp, valueUsedInTransform } = createCallback([
{
type: 'arrayOrObjItem',
index: 0,
key: 'angle',
argType: 'angle',
expr: angle,
},
{
type: 'arrayOrObjItem',
index: 1,
key: 'to',
argType: 'yAbsolute',
expr: yArg,
},
])
const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
pipe.body[callIndex] = callExp
return {
@ -2121,7 +2104,7 @@ export function replaceSketchLine({
pathToNode: PathToNode
fnName: ToolTip
segmentInput: SegmentInputs
createCallback: TransformCallback
createCallback: (rawArgs: RawArgs) => ReturnType<CreateStdLibSketchCallExpr>
referencedSegment?: Path
}):
| {
@ -2151,13 +2134,16 @@ export function replaceSketchLine({
return { modifiedAst, valueUsedInTransform, pathToNode }
}
export function addTagForSketchOnFace(a: AddTagInfo, expressionName: string) {
export function addTagForSketchOnFace(
tagInfo: AddTagInfo,
expressionName: string
) {
if (expressionName === 'close') {
return addTag(1)(a)
return addTag(1)(tagInfo)
}
if (expressionName in sketchLineHelperMap) {
const { addTag } = sketchLineHelperMap[expressionName]
return addTag(a)
return addTag(tagInfo)
}
return new Error(`"${expressionName}" is not a sketch line helper`)
}

File diff suppressed because it is too large Load Diff

View File

@ -69,7 +69,7 @@ interface addCall extends ModifyAstBase {
segmentInput: SegmentInputs
referencedSegment?: Path
replaceExisting?: boolean
createCallback?: TransformCallback // TODO: #29 probably should not be optional
createCallback?: (rawArgs: RawArgs) => ReturnType<CreateStdLibSketchCallExpr>
/// defaults to false, normal behavior is to add a new callExpression to the end of the pipeExpression
spliceBetween?: boolean
}
@ -149,13 +149,13 @@ type RawArg = _VarValue<Literal>
export type InputArgs = Array<InputArg>
// /**
// * The literal equivalent of whatever current expression is
// * i.e. if the expression is 5 + 6, the literal would be 11
// * but of course works for expressions like myVar + someFn() etc too
// * This is useful in cases where we want to "un-constrain" inputs to segments
// */
type RawArgs = Array<RawArg>
/**
* The literal equivalent of whatever current expression is
* i.e. if the expression is 5 + 6, the literal would be 11
* but of course works for expressions like myVar + someFn() etc too
* This is useful in cases where we want to "un-constrain" inputs to segments
*/
export type RawArgs = Array<RawArg>
/**
* Serves the same role as {@link InputArg} on {@link RawArg}
@ -174,14 +174,23 @@ export type SimplifiedArgDetails =
index: 0 | 1
}
export type TransformCallback = (
inputs: InputArgs,
export type CreateStdLibSketchCallExpr = (args: {
inputs: InputArgs
referenceSegName: string
tag?: Expr
forceValueUsedInTransform?: Expr
rawArgs: InputArgs
referencedSegment?: Path
) => {
}) => {
callExp: Expr
valueUsedInTransform?: number
}
export type TransformInfo = {
tooltip: ToolTip
createNode: CreateStdLibSketchCallExpr
}
export interface ConstrainInfo {
stdLibFnName: ToolTip
type: