diff --git a/packages/cadmium/src/message.rs b/packages/cadmium/src/message.rs index 8a34bcab..3545a192 100644 --- a/packages/cadmium/src/message.rs +++ b/packages/cadmium/src/message.rs @@ -1,12 +1,9 @@ -use isotope::primitives::Primitive; - use serde::{Deserialize, Serialize}; use tsify::Tsify; use crate::error::CADmiumError; -use crate::solid::extrusion::{self, Direction, Extrusion, Mode}; +use crate::solid::extrusion::Direction; use crate::project::Project; -use crate::solid::SolidLike; use crate::step::StepData; use crate::IDType; @@ -158,13 +155,13 @@ impl Message { extrusion_id, sketch_id, face_ids, - length, - offset, - direction, + length:_, + offset:_, + direction:_, } => { let workbench = project.get_workbench_by_id_mut(*workbench_id)?; let sketch = workbench.get_sketch_by_id(*sketch_id)?; - let faces = sketch + let _faces = sketch .borrow() .faces() .iter() @@ -176,7 +173,7 @@ impl Message { None } }).collect::>(); - let extrusion = workbench.solids.get(extrusion_id).ok_or(anyhow::anyhow!("Could not find extrusion ID!"))?.borrow_mut(); + let _extrusion = workbench.solids.get(extrusion_id).ok_or(anyhow::anyhow!("Could not find extrusion ID!"))?.borrow_mut(); todo!("Update Extrusion") // let new_extrusion = extrusion::Extrusion::new(faces, sketch, *length, *offset, *direction, extrusion.mode).to_feature().as_solid_like(); @@ -186,9 +183,9 @@ impl Message { // Ok(format!("\"id\": \"{}\"", extrusion_id)) } Message::UpdateExtrusionLength { - workbench_id, - extrusion_name, - length, + workbench_id:_, + extrusion_name:_, + length:_, } => { // let workbench = project.get_workbench_by_id_mut(*workbench_id)?; // let step = workbench.get_step_mut(&extrusion_name)?; diff --git a/packages/cadmium/src/project.rs b/packages/cadmium/src/project.rs index 307a3ae4..8b6cede5 100644 --- a/packages/cadmium/src/project.rs +++ b/packages/cadmium/src/project.rs @@ -87,16 +87,12 @@ pub struct Assembly { #[cfg(test)] pub mod tests { - use truck_polymesh::obj; use crate::archetypes::PlaneDescription; use crate::archetypes::Point2; use crate::solid::extrusion::Direction; - use crate::solid::extrusion::Extrusion; use crate::solid::extrusion::Mode; use crate::message::Message; - use truck_meshalgo::filters::*; - use truck_meshalgo::tessellation::*; use super::*; diff --git a/packages/cadmium/src/solid/extrusion.rs b/packages/cadmium/src/solid/extrusion.rs index 7ae963c1..e191fb4f 100644 --- a/packages/cadmium/src/solid/extrusion.rs +++ b/packages/cadmium/src/solid/extrusion.rs @@ -3,7 +3,7 @@ use std::rc::Rc; use isotope::decompose::face::Face; use serde::{Deserialize, Serialize}; -use truck_modeling::Wire; +use truck_modeling::builder; use tsify::Tsify; use truck_polymesh::InnerSpace; @@ -82,7 +82,6 @@ impl SolidLike for Extrusion { } fn get_truck_solids(&self) -> anyhow::Result> { - let mut retval = vec![]; let plane = self.sketch.borrow().plane.borrow().clone(); let extrusion_direction = match &self.direction { @@ -93,10 +92,21 @@ impl SolidLike for Extrusion { let extrusion_vector = extrusion_direction.times(self.length - self.offset); let offset_vector = extrusion_direction.times(self.offset); + let extrusion_tvector = TruckVector3::new(extrusion_vector.x, extrusion_vector.y, extrusion_vector.z); + let offset_tvector = TruckVector3::new(offset_vector.x, offset_vector.y, offset_vector.z); - let wires = self.faces.iter().flat_map(|f| get_isoface_wires(self.sketch.clone(), f)).flatten().collect::>(); + Ok(self.faces + .iter() + .map(|f| { + let wires = get_isoface_wires(self.sketch.clone(), f).unwrap(); + let face = builder::try_attach_plane(&wires).unwrap(); - Ok(retval) + // Can we calculate ALL the wires at once and not iter-sweep? + let sweep = builder::tsweep(&face, extrusion_tvector); + let translated = builder::translated(&sweep, offset_tvector); + + translated + }).collect()) } } diff --git a/packages/cadmium/src/solid/mod.rs b/packages/cadmium/src/solid/mod.rs index d3461bab..e0690b5b 100644 --- a/packages/cadmium/src/solid/mod.rs +++ b/packages/cadmium/src/solid/mod.rs @@ -29,10 +29,8 @@ pub trait SolidLike: Debug { fn references(&self) -> Vec; fn get_truck_solids(&self) -> anyhow::Result>; fn to_feature(&self) -> Feature; -} -impl dyn SolidLike { - pub fn to_solids(&self) -> anyhow::Result> { + fn to_solids(&self) -> anyhow::Result> { let truck_solids = self.get_truck_solids()?; Ok(truck_solids.iter().map(|truck_solid| { diff --git a/packages/cadmium/src/workbench.rs b/packages/cadmium/src/workbench.rs index d8348b74..343fd281 100644 --- a/packages/cadmium/src/workbench.rs +++ b/packages/cadmium/src/workbench.rs @@ -137,8 +137,9 @@ 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 sketch = self.get_sketch_by_id(step.id)?.borrow().clone(); + 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 sketch = ISketch::new(plane_ref); realized.sketches.insert( step.id, @@ -149,7 +150,7 @@ impl Workbench { ), ); } - PlaneDescription::SolidFace { solid_id, normal } => { + PlaneDescription::SolidFace { solid_id: _, normal: _ } => { // let solid = &realized.solids[&solid_id]; // let face = solid.get_face_by_normal(&normal).unwrap(); // let oriented_surface = face.oriented_surface(); @@ -290,7 +291,7 @@ impl Workbench { Ok(self.points_next_id - 1) } - pub(super) fn add_workbench_plane(&mut self, plane: Plane, width: f64, height: f64) -> Result { + 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_next_id += 1; @@ -304,7 +305,7 @@ impl Workbench { 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))?, - PlaneDescription::SolidFace { solid_id, normal } => todo!("Implement SolidFace"), + PlaneDescription::SolidFace { solid_id: _, normal: _ } => todo!("Implement SolidFace"), }.clone(); let sketch = ISketch::new(plane); @@ -317,12 +318,12 @@ impl Workbench { pub(crate) fn add_solid_extrusion( &mut self, - face_ids: Vec, - sketch_id: IDType, - length: f64, - offset: f64, - mode: extrusion::Mode, - direction: extrusion::Direction, + _face_ids: Vec, + _sketch_id: IDType, + _length: f64, + _offset: f64, + _mode: extrusion::Mode, + _direction: extrusion::Direction, ) -> Result { // I guess nothing to do? only realization? // TODO: What ID should be returned here?