Salome HOME
Issue #1942: group - names are empty strings
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeAPI.cpp
index 185a2ca8b9b9010a83873b26c87d690dfb546c4c..b10e028abeeb62761ca4490884a41c578298b5a5 100644 (file)
@@ -7,14 +7,18 @@
 #include "GeomAlgoAPI_ShapeAPI.h"
 
 #include <GeomAlgoAPI_Box.h>
+#include <GeomAlgoAPI_Cylinder.h>
 #include <GeomAlgoAPI_ConeSegment.h>
 #include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomAlgoAPI_Scale.h>
 #include <GeomAlgoAPI_Symmetry.h>
 #include <GeomAlgoAPI_Translation.h>
 
+#include <GeomAPI_Lin.h>
+
 namespace GeomAlgoAPI_ShapeAPI
 {
-  //=======================================================================================
+  //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
     const double theDx, const double theDy,
     const double theDz) throw (GeomAlgoAPI_Exception)
@@ -36,7 +40,7 @@ namespace GeomAlgoAPI_ShapeAPI
     return aBoxAlgo.shape();
   }
 
-  //======================================================================================
+  //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
     std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
     std::shared_ptr<GeomAPI_Pnt> theSecondPoint) throw (GeomAlgoAPI_Exception)
@@ -58,7 +62,115 @@ namespace GeomAlgoAPI_ShapeAPI
     return aBoxAlgo.shape();
   }
 
-  //=========================================================================================================
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
+    std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
+    double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
+  {
+    std::shared_ptr<GeomAPI_Ax2> anAxis;
+    anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
+                                                          theEdge->line()->direction()));
+
+    GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
+
+    if (!aCylinderAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+
+    aCylinderAlgo.build();
+
+    if(!aCylinderAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+    if (!aCylinderAlgo.checkValid("Cylinder builder")) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+    return aCylinderAlgo.shape();
+  }
+
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
+    std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
+    double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
+  {
+    std::shared_ptr<GeomAPI_Ax2> anAxis;
+    anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
+                                                          theEdge->line()->direction()));
+
+    GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
+
+    if (!aCylinderAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+
+    aCylinderAlgo.build();
+
+    if(!aCylinderAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+    if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+    return aCylinderAlgo.shape();
+  }
+
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
+    double theRadius, 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_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
+
+    if (!aCylinderAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+
+    aCylinderAlgo.build();
+
+    if(!aCylinderAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+    if (!aCylinderAlgo.checkValid("Cylinder builder")) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+    return aCylinderAlgo.shape();
+  }
+
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
+    double theRadius, double theHeight, double theAngle) 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_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
+
+    if (!aCylinderAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+
+    aCylinderAlgo.build();
+
+    if(!aCylinderAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+    if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
+      throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
+    }
+    return aCylinderAlgo.shape();
+  }
+
+  //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
     std::shared_ptr<GeomAPI_Shape> theSourceShape,
     std::shared_ptr<GeomAPI_Ax1>   theAxis,
@@ -81,7 +193,7 @@ namespace GeomAlgoAPI_ShapeAPI
     return aTranslationAlgo.shape();
   }
 
-  //=========================================================================================================
+  //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
     std::shared_ptr<GeomAPI_Shape> theSourceShape,
     const double theDx,
@@ -105,7 +217,7 @@ namespace GeomAlgoAPI_ShapeAPI
     return aTranslationAlgo.shape();
   }
 
-  //=========================================================================================================
+  //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
     std::shared_ptr<GeomAPI_Shape> theSourceShape,
     std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
@@ -128,13 +240,13 @@ namespace GeomAlgoAPI_ShapeAPI
     return aTranslationAlgo.shape();
   }
 
-  //=========================================================================================================
+  //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
     std::shared_ptr<GeomAPI_Shape> theSourceShape,
     std::shared_ptr<GeomAPI_Pnt>   thePoint) throw (GeomAlgoAPI_Exception)
   {
     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint);
-    
+
     if (!aSymmetryAlgo.check()) {
       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
     }
@@ -150,13 +262,13 @@ namespace GeomAlgoAPI_ShapeAPI
     return aSymmetryAlgo.shape();
   }
 
-  //=========================================================================================================
+  //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
     std::shared_ptr<GeomAPI_Shape> theSourceShape,
     std::shared_ptr<GeomAPI_Ax1>   theAxis) throw (GeomAlgoAPI_Exception)
   {
     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis);
-    
+
     if (!aSymmetryAlgo.check()) {
       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
     }
@@ -172,13 +284,13 @@ namespace GeomAlgoAPI_ShapeAPI
     return aSymmetryAlgo.shape();
   }
 
-  //=========================================================================================================
+  //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
     std::shared_ptr<GeomAPI_Shape> theSourceShape,
     std::shared_ptr<GeomAPI_Ax2>   thePlane) throw (GeomAlgoAPI_Exception)
   {
     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane);
-    
+
     if (!aSymmetryAlgo.check()) {
       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
     }
@@ -194,7 +306,30 @@ namespace GeomAlgoAPI_ShapeAPI
     return aSymmetryAlgo.shape();
   }
 
-  //=========================================================================================================
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeScale(
+    std::shared_ptr<GeomAPI_Shape> theSourceShape,
+    std::shared_ptr<GeomAPI_Pnt>   theCenterPoint,
+    const double                   theScaleFactor) throw (GeomAlgoAPI_Exception)
+  {
+    GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint, theScaleFactor);
+
+    if (!aScaleAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
+    }
+
+    aScaleAlgo.build();
+
+    if(!aScaleAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
+    }
+    if (!aScaleAlgo.checkValid("Scale builder by a scale factor")) {
+      throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
+    }
+    return aScaleAlgo.shape();
+  }
+
+  //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
     const double theRMin1, const double theRMax1,
     const double theRMin2, const double theRMax2,