#include "rust/cxx.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Generic template constructor template std::unique_ptr construct_unique(Args... args) { return std::unique_ptr(new T(args...)); } // Generic List template std::unique_ptr> list_to_vector(const NCollection_List &list) { return std::unique_ptr>(new std::vector(list.begin(), list.end())); } // Handles typedef opencascade::handle HandleStandardType; typedef opencascade::handle HandleGeomCurve; typedef opencascade::handle HandleGeomTrimmedCurve; typedef opencascade::handle HandleGeomSurface; typedef opencascade::handle HandleGeomBezierSurface; typedef opencascade::handle HandleGeomPlane; typedef opencascade::handle HandleGeom2d_Curve; typedef opencascade::handle HandleGeom2d_Ellipse; typedef opencascade::handle HandleGeom2d_TrimmedCurve; typedef opencascade::handle HandleGeom_CylindricalSurface; typedef opencascade::handle Handle_Poly_Triangulation; // Handle stuff template const T &handle_try_deref(const opencascade::handle &handle) { if (handle.IsNull()) { throw std::runtime_error("null handle dereference"); } return *handle; } inline const HandleStandardType &DynamicType(const HandleGeomSurface &surface) { return surface->DynamicType(); } inline rust::String type_name(const HandleStandardType &handle) { return std::string(handle->Name()); } inline std::unique_ptr HandleGeomCurve_Value(const HandleGeomCurve &curve, const Standard_Real U) { return std::unique_ptr(new gp_Pnt(curve->Value(U))); } inline std::unique_ptr GCPnts_TangentialDeflection_Value(const GCPnts_TangentialDeflection &approximator, Standard_Integer i) { return std::unique_ptr(new gp_Pnt(approximator.Value(i))); } inline std::unique_ptr new_HandleGeomPlane_from_HandleGeomSurface(const HandleGeomSurface &surface) { HandleGeomPlane plane_handle = opencascade::handle::DownCast(surface); return std::unique_ptr(new opencascade::handle(plane_handle)); } // Collections inline void shape_list_append_face(TopTools_ListOfShape &list, const TopoDS_Face &face) { list.Append(face); } // Geometry inline const gp_Pnt &handle_geom_plane_location(const HandleGeomPlane &plane) { return plane->Location(); } inline std::unique_ptr Geom_CylindricalSurface_ctor(const gp_Ax3 &axis, double radius) { return std::unique_ptr( new opencascade::handle(new Geom_CylindricalSurface(axis, radius))); } inline std::unique_ptr cylinder_to_surface(const HandleGeom_CylindricalSurface &cylinder_handle) { return std::unique_ptr(new opencascade::handle(cylinder_handle)); } inline std::unique_ptr Geom_BezierSurface_ctor(const TColgp_Array2OfPnt &poles) { return std::unique_ptr( new opencascade::handle(new Geom_BezierSurface(poles))); } inline std::unique_ptr bezier_to_surface(const HandleGeomBezierSurface &bezier_handle) { return std::unique_ptr(new opencascade::handle(bezier_handle)); } inline std::unique_ptr Geom2d_Ellipse_ctor(const gp_Ax2d &axis, double major_radius, double minor_radius) { return std::unique_ptr( new opencascade::handle(new Geom2d_Ellipse(axis, major_radius, minor_radius))); } inline std::unique_ptr ellipse_to_HandleGeom2d_Curve(const HandleGeom2d_Ellipse &ellipse_handle) { return std::unique_ptr(new opencascade::handle(ellipse_handle)); } inline std::unique_ptr Geom2d_TrimmedCurve_ctor(const HandleGeom2d_Curve &curve, double u1, double u2) { return std::unique_ptr( new opencascade::handle(new Geom2d_TrimmedCurve(curve, u1, u2))); } inline std::unique_ptr HandleGeom2d_TrimmedCurve_to_curve(const HandleGeom2d_TrimmedCurve &trimmed_curve) { return std::unique_ptr(new opencascade::handle(trimmed_curve)); } inline std::unique_ptr ellipse_value(const HandleGeom2d_Ellipse &ellipse, double u) { return std::unique_ptr(new gp_Pnt2d(ellipse->Value(u))); } // Segment Stuff inline std::unique_ptr GC_MakeSegment_Value(const GC_MakeSegment &segment) { return std::unique_ptr(new opencascade::handle(segment.Value())); } inline std::unique_ptr GCE2d_MakeSegment_point_point(const gp_Pnt2d &p1, const gp_Pnt2d &p2) { return std::unique_ptr( new opencascade::handle(GCE2d_MakeSegment(p1, p2))); } // Arc stuff inline std::unique_ptr GC_MakeArcOfCircle_Value(const GC_MakeArcOfCircle &arc) { return std::unique_ptr(new opencascade::handle(arc.Value())); } inline std::unique_ptr BRepAdaptor_Curve_value(const BRepAdaptor_Curve &curve, const Standard_Real U) { return std::unique_ptr(new gp_Pnt(curve.Value(U))); } // BRepLib inline bool BRepLibBuildCurves3d(const TopoDS_Shape &shape) { return BRepLib::BuildCurves3d(shape); } inline void MakeThickSolidByJoin(BRepOffsetAPI_MakeThickSolid &make_thick_solid, const TopoDS_Shape &shape, const TopTools_ListOfShape &closing_faces, const Standard_Real offset, const Standard_Real tolerance) { make_thick_solid.MakeThickSolidByJoin(shape, closing_faces, offset, tolerance); } // Geometric processing inline const gp_Ax1 &gp_OX() { return gp::OX(); } inline const gp_Ax1 &gp_OY() { return gp::OY(); } inline const gp_Ax1 &gp_OZ() { return gp::OZ(); } inline const gp_Dir &gp_DZ() { return gp::DZ(); } inline std::unique_ptr gp_Ax1_ctor(const gp_Pnt &origin, const gp_Dir &main_dir) { return std::unique_ptr(new gp_Ax1(origin, main_dir)); } inline std::unique_ptr gp_Ax2_ctor(const gp_Pnt &origin, const gp_Dir &main_dir) { return std::unique_ptr(new gp_Ax2(origin, main_dir)); } inline std::unique_ptr gp_Ax3_from_gp_Ax2(const gp_Ax2 &axis) { return std::unique_ptr(new gp_Ax3(axis)); } inline std::unique_ptr gp_Dir_ctor(double x, double y, double z) { return std::unique_ptr(new gp_Dir(x, y, z)); } inline std::unique_ptr gp_Dir2d_ctor(double x, double y) { return std::unique_ptr(new gp_Dir2d(x, y)); } inline std::unique_ptr gp_Ax2d_ctor(const gp_Pnt2d &point, const gp_Dir2d &dir) { return std::unique_ptr(new gp_Ax2d(point, dir)); } // Shape stuff inline const TopoDS_Vertex &TopoDS_cast_to_vertex(const TopoDS_Shape &shape) { return TopoDS::Vertex(shape); } inline const TopoDS_Edge &TopoDS_cast_to_edge(const TopoDS_Shape &shape) { return TopoDS::Edge(shape); } inline const TopoDS_Wire &TopoDS_cast_to_wire(const TopoDS_Shape &shape) { return TopoDS::Wire(shape); } inline const TopoDS_Face &TopoDS_cast_to_face(const TopoDS_Shape &shape) { return TopoDS::Face(shape); } inline const TopoDS_Solid &TopoDS_cast_to_solid(const TopoDS_Shape &shape) { return TopoDS::Solid(shape); } inline const TopoDS_Compound &TopoDS_cast_to_compound(const TopoDS_Shape &shape) { return TopoDS::Compound(shape); } inline const TopoDS_Shape &cast_vertex_to_shape(const TopoDS_Vertex &vertex) { return vertex; } inline const TopoDS_Shape &cast_edge_to_shape(const TopoDS_Edge &edge) { return edge; } inline const TopoDS_Shape &cast_wire_to_shape(const TopoDS_Wire &wire) { return wire; } inline const TopoDS_Shape &cast_face_to_shape(const TopoDS_Face &face) { return face; } inline const TopoDS_Shape &cast_solid_to_shape(const TopoDS_Solid &solid) { return solid; } inline const TopoDS_Shape &cast_compound_to_shape(const TopoDS_Compound &compound) { return compound; } // Compound shapes inline std::unique_ptr TopoDS_Compound_as_shape(std::unique_ptr compound) { return compound; } inline const TopoDS_Builder &BRep_Builder_upcast_to_topods_builder(const BRep_Builder &builder) { return builder; } // Transforms inline std::unique_ptr BRep_Tool_Surface(const TopoDS_Face &face) { return std::unique_ptr(new opencascade::handle(BRep_Tool::Surface(face))); } inline std::unique_ptr BRep_Tool_Curve(const TopoDS_Edge &edge, Standard_Real &first, Standard_Real &last) { return std::unique_ptr(new opencascade::handle(BRep_Tool::Curve(edge, first, last))); } inline std::unique_ptr BRep_Tool_Pnt(const TopoDS_Vertex &vertex) { return std::unique_ptr(new gp_Pnt(BRep_Tool::Pnt(vertex))); } inline std::unique_ptr TopLoc_Location_Transformation(const TopLoc_Location &location) { return std::unique_ptr(new gp_Trsf(location.Transformation())); } inline std::unique_ptr BRep_Tool_Triangulation(const TopoDS_Face &face, TopLoc_Location &location) { return std::unique_ptr( new opencascade::handle(BRep_Tool::Triangulation(face, location))); } inline std::unique_ptr ExplorerCurrentShape(const TopExp_Explorer &explorer) { return std::unique_ptr(new TopoDS_Shape(explorer.Current())); } inline std::unique_ptr TopExp_FirstVertex(const TopoDS_Edge &edge) { return std::unique_ptr(new TopoDS_Vertex(TopExp::FirstVertex(edge))); } inline std::unique_ptr TopExp_LastVertex(const TopoDS_Edge &edge) { return std::unique_ptr(new TopoDS_Vertex(TopExp::LastVertex(edge))); } inline void TopExp_EdgeVertices(const TopoDS_Edge &edge, TopoDS_Vertex &vertex1, TopoDS_Vertex &vertex2) { return TopExp::Vertices(edge, vertex1, vertex2); } inline void TopExp_WireVertices(const TopoDS_Wire &wire, TopoDS_Vertex &vertex1, TopoDS_Vertex &vertex2) { return TopExp::Vertices(wire, vertex1, vertex2); } inline bool TopExp_CommonVertex(const TopoDS_Edge &edge1, const TopoDS_Edge &edge2, TopoDS_Vertex &vertex) { return TopExp::CommonVertex(edge1, edge2, vertex); } inline std::unique_ptr BRepIntCurveSurface_Inter_face(const BRepIntCurveSurface_Inter &intersector) { return std::unique_ptr(new TopoDS_Face(intersector.Face())); } inline std::unique_ptr BRepIntCurveSurface_Inter_point(const BRepIntCurveSurface_Inter &intersector) { return std::unique_ptr(new gp_Pnt(intersector.Pnt())); } // BRepFeat inline std::unique_ptr BRepFeat_MakeCylindricalHole_ctor() { return std::unique_ptr(new BRepFeat_MakeCylindricalHole()); } // Data Import inline IFSelect_ReturnStatus read_step(STEPControl_Reader &reader, rust::String theFileName) { return reader.ReadFile(theFileName.c_str()); } inline std::unique_ptr one_shape(const STEPControl_Reader &reader) { return std::unique_ptr(new TopoDS_Shape(reader.OneShape())); } // Data Export inline IFSelect_ReturnStatus transfer_shape(STEPControl_Writer &writer, const TopoDS_Shape &theShape) { return writer.Transfer(theShape, STEPControl_AsIs); } inline IFSelect_ReturnStatus write_step(STEPControl_Writer &writer, rust::String theFileName) { return writer.Write(theFileName.c_str()); } inline bool write_stl(StlAPI_Writer &writer, const TopoDS_Shape &theShape, rust::String theFileName) { return writer.Write(theShape, theFileName.c_str()); } inline std::unique_ptr Poly_Triangulation_Normal(const Poly_Triangulation &triangulation, const Standard_Integer index) { return std::unique_ptr(new gp_Dir(triangulation.Normal(index))); } inline std::unique_ptr Poly_Triangulation_Node(const Poly_Triangulation &triangulation, const Standard_Integer index) { return std::unique_ptr(new gp_Pnt(triangulation.Node(index))); } inline std::unique_ptr Poly_Triangulation_UV(const Poly_Triangulation &triangulation, const Standard_Integer index) { return std::unique_ptr(new gp_Pnt2d(triangulation.UVNode(index))); } inline void compute_normals(const TopoDS_Face &face, const Handle(Poly_Triangulation) & triangulation) { BRepLib_ToolTriangulatedShape::ComputeNormals(face, triangulation); } // Shape Properties inline std::unique_ptr GProp_GProps_CentreOfMass(const GProp_GProps &props) { return std::unique_ptr(new gp_Pnt(props.CentreOfMass())); } inline void BRepGProp_LinearProperties(const TopoDS_Shape &shape, GProp_GProps &props) { BRepGProp::LinearProperties(shape, props); } inline void BRepGProp_SurfaceProperties(const TopoDS_Shape &shape, GProp_GProps &props) { BRepGProp::SurfaceProperties(shape, props); } inline void BRepGProp_VolumeProperties(const TopoDS_Shape &shape, GProp_GProps &props) { BRepGProp::VolumeProperties(shape, props); } // Fillets inline std::unique_ptr BRepFilletAPI_MakeFillet2d_add_fillet(BRepFilletAPI_MakeFillet2d &make_fillet, const TopoDS_Vertex &vertex, Standard_Real radius) { return std::unique_ptr(new TopoDS_Edge(make_fillet.AddFillet(vertex, radius))); } // Chamfers inline std::unique_ptr BRepFilletAPI_MakeFillet2d_add_chamfer(BRepFilletAPI_MakeFillet2d &make_fillet, const TopoDS_Edge &edge1, const TopoDS_Edge &edge2, const Standard_Real dist1, const Standard_Real dist2) { return std::unique_ptr(new TopoDS_Edge(make_fillet.AddChamfer(edge1, edge2, dist1, dist2))); } inline std::unique_ptr BRepFilletAPI_MakeFillet2d_add_chamfer_angle(BRepFilletAPI_MakeFillet2d &make_fillet, const TopoDS_Edge &edge, const TopoDS_Vertex &vertex, const Standard_Real dist, const Standard_Real angle) { return std::unique_ptr(new TopoDS_Edge(make_fillet.AddChamfer(edge, vertex, dist, angle))); } // BRepTools inline std::unique_ptr outer_wire(const TopoDS_Face &face) { return std::unique_ptr(new TopoDS_Wire(BRepTools::OuterWire(face))); } // Collections inline void map_shapes(const TopoDS_Shape &S, const TopAbs_ShapeEnum T, TopTools_IndexedMapOfShape &M) { TopExp::MapShapes(S, T, M); } inline void map_shapes_and_ancestors(const TopoDS_Shape &S, const TopAbs_ShapeEnum TS, const TopAbs_ShapeEnum TA, TopTools_IndexedDataMapOfShapeListOfShape &M) { TopExp::MapShapesAndAncestors(S, TS, TA, M); } inline void map_shapes_and_unique_ancestors(const TopoDS_Shape &S, const TopAbs_ShapeEnum TS, const TopAbs_ShapeEnum TA, TopTools_IndexedDataMapOfShapeListOfShape &M) { TopExp::MapShapesAndUniqueAncestors(S, TS, TA, M); } inline std::unique_ptr TColgp_Array1OfDir_Value(const TColgp_Array1OfDir &array, Standard_Integer index) { return std::unique_ptr(new gp_Dir(array.Value(index))); }