Salome HOME
Fix for the problem of the nightly unit-tests performance.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Pipe.cpp
index 425ac1f49b315a5c9664f81c9debb5ce4a1aacc1..c3a38788782385f5fa00772b093daaa95fefc2fb 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_Pipe.h"
@@ -30,6 +29,8 @@
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_Pipe.h>
 #include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_Tools.h>
+
 #include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_ShapeExplorer.h>
 
@@ -145,14 +146,9 @@ void FeaturesPlugin_Pipe::execute()
 
   // Searching faces with common edges.
   if(aCreationMethod == CREATION_METHOD_SIMPLE()) {
-    ListOfShape aShells;
-    ListOfShape aFreeFaces;
     std::shared_ptr<GeomAPI_Shape> aFacesCompound =
       GeomAlgoAPI_CompoundBuilder::compound(aBaseFacesList);
-    GeomAlgoAPI_ShapeTools::combineShapes(aFacesCompound, GeomAPI_Shape::SHELL,
-                                          aShells, aFreeFaces);
-    aBaseShapesList.insert(aBaseShapesList.end(), aFreeFaces.begin(), aFreeFaces.end());
-    aBaseShapesList.insert(aBaseShapesList.end(), aShells.begin(), aShells.end());
+    GeomAlgoAPI_ShapeTools::combineShapes(aFacesCompound, GeomAPI_Shape::SHELL, aBaseShapesList);
   } else {
     aBaseShapesList.insert(aBaseShapesList.end(), aBaseFacesList.begin(), aBaseFacesList.end());
   }
@@ -166,7 +162,7 @@ void FeaturesPlugin_Pipe::execute()
   std::shared_ptr<GeomAPI_Shape> aPathShape =
     std::dynamic_pointer_cast<GeomAPI_Shape>(aPathSelection->value());
   if(!aPathShape.get() && aPathSelection->context().get()) {
-    // Probaply it is a construction.
+    // Probably it is a construction.
     aPathShape = aPathSelection->context()->shape();
   }
   if(!aPathShape.get() || aPathShape->isNull()) {
@@ -222,6 +218,7 @@ void FeaturesPlugin_Pipe::execute()
 
   // Generating result for each object.
   int aResultIndex = 0;
+  std::string anError;
   if(aCreationMethod == CREATION_METHOD_SIMPLE() ||
       aCreationMethod == CREATION_METHOD_BINORMAL()) {
     for(ListOfShape::const_iterator
@@ -235,50 +232,26 @@ void FeaturesPlugin_Pipe::execute()
                                                                            aPathShape,
                                                                            aBiNormal));
 
-      if(!aPipeAlgo->isDone()) {
-        setError("Error: Pipe algorithm failed.");
-        aResultIndex = 0;
-        break;
-      }
-
-      // Check if shape is valid
-      if(!aPipeAlgo->shape().get() || aPipeAlgo->shape()->isNull()) {
-        setError("Error: Resulting shape is Null.");
-        aResultIndex = 0;
-        break;
-      }
-      if(!aPipeAlgo->isValid()) {
-        setError("Error: Resulting shape is not valid.");
+      if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPipeAlgo, getKind(), anError)) {
+        setError(anError);
         aResultIndex = 0;
         break;
       }
 
-      storeResult(aBaseShape, aPipeAlgo, aResultIndex++);
+      storeResult(aBaseShape, aPathShape, aPipeAlgo, aResultIndex++);
     }
   } else if(aCreationMethod == CREATION_METHOD_LOCATIONS()) {
     std::shared_ptr<GeomAlgoAPI_Pipe> aPipeAlgo(new GeomAlgoAPI_Pipe(aBaseShapesList,
                                                                      aLocations,
                                                                      aPathShape));
 
-    if(!aPipeAlgo->isDone()) {
-      setError("Error: Pipe algorithm failed.");
+    if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPipeAlgo, getKind(), anError)) {
+      setError(anError);
       removeResults(0);
       return;
     }
 
-    // Check if shape is valid
-    if(!aPipeAlgo->shape().get() || aPipeAlgo->shape()->isNull()) {
-      setError("Error: Resulting shape is Null.");
-      removeResults(0);
-      return;
-    }
-    if(!aPipeAlgo->isValid()) {
-      setError("Error: Resulting shape is not valid.");
-      removeResults(0);
-      return;
-    }
-
-    storeResult(aBaseShapesList, aPipeAlgo, aResultIndex++);
+    storeResult(aBaseShapesList, aPathShape, aPipeAlgo, aResultIndex++);
   } else {
     setError("Error: Wrong creation method.");
     return;
@@ -289,6 +262,7 @@ void FeaturesPlugin_Pipe::execute()
 
 //==================================================================================================
 void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
+                                      const std::shared_ptr<GeomAPI_Shape> thePathShape,
                                       const std::shared_ptr<GeomAlgoAPI_Pipe> thePipeAlgo,
                                       const int theResultIndex)
 {
@@ -339,6 +313,8 @@ void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr<GeomAPI_Shape> theBa
       aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) {
     aResultBody->loadGeneratedShapes(thePipeAlgo, theBaseShape, GeomAPI_Shape::EDGE);
   }
+  if (thePathShape.get())
+    aResultBody->loadGeneratedShapes(thePipeAlgo, thePathShape, GeomAPI_Shape::EDGE);
 
   // Store from shapes.
   storeShapes(aResultBody, aBaseShapeType, thePipeAlgo->fromShapes(), "From_");
@@ -351,6 +327,7 @@ void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr<GeomAPI_Shape> theBa
 
 //==================================================================================================
 void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes,
+                                      const std::shared_ptr<GeomAPI_Shape> thePathShape,
                                       const std::shared_ptr<GeomAlgoAPI_Pipe> thePipeAlgo,
                                       const int theResultIndex)
 {
@@ -392,6 +369,9 @@ void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes,
     aResultBody->loadGeneratedShapes(thePipeAlgo, aBaseShape, aShapeTypeToExplode);
   }
 
+  if (thePathShape.get())
+    aResultBody->loadGeneratedShapes(thePipeAlgo, thePathShape, GeomAPI_Shape::EDGE);
+
   // Store from shapes.
   storeShapes(aResultBody, theBaseShapes.front()->shapeType(), thePipeAlgo->fromShapes(), "From_");