Salome HOME
Merge remote-tracking branch 'remotes/origin/HighLevelDump'
[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()
95 {
96 }
97
98 //==================================================================================================
99 void ConstructionAPI_Axis::setByPoints(const ModelHighAPI_Selection& thePoint1,
100                                        const ModelHighAPI_Selection& thePoint2)
101 {
102   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
103   fillAttribute(thePoint1, firstPoint());
104   fillAttribute(thePoint2, secondPoint());
105
106   execute();
107 }
108
109 //==================================================================================================
110 void ConstructionAPI_Axis::setByCylindricalFace(const ModelHighAPI_Selection& theCylindricalFace)
111 {
112   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE(), creationMethod());
113   fillAttribute(theCylindricalFace, cylindricalFace());
114
115   execute();
116 }
117
118 //==================================================================================================
119 void ConstructionAPI_Axis::setByPointAndDirection(const ModelHighAPI_Selection& thePoint,
120                                                   const ModelHighAPI_Double& theX,
121                                                   const ModelHighAPI_Double& theY,
122                                                   const ModelHighAPI_Double& theZ)
123 {
124   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION(), creationMethod());
125   fillAttribute(thePoint, firstPoint());
126   fillAttribute(theX, xDirection());
127   fillAttribute(theY, yDirection());
128   fillAttribute(theZ, zDirection());
129
130   execute();
131 }
132
133 //==================================================================================================
134 void ConstructionAPI_Axis::setByDimensions(const ModelHighAPI_Double& theDX,
135                                            const ModelHighAPI_Double& theDY,
136                                            const ModelHighAPI_Double& theDZ)
137 {
138   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
139   fillAttribute(theDX, xDimension());
140   fillAttribute(theDY, yDimension());
141   fillAttribute(theDZ, zDimension());
142
143   execute();
144 }
145
146 //==================================================================================================
147 void ConstructionAPI_Axis::setByLine(const ModelHighAPI_Selection& theLine)
148 {
149   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE(), creationMethod());
150   fillAttribute(theLine, line());
151
152   execute();
153 }
154
155 //==================================================================================================
156 void ConstructionAPI_Axis::setByPlaneAndPoint(const ModelHighAPI_Selection& thePlane,
157                                               const ModelHighAPI_Selection& thePoint)
158 {
159   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT(), creationMethod());
160   fillAttribute(thePlane, plane());
161   fillAttribute(thePoint, point());
162
163   execute();
164 }
165
166 //==================================================================================================
167 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
168                                           const ModelHighAPI_Selection& thePlane2)
169 {
170   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
171   fillAttribute(thePlane1, plane1());
172   fillAttribute("", useOffset1());
173   fillAttribute(thePlane2, plane2());
174   fillAttribute("", useOffset2());
175
176   execute();
177 }
178
179 //==================================================================================================
180 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
181                                           const ModelHighAPI_Double& theOffset1,
182                                           const bool theReverseOffset1,
183                                           const ModelHighAPI_Selection& thePlane2,
184                                           const ModelHighAPI_Double& theOffset2,
185                                           const bool theReverseOffset2)
186 {
187   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
188   fillAttribute(thePlane1, plane1());
189   fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1());
190   fillAttribute(theOffset1, offset1());
191   fillAttribute(theReverseOffset1, reverseOffset1());
192   fillAttribute(thePlane2, plane2());
193   fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2());
194   fillAttribute(theOffset2, offset2());
195   fillAttribute(theReverseOffset2, reverseOffset2());
196
197   execute();
198 }
199
200 //==================================================================================================
201 void ConstructionAPI_Axis::dump(ModelHighAPI_Dumper& theDumper) const
202 {
203   FeaturePtr aBase = feature();
204   const std::string& aDocName = theDumper.name(aBase->document());
205
206   theDumper << aBase << " = model.addAxis(" << aDocName;
207
208   std::string aCreationMethod = aBase->string(ConstructionPlugin_Axis::METHOD())->value();
209
210   if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS()) {
211     AttributeDoublePtr anAttrDX = aBase->real(ConstructionPlugin_Axis::DX());
212     AttributeDoublePtr anAttrDY = aBase->real(ConstructionPlugin_Axis::DY());
213     AttributeDoublePtr anAttrDZ = aBase->real(ConstructionPlugin_Axis::DZ());
214
215     theDumper << ", " << anAttrDX << ", " << anAttrDY << ", " << anAttrDZ;
216   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS()) {
217     AttributeSelectionPtr anAttrFirstPnt = aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
218     AttributeSelectionPtr anAttrSecondPnt = aBase->selection(ConstructionPlugin_Axis::POINT_SECOND());
219
220     theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
221   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE()) {
222     AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Axis::LINE());
223
224     theDumper << ", " << anAttrLine;
225   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE()) {
226     AttributeSelectionPtr anAttrFace = aBase->selection(ConstructionPlugin_Axis::CYLINDRICAL_FACE());
227
228     theDumper << ", " << anAttrFace;
229   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT()) {
230     AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Axis::PLANE());
231     AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Axis::POINT());
232
233     theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
234   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES()) {
235     AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Axis::PLANE1());
236     AttributeDoublePtr anAttrOffset1 = aBase->real(ConstructionPlugin_Axis::OFFSET1());
237     AttributeBooleanPtr anAttrReverseOffset1 = aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET1());
238     AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Axis::PLANE2());
239     AttributeDoublePtr anAttrOffset2 = aBase->real(ConstructionPlugin_Axis::OFFSET2());
240     AttributeBooleanPtr anAttrReverseOffset2 = aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET2());
241
242     theDumper << ", " << anAttrPlane1 << ", " << anAttrOffset1 << ", " << anAttrReverseOffset1
243               << ", " << anAttrPlane2 << ", " << anAttrOffset2 << ", " << anAttrReverseOffset2;
244   } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION()) {
245     AttributeSelectionPtr anAttrFirstPnt = aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
246     AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Axis::X_DIRECTION());
247     AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Axis::Y_DIRECTION());
248     AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Axis::Z_DIRECTION());
249
250     theDumper << ", " << anAttrFirstPnt << ", " << anAttrX << ", " << anAttrY << ", " << anAttrZ;
251   }
252
253   theDumper << ")" << std::endl;
254 }
255
256 //==================================================================================================
257 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
258                 const ModelHighAPI_Selection& theObject1,
259                 const ModelHighAPI_Selection& theObject2)
260 {
261   // TODO(spo): check that thePart is not empty
262   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
263   return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject1, theObject2));
264 }
265
266 //==================================================================================================
267 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
268                 const ModelHighAPI_Selection& theObject)
269 {
270   // TODO(spo): check that thePart is not empty
271   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
272   return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject));
273 }
274
275 //==================================================================================================
276 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
277                 const ModelHighAPI_Selection& thePoint,
278                 const ModelHighAPI_Double& theX,
279                 const ModelHighAPI_Double& theY,
280                 const ModelHighAPI_Double& theZ)
281 {
282   // TODO(spo): check that thePart is not empty
283   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
284   return AxisPtr(new ConstructionAPI_Axis(aFeature, thePoint, theX, theY, theZ));
285 }
286
287 //==================================================================================================
288 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
289                 const ModelHighAPI_Double& theDX,
290                 const ModelHighAPI_Double& theDY,
291                 const ModelHighAPI_Double& theDZ)
292 {
293   // TODO(spo): check that thePart is not empty
294   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
295   return AxisPtr(new ConstructionAPI_Axis(aFeature, theDX, theDY, theDZ));
296 }
297
298 //==================================================================================================
299 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
300                 const ModelHighAPI_Selection& thePlane1,
301                 const ModelHighAPI_Double& theOffset1,
302                 const bool theReverseOffset1,
303                 const ModelHighAPI_Selection& thePlane2,
304                 const ModelHighAPI_Double& theOffset2,
305                 const bool theReverseOffset2)
306 {
307   // TODO(spo): check that thePart is not empty
308   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
309   return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1,
310                                                     thePlane2, theOffset2, theReverseOffset2));
311 }