From 93b0a8946290450b3e0252b853251971eed14e87 Mon Sep 17 00:00:00 2001 From: alteous Date: Fri, 5 Sep 2025 17:56:22 +0100 Subject: [PATCH] Automatically label tagged path segments --- rust/Cargo.lock | 9 +++------ rust/Cargo.toml | 2 +- rust/kcl-lib/src/std/shapes.rs | 13 ++++++++++++- rust/kcl-lib/src/std/sketch.rs | 20 ++++++++++++++++++-- rust/kcl-to-core/src/conn_mock_core.rs | 6 +++++- 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 2ad9d349f74..84b338ee176 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2801,8 +2801,7 @@ dependencies = [ [[package]] name = "kittycad-modeling-cmds" version = "0.2.131" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b589ac0110d08e13371ee186c2c49f8bf1fffdf37aa9885fbbf43f2d4b977b7c" +source = "git+https://github.com/alteous/modeling-api.git?rev=48be0bca23805a05936fb10af760ad26162467a3#48be0bca23805a05936fb10af760ad26162467a3" dependencies = [ "anyhow", "chrono", @@ -2829,8 +2828,7 @@ dependencies = [ [[package]] name = "kittycad-modeling-cmds-macros" version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb9bb1a594541b878adc1c8dcb821328774bf7aa09b65b104a206b1291a5235c" +source = "git+https://github.com/alteous/modeling-api.git?rev=48be0bca23805a05936fb10af760ad26162467a3#48be0bca23805a05936fb10af760ad26162467a3" dependencies = [ "kittycad-modeling-cmds-macros-impl", "proc-macro2", @@ -2841,8 +2839,7 @@ dependencies = [ [[package]] name = "kittycad-modeling-cmds-macros-impl" version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdb4ee23cc996aa2dca7584d410e8826e08161e1ac4335bb646d5ede33f37cb3" +source = "git+https://github.com/alteous/modeling-api.git?rev=48be0bca23805a05936fb10af760ad26162467a3#48be0bca23805a05936fb10af760ad26162467a3" dependencies = [ "proc-macro2", "quote", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ea254171ffd..e8cc0ac5ab9 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -27,7 +27,7 @@ kittycad = { version = "0.3.37", default-features = false, features = [ "js", "requests", ] } -kittycad-modeling-cmds = { version = "0.2.131", features = [ +kittycad-modeling-cmds = { git = "https://github.com/alteous/modeling-api.git", rev = "48be0bca23805a05936fb10af760ad26162467a3", features = [ "ts-rs", "websocket", ] } diff --git a/rust/kcl-lib/src/std/shapes.rs b/rust/kcl-lib/src/std/shapes.rs index 38760bc25d0..06ba3f3142d 100644 --- a/rust/kcl-lib/src/std/shapes.rs +++ b/rust/kcl-lib/src/std/shapes.rs @@ -46,8 +46,9 @@ pub async fn rectangle(exec_state: &mut ExecState, args: Args) -> Result, width: TyF64, height: TyF64, + tag: Option, exec_state: &mut ExecState, args: Args, ) -> Result { @@ -113,6 +115,7 @@ async fn inner_rectangle( .map(LengthUnit), relative: true, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -207,6 +210,7 @@ async fn inner_circle( radius: LengthUnit(radius.to_mm()), relative: false, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -308,6 +312,7 @@ async fn inner_circle_three_point( radius: units.adjust_to(radius, UnitLen::Mm).0.into(), relative: false, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -365,6 +370,7 @@ pub async fn polygon(exec_state: &mut ExecState, args: Args) -> Result Result, + tag: Option, exec_state: &mut ExecState, args: Args, ) -> Result { @@ -459,6 +467,7 @@ async fn inner_polygon( .map(LengthUnit), relative: false, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -494,6 +503,7 @@ async fn inner_polygon( .map(LengthUnit), relative: false, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -611,6 +621,7 @@ async fn inner_ellipse( start_angle: Angle::from_degrees(angle_start.to_degrees()), end_angle: Angle::from_degrees(angle_end.to_degrees()), }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; diff --git a/rust/kcl-lib/src/std/sketch.rs b/rust/kcl-lib/src/std/sketch.rs index a9dd443bf6a..30d17175e61 100644 --- a/rust/kcl-lib/src/std/sketch.rs +++ b/rust/kcl-lib/src/std/sketch.rs @@ -181,6 +181,7 @@ async fn inner_involute_circular( angle: Angle::from_degrees(angle.to_degrees()), reverse: reverse.unwrap_or_default(), }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -331,6 +332,7 @@ async fn straight_line( end: KPoint2d::from(point_to_mm(point.clone())).with_z(0.0).map(LengthUnit), relative: !is_absolute, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -557,6 +559,7 @@ async fn inner_angled_line_length( .map(LengthUnit), relative, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -1373,6 +1376,7 @@ pub async fn absolute_arc( }, relative: false, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -1442,6 +1446,7 @@ pub async fn relative_arc( radius: LengthUnit(from.units.adjust_to(radius, UnitLen::Mm).0), relative: false, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -1609,6 +1614,7 @@ async fn inner_tangential_arc_radius_angle( radius: LengthUnit(radius.to_mm()), offset, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -1642,7 +1648,7 @@ async fn inner_tangential_arc_radius_angle( } // `to` must be in sketch.units -fn tan_arc_to(sketch: &Sketch, to: [f64; 2]) -> ModelingCmd { +fn tan_arc_to(sketch: &Sketch, to: [f64; 2], label: Option) -> ModelingCmd { ModelingCmd::from(mcmd::ExtendPath { path: sketch.id.into(), segment: PathSegment::TangentialArcTo { @@ -1651,6 +1657,7 @@ fn tan_arc_to(sketch: &Sketch, to: [f64; 2]) -> ModelingCmd { .with_z(0.0) .map(LengthUnit), }, + label, }) } @@ -1702,7 +1709,10 @@ async fn inner_tangential_arc_to_point( }; let id = exec_state.next_uuid(); exec_state - .batch_modeling_cmd(ModelingCmdMeta::from_args_id(&args, id), tan_arc_to(&sketch, delta)) + .batch_modeling_cmd( + ModelingCmdMeta::from_args_id(&args, id), + tan_arc_to(&sketch, delta, tag.as_ref().map(|node| node.name.clone())), + ) .await?; let current_path = Path::TangentialArcTo { @@ -1802,6 +1812,7 @@ async fn inner_bezier_curve( end: KPoint2d::from(point_to_mm(delta)).with_z(0.0).map(LengthUnit), relative: true, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -1821,6 +1832,7 @@ async fn inner_bezier_curve( end: KPoint2d::from(point_to_mm(end)).with_z(0.0).map(LengthUnit), relative: false, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -2079,6 +2091,7 @@ pub(crate) async fn inner_elliptic( start_angle, end_angle, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -2246,6 +2259,7 @@ pub(crate) async fn inner_hyperbolic( interior: KPoint2d::from(untyped_point_to_mm(interior, from.units)).map(LengthUnit), relative, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -2459,6 +2473,7 @@ pub(crate) async fn inner_parabolic( interior: KPoint2d::from(untyped_point_to_mm(interior, from.units)).map(LengthUnit), relative, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; @@ -2613,6 +2628,7 @@ pub(crate) async fn inner_conic( interior: KPoint2d::from(untyped_point_to_mm(interior, from.units)).map(LengthUnit), relative, }, + label: tag.as_ref().map(|node| node.name.clone()), }), ) .await?; diff --git a/rust/kcl-to-core/src/conn_mock_core.rs b/rust/kcl-to-core/src/conn_mock_core.rs index 52e1ae57a9b..69bdb70ef2b 100644 --- a/rust/kcl-to-core/src/conn_mock_core.rs +++ b/rust/kcl-to-core/src/conn_mock_core.rs @@ -130,7 +130,11 @@ impl EngineConnection { to.y.0 ) } - kcmc::ModelingCmd::ExtendPath(kcmc::ExtendPath { path, segment }) => match segment { + kcmc::ModelingCmd::ExtendPath(kcmc::ExtendPath { + path, + segment, + label: _, + }) => match segment { Line { end, relative } => { format!( r#"