Salome HOME
Fix for issue #461
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Axis.cpp
index 8e90fae27eb89033d6f4e06ed2c314117a08c096..ae24aaf3c7916561f9de78cd36f8dfdbc6dcbf69 100644 (file)
@@ -29,13 +29,13 @@ ConstructionPlugin_Axis::ConstructionPlugin_Axis()
 void ConstructionPlugin_Axis::initAttributes()
 {
   data()->addAttribute(ConstructionPlugin_Axis::METHOD(),
-                       ModelAPI_AttributeString::type());
+                       ModelAPI_AttributeString::typeId());
   data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(),
-                       ModelAPI_AttributeSelection::type());
+                       ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(),
-                       ModelAPI_AttributeSelection::type());
+                       ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(),
-                       ModelAPI_AttributeSelection::type());
+                       ModelAPI_AttributeSelection::typeId());
 }
 
 void ConstructionPlugin_Axis::createAxisByTwoPoints()
@@ -59,23 +59,32 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints()
   }
 }
 
+void ConstructionPlugin_Axis::createAxisByCylindricalFace()
+{
+    std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
+     // update arguments due to the selection value
+    if (aSelection && !aSelection->isNull() && aSelection->isFace()) {
+      std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection);
+
+      ResultConstructionPtr aConstr = document()->createConstruction(data());
+      aConstr->setShape(anEdge);
+      setResult(aConstr);
+    }
+}
+
 void ConstructionPlugin_Axis::execute()
 {
-  AttributePtr anAttr = data()->attribute(ConstructionPlugin_Axis::METHOD());
-  AttributeStringPtr aMethodTypeAttr =
-      std::dynamic_pointer_cast<ModelAPI_AttributeString>(anAttr);
+  AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
   std::string aMethodType = aMethodTypeAttr->value();
   if (aMethodType == "AxisByPointsCase") {
     createAxisByTwoPoints();
   } else if (aMethodType == "AxisByCylindricalFaceCase") {
-    #ifdef _DEBUG
-    std::cout << "ConstructionPlugin_Axis::execute: " << "AxisByCylindricalFaceCase is not supported yet." << std::endl;
-    #endif
+    createAxisByCylindricalFace();
   }
 }
 
 bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
-                                                    std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+  std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
 {
   bool isCustomized = theDefaultPrs.get() != NULL &&
                       theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);