X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Scale.cpp;h=91dabbe379d7e361bb82ecc04db7bbdd5089d4b7;hb=50a8df0c6a66da8067b16155e5ae39f8f26a7ebc;hp=a2c6105c8bce9258524498c03f1714a582f61f9f;hpb=d4b0a5cb916f4eccf4a0bce02e43a54c7a67cb93;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp b/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp index a2c6105c8..91dabbe37 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 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 @@ -12,15 +12,19 @@ // // 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include +#include + +#include +#include #include +#include #include #include @@ -29,7 +33,8 @@ #include #include -#include +static const std::string SCALE_VERSION_1("v9.5"); + //================================================================================================= FeaturesPlugin_Scale::FeaturesPlugin_Scale() @@ -58,6 +63,11 @@ void FeaturesPlugin_Scale::initAttributes() ModelAPI_AttributeDouble::typeId()); data()->addAttribute(FeaturesPlugin_Scale::SCALE_FACTOR_Z_ID(), ModelAPI_AttributeDouble::typeId()); + + if (!aSelection->isInitialized()) { + // new feature, not read from file + data()->setVersion(SCALE_VERSION_1); + } } //================================================================================================= @@ -69,8 +79,7 @@ void FeaturesPlugin_Scale::execute() if (aMethodType == FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR()) { performScaleByFactor(); } - - if (aMethodType == FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS()) { + else if (aMethodType == FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS()) { performScaleByDimensions(); } } @@ -78,24 +87,15 @@ void FeaturesPlugin_Scale::execute() //================================================================================================= void FeaturesPlugin_Scale::performScaleByFactor() { + bool isKeepSubShapes = data()->version() == SCALE_VERSION_1; + // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_Scale::OBJECTS_LIST_ID()); - if (anObjectsSelList->size() == 0) { + GeomAPI_ShapeHierarchy anObjects; + std::list aParts; + AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID()); + if (!FeaturesPlugin_Tools::shapesFromSelectionList( + anObjSelList, isKeepSubShapes, anObjects, aParts)) 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 the center point std::shared_ptr aCenterPoint; @@ -114,22 +114,14 @@ void FeaturesPlugin_Scale::performScaleByFactor() // Getting scale factor double aScaleFactor = real(FeaturesPlugin_Scale::SCALE_FACTOR_ID())->value(); - // Moving each object. + // Collect transformation for each object std::string anError; - int aResultIndex = 0; - std::list::iterator aContext = aContextes.begin(); - for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); - anObjectsIt++, aContext++) { + std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList); + for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin(); + anObjectsIt != anObjects.end(); ++anObjectsIt) { std::shared_ptr aBaseShape = *anObjectsIt; std::shared_ptr aScaleAlgo( - new GeomAlgoAPI_Scale(aBaseShape, aCenterPoint, aScaleFactor)); - - if (!aScaleAlgo->check()) { - setError(aScaleAlgo->getError()); - return; - } - - aScaleAlgo->build(); + new GeomAlgoAPI_Scale(aBaseShape, aCenterPoint, aScaleFactor)); // Checking that the algorithm worked properly. if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aScaleAlgo, getKind(), anError)) { @@ -137,11 +129,20 @@ void FeaturesPlugin_Scale::performScaleByFactor() break; } + anObjects.markModified(aBaseShape, aScaleAlgo->shape()); + aMakeShapeList->appendAlgo(aScaleAlgo); + } + + // Build results of the scaling + int aResultIndex = 0; + 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); - aResultBody->storeModified(aBaseShape, aScaleAlgo->shape()); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, aBaseShape, aScaleAlgo, "Scaled"); - setResult(aResultBody, aResultIndex); - aResultIndex++; + FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(), + aMakeShapeList, *anIt, "Scaled"); + setResult(aResultBody, aResultIndex++); } // Remove the rest results if there were produced in the previous pass. @@ -151,24 +152,15 @@ void FeaturesPlugin_Scale::performScaleByFactor() //================================================================================================= void FeaturesPlugin_Scale::performScaleByDimensions() { + bool isKeepSubShapes = data()->version() == SCALE_VERSION_1; + // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_Scale::OBJECTS_LIST_ID()); - if (anObjectsSelList->size() == 0) { + GeomAPI_ShapeHierarchy anObjects; + std::list aParts; + AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID()); + if (!FeaturesPlugin_Tools::shapesFromSelectionList( + anObjSelList, isKeepSubShapes, anObjects, aParts)) 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 the center point std::shared_ptr aCenterPoint; @@ -189,12 +181,11 @@ void FeaturesPlugin_Scale::performScaleByDimensions() double aScaleFactorY = real(FeaturesPlugin_Scale::SCALE_FACTOR_Y_ID())->value(); double aScaleFactorZ = real(FeaturesPlugin_Scale::SCALE_FACTOR_Z_ID())->value(); - // Moving each object. + // Collect transformation for each object std::string anError; - int aResultIndex = 0; - std::list::iterator aContext = aContextes.begin(); - for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); - anObjectsIt++, aContext++) { + std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList); + for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin(); + anObjectsIt != anObjects.end(); ++anObjectsIt) { std::shared_ptr aBaseShape = *anObjectsIt; std::shared_ptr aScaleAlgo(new GeomAlgoAPI_Scale(aBaseShape, aCenterPoint, @@ -202,24 +193,26 @@ void FeaturesPlugin_Scale::performScaleByDimensions() aScaleFactorY, aScaleFactorZ)); - if (!aScaleAlgo->check()) { - setError(aScaleAlgo->getError()); - return; - } - - aScaleAlgo->build(); - // Checking that the algorithm worked properly. if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aScaleAlgo, getKind(), anError)) { setError(anError); break; } + anObjects.markModified(aBaseShape, aScaleAlgo->shape()); + aMakeShapeList->appendAlgo(aScaleAlgo); + } + + // Build results of the scaling + int aResultIndex = 0; + 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); - aResultBody->storeModified(aBaseShape, aScaleAlgo->shape()); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, aBaseShape, aScaleAlgo, "Scaled"); - setResult(aResultBody, aResultIndex); - aResultIndex++; + FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(), + aMakeShapeList, *anIt, "Scaled"); + setResult(aResultBody, aResultIndex++); } // Remove the rest results if there were produced in the previous pass.