Skip to content

Surface IDs are set up properly to accommodate clone improvements #7881

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 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 20 additions & 2 deletions rust/kcl-lib/src/execution/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,10 @@
} => [center[0] + major_radius, center[1] + if *ccw { -1.0 } else { 1.0 }],
}
}
}

Check warning on line 770 in rust/kcl-lib/src/execution/geometry.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/modeling-app/modeling-app/rust/kcl-lib/src/execution/geometry.rs

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<ExtrudeSurface>) {
let mut tag_identifier: TagIdentifier = tag.into();
let base = current_path.get_base();
tag_identifier.info.push((
Expand All @@ -779,7 +779,7 @@
id: base.geo_meta.id,
sketch: self.id,
path: Some(current_path.clone()),
surface: None,
surface: surface.clone(),
},
));

Expand Down Expand Up @@ -1640,6 +1640,24 @@
}
}

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<Node<TagDeclarator>> {
match self {
ExtrudeSurface::ExtrudePlane(ep) => ep.tag.clone(),
Expand Down
21 changes: 14 additions & 7 deletions rust/kcl-lib/src/std/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
use kittycad_modeling_cmds::{self as kcmc};

use super::extrude::do_post_extrude;
use crate::{

Check warning on line 14 in rust/kcl-lib/src/std/clone.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/modeling-app/modeling-app/rust/kcl-lib/src/std/clone.rs
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.
Expand Down Expand Up @@ -111,15 +110,15 @@
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.
solid.sketch.id = new_geometry_id;
solid.sketch.original_id = new_geometry_id;

Check warning on line 118 in rust/kcl-lib/src/std/clone.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/modeling-app/modeling-app/rust/kcl-lib/src/std/clone.rs
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);

Expand Down Expand Up @@ -222,10 +221,10 @@
}

/// Fix the tags and references of a sketch.
async fn fix_sketch_tags_and_references(

Check warning on line 224 in rust/kcl-lib/src/std/clone.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/modeling-app/modeling-app/rust/kcl-lib/src/std/clone.rs
new_sketch: &mut Sketch,
entity_id_map: &HashMap<uuid::Uuid, uuid::Uuid>,
exec_state: &mut ExecState,
exec_state: &mut ExecState, surfaces: Option<Vec<ExtrudeSurface>>,
) -> Result<()> {
// Fix the path references in the sketch.
for path in new_sketch.paths.as_mut_slice() {
Expand All @@ -244,7 +243,15 @@
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<ExtrudeSurface> = None;
for (i, s) in surfaces.clone().unwrap_or(vec![]).iter().enumerate() {

Check warning on line 247 in rust/kcl-lib/src/std/clone.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/modeling-app/modeling-app/rust/kcl-lib/src/std/clone.rs
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());

Check warning on line 250 in rust/kcl-lib/src/std/clone.rs

View workflow job for this annotation

GitHub Actions / semgrep-oss/scan

panic-in-function-returning-result

expect or unwrap called in function returning a Result
}
}

new_sketch.add_tag(&tag.clone(), &path, exec_state, &surface);
}
}

Expand Down
6 changes: 3 additions & 3 deletions rust/kcl-lib/src/std/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down
26 changes: 13 additions & 13 deletions rust/kcl-lib/src/std/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ async fn inner_involute_circular(

let mut new_sketch = sketch;
if let Some(tag) = &tag {
new_sketch.add_tag(tag, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}
new_sketch.paths.push(current_path);
Ok(new_sketch)
Expand Down Expand Up @@ -358,7 +358,7 @@ async fn straight_line(

let mut new_sketch = sketch;
if let Some(tag) = &tag {
new_sketch.add_tag(tag, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}
new_sketch.paths.push(current_path);
new_sketch.is_closed = true;
Expand Down Expand Up @@ -1395,7 +1395,7 @@ pub async fn absolute_arc(

let mut new_sketch = sketch;
if let Some(tag) = &tag {
new_sketch.add_tag(tag, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -1461,7 +1461,7 @@ pub async fn relative_arc(

let mut new_sketch = sketch;
if let Some(tag) = &tag {
new_sketch.add_tag(tag, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -1846,7 +1846,7 @@ async fn inner_bezier_curve(

let mut new_sketch = sketch;
if let Some(tag) = &tag {
new_sketch.add_tag(tag, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down Expand Up @@ -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, &current_path, exec_state);
new_sketch.add_tag(tag, &current_path, exec_state, &None);
}

new_sketch.paths.push(current_path);
Expand Down
28 changes: 16 additions & 12 deletions rust/kcl-lib/std/prelude.kcl
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
/// )
/// ```
///
Expand Down Expand Up @@ -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)
/// ```
///
Expand Down Expand Up @@ -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])
Expand Down
Binary file modified rust/kcl-lib/tests/subtract_regression12/rendered_model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading