From 6d9dce8d6ca39b0d9c8b01a34cc5b5ec5d5f4a72 Mon Sep 17 00:00:00 2001 From: dbv Date: Thu, 20 Aug 2015 11:20:47 +0300 Subject: [PATCH] Compsolids in composite features --- .../FeaturesPlugin_CompositeBoolean.cpp | 81 +++++++++++-------- .../FeaturesPlugin_CompositeBoolean.h | 2 +- src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp | 6 ++ 3 files changed, 53 insertions(+), 36 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp index f8896999d..f0876e1f1 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -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 aFace = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); - aSketchFacesList.push_back(aFace); + aFacesList.push_back(aFace); + } + + // Searching faces with common edges. + ListOfShape aShells; + ListOfShape aFreeFaces; + std::shared_ptr 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> theSolidsAlgos; - makeSolids(aSketchFacesList, aBooleanTools, theSolidsAlgos); + std::list> 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 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 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 theResultBody, const std::shared_ptr& theBaseShape, - const ListOfShape& theFaces, + const ListOfShape& theShells, const std::list>& theSolidsAlgos, const ListOfShape& theTools, const GeomAlgoAPI_Boolean& theAlgo) @@ -210,7 +222,7 @@ void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptrstore(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_ptrstoreModified(theBaseShape, theAlgo.shape(), aSubsolidsTag); - ListOfShape::const_iterator aFaceIter = theFaces.begin(); + ListOfShape::const_iterator aShellsIter = theShells.begin(); std::list>::const_iterator aSolidsAlgosIter = theSolidsAlgos.begin(); - for(; aFaceIter != theFaces.end() && aSolidsAlgosIter != theSolidsAlgos.end(); aFaceIter++, aSolidsAlgosIter++) { - std::shared_ptr aFromFace; - std::shared_ptr aToFace; + for(; aShellsIter != theShells.end() && aSolidsAlgosIter != theSolidsAlgos.end(); aShellsIter++, aSolidsAlgosIter++) { + ListOfShape aFromFaces; + ListOfShape aToFaces; std::shared_ptr aSubShapes; //Insert lateral face : Face from Edge if(std::dynamic_pointer_cast(*aSolidsAlgosIter)) { std::shared_ptr aPrismAlgo = std::dynamic_pointer_cast(*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(*aSolidsAlgosIter)) { std::shared_ptr aRevolAlgo = std::dynamic_pointer_cast(*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 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 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, diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h index 0b16d5df7..d5ce37c38 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h @@ -74,7 +74,7 @@ protected: void loadNamingDS(std::shared_ptr theResultBody, const std::shared_ptr& theBaseShape, - const ListOfShape& theFaces, + const ListOfShape& theShells, const std::list>& theAlgos, const ListOfShape& theTools, const GeomAlgoAPI_Boolean& theAlgo); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp index 0a3305bcd..32b7660e2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp @@ -6,6 +6,8 @@ #include "GeomAlgoAPI_Boolean.h" +#include + #include #include #include @@ -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 aCurrentShape(new GeomAPI_Shape()); -- 2.39.2