Salome HOME
Issue #1648: Dump Python in the High Level Parameterized Geometry API
[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_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
15 {
16   initialize();
17 }
18
19 //==================================================================================================
20 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
21                                              const ModelHighAPI_Selection& theFace,
22                                              const ModelHighAPI_Double& theDistance,
23                                              const bool theIsReverse)
24 : ModelHighAPI_Interface(theFeature)
25 {
26   if(initialize()) {
27     setByFaceAndDistance(theFace, theDistance, theIsReverse);
28   }
29 }
30
31 //==================================================================================================
32 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
33                                              const ModelHighAPI_Double& theA,
34                                              const ModelHighAPI_Double& theB,
35                                              const ModelHighAPI_Double& theC,
36                                              const ModelHighAPI_Double& theD)
37 : ModelHighAPI_Interface(theFeature)
38 {
39   if(initialize()) {
40     setByGeneralEquation(theA, theB, theC, theD);
41   }
42 }
43
44 //==================================================================================================
45 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
46                                              const ModelHighAPI_Selection& thePoint1,
47                                              const ModelHighAPI_Selection& thePoint2,
48                                              const ModelHighAPI_Selection& thePoint3)
49 : ModelHighAPI_Interface(theFeature)
50 {
51   if(initialize()) {
52     setByThreePoints(thePoint1, thePoint2, thePoint3);
53   }
54 }
55
56 //==================================================================================================
57 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
58                                              const ModelHighAPI_Selection& theLine,
59                                              const ModelHighAPI_Selection& thePoint,
60                                              const bool theIsPerpendicular)
61 : ModelHighAPI_Interface(theFeature)
62 {
63   if(initialize()) {
64     setByLineAndPoint(theLine, thePoint, theIsPerpendicular);
65   }
66 }
67
68 //==================================================================================================
69 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
70                                              const ModelHighAPI_Selection& theObject1,
71                                              const ModelHighAPI_Selection& theObject2)
72 : ModelHighAPI_Interface(theFeature)
73 {
74   if(initialize()) {
75     GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
76     GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
77     if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) {
78       setByCoincidentToPoint(theObject1, theObject2);
79     } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) {
80       setByTwoParallelPlanes(theObject1, theObject2);
81     }
82   }
83 }
84
85 //==================================================================================================
86 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
87                                              const ModelHighAPI_Selection& thePlane,
88                                              const ModelHighAPI_Selection& theAxis,
89                                              const ModelHighAPI_Double& theAngle)
90 : ModelHighAPI_Interface(theFeature)
91 {
92   if(initialize()) {
93     setByRotation(thePlane, theAxis, theAngle);
94   }
95 }
96
97 //==================================================================================================
98 ConstructionAPI_Plane::~ConstructionAPI_Plane()
99 {
100 }
101
102 //==================================================================================================
103 void ConstructionAPI_Plane::setByFaceAndDistance(const ModelHighAPI_Selection& theFace,
104                                                  const ModelHighAPI_Double& theDistance,
105                                                  const bool theIsReverse)
106 {
107   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
108   fillAttribute(theFace, myplane);
109   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER(), mycreationMethodByOtherPlane);
110   fillAttribute(theDistance, mydistance);
111   fillAttribute(theIsReverse, myreverse);
112
113   execute();
114 }
115
116 //==================================================================================================
117 void ConstructionAPI_Plane::setByGeneralEquation(const ModelHighAPI_Double& theA,
118                                                  const ModelHighAPI_Double& theB,
119                                                  const ModelHighAPI_Double& theC,
120                                                  const ModelHighAPI_Double& theD)
121 {
122   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION(), mycreationMethod);
123   fillAttribute(theA, myA);
124   fillAttribute(theB, myB);
125   fillAttribute(theC, myC);
126   fillAttribute(theD, myD);
127
128   execute();
129 }
130
131 //==================================================================================================
132 void ConstructionAPI_Plane::setByThreePoints(const ModelHighAPI_Selection& thePoint1,
133                                              const ModelHighAPI_Selection& thePoint2,
134                                              const ModelHighAPI_Selection& thePoint3)
135 {
136   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
137   fillAttribute(thePoint1, mypoint1);
138   fillAttribute(thePoint2, mypoint2);
139   fillAttribute(thePoint3, mypoint3);
140
141   execute();
142 }
143
144 //==================================================================================================
145 void ConstructionAPI_Plane::setByLineAndPoint(const ModelHighAPI_Selection& theLine,
146                                               const ModelHighAPI_Selection& thePoint,
147                                               const bool theIsPerpendicular)
148 {
149   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT(), mycreationMethod);
150   fillAttribute(theLine, myline);
151   fillAttribute(thePoint, mypoint);
152   fillAttribute(theIsPerpendicular, myperpendicular);
153
154   execute();
155 }
156
157 //==================================================================================================
158 void ConstructionAPI_Plane::setByTwoParallelPlanes(const ModelHighAPI_Selection& thePlane1,
159                                                    const ModelHighAPI_Selection& thePlane2)
160 {
161   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES(), mycreationMethod);
162   fillAttribute(thePlane1, myplane1);
163   fillAttribute(thePlane2, myplane2);
164
165   execute();
166 }
167
168 //==================================================================================================
169 void ConstructionAPI_Plane::setByCoincidentToPoint(const ModelHighAPI_Selection& thePlane,
170                                                    const ModelHighAPI_Selection& thePoint)
171 {
172   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
173   fillAttribute(thePlane, myplane);
174   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT(), mycreationMethodByOtherPlane);
175   fillAttribute(thePoint, mycoincidentPoint);
176
177   execute();
178 }
179
180 //==================================================================================================
181 void ConstructionAPI_Plane::setByRotation(const ModelHighAPI_Selection& thePlane,
182                                           const ModelHighAPI_Selection& theAxis,
183                                           const ModelHighAPI_Double& theAngle)
184 {
185   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
186   fillAttribute(thePlane, myplane);
187   fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION(), mycreationMethodByOtherPlane);
188   fillAttribute(theAxis, myaxis);
189   fillAttribute(theAngle, myangle);
190
191   execute();
192 }
193
194 //==================================================================================================
195 void ConstructionAPI_Plane::dump(ModelHighAPI_Dumper& theDumper) const
196 {
197   FeaturePtr aBase = feature();
198   const std::string& aDocName = theDumper.name(aBase->document());
199
200   theDumper << aBase << " = model.addPlane(" << aDocName;
201
202   std::string aCreationMethod = aBase->string(ConstructionPlugin_Plane::CREATION_METHOD())->value();
203
204   if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION()) {
205     AttributeDoublePtr anAttrA = aBase->real(ConstructionPlugin_Plane::A());
206     AttributeDoublePtr anAttrB = aBase->real(ConstructionPlugin_Plane::B());
207     AttributeDoublePtr anAttrC = aBase->real(ConstructionPlugin_Plane::C());
208     AttributeDoublePtr anAttrD = aBase->real(ConstructionPlugin_Plane::D());
209
210     theDumper << ", " << anAttrA << ", " << anAttrB << ", " << anAttrC << ", " << anAttrD;
211   } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS()) {
212     AttributeSelectionPtr anAttrPnt1 = aBase->selection(ConstructionPlugin_Plane::POINT1());
213     AttributeSelectionPtr anAttrPnt2 = aBase->selection(ConstructionPlugin_Plane::POINT2());
214     AttributeSelectionPtr anAttrPnt3 = aBase->selection(ConstructionPlugin_Plane::POINT3());
215
216     theDumper << ", " << anAttrPnt1 << ", " << anAttrPnt2 << ", " << anAttrPnt3;
217   } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT()) {
218     AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Plane::LINE());
219     AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Plane::POINT());
220     AttributeBooleanPtr anAttrPerpendicular = aBase->boolean(ConstructionPlugin_Plane::PERPENDICULAR());
221
222     theDumper << ", " << anAttrLine << ", " << anAttrPoint << ", " << anAttrPerpendicular;
223   } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE()) {
224     AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Plane::PLANE());
225
226     std::string aCreationMethodOption =
227         aBase->string(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
228     if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
229       AttributeDoublePtr anAttrDistance = aBase->real(ConstructionPlugin_Plane::DISTANCE());
230       AttributeBooleanPtr anAttrReverse = aBase->boolean(ConstructionPlugin_Plane::REVERSE());
231
232       theDumper << ", " << anAttrPlane << ", " << anAttrDistance << ", " << anAttrReverse;
233     } else if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
234       AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Plane::COINCIDENT_POINT());
235
236       theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
237     } else if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION()) {
238       AttributeSelectionPtr anAttrAxis = aBase->selection(ConstructionPlugin_Plane::AXIS());
239       AttributeDoublePtr anAttrAngle = aBase->real(ConstructionPlugin_Plane::ANGLE());
240
241       theDumper << ", " << anAttrPlane << ", " << anAttrAxis << ", " << anAttrAngle;
242     }
243   } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES()) {
244     AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Plane::PLANE1());
245     AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Plane::PLANE2());
246
247     theDumper << ", " << anAttrPlane1 << ", " << anAttrPlane2;
248   }
249
250   theDumper << ")" << std::endl;
251 }
252
253 //==================================================================================================
254 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
255                   const ModelHighAPI_Selection& theFace,
256                   const ModelHighAPI_Double& theDistance,
257                   const bool theIsReverse)
258 {
259   // TODO(spo): check that thePart is not empty
260   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
261   return PlanePtr(new ConstructionAPI_Plane(aFeature, theFace, theDistance, theIsReverse));
262 }
263
264 //==================================================================================================
265 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
266                   const ModelHighAPI_Double& theA,
267                   const ModelHighAPI_Double& theB,
268                   const ModelHighAPI_Double& theC,
269                   const ModelHighAPI_Double& theD)
270 {
271   // TODO(spo): check that thePart is not empty
272   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
273   return PlanePtr(new ConstructionAPI_Plane(aFeature, theA, theB, theC, theD));
274 }
275
276 //==================================================================================================
277 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
278                   const ModelHighAPI_Selection& thePoint1,
279                   const ModelHighAPI_Selection& thePoint2,
280                   const ModelHighAPI_Selection& thePoint3)
281 {
282   // TODO(spo): check that thePart is not empty
283   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
284   return PlanePtr(new ConstructionAPI_Plane(aFeature, thePoint1, thePoint2, thePoint3));
285 }
286
287 //==================================================================================================
288 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
289                   const ModelHighAPI_Selection& theLine,
290                   const ModelHighAPI_Selection& thePoint,
291                   const bool theIsPerpendicular)
292 {
293   // TODO(spo): check that thePart is not empty
294   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
295   return PlanePtr(new ConstructionAPI_Plane(aFeature, theLine, thePoint, theIsPerpendicular));
296 }
297
298 //==================================================================================================
299 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
300                   const ModelHighAPI_Selection& theObject1,
301                   const ModelHighAPI_Selection& theObject2)
302 {
303   // TODO(spo): check that thePart is not empty
304   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
305   return PlanePtr(new ConstructionAPI_Plane(aFeature, theObject1, theObject2));
306 }
307
308 //==================================================================================================
309 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
310                   const ModelHighAPI_Selection& thePlane,
311                   const ModelHighAPI_Selection& theAxis,
312                   const ModelHighAPI_Double& theAngle)
313 {
314   // TODO(spo): check that thePart is not empty
315   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
316   return PlanePtr(new ConstructionAPI_Plane(aFeature, thePlane, theAxis, theAngle));
317 }