Skip to content

Commit

Permalink
Fix one_extrusion
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Zervas <[email protected]>
  • Loading branch information
dzervas committed Jun 4, 2024
1 parent fbcd1f7 commit 15bd777
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 62 deletions.
34 changes: 19 additions & 15 deletions packages/cadmium/src/isketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,33 @@ impl Identifiable for Rc<RefCell<ISketch>> {
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(from_wasm_abi, into_wasm_abi)]
pub struct AddPoint {
x: f64,
y: f64,
pub x: f64,
pub y: f64,
}

impl MessageHandler for AddPoint {
type Parent = Rc<RefCell<ISketch>>;
fn handle_message(&self, sketch_ref: Self::Parent) -> anyhow::Result<Option<IDType>> {
let iso_point = PrimitiveCell::Point2(Rc::new(RefCell::new(ISOPoint2::new(self.x, self.y))));

let point_id = sketch_ref.borrow().sketch().borrow_mut().add_primitive(iso_point)?;
// self.points_3d.insert(point_id, Point3::from_plane_point(&self.plane.borrow(), &point.into()));
let iso_point = ISOPoint2::new(self.x, self.y);
let iso_point_cell = PrimitiveCell::Point2(Rc::new(RefCell::new(iso_point.clone())));

let mut sketch = sketch_ref.borrow_mut();
// TODO: On plane change the 3D points have to be recalculated
let plane = sketch.plane.borrow().clone();
let point_id = sketch.sketch().borrow_mut().add_primitive(iso_point_cell)?;
sketch.points_3d.insert(point_id, Point3::from_plane_point(&plane, &iso_point));
Ok(Some(point_id))
}
}

#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(from_wasm_abi, into_wasm_abi)]
pub struct AddArc {
center: IDType,
radius: f64,
clockwise: bool,
start_angle: f64,
end_angle: f64
pub center: IDType,
pub radius: f64,
pub clockwise: bool,
pub start_angle: f64,
pub end_angle: f64
}

impl MessageHandler for AddArc {
Expand All @@ -172,8 +176,8 @@ impl MessageHandler for AddArc {
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(from_wasm_abi, into_wasm_abi)]
pub struct AddCircle {
center: IDType,
radius: f64,
pub center: IDType,
pub radius: f64,
}

impl MessageHandler for AddCircle {
Expand All @@ -198,8 +202,8 @@ impl MessageHandler for AddCircle {
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(from_wasm_abi, into_wasm_abi)]
pub struct AddLine {
start: IDType,
end: IDType,
pub start: IDType,
pub end: IDType,
}

impl MessageHandler for AddLine {
Expand Down
66 changes: 33 additions & 33 deletions packages/cadmium/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,47 +104,47 @@ pub mod tests {

use crate::archetypes::PlaneDescription;
use crate::archetypes::Point2;
use crate::isketch::AddLine;
use crate::isketch::AddPoint;
use crate::message::MessageHandler;
use crate::solid::extrusion;
use crate::solid::extrusion::Direction;
use crate::solid::extrusion::Mode;
use crate::workbench::AddSketch;

use super::*;

pub fn create_test_project() -> Project {
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 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();
let p = Project::new("Test Project");
let wb = p.workbenches.get(0).unwrap();
let plane_description = PlaneDescription::PlaneId(0);
let sketch_id = AddSketch { plane_description }.handle_message(wb.clone()).unwrap().unwrap();
let sketch = wb.borrow().get_sketch_by_id(sketch_id).unwrap();

let ll = AddPoint { x: 0.0, y: 0.0 }.handle_message(sketch.clone()).unwrap().unwrap();
let lr = AddPoint { x: 40.0, y: 0.0 }.handle_message(sketch.clone()).unwrap().unwrap();
let ul = AddPoint { x: 0.0, y: 40.0 }.handle_message(sketch.clone()).unwrap().unwrap();
let ur = AddPoint { x: 40.0, y: 40.0 }.handle_message(sketch.clone()).unwrap().unwrap();

AddLine { start: ll, end: lr }.handle_message(sketch.clone()).unwrap();
AddLine { start: lr, end: ur }.handle_message(sketch.clone()).unwrap();
AddLine { start: ur, end: ul }.handle_message(sketch.clone()).unwrap();
AddLine { start: ul, end: ll }.handle_message(sketch.clone()).unwrap();

let faces = sketch.borrow().sketch().borrow().get_faces();
extrusion::Add { sketch_id, faces, length: 25.0, offset: 0.0, direction: Direction::Normal, mode: Mode::New }.handle_message(wb.clone()).unwrap();

p
}

#[test]
#[ignore = "test failing due to new architecture"]
fn one_extrusion() {
let p = create_test_project();

let workbench_ref = p.get_workbench_by_id(0).unwrap();
let workbench = workbench_ref.borrow();
let solids = &workbench.solids;
println!("solids: {:?}", solids);

assert_eq!(solids.len(), 1);
}
Expand Down Expand Up @@ -202,17 +202,17 @@ pub mod tests {
// println!("{:?}", p2);
// }

#[test]
fn circle_crashing() {
let file_contents =
std::fs::read_to_string("src/test_inputs/circle_crashing_2.cadmium").unwrap();
// #[test]
// fn circle_crashing() {
// let file_contents =
// std::fs::read_to_string("src/test_inputs/circle_crashing_2.cadmium").unwrap();

let p = Project::from_json(&file_contents);
// let p = Project::from_json(&file_contents);

let workbench_ref = p.get_workbench_by_id(0).unwrap();
let workbench = workbench_ref.borrow();
println!("{:?}", workbench);
}
// let workbench_ref = p.get_workbench_by_id(0).unwrap();
// let workbench = workbench_ref.borrow();
// println!("{:?}", workbench);
// }

// #[test]
// fn bruno() {
Expand Down
12 changes: 6 additions & 6 deletions packages/cadmium/src/solid/extrusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ impl SolidLike for Extrusion {
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(from_wasm_abi, into_wasm_abi)]
pub struct Add {
sketch_id: IDType,
faces: Vec<Face>, // TODO: This should be a list of face IDs
length: f64,
offset: f64,
direction: Direction,
mode: Mode,
pub sketch_id: IDType,
pub faces: Vec<Face>, // TODO: This should be a list of face IDs
pub length: f64,
pub offset: f64,
pub direction: Direction,
pub mode: Mode,
}

impl MessageHandler for Add {
Expand Down
16 changes: 8 additions & 8 deletions packages/cadmium/src/workbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ impl Workbench {
solids_next_id: 0,
};

wb.points.insert(0, Rc::new(RefCell::new(Point3::new(0.0, 0.0, 0.0)))).unwrap();
wb.planes.insert(0, Rc::new(RefCell::new(Plane::front()))).unwrap();
wb.planes.insert(1, Rc::new(RefCell::new(Plane::front()))).unwrap();
wb.planes.insert(2, Rc::new(RefCell::new(Plane::front()))).unwrap();
wb.points.insert(0, Rc::new(RefCell::new(Point3::new(0.0, 0.0, 0.0))));
wb.planes.insert(0, Rc::new(RefCell::new(Plane::front())));
wb.planes.insert(1, Rc::new(RefCell::new(Plane::front())));
wb.planes.insert(2, Rc::new(RefCell::new(Plane::front())));

wb
}
Expand Down Expand Up @@ -154,13 +154,13 @@ impl MessageHandler for AddPlane {
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(from_wasm_abi, into_wasm_abi)]
pub struct AddSketch {
plane_description: PlaneDescription,
pub plane_description: PlaneDescription,
}

impl MessageHandler for AddSketch {
type Parent = Rc<RefCell<Workbench>>;
fn handle_message(&self, sketch_ref: Self::Parent) -> anyhow::Result<Option<IDType>> {
let mut wb = sketch_ref.borrow_mut();
fn handle_message(&self, workbench_ref: Self::Parent) -> anyhow::Result<Option<IDType>> {
let mut wb = workbench_ref.borrow_mut();

println!("Adding sketch with plane description: {:?}", self.plane_description);
let sketch = ISketch::try_from_plane_description(&wb, &self.plane_description)?;
Expand All @@ -175,7 +175,7 @@ impl MessageHandler for AddSketch {
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct WorkbenchRename {
new_name: String,
pub new_name: String,
}

impl MessageHandler for WorkbenchRename {
Expand Down

0 comments on commit 15bd777

Please sign in to comment.