Salome HOME
Fixed crash on when creating circle by 3 points.
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Point.cpp
index c7b4f1d444a44ef351e0d2f928115d78605bfea0..fa0cf672a2d801930cc5c663b2e5b342fa5d9c56 100644 (file)
 #include <ModelAPI_ResultConstruction.h>
 
 #include <GeomAlgoAPI_PointBuilder.h>
-#include <GeomAlgoAPI_ShapeTools.h>
 
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_Vertex.h>
 
 //==================================================================================================
 ConstructionPlugin_Point::ConstructionPlugin_Point()
@@ -33,41 +33,60 @@ const std::string& ConstructionPlugin_Point::getKind()
 //==================================================================================================
 void ConstructionPlugin_Point::initAttributes()
 {
+  //data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
+
   data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
 
-  data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
-
-  data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
+  /*data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
   data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
+
+  data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
+
+  data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId());
+
+  data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());*/
 }
 
 //==================================================================================================
 void ConstructionPlugin_Point::execute()
 {
-  GeomShapePtr aShape;
+  GeomShapePtr aShape = createByXYZ();
+
+  /*GeomShapePtr aShape;
 
   std::string aCreationMethod = string(CREATION_METHOD())->value();
   if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
     aShape = createByXYZ();
   } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
     aShape = createByDistanceOnEdge();
-  }
+  } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
+    aShape = createByProjection();
+  } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
+    aShape = createByLinesIntersection();
+  } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
+    aShape = createByLineAndPlaneIntersection();
+  }*/
 
-  if(aShape.get()) {
-    std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
-    aConstr->setShape(aShape);
-    setResult(aConstr);
+  if(!aShape.get()) {
+    return;
   }
+
+  std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
+  aConstr->setShape(aShape);
+  setResult(aConstr);
 }
 
 //==================================================================================================
 bool ConstructionPlugin_Point::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);
@@ -76,15 +95,15 @@ bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
 }
 
 //==================================================================================================
-GeomShapePtr ConstructionPlugin_Point::createByXYZ()
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
 {
-  return GeomAlgoAPI_PointBuilder::point(real(X())->value(),
-                                         real(Y())->value(),
-                                         real(Z())->value());
+  return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
+                                          real(Y())->value(),
+                                          real(Z())->value());
 }
 
-//==================================================================================================
-GeomShapePtr ConstructionPlugin_Point::createByDistanceOnEdge()
+/*//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
 {
   // Get edge.
   AttributeSelectionPtr anEdgeSelection = selection(EDGE());
@@ -101,5 +120,71 @@ GeomShapePtr ConstructionPlugin_Point::createByDistanceOnEdge()
   // Get reverse flag.
   bool anIsReverse = boolean(REVERSE())->value();
 
-  return GeomAlgoAPI_ShapeTools::findVertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
+  return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
 }
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
+{
+  // Get point.
+  AttributeSelectionPtr aPointSelection = selection(POINT());
+  GeomShapePtr aPointShape = aPointSelection->value();
+  if(!aPointShape.get()) {
+    aPointShape = aPointSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
+
+  // Get plane.
+  AttributeSelectionPtr aPlaneSelection = selection(PLANE());
+  GeomShapePtr aPlaneShape = aPlaneSelection->value();
+  if(!aPlaneShape.get()) {
+    aPlaneShape = aPlaneSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
+
+  return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersection()
+{
+  // Get first line.
+  AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE());
+  GeomShapePtr aFirstLineShape = aFirstLineSelection->value();
+  if(!aFirstLineShape.get()) {
+    aFirstLineShape = aFirstLineSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
+
+  // Get second line.
+  AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
+  GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
+  if(!aSecondLineShape.get()) {
+    aSecondLineShape = aSecondLineSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Edge> aSecondEdge(new GeomAPI_Edge(aSecondLineShape));
+
+  return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
+{
+  // Get line.
+  AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE());
+  GeomShapePtr aLineShape = aLineSelection->value();
+  if(!aLineShape.get()) {
+    aLineShape = aLineSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
+
+  // Get plane.
+  AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE());
+  GeomShapePtr aPlaneShape = aPlaneSelection->value();
+  if(!aPlaneShape.get()) {
+    aPlaneShape = aPlaneSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
+
+  return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace);
+}*/