Salome HOME
Issue #2578: EDF 2018-2 Removal of faces.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_MakeShape.cpp
index 87d38d2b8c12ff8ad933ecb019569e77547fd04c..916feb8142afc338f158f68bd5578f0daecab1c2 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomAlgoAPI_MakeShape.cpp
-// Created:     20 Oct 2014
-// Author:      Sergey ZARITCHNY
+// 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 "GeomAlgoAPI_MakeShape.h"
 
@@ -15,6 +29,7 @@
 #include <TopExp_Explorer.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <GeomAPI_ShapeExplorer.h>
 
 //=================================================================================================
 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
@@ -154,6 +169,11 @@ void GeomAlgoAPI_MakeShape::setShape(const std::shared_ptr<GeomAPI_Shape> theSha
     }
 
     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()));
@@ -201,3 +221,42 @@ void GeomAlgoAPI_MakeShape::initialize() {
     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 ;
+}
+