Salome HOME
Implementation of the task #3109 : Feature Copy. Documentation and translation.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Translation.cpp
index 14de51957495cab9d5ece56bf93838060611d125..eff54dc689f759480f280cca2cc47ef3a11f5a39 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-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
 //
 // 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
+// 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>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include <FeaturesPlugin_Translation.h>
@@ -34,6 +33,7 @@
 #include <GeomAPI_Trsf.h>
 
 #include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAlgoAPI_Tools.h>
 
 #include <FeaturesPlugin_Tools.h>
 
@@ -150,6 +150,7 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance()
   double aDistance = real(FeaturesPlugin_Translation::DISTANCE_ID())->value();
 
   // Moving each object.
+  std::string anError;
   int aResultIndex = 0;
   std::list<ResultPtr>::iterator aContext = aContextes.begin();
   for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
@@ -177,27 +178,20 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance()
       aTranslationAlgo->build();
 
       // Checking that the algorithm worked properly.
-      if(!aTranslationAlgo->isDone()) {
-        static const std::string aFeatureError = "Error: Translation algorithm failed.";
-        setError(aFeatureError);
-        break;
-      }
-      if(aTranslationAlgo->shape()->isNull()) {
-        static const std::string aShapeError = "Error: Resulting shape is Null.";
-        setError(aShapeError);
-        break;
-      }
-      if(!aTranslationAlgo->isValid()) {
-        std::string aFeatureError = "Error: Resulting shape is not valid.";
-        setError(aFeatureError);
+      if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) {
+        setError(anError);
         break;
       }
 
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      aResultBody->storeModified(aBaseShape, aTranslationAlgo->shape());
+
+      ListOfShape aShapes;
+      aShapes.push_back(aBaseShape);
       FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
-                                               aBaseShape,
+                                               aShapes,
+                                               ListOfShape(),
                                                aTranslationAlgo,
+                                               aTranslationAlgo->shape(),
                                                "Translated");
       setResult(aResultBody, aResultIndex);
     }
@@ -236,6 +230,7 @@ void FeaturesPlugin_Translation::performTranslationByDimensions()
   double aDZ = real(FeaturesPlugin_Translation::DZ_ID())->value();
 
   // Moving each object.
+  std::string anError;
   int aResultIndex = 0;
   std::list<ResultPtr>::iterator aContext = aContextes.begin();
   for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
@@ -263,27 +258,20 @@ void FeaturesPlugin_Translation::performTranslationByDimensions()
       aTranslationAlgo->build();
 
       // Checking that the algorithm worked properly.
-      if(!aTranslationAlgo->isDone()) {
-        static const std::string aFeatureError = "Error: Translation algorithm failed.";
-        setError(aFeatureError);
-        break;
-      }
-      if(aTranslationAlgo->shape()->isNull()) {
-        static const std::string aShapeError = "Error: Resulting shape is Null.";
-        setError(aShapeError);
-        break;
-      }
-      if(!aTranslationAlgo->isValid()) {
-        std::string aFeatureError = "Error: Resulting shape is not valid.";
-        setError(aFeatureError);
+      if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) {
+        setError(anError);
         break;
       }
 
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      aResultBody->storeModified(aBaseShape, aTranslationAlgo->shape());
+
+      ListOfShape aShapes;
+      aShapes.push_back(aBaseShape);
       FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
-                                               aBaseShape,
+                                               aShapes,
+                                               ListOfShape(),
                                                aTranslationAlgo,
+                                               aTranslationAlgo->shape(),
                                                "Translated");
       setResult(aResultBody, aResultIndex);
     }
@@ -335,6 +323,7 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints()
   }
 
   // Moving each object.
+  std::string anError;
   int aResultIndex = 0;
   std::list<ResultPtr>::iterator aContext = aContextes.begin();
   for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
@@ -362,27 +351,20 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints()
       aTranslationAlgo->build();
 
       // Checking that the algorithm worked properly.
-      if(!aTranslationAlgo->isDone()) {
-        static const std::string aFeatureError = "Error: Translation algorithm failed.";
-        setError(aFeatureError);
-        break;
-      }
-      if(aTranslationAlgo->shape()->isNull()) {
-        static const std::string aShapeError = "Error: Resulting shape is Null.";
-        setError(aShapeError);
-        break;
-      }
-      if(!aTranslationAlgo->isValid()) {
-        std::string aFeatureError = "Error: Resulting shape is not valid.";
-        setError(aFeatureError);
+      if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgo, getKind(), anError)) {
+        setError(anError);
         break;
       }
 
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      aResultBody->storeModified(aBaseShape, aTranslationAlgo->shape());
+
+      ListOfShape aShapes;
+      aShapes.push_back(aBaseShape);
       FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
-                                               aBaseShape,
+                                               aShapes,
+                                               ListOfShape(),
                                                aTranslationAlgo,
+                                               aTranslationAlgo->shape(),
                                                "Translated");
       setResult(aResultBody, aResultIndex);
     }