diff --git a/crates/opencascade-sys/include/wrapper.hxx b/crates/opencascade-sys/include/wrapper.hxx index ccd7d43..1adc891 100644 --- a/crates/opencascade-sys/include/wrapper.hxx +++ b/crates/opencascade-sys/include/wrapper.hxx @@ -1,6 +1,7 @@ #include "rust/cxx.h" #include #include +#include #include #include #include @@ -63,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -85,6 +87,19 @@ #include #include +// OCAF stuff +#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...)); @@ -119,6 +134,207 @@ new_HandleTColgpHArray1OfPnt_from_TColgpHArray1OfPnt(std::unique_ptr(new Handle_TColgpHArray1OfPnt(array.release())); } +/* +typedef opencascade::handle Handle_TDF_Data; + +inline std::unique_ptr +new_Handle_TDF_Data() { + return std::unique_ptr(new Handle_TDF_Data(new TDF_Data())); +} + +inline std::unique_ptr +Handle_TDF_Data_Root(const Handle_TDF_Data &h) { + return std::unique_ptr(new TDF_Label(h->Root())); +} + +inline std::unique_ptr +TDF_Label_FindChild(const TDF_Label &h, const Standard_Integer tag, const Standard_Boolean create) { + return std::unique_ptr(new TDF_Label(h.FindChild(tag, create))); +} + +inline std::unique_ptr +TDF_ChildIterator_ctor(const TDF_Label &lab, const Standard_Boolean allLevels) { + return std::unique_ptr(new TDF_ChildIterator(lab, allLevels)); +} + +inline Standard_Boolean +TDF_ChildIterator_More(const TDF_ChildIterator& it) +{ + return it.More(); +} + +inline void +TDF_ChildIterator_Next(TDF_ChildIterator& it) +{ + it.Next(); +} + +inline std::unique_ptr +TDF_ChildIterator_Value(const TDF_ChildIterator& it) +{ + return std::unique_ptr(new TDF_Label(it.Value())); +} + +inline Standard_Boolean +TDF_Label_HasIntegerAttribute(const TDF_Label &lab) { + return lab.IsAttribute(TDataStd_Integer::GetID()); +} + +inline Standard_Integer +TDF_Label_GetIntegerAttribute(const TDF_Label &lab) { + Handle(TDataStd_Integer) ResultNS; + lab.FindAttribute(TDataStd_Integer::GetID(), ResultNS); + return ResultNS->Get(); +} + +inline void +TDF_Label_AddIntegerAttribute(const TDF_Label &lab, Standard_Integer v) { + TDataStd_Integer::Set(lab, v); +} + +// TODO maybe FindAttribute should be exposed explicitly + +inline std::unique_ptr +TopoDS_Shape_Moved(const TopoDS_Shape &shape, const TopLoc_Location& loc, bool raise_exception) { + return std::unique_ptr(new TopoDS_Shape(shape.Moved(loc, raise_exception))); +} + +inline std::unique_ptr +TDF_Label_GetShape(const TDF_Label &lab) { + Handle(TNaming_NamedShape) ResultNS; + lab.FindAttribute(TNaming_NamedShape::GetID(), ResultNS); + const TopoDS_Shape& s = ResultNS->Get(); + return std::unique_ptr(new TopoDS_Shape(s)); +} + +inline void +TDF_Label_Dump(const TDF_Label& lab) { + lab.Dump(std::cout); +} + +inline void +TDF_Label_Displace(const TDF_Label &lab, const TopLoc_Location& loc) { + TNaming::Displace(lab, loc, Standard_True);//with oldshapes +} +*/ + +// TODO remove this and expose all the things it calls at finer granularity +inline void +unused_TDF_Label_Subtract(const TDF_Label& aLabel, const TDF_Label &lab, const TopoDS_Shape& TOOL) +{ + Handle(TNaming_NamedShape) ObjectNS; + lab.FindAttribute(TNaming_NamedShape::GetID(), ObjectNS); + TopoDS_Shape OBJECT = ObjectNS->Get(); + + TopTools_MapOfShape View; + TopExp_Explorer ShapeExplorer (OBJECT, TopAbs_EDGE); + BRepAlgoAPI_Cut mkCUT (OBJECT, TOOL); + + //TDF_Label CutLabel = aLabel.FindChild(5); // TODO CutPOS 5 + + if (!mkCUT.IsDone()) { + //cout << "CUT: Algorithm failed" << endl; + return; + } else + { + TopTools_ListOfShape Larg; + Larg.Append(OBJECT); + Larg.Append(TOOL); + + if (!BRepAlgo::IsValid(Larg, mkCUT.Shape(), Standard_True, Standard_False)) { + + //cout << "CUT: Result is not valid" << endl; + return; + } else + { + // push CUT results in DF as modification of Box1 + //TDF_Label Modified = CutLabel.FindChild(2); + //TDF_Label Deleted = CutLabel.FindChild(3); + //TDF_Label Intersections = CutLabel.FindChild(4); + //TDF_Label NewFaces = CutLabel.FindChild(5); + + TopoDS_Shape newS1 = mkCUT.Shape(); + const TopoDS_Shape& ObjSh = mkCUT.Shape1(); + + //push in the DF result of CUT + TNaming_Builder CutBuilder (lab); // TODO CutLabel + // TNaming_Evolution == MODIFY + CutBuilder.Modify (ObjSh, newS1); + + ShapeExplorer.Init(ObjSh, TopAbs_FACE); + for (; ShapeExplorer.More(); ShapeExplorer.Next ()) { + const TopoDS_Shape& Root = ShapeExplorer.Current (); + //if (!View.Add(Root)) continue; + const TopTools_ListOfShape& Shapes = mkCUT.Modified (Root); + TopTools_ListIteratorOfListOfShape ShapesIterator (Shapes); + for (;ShapesIterator.More (); ShapesIterator.Next ()) { + const TopoDS_Shape& newShape = ShapesIterator.Value (); + std::cout << "a modified face" << std::endl; + // TNaming_Evolution == MODIFY + //if (!Root.IsSame (newShape)) ModBuilder.Modify (Root,newShape ); + } + } + +/* + //push in the DF modified faces + View.Clear(); + TNaming_Builder ModBuilder(Modified); + ShapeExplorer.Init(ObjSh, TopAbs_FACE); + for (; ShapeExplorer.More(); ShapeExplorer.Next ()) { + const TopoDS_Shape& Root = ShapeExplorer.Current (); + if (!View.Add(Root)) continue; + const TopTools_ListOfShape& Shapes = mkCUT.Modified (Root); + TopTools_ListIteratorOfListOfShape ShapesIterator (Shapes); + for (;ShapesIterator.More (); ShapesIterator.Next ()) { + const TopoDS_Shape& newShape = ShapesIterator.Value (); + // TNaming_Evolution == MODIFY + if (!Root.IsSame (newShape)) ModBuilder.Modify (Root,newShape ); + } + } + + //push in the DF deleted faces + View.Clear(); + TNaming_Builder DelBuilder(Deleted); + ShapeExplorer.Init (ObjSh,TopAbs_FACE); + for (; ShapeExplorer.More(); ShapeExplorer.Next ()) { + const TopoDS_Shape& Root = ShapeExplorer.Current (); + if (!View.Add(Root)) continue; + // TNaming_Evolution == DELETE + if (mkCUT.IsDeleted (Root)) DelBuilder.Delete (Root); + } + + // push in the DF section edges + TNaming_Builder IntersBuilder(Intersections); + TopTools_ListIteratorOfListOfShape its(mkCUT.SectionEdges()); + for (; its.More(); its.Next()) { + // TNaming_Evolution == SELECTED + IntersBuilder.Select(its.Value(),its.Value()); + } + + // push in the DF new faces added to the object: + const TopoDS_Shape& ToolSh = mkCUT.Shape2(); + TNaming_Builder newBuilder (NewFaces); + ShapeExplorer.Init(ToolSh, TopAbs_FACE); + for (; ShapeExplorer.More(); ShapeExplorer.Next()) { + const TopoDS_Shape& F = ShapeExplorer.Current(); + const TopTools_ListOfShape& modified = mkCUT.Modified(F); + if (!modified.IsEmpty()) { + TopTools_ListIteratorOfListOfShape itr(modified); + for (; itr.More (); itr.Next ()) { + const TopoDS_Shape& newShape = itr.Value(); + Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(newShape, NewFaces); + if (NS.IsNull() || NS->Evolution() != TNaming_MODIFY) { + // TNaming_Evolution == GENERATED + newBuilder.Generated(F, newShape); + } + } + } + } + */ + } + } +} + // Handle stuff template const T &handle_try_deref(const opencascade::handle &handle) { if (handle.IsNull()) { @@ -313,6 +529,16 @@ inline std::unique_ptr BRep_Tool_Pnt(const TopoDS_Vertex &vertex) { return std::unique_ptr(new gp_Pnt(BRep_Tool::Pnt(vertex))); } +/* +inline Standard_Boolean BRep_Tool_HasContinuity(const TopoDS_Edge &e, const TopoDS_Face &f1, const TopoDS_Face &f2) { + return BRep_Tool::HasContinuity(e, f1, f2); +} + +inline Standard_Integer BRep_Tool_Continuity(const TopoDS_Edge &e, const TopoDS_Face &f1, const TopoDS_Face &f2) { + return (Standard_Integer) BRep_Tool::Continuity(e, f1, f2); +} +*/ + inline std::unique_ptr TopLoc_Location_Transformation(const TopLoc_Location &location) { return std::unique_ptr(new gp_Trsf(location.Transformation())); } @@ -332,6 +558,16 @@ inline std::unique_ptr ExplorerCurrentShape(const TopExp_Explorer return std::unique_ptr(new TopoDS_Shape(explorer.Current())); } +inline std::unique_ptr ShapeAnalysis_Edge_FirstVertex(const TopoDS_Edge &edge) { + ShapeAnalysis_Edge se; + return std::unique_ptr(new TopoDS_Vertex(se.FirstVertex(edge))); +} + +inline std::unique_ptr ShapeAnalysis_Edge_LastVertex(const TopoDS_Edge &edge) { + ShapeAnalysis_Edge se; + return std::unique_ptr(new TopoDS_Vertex(se.LastVertex(edge))); +} + inline std::unique_ptr TopExp_FirstVertex(const TopoDS_Edge &edge) { return std::unique_ptr(new TopoDS_Vertex(TopExp::FirstVertex(edge))); } diff --git a/crates/opencascade-sys/src/lib.rs b/crates/opencascade-sys/src/lib.rs index e369a11..2f5f204 100644 --- a/crates/opencascade-sys/src/lib.rs +++ b/crates/opencascade-sys/src/lib.rs @@ -14,6 +14,7 @@ pub mod ffi { TopAbs_SHAPE, } + #[derive(Debug)] #[repr(u32)] pub enum TopAbs_Orientation { TopAbs_FORWARD, @@ -462,11 +463,13 @@ pub mod ffi { pub fn IsNull(self: &TopoDS_Shape) -> bool; pub fn IsEqual(self: &TopoDS_Shape, other: &TopoDS_Shape) -> bool; + pub fn IsSame(self: &TopoDS_Shape, other: &TopoDS_Shape) -> bool; pub fn ShapeType(self: &TopoDS_Shape) -> TopAbs_ShapeEnum; type TopAbs_Orientation; pub fn Orientation(self: &TopoDS_Shape) -> TopAbs_Orientation; pub fn Orientation(self: &TopoDS_Face) -> TopAbs_Orientation; + pub fn Orientation(self: &TopoDS_Edge) -> TopAbs_Orientation; // Compound Shapes type TopoDS_Compound; @@ -898,12 +901,17 @@ pub mod ffi { ) -> UniquePtr; pub fn Shape(self: Pin<&mut BRepAlgoAPI_Cut>) -> &TopoDS_Shape; + // TODO pub fn Shape1(self: Pin<&mut BRepAlgoAPI_Cut>) -> &TopoDS_Shape; pub fn Build(self: Pin<&mut BRepAlgoAPI_Cut>, progress: &Message_ProgressRange); pub fn IsDone(self: &BRepAlgoAPI_Cut) -> bool; pub fn Generated<'a>( self: Pin<&'a mut BRepAlgoAPI_Cut>, shape: &'a TopoDS_Shape, ) -> &'a TopTools_ListOfShape; + pub fn Modified<'a>( + self: Pin<&'a mut BRepAlgoAPI_Cut>, + shape: &'a TopoDS_Shape, + ) -> &'a TopTools_ListOfShape; pub fn SectionEdges(self: Pin<&mut BRepAlgoAPI_Cut>) -> &TopTools_ListOfShape; type BRepAlgoAPI_Common; @@ -1068,6 +1076,14 @@ pub mod ffi { pub fn Shape(self: Pin<&mut BRepBuilderAPI_Transform>) -> &TopoDS_Shape; pub fn Build(self: Pin<&mut BRepBuilderAPI_Transform>, progress: &Message_ProgressRange); + pub fn Generated<'a>( + self: Pin<&'a mut BRepBuilderAPI_Transform>, + shape: &'a TopoDS_Shape, + ) -> &'a TopTools_ListOfShape; + pub fn Modified<'a>( + self: Pin<&'a mut BRepBuilderAPI_Transform>, + shape: &'a TopoDS_Shape, + ) -> &'a TopTools_ListOfShape; pub fn IsDone(self: &BRepBuilderAPI_Transform) -> bool; type BRepBuilderAPI_GTransform; @@ -1098,6 +1114,8 @@ pub mod ffi { pub fn ExplorerCurrentShape(explorer: &TopExp_Explorer) -> UniquePtr; pub fn Current(self: &TopExp_Explorer) -> &TopoDS_Shape; + pub fn ShapeAnalysis_Edge_FirstVertex(edge: &TopoDS_Edge) -> UniquePtr; + pub fn ShapeAnalysis_Edge_LastVertex(edge: &TopoDS_Edge) -> UniquePtr; pub fn TopExp_FirstVertex(edge: &TopoDS_Edge) -> UniquePtr; pub fn TopExp_LastVertex(edge: &TopoDS_Edge) -> UniquePtr; pub fn TopExp_EdgeVertices( @@ -1123,6 +1141,8 @@ pub mod ffi { last: &mut f64, ) -> UniquePtr; pub fn BRep_Tool_Pnt(vertex: &TopoDS_Vertex) -> UniquePtr; + //pub fn BRep_Tool_HasContinuity(e: &TopoDS_Edge, f1: &TopoDS_Face, f2: &TopoDS_Face) -> bool; + //pub fn BRep_Tool_Continuity(e: &TopoDS_Edge, f1: &TopoDS_Face, f2: &TopoDS_Face) -> i32; pub fn BRep_Tool_Triangulation( face: &TopoDS_Face, location: Pin<&mut TopLoc_Location>, @@ -1370,6 +1390,58 @@ pub mod ffi { shared: bool, wires: Pin<&mut HandleTopTools_HSequenceOfShape>, ); + +/* + type Handle_TDF_Data; + type TDF_Label; + type TNaming_Builder; + type TDF_ChildIterator; + + pub fn new_Handle_TDF_Data() -> UniquePtr; + + pub fn Handle_TDF_Data_Root(h: &Handle_TDF_Data) -> UniquePtr; + + pub fn TDF_Label_FindChild(lab: &TDF_Label, x: i32, b: bool) -> UniquePtr; + + pub fn TDF_Label_GetShape(lab: &TDF_Label) -> UniquePtr; + pub fn TDF_Label_Displace(lab: &TDF_Label, loc: &TopLoc_Location); + pub fn TDF_Label_Subtract(root: &TDF_Label, lab: &TDF_Label, other: &TopoDS_Shape); + pub fn TDF_Label_Dump(lab: &TDF_Label); + + #[cxx_name = "construct_unique"] + pub fn TNaming_Builder_ctor( + lab: &TDF_Label, + ) -> UniquePtr; + + pub fn Generated(self: Pin<&mut TNaming_Builder>, shape: &TopoDS_Shape); + + pub fn TDF_ChildIterator_ctor(lab: &TDF_Label, allLevels: bool) -> UniquePtr; + pub fn TDF_ChildIterator_More(it: &TDF_ChildIterator) -> bool; + pub fn TDF_ChildIterator_Next(it: Pin<&mut TDF_ChildIterator>); + pub fn TDF_ChildIterator_Value(it: &TDF_ChildIterator) -> UniquePtr; + + pub fn TDF_Label_AddIntegerAttribute(lab: &TDF_Label, v: i32); +*/ + +/* +inline Standard_Boolean +TDF_Label_HasIntegerAttribute(const TDF_Label &lab) { + return lab.IsAttribute(TDataStd_Integer::GetID()); +} + +inline Standard_Integer +TDF_Label_GetIntegerAttribute(const TDF_Label &lab) { + Handle(TDataStd_Integer) ResultNS; + lab.FindAttribute(TDataStd_Integer::GetID(), ResultNS); + return ResultNS->Get(); +} + +inline void +TDF_Label_AddIntegerAttribute(const TDF_Label &lab, Standard_Integer v) { + TDataStd_Integer::Set(lab, v); +} +*/ + } }