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
7 changes: 7 additions & 0 deletions crates/opencascade-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ fn main() {

if is_windows {
println!("cargo:rustc-link-lib=dylib=user32");
// MSVC only: TKernel's
// OSD_* (file protection, process user name, registry-based debug
// flags) needs the Win32 security/registry API, which isn't pulled in
// by anything else here. Without it, linking any binary against
// opencascade-sys fails with ~23 unresolved externals (SetFileSecurityW,
// OpenProcessToken, GetTokenInformation, RegOpenKeyExW, ...).
println!("cargo:rustc-link-lib=dylib=advapi32");
}

// TODO(bschwind) - Iterate over the src/ directory to populate this.
Expand Down
6 changes: 3 additions & 3 deletions crates/opencascade-sys/include/b_rep.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
inline const TopoDS_Builder &BRep_Builder_upcast_to_topods_builder(const BRep_Builder &builder) { return builder; }

inline std::unique_ptr<Handle_Geom_Surface> BRep_Tool_Surface(const TopoDS_Face &face) {
return std::unique_ptr<Handle_Geom_Surface>(new opencascade::handle<Geom_Surface>(BRep_Tool::Surface(face)));
return std::unique_ptr<Handle_Geom_Surface>(new Handle_Geom_Surface(BRep_Tool::Surface(face)));
}

inline std::unique_ptr<Handle_Geom_Curve> BRep_Tool_Curve(const TopoDS_Edge &edge, Standard_Real &first,
Standard_Real &last) {
return std::unique_ptr<Handle_Geom_Curve>(new opencascade::handle<Geom_Curve>(BRep_Tool::Curve(edge, first, last)));
return std::unique_ptr<Handle_Geom_Curve>(new Handle_Geom_Curve(BRep_Tool::Curve(edge, first, last)));
}

inline std::unique_ptr<gp_Pnt> BRep_Tool_Pnt(const TopoDS_Vertex &vertex) {
Expand All @@ -28,5 +28,5 @@ inline std::unique_ptr<gp_Pnt> BRep_Tool_Pnt(const TopoDS_Vertex &vertex) {
inline std::unique_ptr<Handle_Poly_Triangulation> BRep_Tool_Triangulation(const TopoDS_Face &face,
TopLoc_Location &location) {
return std::unique_ptr<Handle_Poly_Triangulation>(
new opencascade::handle<Poly_Triangulation>(BRep_Tool::Triangulation(face, location)));
new Handle_Poly_Triangulation(BRep_Tool::Triangulation(face, location)));
}
13 changes: 13 additions & 0 deletions crates/opencascade-sys/include/b_rep_lib.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@
#include <BRepLib_ToolTriangulatedShape.hxx>
#include <TopoDS_Shape.hxx>
#include <bindings_common.hxx>

// MSVC only: `Handle_Poly_Triangulation` is a distinct subclass of
// `opencascade::handle<Poly_Triangulation>` there (see
// Standard_Handle.hxx), so a function pointer to
// `BRepLib_ToolTriangulatedShape::ComputeNormals` (declared with
// `Handle(Poly_Triangulation)`, i.e. the base type) doesn't exact-match a
// `Handle_Poly_Triangulation` parameter. An inline wrapper sidesteps the
// function-pointer binding entirely; the implicit conversion at the call
// site is fine either way.
inline void BRepLib_ToolTriangulatedShape_ComputeNormals(const TopoDS_Face &face,
const Handle_Poly_Triangulation &triangulation) {
BRepLib_ToolTriangulatedShape::ComputeNormals(face, triangulation);
}
12 changes: 12 additions & 0 deletions crates/opencascade-sys/include/b_rep_offset_api.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@
#include <TopTools_ListOfShape.hxx>
#include <TopoDS_Shape.hxx>
#include <bindings_common.hxx>

// MSVC only: a
// member-function pointer to `BRepOffsetAPI_MakePipeShell::SetLaw`
// doesn't exact-match `Handle_Law_Function` (a distinct subclass of
// `opencascade::handle<Law_Function>` under MSVC) against OCCT's own
// `Handle(Law_Function)`-typed parameter. A free-function wrapper
// sidesteps the pointer-type binding.
inline void BRepOffsetAPI_MakePipeShell_SetLaw(BRepOffsetAPI_MakePipeShell &shell, const TopoDS_Shape &profile,
const Handle_Law_Function &law, bool with_contact,
bool with_correction) {
shell.SetLaw(profile, law, with_contact, with_correction);
}
12 changes: 8 additions & 4 deletions crates/opencascade-sys/include/gc.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
#include <bindings_common.hxx>

inline std::unique_ptr<Handle_Geom_TrimmedCurve> GC_MakeSegment_Value(const GC_MakeSegment &segment) {
return std::unique_ptr<Handle_Geom_TrimmedCurve>(new opencascade::handle<Geom_TrimmedCurve>(segment.Value()));
return std::unique_ptr<Handle_Geom_TrimmedCurve>(new Handle_Geom_TrimmedCurve(segment.Value()));
}

inline std::unique_ptr<Handle_Geom2d_TrimmedCurve> GCE2d_MakeSegment_point_point(const gp_Pnt2d &p1,
const gp_Pnt2d &p2) {
return std::unique_ptr<Handle_Geom2d_TrimmedCurve>(
new opencascade::handle<Geom2d_TrimmedCurve>(GCE2d_MakeSegment(p1, p2)));
// MSVC only: `Handle_Geom2d_TrimmedCurve`'s
// own constructors don't accept `GCE2d_MakeSegment`'s implicit conversion directly (it lands
// on a `const opencascade::handle<...>&&` overload and loses the const qualifier). Converting
// through a plain `opencascade::handle<...>` lvalue first sidesteps that.
opencascade::handle<Geom2d_TrimmedCurve> segment_handle = GCE2d_MakeSegment(p1, p2);
return std::unique_ptr<Handle_Geom2d_TrimmedCurve>(new Handle_Geom2d_TrimmedCurve(segment_handle));
}

inline std::unique_ptr<Handle_Geom_TrimmedCurve> GC_MakeArcOfCircle_Value(const GC_MakeArcOfCircle &arc) {
return std::unique_ptr<Handle_Geom_TrimmedCurve>(new opencascade::handle<Geom_TrimmedCurve>(arc.Value()));
return std::unique_ptr<Handle_Geom_TrimmedCurve>(new Handle_Geom_TrimmedCurve(arc.Value()));
}
10 changes: 5 additions & 5 deletions crates/opencascade-sys/include/geom.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

inline std::unique_ptr<Handle_Geom_CylindricalSurface> Geom_CylindricalSurface_new(const gp_Ax3 &axis, double radius) {
return std::unique_ptr<Handle_Geom_CylindricalSurface>(
new opencascade::handle<Geom_CylindricalSurface>(new Geom_CylindricalSurface(axis, radius)));
new Handle_Geom_CylindricalSurface(new Geom_CylindricalSurface(axis, radius)));
}

inline std::unique_ptr<Handle_Geom_Surface> cylinder_to_surface(const Handle_Geom_CylindricalSurface &cylinder_handle) {
return std::unique_ptr<Handle_Geom_Surface>(new opencascade::handle<Geom_Surface>(cylinder_handle));
return std::unique_ptr<Handle_Geom_Surface>(new Handle_Geom_Surface(cylinder_handle));
}

inline std::unique_ptr<Handle_Geom_BezierSurface> Geom_BezierSurface_new(const TColgp_Array2OfPnt &poles) {
return std::unique_ptr<Handle_Geom_BezierSurface>(
new opencascade::handle<Geom_BezierSurface>(new Geom_BezierSurface(poles)));
new Handle_Geom_BezierSurface(new Geom_BezierSurface(poles)));
}

inline const gp_Pnt &handle_geom_plane_location(const Handle_Geom_Plane &plane) { return plane->Location(); }
Expand All @@ -29,13 +29,13 @@ Geom_BezierCurve_to_handle(std::unique_ptr<Geom_BezierCurve> bezier_curve) {
}

inline std::unique_ptr<Handle_Geom_Surface> bezier_to_surface(const Handle_Geom_BezierSurface &bezier_handle) {
return std::unique_ptr<Handle_Geom_Surface>(new opencascade::handle<Geom_Surface>(bezier_handle));
return std::unique_ptr<Handle_Geom_Surface>(new Handle_Geom_Surface(bezier_handle));
}

inline std::unique_ptr<Handle_Geom_Plane>
new_HandleGeomPlane_from_HandleGeomSurface(const Handle_Geom_Surface &surface) {
Handle_Geom_Plane plane_handle = opencascade::handle<Geom_Plane>::DownCast(surface);
return std::unique_ptr<Handle_Geom_Plane>(new opencascade::handle<Geom_Plane>(plane_handle));
return std::unique_ptr<Handle_Geom_Plane>(new Handle_Geom_Plane(plane_handle));
}

inline std::unique_ptr<gp_Pnt> HandleGeomCurve_Value(const Handle_Geom_Curve &curve, const Standard_Real U) {
Expand Down
8 changes: 4 additions & 4 deletions crates/opencascade-sys/include/geom2d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
inline std::unique_ptr<Handle_Geom2d_Ellipse> Geom2d_Ellipse_new(const gp_Ax2d &axis, double major_radius,
double minor_radius) {
return std::unique_ptr<Handle_Geom2d_Ellipse>(
new opencascade::handle<Geom2d_Ellipse>(new Geom2d_Ellipse(axis, major_radius, minor_radius)));
new Handle_Geom2d_Ellipse(new Geom2d_Ellipse(axis, major_radius, minor_radius)));
}

inline std::unique_ptr<Handle_Geom2d_Curve> ellipse_to_HandleGeom2d_Curve(const Handle_Geom2d_Ellipse &ellipse_handle) {
return std::unique_ptr<Handle_Geom2d_Curve>(new opencascade::handle<Geom2d_Curve>(ellipse_handle));
return std::unique_ptr<Handle_Geom2d_Curve>(new Handle_Geom2d_Curve(ellipse_handle));
}

inline std::unique_ptr<Handle_Geom2d_TrimmedCurve> Geom2d_TrimmedCurve_new(const Handle_Geom2d_Curve &curve, double u1,
double u2) {
return std::unique_ptr<Handle_Geom2d_TrimmedCurve>(
new opencascade::handle<Geom2d_TrimmedCurve>(new Geom2d_TrimmedCurve(curve, u1, u2)));
new Handle_Geom2d_TrimmedCurve(new Geom2d_TrimmedCurve(curve, u1, u2)));
}

inline std::unique_ptr<Handle_Geom2d_Curve>
HandleGeom2d_TrimmedCurve_to_curve(const Handle_Geom2d_TrimmedCurve &trimmed_curve) {
return std::unique_ptr<Handle_Geom2d_Curve>(new opencascade::handle<Geom2d_Curve>(trimmed_curve));
return std::unique_ptr<Handle_Geom2d_Curve>(new Handle_Geom2d_Curve(trimmed_curve));
}

inline std::unique_ptr<gp_Pnt2d> ellipse_value(const Handle_Geom2d_Ellipse &ellipse, double u) {
Expand Down
2 changes: 1 addition & 1 deletion crates/opencascade-sys/include/geom_api.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
#include <bindings_common.hxx>

inline std::unique_ptr<Handle_Geom_BSplineCurve> GeomAPI_Interpolate_Curve(const GeomAPI_Interpolate &interpolate) {
return std::unique_ptr<Handle_Geom_BSplineCurve>(new opencascade::handle<Geom_BSplineCurve>(interpolate.Curve()));
return std::unique_ptr<Handle_Geom_BSplineCurve>(new Handle_Geom_BSplineCurve(interpolate.Curve()));
}
10 changes: 10 additions & 0 deletions crates/opencascade-sys/include/poly.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
#include <Poly_Triangulation.hxx>
#include <bindings_common.hxx>

// MSVC only: `handle_try_deref<T>`
// can't be bound directly by function pointer against `Handle_Poly_Triangulation`
// (a distinct subclass of `opencascade::handle<Poly_Triangulation>` under MSVC).
// A thin, exactly-typed wrapper sidesteps the pointer-type binding; the call to
// the template itself is fine since ordinary calls allow the derived-to-base
// reference conversion that function-pointer binding doesn't.
inline const Poly_Triangulation &Handle_Poly_Triangulation_deref(const Handle_Poly_Triangulation &handle) {
return handle_try_deref<Poly_Triangulation>(handle);
}

inline std::unique_ptr<Handle_Poly_Triangulation>
Handle_Poly_Triangulation_new(std::unique_ptr<Poly_Triangulation> triangulation) {
return std::unique_ptr<Handle_Poly_Triangulation>(new Handle_Poly_Triangulation(triangulation.release()));
Expand Down
10 changes: 10 additions & 0 deletions crates/opencascade-sys/include/shape_analysis.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
#include <ShapeAnalysis_FreeBounds.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <bindings_common.hxx>

// MSVC only: same reasoning
// as the other wrappers here - a static-method function pointer doesn't
// exact-match `Handle_TopTools_HSequenceOfShape` against OCCT's own
// `Handle(TopTools_HSequenceOfShape)&`-typed parameters.
inline void ShapeAnalysis_FreeBounds_ConnectEdgesToWires(Handle_TopTools_HSequenceOfShape &edges,
Standard_Real tolerance, Standard_Boolean shared,
Handle_TopTools_HSequenceOfShape &wires) {
ShapeAnalysis_FreeBounds::ConnectEdgesToWires(edges, tolerance, shared, wires);
}
9 changes: 8 additions & 1 deletion crates/opencascade-sys/include/top_tools.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
#include <TopoDS_Face.hxx>
#include <bindings_common.hxx>

// MSVC only: same reasoning
// as Handle_Poly_Triangulation_deref in poly.hxx.
inline const TopTools_HSequenceOfShape &
Handle_TopTools_HSequenceOfShape_deref(const Handle_TopTools_HSequenceOfShape &handle) {
return handle_try_deref<TopTools_HSequenceOfShape>(handle);
}

inline std::unique_ptr<Handle_TopTools_HSequenceOfShape> new_Handle_TopTools_HSequenceOfShape() {
auto sequence = new TopTools_HSequenceOfShape();
auto handle = new opencascade::handle<TopTools_HSequenceOfShape>(sequence);
auto handle = new Handle_TopTools_HSequenceOfShape(sequence);

return std::unique_ptr<Handle_TopTools_HSequenceOfShape>(handle);
}
Expand Down
4 changes: 1 addition & 3 deletions crates/opencascade-sys/src/b_rep_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ mod inner {
#[Self = "BRepLib"]
pub fn BuildCurves3d(shape: &TopoDS_Shape) -> bool;

type BRepLib_ToolTriangulatedShape;
#[Self = "BRepLib_ToolTriangulatedShape"]
pub fn ComputeNormals(face: &TopoDS_Face, triangulation: &Handle_Poly_Triangulation);
pub fn BRepLib_ToolTriangulatedShape_ComputeNormals(face: &TopoDS_Face, triangulation: &Handle_Poly_Triangulation);
}
}
4 changes: 2 additions & 2 deletions crates/opencascade-sys/src/b_rep_offset_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ mod inner {
with_contact: bool,
with_correction: bool,
);
pub fn SetLaw(
self: Pin<&mut BRepOffsetAPI_MakePipeShell>,
pub fn BRepOffsetAPI_MakePipeShell_SetLaw(
shell: Pin<&mut BRepOffsetAPI_MakePipeShell>,
profile: &TopoDS_Shape,
law: &Handle_Law_Function,
with_contact: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/opencascade-sys/src/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod inner {
// Handles
type Handle_Poly_Triangulation;
pub fn IsNull(self: &Handle_Poly_Triangulation) -> bool;
#[cxx_name = "handle_try_deref"]
#[cxx_name = "Handle_Poly_Triangulation_deref"]
pub fn Handle_Poly_Triangulation_Get(
handle: &Handle_Poly_Triangulation,
) -> Result<&Poly_Triangulation>;
Expand Down
4 changes: 1 addition & 3 deletions crates/opencascade-sys/src/shape_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ mod inner {
type TopoDS_Shape = crate::topo_ds::TopoDS_Shape;
type Handle_TopTools_HSequenceOfShape = crate::top_tools::Handle_TopTools_HSequenceOfShape;

type ShapeAnalysis_FreeBounds;
#[Self = "ShapeAnalysis_FreeBounds"]
pub fn ConnectEdgesToWires(
pub fn ShapeAnalysis_FreeBounds_ConnectEdgesToWires(
edges: Pin<&mut Handle_TopTools_HSequenceOfShape>,
tolerance: f64,
shared: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/opencascade-sys/src/top_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod inner {
index: i32,
) -> &TopoDS_Shape;

#[cxx_name = "handle_try_deref"]
#[cxx_name = "Handle_TopTools_HSequenceOfShape_deref"]
pub fn HandleTopTools_HSequenceOfShape_Get(
handle: &Handle_TopTools_HSequenceOfShape,
) -> Result<&TopTools_HSequenceOfShape>;
Expand Down
8 changes: 7 additions & 1 deletion crates/opencascade/src/make_pipe_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ pub(crate) fn make_pipe_shell_with_law_function(
let profile_shape = ffi::topo_ds::cast_wire_to_shape(profile);
let with_contact = false;
let with_correction = true;
make_pipe_shell.pin_mut().SetLaw(profile_shape, law_function, with_contact, with_correction);
ffi::b_rep_offset_api::BRepOffsetAPI_MakePipeShell_SetLaw(
make_pipe_shell.pin_mut(),
profile_shape,
law_function,
with_contact,
with_correction,
);
make_pipe_shell
}
2 changes: 1 addition & 1 deletion crates/opencascade/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Mesher {
// TODO(bschwind) - Use `location` to transform the normals.
let normal_array = ffi::t_col_gp::TColgp_Array1OfDir_new(0, face_point_count);

ffi::b_rep_lib::BRepLib_ToolTriangulatedShape::ComputeNormals(
ffi::b_rep_lib::BRepLib_ToolTriangulatedShape_ComputeNormals(
&face.inner,
&triangulation_handle,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/opencascade/src/primitives/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Wire {
EdgeConnection::Fuzzy { tolerance } => (tolerance, false),
};

ffi::shape_analysis::ShapeAnalysis_FreeBounds::ConnectEdgesToWires(
ffi::shape_analysis::ShapeAnalysis_FreeBounds_ConnectEdgesToWires(
edges.pin_mut(),
tolerance,
shared,
Expand Down