Salome HOME
Issue #555 - Make a number of shifted/rotated copies - selected object does not appea...
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Axis.cpp
index 570a3a3b8edb2b58a4a19ff02b5c39e0f59dacd7..60b9833c35c7a9e4f45515aa940f4e41d6a05aa0 100644 (file)
@@ -6,13 +6,20 @@
 
 #include "ConstructionPlugin_Axis.h"
 
+#include <Config_PropManager.h>
+
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeString.h>
 
 #include <GeomAPI_Edge.h>
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_PointBuilder.h>
 
+#ifdef _DEBUG
+#include <iostream>
+#endif
+
 using namespace std;
 
 ConstructionPlugin_Axis::ConstructionPlugin_Axis()
@@ -21,24 +28,32 @@ ConstructionPlugin_Axis::ConstructionPlugin_Axis()
 
 void ConstructionPlugin_Axis::initAttributes()
 {
+  data()->addAttribute(ConstructionPlugin_Axis::METHOD(),
+                       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::typeId());
 }
 
-void ConstructionPlugin_Axis::execute()
+void ConstructionPlugin_Axis::createAxisByTwoPoints()
 {
   AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
   AttributeSelectionPtr aRef2 = data()->selection(ConstructionPlugin_Axis::POINT_SECOND());
   if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
     GeomShapePtr aShape1 = aRef1->value();
+    if (!aShape1.get())
+      aShape1 = aRef1->context()->shape();
     GeomShapePtr aShape2 = aRef2->value();
+    if (!aShape2.get())
+      aShape2 = aRef2->context()->shape();
     if (aShape1->isVertex() && aShape2->isVertex() && (!aShape1->isEqual(aShape2))) {
       std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
       std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
       if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
-        std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+        std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd, true);
 
         ResultConstructionPtr aConstr = document()->createConstruction(data());
         aConstr->setShape(anEdge);
@@ -48,9 +63,38 @@ void ConstructionPlugin_Axis::execute()
   }
 }
 
-void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
+void ConstructionPlugin_Axis::createAxisByCylindricalFace()
 {
-  thePrs->setColor(0, 0, 0);
-  thePrs->setLineStyle(3);
-  thePrs->redisplay();
+    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()
+{
+  AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
+  std::string aMethodType = aMethodTypeAttr->value();
+  if (aMethodType == "AxisByPointsCase") {
+    createAxisByTwoPoints();
+  } else if (aMethodType == "AxisByCylindricalFaceCase") {
+    createAxisByCylindricalFace();
+  }
+}
+
+bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+  std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+{
+  bool isCustomized = theDefaultPrs.get() != NULL &&
+                      theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+
+  isCustomized = thePrs->setLineStyle(3) || isCustomized;
+  isCustomized = thePrs->setWidth(2) || isCustomized;
+
+  return isCustomized;
 }