]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConstructionPlugin/ConstructionPlugin_Point.cpp
Salome HOME
Added option to create Construction Point by projection point on plane. Fixed CPP...
[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
17 #include <GeomAPI_Edge.h>
18 #include <GeomAPI_Pnt.h>
19 #include <GeomAPI_Vertex.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   data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
48   data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
49 }
50
51 //==================================================================================================
52 void ConstructionPlugin_Point::execute()
53 {
54   GeomShapePtr aShape;
55
56   std::string aCreationMethod = string(CREATION_METHOD())->value();
57   if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
58     aShape = createByXYZ();
59   } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
60     aShape = createByDistanceOnEdge();
61   } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
62     aShape = createByProjection();
63   }
64
65   if(aShape.get()) {
66     std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
67     aConstr->setShape(aShape);
68     setResult(aConstr);
69   }
70 }
71
72 //==================================================================================================
73 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
74                                                      AISObjectPtr thePrs,
75                                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
76 {
77   bool isCustomized = theDefaultPrs.get() != NULL &&
78                       theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
79   //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
80   return true;
81 }
82
83 //==================================================================================================
84 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
85 {
86   return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
87                                           real(Y())->value(),
88                                           real(Z())->value());
89 }
90
91 //==================================================================================================
92 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
93 {
94   // Get edge.
95   AttributeSelectionPtr anEdgeSelection = selection(EDGE());
96   GeomShapePtr aShape = anEdgeSelection->value();
97   if(!aShape.get()) {
98     aShape = anEdgeSelection->context()->shape();
99   }
100   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
101
102   // Get distance value and percent flag.
103   double aValue = real(DISTANCE_VALUE())->value();
104   bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
105
106   // Get reverse flag.
107   bool anIsReverse = boolean(REVERSE())->value();
108
109   return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
110 }
111
112 //==================================================================================================
113 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
114 {
115   // Get point.
116   AttributeSelectionPtr aPointSelection = selection(POINT());
117   GeomShapePtr aPointShape = aPointSelection->value();
118   if(!aPointShape.get()) {
119     aPointShape = aPointSelection->context()->shape();
120   }
121   std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
122
123   // Get plane.
124   AttributeSelectionPtr aPlaneSelection = selection(PLANE());
125   GeomShapePtr aPlaneShape = aPlaneSelection->value();
126   if(!aPlaneShape.get()) {
127     aPlaneShape = aPlaneSelection->context()->shape();
128   }
129   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
130
131   return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
132 }