Skip to content

Commit

Permalink
init | rsrch : first commit
Browse files Browse the repository at this point in the history
Related to a-givertzman/mdmt-server#5 (rsrch).
  • Loading branch information
novartole committed Nov 13, 2024
1 parent ba2a149 commit bf5704b
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 90 deletions.
2 changes: 1 addition & 1 deletion crates/occt-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
.define("USE_OPENGL", "FALSE")
.define("USE_OPENVR", "FALSE")
.define("USE_RAPIDJSON", "FALSE")
.define("USE_TBB", "FALSE")
.define("USE_TBB", "TRUE")
.define("USE_TCL", "FALSE")
.define("USE_TK", "FALSE")
.define("USE_VTK", "FALSE")
Expand Down
35 changes: 16 additions & 19 deletions crates/opencascade-sys/include/wrapper.hxx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "rust/cxx.h"
#include <BOPAlgo_GlueEnum.hxx>
#include <BOPAlgo_MakerVolume.hxx>
#include <BOPAlgo_Operation.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepAlgoAPI_Section.hxx>
#include <BRepBuilderAPI_GTransform.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeShapeOnMesh.hxx>
Expand Down Expand Up @@ -44,7 +45,6 @@
#include <GProp_GProps.hxx>
#include <Geom2d_Ellipse.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <GeomAbs_CurveType.hxx>
#include <GeomAbs_JoinType.hxx>
Expand All @@ -65,7 +65,6 @@
#include <Standard_Type.hxx>
#include <StlAPI_Writer.hxx>
#include <TColgp_Array1OfDir.hxx>
#include <TColgp_HArray1OfPnt.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_HSequenceOfShape.hxx>
Expand All @@ -92,10 +91,23 @@ template <typename T> std::unique_ptr<std::vector<T>> list_to_vector(const NColl
return std::unique_ptr<std::vector<T>>(new std::vector<T>(list.begin(), list.end()));
}

inline void shape_list_append_shape(TopTools_ListOfShape &list, const TopoDS_Shape &shape) { list.Append(shape); }

inline void SetRunParallel_BRepAlgoAPI_Common(BRepAlgoAPI_Common &theBOP, bool theFlag) {
theBOP.SetRunParallel(theFlag);
}
inline void SetUseOBB_BRepAlgoAPI_Common(BRepAlgoAPI_Common &theBOP, bool theFlag) { theBOP.SetUseOBB(theFlag); }
inline void SetFuzzyValue_BRepAlgoAPI_Common(BRepAlgoAPI_Common &theBOP, double theFuzz) {
theBOP.SetFuzzyValue(theFuzz);
}

inline bool HasErrors_BRepAlgoAPI_Common(const BRepAlgoAPI_Common &theBOP) { return theBOP.HasErrors(); }

inline const TopoDS_Shape &BOPAlgo_MakerVolume_Shape(const BOPAlgo_MakerVolume &aMV) { return aMV.Shape(); }

// Handles
typedef opencascade::handle<Standard_Type> HandleStandardType;
typedef opencascade::handle<Geom_Curve> HandleGeomCurve;
typedef opencascade::handle<Geom_BSplineCurve> HandleGeomBSplineCurve;
typedef opencascade::handle<Geom_TrimmedCurve> HandleGeomTrimmedCurve;
typedef opencascade::handle<Geom_Surface> HandleGeomSurface;
typedef opencascade::handle<Geom_BezierSurface> HandleGeomBezierSurface;
Expand All @@ -108,13 +120,6 @@ typedef opencascade::handle<Poly_Triangulation> Handle_Poly_Triangulation;
typedef opencascade::handle<TopTools_HSequenceOfShape> Handle_TopTools_HSequenceOfShape;
typedef opencascade::handle<Law_Function> HandleLawFunction;

typedef opencascade::handle<TColgp_HArray1OfPnt> Handle_TColgpHArray1OfPnt;

inline std::unique_ptr<Handle_TColgpHArray1OfPnt>
new_HandleTColgpHArray1OfPnt_from_TColgpHArray1OfPnt(std::unique_ptr<TColgp_HArray1OfPnt> array) {
return std::unique_ptr<Handle_TColgpHArray1OfPnt>(new Handle_TColgpHArray1OfPnt(array.release()));
}

// Handle stuff
template <typename T> const T &handle_try_deref(const opencascade::handle<T> &handle) {
if (handle.IsNull()) {
Expand Down Expand Up @@ -152,10 +157,6 @@ inline std::unique_ptr<HandleGeom_CylindricalSurface> Geom_CylindricalSurface_ct
new opencascade::handle<Geom_CylindricalSurface>(new Geom_CylindricalSurface(axis, radius)));
}

inline std::unique_ptr<HandleGeomBSplineCurve> GeomAPI_Interpolate_Curve(const GeomAPI_Interpolate &interpolate) {
return std::unique_ptr<HandleGeomBSplineCurve>(new opencascade::handle<Geom_BSplineCurve>(interpolate.Curve()));
}

inline std::unique_ptr<HandleGeomSurface> cylinder_to_surface(const HandleGeom_CylindricalSurface &cylinder_handle) {
return std::unique_ptr<HandleGeomSurface>(new opencascade::handle<Geom_Surface>(cylinder_handle));
}
Expand Down Expand Up @@ -463,10 +464,6 @@ inline std::unique_ptr<gp_Pnt2d> TColgp_Array1OfPnt2d_Value(const TColgp_Array1O
return std::unique_ptr<gp_Pnt2d>(new gp_Pnt2d(array.Value(index)));
}

inline std::unique_ptr<gp_Pnt> TColgp_HArray1OfPnt_Value(const TColgp_HArray1OfPnt &array, Standard_Integer index) {
return std::unique_ptr<gp_Pnt>(new gp_Pnt(array.Value(index)));
}

inline void connect_edges_to_wires(Handle_TopTools_HSequenceOfShape &edges, const Standard_Real toler,
const Standard_Boolean shared, Handle_TopTools_HSequenceOfShape &wires) {
ShapeAnalysis_FreeBounds::ConnectEdgesToWires(edges, toler, shared, wires);
Expand Down
112 changes: 44 additions & 68 deletions crates/opencascade-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#[cxx::bridge]
pub mod ffi {
#[derive(Debug)]
#[repr(u32)]
pub enum BOPAlgo_Operation {
BOPAlgo_COMMON,
BOPAlgo_FUSE,
BOPAlgo_CUT,
BOPAlgo_CUT21,
BOPAlgo_SECTION,
BOPAlgo_UNKNOWN,
}

#[repr(u32)]
#[derive(Debug)]
pub enum TopAbs_ShapeEnum {
Expand Down Expand Up @@ -77,7 +88,6 @@ pub mod ffi {
// Handles
type HandleStandardType;
type HandleGeomCurve;
type HandleGeomBSplineCurve;
type HandleGeomTrimmedCurve;
type HandleGeomSurface;
type HandleGeomBezierSurface;
Expand All @@ -89,19 +99,9 @@ pub mod ffi {
type Handle_TopTools_HSequenceOfShape;
type HandleLawFunction;

type Handle_TColgpHArray1OfPnt;
pub fn new_HandleTColgpHArray1OfPnt_from_TColgpHArray1OfPnt(
array: UniquePtr<TColgp_HArray1OfPnt>,
) -> UniquePtr<Handle_TColgpHArray1OfPnt>;

pub fn DynamicType(surface: &HandleGeomSurface) -> &HandleStandardType;
pub fn type_name(handle: &HandleStandardType) -> String;

#[cxx_name = "construct_unique"]
pub fn new_HandleGeomCurve_from_HandleGeom_BSplineCurve(
bspline_curve_handle: &HandleGeomBSplineCurve,
) -> UniquePtr<HandleGeomCurve>;

#[cxx_name = "construct_unique"]
pub fn new_HandleGeomCurve_from_HandleGeom_TrimmedCurve(
trimmed_curve_handle: &HandleGeomTrimmedCurve,
Expand Down Expand Up @@ -131,6 +131,7 @@ pub mod ffi {
#[cxx_name = "construct_unique"]
pub fn new_list_of_shape() -> UniquePtr<TopTools_ListOfShape>;
pub fn shape_list_append_face(list: Pin<&mut TopTools_ListOfShape>, face: &TopoDS_Face);
pub fn shape_list_append_shape(list: Pin<&mut TopTools_ListOfShape>, face: &TopoDS_Shape);
pub fn Size(self: &TopTools_ListOfShape) -> i32;

#[cxx_name = "list_to_vector"]
Expand Down Expand Up @@ -222,19 +223,6 @@ pub mod ffi {
) -> UniquePtr<TColgp_Array2OfPnt>;
pub fn SetValue(self: Pin<&mut TColgp_Array2OfPnt>, row: i32, column: i32, item: &gp_Pnt);

type TColgp_HArray1OfPnt;
#[cxx_name = "construct_unique"]
pub fn TColgp_HArray1OfPnt_ctor(
lower_bound: i32,
upper_bound: i32,
) -> UniquePtr<TColgp_HArray1OfPnt>;
pub fn Length(self: &TColgp_HArray1OfPnt) -> i32;
pub fn TColgp_HArray1OfPnt_Value(
array: &TColgp_HArray1OfPnt,
index: i32,
) -> UniquePtr<gp_Pnt>;
pub fn SetValue(self: Pin<&mut TColgp_HArray1OfPnt>, index: i32, item: &gp_Pnt);

type TopTools_HSequenceOfShape;

pub fn Length(self: &TopTools_HSequenceOfShape) -> i32;
Expand Down Expand Up @@ -900,18 +888,49 @@ pub mod ffi {
) -> &'a TopTools_ListOfShape;
pub fn SectionEdges(self: Pin<&mut BRepAlgoAPI_Cut>) -> &TopTools_ListOfShape;

type BOPAlgo_MakerVolume;

#[cxx_name = "construct_unique"]
pub fn BOPAlgo_MakerVolume_ctor() -> UniquePtr<BOPAlgo_MakerVolume>;
pub fn SetArguments(self: Pin<&mut BOPAlgo_MakerVolume>, the_ls: &TopTools_ListOfShape);
pub fn Perform(self: Pin<&mut BOPAlgo_MakerVolume>, the_range: &Message_ProgressRange);
pub fn BOPAlgo_MakerVolume_Shape(theMV: &BOPAlgo_MakerVolume) -> &TopoDS_Shape;
// pub fn Shape(self: Pin<&mut BOPAlgo_MakerVolume>) -> &TopoDS_Shape;

type BRepAlgoAPI_Common;
type BOPAlgo_Operation;

#[cxx_name = "construct_unique"]
pub fn BRepAlgoAPI_Common_ctor() -> UniquePtr<BRepAlgoAPI_Common>;

/// Obsolete.
#[rust_name = "BRepAlgoAPI_Common_ctor2"]
#[cxx_name = "construct_unique"]
pub fn BRepAlgoAPI_Common_ctor(
shape_1: &TopoDS_Shape,
shape_2: &TopoDS_Shape,
) -> UniquePtr<BRepAlgoAPI_Common>;

pub fn Shape(self: Pin<&mut BRepAlgoAPI_Common>) -> &TopoDS_Shape;
pub fn Build(self: Pin<&mut BRepAlgoAPI_Common>, progress: &Message_ProgressRange);
pub fn Build(self: Pin<&mut BRepAlgoAPI_Common>, the_range: &Message_ProgressRange);
pub fn IsDone(self: &BRepAlgoAPI_Common) -> bool;
pub fn SectionEdges(self: Pin<&mut BRepAlgoAPI_Common>) -> &TopTools_ListOfShape;
pub fn SetTools(self: Pin<&mut BRepAlgoAPI_Common>, the_ls: &TopTools_ListOfShape);
pub fn SetArguments(self: Pin<&mut BRepAlgoAPI_Common>, the_ls: &TopTools_ListOfShape);
pub fn HasErrors_BRepAlgoAPI_Common(the_bop: &BRepAlgoAPI_Common) -> bool;
pub fn SetFuzzyValue_BRepAlgoAPI_Common(
the_bop: Pin<&mut BRepAlgoAPI_Common>,
the_fuzz: f64,
);
pub fn SetRunParallel_BRepAlgoAPI_Common(
the_bop: Pin<&mut BRepAlgoAPI_Common>,
the_flag: bool,
);
pub fn SetUseOBB_BRepAlgoAPI_Common(
the_bop: Pin<&mut BRepAlgoAPI_Common>,
the_use_obb: bool,
);
pub fn SetGlue(self: Pin<&mut BRepAlgoAPI_Common>, glue: BOPAlgo_GlueEnum);

type BRepAlgoAPI_Section;

Expand Down Expand Up @@ -959,29 +978,6 @@ pub mod ffi {
#[cxx_name = "construct_unique"]
pub fn gp_Ax2d_ctor(point: &gp_Pnt2d, dir: &gp_Dir2d) -> UniquePtr<gp_Ax2d>;

// Geometry Interpolation
type GeomAPI_Interpolate;

#[cxx_name = "construct_unique"]
pub fn GeomAPI_Interpolate_ctor(
points: &Handle_TColgpHArray1OfPnt,
periodic: bool,
tolerance: f64,
) -> UniquePtr<GeomAPI_Interpolate>;

pub fn Load(
self: Pin<&mut GeomAPI_Interpolate>,
initial_tangent: &gp_Vec,
final_tangent: &gp_Vec,
scale: bool,
);

pub fn Perform(self: Pin<&mut GeomAPI_Interpolate>);

pub fn GeomAPI_Interpolate_Curve(
interpolate: &GeomAPI_Interpolate,
) -> UniquePtr<HandleGeomBSplineCurve>;

// Geometry Querying
type GeomAPI_ProjectPointOnSurf;

Expand All @@ -1003,17 +999,10 @@ pub mod ffi {
pub fn SetRotation(self: Pin<&mut gp_Trsf>, axis: &gp_Ax1, angle: f64);
pub fn SetScale(self: Pin<&mut gp_Trsf>, point: &gp_Pnt, scale: f64);
pub fn SetTranslation(self: Pin<&mut gp_Trsf>, point1: &gp_Pnt, point2: &gp_Pnt);
pub fn Value(self: &gp_Trsf, the_row: i32, the_col: i32) -> f64;

#[cxx_name = "SetTranslationPart"]
pub fn set_translation_vec(self: Pin<&mut gp_Trsf>, translation: &gp_Vec);

type gp_GTrsf;
#[cxx_name = "construct_unique"]
pub fn new_gp_GTrsf() -> UniquePtr<gp_GTrsf>;
pub fn SetValue(self: Pin<&mut gp_GTrsf>, the_row: i32, the_col: i32, the_value: f64);
pub fn Value(self: &gp_GTrsf, the_row: i32, the_col: i32) -> f64;

type BRepBuilderAPI_MakeSolid;

#[cxx_name = "construct_unique"]
Expand Down Expand Up @@ -1052,19 +1041,6 @@ pub mod ffi {
pub fn Build(self: Pin<&mut BRepBuilderAPI_Transform>, progress: &Message_ProgressRange);
pub fn IsDone(self: &BRepBuilderAPI_Transform) -> bool;

type BRepBuilderAPI_GTransform;

#[cxx_name = "construct_unique"]
pub fn BRepBuilderAPI_GTransform_ctor(
shape: &TopoDS_Shape,
transform: &gp_GTrsf,
copy: bool,
) -> UniquePtr<BRepBuilderAPI_GTransform>;

pub fn Shape(self: Pin<&mut BRepBuilderAPI_GTransform>) -> &TopoDS_Shape;
pub fn Build(self: Pin<&mut BRepBuilderAPI_GTransform>, progress: &Message_ProgressRange);
pub fn IsDone(self: &BRepBuilderAPI_GTransform) -> bool;

// Topology Explorer
type TopExp_Explorer;
type TopAbs_ShapeEnum;
Expand Down
Loading

0 comments on commit bf5704b

Please sign in to comment.