Salome HOME
Issue #1114: Provide selection of origin and axis of trihedron with reference to...
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Axis.cpp
index 8a6c2a5d0c23fb8ea0dad5ad7b35404771e1c90c..20a11909a88d57c8b2fdf4e3250c57322b544b9f 100644 (file)
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeDouble.h>
 
 #include <GeomAPI_Edge.h>
+#include <GeomAPI_Vertex.h>
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_PointBuilder.h>
 
@@ -36,6 +38,12 @@ void ConstructionPlugin_Axis::initAttributes()
                        ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(),
                        ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(ConstructionPlugin_Axis::X_DIRECTION(),
+                       ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(ConstructionPlugin_Axis::Y_DIRECTION(),
+                       ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(ConstructionPlugin_Axis::Z_DIRECTION(),
+                       ModelAPI_AttributeDouble::typeId());
 }
 
 void ConstructionPlugin_Axis::createAxisByTwoPoints()
@@ -64,6 +72,38 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints()
   }
 }
 
+
+void ConstructionPlugin_Axis::createAxisByPointAndDirection()
+{
+  AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
+  AttributeDoublePtr aXAttr = data()->real(ConstructionPlugin_Axis::X_DIRECTION());
+  AttributeDoublePtr aYAttr = data()->real(ConstructionPlugin_Axis::Y_DIRECTION());
+  AttributeDoublePtr aZAttr = data()->real(ConstructionPlugin_Axis::Z_DIRECTION());
+  if ((aRef1.get() != NULL) && (aXAttr.get() != NULL) && 
+      (aYAttr.get() != NULL) && (aZAttr.get() != NULL)) {
+    GeomShapePtr aShape1 = aRef1->value();
+    if (!aShape1.get())
+      aShape1 = aRef1->context()->shape();
+
+    std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aXAttr->value(), 
+                                                               aYAttr->value(),
+                                                               aZAttr->value()));
+    if (aShape1->isVertex() && (!aShape1->isEqual(aVertex))) {
+      std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
+      std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aVertex);
+      if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
+        std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+
+        ResultConstructionPtr aConstr = document()->createConstruction(data());
+        aConstr->setInfinite(true);
+        aConstr->setShape(anEdge);
+        setResult(aConstr);
+      }
+    }
+  }
+}
+
+
 void ConstructionPlugin_Axis::createAxisByCylindricalFace()
 {
     std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
@@ -78,6 +118,8 @@ void ConstructionPlugin_Axis::createAxisByCylindricalFace()
     }
 }
 
+
+
 void ConstructionPlugin_Axis::execute()
 {
   AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
@@ -86,6 +128,8 @@ void ConstructionPlugin_Axis::execute()
     createAxisByTwoPoints();
   } else if (aMethodType == "AxisByCylindricalFaceCase") {
     createAxisByCylindricalFace();
+  } else if (aMethodType == "AxisByPointAndDirection") {
+    createAxisByPointAndDirection();
   }
 }