Skip to content

Commit

Permalink
Lifetime tinkerings
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Zervas <[email protected]>
  • Loading branch information
dzervas committed May 29, 2024
1 parent fa7f204 commit 506d0a3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
21 changes: 9 additions & 12 deletions packages/cadmium/src/message.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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()
Expand All @@ -176,7 +173,7 @@ impl Message {
None
}
}).collect::<Vec<_>>();
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();
Expand All @@ -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)?;
Expand Down
4 changes: 0 additions & 4 deletions packages/cadmium/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down
18 changes: 14 additions & 4 deletions packages/cadmium/src/solid/extrusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,7 +82,6 @@ impl SolidLike for Extrusion {
}

fn get_truck_solids(&self) -> anyhow::Result<Vec<TruckClosedSolid>> {
let mut retval = vec![];
let plane = self.sketch.borrow().plane.borrow().clone();

let extrusion_direction = match &self.direction {
Expand All @@ -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::<Vec<Wire>>();
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())
}
}

Expand Down
4 changes: 1 addition & 3 deletions packages/cadmium/src/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ pub trait SolidLike: Debug {
fn references(&self) -> Vec<FeatureCell>;
fn get_truck_solids(&self) -> anyhow::Result<Vec<TruckClosedSolid>>;
fn to_feature(&self) -> Feature;
}

impl dyn SolidLike {
pub fn to_solids(&self) -> anyhow::Result<Vec<Solid>> {
fn to_solids(&self) -> anyhow::Result<Vec<Solid>> {
let truck_solids = self.get_truck_solids()?;

Ok(truck_solids.iter().map(|truck_solid| {
Expand Down
23 changes: 12 additions & 11 deletions packages/cadmium/src/workbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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<IDType, anyhow::Error> {
pub(super) fn add_workbench_plane(&mut self, plane: Plane, _width: f64, _height: f64) -> Result<IDType, anyhow::Error> {
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;
Expand All @@ -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);
Expand All @@ -317,12 +318,12 @@ impl Workbench {

pub(crate) fn add_solid_extrusion(
&mut self,
face_ids: Vec<IDType>,
sketch_id: IDType,
length: f64,
offset: f64,
mode: extrusion::Mode,
direction: extrusion::Direction,
_face_ids: Vec<IDType>,
_sketch_id: IDType,
_length: f64,
_offset: f64,
_mode: extrusion::Mode,
_direction: extrusion::Direction,
) -> Result<IDType, anyhow::Error> {
// I guess nothing to do? only realization?
// TODO: What ID should be returned here?
Expand Down

0 comments on commit 506d0a3

Please sign in to comment.