Salome HOME
Improved stability of Test2248 sketch faces order.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Pipe.cpp
index ca171dd01688e8105dea871d4a18588fb29e7761..ca72a5aeb951bc15b49bf129cd14b79e5e0e3508 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        FeaturesPlugin_Pipe.cpp
-// Created:     16 March 2016
-// Author:      Dmitry Bobylev
+// 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 "FeaturesPlugin_Pipe.h"
 
@@ -78,7 +92,8 @@ void FeaturesPlugin_Pipe::execute()
       GeomAPI_Shape::ShapeType aST = aBaseShape->shapeType();
       ResultConstructionPtr aConstruction =
         std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseObjectSelection->context());
-      if(aConstruction.get() && !aBaseShape->isEqual(aConstruction->shape()) && aST == GeomAPI_Shape::WIRE) {
+      if(aConstruction.get() && !aBaseShape->isEqual(aConstruction->shape()) &&
+          aST == GeomAPI_Shape::WIRE) {
         // It is a wire on the sketch, store it to make face later.
         aSketchWiresMap[aConstruction].push_back(aBaseShape);
         continue;
@@ -88,7 +103,8 @@ void FeaturesPlugin_Pipe::execute()
       }
     } else {
       // This may be the whole sketch result selected, check and get faces.
-      ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseObjectSelection->context());
+      ResultConstructionPtr aConstruction =
+        std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseObjectSelection->context());
       if(!aConstruction.get()) {
         setError("Error: One of selected sketches does not have results.");
         return;
@@ -103,7 +119,8 @@ void FeaturesPlugin_Pipe::execute()
         }
       } else {
         for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
-          std::shared_ptr<GeomAPI_Shape> aBaseFace = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
+          std::shared_ptr<GeomAPI_Shape> aBaseFace =
+            std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
           if(!aBaseFace.get() || aBaseFace->isNull()) {
             setError("Error: One of the faces on selected sketch is Null.");
             return;
@@ -129,11 +146,13 @@ void FeaturesPlugin_Pipe::execute()
   }
 
   // Searching faces with common edges.
-  if(aCreationMethod == "simple") {
+  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);
+    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());
   } else {
@@ -146,7 +165,8 @@ void FeaturesPlugin_Pipe::execute()
     setError("Error: Path selection is empty.");
     return;
   }
-  std::shared_ptr<GeomAPI_Shape> aPathShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aPathSelection->value());
+  std::shared_ptr<GeomAPI_Shape> aPathShape =
+    std::dynamic_pointer_cast<GeomAPI_Shape>(aPathSelection->value());
   if(!aPathShape.get()) {
     // Probaply it is a construction.
     aPathShape = aPathSelection->context()->shape();
@@ -158,7 +178,7 @@ void FeaturesPlugin_Pipe::execute()
 
   // Getting Bi-Normal
   std::shared_ptr<GeomAPI_Shape> aBiNormal;
-  if(aCreationMethod == "binormal") {
+  if(aCreationMethod == CREATION_METHOD_BINORMAL()) {
     AttributeSelectionPtr aBiNormalSelection = selection(BINORMAL_ID());
     if(!aBiNormalSelection.get()) {
       setError("Error: Bi-Normal selection is empty.");
@@ -177,7 +197,7 @@ void FeaturesPlugin_Pipe::execute()
 
   // Getting locations.
   ListOfShape aLocations;
-  if(aCreationMethod == "locations") {
+  if(aCreationMethod == CREATION_METHOD_LOCATIONS()) {
     AttributeSelectionListPtr aLocationsSelectionList = selectionList(LOCATIONS_ID());
     if(!aLocationsSelectionList.get()) {
       setError("Error: Could not get locations selection list.");
@@ -204,12 +224,15 @@ void FeaturesPlugin_Pipe::execute()
 
   // Generating result for each object.
   int aResultIndex = 0;
-  if(aCreationMethod == "simple" || aCreationMethod == "binormal") {
-    for(ListOfShape::const_iterator anIter = aBaseShapesList.cbegin(); anIter != aBaseShapesList.cend(); anIter++) {
+  if(aCreationMethod == CREATION_METHOD_SIMPLE() ||
+      aCreationMethod == CREATION_METHOD_BINORMAL()) {
+    for(ListOfShape::const_iterator
+        anIter = aBaseShapesList.cbegin(); anIter != aBaseShapesList.cend(); anIter++) {
       std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIter;
 
-      GeomAlgoAPI_Pipe aPipeAlgo = aCreationMethod == "simple" ? GeomAlgoAPI_Pipe(aBaseShape, aPathShape) :
-                                                                 GeomAlgoAPI_Pipe(aBaseShape, aPathShape, aBiNormal);
+      GeomAlgoAPI_Pipe aPipeAlgo = aCreationMethod ==
+        CREATION_METHOD_SIMPLE() ? GeomAlgoAPI_Pipe(aBaseShape, aPathShape) :
+                                   GeomAlgoAPI_Pipe(aBaseShape, aPathShape, aBiNormal);
 
       if(!aPipeAlgo.isDone()) {
         setError("Error: Pipe algorithm failed.");
@@ -231,7 +254,7 @@ void FeaturesPlugin_Pipe::execute()
 
       storeResult(aBaseShape, aPipeAlgo, aResultIndex++);
     }
-  } else if(aCreationMethod == "locations") {
+  } else if(aCreationMethod == CREATION_METHOD_LOCATIONS()) {
     GeomAlgoAPI_Pipe aPipeAlgo = GeomAlgoAPI_Pipe(aBaseShapesList, aLocations, aPathShape);
 
     if(!aPipeAlgo.isDone()) {
@@ -308,20 +331,21 @@ void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr<GeomAPI_Shape> theBa
     }
   }
 
-  if(aShapeTypeToExplode == GeomAPI_Shape::VERTEX || aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) {
+  if(aShapeTypeToExplode == GeomAPI_Shape::VERTEX ||
+      aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) {
     aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, theBaseShape, GeomAPI_Shape::VERTEX,
-                                              aGenTag++, aGenName + "Edge", *aMapOfSubShapes.get());
+                                           aGenTag++, aGenName + "Edge", *aMapOfSubShapes.get());
   }
-  if(aShapeTypeToExplode == GeomAPI_Shape::EDGE || aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) {
+  if(aShapeTypeToExplode == GeomAPI_Shape::EDGE ||
+      aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) {
     aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, theBaseShape, GeomAPI_Shape::EDGE,
-                                              aGenTag++, aGenName + "Face", *aMapOfSubShapes.get());
+                                           aGenTag++, aGenName + "Face", *aMapOfSubShapes.get());
   }
 
-  aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, theBaseShape, aShapeTypeToExplode, aGenTag++, aGenName, *aMapOfSubShapes.get());
-
   // Store from shapes.
   int aFromTag = aGenTag;
-  storeShapes(aResultBody, aBaseShapeType, aMapOfSubShapes, thePipeAlgo.fromShapes(), "From_", aFromTag);
+  storeShapes(aResultBody, aBaseShapeType, aMapOfSubShapes,
+              thePipeAlgo.fromShapes(), "From_", aFromTag);
 
   // Store to shapes.
   int aToTag = aFromTag;
@@ -345,7 +369,8 @@ void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes,
   int aGenTag = 1;
   std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfSubShapes = thePipeAlgo.mapOfSubShapes();
 
-  for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
+  for(ListOfShape::const_iterator
+      anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
     GeomShapePtr aBaseShape = *anIter;
     GeomAPI_Shape::ShapeType aBaseShapeType = aBaseShape->shapeType();
     GeomAPI_Shape::ShapeType aShapeTypeToExplode;
@@ -373,16 +398,19 @@ void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes,
         break;
       }
     }
-    aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, aBaseShape, aShapeTypeToExplode, aGenTag++, aGenName, *aMapOfSubShapes.get());
+    aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, aBaseShape, aShapeTypeToExplode,
+                                              aGenTag++, aGenName, *aMapOfSubShapes.get());
   }
 
   // Store from shapes.
   int aFromTag = aGenTag;
-  storeShapes(aResultBody, theBaseShapes.front()->shapeType(), aMapOfSubShapes, thePipeAlgo.fromShapes(), "From", aFromTag);
+  storeShapes(aResultBody, theBaseShapes.front()->shapeType(), aMapOfSubShapes,
+              thePipeAlgo.fromShapes(), "From", aFromTag);
 
   // Store to shapes.
   int aToTag = aFromTag;
-  storeShapes(aResultBody, theBaseShapes.back()->shapeType(), aMapOfSubShapes, thePipeAlgo.toShapes(), "To", aToTag);
+  storeShapes(aResultBody, theBaseShapes.back()->shapeType(),
+              aMapOfSubShapes, thePipeAlgo.toShapes(), "To", aToTag);
 
 
   setResult(aResultBody, theResultIndex);
@@ -390,11 +418,11 @@ void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes,
 
 //==================================================================================================
 void FeaturesPlugin_Pipe::storeShapes(ResultBodyPtr theResultBody,
-                                      const GeomAPI_Shape::ShapeType theBaseShapeType,
-                                      const std::shared_ptr<GeomAPI_DataMapOfShapeShape> theMapOfSubShapes,
-                                      const ListOfShape& theShapes,
-                                      const std::string theName,
-                                      int& theTag)
+                              const GeomAPI_Shape::ShapeType theBaseShapeType,
+                              const std::shared_ptr<GeomAPI_DataMapOfShapeShape> theMapOfSubShapes,
+                              const ListOfShape& theShapes,
+                              const std::string theName,
+                              int& theTag)
 {
   GeomAPI_Shape::ShapeType aShapeTypeToExplore = GeomAPI_Shape::FACE;
   std::string aShapeTypeStr = "Face";