1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
3 // Name : ConstructionAPI_Axis.cpp
7 // 15/06/16 - Sergey POKHODENKO - Creation of the file
9 #include "ConstructionAPI_Axis.h"
11 #include <ModelHighAPI_Dumper.h>
12 #include <ModelHighAPI_Tools.h>
14 //==================================================================================================
15 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature)
16 : ModelHighAPI_Interface(theFeature)
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)
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);
40 //==================================================================================================
41 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
42 const ModelHighAPI_Selection& theObject)
43 : ModelHighAPI_Interface(theFeature)
46 GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
47 if(aType == GeomAPI_Shape::EDGE) {
49 } else if(aType == GeomAPI_Shape::FACE) {
50 setByCylindricalFace(theObject);
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)
64 setByPointAndDirection(thePoint, theX, theY, theZ);
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)
76 setByDimensions(theDX, theDY, theDZ);
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)
91 setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1,
92 thePlane2, theOffset2, theReverseOffset2);
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)
105 setByTwoPlanes(thePlane1, thePlane2, theOffset2, theReverseOffset2);
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)
118 setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1, thePlane2);
122 //==================================================================================================
123 ConstructionAPI_Axis::~ConstructionAPI_Axis()
127 //==================================================================================================
128 void ConstructionAPI_Axis::setByPoints(const ModelHighAPI_Selection& thePoint1,
129 const ModelHighAPI_Selection& thePoint2)
131 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
132 fillAttribute(thePoint1, firstPoint());
133 fillAttribute(thePoint2, secondPoint());
138 //==================================================================================================
139 void ConstructionAPI_Axis::setByCylindricalFace(const ModelHighAPI_Selection& theCylindricalFace)
141 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE(), creationMethod());
142 fillAttribute(theCylindricalFace, cylindricalFace());
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)
153 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION(),
155 fillAttribute(thePoint, firstPoint());
156 fillAttribute(theX, xDirection());
157 fillAttribute(theY, yDirection());
158 fillAttribute(theZ, zDirection());
163 //==================================================================================================
164 void ConstructionAPI_Axis::setByDimensions(const ModelHighAPI_Double& theDX,
165 const ModelHighAPI_Double& theDY,
166 const ModelHighAPI_Double& theDZ)
168 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
169 fillAttribute(theDX, xDimension());
170 fillAttribute(theDY, yDimension());
171 fillAttribute(theDZ, zDimension());
176 //==================================================================================================
177 void ConstructionAPI_Axis::setByLine(const ModelHighAPI_Selection& theLine)
179 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE(), creationMethod());
180 fillAttribute(theLine, line());
185 //==================================================================================================
186 void ConstructionAPI_Axis::setByPlaneAndPoint(const ModelHighAPI_Selection& thePlane,
187 const ModelHighAPI_Selection& thePoint)
189 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT(), creationMethod());
190 fillAttribute(thePlane, plane());
191 fillAttribute(thePoint, point());
196 //==================================================================================================
197 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
198 const ModelHighAPI_Selection& thePlane2)
200 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
201 fillAttribute(thePlane1, plane1());
202 fillAttribute("", useOffset1());
203 fillAttribute(thePlane2, plane2());
204 fillAttribute("", useOffset2());
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)
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());
230 //==================================================================================================
231 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
232 const ModelHighAPI_Selection& thePlane2,
233 const ModelHighAPI_Double& theOffset2,
234 const bool theReverseOffset2)
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());
247 //==================================================================================================
248 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
249 const ModelHighAPI_Double& theOffset1,
250 const bool theReverseOffset1,
251 const ModelHighAPI_Selection& thePlane2)
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());
264 //==================================================================================================
265 void ConstructionAPI_Axis::dump(ModelHighAPI_Dumper& theDumper) const
267 FeaturePtr aBase = feature();
268 const std::string& aDocName = theDumper.name(aBase->document());
270 theDumper << aBase << " = model.addAxis(" << aDocName;
272 std::string aCreationMethod = aBase->string(ConstructionPlugin_Axis::METHOD())->value();
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());
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());
286 theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
287 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE()) {
288 AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Axis::LINE());
290 theDumper << ", " << anAttrLine;
291 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE()) {
292 AttributeSelectionPtr anAttrFace =
293 aBase->selection(ConstructionPlugin_Axis::CYLINDRICAL_FACE());
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());
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());
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;
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;
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());
328 theDumper << ", " << anAttrFirstPnt << ", " << anAttrX << ", " << anAttrY << ", " << anAttrZ;
331 theDumper << ")" << std::endl;
334 //==================================================================================================
335 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
336 const ModelHighAPI_Selection& theObject1,
337 const ModelHighAPI_Selection& theObject2)
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));
344 //==================================================================================================
345 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
346 const ModelHighAPI_Selection& theObject)
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));
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)
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));
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)
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));
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)
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));
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)
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));
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)
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,