Salome HOME
Issue #1942: group - names are empty strings
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_MakeShape.cpp
index 5419c4f151465f565c3eaec968608ef3600ac674..dad018f0cee8d427301db1e382540b5df2e37a49 100644 (file)
@@ -3,6 +3,8 @@
 // File:        GeomAlgoAPI_MakeShape.cpp
 // Created:     20 Oct 2014
 // Author:      Sergey ZARITCHNY
+//
+// Modified by Clarisse Genrault (CEA) : 17 Mar 2016
 
 #include "GeomAlgoAPI_MakeShape.h"
 
 #include <TopExp_Explorer.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <GeomAPI_ShapeExplorer.h>
 
 //=================================================================================================
 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
-: myBuilderType(UNKNOWN),
+: myBuilderType(Unknown),
   myDone(false)
 {
 }
@@ -91,7 +94,10 @@ void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr<GeomAPI_Shape> theSha
   TopTools_ListOfShape aList;
   if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
-    aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
+    try {
+      aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
+    } catch(Standard_NoSuchObject) {
+    }
   } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
     aList = aBOPBuilder->Modified(theShape->impl<TopoDS_Shape>());
@@ -150,8 +156,18 @@ void GeomAlgoAPI_MakeShape::setShape(const std::shared_ptr<GeomAPI_Shape> theSha
       myMap.reset(new GeomAPI_DataMapOfShapeShape);
     }
 
-    const TopoDS_Shape& aTopoDSSHape = myShape->impl<TopoDS_Shape>();
-    for(TopExp_Explorer anExp(aTopoDSSHape,TopAbs_FACE); anExp.More(); anExp.Next()) {
+    const TopoDS_Shape& aTopoDSShape = myShape->impl<TopoDS_Shape>();
+    for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_VERTEX); anExp.More(); anExp.Next()) {
+      std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
+      aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
+      myMap->bind(aCurrentShape, aCurrentShape);
+    }
+    for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_EDGE); anExp.More(); anExp.Next()) {
+      std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
+      aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
+      myMap->bind(aCurrentShape, aCurrentShape);
+    }
+    for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) {
       std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
       aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
       myMap->bind(aCurrentShape, aCurrentShape);
@@ -179,4 +195,56 @@ void GeomAlgoAPI_MakeShape::initialize() {
       break;
     }
   }
+
+  if(myMap.get()) {
+    myMap->clear();
+  } else {
+    myMap.reset(new GeomAPI_DataMapOfShapeShape);
+  }
+
+  const TopoDS_Shape& aTopoDSShape = myShape->impl<TopoDS_Shape>();
+  for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) {
+    std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
+    aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
+    myMap->bind(aCurrentShape, aCurrentShape);
+  }
+}
+
+
+//=================================================================================================
+void GeomAlgoAPI_MakeShape::prepareNamingFaces()
+{
+  long long index = 1;
+  GeomAPI_ShapeExplorer anExp(shape(), GeomAPI_Shape::FACE);
+  for(GeomAPI_ShapeExplorer anExp(shape(), GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {
+    std::shared_ptr<GeomAPI_Shape> aFace = anExp.current();
+    myCreatedFaces["Face_" + std::to_string(index++)] = aFace;
+  }
+}
+
+
+//=================================================================================================
+bool GeomAlgoAPI_MakeShape::checkValid(std::string theMessage){
+
+  // isValid() is called from this method
+  if (!isValid()) {
+    myError = theMessage + " :: resulting shape is not valid.";
+    return false;
+  }
+
+  // Check the number of volumes in myShape, make sure there's one and only one.
+  TopoDS_Shape aTopoDSShape = myShape->impl<TopoDS_Shape>();
+  int aNbVolumes = 0;
+  for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_SOLID); anExp.More(); anExp.Next()) {
+    aNbVolumes ++;
+  }
+
+  if (aNbVolumes != 1) {
+    myError = theMessage +
+      " :: connexity error, the resulting shape is made of several separate solids.";
+    return false;
+  }
+
+  return true ;
 }
+