- // Coord aFirstAxis
- double x1 = aFirstAxis->dir()->x();
- double y1 = aFirstAxis->dir()->y();
- double z1 = aFirstAxis->dir()->z();
- double norm1 = sqrt(x1*x1 + y1*y1 + z1*z1);
-
- // Coord aSecondAxis
- double x2 = aSecondAxis->dir()->x();
- double y2 = aSecondAxis->dir()->y();
- double z2 = aSecondAxis->dir()->z();
- double norm2 = sqrt(x2*x2 + y2*y2 + z2*z2);
-
- // Moving each object.
- int aResultIndex = 0;
- std::list<ResultPtr>::iterator aContext = aContextes.begin();
- for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
- anObjectsIt++, aContext++) {
- std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
- bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
-
- // Setting result.
- if (isPart) {
- ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
- std::shared_ptr<GeomAPI_Trsf> aTrsf(new GeomAPI_Trsf());
- for (int j=0; j<aSecondNbCopies; j++) {
- for (int i=0; i<aFirstNbCopies; i++) {
- double dx = i*aFirstStep*x1/norm1+j*aSecondStep*x2/norm2;
- double dy = i*aFirstStep*y1/norm1+j*aSecondStep*y2/norm2;
- double dz = i*aFirstStep*z1/norm1+j*aSecondStep*z2/norm2;
- aTrsf->setTranslation(dx, dy, dz);
- ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
- aResultPart->setTrsf(*aContext, aTrsf);
- setResult(aResultPart, aResultIndex);
- aResultIndex++;
- }
- }
- } else {
- ListOfShape aListOfShape;
- std::list<std::shared_ptr<GeomAlgoAPI_Translation> > aListOfTranslationAlgo;
-
- for (int j=0; j<aSecondNbCopies; j++) {
- for (int i=0; i<aFirstNbCopies; i++) {
- double dx = i*aFirstStep*x1/norm1+j*aSecondStep*x2/norm2;
- double dy = i*aFirstStep*y1/norm1+j*aSecondStep*y2/norm2;
- double dz = i*aFirstStep*z1/norm1+j*aSecondStep*z2/norm2;
- std::shared_ptr<GeomAlgoAPI_Translation> 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);
- }
- }
- std::shared_ptr<GeomAPI_Shape> aCompound =
- GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
- ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
- aResultBody->storeModified(aBaseShape, aCompound);
- loadNamingDS(aListOfTranslationAlgo, aResultBody, aBaseShape);
- 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);
+ FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
+ aMakeShapeList, *anIt, "Translated");
+ aResultBody->setTextureFile(theTextureFile);
+ setResult(aResultBody, aResultIndex++);