+
+ bool isKeepSubShapes = data()->version() == ROTATION_VERSION_1;
+
+ // Getting objects.
+ GeomAPI_ShapeHierarchy anObjects;
+ std::list<ResultPtr> aParts;
+ AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID());
+ if (!FeaturesPlugin_Tools::shapesFromSelectionList(
+ anObjSelList, isKeepSubShapes, anObjects, aParts))
+ return;
+
+ std::string anError;
+ int aResultIndex = 0;
+ // Rotating each part.
+ for (std::list<ResultPtr>::iterator aPRes = aParts.begin(); aPRes != aParts.end(); ++aPRes) {
+ ResultPartPtr anOriginal = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aPRes);
+ ResultPartPtr aResultPart = document()->copyPart(anOriginal, data(), aResultIndex);
+ aResultPart->setTrsf(anOriginal, theTrsf);
+ setResult(aResultPart, aResultIndex++);
+ }
+
+ // Collect transformations for each object in a part.
+ std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList);
+ for(GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin();
+ anObjectsIt != anObjects.end(); ++anObjectsIt) {
+ std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
+ std::shared_ptr<GeomAlgoAPI_Transform> aRotationAlgo(
+ new GeomAlgoAPI_Transform(aBaseShape, theTrsf));
+
+ // Checking that the algorithm worked properly.
+ if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationAlgo, getKind(), anError)) {
+ setError(anError);
+ break;
+ }
+
+ anObjects.markModified(aBaseShape, aRotationAlgo->shape());
+ aMakeShapeList->appendAlgo(aRotationAlgo);
+ }
+
+ // Build results of the rotation.
+ 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, "Rotated");
+ setResult(aResultBody, aResultIndex++);
+ }
+
+ // Remove the rest results if there were produced in the previous pass.
+ removeResults(aResultIndex);