From 9864b021cefcfabfc8895bcbda78f20377f8a4cc Mon Sep 17 00:00:00 2001 From: Dimitris Zervas Date: Tue, 28 May 2024 08:39:05 +0300 Subject: [PATCH] It works! --- packages/cadmium-macros/src/lib.rs | 32 ++++++++++++++---------------- packages/cadmium/src/step.rs | 11 ++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/cadmium-macros/src/lib.rs b/packages/cadmium-macros/src/lib.rs index 04ff7c8f..c8df9500 100644 --- a/packages/cadmium-macros/src/lib.rs +++ b/packages/cadmium-macros/src/lib.rs @@ -56,22 +56,16 @@ pub fn derive_step_data(input: TokenStream) -> TokenStream { // Process not skipped workbench let mut wb_var = quote! {}; - let mut wb_id_def = quote! {}; - let mut wb_id_arg = quote! {}; if !skip_workbench { wb_var = quote! { let wb_ = self.native.workbenches .get_mut(workbench_id as usize) .ok_or(anyhow::anyhow!("Could not find workbench"))?; }; - wb_id_def = quote! { workbench_id: crate::IDType, }; - wb_id_arg = quote! { workbench_id, }; } // Process type and workbench_field let mut field_var = quote! {}; - let mut field_id_def = quote! {}; - let mut field_id_arg = quote! {}; 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 { @@ -85,8 +79,6 @@ pub fn derive_step_data(input: TokenStream) -> TokenStream { .ok_or(anyhow::anyhow!("Could not find parent"))?; let parent_ = parent_ref_.borrow_mut(); }; - field_id_def = quote! { #id_arg_name: crate::IDType, }; - field_id_arg = quote! { #id_arg_name, }; } else if !skip_workbench { field_var = quote! { let parent_ = wb_; }; } else { @@ -100,19 +92,27 @@ pub fn derive_step_data(input: TokenStream) -> TokenStream { let field_type = &field.ty; quote! { #field_name: #field_type } - }).into_iter(); - let function_args = variant.fields.iter().map(|field| { + }).collect::>(); + let function_args_full = variant.fields.iter().map(|field| { let field_name = &field.ident; quote! { #field_name } - }).into_iter(); - let function_args2 = function_args.clone(); + }).collect::>(); + + let function_args2 = function_args_full.clone(); + let function_args_noauto = function_args2 + .iter() + .filter(|field| + field.to_string() != "workbench_id" + && field.to_string() != id_arg_name.to_string() + ).collect::>(); + quote! { - pub fn #add_func_name(&mut self, #wb_id_def #field_id_def name: String, #( #function_defs ),*) -> Result { + 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 ),*)?; + let result_id_ = parent_.#add_func_name(#( #function_args_noauto ),*)?; let step_ = Step { name, @@ -120,9 +120,7 @@ pub fn derive_step_data(input: TokenStream) -> TokenStream { unique_id: format!(concat!("Add:", stringify!(#name), "-{}"), result_id_), suppressed: false, data: #name::#variant_name { - // #wb_id_arg - // #field_id_arg - #( #function_args2 ),* + #( #function_args_full ),* }, }; diff --git a/packages/cadmium/src/step.rs b/packages/cadmium/src/step.rs index 4364f52d..635130f2 100644 --- a/packages/cadmium/src/step.rs +++ b/packages/cadmium/src/step.rs @@ -29,14 +29,17 @@ pub struct Step { #[tsify(into_wasm_abi, from_wasm_abi)] pub enum StepData { WorkbenchPoint { + workbench_id: IDType, point: Point3, }, WorkbenchPlane { + workbench_id: IDType, plane: Plane, width: f64, height: f64, }, WorkbenchSketch { + workbench_id: IDType, plane_description: PlaneDescription, // sketch: ISketch, // width: f64, @@ -44,10 +47,14 @@ pub enum StepData { }, #[step_data(workbench_field = "sketches", type = "Sketch")] SketchPoint { + workbench_id: IDType, + sketch_id: IDType, point: Point2, }, #[step_data(workbench_field = "sketches", type = "Sketch")] SketchArc { + workbench_id: IDType, + sketch_id: IDType, center: IDType, radius: f64, clockwise: bool, @@ -56,11 +63,15 @@ pub enum StepData { }, #[step_data(workbench_field = "sketches", type = "Sketch")] SketchCircle { + workbench_id: IDType, + sketch_id: IDType, center: IDType, radius: f64, }, #[step_data(workbench_field = "sketches", type = "Sketch")] SketchLine { + workbench_id: IDType, + sketch_id: IDType, start: IDType, end: IDType, }