Salome HOME
Partition naming
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_MakeShape.cpp
index 70cfad9f831744218604d9b6ffd778533a6f042e..e608956c683b3d0556672c0bdc5c1f6381339b82 100644 (file)
@@ -1,69 +1,97 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        GeomAlgoAPI_MakeShape.cpp
 // Created:     20 Oct 2014
 // Author:      Sergey ZARITCHNY
 
 #include <GeomAlgoAPI_MakeShape.h>
+
+#include <BOPAlgo_Builder.hxx>
 #include <BRepBuilderAPI_MakeShape.hxx>
+#include <BRepOffsetAPI_MakePipe.hxx>
+#include <TopExp_Explorer.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
-GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape)
-  : GeomAPI_Interface(theMkShape),myShape(new GeomAPI_Shape())
-{
-  myShape->setImpl((void *)&implPtr<BRepBuilderAPI_MakeShape>()->Shape());
-}
 
-GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
-  : GeomAPI_Interface(),myShape(new GeomAPI_Shape())
-{}
-void GeomAlgoAPI_MakeShape::init(void* theMkShape)
+//=================================================================================================
+GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape, const AlgoType theAlgoType)
+: GeomAPI_Interface(theMkShape),
+  myAlgoType(theAlgoType),
+  myShape(new GeomAPI_Shape())
 {
-  setImpl((void *)implPtr<BRepBuilderAPI_MakeShape>());
+  switch (myAlgoType) {
+    case MakeShape: {
+      myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
+      break;
+    }
+    case BOPAlgoBuilder: {
+      myShape->setImpl(new TopoDS_Shape(implPtr<BOPAlgo_Builder>()->Shape()));
+      break;
+    }
+  }
 }
 
-const boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
+//=================================================================================================
+const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
 {
   return myShape;
 }
 
-/// Returns the  list   of shapes generated   from the shape <theShape>
-void GeomAlgoAPI_MakeShape::generated(
-  const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+//=================================================================================================
+void GeomAlgoAPI_MakeShape::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
+                                      ListOfShape& theHistory)
 {
-  BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
-  if(aBuilder) {
-    const TopTools_ListOfShape& aList =  aBuilder->Generated(theShape->impl<TopoDS_Shape>());
-    TopTools_ListIteratorOfListOfShape it(aList);
-    for(;it.More();it.Next()) {
-      boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
-      aShape->setImpl(new TopoDS_Shape(it.Value()));
-      theHistory.push_back(aShape);
+  TopTools_ListOfShape aList;
+  if(myAlgoType == MakeShape) {
+    BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
+    aList = aMakeShape->Generated(theShape->impl<TopoDS_Shape>());
+  } else if(myAlgoType == BOPAlgoBuilder) {
+    BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
+    aList = aBOPBuilder->Generated(theShape->impl<TopoDS_Shape>());
+  }
+  for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
+    if(anIt.Value().IsNull()) {
+      continue;
     }
+    std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+    aShape->setImpl(new TopoDS_Shape(anIt.Value()));
+    theHistory.push_back(aShape);
   }
 }
 
-/// Returns the  list   of shapes modified   from the shape <theShape>
-void GeomAlgoAPI_MakeShape::modified(
-  const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+//=================================================================================================
+void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
+                                     ListOfShape& theHistory)
 {
-  BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
-  if(aBuilder) {
-    const TopTools_ListOfShape& aList =  aBuilder->Modified(theShape->impl<TopoDS_Shape>());
-    TopTools_ListIteratorOfListOfShape it(aList);
-    for(;it.More();it.Next()) {
-      boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
-      aShape->setImpl(new TopoDS_Shape(it.Value()));
-      theHistory.push_back(aShape);
+  TopTools_ListOfShape aList;
+  if(myAlgoType == MakeShape) {
+    BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
+    aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
+  } else if(myAlgoType == BOPAlgoBuilder) {
+    BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
+    aList = aBOPBuilder->Modified(theShape->impl<TopoDS_Shape>());
+  }
+  for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
+    if(anIt.Value().IsNull()) {
+      continue;
     }
+    std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+    aShape->setImpl(new TopoDS_Shape(anIt.Value()));
+    theHistory.push_back(aShape);
   }
 }
 
-/// Returns whether the shape is an edge
-bool GeomAlgoAPI_MakeShape::isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape)
+//=================================================================================================
+bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
 {
-  bool isDeleted(false);
-  BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
-  if(aBuilder) {
-    isDeleted = aBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
+  bool isDeleted = false;
+  if(myAlgoType == MakeShape) {
+    BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
+    isDeleted = aMakeShape->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
+  } else if(myAlgoType == BOPAlgoBuilder) {
+    BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
+    isDeleted = aBOPBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
   }
+
   return isDeleted;
 }