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