fix circ dep
This commit is contained in:
@ -1,12 +1,8 @@
|
||||
import {
|
||||
BoxGeometry,
|
||||
Color,
|
||||
DoubleSide,
|
||||
Group,
|
||||
Intersection,
|
||||
Line,
|
||||
LineDashedMaterial,
|
||||
BufferGeometry,
|
||||
Mesh,
|
||||
MeshBasicMaterial,
|
||||
Object3D,
|
||||
@ -17,7 +13,6 @@ import {
|
||||
Points,
|
||||
Quaternion,
|
||||
Scene,
|
||||
SphereGeometry,
|
||||
Vector2,
|
||||
Vector3,
|
||||
} from 'three'
|
||||
@ -70,7 +65,6 @@ import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
|
||||
import { executeAst, ToolTip } from 'lang/langHelpers'
|
||||
import {
|
||||
createProfileStartHandle,
|
||||
createCircleGeometry,
|
||||
SegmentUtils,
|
||||
segmentUtils,
|
||||
} from './segments'
|
||||
@ -121,8 +115,6 @@ import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer'
|
||||
import { Point3d } from 'wasm-lib/kcl/bindings/Point3d'
|
||||
import { SegmentInputs } from 'lang/std/stdTypes'
|
||||
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 toast from 'react-hot-toast'
|
||||
import { getArtifactFromRange, codeRefFromRange } from 'lang/std/artifactGraph'
|
||||
|
@ -54,13 +54,11 @@ import {
|
||||
import { getTangentPointFromPreviousArc } from 'lib/utils2d'
|
||||
import {
|
||||
ARROWHEAD,
|
||||
CIRCLE_3_POINT_DRAFT_CIRCLE,
|
||||
DRAFT_POINT,
|
||||
SceneInfra,
|
||||
SEGMENT_LENGTH_LABEL,
|
||||
SEGMENT_LENGTH_LABEL_OFFSET_PX,
|
||||
SEGMENT_LENGTH_LABEL_TEXT,
|
||||
SKETCH_LAYER,
|
||||
} from './sceneInfra'
|
||||
import { Themes, getThemeColorForThreeJs } from 'lib/theme'
|
||||
import { normaliseAngle, roundOff } from 'lib/utils'
|
||||
@ -71,7 +69,7 @@ import {
|
||||
} from 'machines/modelingMachine'
|
||||
import { SegmentInputs } from 'lang/std/stdTypes'
|
||||
import { err } from 'lib/trap'
|
||||
import { editorManager, sceneInfra } from 'lib/singletons'
|
||||
import { sceneInfra } from 'lib/singletons'
|
||||
import { Selections } from 'lib/selections'
|
||||
import { calculate_circle_from_3_points } from 'wasm-lib/pkg/wasm_lib'
|
||||
import { commandBarActor } from 'machines/commandBarMachine'
|
||||
|
@ -69,7 +69,6 @@ import {
|
||||
startSketchOnDefault,
|
||||
} from 'lang/modifyAst'
|
||||
import {
|
||||
CodeRef,
|
||||
PathToNode,
|
||||
Program,
|
||||
VariableDeclaration,
|
||||
@ -84,7 +83,6 @@ import {
|
||||
isCursorInFunctionDefinition,
|
||||
traverse,
|
||||
} from 'lang/queryAst'
|
||||
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
|
||||
import { exportFromEngine } from 'lib/exportFromEngine'
|
||||
import { Models } from '@kittycad/lib/dist/types/src'
|
||||
import toast from 'react-hot-toast'
|
||||
@ -747,6 +745,8 @@ export const ModelingMachineProvider = ({
|
||||
const sketchPaths = getPathsFromArtifact({
|
||||
artifact: selectionRanges.graphSelections[0].artifact,
|
||||
sketchPathToNode: sketchPathToNode || [],
|
||||
artifactGraph: engineCommandManager.artifactGraph,
|
||||
ast: kclManager.ast,
|
||||
})
|
||||
if (err(sketchPaths)) return Promise.reject(sketchPaths)
|
||||
let codeRef =
|
||||
|
@ -3,7 +3,6 @@ import {
|
||||
recast,
|
||||
initPromise,
|
||||
Identifier,
|
||||
SourceRange,
|
||||
topLevelRange,
|
||||
LiteralValue,
|
||||
Literal,
|
||||
|
@ -24,6 +24,7 @@ import {
|
||||
isPathToNodeNumber,
|
||||
parse,
|
||||
formatNumber,
|
||||
ArtifactGraph,
|
||||
} from './wasm'
|
||||
import {
|
||||
isNodeSafeToReplacePath,
|
||||
@ -63,6 +64,8 @@ import { Artifact, getPathsFromArtifact } from './std/artifactGraph'
|
||||
import { BodyItem } from 'wasm-lib/kcl/bindings/BodyItem'
|
||||
import { findKwArg } from './util'
|
||||
import { deleteEdgeTreatment } from './modifyAst/addEdgeTreatment'
|
||||
import { kclManager } from 'lib/singletons'
|
||||
import React from 'react'
|
||||
|
||||
export function startSketchOnDefault(
|
||||
node: Node<Program>,
|
||||
@ -321,12 +324,14 @@ export function extrudeSketch({
|
||||
distance = createLiteral(4),
|
||||
extrudeName,
|
||||
artifact,
|
||||
artifactGraph,
|
||||
}: {
|
||||
node: Node<Program>
|
||||
pathToNode: PathToNode
|
||||
shouldPipe?: boolean
|
||||
distance: Expr
|
||||
extrudeName?: string
|
||||
artifactGraph: ArtifactGraph
|
||||
artifact?: Artifact
|
||||
}):
|
||||
| {
|
||||
@ -338,6 +343,8 @@ export function extrudeSketch({
|
||||
const orderedSketchNodePaths = getPathsFromArtifact({
|
||||
artifact: artifact,
|
||||
sketchPathToNode: pathToNode,
|
||||
artifactGraph,
|
||||
ast: node,
|
||||
})
|
||||
if (err(orderedSketchNodePaths)) return orderedSketchNodePaths
|
||||
const _node = structuredClone(node)
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
CallExpression,
|
||||
VariableDeclarator,
|
||||
CallExpressionKw,
|
||||
ArtifactGraph,
|
||||
} from 'lang/wasm'
|
||||
import { Selections } from 'lib/selections'
|
||||
import { Node } from 'wasm-lib/kcl/bindings/Node'
|
||||
@ -25,6 +26,8 @@ import {
|
||||
getEdgeTagCall,
|
||||
} from 'lang/modifyAst/addEdgeTreatment'
|
||||
import { Artifact, getPathsFromArtifact } from 'lang/std/artifactGraph'
|
||||
import { kclManager } from 'lib/singletons'
|
||||
|
||||
export function revolveSketch(
|
||||
ast: Node<Program>,
|
||||
pathToSketchNode: PathToNode,
|
||||
@ -32,6 +35,7 @@ export function revolveSketch(
|
||||
axisOrEdge: string,
|
||||
axis: string,
|
||||
edge: Selections,
|
||||
artifactGraph: ArtifactGraph,
|
||||
artifact?: Artifact
|
||||
):
|
||||
| {
|
||||
@ -43,6 +47,8 @@ export function revolveSketch(
|
||||
const orderedSketchNodePaths = getPathsFromArtifact({
|
||||
artifact: artifact,
|
||||
sketchPathToNode: pathToSketchNode,
|
||||
artifactGraph,
|
||||
ast: kclManager.ast,
|
||||
})
|
||||
if (err(orderedSketchNodePaths)) return orderedSketchNodePaths
|
||||
const clonedAst = structuredClone(ast)
|
||||
|
@ -19,7 +19,6 @@ import {
|
||||
import { Models } from '@kittycad/lib'
|
||||
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
|
||||
import { err } from 'lib/trap'
|
||||
import { engineCommandManager, kclManager } from 'lib/singletons'
|
||||
|
||||
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`)
|
||||
}
|
||||
|
||||
const isExprSafe = (index: number): boolean => {
|
||||
const expr = kclManager.ast.body?.[index]
|
||||
const isExprSafe = (index: number, ast: Program): boolean => {
|
||||
const expr = ast.body?.[index]
|
||||
if (!expr) {
|
||||
return false
|
||||
}
|
||||
@ -525,7 +524,8 @@ const isExprSafe = (index: number): boolean => {
|
||||
|
||||
const onlyConsecutivePaths = (
|
||||
orderedNodePaths: PathToNode[],
|
||||
originalPath: PathToNode
|
||||
originalPath: PathToNode,
|
||||
ast: Program
|
||||
): PathToNode[] => {
|
||||
const originalIndex = Number(
|
||||
orderedNodePaths.find(
|
||||
@ -547,58 +547,63 @@ const onlyConsecutivePaths = (
|
||||
for (let i = originalIndex; i <= maxIndex; i++) {
|
||||
if (pathIndexMap[i]) {
|
||||
safePaths.push(pathIndexMap[i])
|
||||
} else if (!isExprSafe(i)) {
|
||||
} else if (!isExprSafe(i, ast)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
for (let i = originalIndex - 1; i >= minIndex; i--) {
|
||||
if (pathIndexMap[i]) {
|
||||
safePaths.unshift(pathIndexMap[i])
|
||||
} else if (!isExprSafe(i)) {
|
||||
} else if (!isExprSafe(i, ast)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return safePaths
|
||||
}
|
||||
|
||||
export function getPathsFromPlaneArtifact(planeArtifact: PlaneArtifact) {
|
||||
export function getPathsFromPlaneArtifact(
|
||||
planeArtifact: PlaneArtifact,
|
||||
artifactGraph: ArtifactGraph,
|
||||
ast: Program
|
||||
): PathToNode[] {
|
||||
const nodePaths: PathToNode[] = []
|
||||
for (const pathId of planeArtifact.pathIds) {
|
||||
const path = engineCommandManager.artifactGraph.get(pathId)
|
||||
const path = artifactGraph.get(pathId)
|
||||
if (!path) continue
|
||||
if ('codeRef' in path && path.codeRef) {
|
||||
// TODO should figure out why upstream the path is bad
|
||||
const isNodePathBad = path.codeRef.pathToNode.length < 2
|
||||
nodePaths.push(
|
||||
isNodePathBad
|
||||
? getNodePathFromSourceRange(kclManager.ast, path.codeRef.range)
|
||||
? getNodePathFromSourceRange(ast, path.codeRef.range)
|
||||
: path.codeRef.pathToNode
|
||||
)
|
||||
}
|
||||
}
|
||||
return onlyConsecutivePaths(nodePaths, nodePaths[0])
|
||||
return onlyConsecutivePaths(nodePaths, nodePaths[0], ast)
|
||||
}
|
||||
|
||||
export function getPathsFromArtifact({
|
||||
sketchPathToNode,
|
||||
artifact,
|
||||
artifactGraph,
|
||||
ast,
|
||||
}: {
|
||||
sketchPathToNode: PathToNode
|
||||
artifact?: Artifact
|
||||
artifactGraph: ArtifactGraph
|
||||
ast: Program
|
||||
}): PathToNode[] | Error {
|
||||
const plane = getPlaneFromArtifact(
|
||||
artifact,
|
||||
engineCommandManager.artifactGraph
|
||||
)
|
||||
const plane = getPlaneFromArtifact(artifact, artifactGraph)
|
||||
if (err(plane)) return plane
|
||||
const paths = getArtifactsOfTypes(
|
||||
{ keys: plane.pathIds, types: ['path'] },
|
||||
engineCommandManager.artifactGraph
|
||||
artifactGraph
|
||||
)
|
||||
let nodePaths = [...paths.values()]
|
||||
.map((path) => path.codeRef.pathToNode)
|
||||
.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 {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { CustomIconName } from 'components/CustomIcon'
|
||||
import { DEV } from 'env'
|
||||
import { commandBarActor, commandBarMachine } from 'machines/commandBarMachine'
|
||||
import { commandBarActor } from 'machines/commandBarMachine'
|
||||
import {
|
||||
isEditingExistingSketch,
|
||||
modelingMachine,
|
||||
|
@ -702,6 +702,7 @@ export const modelingMachine = setup({
|
||||
axisOrEdge,
|
||||
axis,
|
||||
edge,
|
||||
engineCommandManager.artifactGraph,
|
||||
selection.graphSelections[0]?.artifact
|
||||
)
|
||||
if (trap(revolveSketchRes)) return
|
||||
@ -1063,7 +1064,11 @@ export const modelingMachine = setup({
|
||||
JSON.stringify(sketchDetails.planeNodePath)
|
||||
)
|
||||
if (planeArtifact?.type !== 'plane') return {}
|
||||
const newPaths = getPathsFromPlaneArtifact(planeArtifact)
|
||||
const newPaths = getPathsFromPlaneArtifact(
|
||||
planeArtifact,
|
||||
engineCommandManager.artifactGraph,
|
||||
kclManager.ast
|
||||
)
|
||||
return {
|
||||
sketchDetails: {
|
||||
...sketchDetails,
|
||||
@ -1635,6 +1640,7 @@ export const modelingMachine = setup({
|
||||
node: ast,
|
||||
pathToNode,
|
||||
artifact: selection.graphSelections[0].artifact,
|
||||
artifactGraph: engineCommandManager.artifactGraph,
|
||||
distance:
|
||||
'variableName' in distance
|
||||
? distance.variableIdentifierAst
|
||||
|
Reference in New Issue
Block a user