fix sketch on face of union (#6949)
* fix sketch on face of union Signed-off-by: Jess Frazelle <github@jessfraz.com> * rotate the model Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -3092,3 +3092,24 @@ mod error_revolve_on_edge_get_edge {
|
||||
super::execute(TEST_NAME, true).await
|
||||
}
|
||||
}
|
||||
mod sketch_on_face_union {
|
||||
const TEST_NAME: &str = "sketch_on_face_union";
|
||||
|
||||
/// Test parsing KCL.
|
||||
#[test]
|
||||
fn parse() {
|
||||
super::parse(TEST_NAME)
|
||||
}
|
||||
|
||||
/// Test that parsing and unparsing KCL produces the original KCL input.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn unparse() {
|
||||
super::unparse(TEST_NAME).await
|
||||
}
|
||||
|
||||
/// Test that KCL is executed correctly.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn kcl_test_execute() {
|
||||
super::execute(TEST_NAME, true).await
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use super::{args::TyF64, DEFAULT_TOLERANCE};
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
execution::{types::RuntimeType, ExecState, KclValue, Solid},
|
||||
std::Args,
|
||||
std::{patterns::GeometryTrait, Args},
|
||||
};
|
||||
|
||||
/// Union two or more solids into a single solid.
|
||||
@ -123,7 +123,7 @@ pub(crate) async fn inner_union(
|
||||
let solid_out_id = exec_state.next_uuid();
|
||||
|
||||
let mut solid = solids[0].clone();
|
||||
solid.id = solid_out_id;
|
||||
solid.set_id(solid_out_id);
|
||||
let mut new_solids = vec![solid.clone()];
|
||||
|
||||
if args.ctx.no_engine_commands().await {
|
||||
@ -155,7 +155,7 @@ pub(crate) async fn inner_union(
|
||||
|
||||
// If we have more solids, set those as well.
|
||||
if !extra_solid_ids.is_empty() {
|
||||
solid.id = extra_solid_ids[0];
|
||||
solid.set_id(extra_solid_ids[0]);
|
||||
new_solids.push(solid.clone());
|
||||
}
|
||||
|
||||
@ -249,7 +249,7 @@ pub(crate) async fn inner_intersect(
|
||||
let solid_out_id = exec_state.next_uuid();
|
||||
|
||||
let mut solid = solids[0].clone();
|
||||
solid.id = solid_out_id;
|
||||
solid.set_id(solid_out_id);
|
||||
let mut new_solids = vec![solid.clone()];
|
||||
|
||||
if args.ctx.no_engine_commands().await {
|
||||
@ -281,7 +281,7 @@ pub(crate) async fn inner_intersect(
|
||||
|
||||
// If we have more solids, set those as well.
|
||||
if !extra_solid_ids.is_empty() {
|
||||
solid.id = extra_solid_ids[0];
|
||||
solid.set_id(extra_solid_ids[0]);
|
||||
new_solids.push(solid.clone());
|
||||
}
|
||||
|
||||
@ -385,7 +385,7 @@ pub(crate) async fn inner_subtract(
|
||||
let solid_out_id = exec_state.next_uuid();
|
||||
|
||||
let mut solid = solids[0].clone();
|
||||
solid.id = solid_out_id;
|
||||
solid.set_id(solid_out_id);
|
||||
let mut new_solids = vec![solid.clone()];
|
||||
|
||||
if args.ctx.no_engine_commands().await {
|
||||
@ -419,7 +419,7 @@ pub(crate) async fn inner_subtract(
|
||||
|
||||
// If we have more solids, set those as well.
|
||||
if !extra_solid_ids.is_empty() {
|
||||
solid.id = extra_solid_ids[0];
|
||||
solid.set_id(extra_solid_ids[0]);
|
||||
new_solids.push(solid.clone());
|
||||
}
|
||||
|
||||
|
@ -598,7 +598,7 @@ fn array_to_point2d(
|
||||
.map(|val| val.as_point2d().unwrap())
|
||||
}
|
||||
|
||||
trait GeometryTrait: Clone {
|
||||
pub trait GeometryTrait: Clone {
|
||||
type Set: Into<Vec<Self>> + Clone;
|
||||
fn id(&self) -> Uuid;
|
||||
fn original_id(&self) -> Uuid;
|
||||
@ -608,6 +608,7 @@ trait GeometryTrait: Clone {
|
||||
source_ranges: Vec<SourceRange>,
|
||||
exec_state: &mut ExecState,
|
||||
) -> Result<[TyF64; 3], KclError>;
|
||||
#[allow(async_fn_in_trait)]
|
||||
async fn flush_batch(args: &Args, exec_state: &mut ExecState, set: &Self::Set) -> Result<(), KclError>;
|
||||
}
|
||||
|
||||
@ -641,6 +642,8 @@ impl GeometryTrait for Solid {
|
||||
type Set = Vec<Solid>;
|
||||
fn set_id(&mut self, id: Uuid) {
|
||||
self.id = id;
|
||||
// We need this for in extrude.rs when you sketch on face.
|
||||
self.sketch.id = id;
|
||||
}
|
||||
|
||||
fn id(&self) -> Uuid {
|
||||
|
1060
rust/kcl-lib/tests/sketch_on_face_union/artifact_commands.snap
Normal file
1060
rust/kcl-lib/tests/sketch_on_face_union/artifact_commands.snap
Normal file
File diff suppressed because it is too large
Load Diff
3671
rust/kcl-lib/tests/sketch_on_face_union/ast.snap
Normal file
3671
rust/kcl-lib/tests/sketch_on_face_union/ast.snap
Normal file
File diff suppressed because it is too large
Load Diff
58
rust/kcl-lib/tests/sketch_on_face_union/input.kcl
Normal file
58
rust/kcl-lib/tests/sketch_on_face_union/input.kcl
Normal file
@ -0,0 +1,58 @@
|
||||
@settings(defaultLengthUnit = in)
|
||||
|
||||
// Define parameters
|
||||
trussSupportAngle = 15
|
||||
height = 120
|
||||
thickness = 4
|
||||
|
||||
sketch001 = startSketchOn(YZ)
|
||||
profile001 = startProfile(sketch001, at = [60, 0])
|
||||
|> xLine(length = -120, tag = $bottomFace)
|
||||
|> yLine(length = 12)
|
||||
|> angledLine(angle = 25, endAbsoluteX = 0, tag = $tag001)
|
||||
|> angledLine(angle = -25, endAbsoluteX = 60)
|
||||
|> close()
|
||||
|
||||
profile002 = startProfile(sketch001, at = [60-thickness, thickness])
|
||||
|> xLine(endAbsolute = thickness/2)
|
||||
|> yLine(endAbsolute = segEndY(tag001)-thickness) // update
|
||||
|> angledLine(endAbsoluteX = profileStartX(%), angle = -25)
|
||||
|> close(%)
|
||||
|
||||
profile003 = startProfile(sketch001, at = [-60+thickness, thickness])
|
||||
|> xLine(endAbsolute = -thickness/2)
|
||||
|> yLine(endAbsolute = segEndY(tag001)-thickness) // update
|
||||
|> angledLine(endAbsoluteX = profileStartX(%), angle = 205)
|
||||
|> close(%)
|
||||
|
||||
profile004 = subtract2d(profile001, tool = profile002)
|
||||
subtract2d(profile001, tool = profile003)
|
||||
|
||||
body001 = extrude(profile001, length = 2)
|
||||
|
||||
sketch002 = startSketchOn(offsetPlane(YZ, offset = .1))
|
||||
profile006 = startProfile(sketch002, at = [thickness/2-1, 14])
|
||||
|> angledLine(angle = 30, length = 25)
|
||||
|> angledLine(angle = -25, length = 5)
|
||||
|> angledLine(angle = 210, endAbsoluteX = profileStartX(%))
|
||||
|> close(%)
|
||||
|> extrude(%, length = 1.8)
|
||||
|
||||
profile007 = startProfile(sketch002, at = [-thickness/2+1, 14])
|
||||
|> angledLine(angle = 150, length = 25)
|
||||
|> angledLine(angle = 205, length = 5)
|
||||
|> angledLine(angle = -30, endAbsoluteX = profileStartX(%))
|
||||
|> close(%)
|
||||
|> extrude(%, length = 1.8)
|
||||
|
||||
newSketch = body001 + profile006 + profile007
|
||||
|
||||
leg001Sketch = startSketchOn(newSketch, face = bottomFace)
|
||||
legProfile001 = startProfile(leg001Sketch, at = [-60, 0])
|
||||
|> xLine(%, length = 4)
|
||||
|> yLine(%, length = 2)
|
||||
|> xLine(%, endAbsolute = profileStartX(%))
|
||||
|> close(%)
|
||||
|
||||
leg001 = extrude(legProfile001, length = 48)
|
||||
|> rotate(axis = [0, 0, 1.0], angle = -90)
|
264
rust/kcl-lib/tests/sketch_on_face_union/ops.snap
Normal file
264
rust/kcl-lib/tests/sketch_on_face_union/ops.snap
Normal file
@ -0,0 +1,264 @@
|
||||
---
|
||||
source: kcl-lib/src/simulation_tests.rs
|
||||
description: Operations executed sketch_on_face_union.kcl
|
||||
---
|
||||
[
|
||||
{
|
||||
"labeledArgs": {},
|
||||
"name": "startSketchOn",
|
||||
"sourceRange": [],
|
||||
"type": "StdLibCall",
|
||||
"unlabeledArg": {
|
||||
"value": {
|
||||
"type": "Plane",
|
||||
"artifact_id": "[uuid]"
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"labeledArgs": {
|
||||
"tool": {
|
||||
"value": {
|
||||
"type": "Sketch",
|
||||
"value": {
|
||||
"artifactId": "[uuid]"
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
"name": "subtract2d",
|
||||
"sourceRange": [],
|
||||
"type": "StdLibCall",
|
||||
"unlabeledArg": {
|
||||
"value": {
|
||||
"type": "Sketch",
|
||||
"value": {
|
||||
"artifactId": "[uuid]"
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"labeledArgs": {
|
||||
"tool": {
|
||||
"value": {
|
||||
"type": "Sketch",
|
||||
"value": {
|
||||
"artifactId": "[uuid]"
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
"name": "subtract2d",
|
||||
"sourceRange": [],
|
||||
"type": "StdLibCall",
|
||||
"unlabeledArg": {
|
||||
"value": {
|
||||
"type": "Sketch",
|
||||
"value": {
|
||||
"artifactId": "[uuid]"
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"labeledArgs": {
|
||||
"length": {
|
||||
"value": {
|
||||
"type": "Number",
|
||||
"value": 2.0,
|
||||
"ty": {
|
||||
"type": "Default",
|
||||
"len": {
|
||||
"type": "Inches"
|
||||
},
|
||||
"angle": {
|
||||
"type": "Degrees"
|
||||
}
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
"name": "extrude",
|
||||
"sourceRange": [],
|
||||
"type": "StdLibCall",
|
||||
"unlabeledArg": {
|
||||
"value": {
|
||||
"type": "Sketch",
|
||||
"value": {
|
||||
"artifactId": "[uuid]"
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"labeledArgs": {},
|
||||
"name": "startSketchOn",
|
||||
"sourceRange": [],
|
||||
"type": "StdLibCall",
|
||||
"unlabeledArg": {
|
||||
"value": {
|
||||
"type": "Plane",
|
||||
"artifact_id": "[uuid]"
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "KclStdLibCall",
|
||||
"name": "offsetPlane",
|
||||
"unlabeledArg": {
|
||||
"value": {
|
||||
"type": "Plane",
|
||||
"artifact_id": "[uuid]"
|
||||
},
|
||||
"sourceRange": []
|
||||
},
|
||||
"labeledArgs": {
|
||||
"offset": {
|
||||
"value": {
|
||||
"type": "Number",
|
||||
"value": 0.1,
|
||||
"ty": {
|
||||
"type": "Default",
|
||||
"len": {
|
||||
"type": "Inches"
|
||||
},
|
||||
"angle": {
|
||||
"type": "Degrees"
|
||||
}
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
},
|
||||
{
|
||||
"labeledArgs": {
|
||||
"length": {
|
||||
"value": {
|
||||
"type": "Number",
|
||||
"value": 1.8,
|
||||
"ty": {
|
||||
"type": "Default",
|
||||
"len": {
|
||||
"type": "Inches"
|
||||
},
|
||||
"angle": {
|
||||
"type": "Degrees"
|
||||
}
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
"name": "extrude",
|
||||
"sourceRange": [],
|
||||
"type": "StdLibCall",
|
||||
"unlabeledArg": {
|
||||
"value": {
|
||||
"type": "Sketch",
|
||||
"value": {
|
||||
"artifactId": "[uuid]"
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"labeledArgs": {
|
||||
"length": {
|
||||
"value": {
|
||||
"type": "Number",
|
||||
"value": 1.8,
|
||||
"ty": {
|
||||
"type": "Default",
|
||||
"len": {
|
||||
"type": "Inches"
|
||||
},
|
||||
"angle": {
|
||||
"type": "Degrees"
|
||||
}
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
"name": "extrude",
|
||||
"sourceRange": [],
|
||||
"type": "StdLibCall",
|
||||
"unlabeledArg": {
|
||||
"value": {
|
||||
"type": "Sketch",
|
||||
"value": {
|
||||
"artifactId": "[uuid]"
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"labeledArgs": {
|
||||
"face": {
|
||||
"value": {
|
||||
"type": "TagIdentifier",
|
||||
"value": "bottomFace",
|
||||
"artifact_id": "[uuid]"
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
"name": "startSketchOn",
|
||||
"sourceRange": [],
|
||||
"type": "StdLibCall",
|
||||
"unlabeledArg": {
|
||||
"value": {
|
||||
"type": "Solid",
|
||||
"value": {
|
||||
"artifactId": "[uuid]"
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"labeledArgs": {
|
||||
"length": {
|
||||
"value": {
|
||||
"type": "Number",
|
||||
"value": 48.0,
|
||||
"ty": {
|
||||
"type": "Default",
|
||||
"len": {
|
||||
"type": "Inches"
|
||||
},
|
||||
"angle": {
|
||||
"type": "Degrees"
|
||||
}
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
},
|
||||
"name": "extrude",
|
||||
"sourceRange": [],
|
||||
"type": "StdLibCall",
|
||||
"unlabeledArg": {
|
||||
"value": {
|
||||
"type": "Sketch",
|
||||
"value": {
|
||||
"artifactId": "[uuid]"
|
||||
}
|
||||
},
|
||||
"sourceRange": []
|
||||
}
|
||||
}
|
||||
]
|
2639
rust/kcl-lib/tests/sketch_on_face_union/program_memory.snap
Normal file
2639
rust/kcl-lib/tests/sketch_on_face_union/program_memory.snap
Normal file
File diff suppressed because it is too large
Load Diff
BIN
rust/kcl-lib/tests/sketch_on_face_union/rendered_model.png
Normal file
BIN
rust/kcl-lib/tests/sketch_on_face_union/rendered_model.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 57 KiB |
62
rust/kcl-lib/tests/sketch_on_face_union/unparsed.snap
Normal file
62
rust/kcl-lib/tests/sketch_on_face_union/unparsed.snap
Normal file
@ -0,0 +1,62 @@
|
||||
---
|
||||
source: kcl-lib/src/simulation_tests.rs
|
||||
description: Result of unparsing sketch_on_face_union.kcl
|
||||
---
|
||||
@settings(defaultLengthUnit = in)
|
||||
|
||||
// Define parameters
|
||||
trussSupportAngle = 15
|
||||
height = 120
|
||||
thickness = 4
|
||||
|
||||
sketch001 = startSketchOn(YZ)
|
||||
profile001 = startProfile(sketch001, at = [60, 0])
|
||||
|> xLine(length = -120, tag = $bottomFace)
|
||||
|> yLine(length = 12)
|
||||
|> angledLine(angle = 25, endAbsoluteX = 0, tag = $tag001)
|
||||
|> angledLine(angle = -25, endAbsoluteX = 60)
|
||||
|> close()
|
||||
|
||||
profile002 = startProfile(sketch001, at = [60 - thickness, thickness])
|
||||
|> xLine(endAbsolute = thickness / 2)
|
||||
|> yLine(endAbsolute = segEndY(tag001) - thickness) // update
|
||||
|> angledLine(endAbsoluteX = profileStartX(%), angle = -25)
|
||||
|> close(%)
|
||||
|
||||
profile003 = startProfile(sketch001, at = [-60 + thickness, thickness])
|
||||
|> xLine(endAbsolute = -thickness / 2)
|
||||
|> yLine(endAbsolute = segEndY(tag001) - thickness) // update
|
||||
|> angledLine(endAbsoluteX = profileStartX(%), angle = 205)
|
||||
|> close(%)
|
||||
|
||||
profile004 = subtract2d(profile001, tool = profile002)
|
||||
subtract2d(profile001, tool = profile003)
|
||||
|
||||
body001 = extrude(profile001, length = 2)
|
||||
|
||||
sketch002 = startSketchOn(offsetPlane(YZ, offset = .1))
|
||||
profile006 = startProfile(sketch002, at = [thickness / 2 - 1, 14])
|
||||
|> angledLine(angle = 30, length = 25)
|
||||
|> angledLine(angle = -25, length = 5)
|
||||
|> angledLine(angle = 210, endAbsoluteX = profileStartX(%))
|
||||
|> close(%)
|
||||
|> extrude(%, length = 1.8)
|
||||
|
||||
profile007 = startProfile(sketch002, at = [-thickness / 2 + 1, 14])
|
||||
|> angledLine(angle = 150, length = 25)
|
||||
|> angledLine(angle = 205, length = 5)
|
||||
|> angledLine(angle = -30, endAbsoluteX = profileStartX(%))
|
||||
|> close(%)
|
||||
|> extrude(%, length = 1.8)
|
||||
|
||||
newSketch = body001 + profile006 + profile007
|
||||
|
||||
leg001Sketch = startSketchOn(newSketch, face = bottomFace)
|
||||
legProfile001 = startProfile(leg001Sketch, at = [-60, 0])
|
||||
|> xLine(%, length = 4)
|
||||
|> yLine(%, length = 2)
|
||||
|> xLine(%, endAbsolute = profileStartX(%))
|
||||
|> close(%)
|
||||
|
||||
leg001 = extrude(legProfile001, length = 48)
|
||||
|> rotate(axis = [0, 0, 1.0], angle = -90)
|
Reference in New Issue
Block a user