fix circ dep

This commit is contained in:
Kurt Hutten Irev-Dev
2025-02-07 12:59:19 +11:00
parent a7f4b0f037
commit 319029235c
9 changed files with 45 additions and 32 deletions

View File

@ -1,12 +1,8 @@
import { import {
BoxGeometry, BoxGeometry,
Color,
DoubleSide, DoubleSide,
Group, Group,
Intersection, Intersection,
Line,
LineDashedMaterial,
BufferGeometry,
Mesh, Mesh,
MeshBasicMaterial, MeshBasicMaterial,
Object3D, Object3D,
@ -17,7 +13,6 @@ import {
Points, Points,
Quaternion, Quaternion,
Scene, Scene,
SphereGeometry,
Vector2, Vector2,
Vector3, Vector3,
} from 'three' } from 'three'
@ -70,7 +65,6 @@ import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
import { executeAst, ToolTip } from 'lang/langHelpers' import { executeAst, ToolTip } from 'lang/langHelpers'
import { import {
createProfileStartHandle, createProfileStartHandle,
createCircleGeometry,
SegmentUtils, SegmentUtils,
segmentUtils, segmentUtils,
} from './segments' } from './segments'
@ -121,8 +115,6 @@ import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer'
import { Point3d } from 'wasm-lib/kcl/bindings/Point3d' import { Point3d } from 'wasm-lib/kcl/bindings/Point3d'
import { SegmentInputs } from 'lang/std/stdTypes' import { SegmentInputs } from 'lang/std/stdTypes'
import { Node } from 'wasm-lib/kcl/bindings/Node' import { Node } from 'wasm-lib/kcl/bindings/Node'
import { LabeledArg } from 'wasm-lib/kcl/bindings/LabeledArg'
import { Literal } from 'wasm-lib/kcl/bindings/Literal'
import { radToDeg } from 'three/src/math/MathUtils' import { radToDeg } from 'three/src/math/MathUtils'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import { getArtifactFromRange, codeRefFromRange } from 'lang/std/artifactGraph' import { getArtifactFromRange, codeRefFromRange } from 'lang/std/artifactGraph'

View File

@ -54,13 +54,11 @@ import {
import { getTangentPointFromPreviousArc } from 'lib/utils2d' import { getTangentPointFromPreviousArc } from 'lib/utils2d'
import { import {
ARROWHEAD, ARROWHEAD,
CIRCLE_3_POINT_DRAFT_CIRCLE,
DRAFT_POINT, DRAFT_POINT,
SceneInfra, SceneInfra,
SEGMENT_LENGTH_LABEL, SEGMENT_LENGTH_LABEL,
SEGMENT_LENGTH_LABEL_OFFSET_PX, SEGMENT_LENGTH_LABEL_OFFSET_PX,
SEGMENT_LENGTH_LABEL_TEXT, SEGMENT_LENGTH_LABEL_TEXT,
SKETCH_LAYER,
} from './sceneInfra' } from './sceneInfra'
import { Themes, getThemeColorForThreeJs } from 'lib/theme' import { Themes, getThemeColorForThreeJs } from 'lib/theme'
import { normaliseAngle, roundOff } from 'lib/utils' import { normaliseAngle, roundOff } from 'lib/utils'
@ -71,7 +69,7 @@ import {
} from 'machines/modelingMachine' } from 'machines/modelingMachine'
import { SegmentInputs } from 'lang/std/stdTypes' import { SegmentInputs } from 'lang/std/stdTypes'
import { err } from 'lib/trap' import { err } from 'lib/trap'
import { editorManager, sceneInfra } from 'lib/singletons' import { sceneInfra } from 'lib/singletons'
import { Selections } from 'lib/selections' import { Selections } from 'lib/selections'
import { calculate_circle_from_3_points } from 'wasm-lib/pkg/wasm_lib' import { calculate_circle_from_3_points } from 'wasm-lib/pkg/wasm_lib'
import { commandBarActor } from 'machines/commandBarMachine' import { commandBarActor } from 'machines/commandBarMachine'

View File

@ -69,7 +69,6 @@ import {
startSketchOnDefault, startSketchOnDefault,
} from 'lang/modifyAst' } from 'lang/modifyAst'
import { import {
CodeRef,
PathToNode, PathToNode,
Program, Program,
VariableDeclaration, VariableDeclaration,
@ -84,7 +83,6 @@ import {
isCursorInFunctionDefinition, isCursorInFunctionDefinition,
traverse, traverse,
} from 'lang/queryAst' } from 'lang/queryAst'
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
import { exportFromEngine } from 'lib/exportFromEngine' import { exportFromEngine } from 'lib/exportFromEngine'
import { Models } from '@kittycad/lib/dist/types/src' import { Models } from '@kittycad/lib/dist/types/src'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
@ -747,6 +745,8 @@ export const ModelingMachineProvider = ({
const sketchPaths = getPathsFromArtifact({ const sketchPaths = getPathsFromArtifact({
artifact: selectionRanges.graphSelections[0].artifact, artifact: selectionRanges.graphSelections[0].artifact,
sketchPathToNode: sketchPathToNode || [], sketchPathToNode: sketchPathToNode || [],
artifactGraph: engineCommandManager.artifactGraph,
ast: kclManager.ast,
}) })
if (err(sketchPaths)) return Promise.reject(sketchPaths) if (err(sketchPaths)) return Promise.reject(sketchPaths)
let codeRef = let codeRef =

View File

@ -3,7 +3,6 @@ import {
recast, recast,
initPromise, initPromise,
Identifier, Identifier,
SourceRange,
topLevelRange, topLevelRange,
LiteralValue, LiteralValue,
Literal, Literal,

View File

@ -24,6 +24,7 @@ import {
isPathToNodeNumber, isPathToNodeNumber,
parse, parse,
formatNumber, formatNumber,
ArtifactGraph,
} from './wasm' } from './wasm'
import { import {
isNodeSafeToReplacePath, isNodeSafeToReplacePath,
@ -63,6 +64,8 @@ import { Artifact, getPathsFromArtifact } from './std/artifactGraph'
import { BodyItem } from 'wasm-lib/kcl/bindings/BodyItem' import { BodyItem } from 'wasm-lib/kcl/bindings/BodyItem'
import { findKwArg } from './util' import { findKwArg } from './util'
import { deleteEdgeTreatment } from './modifyAst/addEdgeTreatment' import { deleteEdgeTreatment } from './modifyAst/addEdgeTreatment'
import { kclManager } from 'lib/singletons'
import React from 'react'
export function startSketchOnDefault( export function startSketchOnDefault(
node: Node<Program>, node: Node<Program>,
@ -321,12 +324,14 @@ export function extrudeSketch({
distance = createLiteral(4), distance = createLiteral(4),
extrudeName, extrudeName,
artifact, artifact,
artifactGraph,
}: { }: {
node: Node<Program> node: Node<Program>
pathToNode: PathToNode pathToNode: PathToNode
shouldPipe?: boolean shouldPipe?: boolean
distance: Expr distance: Expr
extrudeName?: string extrudeName?: string
artifactGraph: ArtifactGraph
artifact?: Artifact artifact?: Artifact
}): }):
| { | {
@ -338,6 +343,8 @@ export function extrudeSketch({
const orderedSketchNodePaths = getPathsFromArtifact({ const orderedSketchNodePaths = getPathsFromArtifact({
artifact: artifact, artifact: artifact,
sketchPathToNode: pathToNode, sketchPathToNode: pathToNode,
artifactGraph,
ast: node,
}) })
if (err(orderedSketchNodePaths)) return orderedSketchNodePaths if (err(orderedSketchNodePaths)) return orderedSketchNodePaths
const _node = structuredClone(node) const _node = structuredClone(node)

View File

@ -7,6 +7,7 @@ import {
CallExpression, CallExpression,
VariableDeclarator, VariableDeclarator,
CallExpressionKw, CallExpressionKw,
ArtifactGraph,
} from 'lang/wasm' } from 'lang/wasm'
import { Selections } from 'lib/selections' import { Selections } from 'lib/selections'
import { Node } from 'wasm-lib/kcl/bindings/Node' import { Node } from 'wasm-lib/kcl/bindings/Node'
@ -25,6 +26,8 @@ import {
getEdgeTagCall, getEdgeTagCall,
} from 'lang/modifyAst/addEdgeTreatment' } from 'lang/modifyAst/addEdgeTreatment'
import { Artifact, getPathsFromArtifact } from 'lang/std/artifactGraph' import { Artifact, getPathsFromArtifact } from 'lang/std/artifactGraph'
import { kclManager } from 'lib/singletons'
export function revolveSketch( export function revolveSketch(
ast: Node<Program>, ast: Node<Program>,
pathToSketchNode: PathToNode, pathToSketchNode: PathToNode,
@ -32,6 +35,7 @@ export function revolveSketch(
axisOrEdge: string, axisOrEdge: string,
axis: string, axis: string,
edge: Selections, edge: Selections,
artifactGraph: ArtifactGraph,
artifact?: Artifact artifact?: Artifact
): ):
| { | {
@ -43,6 +47,8 @@ export function revolveSketch(
const orderedSketchNodePaths = getPathsFromArtifact({ const orderedSketchNodePaths = getPathsFromArtifact({
artifact: artifact, artifact: artifact,
sketchPathToNode: pathToSketchNode, sketchPathToNode: pathToSketchNode,
artifactGraph,
ast: kclManager.ast,
}) })
if (err(orderedSketchNodePaths)) return orderedSketchNodePaths if (err(orderedSketchNodePaths)) return orderedSketchNodePaths
const clonedAst = structuredClone(ast) const clonedAst = structuredClone(ast)

View File

@ -19,7 +19,6 @@ import {
import { Models } from '@kittycad/lib' import { Models } from '@kittycad/lib'
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
import { err } from 'lib/trap' import { err } from 'lib/trap'
import { engineCommandManager, kclManager } from 'lib/singletons'
export type { Artifact, ArtifactId, SegmentArtifact } from 'lang/wasm' export type { Artifact, ArtifactId, SegmentArtifact } from 'lang/wasm'
@ -499,8 +498,8 @@ export function getPlaneFromArtifact(
return new Error(`Artifact type ${artifact.type} does not have a plane`) return new Error(`Artifact type ${artifact.type} does not have a plane`)
} }
const isExprSafe = (index: number): boolean => { const isExprSafe = (index: number, ast: Program): boolean => {
const expr = kclManager.ast.body?.[index] const expr = ast.body?.[index]
if (!expr) { if (!expr) {
return false return false
} }
@ -525,7 +524,8 @@ const isExprSafe = (index: number): boolean => {
const onlyConsecutivePaths = ( const onlyConsecutivePaths = (
orderedNodePaths: PathToNode[], orderedNodePaths: PathToNode[],
originalPath: PathToNode originalPath: PathToNode,
ast: Program
): PathToNode[] => { ): PathToNode[] => {
const originalIndex = Number( const originalIndex = Number(
orderedNodePaths.find( orderedNodePaths.find(
@ -547,58 +547,63 @@ const onlyConsecutivePaths = (
for (let i = originalIndex; i <= maxIndex; i++) { for (let i = originalIndex; i <= maxIndex; i++) {
if (pathIndexMap[i]) { if (pathIndexMap[i]) {
safePaths.push(pathIndexMap[i]) safePaths.push(pathIndexMap[i])
} else if (!isExprSafe(i)) { } else if (!isExprSafe(i, ast)) {
break break
} }
} }
for (let i = originalIndex - 1; i >= minIndex; i--) { for (let i = originalIndex - 1; i >= minIndex; i--) {
if (pathIndexMap[i]) { if (pathIndexMap[i]) {
safePaths.unshift(pathIndexMap[i]) safePaths.unshift(pathIndexMap[i])
} else if (!isExprSafe(i)) { } else if (!isExprSafe(i, ast)) {
break break
} }
} }
return safePaths return safePaths
} }
export function getPathsFromPlaneArtifact(planeArtifact: PlaneArtifact) { export function getPathsFromPlaneArtifact(
planeArtifact: PlaneArtifact,
artifactGraph: ArtifactGraph,
ast: Program
): PathToNode[] {
const nodePaths: PathToNode[] = [] const nodePaths: PathToNode[] = []
for (const pathId of planeArtifact.pathIds) { for (const pathId of planeArtifact.pathIds) {
const path = engineCommandManager.artifactGraph.get(pathId) const path = artifactGraph.get(pathId)
if (!path) continue if (!path) continue
if ('codeRef' in path && path.codeRef) { if ('codeRef' in path && path.codeRef) {
// TODO should figure out why upstream the path is bad // TODO should figure out why upstream the path is bad
const isNodePathBad = path.codeRef.pathToNode.length < 2 const isNodePathBad = path.codeRef.pathToNode.length < 2
nodePaths.push( nodePaths.push(
isNodePathBad isNodePathBad
? getNodePathFromSourceRange(kclManager.ast, path.codeRef.range) ? getNodePathFromSourceRange(ast, path.codeRef.range)
: path.codeRef.pathToNode : path.codeRef.pathToNode
) )
} }
} }
return onlyConsecutivePaths(nodePaths, nodePaths[0]) return onlyConsecutivePaths(nodePaths, nodePaths[0], ast)
} }
export function getPathsFromArtifact({ export function getPathsFromArtifact({
sketchPathToNode, sketchPathToNode,
artifact, artifact,
artifactGraph,
ast,
}: { }: {
sketchPathToNode: PathToNode sketchPathToNode: PathToNode
artifact?: Artifact artifact?: Artifact
artifactGraph: ArtifactGraph
ast: Program
}): PathToNode[] | Error { }): PathToNode[] | Error {
const plane = getPlaneFromArtifact( const plane = getPlaneFromArtifact(artifact, artifactGraph)
artifact,
engineCommandManager.artifactGraph
)
if (err(plane)) return plane if (err(plane)) return plane
const paths = getArtifactsOfTypes( const paths = getArtifactsOfTypes(
{ keys: plane.pathIds, types: ['path'] }, { keys: plane.pathIds, types: ['path'] },
engineCommandManager.artifactGraph artifactGraph
) )
let nodePaths = [...paths.values()] let nodePaths = [...paths.values()]
.map((path) => path.codeRef.pathToNode) .map((path) => path.codeRef.pathToNode)
.sort((a, b) => Number(a[1][0]) - Number(b[1][0])) .sort((a, b) => Number(a[1][0]) - Number(b[1][0]))
return onlyConsecutivePaths(nodePaths, sketchPathToNode) return onlyConsecutivePaths(nodePaths, sketchPathToNode, ast)
} }
function isNodeSafe(node: Expr): boolean { function isNodeSafe(node: Expr): boolean {

View File

@ -1,6 +1,6 @@
import { CustomIconName } from 'components/CustomIcon' import { CustomIconName } from 'components/CustomIcon'
import { DEV } from 'env' import { DEV } from 'env'
import { commandBarActor, commandBarMachine } from 'machines/commandBarMachine' import { commandBarActor } from 'machines/commandBarMachine'
import { import {
isEditingExistingSketch, isEditingExistingSketch,
modelingMachine, modelingMachine,

View File

@ -702,6 +702,7 @@ export const modelingMachine = setup({
axisOrEdge, axisOrEdge,
axis, axis,
edge, edge,
engineCommandManager.artifactGraph,
selection.graphSelections[0]?.artifact selection.graphSelections[0]?.artifact
) )
if (trap(revolveSketchRes)) return if (trap(revolveSketchRes)) return
@ -1063,7 +1064,11 @@ export const modelingMachine = setup({
JSON.stringify(sketchDetails.planeNodePath) JSON.stringify(sketchDetails.planeNodePath)
) )
if (planeArtifact?.type !== 'plane') return {} if (planeArtifact?.type !== 'plane') return {}
const newPaths = getPathsFromPlaneArtifact(planeArtifact) const newPaths = getPathsFromPlaneArtifact(
planeArtifact,
engineCommandManager.artifactGraph,
kclManager.ast
)
return { return {
sketchDetails: { sketchDetails: {
...sketchDetails, ...sketchDetails,
@ -1635,6 +1640,7 @@ export const modelingMachine = setup({
node: ast, node: ast,
pathToNode, pathToNode,
artifact: selection.graphSelections[0].artifact, artifact: selection.graphSelections[0].artifact,
artifactGraph: engineCommandManager.artifactGraph,
distance: distance:
'variableName' in distance 'variableName' in distance
? distance.variableIdentifierAst ? distance.variableIdentifierAst