Skip to content

Commit

Permalink
Add edit flow for sketch-on-offset-plane
Browse files Browse the repository at this point in the history
Leveraging the new data that was introduced by
#5489
  • Loading branch information
franknoirot committed Feb 25, 2025
1 parent ee06f3e commit a375279
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/components/ModelingMachineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,13 @@ export const ModelingMachineProvider = ({
if (event.data?.forceNewSketch) return false
if (artifactIsPlaneWithPaths(selectionRanges)) {
return true
} else if (selectionRanges.graphSelections[0]?.artifact) {
// See if the selection is "close enough" to be coerced to the plane later
const maybePlane = getPlaneFromArtifact(
selectionRanges.graphSelections[0].artifact,
engineCommandManager.artifactGraph
)
return !err(maybePlane)
}
if (
isCursorInFunctionDefinition(
Expand Down
2 changes: 1 addition & 1 deletion src/lang/queryAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
import { err, Reason } from 'lib/trap'
import { Node } from 'wasm-lib/kcl/bindings/Node'
import { findKwArg } from './util'
import { codeRefFromRange } from './std/artifactGraph'
import { codeRefFromRange, getPlaneFromArtifact } from './std/artifactGraph'
import { FunctionExpression } from 'wasm-lib/kcl/bindings/FunctionExpression'
import { ImportStatement } from 'wasm-lib/kcl/bindings/ImportStatement'
import { KclSettingsAnnotation } from 'lib/settings/settingsTypes'
Expand Down
32 changes: 31 additions & 1 deletion src/lang/std/artifactGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import {
import { Models } from '@kittycad/lib'
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
import { err } from 'lib/trap'
import { Cap, Plane, Wall } from 'wasm-lib/kcl/bindings/Artifact'
import {
Cap,
Plane,
StartSketchOnFace,
StartSketchOnPlane,
Wall,
} from 'wasm-lib/kcl/bindings/Artifact'
import { CapSubType } from 'wasm-lib/kcl/bindings/Artifact'

export type { Artifact, ArtifactId, SegmentArtifact } from 'lang/wasm'
Expand Down Expand Up @@ -568,6 +574,26 @@ function getPlaneFromSweepEdge(edge: SweepEdge, graph: ArtifactGraph) {
if (err(path)) return path
return getPlaneFromPath(path, graph)
}
function getPlaneFromStartSketchOnFace(
sketch: StartSketchOnFace,
graph: ArtifactGraph
) {
const plane = getArtifactOfTypes(
{ key: sketch.faceId, types: ['plane'] },
graph
)
return plane
}
function getPlaneFromStartSketchOnPlane(
sketch: StartSketchOnPlane,
graph: ArtifactGraph
) {
const plane = getArtifactOfTypes(
{ key: sketch.planeId, types: ['plane'] },
graph
)
return plane
}

export function getPlaneFromArtifact(
artifact: Artifact | undefined,
Expand All @@ -589,6 +615,10 @@ export function getPlaneFromArtifact(
if (artifact.type === 'wall') return getPlaneFromWall(artifact, graph)
if (artifact.type === 'sweepEdge')
return getPlaneFromSweepEdge(artifact, graph)
if (artifact.type === 'startSketchOnFace')
return getPlaneFromStartSketchOnFace(artifact, graph)
if (artifact.type === 'startSketchOnPlane')
return getPlaneFromStartSketchOnPlane(artifact, graph)
return new Error(`Artifact type ${artifact.type} does not have a plane`)
}

Expand Down

0 comments on commit a375279

Please sign in to comment.