Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Symmetry.cpp
index b1b34237b6821cb90bea397a4422b7c215fb7c8a..f700c366d288f548d77aeec8dba515f33908d6da 100644 (file)
@@ -1,22 +1,51 @@
-// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
-
-// File:        FeaturesPlugin_Symmetry.cpp
-// Created:     30 Nov 2016
-// Author:      Clarisse Genrault (CEA)
+// Copyright (C) 2014-2023  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
+//
 
 #include <FeaturesPlugin_Symmetry.h>
 
+#include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_PointBuilder.h>
-
+#include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomAlgoAPI_Copy.h>
+#include <GeomAlgoAPI_MakeShapeList.h>
+#include <GeomAlgoAPI_Tools.h>
+#include <GeomAlgoAPI_Transform.h>
+
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_Ax2.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Face.h>
 #include <GeomAPI_Lin.h>
 #include <GeomAPI_Pln.h>
+#include <GeomAPI_ShapeIterator.h>
+#include <GeomAPI_Trsf.h>
 
+#include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Tools.h>
+
+#include <FeaturesPlugin_Tools.h>
+
+static const std::string SYMMETRY_VERSION_1("v9.5");
 
 //=================================================================================================
 FeaturesPlugin_Symmetry::FeaturesPlugin_Symmetry()
@@ -41,6 +70,14 @@ void FeaturesPlugin_Symmetry::initAttributes()
 
   data()->addAttribute(FeaturesPlugin_Symmetry::PLANE_OBJECT_ID(),
                        ModelAPI_AttributeSelection::typeId());
+
+  data()->addAttribute(FeaturesPlugin_Symmetry::KEEP_ORIGINAL_RESULT(),
+                       ModelAPI_AttributeBoolean::typeId());
+
+  if (!aSelection->isInitialized()) {
+    // new feature, not read from file
+    data()->setVersion(SYMMETRY_VERSION_1);
+  }
 }
 
 //=================================================================================================
@@ -49,46 +86,23 @@ void FeaturesPlugin_Symmetry::execute()
   AttributeStringPtr aMethodTypeAttr = string(FeaturesPlugin_Symmetry::CREATION_METHOD());
   std::string aMethodType = aMethodTypeAttr->value();
 
-  if (aMethodType == CREATION_METHOD_BY_POINT()) {
-    performSymmetryByPoint();
-  }
-
-  if (aMethodType == CREATION_METHOD_BY_AXIS()) {
-    performSymmetryByAxis();
-  }
+  GeomTrsfPtr aTrsf;
+  if (aMethodType == CREATION_METHOD_BY_POINT())
+    aTrsf = symmetryByPoint();
+  else if (aMethodType == CREATION_METHOD_BY_AXIS())
+    aTrsf = symmetryByAxis();
+  else if (aMethodType == CREATION_METHOD_BY_PLANE())
+    aTrsf = symmetryByPlane();
 
-  if (aMethodType == CREATION_METHOD_BY_PLANE()) {
-    performSymmetryByPlane();
-  }
+  performSymmetry(aTrsf);
 }
 
 //=================================================================================================
-void FeaturesPlugin_Symmetry::performSymmetryByPoint()
+GeomTrsfPtr FeaturesPlugin_Symmetry::symmetryByPoint()
 {
-  // Getting objects.
-  ListOfShape anObjects;
-  std::list<ResultPtr> aContextes;
-  AttributeSelectionListPtr anObjectsSelList =
-    selectionList(FeaturesPlugin_Symmetry::OBJECTS_LIST_ID());
-  if (anObjectsSelList->size() == 0) {
-    return;
-  }
-  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
-    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
-      anObjectsSelList->value(anObjectsIndex);
-    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
-    if(!anObject.get()) { // may be for not-activated parts
-      eraseResults();
-      return;
-    }
-    anObjects.push_back(anObject);
-    aContextes.push_back(anObjectAttr->context());
-  }
-
   //Getting point.
   std::shared_ptr<GeomAPI_Pnt> aPoint;
-  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
-    selection(FeaturesPlugin_Symmetry::POINT_OBJECT_ID());
+  AttributeSelectionPtr anObjRef = selection(FeaturesPlugin_Symmetry::POINT_OBJECT_ID());
   if (anObjRef.get() != NULL) {
     GeomShapePtr aShape1 = anObjRef->value();
     if (!aShape1.get()) {
@@ -99,261 +113,209 @@ void FeaturesPlugin_Symmetry::performSymmetryByPoint()
     }
   }
 
-  // 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) {
-      std::shared_ptr<GeomAPI_Trsf> aTrsf(new GeomAPI_Trsf());
-      aTrsf->setSymmetry(aPoint);
-      ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
-      ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
-      aResultPart->setTrsf(*aContext, aTrsf);
-      setResult(aResultPart, aResultIndex);
-    } else {
-      GeomAlgoAPI_Symmetry aSymmetryAlgo(aBaseShape, aPoint);
-
-      if (!aSymmetryAlgo.check()) {
-        setError(aSymmetryAlgo.getError());
-        return;
-      }
-
-      aSymmetryAlgo.build();
-
-      // Checking that the algorithm worked properly.
-      if(!aSymmetryAlgo.isDone()) {
-        static const std::string aFeatureError = "Error: Symmetry algorithm failed.";
-        setError(aFeatureError);
-        break;
-      }
-      if(aSymmetryAlgo.shape()->isNull()) {
-        static const std::string aShapeError = "Error: Resulting shape is Null.";
-        setError(aShapeError);
-        break;
-      }
-      if(!aSymmetryAlgo.isValid()) {
-        std::string aFeatureError = "Error: Resulting shape is not valid.";
-        setError(aFeatureError);
-        break;
-      }
-
-      ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      loadNamingDS(aSymmetryAlgo, aResultBody, aBaseShape);
-      setResult(aResultBody, aResultIndex);
+  GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+  aTrsf->setSymmetry(aPoint);
+  return aTrsf;
+}
+
+//=================================================================================================
+GeomTrsfPtr FeaturesPlugin_Symmetry::symmetryByAxis()
+{
+  //Getting axis.
+  static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+  AttributeSelectionPtr anObjRef = selection(AXIS_OBJECT_ID());
+  GeomShapePtr aShape = anObjRef->value();
+  if (!aShape.get()) {
+    if (anObjRef->context().get()) {
+      aShape = anObjRef->context()->shape();
     }
-    aResultIndex++;
+  }
+  if (!aShape.get()) {
+    setError(aSelectionError);
+    return GeomTrsfPtr();
   }
 
-  // Remove the rest results if there were produced in the previous pass.
-  removeResults(aResultIndex);
+  GeomEdgePtr anEdge;
+  if (aShape->isEdge())
+  {
+    anEdge = aShape->edge();
+  }
+  else if (aShape->isCompound())
+  {
+    GeomAPI_ShapeIterator anIt(aShape);
+    anEdge = anIt.current()->edge();
+  }
+
+  if (!anEdge.get())
+  {
+    setError(aSelectionError);
+    return GeomTrsfPtr();
+  }
+
+  std::shared_ptr<GeomAPI_Ax1> anAxis (new GeomAPI_Ax1(anEdge->line()->location(),
+                                                       anEdge->line()->direction()));
+  GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+  aTrsf->setSymmetry(anAxis);
+  return aTrsf;
 }
 
 //=================================================================================================
-void FeaturesPlugin_Symmetry::performSymmetryByAxis()
+GeomTrsfPtr FeaturesPlugin_Symmetry::symmetryByPlane()
 {
-  // Getting objects.
-  ListOfShape anObjects;
-  std::list<ResultPtr> aContextes;
-  AttributeSelectionListPtr anObjectsSelList =
-    selectionList(FeaturesPlugin_Symmetry::OBJECTS_LIST_ID());
-  if (anObjectsSelList->size() == 0) {
-    return;
-  }
-  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
-    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
-      anObjectsSelList->value(anObjectsIndex);
-    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
-    if(!anObject.get()) { // may be for not-activated parts
-      eraseResults();
-      return;
+  //Getting plane.
+  static const std::string aSelectionError = "Error: The plane shape selection is bad.";
+  AttributeSelectionPtr anObjRef = selection(PLANE_OBJECT_ID());
+  GeomShapePtr aShape = anObjRef->value();
+  if (!aShape.get()) {
+    if (anObjRef->context().get()) {
+      aShape = anObjRef->context()->shape();
     }
-    anObjects.push_back(anObject);
-    aContextes.push_back(anObjectAttr->context());
+  }
+  if (!aShape.get()) {
+    setError(aSelectionError);
+    return GeomTrsfPtr();
   }
 
-  //Getting axis.
-  std::shared_ptr<GeomAPI_Ax1> anAxis;
-  std::shared_ptr<GeomAPI_Edge> anEdge;
-  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
-    selection(FeaturesPlugin_Symmetry::AXIS_OBJECT_ID());
-  if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
-    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
-  } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
-             anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
-    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+  GeomFacePtr aFace;
+  if (aShape->isFace())
+  {
+    aFace = aShape->face();
   }
-  if(anEdge) {
-    anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
-                                                          anEdge->line()->direction()));
+  else if (aShape->isCompound())
+  {
+    GeomAPI_ShapeIterator anIt(aShape);
+    aFace = anIt.current()->face();
   }
 
-  // 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) {
-      std::shared_ptr<GeomAPI_Trsf> aTrsf(new GeomAPI_Trsf());
-      aTrsf->setSymmetry(anAxis);
-      ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
-      ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
-      aResultPart->setTrsf(*aContext, aTrsf);
-      setResult(aResultPart, aResultIndex);
-    } else {
-      GeomAlgoAPI_Symmetry aSymmetryAlgo(aBaseShape, anAxis);
-
-      if (!aSymmetryAlgo.check()) {
-        setError(aSymmetryAlgo.getError());
-        return;
-      }
-
-      aSymmetryAlgo.build();
-
-      // Checking that the algorithm worked properly.
-      if(!aSymmetryAlgo.isDone()) {
-        static const std::string aFeatureError = "Error: Symmetry algorithm failed.";
-        setError(aFeatureError);
-        break;
-      }
-      if(aSymmetryAlgo.shape()->isNull()) {
-        static const std::string aShapeError = "Error: Resulting shape is Null.";
-        setError(aShapeError);
-        break;
-      }
-      if(!aSymmetryAlgo.isValid()) {
-        std::string aFeatureError = "Error: Resulting shape is not valid.";
-        setError(aFeatureError);
-        break;
-      }
-
-      ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      loadNamingDS(aSymmetryAlgo, aResultBody, aBaseShape);
-      setResult(aResultBody, aResultIndex);
-    }
-    aResultIndex++;
+  if (!aFace.get())
+  {
+    setError(aSelectionError);
+    return GeomTrsfPtr();
   }
 
-  // Remove the rest results if there were produced in the previous pass.
-  removeResults(aResultIndex);
+  std::shared_ptr<GeomAPI_Ax2> aPlane(new GeomAPI_Ax2(aFace->getPlane()->location(),
+                                                      aFace->getPlane()->direction()));
+  GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+  aTrsf->setSymmetry(aPlane);
+  return aTrsf;
 }
 
 //=================================================================================================
-void FeaturesPlugin_Symmetry::performSymmetryByPlane()
+void FeaturesPlugin_Symmetry::buildResult(
+    const std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theAlgo,
+    const std::list<std::shared_ptr<GeomAPI_Shape> >& theOriginalShapes,
+    std::shared_ptr<GeomAPI_Shape> theTargetShape, int& theResultIndex,
+    const ResultPtr& theTextureSource)
 {
-  // Getting objects.
-  ListOfShape anObjects;
-  std::list<ResultPtr> aContextes;
-  AttributeSelectionListPtr anObjectsSelList =
-    selectionList(FeaturesPlugin_Symmetry::OBJECTS_LIST_ID());
-  if (anObjectsSelList->size() == 0) {
-    return;
-  }
-  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
-    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
-      anObjectsSelList->value(anObjectsIndex);
-    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
-    if(!anObject.get()) { // may be for not-activated parts
-      eraseResults();
-      return;
-    }
-    anObjects.push_back(anObject);
-    aContextes.push_back(anObjectAttr->context());
-  }
+  // Store and name the result.
+  ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex);
+  ModelAPI_Tools::loadModifiedShapes(aResultBody, theOriginalShapes, ListOfShape(),
+                                     theAlgo, theTargetShape, "Symmetried");
+  // Copy image data, if any
+  ModelAPI_Tools::copyImageAttribute(theTextureSource, aResultBody);
+  setResult(aResultBody, theResultIndex++);
+}
 
-  //Getting axis.
-  std::shared_ptr<GeomAPI_Ax2> aPlane;
-  std::shared_ptr<GeomAPI_Pln> aPln;
-  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
-    selection(FeaturesPlugin_Symmetry::PLANE_OBJECT_ID());
-  if(anObjRef && anObjRef->value() && anObjRef->value()->isFace()) {
-    aPln = std::shared_ptr<GeomAPI_Face>(new GeomAPI_Face(anObjRef->value()))->getPlane();
+//=================================================================================================
+void FeaturesPlugin_Symmetry::buildResult(ResultPartPtr theOriginal,
+                                          std::shared_ptr<GeomAPI_Trsf> theTrsf,
+                                          int& theResultIndex)
+{
+  if (boolean(KEEP_ORIGINAL_RESULT())->value()) {
+    std::shared_ptr<GeomAPI_Trsf> anIdentity(new GeomAPI_Trsf());
+    ResultPartPtr aCopy = document()->copyPart(theOriginal, data(), theResultIndex);
+    aCopy->setTrsf(theOriginal, anIdentity);
+    setResult(aCopy, theResultIndex++);
   }
-  else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
-             anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
-    aPln =
-      std::shared_ptr<GeomAPI_Face>(new GeomAPI_Face(anObjRef->context()->shape()))->getPlane();
+
+  ResultPartPtr aResultPart = document()->copyPart(theOriginal, data(), theResultIndex);
+  aResultPart->setTrsf(theOriginal, theTrsf);
+  setResult(aResultPart, theResultIndex++);
+}
+
+//=================================================================================================
+static bool performShapeSymmetry(std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theAlgoList,
+                                 GeomAPI_ShapeHierarchy& theHierarchy,
+                                 GeomShapePtr theBaseShape,
+                                 GeomTrsfPtr theTrsf,
+                                 bool isKeepOriginalResult,
+                                 const std::string& theFeatureKind,
+                                 std::string& theError)
+{
+  std::shared_ptr<GeomAlgoAPI_Transform> aSymmetryAlgo(
+      new GeomAlgoAPI_Transform(theBaseShape, theTrsf));
+
+  // Checking that the algorithm worked properly.
+  if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSymmetryAlgo, theFeatureKind, theError))
+    return false;
+
+  theAlgoList->appendAlgo(aSymmetryAlgo);
+
+  // Compose source shape and the result of symmetry.
+  GeomShapePtr aCompound;
+  if (isKeepOriginalResult) {
+    ListOfShape aShapes;
+    // add a copy of a base shape otherwise selection of this base shape is bad (2592)
+    std::shared_ptr<GeomAlgoAPI_Copy> aCopyAlgo(new GeomAlgoAPI_Copy(theBaseShape));
+    aShapes.push_back(aCopyAlgo->shape());
+    theAlgoList->appendAlgo(aCopyAlgo);
+
+    aShapes.push_back(aSymmetryAlgo->shape());
+    aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
   }
-  if(aPln) {
-    aPlane = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aPln->location(),
-                                                          aPln->direction()));
+  else
+    aCompound = aSymmetryAlgo->shape();
+
+  theHierarchy.markModified(theBaseShape, aCompound);
+  return true;
+}
+
+void FeaturesPlugin_Symmetry::performSymmetry(GeomTrsfPtr theTrsf)
+{
+  if (!theTrsf) {
+    setError("Invalid transformation.");
+    return;
   }
 
-  // Moving each object.
+  bool isKeepOriginal = boolean(KEEP_ORIGINAL_RESULT())->value();
+  bool isKeepSubShapes = data()->version() == SYMMETRY_VERSION_1;
+
+  // Getting objects.
+  GeomAPI_ShapeHierarchy anObjects;
+  std::list<ResultPtr> aParts;
+  ResultPtr aTextureSource;
+  AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID());
+  if (!FeaturesPlugin_Tools::shapesFromSelectionList(
+       anObjSelList, isKeepSubShapes, anObjects, aParts, aTextureSource))
+    return;
+
+  std::string anError;
   int aResultIndex = 0;
-  std::list<ResultPtr>::iterator aContext = aContextes.begin();
-  for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
-        anObjectsIt++, aContext++) {
+  // Symmetrying parts.
+  for (std::list<ResultPtr>::iterator aPRes = aParts.begin(); aPRes != aParts.end(); ++aPRes) {
+    ResultPartPtr anOriginal = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aPRes);
+    buildResult(anOriginal, theTrsf, 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;
-    bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
-
-    // Setting result.
-    if (isPart) {
-      std::shared_ptr<GeomAPI_Trsf> aTrsf(new GeomAPI_Trsf());
-      aTrsf->setSymmetry(aPlane);
-      ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
-      ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
-      aResultPart->setTrsf(*aContext, aTrsf);
-      setResult(aResultPart, aResultIndex);
-    } else {
-      GeomAlgoAPI_Symmetry aSymmetryAlgo(aBaseShape, aPlane);
-
-      if (!aSymmetryAlgo.check()) {
-        setError(aSymmetryAlgo.getError());
-        return;
-      }
-
-      aSymmetryAlgo.build();
-
-      // Checking that the algorithm worked properly.
-      if(!aSymmetryAlgo.isDone()) {
-        static const std::string aFeatureError = "Error: Symmetry algorithm failed.";
-        setError(aFeatureError);
-        break;
-      }
-      if(aSymmetryAlgo.shape()->isNull()) {
-        static const std::string aShapeError = "Error: Resulting shape is Null.";
-        setError(aShapeError);
-        break;
-      }
-      if(!aSymmetryAlgo.isValid()) {
-        std::string aFeatureError = "Error: Resulting shape is not valid.";
-        setError(aFeatureError);
-        break;
-      }
-
-      ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-      loadNamingDS(aSymmetryAlgo, aResultBody, aBaseShape);
-      setResult(aResultBody, aResultIndex);
+    if (!performShapeSymmetry(aMakeShapeList, anObjects, aBaseShape, theTrsf,
+                              isKeepOriginal, getKind(), anError)) {
+      setError(anError);
+      break;
     }
-    aResultIndex++;
   }
 
+  // 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)
+    buildResult(aMakeShapeList, anOriginalShapes, *anIt, aResultIndex, aTextureSource);
+
   // Remove the rest results if there were produced in the previous pass.
   removeResults(aResultIndex);
 }
-
-//=================================================================================================
-void FeaturesPlugin_Symmetry::loadNamingDS(GeomAlgoAPI_Symmetry& theSymmetryAlgo,
-                                           std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                                           std::shared_ptr<GeomAPI_Shape> theBaseShape)
-{
-  // Store and name the result.
-  theResultBody->storeModified(theBaseShape, theSymmetryAlgo.shape());
-
-  // Name the faces
-  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theSymmetryAlgo.mapOfSubShapes();
-  int aReflectedTag = 1;
-  std::string aReflectedName = "Symmetried";
-  theResultBody->loadAndOrientModifiedShapes(&theSymmetryAlgo,
-                                              theBaseShape, GeomAPI_Shape::FACE,
-                                              aReflectedTag, aReflectedName, *aSubShapes.get());
-}