From 5a42c107fe090da1986f2f6206e9eb805b35ba7b Mon Sep 17 00:00:00 2001 From: Dimitris Zervas Date: Wed, 29 May 2024 23:13:52 +0300 Subject: [PATCH] Fix most stuff Signed-off-by: Dimitris Zervas --- Cargo.lock | 212 +++++++++++++---------------- packages/cadmium-macros/src/lib.rs | 19 +-- packages/cadmium/src/main.rs | 2 +- packages/cadmium/src/project.rs | 28 ++-- packages/cadmium/src/solid/mod.rs | 8 +- packages/cadmium/src/workbench.rs | 18 +-- 6 files changed, 137 insertions(+), 150 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7fa3981..d9a42555 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,7 +45,7 @@ version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ - "memchr 2.6.4", + "memchr 2.7.2", ] [[package]] @@ -96,6 +96,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "array-macro" +version = "2.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "220a2c618ab466efe41d0eace94dfeff1c35e3aa47891bdb95e1c0fefffd3c99" + [[package]] name = "atomic-polyfill" version = "1.0.3" @@ -126,6 +132,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.22.1" @@ -187,7 +199,7 @@ dependencies = [ "geo 0.26.0", "indexmap 2.2.6", "isotope", - "itertools 0.11.0", + "itertools 0.12.1", "paste", "serde", "serde_json", @@ -250,7 +262,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.5", + "windows-targets", ] [[package]] @@ -449,8 +461,8 @@ dependencies = [ "geographiclib-rs", "log", "num-traits", - "rstar", "robust", + "rstar 0.11.0", ] [[package]] @@ -666,6 +678,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.12.1" @@ -773,6 +794,15 @@ dependencies = [ "rawpointer", ] +[[package]] +name = "memchr" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" +dependencies = [ + "libc", +] + [[package]] name = "memchr" version = "2.7.2" @@ -837,34 +867,10 @@ version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ - "memchr 2.6.4", + "memchr 2.7.2", "minimal-lexical", ] -[[package]] -name = "num" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" -dependencies = [ - "num-bigint", - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" -dependencies = [ - "num-integer", - "num-traits", -] - [[package]] name = "num-complex" version = "0.4.6" @@ -882,22 +888,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] -name = "num-integer" -version = "0.1.46" +name = "num-derive" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ - "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] -name = "num-iter" -version = "0.1.45" +name = "num-integer" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", - "num-integer", "num-traits", ] @@ -907,7 +913,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "num-bigint", "num-integer", "num-traits", ] @@ -928,7 +933,7 @@ version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ - "memchr 2.6.4", + "memchr 2.7.2", ] [[package]] @@ -937,12 +942,41 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + [[package]] name = "paste" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + [[package]] name = "powerfmt" version = "0.2.0" @@ -1004,7 +1038,7 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8533f14c8382aaad0d592c812ac3b826162128b65662331e1127b45c3d18536b" dependencies = [ - "memchr 2.6.4", + "memchr 2.7.2", "serde", ] @@ -1073,6 +1107,24 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "rclite" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee9f0c2e8b8ef3ea8b0d074b9a0a192d99d47e2023bec8fd6336f2d8543a43b9" +dependencies = [ + "branches", +] + +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" version = "1.10.4" @@ -1080,7 +1132,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", - "memchr 2.6.4", + "memchr 2.7.2", "regex-automata", "regex-syntax", ] @@ -1092,7 +1144,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", - "memchr 2.6.4", + "memchr 2.7.2", "regex-syntax", ] @@ -1260,7 +1312,7 @@ version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ad483d2ab0149d5a5ebcd9972a3852711e0153d863bf5a5d0391d28883c4a20" dependencies = [ - "base64 0.21.5", + "base64 0.22.1", "chrono", "hex", "indexmap 1.9.3", @@ -1748,7 +1800,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.48.5", + "windows-targets", ] [[package]] @@ -1773,18 +1825,6 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - [[package]] name = "windows_aarch64_msvc" version = "0.52.5" @@ -1803,24 +1843,6 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - [[package]] name = "windows_i686_msvc" version = "0.52.5" @@ -1833,18 +1855,6 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" @@ -1857,19 +1867,13 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" - [[package]] name = "winnow" version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" dependencies = [ - "memchr 2.6.4", + "memchr 2.7.2", ] [[package]] @@ -1900,23 +1904,3 @@ dependencies = [ "quote", "syn 2.0.66", ] - -[[package]] -name = "zerocopy" -version = "0.7.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] diff --git a/packages/cadmium-macros/src/lib.rs b/packages/cadmium-macros/src/lib.rs index 5e1e4978..b55692e9 100644 --- a/packages/cadmium-macros/src/lib.rs +++ b/packages/cadmium-macros/src/lib.rs @@ -66,7 +66,8 @@ pub fn derive_step_data(input: TokenStream) -> TokenStream { } // Process type and workbench_field - let mut field_var = quote! {}; + let mut _field_var = quote! {}; + let mut _parent_var_ = quote! { wb_ }; let id_arg_name = if let Some(f) = parent_type.clone() { Ident::new(format!("{}_id", f.to_string().to_case(Case::Snake)).as_str(), f.span()) } else { @@ -74,16 +75,17 @@ pub fn derive_step_data(input: TokenStream) -> TokenStream { }; if let Some(field_ident) = workbench_field.clone() { let field_name = Ident::new(field_ident.as_str(), field_ident.span()); - field_var = quote! { + _field_var = quote! { let parent_ref_ = wb_.#field_name .get(& #id_arg_name) - .ok_or(anyhow::anyhow!("Could not find parent"))?; + .ok_or(anyhow::anyhow!(concat!("Could not find parent ", stringify!(#parent_type), " with ID {}"), #id_arg_name))?; let mut parent_ = parent_ref_.borrow_mut(); }; + _parent_var_ = quote! { parent_ }; } else if !skip_workbench { - field_var = quote! { let mut parent_ = wb_; }; + _parent_var_ = quote! { wb_ }; } else { - field_var = quote! { let mut parent_ = self; }; + _parent_var_ = quote! { self }; } // Function declaration @@ -116,15 +118,14 @@ pub fn derive_step_data(input: TokenStream) -> TokenStream { quote! { pub fn #add_func_name(&mut self, name: String, #( #function_defs ),*) -> Result { #wb_var - #field_var - let result_id_ = parent_.#add_func_name(#( #function_args_noauto.clone() ),*)?; - drop(parent_); + #_field_var + let result_id_ = #_parent_var_.#add_func_name(#( #function_args_noauto.clone() ),*)?; let step_ = Step { name, id: result_id_, operation: StepOperation::Add, - unique_id: format!(concat!("Add:", stringify!(#name), "-{}"), result_id_), + unique_id: format!(concat!("Add:", stringify!(#variant_name), "-{}"), result_id_), suppressed: false, data: #name::#variant_name { #( #function_args_full ),* diff --git a/packages/cadmium/src/main.rs b/packages/cadmium/src/main.rs index 1759992a..cbd771de 100644 --- a/packages/cadmium/src/main.rs +++ b/packages/cadmium/src/main.rs @@ -2,7 +2,7 @@ use std::ops::{Sub, SubAssign}; -use cadmium::extrusion::fuse; +use cadmium::solid::extrusion::fuse; use truck_meshalgo::filters::OptimizingFilter; use truck_meshalgo::tessellation::{MeshableShape, MeshedShape}; use truck_modeling::builder::{translated, tsweep, vertex}; diff --git a/packages/cadmium/src/project.rs b/packages/cadmium/src/project.rs index 8b6cede5..462d36e2 100644 --- a/packages/cadmium/src/project.rs +++ b/packages/cadmium/src/project.rs @@ -100,26 +100,26 @@ pub mod tests { let mut p = Project::new("Test Project"); let plane_desc = PlaneDescription::PlaneId(0); let sid = p.add_workbench_sketch("Sketch 1".to_string(), 0, plane_desc).unwrap(); - let wb = p.workbenches.get_mut(0).unwrap(); - let s_ref = wb.get_sketch_by_id(sid).unwrap(); - let mut s = s_ref.borrow_mut(); - let ll = s.add_sketch_point(Point2 { x: 0.0, y: 0.0, hidden: false }).unwrap(); - let lr = s.add_sketch_point(Point2 { x: 40.0, y: 0.0, hidden: false }).unwrap(); - let ul = s.add_sketch_point(Point2 { x: 0.0, y: 40.0, hidden: false }).unwrap(); - let ur = s.add_sketch_point(Point2 { x: 40.0, y: 40.0, hidden: false }).unwrap(); - s.add_sketch_line(ll, lr); - s.add_sketch_line(lr, ur); - s.add_sketch_line(ur, ul); - s.add_sketch_line(ul, ll); - - wb.add_solid_extrusion( + + let ll = p.add_sketch_point("bottom left".to_string(), 0, sid, Point2 { x: 0.0, y: 0.0, hidden: false }).unwrap(); + let lr = p.add_sketch_point("bottom right".to_string(), 0, sid, Point2 { x: 40.0, y: 0.0, hidden: false }).unwrap(); + let ul = p.add_sketch_point("top left".to_string(), 0, sid, Point2 { x: 0.0, y: 40.0, hidden: false }).unwrap(); + let ur = p.add_sketch_point("top right".to_string(), 0, sid, Point2 { x: 40.0, y: 40.0, hidden: false }).unwrap(); + p.add_sketch_line("bottom".to_string(), 0, sid, ll, lr).unwrap(); + p.add_sketch_line("right".to_string(), 0, sid, lr, ur).unwrap(); + p.add_sketch_line("up".to_string(), 0, sid, ur, ul).unwrap(); + p.add_sketch_line("left".to_string(), 0, sid, ul, ll).unwrap(); + + p.add_solid_extrusion( + "Extrusion 1".to_string(), + 0, vec![0], 0, 25.0, 0.0, Mode::New, Direction::Normal, - ); + ).unwrap(); p } diff --git a/packages/cadmium/src/solid/mod.rs b/packages/cadmium/src/solid/mod.rs index e0690b5b..f5607515 100644 --- a/packages/cadmium/src/solid/mod.rs +++ b/packages/cadmium/src/solid/mod.rs @@ -114,7 +114,7 @@ impl Solid { truck_solid, }; let mut mesh = solid.truck_solid.triangulation(MESH_TOLERANCE).to_polygon(); - mesh.put_together_same_attrs(); + mesh.put_together_same_attrs(MESH_TOLERANCE); // the mesh is prepared for obj export, but we need to convert it // to a format compatible for rendering @@ -187,7 +187,7 @@ impl Solid { pub fn to_obj_string(&self, tolerance: f64) -> String { let mut mesh = self.truck_solid.triangulation(tolerance).to_polygon(); - mesh.put_together_same_attrs(); + mesh.put_together_same_attrs(MESH_TOLERANCE); let mut buf = Vec::new(); obj::write(&mesh, &mut buf).unwrap(); let string = String::from_utf8(buf).unwrap(); @@ -196,7 +196,7 @@ impl Solid { pub fn save_as_obj(&self, filename: &str, tolerance: f64) { let mut mesh = self.truck_solid.triangulation(tolerance).to_polygon(); - mesh.put_together_same_attrs(); + mesh.put_together_same_attrs(MESH_TOLERANCE); let file = std::fs::File::create(filename).unwrap(); obj::write(&mesh, file).unwrap(); } @@ -206,7 +206,7 @@ impl Solid { let step_string = out::CompleteStepDisplay::new( out::StepModel::from(&compressed), out::StepHeaderDescriptor { - origination_system: "cadmium-shape-to-step".to_owned(), + organization_system: "cadmium-shape-to-step".to_owned(), ..Default::default() }, ) diff --git a/packages/cadmium/src/workbench.rs b/packages/cadmium/src/workbench.rs index 343fd281..6e13a012 100644 --- a/packages/cadmium/src/workbench.rs +++ b/packages/cadmium/src/workbench.rs @@ -41,6 +41,7 @@ pub struct Workbench { impl Workbench { pub fn new(name: &str) -> Self { + println!("Creating new workbench: {:?}", name); let mut wb = Workbench { name: name.to_owned(), history: vec![], @@ -81,6 +82,7 @@ impl Workbench { } pub fn get_sketch_by_id(&self, id: IDType) -> Result>, CADmiumError> { + println!("Getting sketch by id: {:?} {:?}", id, self.sketches); self.sketches.get(&id).ok_or(CADmiumError::SketchIDNotFound(id)).cloned() } @@ -137,8 +139,8 @@ impl Workbench { .. } => match plane_description { PlaneDescription::PlaneId(plane_id) => { - let plane = realized.planes.get(&plane_id).ok_or(anyhow::anyhow!("Failed to find plane with id {}", plane_id))?; - let plane_ref = Rc::new(RefCell::new(plane.plane.clone())); + let plane = self.planes.get(&plane_id).ok_or(anyhow::anyhow!("Failed to find plane with id {}", plane_id))?; + let plane_ref = plane.clone(); let sketch = ISketch::new(plane_ref); realized.sketches.insert( @@ -217,7 +219,7 @@ impl Workbench { match &new_extrusion.mode { extrusion::Mode::New => { - new_solids.iter().map(|s| { + new_solids.iter().for_each(|s| { realized.solids.insert(self.solids_next_id, s.clone()); self.solids_next_id += 1; }); @@ -286,14 +288,14 @@ impl Workbench { // Step operations impl Workbench { pub(super) fn add_workbench_point(&mut self, point: Point3) -> Result { - self.points.insert(self.points_next_id, point).ok_or(anyhow::anyhow!("Failed to insert point")); + self.points.insert(self.points_next_id, point); self.points_next_id += 1; Ok(self.points_next_id - 1) } pub(super) fn add_workbench_plane(&mut self, plane: Plane, _width: f64, _height: f64) -> Result { let plane_cell = Rc::new(RefCell::new(plane)); - self.planes.insert(self.planes_next_id, plane_cell).ok_or(anyhow::anyhow!("Failed to insert plane")); + self.planes.insert(self.planes_next_id, plane_cell); self.planes_next_id += 1; Ok(self.planes_next_id - 1) } @@ -302,6 +304,7 @@ impl Workbench { &mut self, plane_description: PlaneDescription, ) -> Result { + println!("Adding sketch with plane description: {:?}", plane_description); let plane = match plane_description { PlaneDescription::PlaneId(plane_id) => self.planes.get(&plane_id).ok_or(anyhow::anyhow!("Failed to find plane with id {}", plane_id))?, @@ -309,9 +312,8 @@ impl Workbench { }.clone(); let sketch = ISketch::new(plane); - self.sketches - .insert(self.sketches_next_id, Rc::new(RefCell::new(sketch))) - .ok_or(anyhow::anyhow!("Failed to insert sketch")); + self.sketches.insert(self.sketches_next_id, Rc::new(RefCell::new(sketch))); + println!("Added sketch with id: {:?}", self.sketches); self.sketches_next_id += 1; Ok(self.sketches_next_id - 1) }