diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 2ad9d349f74..1398c2f0425 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/KittyCAD/modeling-api.git?rev=d6cc8789a706ef9c0b88a9c31a5d08a3e71635a7#d6cc8789a706ef9c0b88a9c31a5d08a3e71635a7" 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/KittyCAD/modeling-api.git?rev=d6cc8789a706ef9c0b88a9c31a5d08a3e71635a7#d6cc8789a706ef9c0b88a9c31a5d08a3e71635a7" 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/KittyCAD/modeling-api.git?rev=d6cc8789a706ef9c0b88a9c31a5d08a3e71635a7#d6cc8789a706ef9c0b88a9c31a5d08a3e71635a7" dependencies = [ "proc-macro2", "quote", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ea254171ffd..2b00382b5c9 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -27,10 +27,7 @@ kittycad = { version = "0.3.37", default-features = false, features = [ "js", "requests", ] } -kittycad-modeling-cmds = { version = "0.2.131", features = [ - "ts-rs", - "websocket", -] } +kittycad-modeling-cmds = { git = "https://github.com/KittyCAD/modeling-api.git", rev = "d6cc8789a706ef9c0b88a9c31a5d08a3e71635a7", features = ["ts-rs","websocket"] } lazy_static = "1.5.0" miette = "7.6.0" pyo3 = { version = "0.25.1" } diff --git a/rust/kcl-lib/src/execution/kcl_value.rs b/rust/kcl-lib/src/execution/kcl_value.rs index 97deac254c3..9dd09d52ab7 100644 --- a/rust/kcl-lib/src/execution/kcl_value.rs +++ b/rust/kcl-lib/src/execution/kcl_value.rs @@ -250,6 +250,30 @@ impl From<&KclValue> for SourceRange { } impl KclValue { + pub(crate) fn id(&self) -> Option { + match self { + KclValue::Uuid { value, .. } => Some(*value), + KclValue::Bool { .. } => None, + KclValue::Number { .. } => None, + KclValue::String { .. } => None, + KclValue::Tuple { .. } => None, + KclValue::HomArray { .. } => None, + KclValue::Object { .. } => None, + KclValue::TagIdentifier(tag) => tag.get_cur_info().map(|info| info.id), + KclValue::TagDeclarator(_) => None, + KclValue::Plane { value } => Some(value.id), + KclValue::Face { value } => Some(value.id), + KclValue::Sketch { value } => Some(value.id), + KclValue::Solid { value } => Some(value.id), + KclValue::Helix { value } => Some(value.value), + KclValue::ImportedGeometry(imported_geometry) => Some(imported_geometry.id), + KclValue::Function { .. } => None, + KclValue::Module { .. } => None, + KclValue::Type { .. } => None, + KclValue::KclNone { .. } => None, + } + } + pub(crate) fn metadata(&self) -> Vec { match self { KclValue::Uuid { value: _, meta } => meta.clone(), diff --git a/rust/kcl-lib/src/std/label.rs b/rust/kcl-lib/src/std/label.rs new file mode 100644 index 00000000000..8164a78e7b6 --- /dev/null +++ b/rust/kcl-lib/src/std/label.rs @@ -0,0 +1,28 @@ +use crate::errors::KclErrorDetails; +use crate::std::Args; +use crate::{ExecState, KclError}; +use crate::exec::KclValue; +use crate::execution::types::RuntimeType; + +use kittycad_modeling_cmds::ModelingCmd; +use kittycad_modeling_cmds::each_cmd as mcmd; + +pub async fn label(exec_state: &mut ExecState, args: Args) -> Result { + let item: KclValue = args.get_unlabeled_kw_arg("item", &RuntimeType::any(), exec_state)?; + let text: String = args.get_kw_arg("text", &RuntimeType::string(), exec_state)?; + if let Some(id) = item.id() { + let command = ModelingCmd::from(mcmd::SetLabel { + object_id: id, + label: text, + }); + let _ = exec_state.send_modeling_cmd((&args).into(), command).await?; + Ok(KclValue::none()) + } else { + Err(KclError::Type { + details: KclErrorDetails::new( + format!("This type is not suitable for labeling"), + vec![args.source_range.into()], + ) + }) + } +} \ No newline at end of file diff --git a/rust/kcl-lib/src/std/mod.rs b/rust/kcl-lib/src/std/mod.rs index 2536a6d3045..2e09e0e5c61 100644 --- a/rust/kcl-lib/src/std/mod.rs +++ b/rust/kcl-lib/src/std/mod.rs @@ -12,6 +12,7 @@ pub mod edge; pub mod extrude; pub mod fillet; pub mod helix; +pub mod label; pub mod loft; pub mod math; pub mod mirror; @@ -194,6 +195,10 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp |e, a| Box::pin(crate::std::assert::assert_is(e, a)), StdFnProps::default("std::assertIs"), ), + ("prelude", "label") => ( + |e, a| Box::pin(crate::std::label::label(e, a)), + StdFnProps::default("std::label"), + ), ("solid", "fillet") => ( |e, a| Box::pin(crate::std::fillet::fillet(e, a)), StdFnProps::default("std::solid::fillet").include_in_feature_tree(), diff --git a/rust/kcl-lib/std/prelude.kcl b/rust/kcl-lib/std/prelude.kcl index 44a1a1e551b..339e179f2bc 100644 --- a/rust/kcl-lib/std/prelude.kcl +++ b/rust/kcl-lib/std/prelude.kcl @@ -536,3 +536,7 @@ export fn assert( /// If the value was false, the program will terminate with this error message error?: string, ) {} + +/// Set a label. +@(impl = std_rust) +export fn label(@item: any, text: string): {} \ No newline at end of file