X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Translation.cpp;h=19ec3564ae804999dd42963d2851767990d137e9;hb=fbb1e5c91c5d6ed1862a7621baca9db73433689e;hp=4e7dcef66a9b08d3b02e39bc27c658b8bd79e7ef;hpb=76124b76e23a10697d5174719d4c64d808e8d0f7;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp index 4e7dcef66..19ec3564a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp @@ -1,10 +1,22 @@ -// Copyright (C) 2014-2016 CEA/DEN, EDF R&D - -// File: FeaturesPlugin_Translation.cpp -// Created: 8 June 2015 -// Author: Dmitry Bobylev +// Copyright (C) 2014-2017 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 // -// Modified by Clarisse Genrault (CEA) : 17 Nov 2016 #include @@ -18,6 +30,7 @@ #include #include +#include #include @@ -123,7 +136,7 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -134,34 +147,39 @@ void FeaturesPlugin_Translation::performTranslationByAxisAndDistance() aResultPart->setTrsf(*aContext, aTrsf); setResult(aResultPart, aResultIndex); } else { - GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, anAxis, aDistance); + std::shared_ptr aTranslationAlgo( + new GeomAlgoAPI_Translation(aBaseShape, anAxis, aDistance)); - if (!aTranslationAlgo.check()) { - setError(aTranslationAlgo.getError()); + if (!aTranslationAlgo->check()) { + setError(aTranslationAlgo->getError()); return; } - aTranslationAlgo.build(); + aTranslationAlgo->build(); // Checking that the algorithm worked properly. - if(!aTranslationAlgo.isDone()) { + if(!aTranslationAlgo->isDone()) { static const std::string aFeatureError = "Error: Translation algorithm failed."; setError(aFeatureError); break; } - if(aTranslationAlgo.shape()->isNull()) { + if(aTranslationAlgo->shape()->isNull()) { static const std::string aShapeError = "Error: Resulting shape is Null."; setError(aShapeError); break; } - if(!aTranslationAlgo.isValid()) { + if(!aTranslationAlgo->isValid()) { std::string aFeatureError = "Error: Resulting shape is not valid."; setError(aFeatureError); break; } ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - loadNamingDS(aTranslationAlgo, aResultBody, aBaseShape); + aResultBody->storeModified(aBaseShape, aTranslationAlgo->shape()); + FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, + aBaseShape, + aTranslationAlgo, + "Translated"); setResult(aResultBody, aResultIndex); } aResultIndex++; @@ -205,7 +223,7 @@ void FeaturesPlugin_Translation::performTranslationByDimensions() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -216,34 +234,39 @@ void FeaturesPlugin_Translation::performTranslationByDimensions() aResultPart->setTrsf(*aContext, aTrsf); setResult(aResultPart, aResultIndex); } else { - GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, aDX, aDY, aDZ); + std::shared_ptr aTranslationAlgo( + new GeomAlgoAPI_Translation(aBaseShape, aDX, aDY, aDZ)); - if (!aTranslationAlgo.check()) { - setError(aTranslationAlgo.getError()); + if (!aTranslationAlgo->check()) { + setError(aTranslationAlgo->getError()); return; } - aTranslationAlgo.build(); + aTranslationAlgo->build(); // Checking that the algorithm worked properly. - if(!aTranslationAlgo.isDone()) { + if(!aTranslationAlgo->isDone()) { static const std::string aFeatureError = "Error: Translation algorithm failed."; setError(aFeatureError); break; } - if(aTranslationAlgo.shape()->isNull()) { + if(aTranslationAlgo->shape()->isNull()) { static const std::string aShapeError = "Error: Resulting shape is Null."; setError(aShapeError); break; } - if(!aTranslationAlgo.isValid()) { + if(!aTranslationAlgo->isValid()) { std::string aFeatureError = "Error: Resulting shape is not valid."; setError(aFeatureError); break; } ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - loadNamingDS(aTranslationAlgo, aResultBody, aBaseShape); + aResultBody->storeModified(aBaseShape, aTranslationAlgo->shape()); + FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, + aBaseShape, + aTranslationAlgo, + "Translated"); setResult(aResultBody, aResultIndex); } aResultIndex++; @@ -300,7 +323,7 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + bool isPart = aContext->get() && (*aContext)->groupName() == ModelAPI_ResultPart::group(); // Setting result. if (isPart) { @@ -311,34 +334,39 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints() aResultPart->setTrsf(*aContext, aTrsf); setResult(aResultPart, aResultIndex); } else { - GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, aFirstPoint, aSecondPoint); + std::shared_ptr aTranslationAlgo( + new GeomAlgoAPI_Translation(aBaseShape, aFirstPoint, aSecondPoint)); - if (!aTranslationAlgo.check()) { - setError(aTranslationAlgo.getError()); + if (!aTranslationAlgo->check()) { + setError(aTranslationAlgo->getError()); return; } - aTranslationAlgo.build(); + aTranslationAlgo->build(); // Checking that the algorithm worked properly. - if(!aTranslationAlgo.isDone()) { + if(!aTranslationAlgo->isDone()) { static const std::string aFeatureError = "Error: Translation algorithm failed."; setError(aFeatureError); break; } - if(aTranslationAlgo.shape()->isNull()) { + if(aTranslationAlgo->shape()->isNull()) { static const std::string aShapeError = "Error: Resulting shape is Null."; setError(aShapeError); break; } - if(!aTranslationAlgo.isValid()) { + if(!aTranslationAlgo->isValid()) { std::string aFeatureError = "Error: Resulting shape is not valid."; setError(aFeatureError); break; } ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - loadNamingDS(aTranslationAlgo, aResultBody, aBaseShape); + aResultBody->storeModified(aBaseShape, aTranslationAlgo->shape()); + FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, + aBaseShape, + aTranslationAlgo, + "Translated"); setResult(aResultBody, aResultIndex); } aResultIndex++; @@ -347,20 +375,3 @@ void FeaturesPlugin_Translation::performTranslationByTwoPoints() // Remove the rest results if there were produced in the previous pass. removeResults(aResultIndex); } - -//================================================================================================= -void FeaturesPlugin_Translation::loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo, - std::shared_ptr theResultBody, - std::shared_ptr theBaseShape) -{ - // Store result. - theResultBody->storeModified(theBaseShape, theTranslationAlgo.shape()); - - int aTranslatedTag = 1; - std::string aTranslatedName = "Translated"; - std::shared_ptr aSubShapes = theTranslationAlgo.mapOfSubShapes(); - - FeaturesPlugin_Tools::storeModifiedShapes(theTranslationAlgo, theResultBody, - theBaseShape, aTranslatedTag, aTranslatedName, - *aSubShapes.get()); -}