Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_MultiRotation.cpp
index 5f8870f5952bb4799b2cf337555b26e35b7a766c..2a7bec49c74f7f1398f8d790dd2e54f44928f7a1 100644 (file)
@@ -15,6 +15,7 @@
 #include <GeomAPI_Ax1.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
+#include <GeomAPI_ShapeIterator.h>
 #include <GeomAPI_Trsf.h>
 
 #include <ModelAPI_AttributeDouble.h>
@@ -85,7 +86,6 @@ void FeaturesPlugin_MultiRotation::performRotation1D()
       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);
@@ -93,21 +93,44 @@ void FeaturesPlugin_MultiRotation::performRotation1D()
   }
 
   //Getting axis.
-  std::shared_ptr<GeomAPI_Ax1> anAxis;
-  std::shared_ptr<GeomAPI_Edge> anEdge;
-  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
-    selection(FeaturesPlugin_MultiRotation::AXIS_ANGULAR_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()));
+  static const std::string aSelectionError = "Error: The axis shape selection is bad.";
+  AttributeSelectionPtr anObjRef = selection(AXIS_ANGULAR_ID());
+  GeomShapePtr aShape = anObjRef->value();
+  if (!aShape.get()) {
+    if (anObjRef->context().get()) {
+      aShape = anObjRef->context()->shape();
+    }
   }
-  if(anEdge) {
-    anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
-                                                          anEdge->line()->direction()));
+  if (!aShape.get()) {
+    setError(aSelectionError);
+    return;
+  }
+
+  GeomEdgePtr anEdge;
+  if (aShape->isEdge())
+  {
+    anEdge = aShape->edge();
+  }
+  else if (aShape->isCompound())
+  {
+    GeomAPI_ShapeIterator anIt(aShape);
+    anEdge = anIt.current()->edge();
+  }
+  else
+  {
+    setError(aSelectionError);
+    return;
+  }
+
+  if (!anEdge.get())
+  {
+    setError(aSelectionError);
+    return;
   }
 
+  std::shared_ptr<GeomAPI_Ax1> anAxis(new GeomAPI_Ax1(anEdge->line()->location(),
+                                                      anEdge->line()->direction()));
+
   // Getting number of copies.
   int nbCopies =
     integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID())->value();
@@ -213,7 +236,6 @@ void FeaturesPlugin_MultiRotation::performRotation2D()
       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);
@@ -388,34 +410,16 @@ void FeaturesPlugin_MultiRotation::loadNamingDS2(
     std::shared_ptr<ModelAPI_ResultBody> theResultBody,
     std::shared_ptr<GeomAPI_Shape> theBaseShape)
 {
-  int aTag = 1;
-  int anIndex = 1;
-  std::string aRotatedName;
-
   for (std::list<std::shared_ptr<GeomAlgoAPI_Translation> >::const_iterator anIt =
     theListOfTranslationAlgo.begin(); anIt != theListOfTranslationAlgo.cend(); ++anIt) {
-    std::cout << "LOAD" << std::endl;
-    std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = (*anIt)->mapOfSubShapes();
-
     // naming of faces
-    aRotatedName = "Rotated_Face_" + std::to_string((long long) anIndex);
-    theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::FACE,
-                                               aTag++, aRotatedName, *aSubShapes.get(),
-                                               false, true);
+    theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::FACE, "Rotated_Face");
 
     // naming of edges
-    aRotatedName = "Rotated_Edge_" + std::to_string((long long) anIndex);
-    theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::EDGE,
-                                               aTag++, aRotatedName, *aSubShapes.get(),
-                                               false, true);
+    theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::EDGE, "Rotated_Edge");
 
     // naming of vertex
-    aRotatedName = "Rotated_Vertex_" + std::to_string((long long) anIndex);
-    theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::VERTEX,
-                                               aTag++, aRotatedName, *aSubShapes.get(),
-                                               false, true);
-
-    ++anIndex;
+    theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::VERTEX, "Rotated_Vertex");
   }
 }
 
@@ -425,7 +429,6 @@ void FeaturesPlugin_MultiRotation::loadNamingDS3(
     std::shared_ptr<ModelAPI_ResultBody> theResultBody,
     std::shared_ptr<GeomAPI_Shape> theBaseShape, int nb)
 {
-  int aTag = 6*nb+1;
   int anIndex = nb+1;
   std::string aRotatedName;
 
@@ -438,7 +441,7 @@ void FeaturesPlugin_MultiRotation::loadNamingDS3(
     for(; anExp.more(); anExp.next()) {
        aRotatedName = "Rotated_Face_" + std::to_string((long long) anIndex);
        aRotatedName = aRotatedName + "_" + std::to_string((long long) numFace);
-       theResultBody->generated(anExp.current(), aRotatedName, aTag++);
+       theResultBody->generated(anExp.current(), aRotatedName);
        ++numFace;
     }
     ++anIndex;
@@ -451,31 +454,15 @@ void FeaturesPlugin_MultiRotation::loadNamingDS(
     std::shared_ptr<ModelAPI_ResultBody> theResultBody,
     std::shared_ptr<GeomAPI_Shape> theBaseShape)
 {
-  int aTag = 1;
-  int anIndex = 1;
-  std::string aRotatedName;
-
   for (std::list<std::shared_ptr<GeomAlgoAPI_Rotation> >::const_iterator anIt =
     theListOfRotationAlgo.begin(); anIt != theListOfRotationAlgo.cend(); ++anIt) {
-    std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = (*anIt)->mapOfSubShapes();
-
     // naming of faces
-    aRotatedName = "Rotated_Face_" + std::to_string((long long) anIndex);
-    theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::FACE,
-                                               aTag++, aRotatedName, *aSubShapes.get(),
-                                               false, true);
+    theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::FACE, "Rotated_Face");
 
     // naming of edges
-    aRotatedName = "Rotated_Edge_" + std::to_string((long long) anIndex);
-    theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::EDGE,
-                                               aTag++, aRotatedName, *aSubShapes.get(),
-                                               false, true);
+    theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::EDGE, "Rotated_Edge");
 
     // naming of vertex
-    aRotatedName = "Rotated_Vertex_" + std::to_string((long long) anIndex);
-    theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::VERTEX,
-                                               aTag++, aRotatedName, *aSubShapes.get(),
-                                               false, true);
-    ++anIndex;
+    theResultBody->loadModifiedShapes(*anIt, theBaseShape, GeomAPI_Shape::VERTEX, "Rotated_Vertex");
   }
 }