Salome HOME
Revert "Issue #2593: CEA 2018-2 Geometrical Naming"
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Rotation.cpp
index 81e24480297f5e0f658bd7e9a00952e0353ae018..07d2d575c109924f51fbb72a73d1174913faded6 100755 (executable)
@@ -30,7 +30,6 @@
 
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
-#include <GeomAPI_ShapeIterator.h>
 #include <GeomAPI_Trsf.h>
 
 #include <FeaturesPlugin_Tools.h>
@@ -100,43 +99,20 @@ void FeaturesPlugin_Rotation::performTranslationByAxisAndAngle()
   }
 
   //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();
-    }
-  }
-  if (!aShape.get()) {
-    setError(aSelectionError);
-    return;
+  std::shared_ptr<GeomAPI_Ax1> anAxis;
+  std::shared_ptr<GeomAPI_Edge> anEdge;
+  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
+    selection(FeaturesPlugin_Rotation::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()));
   }
-
-  GeomEdgePtr anEdge;
-  if (aShape->isEdge())
-  {
-    anEdge = aShape->edge();
-  }
-  else if (aShape->isCompound())
-  {
-    GeomAPI_ShapeIterator anIt(aShape);
-    anEdge = anIt.current()->edge();
+  if(anEdge) {
+    anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
+                                                          anEdge->line()->direction()));
   }
-  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 angle.
   double anAngle = real(FeaturesPlugin_Rotation::ANGLE_ID())->value();