X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Revolution.cpp;h=5a7a34b399d8791c1c086a2412a905f4c12f12c5;hb=676ee79de539b14b242a561857c1505cce13d951;hp=503c1c8a9232c007df9cd84a29c10735df5cacee;hpb=3a3609cb2e2f171082ca2e807e6c8c8ba24d1075;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp index 503c1c8a9..5a7a34b39 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp @@ -4,7 +4,7 @@ // Created: 12 May 2015 // Author: Dmitry Bobylev -#include +#include "FeaturesPlugin_Revolution.h" #include #include @@ -20,6 +20,8 @@ #include #include +#include + //================================================================================================= FeaturesPlugin_Revolution::FeaturesPlugin_Revolution() { @@ -58,34 +60,26 @@ void FeaturesPlugin_Revolution::execute() ListOfShape aFacesList; AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID()); for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) { - std::shared_ptr aFaceSel = aFacesSelectionList->value(anIndex); - ResultPtr aContext = aFaceSel->context(); - std::shared_ptr aContextShape = aContext->shape(); - if(!aContextShape.get()) { - static const std::string aContextError = "The selection context is bad"; - setError(aContextError); - break; - } - + AttributeSelectionPtr aFaceSel = aFacesSelectionList->value(anIndex); std::shared_ptr aFaceShape = aFaceSel->value(); - int aFacesNum = -1; // this mean that "aFace" is used - ResultConstructionPtr aConstruction = - std::dynamic_pointer_cast(aContext); - if(!aFaceShape.get()) { // this may be the whole sketch result selected, check and get faces - if (aConstruction.get()) { - aFacesNum = aConstruction->facesNum(); - } else { - static const std::string aFaceError = "Can not find basis for revolution"; + if(aFaceShape.get() && !aFaceShape->isNull()) { // Getting face. + aFacesList.push_back(aFaceShape); + } else { // This may be the whole sketch result selected, check and get faces. + ResultPtr aContext = aFaceSel->context(); + std::shared_ptr aContextShape = aContext->shape(); + if(!aContextShape.get()) { + static const std::string aContextError = "Error: The selection context is bad."; + setError(aContextError); + return; + } + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aContext); + if(!aConstruction.get()) { + static const std::string aFaceError = "Error: Can not find basis for revolution."; setError(aFaceError); - break; + return; } - } - for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) { - std::shared_ptr aBaseShape; - if (aFacesNum == -1) { - aFacesList.push_back(aFaceShape); - break; - } else { + int aFacesNum = aConstruction->facesNum(); + for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) { aFaceShape = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); aFacesList.push_back(aFaceShape); } @@ -143,9 +137,7 @@ void FeaturesPlugin_Revolution::execute() ListOfShape aFreeFaces; std::shared_ptr aFacesCompound = GeomAlgoAPI_CompoundBuilder::compound(aFacesList); GeomAlgoAPI_ShapeTools::combineShapes(aFacesCompound, GeomAPI_Shape::SHELL, aShells, aFreeFaces); - for(ListOfShape::const_iterator anIter = aFreeFaces.cbegin(); anIter != aFreeFaces.cend(); anIter++) { - aShells.push_back(*anIter); - } + aShells.insert(aShells.end(), aFreeFaces.begin(), aFreeFaces.end()); // Generating result for each shell and face. int aResultIndex = 0; @@ -154,7 +146,7 @@ void FeaturesPlugin_Revolution::execute() GeomAlgoAPI_Revolution aRevolAlgo(aBaseShape, anAxis, aToShape, aToAngle, aFromShape, aFromAngle); if(!aRevolAlgo.isDone()) { - static const std::string aPrismAlgoError = "Revolution algorithm failed"; + static const std::string aPrismAlgoError = "Error: Revolution algorithm failed."; setError(aPrismAlgoError); aResultIndex = 0; break; @@ -162,13 +154,13 @@ void FeaturesPlugin_Revolution::execute() // Check if shape is valid if(!aRevolAlgo.shape().get() || aRevolAlgo.shape()->isNull()) { - static const std::string aShapeError = "Resulting shape is Null"; + static const std::string aShapeError = "Error: Resulting shape is Null."; setError(aShapeError); aResultIndex = 0; break; } if(!aRevolAlgo.isValid()) { - std::string aPrismAlgoError = "Warning: resulting shape is not valid"; + std::string aPrismAlgoError = "Error: Resulting shape is not valid."; setError(aPrismAlgoError); aResultIndex = 0; break; @@ -191,34 +183,40 @@ void FeaturesPlugin_Revolution::loadNamingDS(GeomAlgoAPI_Revolution& theRevolAlg //load result theResultBody->storeGenerated(theBasis, theRevolAlgo.shape()); - std::shared_ptr aSubShapes = theRevolAlgo.mapOfShapes(); + std::shared_ptr aSubShapes = theRevolAlgo.mapOfSubShapes(); //Insert lateral face : Face from Edge const std::string aLatName = "LateralFace"; const int aLatTag = 1; - theResultBody->loadAndOrientGeneratedShapes(theRevolAlgo.makeShape().get(), theBasis, GeomAPI_Shape::EDGE, aLatTag, aLatName, *aSubShapes); + theResultBody->loadAndOrientGeneratedShapes(&theRevolAlgo, theBasis, GeomAPI_Shape::EDGE, aLatTag, aLatName, *aSubShapes); //Insert to faces + int aToFaceIndex = 1; const std::string aToName = "ToFace"; - const int aToTag = 2; + int aToTag = 2; const ListOfShape& aToFaces = theRevolAlgo.toFaces(); 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(aToFace, aToName, aToTag); + std::ostringstream aStr; + aStr << aToName << "_" << aToFaceIndex++; + theResultBody->generated(aToFace, aStr.str(), aToTag++); } //Insert from faces + int aFromFaceIndex = 1; const std::string aFromName = "FromFace"; - const int aFromTag = 3; + int aFromTag = aToTag > 10000 ? aToTag : 10000; const ListOfShape& aFromFaces = theRevolAlgo.fromFaces(); 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(aFromFace, aFromName, aFromTag); + std::ostringstream aStr; + aStr << aFromName << "_" << aFromFaceIndex++; + theResultBody->generated(aFromFace, aStr.str(), aFromTag++); } }