Salome HOME
Avoid crash if there is no parent of selection attribute.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeAPI.cpp
index 5fdeaee509edf96f3dcc1221aa892d2893f5bee4..550bf68f3f0b74d9d9e824b29c685f244d4e172e 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
-
-// File:        GeomAlgoAPI_ShapeAPI.cpp
-// Created:     17 Mar 2016
-// Author:      Clarisse Genrault (CEA)
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "GeomAlgoAPI_ShapeAPI.h"
 
@@ -243,9 +257,9 @@ namespace GeomAlgoAPI_ShapeAPI
   }
 
   //===============================================================================================
-  std::shared_ptr<GeomAPI_Shape> makeTorus(std::shared_ptr<GeomAPI_Pnt> theBasePoint,
-                                           std::shared_ptr<GeomAPI_Edge> theEdge,
-                                           double theRadius, double theRingRadius)
+  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
@@ -280,8 +294,8 @@ namespace GeomAlgoAPI_ShapeAPI
   }
 
   //===============================================================================================
-  std::shared_ptr<GeomAPI_Shape> makeTorus(double theRadius, double theRingRadius)
-      throw (GeomAlgoAPI_Exception)
+  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.));
@@ -309,10 +323,11 @@ namespace GeomAlgoAPI_ShapeAPI
   }
 
   //===============================================================================================
-  std::shared_ptr<GeomAPI_Shape> makeCone(std::shared_ptr<GeomAPI_Pnt> theBasePoint,
-                                          std::shared_ptr<GeomAPI_Edge> theEdge,
-                                          double theBaseRadius, double theTopRadius,
-                                          double theHeight) throw (GeomAlgoAPI_Exception)
+  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) {
@@ -346,8 +361,9 @@ namespace GeomAlgoAPI_ShapeAPI
   }
 
   //===============================================================================================
-  std::shared_ptr<GeomAPI_Shape> makeCone(double theBaseRadius, double theTopRadius,
-                                          double theHeight) throw (GeomAlgoAPI_Exception)
+  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.));
@@ -593,15 +609,15 @@ namespace GeomAlgoAPI_ShapeAPI
     const double theStep,
     const int theNumber) throw (GeomAlgoAPI_Exception)
   {
-    if (theNumber <=0) {
+    if (!theAxis) {
       std::string aError = "Multitranslation builder ";
-      aError+=":: the number of copies for the first direction is null or negative.";
+      aError+=":: the first axis is not valid";
       throw GeomAlgoAPI_Exception(aError);
     }
 
-    if (!theAxis) {
+    if (theNumber <=0) {
       std::string aError = "Multitranslation builder ";
-      aError+=":: the first axis is not valid";
+      aError+=":: the number of copies for the first direction is null or negative.";
       throw GeomAlgoAPI_Exception(aError);
     }
 
@@ -623,27 +639,27 @@ namespace GeomAlgoAPI_ShapeAPI
     const double theSecondStep,
     const int theSecondNumber) throw (GeomAlgoAPI_Exception)
   {
-    if (theFirstNumber <=0) {
+    if (!theFirstAxis) {
       std::string aError = "Multitranslation builder ";
-      aError+=":: the number of copies for the first direction is null or negative.";
+      aError+=":: the first axis is not valid";
       throw GeomAlgoAPI_Exception(aError);
     }
 
-    if (theSecondNumber <=0) {
+    if (!theSecondAxis) {
       std::string aError = "Multitranslation builder ";
-      aError+=":: the number of copies for the second direction is null or negative.";
+      aError+=":: the second axis is not valid";
       throw GeomAlgoAPI_Exception(aError);
     }
 
-    if (!theFirstAxis) {
+    if (theFirstNumber <=0) {
       std::string aError = "Multitranslation builder ";
-      aError+=":: the first axis is not valid";
+      aError+=":: the number of copies for the first direction is null or negative.";
       throw GeomAlgoAPI_Exception(aError);
     }
 
-    if (!theSecondAxis) {
+    if (theSecondNumber <=0) {
       std::string aError = "Multitranslation builder ";
-      aError+=":: the second axis is not valid";
+      aError+=":: the number of copies for the second direction is null or negative.";
       throw GeomAlgoAPI_Exception(aError);
     }
 
@@ -671,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,