Salome HOME
Fix for the issue #2274: closing the study takes too much time.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Pipe.cpp
index 1782c5d453fc628da0f031b631b8d92d223ac5e8..236f8e944d0efdc87925cc54a9a697170d8d55bb 100644 (file)
@@ -14,7 +14,8 @@
 // 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>
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
 //
 
 #include "GeomAlgoAPI_Pipe.h"
@@ -213,49 +214,66 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes,
   }
 
   // Making pipe.
-  BRepOffsetAPI_MakePipeShell* aPipeBuilder = new BRepOffsetAPI_MakePipeShell(aPathWire);
-  if(!aPipeBuilder) {
-    return;
-  }
+  Standard_Boolean isDone = Standard_False;
   bool anIsSolidNeeded = false;
-  ListOfShape::const_iterator aBaseIt = theBaseShapes.cbegin();
-  ListOfShape::const_iterator aLocIt = theLocations.cbegin();
-  while(aBaseIt != theBaseShapes.cend()) {
-    GeomShapePtr aBase = *aBaseIt;
-    TopoDS_Shape aBaseShape;
-    TopAbs_ShapeEnum aBaseShapeType;
-    if(!getBase(aBaseShape, aBaseShapeType, aBase)) {
-      delete aPipeBuilder;
+  BRepOffsetAPI_MakePipeShell* aPipeBuilder;
+  for(int i = 0; i < 2; ++i) {
+    aPipeBuilder = new BRepOffsetAPI_MakePipeShell(aPathWire);
+    if(!aPipeBuilder) {
       return;
     }
-    ++aBaseIt;
-    if(aBaseShapeType == TopAbs_FACE) {
-      anIsSolidNeeded = true;
-    }
-
-    if(aHasLocations) {
-      GeomShapePtr aLocation = *aLocIt;
-      if(!aLocation.get() || aLocation->shapeType() != GeomAPI_Shape::VERTEX) {
+    ListOfShape::const_iterator aBaseIt = theBaseShapes.cbegin();
+    ListOfShape::const_iterator aLocIt = theLocations.cbegin();
+    while(aBaseIt != theBaseShapes.cend()) {
+      GeomShapePtr aBase = *aBaseIt;
+      TopoDS_Shape aBaseShape;
+      TopAbs_ShapeEnum aBaseShapeType;
+      if(!getBase(aBaseShape, aBaseShapeType, aBase)) {
         delete aPipeBuilder;
         return;
       }
-      TopoDS_Vertex aLocationVertex = aLocation->impl<TopoDS_Vertex>();
-      ++aLocIt;
-      aPipeBuilder->Add(aBaseShape, aLocationVertex);
-    } else {
-      aPipeBuilder->Add(aBaseShape);
+      ++aBaseIt;
+      if(aBaseShapeType == TopAbs_FACE) {
+        anIsSolidNeeded = true;
+      }
+
+      if(aHasLocations) {
+        GeomShapePtr aLocation = *aLocIt;
+        if(!aLocation.get() || aLocation->shapeType() != GeomAPI_Shape::VERTEX) {
+          delete aPipeBuilder;
+          return;
+        }
+        TopoDS_Vertex aLocationVertex = aLocation->impl<TopoDS_Vertex>();
+        ++aLocIt;
+        aPipeBuilder->Add(aBaseShape, aLocationVertex);
+      } else {
+        aPipeBuilder->Add(aBaseShape);
+      }
+    }
+
+    if(aPipeBuilder->IsReady() == Standard_False) {
+      delete aPipeBuilder;
+      return;
+    }
+
+    if (i == 1) {
+       // Try to use Descrete Trihedron mode.
+      aPipeBuilder->SetDiscreteMode();
+    }
+    aPipeBuilder->Build();
+    isDone = aPipeBuilder->IsDone();
+
+    if (isDone) {
+      break;
     }
-  }
 
-  if(aPipeBuilder->IsReady() == Standard_False) {
     delete aPipeBuilder;
-    return;
   }
 
-  if(!buildPipe(aPipeBuilder)) {
-    delete aPipeBuilder;
+  if (!isDone) {
     return;
   }
+
   this->initialize(aPipeBuilder);
 
   // Checking result.