From 7eb73cc996c0757b14e931506fee26b06642ea28 Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Thu, 9 Mar 2017 10:30:14 +0100 Subject: [PATCH] Added multitranslation for part. --- .../FeaturesPlugin_MultiTranslation.cpp | 182 +++++++++++------- 1 file changed, 108 insertions(+), 74 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp index 5ef6bba71..7b131b9aa 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -113,46 +114,60 @@ void FeaturesPlugin_MultiTranslation::performOneDirection() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; + bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + + // Setting result. + if (isPart) { + ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); + std::shared_ptr aTrsf(new GeomAPI_Trsf()); + for (int i=0; isetTranslation(anAxis, i*aStep); + ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); + aResultPart->setTrsf(*aContext, aTrsf); + setResult(aResultPart, aResultIndex); + aResultIndex++; + } + } else { + ListOfShape aListOfShape; + std::list > aListOfTranslationAlgo; - ListOfShape aListOfShape; - std::list > aListOfTranslationAlgo; - - for (int i=0; i aTranslationAlgo( - new GeomAlgoAPI_Translation(aBaseShape, anAxis, i*aStep)); + for (int i=0; i aTranslationAlgo( + new GeomAlgoAPI_Translation(aBaseShape, anAxis, i*aStep)); - if (!aTranslationAlgo->check()) { - setError(aTranslationAlgo->getError()); - break; - } + if (!aTranslationAlgo->check()) { + setError(aTranslationAlgo->getError()); + break; + } - aTranslationAlgo->build(); + aTranslationAlgo->build(); - // Checking that the algorithm worked properly. - if (!aTranslationAlgo->isDone()) { - static const std::string aFeatureError = "Error : Multitranslation algorithm failed."; - setError(aFeatureError); - break; - } - if (aTranslationAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error : Resulting shape is null."; - setError(aShapeError); - break; - } - if (!aTranslationAlgo->isValid()) { - static const std::string aFeatureError = "Error : Resulting shape in not valid."; - setError(aFeatureError); - break; + // Checking that the algorithm worked properly. + if (!aTranslationAlgo->isDone()) { + static const std::string aFeatureError = "Error : Multitranslation algorithm failed."; + setError(aFeatureError); + break; + } + if (aTranslationAlgo->shape()->isNull()) { + static const std::string aShapeError = "Error : Resulting shape is null."; + setError(aShapeError); + break; + } + if (!aTranslationAlgo->isValid()) { + static const std::string aFeatureError = "Error : Resulting shape in not valid."; + setError(aFeatureError); + break; + } + aListOfShape.push_back(aTranslationAlgo->shape()); + aListOfTranslationAlgo.push_back(aTranslationAlgo); } - aListOfShape.push_back(aTranslationAlgo->shape()); - aListOfTranslationAlgo.push_back(aTranslationAlgo); - } - std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - aResultBody->storeModified(aBaseShape, aCompound); - loadNamingDS(aListOfTranslationAlgo, aResultBody, aBaseShape); + std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + aResultBody->storeModified(aBaseShape, aCompound); + loadNamingDS(aListOfTranslationAlgo, aResultBody, aBaseShape); - setResult(aResultBody, aResultIndex); + setResult(aResultBody, aResultIndex); + } aResultIndex++; } @@ -239,50 +254,69 @@ void FeaturesPlugin_MultiTranslation::performTwoDirection() for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++, aContext++) { std::shared_ptr aBaseShape = *anObjectsIt; - - ListOfShape aListOfShape; - std::list > aListOfTranslationAlgo; - - for (int j=0; j aTranslationAlgo( - new GeomAlgoAPI_Translation(aBaseShape, dx, dy, dz)); - - if (!aTranslationAlgo->check()) { - setError(aTranslationAlgo->getError()); - break; + bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + + // Setting result. + if (isPart) { + ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); + std::shared_ptr aTrsf(new GeomAPI_Trsf()); + for (int j=0; jsetTranslation(dx, dy, dz); + ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); + aResultPart->setTrsf(*aContext, aTrsf); + setResult(aResultPart, aResultIndex); + aResultIndex++; } - - aTranslationAlgo->build(); - - // Checking that the algorithm worked properly. - if (!aTranslationAlgo->isDone()) { - static const std::string aFeatureError = "Error : Multitranslation algorithm failed."; - setError(aFeatureError); - break; - } - if (aTranslationAlgo->shape()->isNull()) { - static const std::string aShapeError = "Error : Resulting shape is null."; - setError(aShapeError); - break; - } - if (!aTranslationAlgo->isValid()) { - static const std::string aFeatureError = "Error : Resulting shape in not valid."; - setError(aFeatureError); - break; + } + } else { + ListOfShape aListOfShape; + std::list > aListOfTranslationAlgo; + + for (int j=0; j aTranslationAlgo( + new GeomAlgoAPI_Translation(aBaseShape, dx, dy, dz)); + + if (!aTranslationAlgo->check()) { + setError(aTranslationAlgo->getError()); + break; + } + + aTranslationAlgo->build(); + + // Checking that the algorithm worked properly. + if (!aTranslationAlgo->isDone()) { + static const std::string aFeatureError = "Error : Multitranslation algorithm failed."; + setError(aFeatureError); + break; + } + if (aTranslationAlgo->shape()->isNull()) { + static const std::string aShapeError = "Error : Resulting shape is null."; + setError(aShapeError); + break; + } + if (!aTranslationAlgo->isValid()) { + static const std::string aFeatureError = "Error : Resulting shape in not valid."; + setError(aFeatureError); + break; + } + aListOfShape.push_back(aTranslationAlgo->shape()); + aListOfTranslationAlgo.push_back(aTranslationAlgo); } - aListOfShape.push_back(aTranslationAlgo->shape()); - aListOfTranslationAlgo.push_back(aTranslationAlgo); } + std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + aResultBody->storeModified(aBaseShape, aCompound); + loadNamingDS(aListOfTranslationAlgo, aResultBody, aBaseShape); + setResult(aResultBody, aResultIndex); } - std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape); - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - aResultBody->storeModified(aBaseShape, aCompound); - loadNamingDS(aListOfTranslationAlgo, aResultBody, aBaseShape); - setResult(aResultBody, aResultIndex); aResultIndex++; } -- 2.39.2