Salome HOME
c7b4f1d444a44ef351e0d2f928115d78605bfea0
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Point.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ConstructionPlugin_Point.cxx
4 // Created:     27 Mar 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "ConstructionPlugin_Point.h"
8
9 #include <ModelAPI_AttributeBoolean.h>
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_AttributeString.h>
13 #include <ModelAPI_ResultConstruction.h>
14
15 #include <GeomAlgoAPI_PointBuilder.h>
16 #include <GeomAlgoAPI_ShapeTools.h>
17
18 #include <GeomAPI_Edge.h>
19 #include <GeomAPI_Pnt.h>
20
21 //==================================================================================================
22 ConstructionPlugin_Point::ConstructionPlugin_Point()
23 {
24 }
25
26 //==================================================================================================
27 const std::string& ConstructionPlugin_Point::getKind()
28 {
29   static std::string MY_KIND = ConstructionPlugin_Point::ID();
30   return MY_KIND;
31 }
32
33 //==================================================================================================
34 void ConstructionPlugin_Point::initAttributes()
35 {
36   data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
37   data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
38   data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
39
40   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
41
42   data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
43   data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
44   data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
45   data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
46 }
47
48 //==================================================================================================
49 void ConstructionPlugin_Point::execute()
50 {
51   GeomShapePtr aShape;
52
53   std::string aCreationMethod = string(CREATION_METHOD())->value();
54   if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
55     aShape = createByXYZ();
56   } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
57     aShape = createByDistanceOnEdge();
58   }
59
60   if(aShape.get()) {
61     std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
62     aConstr->setShape(aShape);
63     setResult(aConstr);
64   }
65 }
66
67 //==================================================================================================
68 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
69                                                      AISObjectPtr thePrs,
70                                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
71 {
72   bool isCustomized = theDefaultPrs.get() != NULL &&
73                       theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
74   //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
75   return true;
76 }
77
78 //==================================================================================================
79 GeomShapePtr ConstructionPlugin_Point::createByXYZ()
80 {
81   return GeomAlgoAPI_PointBuilder::point(real(X())->value(),
82                                          real(Y())->value(),
83                                          real(Z())->value());
84 }
85
86 //==================================================================================================
87 GeomShapePtr ConstructionPlugin_Point::createByDistanceOnEdge()
88 {
89   // Get edge.
90   AttributeSelectionPtr anEdgeSelection = selection(EDGE());
91   GeomShapePtr aShape = anEdgeSelection->value();
92   if(!aShape.get()) {
93     aShape = anEdgeSelection->context()->shape();
94   }
95   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
96
97   // Get distance value and percent flag.
98   double aValue = real(DISTANCE_VALUE())->value();
99   bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
100
101   // Get reverse flag.
102   bool anIsReverse = boolean(REVERSE())->value();
103
104   return GeomAlgoAPI_ShapeTools::findVertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
105 }