X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Scale.cpp;h=4fbc071d90c499e19ad11ca0fbfaaa3ff04bb70c;hb=05e2e4a31fa248d71445c40e35eeafa44f5d3b1b;hp=bdb4cdd52fde517cc999053ac555b78368b7d3f9;hpb=6e421e939851e0de46554ae45a3ca0e1f67cd91d;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp b/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp index bdb4cdd52..4fbc071d9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Scale.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-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 @@ -18,8 +18,13 @@ // #include +#include + +#include +#include #include +#include #include #include @@ -27,8 +32,10 @@ #include #include #include +#include + +static const std::string SCALE_VERSION_1("v9.5"); -#include //================================================================================================= FeaturesPlugin_Scale::FeaturesPlugin_Scale() @@ -57,6 +64,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); + } } //================================================================================================= @@ -68,8 +80,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(); } } @@ -77,24 +88,16 @@ 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; + ResultPtr aTextureSource; + AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID()); + if (!FeaturesPlugin_Tools::shapesFromSelectionList( + anObjSelList, isKeepSubShapes, anObjects, aParts, aTextureSource)) 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; @@ -113,22 +116,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)) { @@ -136,18 +131,22 @@ void FeaturesPlugin_Scale::performScaleByFactor() break; } - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + anObjects.markModified(aBaseShape, aScaleAlgo->shape()); + aMakeShapeList->appendAlgo(aScaleAlgo); + } - ListOfShape aShapes; - aShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, - aShapes, - ListOfShape(), - aScaleAlgo, - aScaleAlgo->shape(), - "Scaled"); - setResult(aResultBody, aResultIndex); - aResultIndex++; + // 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); + ModelAPI_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(), + aMakeShapeList, *anIt, "Scaled"); + // 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. @@ -157,24 +156,16 @@ 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; + ResultPtr aTextureSource; + AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID()); + if (!FeaturesPlugin_Tools::shapesFromSelectionList( + anObjSelList, isKeepSubShapes, anObjects, aParts, aTextureSource)) 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; @@ -195,12 +186,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, @@ -208,31 +198,28 @@ 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; } - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + anObjects.markModified(aBaseShape, aScaleAlgo->shape()); + aMakeShapeList->appendAlgo(aScaleAlgo); + } - ListOfShape aShapes; - aShapes.push_back(aBaseShape); - FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, - aShapes, - ListOfShape(), - aScaleAlgo, - aScaleAlgo->shape(), - "Scaled"); - setResult(aResultBody, aResultIndex); - aResultIndex++; + // 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); + ModelAPI_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(), + aMakeShapeList, *anIt, "Scaled"); + // 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.