Skip to content

Allow point-and-click Offset Plane to work from sweep faces #7882

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

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
13 changes: 5 additions & 8 deletions e2e/playwright/feature-tree-pane.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,26 +381,23 @@ test.describe('Feature Tree pane', () => {
await cmdBar.expectState({
commandName: 'Offset plane',
stage: 'arguments',
currentArgKey: 'distance',
currentArgKey: 'offset',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed this to be more in line with KCL

currentArgValue: initialInput,
headerArguments: {
Plane: '1 plane',
Distance: initialInput,
Offset: initialInput,
},
highlightedHeaderArg: 'distance',
highlightedHeaderArg: 'offset',
})
})

await test.step('Edit the distance argument and submit', async () => {
await test.step('Edit the offset argument and submit', async () => {
await expect(cmdBar.currentArgumentInput).toBeVisible()
await cmdBar.currentArgumentInput.locator('.cm-content').fill(newInput)
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'review',
headerArguments: {
Plane: '1 plane',
// We show the calculated value in the argument summary
Distance: '15',
Offset: '15',
},
commandName: 'Offset plane',
})
Expand Down
23 changes: 7 additions & 16 deletions e2e/playwright/point-click.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,18 +1083,10 @@ openSketch = startSketchOn(XY)
toolbar,
cmdBar,
}) => {
// One dumb hardcoded screen pixel value
const testPoint = { x: 700, y: 200 }
// TODO: replace the testPoint selection with a feature tree click once that's supported #7544
const [clickOnXzPlane] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
const expectedOutput = `plane001 = offsetPlane(XZ, offset = 5)`

await homePage.goToModelingScene()
await scene.settled(cmdBar)

await test.step(`Look for the blue of the XZ plane`, async () => {
//await scene.expectPixelColor([50, 51, 96], testPoint, 15) // FIXME
})
await test.step(`Go through the command bar flow`, async () => {
await toolbar.offsetPlaneButton.click()
await expect
Expand All @@ -1104,30 +1096,30 @@ openSketch = startSketchOn(XY)
stage: 'arguments',
currentArgKey: 'plane',
currentArgValue: '',
headerArguments: { Plane: '', Distance: '' },
headerArguments: { Plane: '', Offset: '' },
highlightedHeaderArg: 'plane',
commandName: 'Offset plane',
})
await clickOnXzPlane()
const xz = await toolbar.getFeatureTreeOperation('Front plane', 0)
await xz.click()
Comment on lines +932 to +933
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And would like to keep these two tests as they aren't px dependent anymore

await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'distance',
currentArgKey: 'offset',
currentArgValue: '5',
headerArguments: { Plane: '1 plane', Distance: '' },
highlightedHeaderArg: 'distance',
headerArguments: { Plane: '1 plane', Offset: '' },
highlightedHeaderArg: 'offset',
commandName: 'Offset plane',
})
await cmdBar.progressCmdBar()
})

await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
await test.step(`Confirm code is added to the editor`, async () => {
await editor.expectEditor.toContain(expectedOutput)
await editor.expectState({
diagnostics: [],
activeLines: [expectedOutput],
highlightedCode: '',
})
await scene.expectPixelColor([74, 74, 74], testPoint, 15)
})

await test.step('Delete offset plane via feature tree selection', async () => {
Expand All @@ -1138,7 +1130,6 @@ openSketch = startSketchOn(XY)
)
await operationButton.click({ button: 'left' })
await page.keyboard.press('Delete')
//await scene.expectPixelColor([50, 51, 96], testPoint, 15) // FIXME
})
})

Expand Down
14 changes: 14 additions & 0 deletions rust/kcl-lib/src/execution/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ pub struct Solid2d {
pub path_id: ArtifactId,
}

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

#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS)]
#[ts(export_to = "Artifact.ts")]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -325,6 +334,7 @@ pub enum Artifact {
Path(Path),
Segment(Segment),
Solid2d(Solid2d),
PlaneOfFace(PlaneOfFace),
StartSketchOnFace(StartSketchOnFace),
StartSketchOnPlane(StartSketchOnPlane),
Sweep(Sweep),
Expand All @@ -346,6 +356,7 @@ impl Artifact {
Artifact::Solid2d(a) => a.id,
Artifact::StartSketchOnFace(a) => a.id,
Artifact::StartSketchOnPlane(a) => a.id,
Artifact::PlaneOfFace(a) => a.id,
Artifact::Sweep(a) => a.id,
Artifact::Wall(a) => a.id,
Artifact::Cap(a) => a.id,
Expand All @@ -367,6 +378,7 @@ impl Artifact {
Artifact::Solid2d(_) => None,
Artifact::StartSketchOnFace(a) => Some(&a.code_ref),
Artifact::StartSketchOnPlane(a) => Some(&a.code_ref),
Artifact::PlaneOfFace(a) => Some(&a.code_ref),
Artifact::Sweep(a) => Some(&a.code_ref),
Artifact::Wall(_) => None,
Artifact::Cap(_) => None,
Expand All @@ -387,6 +399,7 @@ impl Artifact {
| Artifact::Segment(_)
| Artifact::Solid2d(_)
| Artifact::StartSketchOnFace(_)
| Artifact::PlaneOfFace(_)
| Artifact::StartSketchOnPlane(_)
| Artifact::Sweep(_) => None,
Artifact::Wall(a) => Some(&a.face_code_ref),
Expand All @@ -406,6 +419,7 @@ impl Artifact {
Artifact::Solid2d(_) => Some(new),
Artifact::StartSketchOnFace { .. } => Some(new),
Artifact::StartSketchOnPlane { .. } => Some(new),
Artifact::PlaneOfFace { .. } => Some(new),
Artifact::Sweep(a) => a.merge(new),
Artifact::Wall(a) => a.merge(new),
Artifact::Cap(a) => a.merge(new),
Expand Down
14 changes: 14 additions & 0 deletions rust/kcl-lib/src/execution/artifact/mermaid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl Artifact {
Artifact::Solid2d(a) => vec![a.path_id],
Artifact::StartSketchOnFace(a) => vec![a.face_id],
Artifact::StartSketchOnPlane(a) => vec![a.plane_id],
Artifact::PlaneOfFace(a) => vec![a.face_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 @@ -151,6 +152,10 @@ impl Artifact {
// Note: Don't include these since they're parents: plane_id.
Vec::new()
}
Artifact::PlaneOfFace { .. } => {
// Note: Don't include these since they're parents: face_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 @@ -262,6 +267,7 @@ impl ArtifactGraph {
}
Artifact::StartSketchOnFace { .. }
| Artifact::StartSketchOnPlane { .. }
| Artifact::PlaneOfFace { .. }
| Artifact::Sweep(_)
| Artifact::Wall(_)
| Artifact::Cap(_)
Expand Down Expand Up @@ -381,6 +387,14 @@ impl ArtifactGraph {
)?;
node_path_display(output, prefix, None, code_ref)?;
}
Artifact::PlaneOfFace(PlaneOfFace { code_ref, .. }) => {
writeln!(
output,
"{prefix}{id}[\"PlaneOfFace<br>{:?}\"]",
code_ref_display(code_ref)
)?;
node_path_display(output, prefix, None, code_ref)?;
}
Artifact::Sweep(sweep) => {
writeln!(
output,
Expand Down
4 changes: 3 additions & 1 deletion rust/kcl-lib/src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::sync::Arc;

use anyhow::Result;
#[cfg(feature = "artifact-graph")]
pub use artifact::{Artifact, ArtifactCommand, ArtifactGraph, CodeRef, StartSketchOnFace, StartSketchOnPlane};
pub use artifact::{
Artifact, ArtifactCommand, ArtifactGraph, CodeRef, PlaneOfFace, StartSketchOnFace, StartSketchOnPlane,
};
use cache::GlobalState;
pub use cache::{bust_cache, clear_mem_cache};
#[cfg(feature = "artifact-graph")]
Expand Down
11 changes: 11 additions & 0 deletions rust/kcl-lib/src/std/planes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ async fn inner_plane_of(

// Engine doesn't send back an ID, so let's just make a new plane ID.
let plane_id = exec_state.id_generator().next_uuid();
#[cfg(feature = "artifact-graph")]
{
use crate::execution::{Artifact, ArtifactId, CodeRef, PlaneOfFace};
// Create artifact used only by the UI, not the engine.
exec_state.add_artifact(Artifact::PlaneOfFace(PlaneOfFace {
id: ArtifactId::from(plane_id),
face_id: face_id.into(),
code_ref: CodeRef::placeholder(args.source_range),
}));
}

Ok(Plane {
artifact_id: plane_id.into(),
id: plane_id,
Expand Down
57 changes: 1 addition & 56 deletions src/lang/modifyAst.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { BodyItem } from '@rust/kcl-lib/bindings/BodyItem'
import type { Name } from '@rust/kcl-lib/bindings/Name'
import type { Node } from '@rust/kcl-lib/bindings/Node'
import type { NonCodeMeta } from '@rust/kcl-lib/bindings/NonCodeMeta'

Expand Down Expand Up @@ -27,11 +26,7 @@ import {
isNodeSafeToReplace,
isNodeSafeToReplacePath,
} from '@src/lang/queryAst'
import {
ARG_INDEX_FIELD,
LABELED_ARG_FIELD,
UNLABELED_ARG,
} from '@src/lang/queryAstConstants'
import { ARG_INDEX_FIELD, LABELED_ARG_FIELD } from '@src/lang/queryAstConstants'
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
import {
addTagForSketchOnFace,
Expand Down Expand Up @@ -422,56 +417,6 @@ export function sketchOnExtrudedFace(
}
}

/**
* Append an offset plane to the AST
*/
export function addOffsetPlane({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to faces.ts with the addShell codemod since they will share a few utils

node,
plane,
insertIndex,
offset,
planeName,
}: {
node: Node<Program>
plane: Node<Literal> | Node<Name> // Can be DefaultPlaneStr or string for offsetPlanes
insertIndex?: number
offset: Expr
planeName?: string
}): { modifiedAst: Node<Program>; pathToNode: PathToNode } {
const modifiedAst = structuredClone(node)
const newPlaneName =
planeName ?? findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.PLANE)

const newPlane = createVariableDeclaration(
newPlaneName,
createCallExpressionStdLibKw('offsetPlane', plane, [
createLabeledArg('offset', offset),
])
)

const insertAt =
insertIndex !== undefined
? insertIndex
: modifiedAst.body.length
? modifiedAst.body.length
: 0

modifiedAst.body.length
? modifiedAst.body.splice(insertAt, 0, newPlane)
: modifiedAst.body.push(newPlane)
const pathToNode: PathToNode = [
['body', ''],
[insertAt, 'index'],
['declaration', 'VariableDeclaration'],
['init', 'VariableDeclarator'],
['unlabeled', UNLABELED_ARG],
]
return {
modifiedAst,
pathToNode,
}
}

/**
* Add an import call to load a part
*/
Expand Down
Loading
Loading