Salome HOME
Renaming the direct API high level.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Pipe.cpp
index 612df97c2bb9f63d52698f29bfc20b73d937caba..04b310006af1f7ef84c917153b5fdece5c2b2bfb 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "GeomAlgoAPI_Pipe.h"
 
+#include "GeomAlgoAPI_DFLoader.h"
+
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
@@ -28,15 +30,16 @@ static bool getBase(TopoDS_Shape& theBaseOut,
 static bool getPath(TopoDS_Wire& thePathOut,
                     const GeomShapePtr thePathShape);
 static bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder);
+static ListOfShape getListFromShape(const TopoDS_Shape& theShape);
 
-//=================================================================================================
+//==================================================================================================
 GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape,
                                    const GeomShapePtr thePathShape)
 {
   build(theBaseShape, thePathShape);
 }
 
-//=================================================================================================
+//==================================================================================================
 GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape,
                                    const GeomShapePtr thePathShape,
                                    const GeomShapePtr theBiNormal)
@@ -44,7 +47,7 @@ GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape,
   build(theBaseShape, thePathShape, theBiNormal);
 }
 
-//=================================================================================================
+//==================================================================================================
 GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const ListOfShape& theBaseShapes,
                                    const ListOfShape& theLocations,
                                    const GeomShapePtr thePathShape)
@@ -52,7 +55,7 @@ GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const ListOfShape& theBaseShapes,
   build(theBaseShapes, theLocations, thePathShape);
 }
 
-//=================================================================================================
+//==================================================================================================
 void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape,
                              const GeomShapePtr thePathShape)
 {
@@ -67,7 +70,7 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape,
   TopAbs_ShapeEnum aBaseShapeType = aBaseShape.ShapeType();
   if(aBaseShapeType != TopAbs_VERTEX && aBaseShapeType != TopAbs_EDGE &&
      aBaseShapeType != TopAbs_WIRE && aBaseShapeType != TopAbs_FACE &&
-     aBaseShapeType != TopAbs_SHELL) {
+     aBaseShapeType != TopAbs_SHELL && aBaseShapeType != TopAbs_COMPOUND) {
     return;
   }
 
@@ -92,21 +95,19 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape,
   this->initialize(aPipeBuilder);
 
   // Setting naming.
-  GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape);
-  aFromShape->setImpl(new TopoDS_Shape(aPipeBuilder->FirstShape()));
-  aToShape->setImpl(new TopoDS_Shape(aPipeBuilder->LastShape()));
-  this->addFromShape(aFromShape);
-  this->addToShape(aToShape);
+  this->setToShapes(getListFromShape(aPipeBuilder->LastShape()));
+  this->setFromShapes(getListFromShape(aPipeBuilder->FirstShape()));
 
   // Setting result.
-  TopoDS_Shape aResultShape = aPipeBuilder->Shape();
-  GeomShapePtr aResultGeomShape(new GeomAPI_Shape());
-  aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape));
-  this->setShape(aResultGeomShape);
+  TopoDS_Shape aResult = aPipeBuilder->Shape();
+  aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+  GeomShapePtr aGeomSh(new GeomAPI_Shape());
+  aGeomSh->setImpl(new TopoDS_Shape(aResult));
+  this->setShape(aGeomSh);
   this->setDone(true);
 }
 
-//=================================================================================================
+//==================================================================================================
 void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape,
                              const GeomShapePtr thePathShape,
                              const GeomShapePtr theBiNormal)
@@ -160,26 +161,24 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape,
       return;
     }
   }
-  if(aPipeBuilder->Shape().IsNull()) {
+  TopoDS_Shape aResult = aPipeBuilder->Shape();
+  if(aResult.IsNull()) {
     return;
   }
 
   // Setting naming.
-  GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape);
-  aFromShape->setImpl(new TopoDS_Shape(aPipeBuilder->FirstShape()));
-  aToShape->setImpl(new TopoDS_Shape(aPipeBuilder->LastShape()));
-  this->addFromShape(aFromShape);
-  this->addToShape(aToShape);
+  this->setToShapes(getListFromShape(aPipeBuilder->LastShape()));
+  this->setFromShapes(getListFromShape(aPipeBuilder->FirstShape()));
 
   // Setting result.
-  TopoDS_Shape aResultShape = aPipeBuilder->Shape();
-  GeomShapePtr aResultGeomShape(new GeomAPI_Shape());
-  aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape));
-  this->setShape(aResultGeomShape);
+  aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+  GeomShapePtr aGeomSh(new GeomAPI_Shape());
+  aGeomSh->setImpl(new TopoDS_Shape(aResult));
+  this->setShape(aGeomSh);
   this->setDone(true);
 }
 
-//=================================================================================================
+//==================================================================================================
 void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes,
                              const ListOfShape& theLocations,
                              const GeomShapePtr thePathShape)
@@ -251,9 +250,7 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes,
       return;
     }
   }
-  if(aPipeBuilder->Shape().IsNull()) {
-    return;
-  }
+  TopoDS_Shape aResult = aPipeBuilder->Shape();
 
   // Setting naming.
   GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape);
@@ -263,14 +260,17 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes,
   this->addToShape(aToShape);
 
   // Setting result.
-  TopoDS_Shape aResultShape = aPipeBuilder->Shape();
-  GeomShapePtr aResultGeomShape(new GeomAPI_Shape());
-  aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape));
-  this->setShape(aResultGeomShape);
+  if(aResult.IsNull()) {
+    return;
+  }
+  aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+  GeomShapePtr aGeomSh(new GeomAPI_Shape());
+  aGeomSh->setImpl(new TopoDS_Shape(aResult));
+  this->setShape(aGeomSh);
   this->setDone(true);
 }
 
-//=================================================================================================
+//==================================================================================================
 void GeomAlgoAPI_Pipe::generated(const GeomShapePtr theShape,
                                  ListOfShape& theHistory)
 {
@@ -278,7 +278,7 @@ void GeomAlgoAPI_Pipe::generated(const GeomShapePtr theShape,
 }
 
 // Auxilary functions:
-//=================================================================================================
+//==================================================================================================
 bool getBase(TopoDS_Shape& theBaseOut,
              TopAbs_ShapeEnum& theBaseTypeOut,
              const GeomShapePtr theBaseShape)
@@ -308,7 +308,7 @@ bool getBase(TopoDS_Shape& theBaseOut,
   return true;
 }
 
-//=================================================================================================
+//==================================================================================================
 bool getPath(TopoDS_Wire& thePathOut,
              const GeomShapePtr thePathShape)
 {
@@ -333,7 +333,7 @@ bool getPath(TopoDS_Wire& thePathOut,
   return true;
 }
 
-//=================================================================================================
+//==================================================================================================
 bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder)
 {
   thePipeBuilder->Build();
@@ -349,3 +349,24 @@ bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder)
 
   return isDone == Standard_True;
 }
+
+//==================================================================================================
+ListOfShape getListFromShape(const TopoDS_Shape& theShape)
+{
+  ListOfShape aList;
+
+  TopAbs_ShapeEnum aType = theShape.ShapeType();
+  if(aType == TopAbs_WIRE || aType == TopAbs_SHELL || aType == TopAbs_COMPOUND) {
+    for(TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next()) {
+      GeomShapePtr aGeomShape(new GeomAPI_Shape());
+      aGeomShape->setImpl(new TopoDS_Shape(anIt.Value()));
+      aList.push_back(aGeomShape);
+    }
+  } else {
+    GeomShapePtr aGeomShape(new GeomAPI_Shape());
+    aGeomShape->setImpl(new TopoDS_Shape(theShape));
+    aList.push_back(aGeomShape);
+  }
+
+  return aList;
+}