1 // Name : ConstructionAPI_Axis.cpp
5 // 15/06/16 - Sergey POKHODENKO - Creation of the file
7 #include "ConstructionAPI_Axis.h"
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
12 //==================================================================================================
13 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
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)
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);
38 //==================================================================================================
39 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
40 const ModelHighAPI_Selection& theObject)
41 : ModelHighAPI_Interface(theFeature)
44 GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
45 if(aType == GeomAPI_Shape::EDGE) {
47 } else if(aType == GeomAPI_Shape::FACE) {
48 setByCylindricalFace(theObject);
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)
62 setByPointAndDirection(thePoint, theX, theY, theZ);
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)
74 setByDimensions(theDX, theDY, theDZ);
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)
89 setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1, thePlane2, theOffset2, theReverseOffset2);
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)
102 setByTwoPlanes(thePlane1, thePlane2, theOffset2, theReverseOffset2);
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)
115 setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1, thePlane2);
119 //==================================================================================================
120 ConstructionAPI_Axis::~ConstructionAPI_Axis()
124 //==================================================================================================
125 void ConstructionAPI_Axis::setByPoints(const ModelHighAPI_Selection& thePoint1,
126 const ModelHighAPI_Selection& thePoint2)
128 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
129 fillAttribute(thePoint1, firstPoint());
130 fillAttribute(thePoint2, secondPoint());
135 //==================================================================================================
136 void ConstructionAPI_Axis::setByCylindricalFace(const ModelHighAPI_Selection& theCylindricalFace)
138 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE(), creationMethod());
139 fillAttribute(theCylindricalFace, cylindricalFace());
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)
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());
159 //==================================================================================================
160 void ConstructionAPI_Axis::setByDimensions(const ModelHighAPI_Double& theDX,
161 const ModelHighAPI_Double& theDY,
162 const ModelHighAPI_Double& theDZ)
164 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
165 fillAttribute(theDX, xDimension());
166 fillAttribute(theDY, yDimension());
167 fillAttribute(theDZ, zDimension());
172 //==================================================================================================
173 void ConstructionAPI_Axis::setByLine(const ModelHighAPI_Selection& theLine)
175 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE(), creationMethod());
176 fillAttribute(theLine, line());
181 //==================================================================================================
182 void ConstructionAPI_Axis::setByPlaneAndPoint(const ModelHighAPI_Selection& thePlane,
183 const ModelHighAPI_Selection& thePoint)
185 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT(), creationMethod());
186 fillAttribute(thePlane, plane());
187 fillAttribute(thePoint, point());
192 //==================================================================================================
193 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
194 const ModelHighAPI_Selection& thePlane2)
196 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
197 fillAttribute(thePlane1, plane1());
198 fillAttribute("", useOffset1());
199 fillAttribute(thePlane2, plane2());
200 fillAttribute("", useOffset2());
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)
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());
226 //==================================================================================================
227 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
228 const ModelHighAPI_Selection& thePlane2,
229 const ModelHighAPI_Double& theOffset2,
230 const bool theReverseOffset2)
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());
243 //==================================================================================================
244 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
245 const ModelHighAPI_Double& theOffset1,
246 const bool theReverseOffset1,
247 const ModelHighAPI_Selection& thePlane2)
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());
260 //==================================================================================================
261 void ConstructionAPI_Axis::dump(ModelHighAPI_Dumper& theDumper) const
263 FeaturePtr aBase = feature();
264 const std::string& aDocName = theDumper.name(aBase->document());
266 theDumper << aBase << " = model.addAxis(" << aDocName;
268 std::string aCreationMethod = aBase->string(ConstructionPlugin_Axis::METHOD())->value();
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());
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());
280 theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
281 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE()) {
282 AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Axis::LINE());
284 theDumper << ", " << anAttrLine;
285 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE()) {
286 AttributeSelectionPtr anAttrFace = aBase->selection(ConstructionPlugin_Axis::CYLINDRICAL_FACE());
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());
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());
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;
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;
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());
319 theDumper << ", " << anAttrFirstPnt << ", " << anAttrX << ", " << anAttrY << ", " << anAttrZ;
322 theDumper << ")" << std::endl;
325 //==================================================================================================
326 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
327 const ModelHighAPI_Selection& theObject1,
328 const ModelHighAPI_Selection& theObject2)
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));
335 //==================================================================================================
336 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
337 const ModelHighAPI_Selection& theObject)
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));
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)
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));
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)
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));
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)
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));
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)
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));
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)
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,