Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeAPI.cpp
index 818f52ea6f48e88a9d8227fe1632d12dfd0b1ae1..550bf68f3f0b74d9d9e824b29c685f244d4e172e 100644 (file)
 #include "GeomAlgoAPI_ShapeAPI.h"
 
 #include <GeomAlgoAPI_Box.h>
-#include <GeomAlgoAPI_Cylinder.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_Cone.h>
 #include <GeomAlgoAPI_ConeSegment.h>
+#include <GeomAlgoAPI_Cylinder.h>
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_Rotation.h>
 #include <GeomAlgoAPI_Scale.h>
+#include <GeomAlgoAPI_Sphere.h>
 #include <GeomAlgoAPI_Symmetry.h>
+#include <GeomAlgoAPI_Torus.h>
 #include <GeomAlgoAPI_Translation.h>
 
 #include <GeomAPI_Lin.h>
@@ -206,6 +209,187 @@ namespace GeomAlgoAPI_ShapeAPI
     return aCylinderAlgo.shape();
   }
 
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(
+      std::shared_ptr<GeomAPI_Pnt> theCenterPoint, double theRadius) throw (GeomAlgoAPI_Exception)
+  {
+    GeomAlgoAPI_Sphere aSphereAlgo(theCenterPoint, theRadius);
+
+    if (!aSphereAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+
+    aSphereAlgo.build();
+
+    if(!aSphereAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+
+    if (!aSphereAlgo.checkValid("Sphere builder")) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+    return aSphereAlgo.shape();
+  }
+
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(double theRadius)
+      throw (GeomAlgoAPI_Exception)
+  {
+    std::shared_ptr<GeomAPI_Pnt> aCenterPoint =
+      std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
+
+    GeomAlgoAPI_Sphere aSphereAlgo(aCenterPoint, theRadius);
+
+    if (!aSphereAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+
+    aSphereAlgo.build();
+
+    if(!aSphereAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+
+    if (!aSphereAlgo.checkValid("Sphere builder")) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+    return aSphereAlgo.shape();
+  }
+
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTorus(
+      std::shared_ptr<GeomAPI_Pnt> theBasePoint,
+      std::shared_ptr<GeomAPI_Edge> theEdge,double theRadius, double theRingRadius)
+      throw (GeomAlgoAPI_Exception)
+  {
+    // Check if the base point is OK
+    if (!theBasePoint) {
+      throw GeomAlgoAPI_Exception("Torus builder :: the base point is not valid.");
+    }
+    // Check if the edge is OK
+    if (!theEdge) {
+      throw GeomAlgoAPI_Exception("Torus builder :: the axis is not valid.");
+    }
+
+    std::shared_ptr<GeomAPI_Ax2> anAxis;
+    anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
+                                                          theEdge->line()->direction()));
+
+    GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius);
+
+    if (!aTorusAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
+    }
+
+    aTorusAlgo.build();
+
+    if(!aTorusAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
+    }
+
+    if (!aTorusAlgo.checkValid("Torus builder")) {
+      throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
+    }
+    return aTorusAlgo.shape();
+  }
+
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTorus(double theRadius,
+      double theRingRadius) throw (GeomAlgoAPI_Exception)
+  {
+    std::shared_ptr<GeomAPI_Pnt> aBasePoint =
+      std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
+    std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
+    std::shared_ptr<GeomAPI_Ax2> anAxis;
+    anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
+                                                          aEdge->line()->direction()));
+
+    GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius);
+
+    if (!aTorusAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
+    }
+
+    aTorusAlgo.build();
+
+    if(!aTorusAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
+    }
+
+    if (!aTorusAlgo.checkValid("Torus builder")) {
+      throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
+    }
+    return aTorusAlgo.shape();
+  }
+
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCone(
+      std::shared_ptr<GeomAPI_Pnt> theBasePoint,
+      std::shared_ptr<GeomAPI_Edge> theEdge,
+      double theBaseRadius, double theTopRadius,
+      double theHeight) throw (GeomAlgoAPI_Exception)
+  {
+    // Check if the base point is OK
+    if (!theBasePoint) {
+      throw GeomAlgoAPI_Exception("Cone builder :: the base point is not valid.");
+    }
+    // Check if the edge is OK
+    if (!theEdge) {
+      throw GeomAlgoAPI_Exception("Cone builder :: the axis is not valid.");
+    }
+
+    std::shared_ptr<GeomAPI_Ax2> anAxis;
+    anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
+                                                          theEdge->line()->direction()));
+
+    GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight);
+
+    if (!aConeAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aConeAlgo.getError());
+    }
+
+    aConeAlgo.build();
+
+    if(!aConeAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aConeAlgo.getError());
+    }
+
+    if (!aConeAlgo.checkValid("Cone builder")) {
+      throw GeomAlgoAPI_Exception(aConeAlgo.getError());
+    }
+    return aConeAlgo.shape();
+  }
+
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCone(
+      double theBaseRadius, double theTopRadius,
+      double theHeight) throw (GeomAlgoAPI_Exception)
+  {
+    std::shared_ptr<GeomAPI_Pnt> aBasePoint =
+      std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
+    std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
+    std::shared_ptr<GeomAPI_Ax2> anAxis;
+    anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
+                                                          aEdge->line()->direction()));
+
+    GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight);
+
+    if (!aConeAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aConeAlgo.getError());
+    }
+
+    aConeAlgo.build();
+
+    if(!aConeAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aConeAlgo.getError());
+    }
+
+    if (!aConeAlgo.checkValid("Cone builder")) {
+      throw GeomAlgoAPI_Exception(aConeAlgo.getError());
+    }
+    return aConeAlgo.shape();
+  }
+
   //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
     std::shared_ptr<GeomAPI_Shape> theSourceShape,
@@ -503,6 +687,61 @@ namespace GeomAlgoAPI_ShapeAPI
     return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
   }
 
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiRotation(
+    std::shared_ptr<GeomAPI_Shape> theSourceShape,
+    std::shared_ptr<GeomAPI_Ax1> theAxis,
+    const int theNumber)
+  {
+    if (!theAxis) {
+      std::string aError = "Multirotation builder ";
+      aError+=":: the axis is not valid";
+      throw GeomAlgoAPI_Exception(aError);
+    }
+
+    if (theNumber <=0) {
+      std::string aError = "Multirotation builder ";
+      aError+=":: the number of copies is null or negative.";
+      throw GeomAlgoAPI_Exception(aError);
+    }
+
+    double anAngle = 360./theNumber;
+
+    ListOfShape aListOfShape;
+    for (int i=0; i<theNumber; i++) {
+      aListOfShape.
+        push_back(GeomAlgoAPI_ShapeAPI::makeRotation(theSourceShape, theAxis, i*anAngle));
+    }
+    return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
+  }
+
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiRotation(
+    std::shared_ptr<GeomAPI_Shape> theSourceShape,
+    std::shared_ptr<GeomAPI_Ax1> theAxis,
+    const double theStep,
+    const int theNumber)
+  {
+    if (!theAxis) {
+      std::string aError = "Multirotation builder ";
+      aError+=":: the axis is not valid";
+      throw GeomAlgoAPI_Exception(aError);
+    }
+
+    if (theNumber <=0) {
+      std::string aError = "Multirotation builder ";
+      aError+=":: the number of copies is null or negative.";
+      throw GeomAlgoAPI_Exception(aError);
+    }
+
+    ListOfShape aListOfShape;
+    for (int i=0; i<theNumber; i++) {
+      aListOfShape.
+        push_back(GeomAlgoAPI_ShapeAPI::makeRotation(theSourceShape, theAxis, i*theStep));
+    }
+    return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
+  }
+
   //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
     const double theRMin1, const double theRMax1,