Skip to content

Commit c7f6808

Browse files
jtranIrev-Dev
andauthored
Sketch mode partial execution (#9557)
* Change sketch block args to require a variable The plane Object ID in frontend tests is wrong. * Fix plane types to model ObjectId correctly * Fix to send plane to engine at start of sketch block Update test expectations * Refactor existing code to use new helper function * Fix sketch blocks to always provide on argument * Update generated output for sketch block tests * Add test sketching on offset plane * Fix to find sketch block artifact Ignore it for now. * Update generated output * Rename functions * Make sure to mark the sketch block node whenever we mock execute * Add sketch mode to state * Skip non-sketch-block statements Some tests are failing because ObjectIds are actually wrong. * Change previous memory tuple to named struct * Add scene objects to mock execution cache * Fix delete sketch to use engine execution * Add back assertions that IDs match the array index * Simplify accessor and modifier functions * Add failing test for sketch block on face * Add support for sketch block `on` parameter to be a Face or Sketch * Update output for sketch on face sim test * Update the rest of the sim test output * Fix sketch on face * Add sketch on plane of sim test * Add sketch on planeOf frontend test * allow edit from cursor position in sketch blocks * Update output after merging main * Add comments about reading the cached module state * Fix to never panic when cache length is unexpected * Simplify cache rehydration * Fix segment IDs in tests --------- Co-authored-by: Kurt Hutten Irev-Dev <[email protected]>
1 parent 53f56ef commit c7f6808

File tree

315 files changed

+19269
-3329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

315 files changed

+19269
-3329
lines changed

e2e/playwright/sketch-solve-edit.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ test.describe('Sketch solve edit tests', { tag: '@desktop' }, () => {
125125

126126
await test.step('Drag point segment 13 down', async () => {
127127
const segmentBox = await scene.getBoundingBoxOrThrow(
128-
'[data-segment_id="13"]'
128+
'[data-segment_id="14"]'
129129
)
130130

131131
const centerX = segmentBox.x + segmentBox.width / 2
@@ -145,7 +145,7 @@ test.describe('Sketch solve edit tests', { tag: '@desktop' }, () => {
145145
})
146146

147147
await test.step('Drag line segment by dragging midpoint between points 8 and 9 down', async () => {
148-
const midpoint = await getMidpointBetweenSegments(scene, '8', '9')
148+
const midpoint = await getMidpointBetweenSegments(scene, '9', '10')
149149

150150
const lineToEdit = getCodeLine({ code: TEST_CODE, line: 8 })
151151
await editor.expectEditor.toContain(lineToEdit)
@@ -306,10 +306,10 @@ test.describe('Sketch solve edit tests', { tag: '@desktop' }, () => {
306306
await page.getByTestId('point').click()
307307
})
308308

309-
await test.step('Select segments 1 and 8, then apply coincident constraint', async () => {
310-
await page.locator('[data-segment_id="1"]').click()
309+
await test.step('Select segments 2 and 9, then apply coincident constraint', async () => {
310+
await page.locator('[data-segment_id="2"]').click()
311311
// await page.waitForTimeout(100)
312-
await page.locator('[data-segment_id="8"]').click()
312+
await page.locator('[data-segment_id="9"]').click()
313313
// await page.waitForTimeout(100)
314314

315315
// Click the coincident tool
@@ -323,10 +323,10 @@ test.describe('Sketch solve edit tests', { tag: '@desktop' }, () => {
323323
const [clearSelection] = scene.makeMouseHelpers(0.5, 0.5, {
324324
format: 'ratio',
325325
})
326-
await test.step('Select lines between segments 1-2 and 4-5, then apply parallel constraint', async () => {
326+
await test.step('Select lines between segments 2-3 and 5-6, then apply parallel constraint', async () => {
327327
await clearSelection()
328328
const segmentBox = await scene.getBoundingBoxOrThrow(
329-
'[data-segment_id="1"]'
329+
'[data-segment_id="2"]'
330330
)
331331
const centerX = segmentBox.x + segmentBox.width / 2
332332
const centerY = segmentBox.y + segmentBox.height / 2
@@ -336,10 +336,10 @@ test.describe('Sketch solve edit tests', { tag: '@desktop' }, () => {
336336
await page.mouse.up()
337337
})
338338

339-
await test.step('Select lines between segments 1-2 and 4-5, then apply parallel constraint', async () => {
339+
await test.step('Select lines between segments 2-3 and 5-6, then apply parallel constraint', async () => {
340340
// Click in dead space to clear selections
341-
const midpoint1_2 = await getMidpointBetweenSegments(scene, '1', '2')
342-
const midpoint4_5 = await getMidpointBetweenSegments(scene, '4', '5')
341+
const midpoint1_2 = await getMidpointBetweenSegments(scene, '2', '3')
342+
const midpoint4_5 = await getMidpointBetweenSegments(scene, '5', '6')
343343

344344
await clearSelection()
345345
// await page.waitForTimeout(100)
16 Bytes
Loading
298 Bytes
Loading
-19 Bytes
Loading

rust/kcl-lib/src/execution/cache.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
memory::Stack,
1313
state::{self as exec_state, ModuleInfoMap},
1414
},
15+
front::Object,
1516
parsing::ast::types::{Annotation, Node, Program},
1617
walk::Node as WalkNode,
1718
};
@@ -20,7 +21,7 @@ lazy_static::lazy_static! {
2021
/// A static mutable lock for updating the last successful execution state for the cache.
2122
static ref OLD_AST: Arc<RwLock<Option<GlobalState>>> = Default::default();
2223
// The last successful run's memory. Not cleared after an unsuccessful run.
23-
static ref PREV_MEMORY: Arc<RwLock<Option<(Stack, ModuleInfoMap)>>> = Default::default();
24+
static ref PREV_MEMORY: Arc<RwLock<Option<SketchModeState>>> = Default::default();
2425
}
2526

2627
/// Read the old ast memory from the lock.
@@ -34,12 +35,12 @@ pub(super) async fn write_old_ast(old_state: GlobalState) {
3435
*old_ast = Some(old_state);
3536
}
3637

37-
pub(crate) async fn read_old_memory() -> Option<(Stack, ModuleInfoMap)> {
38+
pub(crate) async fn read_old_memory() -> Option<SketchModeState> {
3839
let old_mem = PREV_MEMORY.read().await;
3940
old_mem.clone()
4041
}
4142

42-
pub(crate) async fn write_old_memory(mem: (Stack, ModuleInfoMap)) {
43+
pub(crate) async fn write_old_memory(mem: SketchModeState) {
4344
let mut old_mem = PREV_MEMORY.write().await;
4445
*old_mem = Some(mem);
4546
}
@@ -134,6 +135,18 @@ pub(super) struct ModuleState {
134135
pub(super) result_env: EnvironmentRef,
135136
}
136137

138+
/// Cached state for sketch mode.
139+
#[derive(Debug, Clone)]
140+
pub(crate) struct SketchModeState {
141+
/// The stack of the main module.
142+
pub stack: Stack,
143+
/// The module info map.
144+
pub module_infos: ModuleInfoMap,
145+
/// The scene objects.
146+
#[cfg_attr(not(feature = "artifact-graph"), expect(dead_code))]
147+
pub scene_objects: Vec<Object>,
148+
}
149+
137150
/// The result of a cache check.
138151
#[derive(Debug, Clone, PartialEq)]
139152
#[allow(clippy::large_enum_variant)]

0 commit comments

Comments
 (0)