Files
modeling-app/src/components/Toolbar/RemoveConstrainingValues.tsx

95 lines
2.5 KiB
TypeScript
Raw Normal View History

import { toolTips } from 'lang/langHelpers'
import { Selection, Selections } from 'lib/selections'
import { PathToNode, Program, Expr } from '../../lang/wasm'
Selections Refactor (#4381) * selection stuff * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * trigger CI * fix bugs * some edge cut stuff * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * trigger CI * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * fix sketch mode issues * fix more tests, selection in sketch related * more test fixing * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger ci * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger ci * more sketch mode selection fixes * fix unit tests * rename function * remove .only * migrate a more selections types * migrate a more selections types * migrate a more selections types * lint * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * fix bad pathToNode issue * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * fix sketch on face * migrate a more selections types * migrate a more selections types * fix code selection of fillets * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * fix bad path to node, looks like a race * migrate a more selections types * migrate a more selections types * fix cmd bar selections * fix cmd bar selections * fix display issues * migrate a more selections types * Revert "migrate a more selections types" This reverts commit 0d0e453bbbb82d10472b6c9e753c53c8b7e3609d. * migrate a more selections types * clean up1 * clean up 2 * fix types after main merge * review tweaks * fix wall selection bug * Update src/lang/std/engineConnection.ts Co-authored-by: Jonathan Tran <jonnytran@gmail.com> * add franks TODO comment * fix type after main merge, plus a touch of clean up --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
2024-11-21 15:04:30 +11:00
import { getNodeFromPath } from '../../lang/queryAst'
import {
PathToNodeMap,
getRemoveConstraintsTransforms,
transformAstSketchLines,
} from '../../lang/std/sketchcombos'
import { TransformInfo } from 'lang/std/stdTypes'
import { kclManager } from 'lib/singletons'
import { err } from 'lib/trap'
Refactor source ranges into a generic node type (#4350) * WIP Signed-off-by: Nick Cameron <nrc@ncameron.org> * Fix formatting * Fix yarn build:wasm * Fix ts_rs bindings * Fix tsc errors * Fix wasm TS types * Add minimal failing test * Rename field to avoid name collisions * Remove node wrapper around NonCodeMeta Trying to fix TS unit test errors deserializing JSON AST in Rust. * Rename Node to BoxNode * Fix lints * Fix lint by boxing literals * Rename UnboxedNode to Node * Look at this (photo)Graph *in the voice of Nickelback* * Update docs * Update snapshots * initial trait Signed-off-by: Jess Frazelle <github@jessfraz.com> * update docs Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * gross hack for TagNode Signed-off-by: Jess Frazelle <github@jessfraz.com> * extend gross hack Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix EnvRef bullshit Signed-off-by: Jess Frazelle <github@jessfraz.com> * Fix to fail parsing when a tag declarator matches a stdlib function name * Fix test errors after merging main * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * Confirm * Change to use simpler map_err * Add comment --------- Signed-off-by: Nick Cameron <nrc@ncameron.org> Signed-off-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: Nick Cameron <nrc@ncameron.org> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jess Frazelle <github@jessfraz.com>
2024-10-30 16:52:17 -04:00
import { Node } from 'wasm-lib/kcl/bindings/Node'
Selections Refactor (#4381) * selection stuff * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * trigger CI * fix bugs * some edge cut stuff * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * trigger CI * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * fix sketch mode issues * fix more tests, selection in sketch related * more test fixing * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger ci * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger ci * more sketch mode selection fixes * fix unit tests * rename function * remove .only * migrate a more selections types * migrate a more selections types * migrate a more selections types * lint * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * fix bad pathToNode issue * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * fix sketch on face * migrate a more selections types * migrate a more selections types * fix code selection of fillets * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * fix bad path to node, looks like a race * migrate a more selections types * migrate a more selections types * fix cmd bar selections * fix cmd bar selections * fix display issues * migrate a more selections types * Revert "migrate a more selections types" This reverts commit 0d0e453bbbb82d10472b6c9e753c53c8b7e3609d. * migrate a more selections types * clean up1 * clean up 2 * fix types after main merge * review tweaks * fix wall selection bug * Update src/lang/std/engineConnection.ts Co-authored-by: Jonathan Tran <jonnytran@gmail.com> * add franks TODO comment * fix type after main merge, plus a touch of clean up --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
2024-11-21 15:04:30 +11:00
import { codeRefFromRange } from 'lang/std/artifactGraph'
export function removeConstrainingValuesInfo({
selectionRanges,
pathToNodes,
}: {
selectionRanges: Selections
pathToNodes?: Array<PathToNode>
}):
| {
transforms: TransformInfo[]
enabled: boolean
updatedSelectionRanges: Selections
}
| Error {
Selections Refactor (#4381) * selection stuff * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * trigger CI * fix bugs * some edge cut stuff * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * trigger CI * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * fix sketch mode issues * fix more tests, selection in sketch related * more test fixing * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger ci * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger ci * more sketch mode selection fixes * fix unit tests * rename function * remove .only * migrate a more selections types * migrate a more selections types * migrate a more selections types * lint * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * fix bad pathToNode issue * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * fix sketch on face * migrate a more selections types * migrate a more selections types * fix code selection of fillets * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * fix bad path to node, looks like a race * migrate a more selections types * migrate a more selections types * fix cmd bar selections * fix cmd bar selections * fix display issues * migrate a more selections types * Revert "migrate a more selections types" This reverts commit 0d0e453bbbb82d10472b6c9e753c53c8b7e3609d. * migrate a more selections types * clean up1 * clean up 2 * fix types after main merge * review tweaks * fix wall selection bug * Update src/lang/std/engineConnection.ts Co-authored-by: Jonathan Tran <jonnytran@gmail.com> * add franks TODO comment * fix type after main merge, plus a touch of clean up --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
2024-11-21 15:04:30 +11:00
const _nodes = selectionRanges.graphSelections.map(({ codeRef }) => {
const tmp = getNodeFromPath<Expr>(kclManager.ast, codeRef.pathToNode)
if (err(tmp)) return tmp
return tmp.node
})
const _err1 = _nodes.find(err)
if (err(_err1)) return _err1
const nodes = _nodes as Expr[]
const updatedSelectionRanges = pathToNodes
? {
otherSelections: [],
Selections Refactor (#4381) * selection stuff * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * trigger CI * fix bugs * some edge cut stuff * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * trigger CI * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * fix sketch mode issues * fix more tests, selection in sketch related * more test fixing * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger ci * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger ci * more sketch mode selection fixes * fix unit tests * rename function * remove .only * migrate a more selections types * migrate a more selections types * migrate a more selections types * lint * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * fix bad pathToNode issue * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * fix sketch on face * migrate a more selections types * migrate a more selections types * fix code selection of fillets * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * migrate a more selections types * fix bad path to node, looks like a race * migrate a more selections types * migrate a more selections types * fix cmd bar selections * fix cmd bar selections * fix display issues * migrate a more selections types * Revert "migrate a more selections types" This reverts commit 0d0e453bbbb82d10472b6c9e753c53c8b7e3609d. * migrate a more selections types * clean up1 * clean up 2 * fix types after main merge * review tweaks * fix wall selection bug * Update src/lang/std/engineConnection.ts Co-authored-by: Jonathan Tran <jonnytran@gmail.com> * add franks TODO comment * fix type after main merge, plus a touch of clean up --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
2024-11-21 15:04:30 +11:00
graphSelections: nodes.map(
(node): Selection => ({
codeRef: codeRefFromRange(
[node.start, node.end, true],
kclManager.ast
),
})
),
}
: selectionRanges
const isAllTooltips = nodes.every(
(node) =>
node?.type === 'CallExpression' &&
toolTips.includes(node.callee.name as any)
)
const transforms = getRemoveConstraintsTransforms(
updatedSelectionRanges,
kclManager.ast,
'removeConstrainingValues'
)
if (err(transforms)) return transforms
const enabled = isAllTooltips && transforms.every(Boolean)
return { enabled, transforms, updatedSelectionRanges }
}
export function applyRemoveConstrainingValues({
selectionRanges,
pathToNodes,
}: {
selectionRanges: Selections
pathToNodes?: Array<PathToNode>
}):
| {
Refactor source ranges into a generic node type (#4350) * WIP Signed-off-by: Nick Cameron <nrc@ncameron.org> * Fix formatting * Fix yarn build:wasm * Fix ts_rs bindings * Fix tsc errors * Fix wasm TS types * Add minimal failing test * Rename field to avoid name collisions * Remove node wrapper around NonCodeMeta Trying to fix TS unit test errors deserializing JSON AST in Rust. * Rename Node to BoxNode * Fix lints * Fix lint by boxing literals * Rename UnboxedNode to Node * Look at this (photo)Graph *in the voice of Nickelback* * Update docs * Update snapshots * initial trait Signed-off-by: Jess Frazelle <github@jessfraz.com> * update docs Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * gross hack for TagNode Signed-off-by: Jess Frazelle <github@jessfraz.com> * extend gross hack Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix EnvRef bullshit Signed-off-by: Jess Frazelle <github@jessfraz.com> * Fix to fail parsing when a tag declarator matches a stdlib function name * Fix test errors after merging main * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * Confirm * Change to use simpler map_err * Add comment --------- Signed-off-by: Nick Cameron <nrc@ncameron.org> Signed-off-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: Nick Cameron <nrc@ncameron.org> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jess Frazelle <github@jessfraz.com>
2024-10-30 16:52:17 -04:00
modifiedAst: Node<Program>
pathToNodeMap: PathToNodeMap
}
| Error {
const constraint = removeConstrainingValuesInfo({
selectionRanges,
pathToNodes,
})
if (err(constraint)) return constraint
const { transforms, updatedSelectionRanges } = constraint
return transformAstSketchLines({
ast: kclManager.ast,
selectionRanges: updatedSelectionRanges,
transformInfos: transforms,
programMemory: kclManager.programMemory,
referenceSegName: '',
})
}