Salome HOME
132adba5124a93bf623cbb65a9f05b0913d46054
[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_Tools.h>
10
11 //==================================================================================================
12 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature)
13 : ModelHighAPI_Interface(theFeature)
14 {
15   initialize();
16 }
17
18 //==================================================================================================
19 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
20                                            const ModelHighAPI_Selection& theObject1,
21                                            const ModelHighAPI_Selection& theObject2)
22 : ModelHighAPI_Interface(theFeature)
23 {
24   if(initialize()) {
25     GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
26     GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
27     if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::VERTEX) {
28       setByPoints(theObject1, theObject2);
29     } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) {
30       setByPlaneAndPoint(theObject1, theObject2);
31     } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) {
32       setByTwoPlanes(theObject1, theObject2);
33     }
34   }
35 }
36
37 //==================================================================================================
38 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
39                                            const ModelHighAPI_Selection& theObject)
40 : ModelHighAPI_Interface(theFeature)
41 {
42   if(initialize()) {
43     GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
44     if(aType == GeomAPI_Shape::EDGE) {
45       setByLine(theObject);
46     } else if(aType == GeomAPI_Shape::FACE) {
47       setByCylindricalFace(theObject);
48     }
49   }
50 }
51
52 //==================================================================================================
53 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
54                                            const ModelHighAPI_Selection& thePoint,
55                                            const ModelHighAPI_Double& theX,
56                                            const ModelHighAPI_Double& theY,
57                                            const ModelHighAPI_Double& theZ)
58 : ModelHighAPI_Interface(theFeature)
59 {
60   if(initialize()) {
61     setByPointAndDirection(thePoint, theX, theY, theZ);
62   }
63 }
64
65 //==================================================================================================
66 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
67                                            const ModelHighAPI_Double& theDX,
68                                            const ModelHighAPI_Double& theDY,
69                                            const ModelHighAPI_Double& theDZ)
70 : ModelHighAPI_Interface(theFeature)
71 {
72   if(initialize()) {
73     setByDimensions(theDX, theDY, theDZ);
74   }
75 }
76
77 //==================================================================================================
78 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
79                                            const ModelHighAPI_Selection& thePlane1,
80                                            const ModelHighAPI_Double& theOffset1,
81                                            const bool theReverseOffset1,
82                                            const ModelHighAPI_Selection& thePlane2,
83                                            const ModelHighAPI_Double& theOffset2,
84                                            const bool theReverseOffset2)
85 : ModelHighAPI_Interface(theFeature)
86 {
87   if(initialize()) {
88     setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1, thePlane2, theOffset2, theReverseOffset2);
89   }
90 }
91
92 //==================================================================================================
93 ConstructionAPI_Axis::~ConstructionAPI_Axis()
94 {
95 }
96
97 //==================================================================================================
98 void ConstructionAPI_Axis::setByPoints(const ModelHighAPI_Selection& thePoint1,
99                                        const ModelHighAPI_Selection& thePoint2)
100 {
101   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
102   fillAttribute(thePoint1, firstPoint());
103   fillAttribute(thePoint2, secondPoint());
104
105   execute();
106 }
107
108 //==================================================================================================
109 void ConstructionAPI_Axis::setByCylindricalFace(const ModelHighAPI_Selection& theCylindricalFace)
110 {
111   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE(), creationMethod());
112   fillAttribute(theCylindricalFace, cylindricalFace());
113
114   execute();
115 }
116
117 //==================================================================================================
118 void ConstructionAPI_Axis::setByPointAndDirection(const ModelHighAPI_Selection& thePoint,
119                                                   const ModelHighAPI_Double& theX,
120                                                   const ModelHighAPI_Double& theY,
121                                                   const ModelHighAPI_Double& theZ)
122 {
123   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION(), creationMethod());
124   fillAttribute(thePoint, firstPoint());
125   fillAttribute(theX, xDirection());
126   fillAttribute(theY, yDirection());
127   fillAttribute(theZ, zDirection());
128
129   execute();
130 }
131
132 //==================================================================================================
133 void ConstructionAPI_Axis::setByDimensions(const ModelHighAPI_Double& theDX,
134                                            const ModelHighAPI_Double& theDY,
135                                            const ModelHighAPI_Double& theDZ)
136 {
137   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
138   fillAttribute(theDX, xDimension());
139   fillAttribute(theDY, yDimension());
140   fillAttribute(theDZ, zDimension());
141
142   execute();
143 }
144
145 //==================================================================================================
146 void ConstructionAPI_Axis::setByLine(const ModelHighAPI_Selection& theLine)
147 {
148   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE(), creationMethod());
149   fillAttribute(theLine, line());
150
151   execute();
152 }
153
154 //==================================================================================================
155 void ConstructionAPI_Axis::setByPlaneAndPoint(const ModelHighAPI_Selection& thePlane,
156                                               const ModelHighAPI_Selection& thePoint)
157 {
158   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT(), creationMethod());
159   fillAttribute(thePlane, plane());
160   fillAttribute(thePoint, point());
161
162   execute();
163 }
164
165 //==================================================================================================
166 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
167                                           const ModelHighAPI_Selection& thePlane2)
168 {
169   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
170   fillAttribute(thePlane1, plane1());
171   fillAttribute("", useOffset1());
172   fillAttribute(thePlane2, plane2());
173   fillAttribute("", useOffset2());
174
175   execute();
176 }
177
178 //==================================================================================================
179 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
180                                           const ModelHighAPI_Double& theOffset1,
181                                           const bool theReverseOffset1,
182                                           const ModelHighAPI_Selection& thePlane2,
183                                           const ModelHighAPI_Double& theOffset2,
184                                           const bool theReverseOffset2)
185 {
186   fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
187   fillAttribute(thePlane1, plane1());
188   fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1());
189   fillAttribute(theOffset1, offset1());
190   fillAttribute(theReverseOffset1, reverseOffset1());
191   fillAttribute(thePlane2, plane2());
192   fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2());
193   fillAttribute(theOffset2, offset2());
194   fillAttribute(theReverseOffset2, reverseOffset2());
195
196   execute();
197 }
198
199 //==================================================================================================
200 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
201                 const ModelHighAPI_Selection& thePoint1,
202                 const ModelHighAPI_Selection& thePoint2)
203 {
204   // TODO(spo): check that thePart is not empty
205   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
206   return AxisPtr(new ConstructionAPI_Axis(aFeature, thePoint1, thePoint2));
207 }
208
209 //==================================================================================================
210 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
211                 const ModelHighAPI_Selection& theObject)
212 {
213   // TODO(spo): check that thePart is not empty
214   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
215   return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject));
216 }
217
218 //==================================================================================================
219 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
220                 const ModelHighAPI_Selection& thePoint,
221                 const ModelHighAPI_Double& theX,
222                 const ModelHighAPI_Double& theY,
223                 const ModelHighAPI_Double& theZ)
224 {
225   // TODO(spo): check that thePart is not empty
226   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
227   return AxisPtr(new ConstructionAPI_Axis(aFeature, thePoint, theX, theY, theZ));
228 }
229
230 //==================================================================================================
231 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
232                 const ModelHighAPI_Double& theDX,
233                 const ModelHighAPI_Double& theDY,
234                 const ModelHighAPI_Double& theDZ)
235 {
236   // TODO(spo): check that thePart is not empty
237   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
238   return AxisPtr(new ConstructionAPI_Axis(aFeature, theDX, theDY, theDZ));
239 }
240
241 //==================================================================================================
242 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
243                 const ModelHighAPI_Selection& thePlane1,
244                 const ModelHighAPI_Double& theOffset1,
245                 const bool theReverseOffset1,
246                 const ModelHighAPI_Selection& thePlane2,
247                 const ModelHighAPI_Double& theOffset2,
248                 const bool theReverseOffset2)
249 {
250   // TODO(spo): check that thePart is not empty
251   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
252   return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1,
253                                                     thePlane2, theOffset2, theReverseOffset2));
254 }