diff --git a/rust/kcl-lib/src/execution/geometry.rs b/rust/kcl-lib/src/execution/geometry.rs index 970c7f333c1..9aee0e6f6cb 100644 --- a/rust/kcl-lib/src/execution/geometry.rs +++ b/rust/kcl-lib/src/execution/geometry.rs @@ -770,7 +770,7 @@ impl GetTangentialInfoFromPathsResult { } impl Sketch { - pub(crate) fn add_tag(&mut self, tag: NodeRef<'_, TagDeclarator>, current_path: &Path, exec_state: &ExecState) { + pub(crate) fn add_tag(&mut self, tag: NodeRef<'_, TagDeclarator>, current_path: &Path, exec_state: &ExecState, surface: &Option) { let mut tag_identifier: TagIdentifier = tag.into(); let base = current_path.get_base(); tag_identifier.info.push(( @@ -779,7 +779,7 @@ impl Sketch { id: base.geo_meta.id, sketch: self.id, path: Some(current_path.clone()), - surface: None, + surface: surface.clone(), }, )); @@ -1640,6 +1640,24 @@ impl ExtrudeSurface { } } + pub fn get_face_id(&self) -> uuid::Uuid { + match self { + ExtrudeSurface::ExtrudePlane(ep) => ep.face_id, + ExtrudeSurface::ExtrudeArc(ea) => ea.face_id, + ExtrudeSurface::Fillet(f) => f.face_id, + ExtrudeSurface::Chamfer(c) => c.face_id, + } + } + + pub fn set_face_id(&mut self, face_id: uuid::Uuid) { + match self { + ExtrudeSurface::ExtrudePlane(ep) => ep.face_id = face_id, + ExtrudeSurface::ExtrudeArc(ea) => ea.face_id = face_id, + ExtrudeSurface::Fillet(f) => f.face_id = face_id, + ExtrudeSurface::Chamfer(c) => c.face_id = face_id, + } + } + pub fn get_tag(&self) -> Option> { match self { ExtrudeSurface::ExtrudePlane(ep) => ep.tag.clone(), diff --git a/rust/kcl-lib/src/std/clone.rs b/rust/kcl-lib/src/std/clone.rs index 43295b48b58..5009c7b5c66 100644 --- a/rust/kcl-lib/src/std/clone.rs +++ b/rust/kcl-lib/src/std/clone.rs @@ -14,11 +14,10 @@ use super::extrude::do_post_extrude; use crate::{ errors::{KclError, KclErrorDetails}, execution::{ - ExecState, GeometryWithImportedGeometry, KclValue, ModelingCmdMeta, Sketch, Solid, - types::{NumericType, PrimitiveType, RuntimeType}, + types::{NumericType, PrimitiveType, RuntimeType}, ExecState, ExtrudeSurface, GeometryWithImportedGeometry, KclValue, ModelingCmdMeta, Sketch, Solid }, parsing::ast::types::TagNode, - std::{Args, extrude::NamedCapTags}, + std::{extrude::NamedCapTags, Args}, }; /// Clone a sketch or solid. @@ -111,7 +110,7 @@ async fn fix_tags_and_references( match new_geometry { GeometryWithImportedGeometry::ImportedGeometry(_) => {} GeometryWithImportedGeometry::Sketch(sketch) => { - fix_sketch_tags_and_references(sketch, &entity_id_map, exec_state).await?; + fix_sketch_tags_and_references(sketch, &entity_id_map, exec_state, None).await?; } GeometryWithImportedGeometry::Solid(solid) => { // Make the sketch id the new geometry id. @@ -119,7 +118,7 @@ async fn fix_tags_and_references( solid.sketch.original_id = new_geometry_id; solid.sketch.artifact_id = new_geometry_id.into(); - fix_sketch_tags_and_references(&mut solid.sketch, &entity_id_map, exec_state).await?; + fix_sketch_tags_and_references(&mut solid.sketch, &entity_id_map, exec_state, Some(solid.value.clone())).await?; let (start_tag, end_tag) = get_named_cap_tags(solid); @@ -225,7 +224,7 @@ async fn get_old_new_child_map( async fn fix_sketch_tags_and_references( new_sketch: &mut Sketch, entity_id_map: &HashMap, - exec_state: &mut ExecState, + exec_state: &mut ExecState, surfaces: Option>, ) -> Result<()> { // Fix the path references in the sketch. for path in new_sketch.paths.as_mut_slice() { @@ -244,7 +243,15 @@ async fn fix_sketch_tags_and_references( for path in new_sketch.paths.clone() { // Check if this path has a tag. if let Some(tag) = path.get_tag() { - new_sketch.add_tag(&tag, &path, exec_state); + let mut surface: Option = None; + for (i, s) in surfaces.clone().unwrap_or(vec![]).iter().enumerate() { + if s.get_tag() == Some(tag.clone()) { + surface = Some(s.clone()); + surface.as_mut().unwrap().set_face_id(entity_id_map.get(&s.get_face_id()).copied().unwrap_or_default()); + } + } + + new_sketch.add_tag(&tag.clone(), &path, exec_state, &surface); } } diff --git a/rust/kcl-lib/src/std/shapes.rs b/rust/kcl-lib/src/std/shapes.rs index a0a8fbb4e3e..a42986546ab 100644 --- a/rust/kcl-lib/src/std/shapes.rs +++ b/rust/kcl-lib/src/std/shapes.rs @@ -230,7 +230,7 @@ async fn inner_circle( let mut new_sketch = sketch; new_sketch.is_closed = true; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -332,7 +332,7 @@ async fn inner_circle_three_point( let mut new_sketch = sketch; new_sketch.is_closed = true; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -617,7 +617,7 @@ async fn inner_ellipse( let mut new_sketch = sketch; new_sketch.is_closed = true; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); diff --git a/rust/kcl-lib/src/std/sketch.rs b/rust/kcl-lib/src/std/sketch.rs index a9b6a970255..9fba007afec 100644 --- a/rust/kcl-lib/src/std/sketch.rs +++ b/rust/kcl-lib/src/std/sketch.rs @@ -222,7 +222,7 @@ async fn inner_involute_circular( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); Ok(new_sketch) @@ -358,7 +358,7 @@ async fn straight_line( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -576,7 +576,7 @@ async fn inner_angled_line_length( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -1269,7 +1269,7 @@ pub(crate) async fn inner_close( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); new_sketch.is_closed = true; @@ -1395,7 +1395,7 @@ pub async fn absolute_arc( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -1461,7 +1461,7 @@ pub async fn relative_arc( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -1630,7 +1630,7 @@ async fn inner_tangential_arc_radius_angle( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -1719,7 +1719,7 @@ async fn inner_tangential_arc_to_point( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -1846,7 +1846,7 @@ async fn inner_bezier_curve( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -2076,7 +2076,7 @@ pub(crate) async fn inner_elliptic( }; let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -2247,7 +2247,7 @@ pub(crate) async fn inner_hyperbolic( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -2467,7 +2467,7 @@ pub(crate) async fn inner_parabolic( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); @@ -2628,7 +2628,7 @@ pub(crate) async fn inner_conic( let mut new_sketch = sketch; if let Some(tag) = &tag { - new_sketch.add_tag(tag, ¤t_path, exec_state); + new_sketch.add_tag(tag, ¤t_path, exec_state, &None); } new_sketch.paths.push(current_path); diff --git a/rust/kcl-lib/std/prelude.kcl b/rust/kcl-lib/std/prelude.kcl index 73d3ae882de..e7d0e9728d4 100644 --- a/rust/kcl-lib/std/prelude.kcl +++ b/rust/kcl-lib/std/prelude.kcl @@ -344,9 +344,11 @@ export fn offsetPlane( /// /// sketch002 = clone(sketch001) /// |> translate(x = 0, y = 0, z = 20) -/// |> fillet( +/// +/// fillet( +/// sketch002, /// radius = 2, -/// tags = [getNextAdjacentEdge(filletTag)], +/// tags = [getNextAdjacentEdge(sketch002.sketch.tags.filletTag)], /// ) /// ``` /// @@ -391,15 +393,17 @@ export fn offsetPlane( /// mountingPlate = extrude(mountingPlateSketch, length = thickness) /// /// clonedMountingPlate = clone(mountingPlate) -/// |> fillet( -/// radius = filletRadius, -/// tags = [ -/// getNextAdjacentEdge(edge1), -/// getNextAdjacentEdge(edge2), -/// getNextAdjacentEdge(edge3), -/// getNextAdjacentEdge(edge4) -/// ], -/// ) +/// +/// fillet( +/// clonedMountingPlate, +/// radius = filletRadius, +/// tags = [ +/// getNextAdjacentEdge(clonedMountingPlate.sketch.tags.edge1), +/// getNextAdjacentEdge(clonedMountingPlate.sketch.tags.edge2), +/// getNextAdjacentEdge(clonedMountingPlate.sketch.tags.edge3), +/// getNextAdjacentEdge(clonedMountingPlate.sketch.tags.edge4) +/// ], +/// ) /// |> translate(x = 0, y = 50, z = 0) /// ``` /// @@ -460,7 +464,7 @@ export fn offsetPlane( /// // |> translate(x = 0, y = 20, z = 0) /// /// // Sketch on the cloned face. -/// // exampleSketch002 = startSketchOn(example002, face = end01) +/// // exampleSketch002 = startSketchOn(example002, face = example002.sketch.tags.end01) /// // |> startProfile(at = [4.5, -5]) /// // |> line(end = [0, 5]) /// // |> line(end = [5, 0]) diff --git a/rust/kcl-lib/tests/subtract_regression12/rendered_model.png b/rust/kcl-lib/tests/subtract_regression12/rendered_model.png index 5aae217e389..c541dac7c7a 100644 Binary files a/rust/kcl-lib/tests/subtract_regression12/rendered_model.png and b/rust/kcl-lib/tests/subtract_regression12/rendered_model.png differ