- // Name the faces
- std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theSymmetryAlgo.mapOfSubShapes();
- std::string aReflectedName = "Symmetried";
- FeaturesPlugin_Tools::storeModifiedShapes(theSymmetryAlgo, theResultBody,
- theBaseShape, 1, 2, 3, aReflectedName,
- *aSubShapes.get());
+ if (!theTrsf) {
+ setError("Invalid transformation.");
+ return;
+ }
+
+ 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;
+ // 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;
+ if (!performShapeSymmetry(aMakeShapeList, anObjects, aBaseShape, theTrsf,
+ isKeepOriginal, getKind(), anError)) {
+ setError(anError);
+ break;
+ }
+ }
+
+ // 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);