From 606daaeec8fffdf1592853893aa6f8fc9919e451 Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 10 Jul 2015 15:10:14 +0300 Subject: [PATCH] Bug #740 - name of group entity is wrong --- .../FeaturesPlugin_CompositeBoolean.cpp | 74 ++++++++++++++++--- .../FeaturesPlugin_CompositeBoolean.h | 8 +- .../FeaturesPlugin_ExtrusionBoolean.cpp | 20 +++-- .../FeaturesPlugin_ExtrusionBoolean.h | 4 +- .../FeaturesPlugin_RevolutionBoolean.cpp | 20 +++-- .../FeaturesPlugin_RevolutionBoolean.h | 4 +- 6 files changed, 99 insertions(+), 31 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp index e15cf507a..56323a20b 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp @@ -11,6 +11,8 @@ #include #include +#include +#include #include //================================================================================================= @@ -118,7 +120,9 @@ void FeaturesPlugin_CompositeBoolean::execute() } // Pass faces to soldis creation function. - ListOfShape aBooleanTools = MakeSolids(aSketchFacesList); + ListOfShape aBooleanTools; + std::list> theSolidsAlgos; + makeSolids(aSketchFacesList, aBooleanTools, theSolidsAlgos); if(aBooleanTools.empty()) { return; } @@ -159,7 +163,7 @@ void FeaturesPlugin_CompositeBoolean::execute() if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) { std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - LoadNamingDS(aResultBody, anObject, aBooleanTools, aBoolAlgo); + loadNamingDS(aResultBody, anObject, aSketchFacesList, theSolidsAlgos, aBooleanTools, aBoolAlgo); setResult(aResultBody, aResultIndex); aResultIndex++; } @@ -177,7 +181,7 @@ void FeaturesPlugin_CompositeBoolean::execute() } std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - LoadNamingDS(aResultBody, aBooleanObjects.front(), aBooleanTools, aBoolAlgo); + loadNamingDS(aResultBody, aBooleanObjects.front(), aSketchFacesList, theSolidsAlgos, aBooleanTools, aBoolAlgo); setResult(aResultBody, aResultIndex); aResultIndex++; break; @@ -193,8 +197,10 @@ void FeaturesPlugin_CompositeBoolean::execute() } //================================================================================================= -void FeaturesPlugin_CompositeBoolean::LoadNamingDS(std::shared_ptr theResultBody, +void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptr theResultBody, const std::shared_ptr& theBaseShape, + const ListOfShape& theFaces, + const std::list>& theSolidsAlgos, const ListOfShape& theTools, const GeomAlgoAPI_Boolean& theAlgo) { @@ -202,23 +208,69 @@ void FeaturesPlugin_CompositeBoolean::LoadNamingDS(std::shared_ptrisEqual(theAlgo.shape())) { theResultBody->store(theAlgo.shape()); } else { - const int aModTag = 1; - const int aDeleteTag = 2; - const int aSubsolidsTag=3; /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids + const int aGenTag = 1; + const int aFrTag = 2; + const int aToTag = 3; + const int aModTag = 4; + const int aDelTag = 5; + const int aSubsolidsTag=6; /// sub solids will be placed at labels 6, 7, etc. if result is compound of solids + const std::string aGenName = "Generated"; + const std::string aModName = "Modified"; + const std::string aLatName = "LateralFace"; + const std::string aFrName = "FromFace"; + const std::string aToName = "ToFace"; theResultBody->storeModified(theBaseShape, theAlgo.shape(), aSubsolidsTag); - GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape(); + ListOfShape::const_iterator aFaceIter = theFaces.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; + 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, + aLatName, *aSubShapes.get()); + aFromFace = aPrismAlgo->firstShape(); + aToFace = aPrismAlgo->lastShape(); + } 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, + aLatName, *aSubShapes.get()); + aFromFace = aRevolAlgo->firstShape(); + aToFace = aRevolAlgo->lastShape(); + } + + //Insert bottom face + if(!aFromFace->isNull()) { + if(aSubShapes->isBound(aFromFace)) { + aFromFace = aSubShapes->find(aFromFace); + } + theResultBody->generated(aFromFace, aFrName, aFrTag); + } + + //Insert top face + if (!aToFace->isNull()) { + if (aSubShapes->isBound(aToFace)) { + aToFace = aSubShapes->find(aToFace); + } + theResultBody->generated(aToFace, aToName, aToTag); + } + } - const std::string aModName = "Modified"; theResultBody->loadAndOrientModifiedShapes(theAlgo.makeShape().get(), theBaseShape, GeomAPI_Shape::FACE, aModTag, aModName, *theAlgo.mapOfShapes().get()); - theResultBody->loadDeletedShapes(theAlgo.makeShape().get(), theBaseShape, GeomAPI_Shape::FACE, aDeleteTag); + theResultBody->loadDeletedShapes(theAlgo.makeShape().get(), theBaseShape, GeomAPI_Shape::FACE, aDelTag); for(ListOfShape::const_iterator anIter = theTools.begin(); anIter != theTools.end(); anIter++) { theResultBody->loadAndOrientModifiedShapes(theAlgo.makeShape().get(), *anIter, GeomAPI_Shape::FACE, aModTag, aModName, *theAlgo.mapOfShapes().get()); - theResultBody->loadDeletedShapes(theAlgo.makeShape().get(), *anIter, GeomAPI_Shape::FACE, aDeleteTag); + theResultBody->loadDeletedShapes(theAlgo.makeShape().get(), *anIter, GeomAPI_Shape::FACE, aDelTag); } } } diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h index 6838e931b..0b16d5df7 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h @@ -68,10 +68,14 @@ protected: virtual void initMakeSolidsAttributes() = 0; /// Define this function to create solids from faces with extrusion/revolution. - virtual ListOfShape MakeSolids(const ListOfShape& theFaces) = 0; + virtual void makeSolids(const ListOfShape& theFaces, + ListOfShape& theResults, + std::list>& theAlgos) = 0; - void LoadNamingDS(std::shared_ptr theResultBody, + void loadNamingDS(std::shared_ptr theResultBody, const std::shared_ptr& theBaseShape, + const ListOfShape& theFaces, + const std::list>& theAlgos, const ListOfShape& theTools, const GeomAlgoAPI_Boolean& theAlgo); diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp index 2a564e955..cc0b7b783 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp @@ -33,7 +33,9 @@ void FeaturesPlugin_ExtrusionBoolean::initMakeSolidsAttributes() } //================================================================================================= -ListOfShape FeaturesPlugin_ExtrusionBoolean::MakeSolids(const ListOfShape& theFaces) +void FeaturesPlugin_ExtrusionBoolean::makeSolids(const ListOfShape& theFaces, + ListOfShape& theResults, + std::list>& theAlgos) { // Getting extrusion sizes. double aToSize = 0.0; @@ -69,18 +71,20 @@ ListOfShape FeaturesPlugin_ExtrusionBoolean::MakeSolids(const ListOfShape& theFa } // Extrude faces. - ListOfShape anExtrusionList; + theResults.clear(); for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) { std::shared_ptr aBaseShape = *aFacesIt; - GeomAlgoAPI_Prism aPrismAlgo(aBaseShape, aToShape, aToSize, aFromShape, aFromSize); + std::shared_ptr aPrismAlgo = std::make_shared(aBaseShape, + aToShape, aToSize, + aFromShape, aFromSize); // Checking that the algorithm worked properly. - if(!aPrismAlgo.isDone() || aPrismAlgo.shape()->isNull() || !aPrismAlgo.isValid()) { + if(!aPrismAlgo->isDone() || aPrismAlgo->shape()->isNull() || !aPrismAlgo->isValid()) { setError("Extrusion algorithm failed"); - return ListOfShape(); + theResults.clear(); + return; } - anExtrusionList.push_back(aPrismAlgo.shape()); + theResults.push_back(aPrismAlgo->shape()); + theAlgos.push_back(aPrismAlgo); } - - return anExtrusionList; } \ No newline at end of file diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.h b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.h index f83ec9147..6ae91aeec 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.h +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.h @@ -70,7 +70,9 @@ protected: virtual void initMakeSolidsAttributes(); /// Create solids from faces with extrusion. - virtual ListOfShape MakeSolids(const ListOfShape& theFaces); + virtual void makeSolids(const ListOfShape& theFaces, + ListOfShape& theResults, + std::list>& theAlgos); protected: FeaturesPlugin_ExtrusionBoolean(){}; diff --git a/src/FeaturesPlugin/FeaturesPlugin_RevolutionBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_RevolutionBoolean.cpp index ef3af8ec6..7fd3e44cd 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_RevolutionBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_RevolutionBoolean.cpp @@ -37,7 +37,9 @@ void FeaturesPlugin_RevolutionBoolean::initMakeSolidsAttributes() } //================================================================================================= -ListOfShape FeaturesPlugin_RevolutionBoolean::MakeSolids(const ListOfShape& theFaces) +void FeaturesPlugin_RevolutionBoolean::makeSolids(const ListOfShape& theFaces, + ListOfShape& theResults, + std::list>& theAlgos) { //Getting axis. std::shared_ptr anAxis; @@ -86,18 +88,20 @@ ListOfShape FeaturesPlugin_RevolutionBoolean::MakeSolids(const ListOfShape& theF } // Revol faces. - ListOfShape aRevolutionList; + theResults.clear(); for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) { std::shared_ptr aBaseShape = *aFacesIt; - GeomAlgoAPI_Revolution aRevolAlgo(aBaseShape, anAxis, aToShape, aToAngle, aFromShape, aFromAngle); + std::shared_ptr aRevolAlgo = std::make_shared(aBaseShape, anAxis, + aToShape, aToAngle, + aFromShape, aFromAngle); // Checking that the algorithm worked properly. - if(!aRevolAlgo.isDone() || aRevolAlgo.shape()->isNull() || !aRevolAlgo.isValid()) { + if(!aRevolAlgo->isDone() || aRevolAlgo->shape()->isNull() || !aRevolAlgo->isValid()) { setError("Revolution algorithm failed"); - return ListOfShape(); + theResults.clear(); + return; } - aRevolutionList.push_back(aRevolAlgo.shape()); + theResults.push_back(aRevolAlgo->shape()); + theAlgos.push_back(aRevolAlgo); } - - return aRevolutionList; } \ No newline at end of file diff --git a/src/FeaturesPlugin/FeaturesPlugin_RevolutionBoolean.h b/src/FeaturesPlugin/FeaturesPlugin_RevolutionBoolean.h index 3e8576aad..ce01edd80 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_RevolutionBoolean.h +++ b/src/FeaturesPlugin/FeaturesPlugin_RevolutionBoolean.h @@ -76,7 +76,9 @@ protected: virtual void initMakeSolidsAttributes(); /// Create solids from faces with revolution. - virtual ListOfShape MakeSolids(const ListOfShape& theFaces); + virtual void makeSolids(const ListOfShape& theFaces, + ListOfShape& theResults, + std::list>& theAlgos); protected: FeaturesPlugin_RevolutionBoolean(){}; -- 2.39.2