Skip to content

Commit

Permalink
Zotac ZBOX Mount (#169)
Browse files Browse the repository at this point in the history
* Add a subtract function for faces

* Add an example file for a zotac zbox PC mount
  • Loading branch information
bschwind authored Sep 14, 2024
1 parent 50b6810 commit fa7a5f7
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/opencascade/src/primitives/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Face {
let profile_base = &self.inner;
let sketch_base = ffi::TopoDS_Face_ctor();
let angle = 0.0;
let fuse = 1; // 0 = subtractive, 1 = additive
let fuse = 0; // 0 = subtractive, 1 = additive
let modify = false;

let mut make_prism = ffi::BRepFeat_MakeDPrism_ctor(
Expand Down Expand Up @@ -310,6 +310,19 @@ impl Face {
CompoundFace::from_compound(compound)
}

pub fn subtract(&self, other: &Face) -> CompoundFace {
let inner_shape = ffi::cast_face_to_shape(&self.inner);
let other_inner_shape = ffi::cast_face_to_shape(&other.inner);

let mut fuse_operation = ffi::BRepAlgoAPI_Cut_ctor(inner_shape, other_inner_shape);

let cut_shape = fuse_operation.pin_mut().Shape();

let compound = ffi::TopoDS_cast_to_compound(cut_shape);

CompoundFace::from_compound(compound)
}

pub fn surface_area(&self) -> f64 {
let mut props = ffi::GProp_GProps_ctor();

Expand Down
3 changes: 3 additions & 0 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod swept_wire;
pub mod swept_wire_variable;
pub mod turners_cube;
pub mod variable_fillet;
pub mod zbox_case;

#[derive(Debug, Copy, Clone, PartialEq, ValueEnum)]
pub enum Example {
Expand All @@ -40,6 +41,7 @@ pub enum Example {
SweptWireVariable,
TurnersCube,
VariableFillet,
ZboxCase,
}

impl Example {
Expand All @@ -63,6 +65,7 @@ impl Example {
Example::SweptWireVariable => swept_wire_variable::shape(),
Example::TurnersCube => turners_cube::shape(),
Example::VariableFillet => variable_fillet::shape(),
Example::ZboxCase => zbox_case::shape(),
}
}
}
91 changes: 91 additions & 0 deletions examples/src/zbox_case.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use glam::dvec3;
use opencascade::{
primitives::{Direction, Shape},
workplane::Workplane,
};

pub fn shape() -> Shape {
// The origin of the coordinate system is the closest bottom left corner of
// the PC box, when viewing its ports from behind.
let case_thickness = 2.0;
let case_width = 212.0;
let case_height = 60.0;
let case_depth = 64.0; // Not measured, arbitrary value

let hook_thickness = 3.0;
let wire_gap = 2.6;

let case_box = Shape::box_with_dimensions(case_width, case_height, case_depth);

let back_face = case_box.faces().farthest(Direction::PosY);

let case_box = case_box.hollow(case_thickness, [back_face]);

let port_cutout = Workplane::xz()
.sketch()
.move_to(10.0, 9.0)
.line_to(10.0, 55.0)
.line_to(200.0, 55.0)
.line_to(200.0, 9.0)
.close()
.to_face();

let cutout = port_cutout.extrude(dvec3(0.0, -case_thickness, 0.0)).into();

let mut case_box = case_box.subtract(&cutout);

// Add the back hooks
let bottom_face = case_box.faces().farthest(Direction::NegZ);

for x_offset in [-75.0, -25.0, 25.0, 75.0] {
let mut hook: Shape = bottom_face
.workplane()
.translated(dvec3(x_offset, -20.0, 0.0))
.rect(40.0, 20.0)
.to_face()
.extrude(dvec3(0.0, 0.0, -(hook_thickness + wire_gap)))
.into();

let hook_bottom = hook.faces().farthest(Direction::NegY);

let hook_descent = hook_bottom
.workplane()
.translated(dvec3(0.0, -(hook_thickness + wire_gap) / 2.0 + hook_thickness / 2.0, 0.0))
.rect(40.0, hook_thickness)
.to_face()
.extrude(dvec3(0.0, -20.0, 0.0))
.into();

hook = hook.union(&hook_descent).into();

let bottom_hook_edges =
hook.faces().farthest(Direction::NegY).edges().parallel_to(Direction::PosZ);
hook = hook.fillet_edges(10.0, bottom_hook_edges);

case_box = case_box.union(&hook);
}

// Punch some holes in the back for optional zipties
for x_offset in [-100.0, -50.0, 0.0, 50.0, 100.0] {
let ziptie_hole = bottom_face
.workplane()
.translated(dvec3(x_offset, -20.0, 0.0))
.circle(0.0, 0.0, 2.25)
.to_face()
.extrude(dvec3(0.0, 0.0, 10.0))
.into();

case_box = case_box.subtract(&ziptie_hole)
}

// Cut out a circle on the front
let front_face = case_box
.faces()
.farthest(Direction::PosZ)
.workplane()
.translated(dvec3(0.0, 75.0, 0.0))
.circle(0.0, 0.0, 100.0)
.to_face();

front_face.subtractive_extrude(&case_box, -case_thickness)
}

0 comments on commit fa7a5f7

Please sign in to comment.