Skip to content
Open
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
3 changes: 3 additions & 0 deletions crates/opencascade-sys/include/b_rep.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
#include <bindings_common.hxx>
#include <gp_Pnt.hxx>

Expand All @@ -30,3 +31,5 @@ inline std::unique_ptr<Handle_Poly_Triangulation> BRep_Tool_Triangulation(const
return std::unique_ptr<Handle_Poly_Triangulation>(
new opencascade::handle<Poly_Triangulation>(BRep_Tool::Triangulation(face, location)));
}

inline bool BRep_Tool_IsClosed(const TopoDS_Wire &wire) { return BRep_Tool::IsClosed(wire); }
10 changes: 10 additions & 0 deletions crates/opencascade-sys/include/b_rep_adaptor.hxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include <BRepAdaptor_Curve.hxx>
#include <bindings_common.hxx>
#include <gp_Circ.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>

inline std::unique_ptr<gp_Pnt> BRepAdaptor_Curve_value(const BRepAdaptor_Curve &curve, const Standard_Real U) {
return std::unique_ptr<gp_Pnt>(new gp_Pnt(curve.Value(U)));
}

inline void BRepAdaptor_Curve_D1(const BRepAdaptor_Curve &curve, const Standard_Real U, gp_Pnt &P, gp_Vec &V1) {
curve.D1(U, P, V1);
}

inline std::unique_ptr<gp_Circ> BRepAdaptor_Curve_Circle(const BRepAdaptor_Curve &curve) {
return std::unique_ptr<gp_Circ>(new gp_Circ(curve.Circle()));
}
79 changes: 79 additions & 0 deletions crates/opencascade-sys/include/geom.hxx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#include <Geom_BSplineCurve.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_Circle.hxx>
#include <Geom_ConicalSurface.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_Plane.hxx>
#include <Geom_SphericalSurface.hxx>
#include <Geom_Surface.hxx>
#include <Geom_ToroidalSurface.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <bindings_common.hxx>
#include <gp_Ax3.hxx>
#include <gp_Circ.hxx>

inline std::unique_ptr<Handle_Geom_CylindricalSurface> Geom_CylindricalSurface_new(const gp_Ax3 &axis, double radius) {
return std::unique_ptr<Handle_Geom_CylindricalSurface>(
Expand Down Expand Up @@ -43,3 +49,76 @@ inline std::unique_ptr<gp_Pnt> HandleGeomCurve_Value(const Handle_Geom_Curve &cu
}

inline const Handle_Standard_Type &DynamicType(const Handle_Geom_Surface &surface) { return surface->DynamicType(); }

inline std::unique_ptr<Handle_Geom_Circle> new_HandleGeomCircle_from_HandleGeomCurve(const Handle_Geom_Curve &curve) {
Handle_Geom_Circle circle_handle = opencascade::handle<Geom_Circle>::DownCast(curve);
return std::unique_ptr<Handle_Geom_Circle>(new opencascade::handle<Geom_Circle>(circle_handle));
}

inline std::unique_ptr<gp_Circ> HandleGeomCircle_Circ(const Handle_Geom_Circle &circle) {
return std::unique_ptr<gp_Circ>(new gp_Circ(circle->Circ()));
}

// CylindricalSurface downcast + accessors

inline std::unique_ptr<Handle_Geom_CylindricalSurface>
new_HandleGeomCylindricalSurface_from_HandleGeomSurface(const Handle_Geom_Surface &surface) {
Handle_Geom_CylindricalSurface handle = opencascade::handle<Geom_CylindricalSurface>::DownCast(surface);
return std::unique_ptr<Handle_Geom_CylindricalSurface>(new opencascade::handle<Geom_CylindricalSurface>(handle));
}

inline double HandleGeomCylindricalSurface_Radius(const Handle_Geom_CylindricalSurface &cyl) { return cyl->Radius(); }

inline const gp_Ax3 &HandleGeomCylindricalSurface_Position(const Handle_Geom_CylindricalSurface &cyl) {
return cyl->Position();
}

// SphericalSurface downcast + accessors

inline std::unique_ptr<Handle_Geom_SphericalSurface>
new_HandleGeomSphericalSurface_from_HandleGeomSurface(const Handle_Geom_Surface &surface) {
Handle_Geom_SphericalSurface handle = opencascade::handle<Geom_SphericalSurface>::DownCast(surface);
return std::unique_ptr<Handle_Geom_SphericalSurface>(new opencascade::handle<Geom_SphericalSurface>(handle));
}

inline double HandleGeomSphericalSurface_Radius(const Handle_Geom_SphericalSurface &sphere) { return sphere->Radius(); }

inline const gp_Ax3 &HandleGeomSphericalSurface_Position(const Handle_Geom_SphericalSurface &sphere) {
return sphere->Position();
}

// ConicalSurface downcast + accessors

inline std::unique_ptr<Handle_Geom_ConicalSurface>
new_HandleGeomConicalSurface_from_HandleGeomSurface(const Handle_Geom_Surface &surface) {
Handle_Geom_ConicalSurface handle = opencascade::handle<Geom_ConicalSurface>::DownCast(surface);
return std::unique_ptr<Handle_Geom_ConicalSurface>(new opencascade::handle<Geom_ConicalSurface>(handle));
}

inline double HandleGeomConicalSurface_RefRadius(const Handle_Geom_ConicalSurface &cone) { return cone->RefRadius(); }

inline double HandleGeomConicalSurface_SemiAngle(const Handle_Geom_ConicalSurface &cone) { return cone->SemiAngle(); }

inline const gp_Ax3 &HandleGeomConicalSurface_Position(const Handle_Geom_ConicalSurface &cone) {
return cone->Position();
}

// ToroidalSurface downcast + accessors

inline std::unique_ptr<Handle_Geom_ToroidalSurface>
new_HandleGeomToroidalSurface_from_HandleGeomSurface(const Handle_Geom_Surface &surface) {
Handle_Geom_ToroidalSurface handle = opencascade::handle<Geom_ToroidalSurface>::DownCast(surface);
return std::unique_ptr<Handle_Geom_ToroidalSurface>(new opencascade::handle<Geom_ToroidalSurface>(handle));
}

inline double HandleGeomToroidalSurface_MajorRadius(const Handle_Geom_ToroidalSurface &torus) {
return torus->MajorRadius();
}

inline double HandleGeomToroidalSurface_MinorRadius(const Handle_Geom_ToroidalSurface &torus) {
return torus->MinorRadius();
}

inline const gp_Ax3 &HandleGeomToroidalSurface_Position(const Handle_Geom_ToroidalSurface &torus) {
return torus->Position();
}
2 changes: 2 additions & 0 deletions crates/opencascade-sys/src/b_rep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod inner {
type TopoDS_Face = crate::topo_ds::TopoDS_Face;
type TopoDS_Edge = crate::topo_ds::TopoDS_Edge;
type TopoDS_Vertex = crate::topo_ds::TopoDS_Vertex;
type TopoDS_Wire = crate::topo_ds::TopoDS_Wire;
type Handle_Geom_Surface = crate::geom::Handle_Geom_Surface;
type Handle_Geom_Curve = crate::geom::Handle_Geom_Curve;
type Handle_Poly_Triangulation = crate::poly::Handle_Poly_Triangulation;
Expand All @@ -32,5 +33,6 @@ mod inner {
face: &TopoDS_Face,
location: Pin<&mut TopLoc_Location>,
) -> UniquePtr<Handle_Poly_Triangulation>;
pub fn BRep_Tool_IsClosed(wire: &TopoDS_Wire) -> bool;
}
}
9 changes: 9 additions & 0 deletions crates/opencascade-sys/src/b_rep_adaptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ mod inner {
include!("opencascade-sys/include/b_rep_adaptor.hxx");

type gp_Pnt = crate::gp::gp_Pnt;
type gp_Vec = crate::gp::gp_Vec;
type gp_Circ = crate::gp::gp_Circ;
type GeomAbs_CurveType = crate::geom_abs::GeomAbs_CurveType;
type TopoDS_Edge = crate::topo_ds::TopoDS_Edge;

Expand All @@ -15,6 +17,13 @@ mod inner {
pub fn FirstParameter(self: &BRepAdaptor_Curve) -> f64;
pub fn LastParameter(self: &BRepAdaptor_Curve) -> f64;
pub fn BRepAdaptor_Curve_value(curve: &BRepAdaptor_Curve, u: f64) -> UniquePtr<gp_Pnt>;
pub fn BRepAdaptor_Curve_D1(
curve: &BRepAdaptor_Curve,
u: f64,
point: Pin<&mut gp_Pnt>,
vec: Pin<&mut gp_Vec>,
);
pub fn BRepAdaptor_Curve_Circle(curve: &BRepAdaptor_Curve) -> UniquePtr<gp_Circ>;
pub fn GetType(self: &BRepAdaptor_Curve) -> GeomAbs_CurveType;
}
}
52 changes: 52 additions & 0 deletions crates/opencascade-sys/src/geom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod inner {

type gp_Ax3 = crate::gp::gp_Ax3;
type gp_Pnt = crate::gp::gp_Pnt;
type gp_Circ = crate::gp::gp_Circ;
type TColgp_Array2OfPnt = crate::t_col_gp::TColgp_Array2OfPnt;
type TColgp_HArray1OfPnt = crate::t_col_gp::TColgp_HArray1OfPnt;
type Handle_Standard_Type = crate::standard::Handle_Standard_Type;
Expand Down Expand Up @@ -35,6 +36,18 @@ mod inner {
type Handle_Geom_Plane;
pub fn IsNull(self: &Handle_Geom_Plane) -> bool;

type Handle_Geom_SphericalSurface;
pub fn IsNull(self: &Handle_Geom_SphericalSurface) -> bool;

type Handle_Geom_ConicalSurface;
pub fn IsNull(self: &Handle_Geom_ConicalSurface) -> bool;

type Handle_Geom_ToroidalSurface;
pub fn IsNull(self: &Handle_Geom_ToroidalSurface) -> bool;

type Handle_Geom_Circle;
pub fn IsNull(self: &Handle_Geom_Circle) -> bool;

type Handle_Geom_CylindricalSurface;
pub fn IsNull(self: &Handle_Geom_CylindricalSurface) -> bool;
// End Handles
Expand Down Expand Up @@ -74,6 +87,41 @@ mod inner {
geom_surface_handle: &Handle_Geom_Surface,
) -> UniquePtr<Handle_Geom_Plane>;

pub fn new_HandleGeomCylindricalSurface_from_HandleGeomSurface(
geom_surface_handle: &Handle_Geom_Surface,
) -> UniquePtr<Handle_Geom_CylindricalSurface>;
pub fn HandleGeomCylindricalSurface_Radius(cyl: &Handle_Geom_CylindricalSurface) -> f64;
pub fn HandleGeomCylindricalSurface_Position(
cyl: &Handle_Geom_CylindricalSurface,
) -> &gp_Ax3;

pub fn new_HandleGeomSphericalSurface_from_HandleGeomSurface(
geom_surface_handle: &Handle_Geom_Surface,
) -> UniquePtr<Handle_Geom_SphericalSurface>;
pub fn HandleGeomSphericalSurface_Radius(sphere: &Handle_Geom_SphericalSurface) -> f64;
pub fn HandleGeomSphericalSurface_Position(
sphere: &Handle_Geom_SphericalSurface,
) -> &gp_Ax3;

pub fn new_HandleGeomConicalSurface_from_HandleGeomSurface(
geom_surface_handle: &Handle_Geom_Surface,
) -> UniquePtr<Handle_Geom_ConicalSurface>;
pub fn HandleGeomConicalSurface_RefRadius(cone: &Handle_Geom_ConicalSurface) -> f64;
pub fn HandleGeomConicalSurface_SemiAngle(cone: &Handle_Geom_ConicalSurface) -> f64;
pub fn HandleGeomConicalSurface_Position(cone: &Handle_Geom_ConicalSurface) -> &gp_Ax3;

pub fn new_HandleGeomToroidalSurface_from_HandleGeomSurface(
geom_surface_handle: &Handle_Geom_Surface,
) -> UniquePtr<Handle_Geom_ToroidalSurface>;
pub fn HandleGeomToroidalSurface_MajorRadius(torus: &Handle_Geom_ToroidalSurface) -> f64;
pub fn HandleGeomToroidalSurface_MinorRadius(torus: &Handle_Geom_ToroidalSurface) -> f64;
pub fn HandleGeomToroidalSurface_Position(torus: &Handle_Geom_ToroidalSurface) -> &gp_Ax3;

pub fn new_HandleGeomCircle_from_HandleGeomCurve(
curve: &Handle_Geom_Curve,
) -> UniquePtr<Handle_Geom_Circle>;
pub fn HandleGeomCircle_Circ(circle: &Handle_Geom_Circle) -> UniquePtr<gp_Circ>;

#[cxx_name = "construct_unique"]
pub fn new_HandleGeomCurve_from_HandleGeom_BSplineCurve(
bspline_curve_handle: &Handle_Geom_BSplineCurve,
Expand All @@ -90,7 +138,11 @@ mod inner {
) -> UniquePtr<Handle_Geom_Curve>;
}

impl UniquePtr<Handle_Geom_Circle> {}
impl UniquePtr<Handle_Geom_CylindricalSurface> {}
impl UniquePtr<Handle_Geom_SphericalSurface> {}
impl UniquePtr<Handle_Geom_ConicalSurface> {}
impl UniquePtr<Handle_Geom_ToroidalSurface> {}
impl UniquePtr<Handle_Geom_BezierSurface> {}
impl UniquePtr<Handle_Geom_BezierCurve> {}
impl UniquePtr<Handle_Geom_Plane> {}
Expand Down
6 changes: 6 additions & 0 deletions crates/opencascade-sys/src/gp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ mod inner {
type gp_Circ;
#[cxx_name = "construct_unique"]
pub fn gp_Circ_new(axis: &gp_Ax2, radius: f64) -> UniquePtr<gp_Circ>;
pub fn Radius(self: &gp_Circ) -> f64;
pub fn Position(self: &gp_Circ) -> &gp_Ax2;

type gp_Ax1;
#[cxx_name = "construct_unique"]
Expand All @@ -53,10 +55,14 @@ mod inner {
type gp_Ax2;
#[cxx_name = "construct_unique"]
pub fn gp_Ax2_new(origin: &gp_Pnt, main_dir: &gp_Dir) -> UniquePtr<gp_Ax2>;
pub fn Location(self: &gp_Ax2) -> &gp_Pnt;
pub fn Direction(self: &gp_Ax2) -> &gp_Dir;

type gp_Ax3;
#[cxx_name = "construct_unique"]
pub fn gp_Ax3_from_gp_Ax2(axis: &gp_Ax2) -> UniquePtr<gp_Ax3>;
pub fn Location(self: &gp_Ax3) -> &gp_Pnt;
pub fn Direction(self: &gp_Ax3) -> &gp_Dir;

type gp_Dir2d;
#[cxx_name = "construct_unique"]
Expand Down
39 changes: 39 additions & 0 deletions crates/opencascade/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ pub use surface::*;
pub use vertex::*;
pub use wire::*;

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum PositionMode {
Parameter,
Length,
}

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ShapeType {
/// Abstract topological data structure describes a basic entity.
Expand Down Expand Up @@ -267,3 +273,36 @@ impl From<JoinType> for ffi::geom_abs::GeomAbs_JoinType {
}
}
}

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum SurfaceType {
Plane,
Cylinder,
Cone,
Sphere,
Torus,
BezierSurface,
BSplineSurface,
SurfaceOfRevolution,
SurfaceOfExtrusion,
OffsetSurface,
OtherSurface,
}

impl std::fmt::Display for SurfaceType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SurfaceType::Plane => write!(f, "Plane"),
SurfaceType::Cylinder => write!(f, "Cylinder"),
SurfaceType::Cone => write!(f, "Cone"),
SurfaceType::Sphere => write!(f, "Sphere"),
SurfaceType::Torus => write!(f, "Torus"),
SurfaceType::BezierSurface => write!(f, "BezierSurface"),
SurfaceType::BSplineSurface => write!(f, "BSplineSurface"),
SurfaceType::SurfaceOfRevolution => write!(f, "SurfaceOfRevolution"),
SurfaceType::SurfaceOfExtrusion => write!(f, "SurfaceOfExtrusion"),
SurfaceType::OffsetSurface => write!(f, "OffsetSurface"),
SurfaceType::OtherSurface => write!(f, "OtherSurface"),
}
}
}
51 changes: 50 additions & 1 deletion crates/opencascade/src/primitives/edge.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::make_vec;
use crate::primitives::{make_axis_2, make_point};
use crate::primitives::{make_axis_2, make_point, PositionMode};
use cxx::UniquePtr;
use glam::{dvec3, DVec3};
use opencascade_sys as ffi;
Expand Down Expand Up @@ -174,6 +174,55 @@ impl Edge {

EdgeType::from(curve.GetType())
}

pub fn length(&self) -> f64 {
let mut props = ffi::g_prop::GProps_new();
ffi::b_rep_g_prop::BRepGProp::LinearProperties(
ffi::topo_ds::cast_edge_to_shape(&self.inner),
props.pin_mut(),
false,
false,
);
props.Mass()
}

pub fn tangent_at(&self, position: f64, mode: PositionMode) -> DVec3 {
let curve = ffi::b_rep_adaptor::BRepAdaptor_Curve_new(&self.inner);
let param = match mode {
PositionMode::Parameter => position,
PositionMode::Length => {
let first = curve.FirstParameter();
let last = curve.LastParameter();
first + position * (last - first)
},
};

let mut point = ffi::gp::new_point(0.0, 0.0, 0.0);
let mut vec = ffi::gp::new_vec(0.0, 0.0, 0.0);
ffi::b_rep_adaptor::BRepAdaptor_Curve_D1(&curve, param, point.pin_mut(), vec.pin_mut());

dvec3(vec.X(), vec.Y(), vec.Z()).normalize()
}

pub fn arc_center(&self) -> Option<DVec3> {
let curve = ffi::b_rep_adaptor::BRepAdaptor_Curve_new(&self.inner);
if curve.GetType() != ffi::geom_abs::GeomAbs_CurveType::GeomAbs_Circle {
return None;
}
let circ = ffi::b_rep_adaptor::BRepAdaptor_Curve_Circle(&curve);
let pos = circ.Position();
let loc = pos.Location();
Some(dvec3(loc.X(), loc.Y(), loc.Z()))
}

pub fn radius(&self) -> Option<f64> {
let curve = ffi::b_rep_adaptor::BRepAdaptor_Curve_new(&self.inner);
if curve.GetType() != ffi::geom_abs::GeomAbs_CurveType::GeomAbs_Circle {
return None;
}
let circ = ffi::b_rep_adaptor::BRepAdaptor_Curve_Circle(&curve);
Some(circ.Radius())
}
}

pub struct ApproximationSegmentIterator {
Expand Down
Loading
Loading