Salome HOME
Issue #1860: fix end lines with spaces
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Axis.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
2
3 // Name   : ConstructionAPI_Axis.cpp
4 // Purpose:
5 //
6 // History:
7 // 15/06/16 - Sergey POKHODENKO - Creation of the file
8
9 #include "ConstructionAPI_Axis.h"
10
11 #include <ModelHighAPI_Dumper.h>
12 #include <ModelHighAPI_Tools.h>
13
14 //==================================================================================================
15 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature)
16 : ModelHighAPI_Interface(theFeature)
17 {
18   initialize();
19 }
20
21 //==================================================================================================
22 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
23                                            const ModelHighAPI_Selection& theObject1,
24                                            const ModelHighAPI_Selection& theObject2)
25 : ModelHighAPI_Interface(theFeature)
26 {
27   if(initialize()) {
28     GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
29     GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
30     if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::VERTEX) {
31       setByPoints(theObject1, theObject2);
32     } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) {
33       setByPlaneAndPoint(theObject1, theObject2);
34     } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) {
35       setByTwoPlanes(theObject1, theObject2);
36     }
37   }
38 }
39
40 //==================================================================================================
41 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
42                                            const ModelHighAPI_Selection& theObject)
43 : ModelHighAPI_Interface(theFeature)
44 {
45   if(initialize()) {
46     GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
47     if(aType == GeomAPI_Shape::EDGE) {
48       setByLine(theObject);
49     } else if(aType == GeomAPI_Shape::FACE) {
50       setByCylindricalFace(theObject);
51     }
52   }
53 }
54
55 //==================================================================================================
56 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
57                                            const ModelHighAPI_Selection& thePoint,
58                                            const ModelHighAPI_Double& theX,
59                                            const ModelHighAPI_Double& theY,
60                                            const ModelHighAPI_Double& theZ)
61 : ModelHighAPI_Interface(theFeature)
62 {
63   if(initialize()) {
64     setByPointAndDirection(thePoint, theX, theY, theZ);
65   }
66 }
67
68 //==================================================================================================
69 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
70                                            const ModelHighAPI_Double& theDX,
71                                            const ModelHighAPI_Double& theDY,
72                                            const ModelHighAPI_Double& theDZ)
73 : ModelHighAPI_Interface(theFeature)
74 {
75   if(initialize()) {
76     setByDimensions(theDX, theDY, theDZ);
77   }
78 }
79
80 //==================================================================================================
81 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
82                                            const ModelHighAPI_Selection& thePlane1,
83                                            const ModelHighAPI_Double& theOffset1,
84                                            const bool theReverseOffset1,
85                                            const ModelHighAPI_Selection& thePlane2,
86                                            const ModelHighAPI_Double& theOffset2,
87                                            const bool theReverseOffset2)
88 : ModelHighAPI_Interface(theFeature)
89 {
90   if(initialize()) {
91     setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1,
92                    thePlane2, theOffset2, theReverseOffset2);
93   }
94 }
95
96 //==================================================================================================
97 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
98                                            const ModelHighAPI_Selection& thePlane1,
99                                            const ModelHighAPI_Selection& thePlane2,
100                                            const ModelHighAPI_Double& theOffset2,
101                                            const bool theReverseOffset2)
102 : ModelHighAPI_Interface(theFeature)
103 {
104   if(initialize()) {
105     setByTwoPlanes(thePlane1, thePlane2, theOffset2, theReverseOffset2);
106   }
107 }
108
109 //==================================================================================================
110 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
111                                            const ModelHighAPI_Selection& thePlane1,
112                                            const ModelHighAPI_Double& theOffset1,
113                                            const bool theReverseOffset1,
114                                            const ModelHighAPI_Selection& thePlane2)
115 : ModelHighAPI_Interface(theFeature)
116 {
117   if(initialize()) {
118     setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1, thePlane2);
119   }
120 }
121
122 //==================================================================================================
123 ConstructionAPI_Axis::~ConstructionAPI_Axis()
124 {
125 }
126
127 //==================================================================================================
128 void ConstructionAPI_Axis::setByPoints(const ModelHighAPI_Selection& thePoint1,
129                                        const ModelHighAPI_Selection& thePoint2)
130 {
131   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
132   fillAttribute(thePoint1, firstPoint());
133   fillAttribute(thePoint2, secondPoint());
134
135   execute();
136 }
137
138 //==================================================================================================
139 void ConstructionAPI_Axis::setByCylindricalFace(const ModelHighAPI_Selection& theCylindricalFace)
140 {
141   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE(), creationMethod());
142   fillAttribute(theCylindricalFace, cylindricalFace());
143
144   execute();
145 }
146
147 //==================================================================================================
148 void ConstructionAPI_Axis::setByPointAndDirection(const ModelHighAPI_Selection& thePoint,
149                                                   const ModelHighAPI_Double& theX,
150                                                   const ModelHighAPI_Double& theY,
151                                                   const ModelHighAPI_Double& theZ)
152 {
153   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION(),
154                 creationMethod());
155   fillAttribute(thePoint, firstPoint());
156   fillAttribute(theX, xDirection());
157   fillAttribute(theY, yDirection());
158   fillAttribute(theZ, zDirection());
159
160   execute();
161 }
162
163 //==================================================================================================
164 void ConstructionAPI_Axis::setByDimensions(const ModelHighAPI_Double& theDX,
165                                            const ModelHighAPI_Double& theDY,
166                                            const ModelHighAPI_Double& theDZ)
167 {
168   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
169   fillAttribute(theDX, xDimension());
170   fillAttribute(theDY, yDimension());
171   fillAttribute(theDZ, zDimension());
172
173   execute();
174 }
175
176 //==================================================================================================
177 void ConstructionAPI_Axis::setByLine(const ModelHighAPI_Selection& theLine)
178 {
179   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE(), creationMethod());
180   fillAttribute(theLine, line());
181
182   execute();
183 }
184
185 //==================================================================================================
186 void ConstructionAPI_Axis::setByPlaneAndPoint(const ModelHighAPI_Selection& thePlane,
187                                               const ModelHighAPI_Selection& thePoint)
188 {
189   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT(), creationMethod());
190   fillAttribute(thePlane, plane());
191   fillAttribute(thePoint, point());
192
193   execute();
194 }
195
196 //==================================================================================================
197 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
198                                           const ModelHighAPI_Selection& thePlane2)
199 {
200   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
201   fillAttribute(thePlane1, plane1());
202   fillAttribute("", useOffset1());
203   fillAttribute(thePlane2, plane2());
204   fillAttribute("", useOffset2());
205
206   execute();
207 }
208
209 //==================================================================================================
210 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
211                                           const ModelHighAPI_Double& theOffset1,
212                                           const bool theReverseOffset1,
213                                           const ModelHighAPI_Selection& thePlane2,
214                                           const ModelHighAPI_Double& theOffset2,
215                                           const bool theReverseOffset2)
216 {
217   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
218   fillAttribute(thePlane1, plane1());
219   fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1());
220   fillAttribute(theOffset1, offset1());
221   fillAttribute(theReverseOffset1, reverseOffset1());
222   fillAttribute(thePlane2, plane2());
223   fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2());
224   fillAttribute(theOffset2, offset2());
225   fillAttribute(theReverseOffset2, reverseOffset2());
226
227   execute();
228 }
229
230 //==================================================================================================
231 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
232                                           const ModelHighAPI_Selection& thePlane2,
233                                           const ModelHighAPI_Double& theOffset2,
234                                           const bool theReverseOffset2)
235 {
236   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
237   fillAttribute(thePlane1, plane1());
238   fillAttribute("", useOffset1());
239   fillAttribute(thePlane2, plane2());
240   fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2());
241   fillAttribute(theOffset2, offset2());
242   fillAttribute(theReverseOffset2, reverseOffset2());
243
244   execute();
245 }
246
247 //==================================================================================================
248 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
249                                           const ModelHighAPI_Double& theOffset1,
250                                           const bool theReverseOffset1,
251                                           const ModelHighAPI_Selection& thePlane2)
252 {
253   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
254   fillAttribute(thePlane1, plane1());
255   fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1());
256   fillAttribute(theOffset1, offset1());
257   fillAttribute(theReverseOffset1, reverseOffset1());
258   fillAttribute(thePlane2, plane2());
259   fillAttribute("", useOffset2());
260
261   execute();
262 }
263
264 //==================================================================================================
265 void ConstructionAPI_Axis::dump(ModelHighAPI_Dumper& theDumper) const
266 {
267   FeaturePtr aBase = feature();
268   const std::string& aDocName = theDumper.name(aBase->document());
269
270   theDumper << aBase << " = model.addAxis(" << aDocName;
271
272   std::string aCreationMethod = aBase->string(ConstructionPlugin_Axis::METHOD())->value();
273
274   if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS()) {
275     AttributeDoublePtr anAttrDX = aBase->real(ConstructionPlugin_Axis::DX());
276     AttributeDoublePtr anAttrDY = aBase->real(ConstructionPlugin_Axis::DY());
277     AttributeDoublePtr anAttrDZ = aBase->real(ConstructionPlugin_Axis::DZ());
278
279     theDumper << ", " << anAttrDX << ", " << anAttrDY << ", " << anAttrDZ;
280   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS()) {
281     AttributeSelectionPtr anAttrFirstPnt =
282       aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
283     AttributeSelectionPtr anAttrSecondPnt =
284       aBase->selection(ConstructionPlugin_Axis::POINT_SECOND());
285
286     theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
287   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE()) {
288     AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Axis::LINE());
289
290     theDumper << ", " << anAttrLine;
291   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE()) {
292     AttributeSelectionPtr anAttrFace =
293       aBase->selection(ConstructionPlugin_Axis::CYLINDRICAL_FACE());
294
295     theDumper << ", " << anAttrFace;
296   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT()) {
297     AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Axis::PLANE());
298     AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Axis::POINT());
299
300     theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
301   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES()) {
302     AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Axis::PLANE1());
303     AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Axis::PLANE2());
304
305     theDumper << ", " << anAttrPlane1;
306     if(aBase->string(ConstructionPlugin_Axis::USE_OFFSET1())->isInitialized()
307       && !aBase->string(ConstructionPlugin_Axis::USE_OFFSET1())->value().empty()) {
308       AttributeDoublePtr anAttrOffset1 = aBase->real(ConstructionPlugin_Axis::OFFSET1());
309       AttributeBooleanPtr anAttrReverseOffset1 =
310         aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET1());
311       theDumper << ", " << anAttrOffset1 << ", " << anAttrReverseOffset1;
312     }
313
314     theDumper << ", " << anAttrPlane2;
315     if(aBase->string(ConstructionPlugin_Axis::USE_OFFSET2())->isInitialized()
316       && !aBase->string(ConstructionPlugin_Axis::USE_OFFSET2())->value().empty()) {
317       AttributeDoublePtr anAttrOffset2 = aBase->real(ConstructionPlugin_Axis::OFFSET2());
318       AttributeBooleanPtr anAttrReverseOffset2 =
319         aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET2());
320       theDumper << ", " << anAttrOffset2 << ", " << anAttrReverseOffset2;
321     }
322   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION()) {
323     AttributeSelectionPtr anAttrFirstPnt = aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
324     AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Axis::X_DIRECTION());
325     AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Axis::Y_DIRECTION());
326     AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Axis::Z_DIRECTION());
327
328     theDumper << ", " << anAttrFirstPnt << ", " << anAttrX << ", " << anAttrY << ", " << anAttrZ;
329   }
330
331   theDumper << ")" << std::endl;
332 }
333
334 //==================================================================================================
335 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
336                 const ModelHighAPI_Selection& theObject1,
337                 const ModelHighAPI_Selection& theObject2)
338 {
339   // TODO(spo): check that thePart is not empty
340   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
341   return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject1, theObject2));
342 }
343
344 //==================================================================================================
345 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
346                 const ModelHighAPI_Selection& theObject)
347 {
348   // TODO(spo): check that thePart is not empty
349   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
350   return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject));
351 }
352
353 //==================================================================================================
354 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
355                 const ModelHighAPI_Selection& thePoint,
356                 const ModelHighAPI_Double& theX,
357                 const ModelHighAPI_Double& theY,
358                 const ModelHighAPI_Double& theZ)
359 {
360   // TODO(spo): check that thePart is not empty
361   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
362   return AxisPtr(new ConstructionAPI_Axis(aFeature, thePoint, theX, theY, theZ));
363 }
364
365 //==================================================================================================
366 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
367                 const ModelHighAPI_Double& theDX,
368                 const ModelHighAPI_Double& theDY,
369                 const ModelHighAPI_Double& theDZ)
370 {
371   // TODO(spo): check that thePart is not empty
372   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
373   return AxisPtr(new ConstructionAPI_Axis(aFeature, theDX, theDY, theDZ));
374 }
375
376 //==================================================================================================
377 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
378                 const ModelHighAPI_Selection& thePlane1,
379                 const ModelHighAPI_Double& theOffset1,
380                 const bool theReverseOffset1,
381                 const ModelHighAPI_Selection& thePlane2,
382                 const ModelHighAPI_Double& theOffset2,
383                 const bool theReverseOffset2)
384 {
385   // TODO(spo): check that thePart is not empty
386   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
387   return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1,
388                                                     thePlane2, theOffset2, theReverseOffset2));
389 }
390
391 //==================================================================================================
392 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
393                 const ModelHighAPI_Selection& thePlane1,
394                 const ModelHighAPI_Selection& thePlane2,
395                 const ModelHighAPI_Double& theOffset2,
396                 const bool theReverseOffset2)
397 {
398   // TODO(spo): check that thePart is not empty
399   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
400   return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1,
401                                                     thePlane2, theOffset2, theReverseOffset2));
402 }
403
404 //==================================================================================================
405 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
406                 const ModelHighAPI_Selection& thePlane1,
407                 const ModelHighAPI_Double& theOffset1,
408                 const bool theReverseOffset1,
409                 const ModelHighAPI_Selection& thePlane2)
410 {
411   // TODO(spo): check that thePart is not empty
412   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
413   return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1,
414                                                     thePlane2));
415 }