From 10341bf658e83198b10e4a7f07e1143a07ed2bbe Mon Sep 17 00:00:00 2001 From: Matt Ferraro Date: Fri, 10 May 2024 03:58:45 -0400 Subject: [PATCH] extrusion modifications all work --- packages/cadmium/src/extrusion.rs | 4 +- packages/cadmium/src/main.rs | 15 ++++--- packages/cadmium/src/oplog/mod.rs | 71 +++++++++++++++++++++++++++++-- 3 files changed, 80 insertions(+), 10 deletions(-) diff --git a/packages/cadmium/src/extrusion.rs b/packages/cadmium/src/extrusion.rs index 33f34519..ce0bfba6 100644 --- a/packages/cadmium/src/extrusion.rs +++ b/packages/cadmium/src/extrusion.rs @@ -49,7 +49,7 @@ const MESH_TOLERANCE: f64 = 0.1; pub struct Extrusion { pub sketch_id: String, pub face_ids: Vec, - pub face_shas: Vec, + pub faces: Vec, pub length: f64, pub offset: f64, pub direction: Direction, @@ -76,7 +76,7 @@ impl Extrusion { Extrusion { sketch_id, face_ids, - face_shas: vec![], + faces: vec![], length, offset, direction, diff --git a/packages/cadmium/src/main.rs b/packages/cadmium/src/main.rs index 0b9c989e..e4d4a1ab 100644 --- a/packages/cadmium/src/main.rs +++ b/packages/cadmium/src/main.rs @@ -92,7 +92,7 @@ fn stacked_cubes() { // });`` // - el.find_faces(&workbench_id, &sketch_id); + let face_id = el.find_faces(&workbench_id, &sketch_id); // extrude the square let extrusion_id = el.append(Operation::CreateExtrusion { @@ -107,10 +107,15 @@ fn stacked_cubes() { extrusion_id: extrusion_id.clone(), depth: 100.0, }); - // el.append(Operation::SetExtrusionSketch { - // extrusion_id: extrusion_id.clone(), - // sketch_id: sketch_id.clone(), - // }); + el.append(Operation::SetExtrusionSketch { + extrusion_id: extrusion_id.clone(), + sketch_id: sketch_id.clone(), + }); + el.append(Operation::SetExtrusionFaces { + extrusion_id: extrusion_id.clone(), + faces: vec![face_id.clone()], + }); + // el.append(Operation::SetExtrusionHandles { // extrusion_id: extrusion_id.clone(), // handles: vec![handle_id.clone()], diff --git a/packages/cadmium/src/oplog/mod.rs b/packages/cadmium/src/oplog/mod.rs index 9bb85ce9..5e9d5fda 100644 --- a/packages/cadmium/src/oplog/mod.rs +++ b/packages/cadmium/src/oplog/mod.rs @@ -77,6 +77,7 @@ pub struct EvolutionLog { pub planes: HashMap, pub sketches: HashMap, pub extrusions: HashMap, + pub faces: HashMap, } impl EvolutionLog { @@ -91,6 +92,7 @@ impl EvolutionLog { planes: HashMap::new(), sketches: HashMap::new(), extrusions: HashMap::new(), + faces: HashMap::new(), } } @@ -202,7 +204,7 @@ impl EvolutionLog { let extrusion = crate::extrusion::Extrusion { sketch_id: "".to_owned(), face_ids: vec![], - face_shas: vec![], + faces: vec![], length: 25.0, offset: 0.0, direction: crate::extrusion::Direction::Normal, @@ -231,7 +233,38 @@ impl EvolutionLog { unreachable!() }; } - + Operation::SetExtrusionFaces { + extrusion_id, + faces, + } => { + let (workbench_idx, extrusion_idx) = self.extrusions.get(&extrusion_id).unwrap(); + let mut wb = self.project.workbenches.get_mut(*workbench_idx).unwrap(); + if let StepData::Extrusion { extrusion, .. } = &mut wb.history[*extrusion_idx].data + { + let actual_faces = faces + .iter() + .map(|sha| self.faces.get(sha).unwrap().clone()) + .collect(); + extrusion.faces = actual_faces; + } else { + unreachable!() + }; + } + Operation::SetExtrusionSketch { + extrusion_id, + sketch_id, + } => { + let (workbench_idx, extrusion_idx) = self.extrusions.get(&extrusion_id).unwrap(); + let (workbench_idx_sketch, sketch_id) = self.sketches.get(&sketch_id).unwrap(); + assert_eq!(workbench_idx, workbench_idx_sketch); + let mut wb = self.project.workbenches.get_mut(*workbench_idx).unwrap(); + if let StepData::Extrusion { extrusion, .. } = &mut wb.history[*extrusion_idx].data + { + extrusion.sketch_id = sketch_id.clone(); + } else { + unreachable!() + }; + } _ => {} } @@ -263,7 +296,12 @@ impl EvolutionLog { }; for face_op in new_face_ops { - self.append(face_op); + self.append(face_op.clone()); + if let Operation::CreateFace { face, .. } = face_op { + self.faces.insert(self.cursor.clone(), face.clone()); + } else { + unreachable!() + } } self.cursor.clone() @@ -569,6 +607,10 @@ pub enum Operation { extrusion_id: Sha, depth: f64, }, + SetExtrusionFaces { + extrusion_id: Sha, + faces: Vec, + }, } impl Operation { @@ -680,6 +722,15 @@ impl Operation { extrusion_id, depth, } => hasher.update(format!("{extrusion_id}-{depth}").as_bytes()), + Operation::SetExtrusionFaces { + extrusion_id, + faces, + } => { + hasher.update(format!("{extrusion_id}").as_bytes()); + for sha in faces { + hasher.update(format!("{sha}").as_bytes()) + } + } } format!("{:x}", hasher.finalize()) @@ -887,6 +938,20 @@ impl Operation { depth ) } + Operation::SetExtrusionFaces { + extrusion_id, + faces, + } => { + let mut face_str = String::new(); + for sha in faces { + face_str.push_str(&format!("{} ", sha.to_owned()[..num_chars].to_string())); + } + format!( + "SetExtrusionFaces: {} {}", + extrusion_id.to_owned()[..num_chars].to_string(), + face_str + ) + } } } }