Salome HOME
Added option to create Construction Point by projection point on plane. Fixed CPP...
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Point.cpp
1 // Name   : ConstructionAPI_Point.cpp
2 // Purpose: 
3 //
4 // History:
5 // 29/03/16 - Sergey POKHODENKO - Creation of the file
6
7 #include "ConstructionAPI_Point.h"
8
9 #include <ModelHighAPI_Tools.h>
10
11 //==================================================================================================
12 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
13 : ModelHighAPI_Interface(theFeature)
14 {
15   initialize();
16 }
17
18 //==================================================================================================
19 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
20                                              const ModelHighAPI_Double& theX,
21                                              const ModelHighAPI_Double& theY,
22                                              const ModelHighAPI_Double& theZ)
23 : ModelHighAPI_Interface(theFeature)
24 {
25   if(initialize()) {
26     setByXYZ(theX, theY, theZ);
27   }
28 }
29
30 //==================================================================================================
31 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
32                                              const ModelHighAPI_Selection& theEdge,
33                                              const ModelHighAPI_Double& theDistanceValue,
34                                              const bool theDistancePercent,
35                                              const bool theReverse)
36 : ModelHighAPI_Interface(theFeature)
37 {
38   if(initialize()) {
39     setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
40   }
41 }
42
43 //==================================================================================================
44 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
45                                              const ModelHighAPI_Selection& theObject1,
46                                              const ModelHighAPI_Selection& theObject2)
47 : ModelHighAPI_Interface(theFeature)
48 {
49   if(initialize()) {
50     /// If first object is vertex and second object is face then set by projection.
51     /// TODO: check
52     setByProjection(theObject1, theObject2);
53   }
54 }
55
56 //==================================================================================================
57 ConstructionAPI_Point::~ConstructionAPI_Point()
58 {
59
60 }
61
62 //==================================================================================================
63 void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
64                                      const ModelHighAPI_Double& theY,
65                                      const ModelHighAPI_Double& theZ)
66 {
67   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
68   fillAttribute(theX, myx);
69   fillAttribute(theY, myy);
70   fillAttribute(theZ, myz);
71
72   execute();
73 }
74
75 //==================================================================================================
76 void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
77                                                 const ModelHighAPI_Double& theDistanceValue,
78                                                 const bool theDistancePercent,
79                                                 const bool theReverse)
80 {
81   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
82   fillAttribute(theEdge, myedge);
83   fillAttribute(theDistanceValue, mydistanceValue);
84   fillAttribute(theDistancePercent, mydistancePercent);
85   fillAttribute(theReverse, myreverse);
86
87   execute();
88 }
89
90 //==================================================================================================
91 void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
92                                             const ModelHighAPI_Selection& thePlane)
93 {
94   fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
95   fillAttribute(theVertex, mypoint);
96   fillAttribute(thePlane, myplane);
97
98   execute();
99 }
100
101 //==================================================================================================
102 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
103                   const ModelHighAPI_Double& theX,
104                   const ModelHighAPI_Double& theY,
105                   const ModelHighAPI_Double& theZ)
106 {
107   // TODO(spo): check that thePart is not empty
108   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
109   return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
110 }
111
112 //==================================================================================================
113 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
114                   const ModelHighAPI_Selection& theEdge,
115                   const ModelHighAPI_Double& theDistanceValue,
116                   const bool theDistancePercent,
117                   const bool theReverse)
118 {
119   // TODO(spo): check that thePart is not empty
120   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
121   return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
122 }
123
124 //==================================================================================================
125 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
126                   const ModelHighAPI_Selection& theObject1,
127                   const ModelHighAPI_Selection& theObject2)
128 {
129   // TODO(spo): check that thePart is not empty
130   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
131   return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
132 }