Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions crates/opencascade-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,21 @@ fn main() {
println!("cargo:rustc-link-lib=dylib=user32");
}

let mut build = cxx_build::bridge("src/lib.rs");
let rust_bridges = [
"src/b_rep_g_prop.rs",
"src/b_rep_mesh.rs",
"src/b_rep_tools.rs",
"src/g_prop.rs",
"src/gc_pnts.rs",
"src/lib.rs",
"src/poly.rs",
"src/shape_analysis.rs",
"src/shape_upgrade.rs",
"src/stl_api.rs",
"src/top_loc.rs",
];

let mut build = cxx_build::bridges(rust_bridges);

if is_windows_gnu {
build.define("OCC_CONVERT_SIGNALS", "TRUE");
Expand All @@ -70,7 +84,10 @@ fn main() {

println!("cargo:rustc-link-lib=static=wrapper");

println!("cargo:rerun-if-changed=src/lib.rs");
for bridge in rust_bridges {
println!("cargo:rerun-if-changed={bridge}");
}

println!("cargo:rerun-if-changed=include/wrapper.hxx");
}

Expand Down
48 changes: 26 additions & 22 deletions crates/opencascade-sys/examples/bottle.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
use cxx::UniquePtr;
use opencascade_sys::ffi::{
cylinder_to_surface, ellipse_to_HandleGeom2d_Curve, ellipse_value, gp_Ax2_ctor, gp_Ax2d_ctor,
gp_Ax3_from_gp_Ax2, gp_DZ, gp_Dir2d_ctor, gp_OX, handle_geom_plane_location,
new_HandleGeomCurve_from_HandleGeom_TrimmedCurve, new_HandleGeomPlane_from_HandleGeomSurface,
new_list_of_shape, new_point, new_point_2d, new_transform, new_vec, shape_list_append_face,
type_name, write_stl, BRepAlgoAPI_Fuse_ctor, BRepBuilderAPI_MakeEdge_CurveSurface2d,
BRepBuilderAPI_MakeEdge_HandleGeomCurve, BRepBuilderAPI_MakeFace_wire,
BRepBuilderAPI_MakeWire_ctor, BRepBuilderAPI_MakeWire_edge_edge,
BRepBuilderAPI_MakeWire_edge_edge_edge, BRepBuilderAPI_Transform_ctor,
BRepFilletAPI_MakeFillet_ctor, BRepLibBuildCurves3d, BRepMesh_IncrementalMesh_ctor,
BRepOffsetAPI_MakeThickSolid_ctor, BRepOffsetAPI_ThruSections_ctor,
BRepPrimAPI_MakeCylinder_ctor, BRepPrimAPI_MakePrism_ctor, BRep_Builder_ctor,
BRep_Builder_upcast_to_topods_builder, BRep_Tool_Surface, DynamicType, ExplorerCurrentShape,
GCE2d_MakeSegment_point_point, GC_MakeArcOfCircle_Value, GC_MakeArcOfCircle_point_point_point,
GC_MakeSegment_Value, GC_MakeSegment_point_point, Geom2d_Ellipse_ctor,
Geom2d_TrimmedCurve_ctor, Geom_CylindricalSurface_ctor, HandleGeom2d_TrimmedCurve_to_curve,
MakeThickSolidByJoin, StlAPI_Writer_ctor, TopAbs_ShapeEnum, TopExp_Explorer_ctor,
TopoDS_Compound_as_shape, TopoDS_Compound_ctor, TopoDS_Face, TopoDS_Face_to_owned,
TopoDS_cast_to_edge, TopoDS_cast_to_face, TopoDS_cast_to_wire,
use opencascade_sys::{
b_rep_mesh::IncrementalMesh,
ffi::{
cylinder_to_surface, ellipse_to_HandleGeom2d_Curve, ellipse_value, gp_Ax2_ctor,
gp_Ax2d_ctor, gp_Ax3_from_gp_Ax2, gp_DZ, gp_Dir2d_ctor, gp_OX, handle_geom_plane_location,
new_HandleGeomCurve_from_HandleGeom_TrimmedCurve,
new_HandleGeomPlane_from_HandleGeomSurface, new_list_of_shape, new_point, new_point_2d,
new_transform, new_vec, shape_list_append_face, type_name, BRepAlgoAPI_Fuse_ctor,
BRepBuilderAPI_MakeEdge_CurveSurface2d, BRepBuilderAPI_MakeEdge_HandleGeomCurve,
BRepBuilderAPI_MakeFace_wire, BRepBuilderAPI_MakeWire_ctor,
BRepBuilderAPI_MakeWire_edge_edge, BRepBuilderAPI_MakeWire_edge_edge_edge,
BRepBuilderAPI_Transform_ctor, BRepFilletAPI_MakeFillet_ctor, BRepLibBuildCurves3d,
BRepOffsetAPI_MakeThickSolid_ctor, BRepOffsetAPI_ThruSections_ctor,
BRepPrimAPI_MakeCylinder_ctor, BRepPrimAPI_MakePrism_ctor, BRep_Builder_ctor,
BRep_Builder_upcast_to_topods_builder, BRep_Tool_Surface, DynamicType,
ExplorerCurrentShape, GCE2d_MakeSegment_point_point, GC_MakeArcOfCircle_Value,
GC_MakeArcOfCircle_point_point_point, GC_MakeSegment_Value, GC_MakeSegment_point_point,
Geom2d_Ellipse_ctor, Geom2d_TrimmedCurve_ctor, Geom_CylindricalSurface_ctor,
HandleGeom2d_TrimmedCurve_to_curve, MakeThickSolidByJoin, TopAbs_ShapeEnum,
TopExp_Explorer_ctor, TopoDS_Compound_as_shape, TopoDS_Compound_ctor, TopoDS_Face,
TopoDS_Face_to_owned, TopoDS_cast_to_edge, TopoDS_cast_to_face, TopoDS_cast_to_wire,
},
stl_api,
};

// All dimensions are in millimeters.
Expand Down Expand Up @@ -217,9 +221,9 @@ pub fn main() {
let final_shape = compound_shape;

// Export to an STL file
let mut stl_writer = StlAPI_Writer_ctor();
let triangulation = BRepMesh_IncrementalMesh_ctor(&final_shape, 0.01);
let success = write_stl(stl_writer.pin_mut(), triangulation.Shape(), "bottle.stl".to_owned());
let mut stl_writer = stl_api::Writer::new();
let triangulation = IncrementalMesh::new(&final_shape, 0.01);
let success = stl_writer.pin_mut().write_stl(triangulation.Shape(), "bottle.stl".to_owned());

println!("Done! Success = {success}");
}
55 changes: 55 additions & 0 deletions crates/opencascade-sys/src/b_rep_g_prop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::pin::Pin;

pub use inner::*;

#[cxx::bridge]
mod inner {
unsafe extern "C++" {
include!("opencascade-sys/include/wrapper.hxx");

type TopoDS_Shape = crate::ffi::TopoDS_Shape;
type TopoDS_Face = crate::ffi::TopoDS_Face;
type gp_Ax1 = crate::ffi::gp_Ax1;
type gp_Pnt = crate::ffi::gp_Pnt;
type gp_Vec = crate::ffi::gp_Vec;

#[cxx_name = "GProp_GProps"]
type GProps = crate::g_prop::GProps;

fn BRepGProp_LinearProperties(shape: &TopoDS_Shape, props: Pin<&mut GProps>);
fn BRepGProp_SurfaceProperties(shape: &TopoDS_Shape, props: Pin<&mut GProps>);
fn BRepGProp_VolumeProperties(shape: &TopoDS_Shape, props: Pin<&mut GProps>);

type BRepGProp;
#[cxx_name = "BRepGProp_Face"]
type Face;

#[cxx_name = "construct_unique"]
fn Face_new(face: &TopoDS_Face) -> UniquePtr<Face>;
fn Normal(self: &Face, u: f64, v: f64, point: Pin<&mut gp_Pnt>, normal: Pin<&mut gp_Vec>);
}
}

impl BRepGProp {
pub fn linear_properties(shape: &TopoDS_Shape, props: Pin<&mut GProps>) {
inner::BRepGProp_LinearProperties(shape, props)
}

pub fn surface_properties(shape: &TopoDS_Shape, props: Pin<&mut GProps>) {
inner::BRepGProp_SurfaceProperties(shape, props)
}

pub fn volume_properties(shape: &TopoDS_Shape, props: Pin<&mut GProps>) {
inner::BRepGProp_VolumeProperties(shape, props)
}
}

impl Face {
pub fn new(face: &TopoDS_Face) -> cxx::UniquePtr<Face> {
Face_new(face)
}

pub fn normal(&self, u: f64, v: f64, point: Pin<&mut gp_Pnt>, normal: Pin<&mut gp_Vec>) {
self.Normal(u, v, point, normal);
}
}
35 changes: 35 additions & 0 deletions crates/opencascade-sys/src/b_rep_mesh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use cxx::UniquePtr;
pub use inner::*;

#[cxx::bridge]
mod inner {
unsafe extern "C++" {
include!("opencascade-sys/include/wrapper.hxx");

type TopoDS_Shape = crate::ffi::TopoDS_Shape;

#[cxx_name = "BRepMesh_IncrementalMesh"]
type IncrementalMesh;

#[cxx_name = "construct_unique"]
fn IncrementalMesh_new(shape: &TopoDS_Shape, deflection: f64)
-> UniquePtr<IncrementalMesh>;

fn Shape(self: &IncrementalMesh) -> &TopoDS_Shape;
fn IsDone(self: &IncrementalMesh) -> bool;
}
}

impl IncrementalMesh {
pub fn new(shape: &TopoDS_Shape, deflection: f64) -> UniquePtr<Self> {
IncrementalMesh_new(shape, deflection)
}

pub fn shape(&self) -> &TopoDS_Shape {
self.Shape()
}

pub fn is_done(&self) -> bool {
self.IsDone()
}
}
22 changes: 22 additions & 0 deletions crates/opencascade-sys/src/b_rep_tools.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use cxx::UniquePtr;
pub use inner::*;

#[cxx::bridge]
mod inner {
unsafe extern "C++" {
include!("opencascade-sys/include/wrapper.hxx");

type TopoDS_Face = crate::ffi::TopoDS_Face;
type TopoDS_Wire = crate::ffi::TopoDS_Wire;

type BRepTools;

fn outer_wire(face: &TopoDS_Face) -> UniquePtr<TopoDS_Wire>;
}
}

impl BRepTools {
pub fn outer_wire(face: &TopoDS_Face) -> UniquePtr<TopoDS_Wire> {
outer_wire(face)
}
}
50 changes: 50 additions & 0 deletions crates/opencascade-sys/src/g_prop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use cxx::UniquePtr;

pub use inner::*;

#[cxx::bridge]
mod inner {
unsafe extern "C++" {
include!("opencascade-sys/include/wrapper.hxx");

type gp_Ax1 = crate::ffi::gp_Ax1;
type gp_Pnt = crate::ffi::gp_Pnt;

#[cxx_name = "GProp_GProps"]
type GProps;

#[cxx_name = "construct_unique"]
fn GProps_new() -> UniquePtr<GProps>;
fn Mass(self: &GProps) -> f64;
fn StaticMoments(self: &GProps, lx: &mut f64, ly: &mut f64, lz: &mut f64);
fn MomentOfInertia(self: &GProps, axis: &gp_Ax1) -> f64;
fn RadiusOfGyration(self: &GProps, axis: &gp_Ax1) -> f64;
fn GProp_GProps_CentreOfMass(props: &GProps) -> UniquePtr<gp_Pnt>;
}
}

impl GProps {
pub fn new() -> cxx::UniquePtr<Self> {
GProps_new()
}

pub fn mass(&self) -> f64 {
self.Mass()
}

pub fn static_moments(&self, lx: &mut f64, ly: &mut f64, lz: &mut f64) {
self.StaticMoments(lx, ly, lz)
}

pub fn moment_of_inertia(&self, axis: &gp_Ax1) -> f64 {
self.MomentOfInertia(axis)
}

pub fn radius_of_gyration(&self, axis: &gp_Ax1) -> f64 {
self.RadiusOfGyration(axis)
}

pub fn center_of_mass(&self) -> UniquePtr<gp_Pnt> {
GProp_GProps_CentreOfMass(self)
}
}
45 changes: 45 additions & 0 deletions crates/opencascade-sys/src/gc_pnts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use cxx::UniquePtr;
pub use inner::*;

#[cxx::bridge]
mod inner {
unsafe extern "C++" {
include!("opencascade-sys/include/wrapper.hxx");

type gp_Pnt = crate::ffi::gp_Pnt;
type BRepAdaptor_Curve = crate::ffi::BRepAdaptor_Curve;

#[cxx_name = "GCPnts_TangentialDeflection"]
type TangentialDeflection;

#[cxx_name = "construct_unique"]
fn TangentialDeflection_new(
curve: &BRepAdaptor_Curve,
angular_deflection: f64,
curvature_deflection: f64,
) -> UniquePtr<TangentialDeflection>;
fn NbPoints(self: &TangentialDeflection) -> i32;
fn GCPnts_TangentialDeflection_Value(
approximator: &TangentialDeflection,
index: i32,
) -> UniquePtr<gp_Pnt>;
}
}

impl TangentialDeflection {
pub fn new(
curve: &BRepAdaptor_Curve,
angular_deflection: f64,
curvature_deflection: f64,
) -> cxx::UniquePtr<Self> {
TangentialDeflection_new(curve, angular_deflection, curvature_deflection)
}

pub fn num_points(&self) -> i32 {
self.NbPoints()
}

pub fn value(&self, index: i32) -> UniquePtr<gp_Pnt> {
GCPnts_TangentialDeflection_Value(self, index)
}
}
Loading