Salome HOME
Compsolids in composite features
authordbv <dbv@opencascade.com>
Thu, 20 Aug 2015 08:20:47 +0000 (11:20 +0300)
committerdbv <dbv@opencascade.com>
Thu, 20 Aug 2015 08:47:39 +0000 (11:47 +0300)
src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp
src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h
src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp

index f8896999d17ac62a6ea345fb83ce38846db0e230..f0876e1f12201d16fa004018d7297f07b0b6918c 100644 (file)
@@ -12,6 +12,7 @@
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
 
+#include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_Prism.h>
 #include <GeomAlgoAPI_Revolution.h>
 #include <GeomAlgoAPI_ShapeTools.h>
@@ -112,18 +113,29 @@ void FeaturesPlugin_CompositeBoolean::execute()
   }
   int aSketchFacesNum = aConstruction->facesNum();
   if(aSketchFacesNum == 0) {
-    return; //TODO: set error message
+    return;
   }
-  ListOfShape aSketchFacesList;
+  ListOfShape aFacesList;
   for(int aFaceIndex = 0; aFaceIndex < aSketchFacesNum; aFaceIndex++) {
     std::shared_ptr<GeomAPI_Shape> aFace = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
-    aSketchFacesList.push_back(aFace);
+    aFacesList.push_back(aFace);
+  }
+
+  // Searching faces with common edges.
+  ListOfShape aShells;
+  ListOfShape aFreeFaces;
+  std::shared_ptr<GeomAPI_Shape> aFacesCompound = GeomAlgoAPI_CompoundBuilder::compound(aFacesList);
+  GeomAlgoAPI_ShapeTools::combineShapes(aFacesCompound, GeomAPI_Shape::SHELL, aShells, aFreeFaces);
+  if(aShells.empty()) {
+    aShells = aFreeFaces;
+  } else {
+    aShells.merge(aFreeFaces);
   }
 
-  // Pass faces to soldis creation function.
+  // Pass shells/faces to soldis creation function.
   ListOfShape aBooleanTools;
-  std::list<std::shared_ptr<GeomAPI_Interface>> theSolidsAlgos;
-  makeSolids(aSketchFacesList, aBooleanTools, theSolidsAlgos);
+  std::list<std::shared_ptr<GeomAPI_Interface>> aSolidsAlgos;
+  makeSolids(aShells, aBooleanTools, aSolidsAlgos);
   if(aBooleanTools.empty()) {
     return;
   }
@@ -164,7 +176,7 @@ void FeaturesPlugin_CompositeBoolean::execute()
 
         if(GeomAlgoAPI_ShapeTools::volume(aBoolAlgo.shape()) > 1.e-7) {
           std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-          loadNamingDS(aResultBody, anObject, aSketchFacesList, theSolidsAlgos, aBooleanTools, aBoolAlgo);
+          loadNamingDS(aResultBody, anObject, aShells, aSolidsAlgos, aBooleanTools, aBoolAlgo);
           setResult(aResultBody, aResultIndex);
           aResultIndex++;
         }
@@ -182,7 +194,7 @@ void FeaturesPlugin_CompositeBoolean::execute()
       }
 
       std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-      loadNamingDS(aResultBody, aBooleanObjects.front(), aSketchFacesList, theSolidsAlgos, aBooleanTools, aBoolAlgo);
+      loadNamingDS(aResultBody, aBooleanObjects.front(), aShells, aSolidsAlgos, aBooleanTools, aBoolAlgo);
       setResult(aResultBody, aResultIndex);
       aResultIndex++;
       break;
@@ -200,7 +212,7 @@ void FeaturesPlugin_CompositeBoolean::execute()
 //=================================================================================================
 void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
                                                    const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
-                                                   const ListOfShape& theFaces,
+                                                   const ListOfShape& theShells,
                                                    const std::list<std::shared_ptr<GeomAPI_Interface>>& theSolidsAlgos,
                                                    const ListOfShape& theTools,
                                                    const GeomAlgoAPI_Boolean& theAlgo)
@@ -210,7 +222,7 @@ void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptr<ModelAPI_Resu
     theResultBody->store(theAlgo.shape());
   } else {
     const int aGenTag = 1;
-    const int aFrTag = 2;
+    const int aFromTag = 2;
     const int aToTag = 3;
     const int aModTag = 4;
     const int aDelTag = 5;
@@ -218,54 +230,53 @@ void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptr<ModelAPI_Resu
     const std::string aGenName = "Generated";
     const std::string aModName = "Modified";
     const std::string aLatName = "LateralFace";
-    const std::string aFrName = "FromFace";
+    const std::string aFromName = "FromFace";
     const std::string aToName = "ToFace";
 
     theResultBody->storeModified(theBaseShape, theAlgo.shape(), aSubsolidsTag);
 
-    ListOfShape::const_iterator aFaceIter = theFaces.begin();
+    ListOfShape::const_iterator aShellsIter = theShells.begin();
     std::list<std::shared_ptr<GeomAPI_Interface>>::const_iterator aSolidsAlgosIter = theSolidsAlgos.begin();
-    for(; aFaceIter != theFaces.end() && aSolidsAlgosIter != theSolidsAlgos.end(); aFaceIter++, aSolidsAlgosIter++) {
-      std::shared_ptr<GeomAPI_Shape> aFromFace;
-      std::shared_ptr<GeomAPI_Shape> aToFace;
+    for(; aShellsIter != theShells.end() && aSolidsAlgosIter != theSolidsAlgos.end(); aShellsIter++, aSolidsAlgosIter++) {
+      ListOfShape aFromFaces;
+      ListOfShape aToFaces;
       std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes;
 
       //Insert lateral face : Face from Edge
       if(std::dynamic_pointer_cast<GeomAlgoAPI_Prism>(*aSolidsAlgosIter)) {
         std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo = std::dynamic_pointer_cast<GeomAlgoAPI_Prism>(*aSolidsAlgosIter);
         aSubShapes = aPrismAlgo->mapOfShapes();
-        theResultBody->loadAndOrientGeneratedShapes(aPrismAlgo->makeShape().get(), *aFaceIter, GeomAPI_Shape::EDGE, aGenTag,
+        theResultBody->loadAndOrientGeneratedShapes(aPrismAlgo->makeShape().get(), *aShellsIter, GeomAPI_Shape::EDGE, aGenTag,
                                                     aLatName, *aSubShapes.get());
-        //TODO: fix
-        //aFromFace = aPrismAlgo->firstShape();
-        //aToFace = aPrismAlgo->lastShape();
+
+        aFromFaces = aPrismAlgo->fromFaces();
+        aToFaces = aPrismAlgo->toFaces();
       } else if(std::dynamic_pointer_cast<GeomAlgoAPI_Revolution>(*aSolidsAlgosIter)) {
         std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo = std::dynamic_pointer_cast<GeomAlgoAPI_Revolution>(*aSolidsAlgosIter);
         aSubShapes = aRevolAlgo->mapOfShapes();
-        theResultBody->loadAndOrientGeneratedShapes(aRevolAlgo->makeShape().get(), *aFaceIter, GeomAPI_Shape::EDGE, aGenTag,
+        theResultBody->loadAndOrientGeneratedShapes(aRevolAlgo->makeShape().get(), *aShellsIter, GeomAPI_Shape::EDGE, aGenTag,
                                                     aLatName, *aSubShapes.get());
-        //TODO: fix
-        //aFromFace = aRevolAlgo->firstShape();
-        //aToFace = aRevolAlgo->lastShape();
+        aFromFaces = aRevolAlgo->fromFaces();
+        aToFaces = aRevolAlgo->toFaces();
       }
 
-      /*
-      //Insert bottom face
-      if(!aFromFace->isNull()) {
-        if(aSubShapes->isBound(aFromFace)) {
-          aFromFace = aSubShapes->find(aFromFace);
+      //Insert to faces
+      for(ListOfShape::const_iterator anIt = aToFaces.cbegin(); anIt != aToFaces.cend(); anIt++) {
+        std::shared_ptr<GeomAPI_Shape> aToFace = *anIt;
+        if(aSubShapes->isBound(aToFace)) {
+          aToFace = aSubShapes->find(aToFace);
         }
-        theResultBody->generated(aFromFace, aFrName, aFrTag);
+        theResultBody->generated(aToFace, aToName, aToTag);
       }
 
-      //Insert top face
-      if (!aToFace->isNull()) {
-        if (aSubShapes->isBound(aToFace)) {
-          aToFace = aSubShapes->find(aToFace);
+      //Insert from faces
+      for(ListOfShape::const_iterator anIt = aFromFaces.cbegin(); anIt != aFromFaces.cend(); anIt++) {
+        std::shared_ptr<GeomAPI_Shape> aFromFace = *anIt;
+        if(aSubShapes->isBound(aFromFace)) {
+          aFromFace = aSubShapes->find(aFromFace);
         }
-        theResultBody->generated(aToFace, aToName, aToTag);
+        theResultBody->generated(aFromFace, aFromName, aFromTag);
       }
-      */
     }
 
     theResultBody->loadAndOrientModifiedShapes(theAlgo.makeShape().get(), theBaseShape, GeomAPI_Shape::FACE,
index 0b16d5df7c0d95fa89bc2ed746abbb3e6371f58c..d5ce37c380d72f4bc1b2e4caf481e22718a1d6d5 100644 (file)
@@ -74,7 +74,7 @@ protected:
 
   void loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
                     const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
-                    const ListOfShape& theFaces,
+                    const ListOfShape& theShells,
                     const std::list<std::shared_ptr<GeomAPI_Interface>>& theAlgos,
                     const ListOfShape& theTools,
                     const GeomAlgoAPI_Boolean& theAlgo);
index 0a3305bcde991df10043552c0915703f31ceaa26..32b7660e211f8d2658217eaa24dee421d2f665f0 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "GeomAlgoAPI_Boolean.h"
 
+#include <GeomAlgoAPI_DFLoader.h>
+
 #include <BRepAlgoAPI_BooleanOperation.hxx>
 #include <BRepAlgoAPI_Common.hxx>
 #include <BRepAlgoAPI_Cut.hxx>
@@ -114,6 +116,10 @@ void GeomAlgoAPI_Boolean::build(const ListOfShape& theObjects,
   }
   TopoDS_Shape aResult = anOperation->Shape();
 
+  if(aResult.ShapeType() == TopAbs_COMPOUND) {
+    aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+  }
+
   // fill data map to keep correct orientation of sub-shapes
   for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
     std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());