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, transformSecondarySketchLinesTagFirst,
getTransformInfos, getTransformInfos,
PathToNodeMap, PathToNodeMap,
TransformInfo,
} from '../../lang/std/sketchcombos' } from '../../lang/std/sketchcombos'
import { kclManager } from 'lib/singletons' import { kclManager } from 'lib/singletons'
import { err } from 'lib/trap' import { err } from 'lib/trap'
import { TransformInfo } from 'lang/std/stdTypes'
export function equalAngleInfo({ export function equalAngleInfo({
selectionRanges, selectionRanges,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,6 @@ import { createPipeExpression, splitPathAtPipeExpression } from '../modifyAst'
import { import {
SketchLineHelper, SketchLineHelper,
TransformCallback,
ConstrainInfo, ConstrainInfo,
ArrayItemInput, ArrayItemInput,
ObjectPropertyInput, ObjectPropertyInput,
@ -36,6 +35,8 @@ import {
AddTagInfo, AddTagInfo,
SegmentInputs, SegmentInputs,
SimplifiedArgDetails, SimplifiedArgDetails,
RawArgs,
CreateStdLibSketchCallExpr,
} from 'lang/std/stdTypes' } from 'lang/std/stdTypes'
import { import {
@ -321,23 +322,20 @@ export const lineTo: SketchLineHelper = {
]) ])
const { index: callIndex } = splitPathAtPipeExpression(pathToNode) const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
if (replaceExisting && createCallback) { if (replaceExisting && createCallback) {
const { callExp, valueUsedInTransform } = createCallback( const { callExp, valueUsedInTransform } = createCallback([
[ {
{ type: 'arrayItem',
type: 'arrayItem', index: 0,
index: 0, argType: 'xAbsolute',
argType: 'xAbsolute', expr: createLiteral(roundOff(to[0], 2)),
expr: createLiteral(roundOff(to[0], 2)), },
}, {
{ type: 'arrayItem',
type: 'arrayItem', index: 1,
index: 1, argType: 'yAbsolute',
argType: 'yAbsolute', expr: createLiteral(roundOff(to[1], 2)),
expr: createLiteral(roundOff(to[1], 2)), },
}, ])
],
referencedSegment
)
pipe.body[callIndex] = callExp pipe.body[callIndex] = callExp
return { return {
modifiedAst: _node, modifiedAst: _node,
@ -441,23 +439,20 @@ export const line: SketchLineHelper = {
if (replaceExisting && createCallback && pipe.type !== 'CallExpression') { if (replaceExisting && createCallback && pipe.type !== 'CallExpression') {
const { index: callIndex } = splitPathAtPipeExpression(pathToNode) const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
const { callExp, valueUsedInTransform } = createCallback( const { callExp, valueUsedInTransform } = createCallback([
[ {
{ type: 'arrayItem',
type: 'arrayItem', index: 0,
index: 0, argType: 'xRelative',
argType: 'xRelative', expr: createLiteral(roundOff(to[0] - from[0], 2)),
expr: createLiteral(roundOff(to[0] - from[0], 2)), },
}, {
{ type: 'arrayItem',
type: 'arrayItem', index: 1,
index: 1, argType: 'yRelative',
argType: 'yRelative', expr: createLiteral(roundOff(to[1] - from[1], 2)),
expr: createLiteral(roundOff(to[1] - from[1], 2)), },
}, ])
],
referencedSegment
)
pipe.body[callIndex] = callExp pipe.body[callIndex] = callExp
return { return {
modifiedAst: _node, modifiedAst: _node,
@ -842,23 +837,20 @@ export const tangentialArcTo: SketchLineHelper = {
if (replaceExisting && createCallback && pipe.type !== 'CallExpression') { if (replaceExisting && createCallback && pipe.type !== 'CallExpression') {
const { index: callIndex } = splitPathAtPipeExpression(pathToNode) const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
const { callExp, valueUsedInTransform } = createCallback( const { callExp, valueUsedInTransform } = createCallback([
[ {
{ type: 'arrayItem',
type: 'arrayItem', index: 0,
index: 0, argType: 'xRelative',
argType: 'xRelative', expr: toX,
expr: toX, },
}, {
{ type: 'arrayItem',
type: 'arrayItem', index: 1,
index: 1, argType: 'yAbsolute',
argType: 'yAbsolute', expr: toY,
expr: toY, },
}, ])
],
referencedSegment
)
pipe.body[callIndex] = callExp pipe.body[callIndex] = callExp
return { return {
modifiedAst: _node, modifiedAst: _node,
@ -1154,25 +1146,22 @@ export const angledLine: SketchLineHelper = {
if (replaceExisting && createCallback) { if (replaceExisting && createCallback) {
const { index: callIndex } = splitPathAtPipeExpression(pathToNode) const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
const { callExp, valueUsedInTransform } = createCallback( const { callExp, valueUsedInTransform } = createCallback([
[ {
{ type: 'arrayOrObjItem',
type: 'arrayOrObjItem', index: 0,
index: 0, key: 'angle',
key: 'angle', argType: 'angle',
argType: 'angle', expr: newAngleVal,
expr: newAngleVal, },
}, {
{ type: 'arrayOrObjItem',
type: 'arrayOrObjItem', index: 1,
index: 1, key: 'length',
key: 'length', argType: 'length',
argType: 'length', expr: newLengthVal,
expr: newLengthVal, },
}, ])
],
referencedSegment
)
pipe.body[callIndex] = callExp pipe.body[callIndex] = callExp
return { return {
modifiedAst: _node, modifiedAst: _node,
@ -1471,25 +1460,22 @@ export const angledLineToX: SketchLineHelper = {
const angle = createLiteral(roundOff(getAngle(from, to), 0)) const angle = createLiteral(roundOff(getAngle(from, to), 0))
const xArg = createLiteral(roundOff(to[0], 2)) const xArg = createLiteral(roundOff(to[0], 2))
if (replaceExisting && createCallback) { if (replaceExisting && createCallback) {
const { callExp, valueUsedInTransform } = createCallback( const { callExp, valueUsedInTransform } = createCallback([
[ {
{ type: 'arrayOrObjItem',
type: 'arrayOrObjItem', index: 0,
index: 0, key: 'angle',
key: 'angle', argType: 'angle',
argType: 'angle', expr: angle,
expr: angle, },
}, {
{ type: 'arrayOrObjItem',
type: 'arrayOrObjItem', index: 1,
index: 1, key: 'to',
key: 'to', argType: 'xAbsolute',
argType: 'xAbsolute', expr: xArg,
expr: xArg, },
}, ])
],
referencedSegment
)
const { index: callIndex } = splitPathAtPipeExpression(pathToNode) const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
pipe.body[callIndex] = callExp pipe.body[callIndex] = callExp
return { return {
@ -1575,25 +1561,22 @@ export const angledLineToY: SketchLineHelper = {
const yArg = createLiteral(roundOff(to[1], 2)) const yArg = createLiteral(roundOff(to[1], 2))
if (replaceExisting && createCallback) { if (replaceExisting && createCallback) {
const { callExp, valueUsedInTransform } = createCallback( const { callExp, valueUsedInTransform } = createCallback([
[ {
{ type: 'arrayOrObjItem',
type: 'arrayOrObjItem', index: 0,
index: 0, key: 'angle',
key: 'angle', argType: 'angle',
argType: 'angle', expr: angle,
expr: angle, },
}, {
{ type: 'arrayOrObjItem',
type: 'arrayOrObjItem', index: 1,
index: 1, key: 'to',
key: 'to', argType: 'yAbsolute',
argType: 'yAbsolute', expr: yArg,
expr: yArg, },
}, ])
],
referencedSegment
)
const { index: callIndex } = splitPathAtPipeExpression(pathToNode) const { index: callIndex } = splitPathAtPipeExpression(pathToNode)
pipe.body[callIndex] = callExp pipe.body[callIndex] = callExp
return { return {
@ -2121,7 +2104,7 @@ export function replaceSketchLine({
pathToNode: PathToNode pathToNode: PathToNode
fnName: ToolTip fnName: ToolTip
segmentInput: SegmentInputs segmentInput: SegmentInputs
createCallback: TransformCallback createCallback: (rawArgs: RawArgs) => ReturnType<CreateStdLibSketchCallExpr>
referencedSegment?: Path referencedSegment?: Path
}): }):
| { | {
@ -2151,13 +2134,16 @@ export function replaceSketchLine({
return { modifiedAst, valueUsedInTransform, pathToNode } return { modifiedAst, valueUsedInTransform, pathToNode }
} }
export function addTagForSketchOnFace(a: AddTagInfo, expressionName: string) { export function addTagForSketchOnFace(
tagInfo: AddTagInfo,
expressionName: string
) {
if (expressionName === 'close') { if (expressionName === 'close') {
return addTag(1)(a) return addTag(1)(tagInfo)
} }
if (expressionName in sketchLineHelperMap) { if (expressionName in sketchLineHelperMap) {
const { addTag } = sketchLineHelperMap[expressionName] const { addTag } = sketchLineHelperMap[expressionName]
return addTag(a) return addTag(tagInfo)
} }
return new Error(`"${expressionName}" is not a sketch line helper`) 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 segmentInput: SegmentInputs
referencedSegment?: Path referencedSegment?: Path
replaceExisting?: boolean 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 /// defaults to false, normal behavior is to add a new callExpression to the end of the pipeExpression
spliceBetween?: boolean spliceBetween?: boolean
} }
@ -149,13 +149,13 @@ type RawArg = _VarValue<Literal>
export type InputArgs = Array<InputArg> export type InputArgs = Array<InputArg>
// /** /**
// * The literal equivalent of whatever current expression is * The literal equivalent of whatever current expression is
// * i.e. if the expression is 5 + 6, the literal would be 11 * i.e. if the expression is 5 + 6, the literal would be 11
// * but of course works for expressions like myVar + someFn() etc too * 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 * This is useful in cases where we want to "un-constrain" inputs to segments
// */ */
type RawArgs = Array<RawArg> export type RawArgs = Array<RawArg>
/** /**
* Serves the same role as {@link InputArg} on {@link RawArg} * Serves the same role as {@link InputArg} on {@link RawArg}
@ -174,14 +174,23 @@ export type SimplifiedArgDetails =
index: 0 | 1 index: 0 | 1
} }
export type TransformCallback = ( export type CreateStdLibSketchCallExpr = (args: {
inputs: InputArgs, inputs: InputArgs
referenceSegName: string
tag?: Expr
forceValueUsedInTransform?: Expr
rawArgs: InputArgs
referencedSegment?: Path referencedSegment?: Path
) => { }) => {
callExp: Expr callExp: Expr
valueUsedInTransform?: number valueUsedInTransform?: number
} }
export type TransformInfo = {
tooltip: ToolTip
createNode: CreateStdLibSketchCallExpr
}
export interface ConstrainInfo { export interface ConstrainInfo {
stdLibFnName: ToolTip stdLibFnName: ToolTip
type: type: