Salome HOME
Add Chamfer feature
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_MultiRotation.cpp
index 85390b59e613968272201a812d7aadd8e3462567..64286a9d7e6d8b70f52cbdfca3d2debc18a95d97 100644 (file)
@@ -1,13 +1,33 @@
-// Copyright (C) 2014-201x CEA/DEN, EDF R&D
+// Copyright (C) 2017-2019  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
+//
 
 // File:        FeaturesPlugin_MultiRotation.cpp
 // Created:     30 Jan 2017
 // Author:      Clarisse Genrault (CEA)
 
 #include <FeaturesPlugin_MultiRotation.h>
+#include <FeaturesPlugin_Tools.h>
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_MakeShapeList.h>
 #include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_Tools.h>
 #include <GeomAlgoAPI_Translation.h>
 
 #include <GeomAPI_ShapeExplorer.h>
@@ -50,24 +70,29 @@ void FeaturesPlugin_MultiRotation::initAttributes()
   data()->addAttribute(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID(),
                        ModelAPI_AttributeInteger::typeId());
 
-  /*data()->addAttribute(FeaturesPlugin_MultiRotation::USE_RADIAL_DIR_ID(),
+#ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS
+  data()->addAttribute(FeaturesPlugin_MultiRotation::USE_RADIAL_DIR_ID(),
                        ModelAPI_AttributeString::typeId());
   data()->addAttribute(FeaturesPlugin_MultiRotation::STEP_RADIAL_ID(),
                        ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(FeaturesPlugin_MultiRotation::NB_COPIES_RADIAL_ID(),
-                       ModelAPI_AttributeInteger::typeId());*/
+                       ModelAPI_AttributeInteger::typeId());
+#endif
 }
 
 //=================================================================================================
 void FeaturesPlugin_MultiRotation::execute()
 {
-  /*std::string useRadialDir = string(FeaturesPlugin_MultiRotation::USE_RADIAL_DIR_ID())->value();
+#ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS
+  std::string useRadialDir = string(FeaturesPlugin_MultiRotation::USE_RADIAL_DIR_ID())->value();
   if (useRadialDir.empty()) {
     performRotation1D();
   } else {
     performRotation2D();
-  }*/
+  }
+#else
   performRotation1D();
+#endif
 }
 
 //=================================================================================================
@@ -79,6 +104,7 @@ void FeaturesPlugin_MultiRotation::performRotation1D()
   AttributeSelectionListPtr anObjectsSelList =
     selectionList(FeaturesPlugin_MultiRotation::OBJECTS_LIST_ID());
   if (anObjectsSelList->size() == 0) {
+    setError("Error: empty selection list");
     return;
   }
   for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
@@ -86,7 +112,6 @@ void FeaturesPlugin_MultiRotation::performRotation1D()
       anObjectsSelList->value(anObjectsIndex);
     std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
     if(!anObject.get()) { // may be for not-activated parts
-      eraseResults();
       return;
     }
     anObjects.push_back(anObject);
@@ -117,11 +142,6 @@ void FeaturesPlugin_MultiRotation::performRotation1D()
     GeomAPI_ShapeIterator anIt(aShape);
     anEdge = anIt.current()->edge();
   }
-  else
-  {
-    setError(aSelectionError);
-    return;
-  }
 
   if (!anEdge.get())
   {
@@ -173,8 +193,10 @@ void FeaturesPlugin_MultiRotation::performRotation1D()
         aResultIndex++;
       }
     } else {
+      std::string anError;
       ListOfShape aListOfShape;
-      std::list<std::shared_ptr<GeomAlgoAPI_Rotation> > aListOfRotationAlgo;
+      std::shared_ptr<GeomAlgoAPI_MakeShapeList>
+          aListOfRotationAlgo(new GeomAlgoAPI_MakeShapeList);
 
       for (int i=0; i<nbCopies; i++) {
         std::shared_ptr<GeomAlgoAPI_Rotation> aRotationnAlgo(
@@ -188,29 +210,21 @@ void FeaturesPlugin_MultiRotation::performRotation1D()
         aRotationnAlgo->build();
 
         // Checking that the algorithm worked properly.
-        if (!aRotationnAlgo->isDone()) {
-          static const std::string aFeatureError = "Error : Multitranslation algorithm failed.";
-          setError(aFeatureError);
-          break;
-        }
-        if (aRotationnAlgo->shape()->isNull()) {
-          static const std::string aShapeError = "Error : Resulting shape is null.";
-          setError(aShapeError);
-          break;
-        }
-        if (!aRotationnAlgo->isValid()) {
-          static const std::string aFeatureError = "Error : Resulting shape in not valid.";
-          setError(aFeatureError);
+        if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationnAlgo, getKind(), anError)) {
+          setError(anError);
           break;
         }
         aListOfShape.push_back(aRotationnAlgo->shape());
-        aListOfRotationAlgo.push_back(aRotationnAlgo);
+        aListOfRotationAlgo->appendAlgo(aRotationnAlgo);
       }
       std::shared_ptr<GeomAPI_Shape> aCompound =
         GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      aResultBody->storeModified(aBaseShape, aCompound);
-      loadNamingDS(aListOfRotationAlgo, aResultBody, aBaseShape);
+
+      ListOfShape aBaseShapes;
+      aBaseShapes.push_back(aBaseShape);
+      FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, aBaseShapes, ListOfShape(),
+                                               aListOfRotationAlgo, aCompound, "Rotated");
 
       setResult(aResultBody, aResultIndex);
     }
@@ -222,6 +236,7 @@ void FeaturesPlugin_MultiRotation::performRotation1D()
 }
 
 //=================================================================================================
+#ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS
 void FeaturesPlugin_MultiRotation::performRotation2D()
 {
   // Getting objects.
@@ -237,7 +252,6 @@ void FeaturesPlugin_MultiRotation::performRotation2D()
       anObjectsSelList->value(anObjectsIndex);
     std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
     if(!anObject.get()) { // may be for not-activated parts
-      eraseResults();
       return;
     }
     anObjects.push_back(anObject);
@@ -449,22 +463,4 @@ void FeaturesPlugin_MultiRotation::loadNamingDS3(
     ++anIndex;
   }
 }
-
-//=================================================================================================
-void FeaturesPlugin_MultiRotation::loadNamingDS(
-    std::list<std::shared_ptr<GeomAlgoAPI_Rotation> > theListOfRotationAlgo,
-    std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-    std::shared_ptr<GeomAPI_Shape> theBaseShape)
-{
-  for (std::list<std::shared_ptr<GeomAlgoAPI_Rotation> >::const_iterator anIt =
-    theListOfRotationAlgo.begin(); anIt != theListOfRotationAlgo.cend(); ++anIt) {
-    // naming of faces
-    theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::FACE, "Rotated_Face");
-
-    // naming of edges
-    theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::EDGE, "Rotated_Edge");
-
-    // naming of vertex
-    theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::VERTEX, "Rotated_Vertex");
-  }
-}
+#endif