Skip to content

Commit

Permalink
Fix the example
Browse files Browse the repository at this point in the history
  • Loading branch information
dzervas authored and av8ta committed Jun 5, 2024
1 parent 8e84431 commit 82e5ff6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 54 deletions.
54 changes: 26 additions & 28 deletions packages/cadmium/examples/project_simple_extrusion.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
use cadmium::{
extrusion::{Direction, Extrusion, ExtrusionMode},
project::Project,
};
use cadmium::workbench::AddSketch;
use cadmium::solid::extrusion::{self, Direction, Mode};
use cadmium::project::Project;
use cadmium::message::MessageHandler as _;
use cadmium::isketch::{AddLine, AddPoint};
use cadmium::archetypes::PlaneDescription;

fn main() {
let mut p = Project::new("Example Project");
let wb = p.workbenches.get_mut(0).unwrap();
wb.add_sketch_to_plane("Sketch 1", "Plane-0");
let s = wb.get_sketch_mut("Sketch 1").unwrap();
let ll = s.add_point(0.0, 0.0);
let lr = s.add_point(40.0, 0.0);
let ul = s.add_point(0.0, 40.0);
let ur = s.add_point(40.0, 40.0);
s.add_segment(ll, lr);
s.add_segment(lr, ur);
s.add_segment(ur, ul);
s.add_segment(ul, ll);
let p = Project::new("Test Project");
let wb_ref = p.workbenches.first().unwrap();
let plane_description = PlaneDescription::PlaneId(0);
let sketch_id = AddSketch { plane_description }.handle_message(wb_ref.clone()).unwrap().unwrap();
let sketch = wb_ref.borrow().get_sketch_by_id(sketch_id).unwrap();

let extrusion = Extrusion::new(
"Sketch-0".to_owned(),
vec![0],
25.0,
0.0,
Direction::Normal,
ExtrusionMode::New,
);
wb.add_extrusion("Ext1", extrusion);
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();

let realization = p.get_realization(0, 1000);
let solids = realization.solids;
let solid = &solids["Ext1:0"];
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_ref.clone()).unwrap();

let wb = wb_ref.borrow();
let solid_ref = wb.solids.first_key_value().unwrap().1;
let solid = solid_ref.borrow();

println!("{:?}", solid);

Expand Down
17 changes: 1 addition & 16 deletions packages/cadmium/src/solid/extrusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl SolidLike for Extrusion {

// Can we calculate ALL the wires at once and not iter-sweep?
let sweep = builder::tsweep(&face, extrusion_tvector);


builder::translated(&sweep, offset_tvector)
}).collect())
Expand Down Expand Up @@ -149,21 +149,6 @@ mod tests {
use crate::project::tests::create_test_project;
use crate::project::Project;

#[allow(unused_imports)]
use super::*;

#[test]
#[ignore = "test failing on CI"]
fn create_project_solid() {
// Demonstrate creating a project and then realizing one solid
let p = create_test_project();

// now get solids? save as obj or stl or step?
let realization = p.get_realization(0, 100).unwrap();
let solids = realization.solids;
assert!(solids.len() == 1);
}

#[test]
#[ignore = "uses old filetype"]
fn project_from_files() {
Expand Down
20 changes: 10 additions & 10 deletions packages/cadmium/src/workbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ use std::rc::Rc;
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct Workbench {
pub(crate) name: String,
pub(crate) history: Vec<Step>,
pub name: String,
pub history: Vec<Step>,

// These are free-standing points in 3D space, not part of sketches
pub(crate) points: BTreeMap<IDType, Rc<RefCell<Point3>>>,
pub(crate) points_next_id: IDType,
pub points: BTreeMap<IDType, Rc<RefCell<Point3>>>,
pub points_next_id: IDType,

pub(crate) planes: BTreeMap<IDType, Rc<RefCell<Plane>>>,
pub(crate) planes_next_id: IDType,
pub planes: BTreeMap<IDType, Rc<RefCell<Plane>>>,
pub planes_next_id: IDType,

pub(crate) sketches: BTreeMap<IDType, Rc<RefCell<ISketch>>>,
pub(crate) sketches_next_id: IDType,
pub(crate) solids: BTreeMap<IDType, Rc<RefCell<Solid>>>,
pub(crate) solids_next_id: IDType,
pub sketches: BTreeMap<IDType, Rc<RefCell<ISketch>>>,
pub sketches_next_id: IDType,
pub solids: BTreeMap<IDType, Rc<RefCell<Solid>>>,
pub solids_next_id: IDType,
}

impl Workbench {
Expand Down

0 comments on commit 82e5ff6

Please sign in to comment.