diff --git a/e2e/playwright/snapshots/prompt-to-edit/prompt-to-edit-snapshot-tests-spec-ts--change-colour.snap.json b/e2e/playwright/snapshots/prompt-to-edit/prompt-to-edit-snapshot-tests-spec-ts--change-colour.snap.json index 8eb0256d35..c37a4a8179 100644 --- a/e2e/playwright/snapshots/prompt-to-edit/prompt-to-edit-snapshot-tests-spec-ts--change-colour.snap.json +++ b/e2e/playwright/snapshots/prompt-to-edit/prompt-to-edit-snapshot-tests-spec-ts--change-colour.snap.json @@ -29,5 +29,5 @@ } } ], - "kcl_version": "0.2.41" + "kcl_version": "0.2.44" } \ No newline at end of file diff --git a/src/wasm-lib/kcl/src/execution/mod.rs b/src/wasm-lib/kcl/src/execution/mod.rs index a72ec118e6..731b4f72a2 100644 --- a/src/wasm-lib/kcl/src/execution/mod.rs +++ b/src/wasm-lib/kcl/src/execution/mod.rs @@ -776,6 +776,14 @@ impl ExecutorContext { ) .await; + if exec_result.is_ok() { + // Flush the batch with all the end commands. + // If we don't do this then some programs might not fully finish executing. + self.engine + .flush_batch(true, SourceRange::new(program.end, program.end, ModuleId::default())) + .await?; + } + // Move the artifact commands and responses to simplify cache management // and error creation. exec_state diff --git a/src/wasm-lib/kcl/src/simulation_tests.rs b/src/wasm-lib/kcl/src/simulation_tests.rs index e2ea794c81..baafb9bfc4 100644 --- a/src/wasm-lib/kcl/src/simulation_tests.rs +++ b/src/wasm-lib/kcl/src/simulation_tests.rs @@ -2074,3 +2074,25 @@ mod import_file_parse_error { super::execute(TEST_NAME, true).await } } + +mod flush_batch_on_end { + const TEST_NAME: &str = "flush_batch_on_end"; + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME); + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, true).await + } +} diff --git a/src/wasm-lib/kcl/tests/assembly_non_default_units/artifact_commands.snap b/src/wasm-lib/kcl/tests/assembly_non_default_units/artifact_commands.snap index 27c40336dd..586927f4cc 100644 --- a/src/wasm-lib/kcl/tests/assembly_non_default_units/artifact_commands.snap +++ b/src/wasm-lib/kcl/tests/assembly_non_default_units/artifact_commands.snap @@ -552,5 +552,17 @@ description: Artifact commands assembly_non_default_units.kcl "type": "close_path", "path_id": "[uuid]" } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "set_scene_units", + "unit": "mm" + } } ] diff --git a/src/wasm-lib/kcl/tests/cube_with_error/artifact_commands.snap b/src/wasm-lib/kcl/tests/cube_with_error/artifact_commands.snap index 481cdc1594..497cf611a6 100644 --- a/src/wasm-lib/kcl/tests/cube_with_error/artifact_commands.snap +++ b/src/wasm-lib/kcl/tests/cube_with_error/artifact_commands.snap @@ -1,7 +1,6 @@ --- source: kcl/src/simulation_tests.rs description: Artifact commands cube_with_error.kcl -snapshot_kind: text --- [ { diff --git a/src/wasm-lib/kcl/tests/flush_batch_on_end/artifact_commands.snap b/src/wasm-lib/kcl/tests/flush_batch_on_end/artifact_commands.snap new file mode 100644 index 0000000000..ea7fbb0033 --- /dev/null +++ b/src/wasm-lib/kcl/tests/flush_batch_on_end/artifact_commands.snap @@ -0,0 +1,667 @@ +--- +source: kcl/src/simulation_tests.rs +description: Artifact commands flush_batch_on_end.kcl +--- +[ + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "plane_set_color", + "plane_id": "[uuid]", + "color": { + "r": 0.7, + "g": 0.28, + "b": 0.28, + "a": 0.4 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "plane_set_color", + "plane_id": "[uuid]", + "color": { + "r": 0.28, + "g": 0.7, + "b": 0.28, + "a": 0.4 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "plane_set_color", + "plane_id": "[uuid]", + "color": { + "r": 0.28, + "g": 0.28, + "b": 0.7, + "a": 0.4 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": -1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": -1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 100.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "edge_lines_visible", + "hidden": false + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "set_scene_units", + "unit": "mm" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 33, + 0 + ], + "command": { + "type": "set_scene_units", + "unit": "in" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 199, + 218, + 0 + ], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "size": 60.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 282, + 365, + 0 + ], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 282, + 365, + 0 + ], + "command": { + "type": "start_path" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 282, + 365, + 0 + ], + "command": { + "type": "move_path_pen", + "path": "[uuid]", + "to": { + "x": 0.2734375, + "y": 0.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 282, + 365, + 0 + ], + "command": { + "type": "extend_path", + "path": "[uuid]", + "segment": { + "type": "arc", + "center": { + "x": 0.0, + "y": 0.0 + }, + "radius": 0.2734375, + "start": { + "unit": "degrees", + "value": 0.0 + }, + "end": { + "unit": "degrees", + "value": 360.0 + }, + "relative": false + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 282, + 365, + 0 + ], + "command": { + "type": "close_path", + "path_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 428, + 511, + 0 + ], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 428, + 511, + 0 + ], + "command": { + "type": "start_path" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 428, + 511, + 0 + ], + "command": { + "type": "move_path_pen", + "path": "[uuid]", + "to": { + "x": 0.182, + "y": 0.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 428, + 511, + 0 + ], + "command": { + "type": "extend_path", + "path": "[uuid]", + "segment": { + "type": "arc", + "center": { + "x": 0.0, + "y": 0.0 + }, + "radius": 0.182, + "start": { + "unit": "degrees", + "value": 0.0 + }, + "end": { + "unit": "degrees", + "value": 360.0 + }, + "relative": false + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 428, + 511, + 0 + ], + "command": { + "type": "close_path", + "path_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 601, + 622, + 0 + ], + "command": { + "type": "solid2d_add_hole", + "object_id": "[uuid]", + "hole_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 601, + 622, + 0 + ], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + }, + { + "cmdId": "[uuid]", + "range": [ + 678, + 715, + 0 + ], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [ + 678, + 715, + 0 + ], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.5, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [ + 678, + 715, + 0 + ], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 678, + 715, + 0 + ], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 678, + 715, + 0 + ], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 678, + 715, + 0 + ], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 678, + 715, + 0 + ], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 678, + 715, + 0 + ], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 678, + 715, + 0 + ], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "set_scene_units", + "unit": "mm" + } + } +] diff --git a/src/wasm-lib/kcl/tests/flush_batch_on_end/artifact_graph_flowchart.snap b/src/wasm-lib/kcl/tests/flush_batch_on_end/artifact_graph_flowchart.snap new file mode 100644 index 0000000000..f14ce9e363 --- /dev/null +++ b/src/wasm-lib/kcl/tests/flush_batch_on_end/artifact_graph_flowchart.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Artifact graph flowchart flush_batch_on_end.kcl +extension: md +snapshot_kind: binary +--- diff --git a/src/wasm-lib/kcl/tests/flush_batch_on_end/artifact_graph_flowchart.snap.md b/src/wasm-lib/kcl/tests/flush_batch_on_end/artifact_graph_flowchart.snap.md new file mode 100644 index 0000000000..09b01049aa --- /dev/null +++ b/src/wasm-lib/kcl/tests/flush_batch_on_end/artifact_graph_flowchart.snap.md @@ -0,0 +1,35 @@ +```mermaid +flowchart LR + subgraph path2 [Path] + 2["Path
[282, 365, 0]"] + 3["Segment
[282, 365, 0]"] + 4[Solid2d] + end + subgraph path5 [Path] + 5["Path
[428, 511, 0]"] + 6["Segment
[428, 511, 0]"] + 7[Solid2d] + end + 1["Plane
[199, 218, 0]"] + 8["Sweep Extrusion
[678, 715, 0]"] + 9[Wall] + 10["Cap Start"] + 11["Cap End"] + 12["SweepEdge Opposite"] + 13["SweepEdge Adjacent"] + 1 --- 2 + 1 --- 5 + 2 --- 3 + 2 ---- 8 + 2 --- 4 + 3 --- 9 + 3 --- 12 + 3 --- 13 + 5 --- 6 + 5 --- 7 + 8 --- 9 + 8 --- 10 + 8 --- 11 + 8 --- 12 + 8 --- 13 +``` diff --git a/src/wasm-lib/kcl/tests/flush_batch_on_end/ast.snap b/src/wasm-lib/kcl/tests/flush_batch_on_end/ast.snap new file mode 100644 index 0000000000..bf67384762 --- /dev/null +++ b/src/wasm-lib/kcl/tests/flush_batch_on_end/ast.snap @@ -0,0 +1,700 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing flush_batch_on_end.kcl +--- +{ + "Ok": { + "body": [ + { + "declaration": { + "end": 105, + "id": { + "end": 97, + "name": "innerDiameter", + "start": 84, + "type": "Identifier" + }, + "init": { + "end": 105, + "raw": "0.364", + "start": 100, + "type": "Literal", + "type": "Literal", + "value": { + "value": 0.364, + "suffix": "None" + } + }, + "start": 84, + "type": "VariableDeclarator" + }, + "end": 105, + "kind": "const", + "start": 84, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declaration": { + "end": 129, + "id": { + "end": 119, + "name": "outerDiameter", + "start": 106, + "type": "Identifier" + }, + "init": { + "end": 129, + "left": { + "end": 124, + "raw": "35", + "start": 122, + "type": "Literal", + "type": "Literal", + "value": { + "value": 35.0, + "suffix": "None" + } + }, + "operator": "/", + "right": { + "end": 129, + "raw": "64", + "start": 127, + "type": "Literal", + "type": "Literal", + "value": { + "value": 64.0, + "suffix": "None" + } + }, + "start": 122, + "type": "BinaryExpression", + "type": "BinaryExpression" + }, + "start": 106, + "type": "VariableDeclarator" + }, + "end": 129, + "kind": "const", + "start": 106, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declaration": { + "end": 148, + "id": { + "end": 136, + "name": "length", + "start": 130, + "type": "Identifier" + }, + "init": { + "end": 148, + "left": { + "end": 140, + "raw": "1", + "start": 139, + "type": "Literal", + "type": "Literal", + "value": { + "value": 1.0, + "suffix": "None" + } + }, + "operator": "+", + "right": { + "end": 148, + "left": { + "end": 144, + "raw": "1", + "start": 143, + "type": "Literal", + "type": "Literal", + "value": { + "value": 1.0, + "suffix": "None" + } + }, + "operator": "/", + "right": { + "end": 148, + "raw": "2", + "start": 147, + "type": "Literal", + "type": "Literal", + "value": { + "value": 2.0, + "suffix": "None" + } + }, + "start": 143, + "type": "BinaryExpression", + "type": "BinaryExpression" + }, + "start": 139, + "type": "BinaryExpression", + "type": "BinaryExpression" + }, + "start": 130, + "type": "VariableDeclarator" + }, + "end": 148, + "kind": "const", + "start": 130, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declaration": { + "end": 218, + "id": { + "end": 196, + "name": "sketch000", + "start": 187, + "type": "Identifier" + }, + "init": { + "arguments": [ + { + "end": 217, + "raw": "'XY'", + "start": 213, + "type": "Literal", + "type": "Literal", + "value": "XY" + } + ], + "callee": { + "end": 212, + "name": "startSketchOn", + "start": 199, + "type": "Identifier" + }, + "end": 218, + "start": 199, + "type": "CallExpression", + "type": "CallExpression" + }, + "start": 187, + "type": "VariableDeclarator" + }, + "end": 218, + "kind": "const", + "start": 187, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declaration": { + "end": 365, + "id": { + "end": 279, + "name": "outerProfile", + "start": 267, + "type": "Identifier" + }, + "init": { + "arguments": [ + { + "end": 344, + "properties": [ + { + "end": 312, + "key": { + "end": 299, + "name": "center", + "start": 293, + "type": "Identifier" + }, + "start": 293, + "type": "ObjectProperty", + "value": { + "elements": [ + { + "end": 306, + "raw": "0.0", + "start": 303, + "type": "Literal", + "type": "Literal", + "value": { + "value": 0.0, + "suffix": "None" + } + }, + { + "end": 311, + "raw": "0.0", + "start": 308, + "type": "Literal", + "type": "Literal", + "value": { + "value": 0.0, + "suffix": "None" + } + } + ], + "end": 312, + "start": 302, + "type": "ArrayExpression", + "type": "ArrayExpression" + } + }, + { + "end": 342, + "key": { + "end": 322, + "name": "radius", + "start": 316, + "type": "Identifier" + }, + "start": 316, + "type": "ObjectProperty", + "value": { + "end": 342, + "left": { + "end": 338, + "name": "outerDiameter", + "start": 325, + "type": "Identifier", + "type": "Identifier" + }, + "operator": "/", + "right": { + "end": 342, + "raw": "2", + "start": 341, + "type": "Literal", + "type": "Literal", + "value": { + "value": 2.0, + "suffix": "None" + } + }, + "start": 325, + "type": "BinaryExpression", + "type": "BinaryExpression" + } + } + ], + "start": 289, + "type": "ObjectExpression", + "type": "ObjectExpression" + }, + { + "end": 355, + "name": "sketch000", + "start": 346, + "type": "Identifier", + "type": "Identifier" + }, + { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "type": "TagDeclarator", + "value": "arc000" + } + ], + "callee": { + "end": 288, + "name": "circle", + "start": 282, + "type": "Identifier" + }, + "end": 365, + "start": 282, + "type": "CallExpression", + "type": "CallExpression" + }, + "start": 267, + "type": "VariableDeclarator" + }, + "end": 365, + "kind": "const", + "start": 267, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declaration": { + "end": 511, + "id": { + "end": 425, + "name": "innerProfile", + "start": 413, + "type": "Identifier" + }, + "init": { + "arguments": [ + { + "end": 490, + "properties": [ + { + "end": 458, + "key": { + "end": 445, + "name": "center", + "start": 439, + "type": "Identifier" + }, + "start": 439, + "type": "ObjectProperty", + "value": { + "elements": [ + { + "end": 452, + "raw": "0.0", + "start": 449, + "type": "Literal", + "type": "Literal", + "value": { + "value": 0.0, + "suffix": "None" + } + }, + { + "end": 457, + "raw": "0.0", + "start": 454, + "type": "Literal", + "type": "Literal", + "value": { + "value": 0.0, + "suffix": "None" + } + } + ], + "end": 458, + "start": 448, + "type": "ArrayExpression", + "type": "ArrayExpression" + } + }, + { + "end": 488, + "key": { + "end": 468, + "name": "radius", + "start": 462, + "type": "Identifier" + }, + "start": 462, + "type": "ObjectProperty", + "value": { + "end": 488, + "left": { + "end": 484, + "name": "innerDiameter", + "start": 471, + "type": "Identifier", + "type": "Identifier" + }, + "operator": "/", + "right": { + "end": 488, + "raw": "2", + "start": 487, + "type": "Literal", + "type": "Literal", + "value": { + "value": 2.0, + "suffix": "None" + } + }, + "start": 471, + "type": "BinaryExpression", + "type": "BinaryExpression" + } + } + ], + "start": 435, + "type": "ObjectExpression", + "type": "ObjectExpression" + }, + { + "end": 501, + "name": "sketch000", + "start": 492, + "type": "Identifier", + "type": "Identifier" + }, + { + "end": 510, + "start": 503, + "type": "TagDeclarator", + "type": "TagDeclarator", + "value": "arc001" + } + ], + "callee": { + "end": 434, + "name": "circle", + "start": 428, + "type": "Identifier" + }, + "end": 511, + "start": 428, + "type": "CallExpression", + "type": "CallExpression" + }, + "start": 413, + "type": "VariableDeclarator" + }, + "end": 511, + "kind": "const", + "start": 413, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declaration": { + "end": 670, + "id": { + "end": 580, + "name": "pipeProfile", + "start": 569, + "type": "Identifier" + }, + "init": { + "body": [ + { + "end": 595, + "name": "outerProfile", + "start": 583, + "type": "Identifier", + "type": "Identifier" + }, + { + "arguments": [ + { + "end": 618, + "name": "innerProfile", + "start": 606, + "type": "Identifier", + "type": "Identifier" + }, + { + "end": 621, + "start": 620, + "type": "PipeSubstitution", + "type": "PipeSubstitution" + } + ], + "callee": { + "end": 605, + "name": "hole", + "start": 601, + "type": "Identifier" + }, + "end": 622, + "start": 601, + "type": "CallExpression", + "type": "CallExpression" + } + ], + "end": 670, + "nonCodeMeta": { + "nonCodeNodes": { + "1": [ + { + "end": 670, + "start": 622, + "type": "NonCodeNode", + "value": { + "type": "newLineBlockComment", + "value": "extrude the pipe profile to create the pipe", + "style": "line" + } + } + ] + }, + "startNodes": [] + }, + "start": 583, + "type": "PipeExpression", + "type": "PipeExpression" + }, + "start": 569, + "type": "VariableDeclarator" + }, + "end": 670, + "kind": "const", + "start": 569, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declaration": { + "end": 715, + "id": { + "end": 675, + "name": "pipe", + "start": 671, + "type": "Identifier" + }, + "init": { + "arguments": [ + { + "type": "LabeledArg", + "label": { + "type": "Identifier", + "name": "length" + }, + "arg": { + "end": 714, + "name": "length", + "start": 708, + "type": "Identifier", + "type": "Identifier" + } + } + ], + "callee": { + "end": 685, + "name": "extrude", + "start": 678, + "type": "Identifier" + }, + "end": 715, + "start": 678, + "type": "CallExpressionKw", + "type": "CallExpressionKw", + "unlabeled": { + "end": 697, + "name": "pipeProfile", + "start": 686, + "type": "Identifier", + "type": "Identifier" + } + }, + "start": 671, + "type": "VariableDeclarator" + }, + "end": 715, + "kind": "const", + "start": 671, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 716, + "innerAttrs": [ + { + "end": 33, + "name": { + "end": 9, + "name": "settings", + "start": 1, + "type": "Identifier" + }, + "properties": [ + { + "end": 32, + "key": { + "end": 27, + "name": "defaultLengthUnit", + "start": 10, + "type": "Identifier" + }, + "start": 10, + "type": "ObjectProperty", + "value": { + "end": 32, + "name": "in", + "start": 30, + "type": "Identifier", + "type": "Identifier" + } + } + ], + "start": 0, + "type": "Annotation" + } + ], + "nonCodeMeta": { + "nonCodeNodes": { + "2": [ + { + "end": 186, + "start": 148, + "type": "NonCodeNode", + "value": { + "type": "newLineBlockComment", + "value": "create a sketch on the 'XY' plane", + "style": "line" + } + } + ], + "3": [ + { + "end": 266, + "start": 218, + "type": "NonCodeNode", + "value": { + "type": "newLineBlockComment", + "value": "create a profile of the outside of the pipe", + "style": "line" + } + } + ], + "4": [ + { + "end": 412, + "start": 365, + "type": "NonCodeNode", + "value": { + "type": "newLineBlockComment", + "value": "create a profile of the inside of the pipe", + "style": "line" + } + } + ], + "5": [ + { + "end": 568, + "start": 511, + "type": "NonCodeNode", + "value": { + "type": "newLineBlockComment", + "value": "create a profile with holes sketch000Profile000Holes", + "style": "line" + } + } + ] + }, + "startNodes": [ + { + "end": 61, + "start": 34, + "type": "NonCodeNode", + "value": { + "type": "blockComment", + "value": "Set units in inches (in)", + "style": "line" + } + }, + { + "end": 64, + "start": 61, + "type": "NonCodeNode", + "value": { + "type": "newLine" + } + }, + { + "end": 83, + "start": 64, + "type": "NonCodeNode", + "value": { + "type": "blockComment", + "value": "Define constants", + "style": "line" + } + } + ] + }, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/flush_batch_on_end/input.kcl b/src/wasm-lib/kcl/tests/flush_batch_on_end/input.kcl new file mode 100644 index 0000000000..b7b99f6dd1 --- /dev/null +++ b/src/wasm-lib/kcl/tests/flush_batch_on_end/input.kcl @@ -0,0 +1,30 @@ +@settings(defaultLengthUnit = in) +// Set units in inches (in) + + +// Define constants +innerDiameter = 0.364 +outerDiameter = 35 / 64 +length = 1 + 1 / 2 + +// create a sketch on the 'XY' plane +sketch000 = startSketchOn('XY') + +// create a profile of the outside of the pipe +outerProfile = circle({ + center = [0.0, 0.0], + radius = outerDiameter / 2 +}, sketch000, $arc000) + +// create a profile of the inside of the pipe +innerProfile = circle({ + center = [0.0, 0.0], + radius = innerDiameter / 2 +}, sketch000, $arc001) + +// create a profile with holes sketch000Profile000Holes +pipeProfile = outerProfile + |> hole(innerProfile, %) + +// extrude the pipe profile to create the pipe +pipe = extrude(pipeProfile, length = length) diff --git a/src/wasm-lib/kcl/tests/flush_batch_on_end/ops.snap b/src/wasm-lib/kcl/tests/flush_batch_on_end/ops.snap new file mode 100644 index 0000000000..75d0d80054 --- /dev/null +++ b/src/wasm-lib/kcl/tests/flush_batch_on_end/ops.snap @@ -0,0 +1,105 @@ +--- +source: kcl/src/simulation_tests.rs +description: Operations executed flush_batch_on_end.kcl +--- +[ + { + "labeledArgs": { + "data": { + "value": { + "type": "String", + "value": "XY" + }, + "sourceRange": [ + 213, + 217, + 0 + ] + } + }, + "name": "startSketchOn", + "sourceRange": [ + 199, + 218, + 0 + ], + "type": "StdLibCall", + "unlabeledArg": null + }, + { + "labeledArgs": { + "holeSketch": { + "value": { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + "sourceRange": [ + 606, + 618, + 0 + ] + }, + "sketch": { + "value": { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + "sourceRange": [ + 620, + 621, + 0 + ] + } + }, + "name": "hole", + "sourceRange": [ + 601, + 622, + 0 + ], + "type": "StdLibCall", + "unlabeledArg": null + }, + { + "labeledArgs": { + "length": { + "value": { + "type": "Number", + "value": 1.5, + "ty": { + "type": "Unknown" + } + }, + "sourceRange": [ + 708, + 714, + 0 + ] + } + }, + "name": "extrude", + "sourceRange": [ + 678, + 715, + 0 + ], + "type": "StdLibCall", + "unlabeledArg": { + "value": { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + "sourceRange": [ + 686, + 697, + 0 + ] + } + } +] diff --git a/src/wasm-lib/kcl/tests/flush_batch_on_end/program_memory.snap b/src/wasm-lib/kcl/tests/flush_batch_on_end/program_memory.snap new file mode 100644 index 0000000000..4bd2b0bbfd --- /dev/null +++ b/src/wasm-lib/kcl/tests/flush_batch_on_end/program_memory.snap @@ -0,0 +1,975 @@ +--- +source: kcl/src/simulation_tests.rs +description: Variables in memory after executing flush_batch_on_end.kcl +--- +{ + "arc000": { + "type": "TagIdentifier", + "type": "TagIdentifier", + "value": "arc000", + "info": { + "type": "TagEngineInfo", + "id": "[uuid]", + "sketch": "[uuid]", + "path": { + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ] + }, + "ccw": true, + "center": [ + 0.0, + 0.0 + ], + "from": [ + 0.2734375, + 0.0 + ], + "radius": 0.2734375, + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "to": [ + 0.2734375, + 0.0 + ], + "type": "Circle", + "units": { + "type": "Inches" + } + }, + "surface": { + "faceId": "[uuid]", + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ], + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "type": "extrudeArc" + } + }, + "__meta": [ + { + "sourceRange": [ + 357, + 364, + 0 + ] + } + ] + }, + "arc001": { + "type": "TagIdentifier", + "type": "TagIdentifier", + "value": "arc001", + "info": { + "type": "TagEngineInfo", + "id": "[uuid]", + "sketch": "[uuid]", + "path": { + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 428, + 511, + 0 + ] + }, + "ccw": true, + "center": [ + 0.0, + 0.0 + ], + "from": [ + 0.182, + 0.0 + ], + "radius": 0.182, + "tag": { + "end": 510, + "start": 503, + "type": "TagDeclarator", + "value": "arc001" + }, + "to": [ + 0.182, + 0.0 + ], + "type": "Circle", + "units": { + "type": "Inches" + } + }, + "surface": null + }, + "__meta": [ + { + "sourceRange": [ + 503, + 510, + 0 + ] + } + ] + }, + "innerDiameter": { + "type": "Number", + "value": 0.364, + "ty": { + "type": "Default", + "len": { + "type": "Inches" + }, + "angle": { + "type": "Degrees" + } + }, + "__meta": [ + { + "sourceRange": [ + 100, + 105, + 0 + ] + } + ] + }, + "innerProfile": { + "type": "Sketch", + "value": { + "type": "Sketch", + "id": "[uuid]", + "paths": [ + { + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 428, + 511, + 0 + ] + }, + "ccw": true, + "center": [ + 0.0, + 0.0 + ], + "from": [ + 0.182, + 0.0 + ], + "radius": 0.182, + "tag": { + "end": 510, + "start": 503, + "type": "TagDeclarator", + "value": "arc001" + }, + "to": [ + 0.182, + 0.0 + ], + "type": "Circle", + "units": { + "type": "Inches" + } + } + ], + "on": { + "type": "plane", + "id": "[uuid]", + "artifactId": "[uuid]", + "value": "XY", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "xAxis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "yAxis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "zAxis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "units": { + "type": "Inches" + }, + "__meta": [] + }, + "start": { + "from": [ + 0.182, + 0.0 + ], + "to": [ + 0.182, + 0.0 + ], + "units": { + "type": "Inches" + }, + "tag": null, + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 428, + 511, + 0 + ] + } + }, + "tags": { + "arc001": { + "type": "TagIdentifier", + "value": "arc001", + "info": { + "type": "TagEngineInfo", + "id": "[uuid]", + "sketch": "[uuid]", + "path": { + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 428, + 511, + 0 + ] + }, + "ccw": true, + "center": [ + 0.0, + 0.0 + ], + "from": [ + 0.182, + 0.0 + ], + "radius": 0.182, + "tag": { + "end": 510, + "start": 503, + "type": "TagDeclarator", + "value": "arc001" + }, + "to": [ + 0.182, + 0.0 + ], + "type": "Circle", + "units": { + "type": "Inches" + } + }, + "surface": null + }, + "__meta": [ + { + "sourceRange": [ + 503, + 510, + 0 + ] + } + ] + } + }, + "artifactId": "[uuid]", + "originalId": "[uuid]", + "units": { + "type": "Inches" + }, + "__meta": [ + { + "sourceRange": [ + 428, + 511, + 0 + ] + } + ] + } + }, + "length": { + "type": "Number", + "value": 1.5, + "ty": { + "type": "Unknown" + }, + "__meta": [ + { + "sourceRange": [ + 139, + 140, + 0 + ] + }, + { + "sourceRange": [ + 143, + 144, + 0 + ] + }, + { + "sourceRange": [ + 147, + 148, + 0 + ] + } + ] + }, + "outerDiameter": { + "type": "Number", + "value": 0.546875, + "ty": { + "type": "Unknown" + }, + "__meta": [ + { + "sourceRange": [ + 122, + 124, + 0 + ] + }, + { + "sourceRange": [ + 127, + 129, + 0 + ] + } + ] + }, + "outerProfile": { + "type": "Sketch", + "value": { + "type": "Sketch", + "id": "[uuid]", + "paths": [ + { + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ] + }, + "ccw": true, + "center": [ + 0.0, + 0.0 + ], + "from": [ + 0.2734, + 0.0 + ], + "radius": 0.2734375, + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "to": [ + 0.2734, + 0.0 + ], + "type": "Circle", + "units": { + "type": "Inches" + } + } + ], + "on": { + "type": "plane", + "id": "[uuid]", + "artifactId": "[uuid]", + "value": "XY", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "xAxis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "yAxis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "zAxis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "units": { + "type": "Inches" + }, + "__meta": [] + }, + "start": { + "from": [ + 0.2734375, + 0.0 + ], + "to": [ + 0.2734375, + 0.0 + ], + "units": { + "type": "Inches" + }, + "tag": null, + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ] + } + }, + "tags": { + "arc000": { + "type": "TagIdentifier", + "value": "arc000", + "info": { + "type": "TagEngineInfo", + "id": "[uuid]", + "sketch": "[uuid]", + "path": { + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ] + }, + "ccw": true, + "center": [ + 0.0, + 0.0 + ], + "from": [ + 0.2734375, + 0.0 + ], + "radius": 0.2734375, + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "to": [ + 0.2734375, + 0.0 + ], + "type": "Circle", + "units": { + "type": "Inches" + } + }, + "surface": { + "faceId": "[uuid]", + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ], + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "type": "extrudeArc" + } + }, + "__meta": [ + { + "sourceRange": [ + 357, + 364, + 0 + ] + } + ] + } + }, + "artifactId": "[uuid]", + "originalId": "[uuid]", + "units": { + "type": "Inches" + }, + "__meta": [ + { + "sourceRange": [ + 282, + 365, + 0 + ] + } + ] + } + }, + "pipe": { + "type": "Solid", + "value": { + "type": "Solid", + "id": "[uuid]", + "artifactId": "[uuid]", + "value": [ + { + "faceId": "[uuid]", + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ], + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "type": "extrudeArc" + } + ], + "sketch": { + "type": "Sketch", + "id": "[uuid]", + "paths": [ + { + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ] + }, + "ccw": true, + "center": [ + 0.0, + 0.0 + ], + "from": [ + 0.2734, + 0.0 + ], + "radius": 0.2734375, + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "to": [ + 0.2734, + 0.0 + ], + "type": "Circle", + "units": { + "type": "Inches" + } + } + ], + "on": { + "type": "plane", + "id": "[uuid]", + "artifactId": "[uuid]", + "value": "XY", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "xAxis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "yAxis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "zAxis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "units": { + "type": "Inches" + }, + "__meta": [] + }, + "start": { + "from": [ + 0.2734375, + 0.0 + ], + "to": [ + 0.2734375, + 0.0 + ], + "units": { + "type": "Inches" + }, + "tag": null, + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ] + } + }, + "tags": { + "arc000": { + "type": "TagIdentifier", + "value": "arc000", + "info": { + "type": "TagEngineInfo", + "id": "[uuid]", + "sketch": "[uuid]", + "path": { + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ] + }, + "ccw": true, + "center": [ + 0.0, + 0.0 + ], + "from": [ + 0.2734375, + 0.0 + ], + "radius": 0.2734375, + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "to": [ + 0.2734375, + 0.0 + ], + "type": "Circle", + "units": { + "type": "Inches" + } + }, + "surface": { + "faceId": "[uuid]", + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ], + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "type": "extrudeArc" + } + }, + "__meta": [ + { + "sourceRange": [ + 357, + 364, + 0 + ] + } + ] + } + }, + "artifactId": "[uuid]", + "originalId": "[uuid]", + "units": { + "type": "Inches" + }, + "__meta": [ + { + "sourceRange": [ + 282, + 365, + 0 + ] + } + ] + }, + "height": 1.5, + "startCapId": "[uuid]", + "endCapId": "[uuid]", + "units": { + "type": "Inches" + }, + "__meta": [ + { + "sourceRange": [ + 282, + 365, + 0 + ] + } + ] + } + }, + "pipeProfile": { + "type": "Sketch", + "value": { + "type": "Sketch", + "id": "[uuid]", + "paths": [ + { + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ] + }, + "ccw": true, + "center": [ + 0.0, + 0.0 + ], + "from": [ + 0.2734, + 0.0 + ], + "radius": 0.2734375, + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "to": [ + 0.2734, + 0.0 + ], + "type": "Circle", + "units": { + "type": "Inches" + } + } + ], + "on": { + "type": "plane", + "id": "[uuid]", + "artifactId": "[uuid]", + "value": "XY", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "xAxis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "yAxis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "zAxis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "units": { + "type": "Inches" + }, + "__meta": [] + }, + "start": { + "from": [ + 0.2734375, + 0.0 + ], + "to": [ + 0.2734375, + 0.0 + ], + "units": { + "type": "Inches" + }, + "tag": null, + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ] + } + }, + "tags": { + "arc000": { + "type": "TagIdentifier", + "value": "arc000", + "info": { + "type": "TagEngineInfo", + "id": "[uuid]", + "sketch": "[uuid]", + "path": { + "__geoMeta": { + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ] + }, + "ccw": true, + "center": [ + 0.0, + 0.0 + ], + "from": [ + 0.2734375, + 0.0 + ], + "radius": 0.2734375, + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "to": [ + 0.2734375, + 0.0 + ], + "type": "Circle", + "units": { + "type": "Inches" + } + }, + "surface": { + "faceId": "[uuid]", + "id": "[uuid]", + "sourceRange": [ + 282, + 365, + 0 + ], + "tag": { + "end": 364, + "start": 357, + "type": "TagDeclarator", + "value": "arc000" + }, + "type": "extrudeArc" + } + }, + "__meta": [ + { + "sourceRange": [ + 357, + 364, + 0 + ] + } + ] + } + }, + "artifactId": "[uuid]", + "originalId": "[uuid]", + "units": { + "type": "Inches" + }, + "__meta": [ + { + "sourceRange": [ + 282, + 365, + 0 + ] + } + ] + } + }, + "sketch000": { + "type": "Plane", + "value": { + "id": "[uuid]", + "artifactId": "[uuid]", + "value": "XY", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "xAxis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "yAxis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "zAxis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "units": { + "type": "Inches" + }, + "__meta": [] + } + } +} diff --git a/src/wasm-lib/kcl/tests/flush_batch_on_end/rendered_model.png b/src/wasm-lib/kcl/tests/flush_batch_on_end/rendered_model.png new file mode 100644 index 0000000000..79054e0ff7 Binary files /dev/null and b/src/wasm-lib/kcl/tests/flush_batch_on_end/rendered_model.png differ diff --git a/src/wasm-lib/kcl/tests/import_function_not_sketch/artifact_commands.snap b/src/wasm-lib/kcl/tests/import_function_not_sketch/artifact_commands.snap index 78670164cd..30b0bf8387 100644 --- a/src/wasm-lib/kcl/tests/import_function_not_sketch/artifact_commands.snap +++ b/src/wasm-lib/kcl/tests/import_function_not_sketch/artifact_commands.snap @@ -292,5 +292,17 @@ description: Artifact commands import_function_not_sketch.kcl "type": "set_scene_units", "unit": "in" } + }, + { + "cmdId": "[uuid]", + "range": [ + 0, + 0, + 0 + ], + "command": { + "type": "set_scene_units", + "unit": "mm" + } } ] diff --git a/src/wasm-lib/kcl/tests/outputs/serial_test_example_revolve6.png b/src/wasm-lib/kcl/tests/outputs/serial_test_example_revolve6.png index 9b5509c921..e69de29bb2 100644 Binary files a/src/wasm-lib/kcl/tests/outputs/serial_test_example_revolve6.png and b/src/wasm-lib/kcl/tests/outputs/serial_test_example_revolve6.png differ diff --git a/src/wasm-lib/kcl/tests/outputs/serial_test_example_revolve7.png b/src/wasm-lib/kcl/tests/outputs/serial_test_example_revolve7.png index 2330dd4a8c..e69de29bb2 100644 Binary files a/src/wasm-lib/kcl/tests/outputs/serial_test_example_revolve7.png and b/src/wasm-lib/kcl/tests/outputs/serial_test_example_revolve7.png differ