]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConstructionAPI/ConstructionAPI_Plane.cpp
Salome HOME
Issue #1649: Added CPP High API for Plane feature;
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Plane.cpp
1 // Name   : ConstructionAPI_Plane.cpp
2 // Purpose: 
3 //
4 // History:
5 // 27/05/16 - Sergey POKHODENKO - Creation of the file
6
7 #include "ConstructionAPI_Plane.h"
8
9 #include <ModelHighAPI_Tools.h>
10
11 //==================================================================================================
12 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature)
13 : ModelHighAPI_Interface(theFeature)
14 {
15   initialize();
16 }
17
18 //==================================================================================================
19 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
20                                              const ModelHighAPI_Selection& theFace,
21                                              const ModelHighAPI_Double& theDistance,
22                                              const bool theIsReverse)
23 : ModelHighAPI_Interface(theFeature)
24 {
25   if(initialize()) {
26     setByFaceAndDistance(theFace, theDistance, theIsReverse);
27   }
28 }
29
30 //==================================================================================================
31 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
32                                              const ModelHighAPI_Double& theA,
33                                              const ModelHighAPI_Double& theB,
34                                              const ModelHighAPI_Double& theC,
35                                              const ModelHighAPI_Double& theD)
36 : ModelHighAPI_Interface(theFeature)
37 {
38   if(initialize()) {
39     setByGeneralEquation(theA, theB, theC, theD);
40   }
41 }
42
43 //==================================================================================================
44 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
45                                              const ModelHighAPI_Selection& thePoint1,
46                                              const ModelHighAPI_Selection& thePoint2,
47                                              const ModelHighAPI_Selection& thePoint3)
48 : ModelHighAPI_Interface(theFeature)
49 {
50   if(initialize()) {
51     setByThreePoints(thePoint1, thePoint2, thePoint3);
52   }
53 }
54
55 //==================================================================================================
56 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
57                                              const ModelHighAPI_Selection& theLine,
58                                              const ModelHighAPI_Selection& thePoint,
59                                              const bool theIsPerpendicular)
60 : ModelHighAPI_Interface(theFeature)
61 {
62   if(initialize()) {
63     setByLineAndPoint(theLine, thePoint, theIsPerpendicular);
64   }
65 }
66
67 //==================================================================================================
68 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
69                                              const ModelHighAPI_Selection& theObject1,
70                                              const ModelHighAPI_Selection& theObject2)
71 : ModelHighAPI_Interface(theFeature)
72 {
73   if(initialize()) {
74     GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
75     GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
76     if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) {
77       setByCoincidentToPoint(theObject1, theObject2);
78     } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) {
79       setByTwoParallelPlanes(theObject1, theObject2);
80     }
81   }
82 }
83
84 //==================================================================================================
85 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
86                                              const ModelHighAPI_Selection& thePlane,
87                                              const ModelHighAPI_Selection& theAxis,
88                                              const ModelHighAPI_Double& theAngle)
89 : ModelHighAPI_Interface(theFeature)
90 {
91   if(initialize()) {
92     setByRotation(thePlane, theAxis, theAngle);
93   }
94 }
95
96 //==================================================================================================
97 ConstructionAPI_Plane::~ConstructionAPI_Plane()
98 {
99 }
100
101 //==================================================================================================
102 void ConstructionAPI_Plane::setByFaceAndDistance(const ModelHighAPI_Selection& theFace,
103                                                  const ModelHighAPI_Double& theDistance,
104                                                  const bool theIsReverse)
105 {
106   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
107   fillAttribute(theFace, myplane);
108   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER(), mycreationMethodByOtherPlane);
109   fillAttribute(theDistance, mydistance);
110   fillAttribute(theIsReverse, myreverse);
111
112   execute();
113 }
114
115 //==================================================================================================
116 void ConstructionAPI_Plane::setByGeneralEquation(const ModelHighAPI_Double& theA,
117                                                  const ModelHighAPI_Double& theB,
118                                                  const ModelHighAPI_Double& theC,
119                                                  const ModelHighAPI_Double& theD)
120 {
121   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION(), mycreationMethod);
122   fillAttribute(theA, myA);
123   fillAttribute(theB, myB);
124   fillAttribute(theC, myC);
125   fillAttribute(theD, myD);
126
127   execute();
128 }
129
130 //==================================================================================================
131 void ConstructionAPI_Plane::setByThreePoints(const ModelHighAPI_Selection& thePoint1,
132                                              const ModelHighAPI_Selection& thePoint2,
133                                              const ModelHighAPI_Selection& thePoint3)
134 {
135   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
136   fillAttribute(thePoint1, mypoint1);
137   fillAttribute(thePoint2, mypoint2);
138   fillAttribute(thePoint3, mypoint3);
139
140   execute();
141 }
142
143 //==================================================================================================
144 void ConstructionAPI_Plane::setByLineAndPoint(const ModelHighAPI_Selection& theLine,
145                                               const ModelHighAPI_Selection& thePoint,
146                                               const bool theIsPerpendicular)
147 {
148   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT(), mycreationMethod);
149   fillAttribute(theLine, myline);
150   fillAttribute(thePoint, mypoint);
151   fillAttribute(theIsPerpendicular, myperpendicular);
152
153   execute();
154 }
155
156 //==================================================================================================
157 void ConstructionAPI_Plane::setByTwoParallelPlanes(const ModelHighAPI_Selection& thePlane1,
158                                                    const ModelHighAPI_Selection& thePlane2)
159 {
160   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES(), mycreationMethod);
161   fillAttribute(thePlane1, myplane1);
162   fillAttribute(thePlane2, myplane2);
163
164   execute();
165 }
166
167 //==================================================================================================
168 void ConstructionAPI_Plane::setByCoincidentToPoint(const ModelHighAPI_Selection& thePlane,
169                                                    const ModelHighAPI_Selection& thePoint)
170 {
171   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
172   fillAttribute(thePlane, myplane);
173   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT(), mycreationMethodByOtherPlane);
174   fillAttribute(thePoint, mycoincidentPoint);
175
176   execute();
177 }
178
179 //==================================================================================================
180 void ConstructionAPI_Plane::setByRotation(const ModelHighAPI_Selection& thePlane,
181                                           const ModelHighAPI_Selection& theAxis,
182                                           const ModelHighAPI_Double& theAngle)
183 {
184   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
185   fillAttribute(thePlane, myplane);
186   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION(), mycreationMethodByOtherPlane);
187   fillAttribute(theAxis, myaxis);
188   fillAttribute(theAngle, myangle);
189
190   execute();
191 }
192
193 //==================================================================================================
194 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
195                   const ModelHighAPI_Selection& theFace,
196                   const ModelHighAPI_Double& theDistance,
197                   const bool theIsReverse)
198 {
199   // TODO(spo): check that thePart is not empty
200   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
201   return PlanePtr(new ConstructionAPI_Plane(aFeature, theFace, theDistance, theIsReverse));
202 }
203
204 //==================================================================================================
205 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
206                   const ModelHighAPI_Double& theA,
207                   const ModelHighAPI_Double& theB,
208                   const ModelHighAPI_Double& theC,
209                   const ModelHighAPI_Double& theD)
210 {
211   // TODO(spo): check that thePart is not empty
212   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
213   return PlanePtr(new ConstructionAPI_Plane(aFeature, theA, theB, theC, theD));
214 }
215
216 //==================================================================================================
217 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
218                   const ModelHighAPI_Selection& thePoint1,
219                   const ModelHighAPI_Selection& thePoint2,
220                   const ModelHighAPI_Selection& thePoint3)
221 {
222   // TODO(spo): check that thePart is not empty
223   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
224   return PlanePtr(new ConstructionAPI_Plane(aFeature, thePoint1, thePoint2, thePoint3));
225 }
226
227 //==================================================================================================
228 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
229                   const ModelHighAPI_Selection& theLine,
230                   const ModelHighAPI_Selection& thePoint,
231                   const bool theIsPerpendicular)
232 {
233   // TODO(spo): check that thePart is not empty
234   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
235   return PlanePtr(new ConstructionAPI_Plane(aFeature, theLine, thePoint, theIsPerpendicular));
236 }
237
238 //==================================================================================================
239 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
240                   const ModelHighAPI_Selection& theObject1,
241                   const ModelHighAPI_Selection& theObject2)
242 {
243   // TODO(spo): check that thePart is not empty
244   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
245   return PlanePtr(new ConstructionAPI_Plane(aFeature, theObject1, theObject2));
246 }
247
248 //==================================================================================================
249 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
250                   const ModelHighAPI_Selection& thePlane,
251                   const ModelHighAPI_Selection& theAxis,
252                   const ModelHighAPI_Double& theAngle)
253 {
254   // TODO(spo): check that thePart is not empty
255   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
256   return PlanePtr(new ConstructionAPI_Plane(aFeature, thePlane, theAxis, theAngle));
257 }