X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FFeaturesPlugin%2FFeaturesPlugin_MultiRotation.cpp;h=83f296653099c249456c86d8365451516819e112;hb=207f4e84daf9c78020f5f250a33a63c71f0b0556;hp=dba9dedf2107ef6ca87a947bf1e132b5b5cf3cad;hpb=c5f8e9b29a4ec001befdc58ad894ad9938c840a0;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp index dba9dedf2..83f296653 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiRotation.cpp @@ -1,4 +1,21 @@ -// Copyright (C) 2014-201x CEA/DEN, EDF R&D +// Copyright (C) 2017-2022 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 +// // File: FeaturesPlugin_MultiRotation.cpp // Created: 30 Jan 2017 @@ -8,7 +25,7 @@ #include #include -#include +#include #include #include #include @@ -27,10 +44,13 @@ #include #include #include +#include #include #include +static const std::string MULTIROTATION_VERSION_1("v9.5"); + //================================================================================================= FeaturesPlugin_MultiRotation::FeaturesPlugin_MultiRotation() { @@ -61,6 +81,11 @@ void FeaturesPlugin_MultiRotation::initAttributes() data()->addAttribute(FeaturesPlugin_MultiRotation::NB_COPIES_RADIAL_ID(), ModelAPI_AttributeInteger::typeId()); #endif + + if (!aSelection->isInitialized()) { + // new feature, not read from file + data()->setVersion(MULTIROTATION_VERSION_1); + } } //================================================================================================= @@ -79,139 +104,131 @@ void FeaturesPlugin_MultiRotation::execute() } //================================================================================================= -void FeaturesPlugin_MultiRotation::performRotation1D() +bool FeaturesPlugin_MultiRotation::paramsOfRotation(std::shared_ptr& theAxis, + double& theAngle, + int& theQuantity) { - // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_MultiRotation::OBJECTS_LIST_ID()); - if (anObjectsSelList->size() == 0) { - setError("Error: empty selection list"); - return; - } - for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { - std::shared_ptr anObjectAttr = - anObjectsSelList->value(anObjectsIndex); - std::shared_ptr anObject = anObjectAttr->value(); - if(!anObject.get()) { // may be for not-activated parts - return; - } - anObjects.push_back(anObject); - aContextes.push_back(anObjectAttr->context()); - } - //Getting axis. static const std::string aSelectionError = "Error: The axis shape selection is bad."; AttributeSelectionPtr anObjRef = selection(AXIS_ANGULAR_ID()); GeomShapePtr aShape = anObjRef->value(); - if (!aShape.get()) { - if (anObjRef->context().get()) { - aShape = anObjRef->context()->shape(); - } - } + if (!aShape.get() && anObjRef->context().get()) + aShape = anObjRef->context()->shape(); if (!aShape.get()) { setError(aSelectionError); - return; + return false; } GeomEdgePtr anEdge; if (aShape->isEdge()) - { anEdge = aShape->edge(); - } - else if (aShape->isCompound()) - { + else if (aShape->isCompound()) { GeomAPI_ShapeIterator anIt(aShape); anEdge = anIt.current()->edge(); } - if (!anEdge.get()) - { + if (!anEdge.get()) { setError(aSelectionError); - return; + return false; } - std::shared_ptr anAxis(new GeomAPI_Ax1(anEdge->line()->location(), - anEdge->line()->direction())); + theAxis.reset(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction())); // Getting number of copies. - int nbCopies = - integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID())->value(); - - if (nbCopies <=0) { + theQuantity = integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID())->value(); + if (theQuantity <= 0) { std::string aFeatureError = "Multirotation builder "; - aFeatureError+=":: the number of copies for the angular direction is null or negative."; + aFeatureError += ":: the number of copies for the angular direction is null or negative."; setError(aFeatureError); - return; + return false; } // Getting angle - double anAngle; std::string useAngularStep = string(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID())->value(); - if (!useAngularStep.empty()) { - anAngle = real(FeaturesPlugin_MultiRotation::STEP_ANGULAR_ID())->value(); - } else { - anAngle = 360./nbCopies; + if (!useAngularStep.empty()) + theAngle = real(FeaturesPlugin_MultiRotation::STEP_ANGULAR_ID())->value(); + else + theAngle = 360. / theQuantity; + return true; +} + +//================================================================================================= +void FeaturesPlugin_MultiRotation::performRotation1D() +{ + bool isKeepSubShapes = data()->version() == MULTIROTATION_VERSION_1; + + // Getting objects. + AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECTS_LIST_ID()); + if (anObjectsSelList->size() == 0) { + setError("Error: empty selection list"); + return; } - // Moving each object. - int aResultIndex = 0; - std::list::iterator aContext = aContextes.begin(); - for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); - anObjectsIt++, aContext++) { - std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); + GeomAPI_ShapeHierarchy anObjects; + std::list aParts; + ResultPtr aTextureSource; + if (!FeaturesPlugin_Tools::shapesFromSelectionList + (anObjectsSelList, isKeepSubShapes, anObjects, aParts, aTextureSource)) + return; - // Setting result. - if (isPart) { - ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); - std::shared_ptr aTrsf(new GeomAPI_Trsf()); - for (int i=0; isetRotation(anAxis, i*anAngle); - ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); - aResultPart->setTrsf(*aContext, aTrsf); - setResult(aResultPart, aResultIndex); - aResultIndex++; - } - } else { - std::string anError; - ListOfShape aListOfShape; - std::shared_ptr - aListOfRotationAlgo(new GeomAlgoAPI_MakeShapeList); + // Parameters of rotation. + std::shared_ptr anAxis; + double anAngle = 0.0; + int nbCopies = 0; + if (!paramsOfRotation(anAxis, anAngle, nbCopies)) + return; - for (int i=0; i aRotationnAlgo( - new GeomAlgoAPI_Rotation(aBaseShape, anAxis, i*anAngle)); - if (!aRotationnAlgo->check()) { - setError(aRotationnAlgo->getError()); - break; - } + std::string anError; + int aResultIndex = 0; + // Moving each part. + for (std::list::iterator aPRes = aParts.begin(); aPRes != aParts.end(); ++aPRes) { + ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aPRes); + std::shared_ptr aTrsf(new GeomAPI_Trsf()); + for (int i = 0; i < nbCopies; ++i) { + aTrsf->setRotation(anAxis, i * anAngle); + ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); + aResultPart->setTrsf(anOrigin, aTrsf); + setResult(aResultPart, aResultIndex++); + } + } - aRotationnAlgo->build(); + // Collect transformations for each object in a part. + std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeSet); + for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin(); + anObjectsIt != anObjects.end(); anObjectsIt++) { + std::shared_ptr aBaseShape = *anObjectsIt; + ListOfShape aListOfShape; - // Checking that the algorithm worked properly. - if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationnAlgo, getKind(), anError)) { - setError(anError); - break; - } - aListOfShape.push_back(aRotationnAlgo->shape()); - aListOfRotationAlgo->appendAlgo(aRotationnAlgo); + for (int i = 0; i < nbCopies; i++) { + std::shared_ptr aRotationnAlgo( + new GeomAlgoAPI_Rotation(aBaseShape, anAxis, i * anAngle)); + + // Checking that the algorithm worked properly. + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationnAlgo, getKind(), anError)) { + setError(anError); + break; } - std::shared_ptr aCompound = - GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + aListOfShape.push_back(aRotationnAlgo->shape()); + aMakeShapeList->appendAlgo(aRotationnAlgo); + } - ListOfShape aBaseShapes; - aBaseShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, aBaseShapes, ListOfShape(), - aListOfRotationAlgo, aCompound, "Rotated"); + GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); + anObjects.markModified(aBaseShape, aCompound); + } - setResult(aResultBody, aResultIndex); - } - aResultIndex++; + // Build results of the operation. + const ListOfShape& anOriginalShapes = anObjects.objects(); + ListOfShape aTopLevel; + anObjects.topLevelObjects(aTopLevel); + for (ListOfShape::iterator anIt = aTopLevel.begin(); anIt != aTopLevel.end(); ++anIt) { + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + ModelAPI_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(), + aMakeShapeList, *anIt, "Rotated"); + // Copy image data, if any + ModelAPI_Tools::copyImageAttribute(aTextureSource, aResultBody); + setResult(aResultBody, aResultIndex++); } // Remove the rest results if there were produced in the previous pass. @@ -241,32 +258,13 @@ void FeaturesPlugin_MultiRotation::performRotation2D() aContextes.push_back(anObjectAttr->context()); } - //Getting axis. + // Parameters of rotation. std::shared_ptr anAxis; - std::shared_ptr anEdge; - std::shared_ptr anObjRef = - selection(FeaturesPlugin_MultiRotation::AXIS_ANGULAR_ID()); - if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); - } else if (anObjRef && !anObjRef->value() && anObjRef->context() && - anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->context()->shape())); - } - if(anEdge) { - anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), - anEdge->line()->direction())); - } - - // Getting number of copies int he angular direction. - int nbAngular = - integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID())->value(); - - if (nbAngular <=0) { - std::string aFeatureError = "Multirotation builder "; - aFeatureError+=":: the number of copies for the angular direction is null or negative."; - setError(aFeatureError); + double anAngle = 0.0; + int nbCopies = 0; + if (!paramsOfRotation(anAxis, anAngle, nbCopies)) return; - } + // Getting number of copies int he radial direction. int nbRadial = @@ -279,16 +277,6 @@ void FeaturesPlugin_MultiRotation::performRotation2D() return; } - // Getting angle - double anAngle; - std::string useAngularStep = - string(FeaturesPlugin_MultiRotation::USE_ANGULAR_STEP_ID())->value(); - if (!useAngularStep.empty()) { - anAngle = real(FeaturesPlugin_MultiRotation::STEP_ANGULAR_ID())->value(); - } else { - anAngle = 360./nbAngular; - } - // Getting step double aStep = real(FeaturesPlugin_MultiRotation::STEP_RADIAL_ID())->value(); @@ -395,8 +383,8 @@ void FeaturesPlugin_MultiRotation::performRotation2D() loadNamingDS2(aListOfTranslationAlgo, aResultBody, aBaseShape); loadNamingDS3(aListOfRotationAlgo, aResultBody, aBaseShape, nbRadial); setResult(aResultBody, aResultIndex); + aResultIndex++; } - aResultIndex++; } // Remove the rest results if there were produced in the previous pass. @@ -447,22 +435,3 @@ void FeaturesPlugin_MultiRotation::loadNamingDS3( } } #endif - -//================================================================================================= -void FeaturesPlugin_MultiRotation::loadNamingDS( - std::list > theListOfRotationAlgo, - std::shared_ptr theResultBody, - std::shared_ptr theBaseShape) -{ - for (std::list >::const_iterator anIt = - theListOfRotationAlgo.begin(); anIt != theListOfRotationAlgo.cend(); ++anIt) { - // naming of faces - theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::FACE, "Rotated_Face"); - - // naming of edges - theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::EDGE, "Rotated_Edge"); - - // naming of vertex - theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::VERTEX, "Rotated_Vertex"); - } -}