Skip to content

Fix sketch-on-face sketches to be in the artifact graph #5489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
2aef99f
Add code ref to sketch-on-face artifacts
jtran Feb 19, 2025
cd69099
Fix to add execution artifacts to the artifact graph
jtran Feb 25, 2025
1d627a4
Update output after including exec artifacts
jtran Feb 25, 2025
ee06f3e
A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubunt…
github-actions[bot] Feb 25, 2025
dd7565e
Merge branch 'main' into jtran/plane-code-ref
jtran Feb 25, 2025
358e252
Merge branch 'main' into jtran/plane-code-ref
jtran Feb 26, 2025
40d8d83
A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubunt…
github-actions[bot] Feb 26, 2025
d0641c7
A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubunt…
github-actions[bot] Feb 26, 2025
8eddda8
A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubunt…
github-actions[bot] Feb 26, 2025
69462dc
A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubunt…
github-actions[bot] Feb 26, 2025
3b58f68
A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubunt…
github-actions[bot] Feb 26, 2025
3c618af
A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubunt…
github-actions[bot] Feb 26, 2025
a3ef8f1
A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubunt…
github-actions[bot] Feb 26, 2025
c8d03fe
A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubunt…
github-actions[bot] Feb 26, 2025
ef2dd92
A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubunt…
github-actions[bot] Feb 26, 2025
3f9edf8
Merge branch 'main' into jtran/plane-code-ref
jtran Feb 28, 2025
26ee86f
Unlock edit for sketches on offset planes (#5497)
franknoirot Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions e2e/playwright/feature-tree-pane.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ test.describe('Feature Tree pane', () => {
await toolbar.exitSketchBtn.click()
})

await test.step('On an offset plane should *not* work', async () => {
await test.step('On an offset plane should work', async () => {
// Tooltip is getting in the way of clicking, so I'm first closing the pane
await toolbar.closeFeatureTreePane()
await (await toolbar.getFeatureTreeOperation('Sketch', 2)).dblclick()
Expand All @@ -212,13 +212,7 @@ test.describe('Feature Tree pane', () => {
})
await expect(
toolbar.exitSketchBtn,
'We should not be in sketch mode now'
).not.toBeVisible()
await expect(
page.getByText(
'Editing sketches on faces or offset planes through the feature tree is not yet supported'
),
'We should see a toast message about this'
'We should be in sketch mode now'
).toBeVisible()
})
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/components/ModelingMachineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,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 @@ -20,7 +20,13 @@ import { Models } from '@kittycad/lib'
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
import { Selection } from 'lib/selections'
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 @@ -610,6 +616,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 @@ -631,6 +657,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
66 changes: 43 additions & 23 deletions src/wasm-lib/kcl/src/execution/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@
pub path_to_node: DummyPathToNode,
}

impl CodeRef {
pub fn placeholder(range: SourceRange) -> Self {
Self {
range,
path_to_node: Vec::new(),
}
}
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS)]
#[ts(export_to = "Artifact.ts")]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -178,6 +187,24 @@
pub path_id: ArtifactId,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS)]
#[ts(export_to = "Artifact.ts")]
#[serde(rename_all = "camelCase")]
pub struct StartSketchOnFace {
pub id: ArtifactId,
pub face_id: ArtifactId,
pub code_ref: CodeRef,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS)]
#[ts(export_to = "Artifact.ts")]
#[serde(rename_all = "camelCase")]
pub struct StartSketchOnPlane {
pub id: ArtifactId,
pub plane_id: ArtifactId,
pub code_ref: CodeRef,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS)]
#[ts(export_to = "Artifact.ts")]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -295,18 +322,8 @@
Path(Path),
Segment(Segment),
Solid2d(Solid2d),
#[serde(rename_all = "camelCase")]
StartSketchOnFace {
id: ArtifactId,
face_id: Uuid,
source_range: SourceRange,
},
#[serde(rename_all = "camelCase")]
StartSketchOnPlane {
id: ArtifactId,
plane_id: Uuid,
source_range: SourceRange,
},
StartSketchOnFace(StartSketchOnFace),
StartSketchOnPlane(StartSketchOnPlane),
Sweep(Sweep),
Wall(Wall),
Cap(Cap),
Expand All @@ -323,8 +340,8 @@
Artifact::Path(a) => a.id,
Artifact::Segment(a) => a.id,
Artifact::Solid2d(a) => a.id,
Artifact::StartSketchOnFace { id, .. } => *id,
Artifact::StartSketchOnPlane { id, .. } => *id,
Artifact::StartSketchOnFace(a) => a.id,
Artifact::StartSketchOnPlane(a) => a.id,
Artifact::Sweep(a) => a.id,
Artifact::Wall(a) => a.id,
Artifact::Cap(a) => a.id,
Expand All @@ -342,9 +359,8 @@
Artifact::Path(a) => Some(&a.code_ref),
Artifact::Segment(a) => Some(&a.code_ref),
Artifact::Solid2d(_) => None,
// TODO: We should add code refs for these.
Artifact::StartSketchOnFace { .. } => None,
Artifact::StartSketchOnPlane { .. } => None,
Artifact::StartSketchOnFace(a) => Some(&a.code_ref),
Artifact::StartSketchOnPlane(a) => Some(&a.code_ref),

Check warning on line 363 in src/wasm-lib/kcl/src/execution/artifact.rs

View check run for this annotation

Codecov / codecov/patch

src/wasm-lib/kcl/src/execution/artifact.rs#L362-L363

Added lines #L362 - L363 were not covered by tests
Artifact::Sweep(a) => Some(&a.code_ref),
Artifact::Wall(_) => None,
Artifact::Cap(_) => None,
Expand Down Expand Up @@ -507,6 +523,10 @@
}
}

for exec_artifact in exec_artifacts.values() {
merge_artifact_into_map(&mut map, exec_artifact.clone());
}
Comment on lines +526 to +528
Copy link
Contributor Author

@jtran jtran Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the core of the change.

It's unfortunate that there are two loops, this one and the one above. I think this might cause some problems when there are multiple sketches-on-face/place on the same face/plane.


Ok(ArtifactGraph { map })
}

Expand Down Expand Up @@ -841,15 +861,15 @@
})
})?;
let extra_artifact = exec_artifacts.values().find(|a| {
if let Artifact::StartSketchOnFace { face_id: id, .. } = a {
*id == face_id.0
if let Artifact::StartSketchOnFace(s) = a {
s.face_id == face_id
} else {
false
}
});
let sketch_on_face_source_range = extra_artifact
.and_then(|a| match a {
Artifact::StartSketchOnFace { source_range, .. } => Some(*source_range),
Artifact::StartSketchOnFace(s) => Some(s.code_ref.range),
// TODO: If we didn't find it, it's probably a bug.
_ => None,
})
Expand Down Expand Up @@ -894,15 +914,15 @@
})
})?;
let extra_artifact = exec_artifacts.values().find(|a| {
if let Artifact::StartSketchOnFace { face_id: id, .. } = a {
*id == face_id.0
if let Artifact::StartSketchOnFace(s) = a {
s.face_id == face_id
} else {
false
}
});
let sketch_on_face_source_range = extra_artifact
.and_then(|a| match a {
Artifact::StartSketchOnFace { source_range, .. } => Some(*source_range),
Artifact::StartSketchOnFace(s) => Some(s.code_ref.range),
_ => None,
})
.unwrap_or_default();
Expand Down
26 changes: 15 additions & 11 deletions src/wasm-lib/kcl/src/execution/artifact/mermaid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ impl Artifact {
Artifact::Path(a) => vec![a.plane_id],
Artifact::Segment(a) => vec![a.path_id],
Artifact::Solid2d(a) => vec![a.path_id],
Artifact::StartSketchOnFace { face_id, .. } => vec![face_id.into()],
Artifact::StartSketchOnPlane { plane_id, .. } => vec![plane_id.into()],
Artifact::StartSketchOnFace(a) => vec![a.face_id],
Artifact::StartSketchOnPlane(a) => vec![a.plane_id],
Artifact::Sweep(a) => vec![a.path_id],
Artifact::Wall(a) => vec![a.seg_id, a.sweep_id],
Artifact::Cap(a) => vec![a.sweep_id],
Expand Down Expand Up @@ -115,8 +115,14 @@ impl Artifact {
// Note: Don't include these since they're parents: path_id.
Vec::new()
}
Artifact::StartSketchOnFace { .. } => Vec::new(),
Artifact::StartSketchOnPlane { .. } => Vec::new(),
Artifact::StartSketchOnFace { .. } => {
// Note: Don't include these since they're parents: face_id.
Vec::new()
}
Artifact::StartSketchOnPlane { .. } => {
// Note: Don't include these since they're parents: plane_id.
Vec::new()
}
Artifact::Sweep(a) => {
// Note: Don't include these since they're parents: path_id.
let mut ids = Vec::new();
Expand Down Expand Up @@ -267,9 +273,7 @@ impl ArtifactGraph {
) -> std::fmt::Result {
// For now, only showing the source range.
fn code_ref_display(code_ref: &CodeRef) -> [usize; 3] {
range_display(code_ref.range)
}
fn range_display(range: SourceRange) -> [usize; 3] {
let range = code_ref.range;
[range.start(), range.end(), range.module_id().as_usize()]
}

Expand Down Expand Up @@ -301,20 +305,20 @@ impl ArtifactGraph {
Artifact::Solid2d(_solid2d) => {
writeln!(output, "{prefix}{}[Solid2d]", id)?;
}
Artifact::StartSketchOnFace { source_range, .. } => {
Artifact::StartSketchOnFace(StartSketchOnFace { code_ref, .. }) => {
writeln!(
output,
"{prefix}{}[\"StartSketchOnFace<br>{:?}\"]",
id,
range_display(*source_range)
code_ref_display(code_ref)
)?;
}
Artifact::StartSketchOnPlane { source_range, .. } => {
Artifact::StartSketchOnPlane(StartSketchOnPlane { code_ref, .. }) => {
writeln!(
output,
"{prefix}{}[\"StartSketchOnPlane<br>{:?}\"]",
id,
range_display(*source_range)
code_ref_display(code_ref)
)?;
}
Artifact::Sweep(sweep) => {
Expand Down
4 changes: 3 additions & 1 deletion src/wasm-lib/kcl/src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use std::{path::PathBuf, sync::Arc};

use anyhow::Result;
pub use artifact::{Artifact, ArtifactCommand, ArtifactGraph, ArtifactId};
pub use artifact::{
Artifact, ArtifactCommand, ArtifactGraph, ArtifactId, CodeRef, StartSketchOnFace, StartSketchOnPlane,
};
use cache::OldAstState;
pub use cache::{bust_cache, clear_mem_cache};
pub use cad_op::Operation;
Expand Down
17 changes: 9 additions & 8 deletions src/wasm-lib/kcl/src/std/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::execution::{CodeRef, StartSketchOnFace, StartSketchOnPlane};
use crate::{
errors::{KclError, KclErrorDetails},
execution::{
Expand Down Expand Up @@ -1150,11 +1151,11 @@ async fn inner_start_sketch_on(
} else {
// Create artifact used only by the UI, not the engine.
let id = exec_state.next_uuid();
exec_state.add_artifact(Artifact::StartSketchOnPlane {
exec_state.add_artifact(Artifact::StartSketchOnPlane(StartSketchOnPlane {
id: ArtifactId::from(id),
plane_id: plane.id,
source_range: args.source_range,
});
plane_id: plane.artifact_id,
code_ref: CodeRef::placeholder(args.source_range),
}));

Ok(SketchSurface::Plane(plane))
}
Expand All @@ -1170,11 +1171,11 @@ async fn inner_start_sketch_on(

// Create artifact used only by the UI, not the engine.
let id = exec_state.next_uuid();
exec_state.add_artifact(Artifact::StartSketchOnFace {
exec_state.add_artifact(Artifact::StartSketchOnFace(StartSketchOnFace {
id: ArtifactId::from(id),
face_id: face.id,
source_range: args.source_range,
});
face_id: face.artifact_id,
code_ref: CodeRef::placeholder(args.source_range),
}));

Ok(SketchSurface::Face(face))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ flowchart LR
39["SweepEdge Adjacent"]
40["SweepEdge Opposite"]
41["SweepEdge Adjacent"]
42["StartSketchOnFace<br>[345, 377, 0]"]
1 --- 2
2 --- 3
2 --- 4
Expand Down Expand Up @@ -106,4 +107,5 @@ flowchart LR
31 --- 39
31 --- 40
31 --- 41
11 <--x 42
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ flowchart LR
1["Plane<br>[17, 47, 0]"]
2["Plane<br>[65, 96, 0]"]
3["Plane<br>[114, 144, 0]"]
6["StartSketchOnPlane<br>[158, 187, 0]"]
1 --- 4
4 --- 5
1 <--x 6
```
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ flowchart LR
68["SweepEdge Adjacent"]
69["SweepEdge Opposite"]
70["SweepEdge Adjacent"]
71["StartSketchOnFace<br>[257, 289, 0]"]
72["StartSketchOnFace<br>[506, 538, 0]"]
73["StartSketchOnFace<br>[768, 800, 0]"]
1 --- 2
2 --- 3
2 --- 4
Expand Down Expand Up @@ -183,4 +186,7 @@ flowchart LR
60 --- 68
60 --- 69
60 --- 70
10 <--x 71
30 <--x 72
46 <--x 73
```
Loading
Loading