1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "ConstructionAPI_Axis.h"
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 //==================================================================================================
27 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
33 //==================================================================================================
34 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35 const ModelHighAPI_Selection& theObject1,
36 const ModelHighAPI_Selection& theObject2)
37 : ModelHighAPI_Interface(theFeature)
40 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
41 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
42 if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::VERTEX) {
43 setByPoints(theObject1, theObject2);
44 } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) {
45 setByPlaneAndPoint(theObject1, theObject2);
46 } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) {
47 setByTwoPlanes(theObject1, theObject2);
52 //==================================================================================================
53 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
54 const ModelHighAPI_Selection& theObject)
55 : ModelHighAPI_Interface(theFeature)
58 GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
59 if(aType == GeomAPI_Shape::EDGE) {
61 } else if(aType == GeomAPI_Shape::FACE) {
62 setByCylindricalFace(theObject);
67 //==================================================================================================
68 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
69 const ModelHighAPI_Selection& thePoint,
70 const ModelHighAPI_Double& theX,
71 const ModelHighAPI_Double& theY,
72 const ModelHighAPI_Double& theZ)
73 : ModelHighAPI_Interface(theFeature)
76 setByPointAndDirection(thePoint, theX, theY, theZ);
80 //==================================================================================================
81 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
82 const ModelHighAPI_Double& theDX,
83 const ModelHighAPI_Double& theDY,
84 const ModelHighAPI_Double& theDZ)
85 : ModelHighAPI_Interface(theFeature)
88 setByDimensions(theDX, theDY, theDZ);
92 //==================================================================================================
93 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
94 const ModelHighAPI_Selection& thePlane1,
95 const ModelHighAPI_Double& theOffset1,
96 const bool theReverseOffset1,
97 const ModelHighAPI_Selection& thePlane2,
98 const ModelHighAPI_Double& theOffset2,
99 const bool theReverseOffset2)
100 : ModelHighAPI_Interface(theFeature)
103 setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1,
104 thePlane2, theOffset2, theReverseOffset2);
108 //==================================================================================================
109 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
110 const ModelHighAPI_Selection& thePlane1,
111 const ModelHighAPI_Selection& thePlane2,
112 const ModelHighAPI_Double& theOffset2,
113 const bool theReverseOffset2)
114 : ModelHighAPI_Interface(theFeature)
117 setByTwoPlanes(thePlane1, thePlane2, theOffset2, theReverseOffset2);
121 //==================================================================================================
122 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
123 const ModelHighAPI_Selection& thePlane1,
124 const ModelHighAPI_Double& theOffset1,
125 const bool theReverseOffset1,
126 const ModelHighAPI_Selection& thePlane2)
127 : ModelHighAPI_Interface(theFeature)
130 setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1, thePlane2);
134 //==================================================================================================
135 ConstructionAPI_Axis::~ConstructionAPI_Axis()
139 //==================================================================================================
140 void ConstructionAPI_Axis::setByPoints(const ModelHighAPI_Selection& thePoint1,
141 const ModelHighAPI_Selection& thePoint2)
143 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
144 fillAttribute(thePoint1, firstPoint());
145 fillAttribute(thePoint2, secondPoint());
150 //==================================================================================================
151 void ConstructionAPI_Axis::setByCylindricalFace(const ModelHighAPI_Selection& theCylindricalFace)
153 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE(), creationMethod());
154 fillAttribute(theCylindricalFace, cylindricalFace());
159 //==================================================================================================
160 void ConstructionAPI_Axis::setByPointAndDirection(const ModelHighAPI_Selection& thePoint,
161 const ModelHighAPI_Double& theX,
162 const ModelHighAPI_Double& theY,
163 const ModelHighAPI_Double& theZ)
165 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION(),
167 fillAttribute(thePoint, firstPoint());
168 fillAttribute(theX, xDirection());
169 fillAttribute(theY, yDirection());
170 fillAttribute(theZ, zDirection());
175 //==================================================================================================
176 void ConstructionAPI_Axis::setByDimensions(const ModelHighAPI_Double& theDX,
177 const ModelHighAPI_Double& theDY,
178 const ModelHighAPI_Double& theDZ)
180 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
181 fillAttribute(theDX, xDimension());
182 fillAttribute(theDY, yDimension());
183 fillAttribute(theDZ, zDimension());
188 //==================================================================================================
189 void ConstructionAPI_Axis::setByLine(const ModelHighAPI_Selection& theLine)
191 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE(), creationMethod());
192 fillAttribute(theLine, line());
197 //==================================================================================================
198 void ConstructionAPI_Axis::setByPlaneAndPoint(const ModelHighAPI_Selection& thePlane,
199 const ModelHighAPI_Selection& thePoint)
201 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT(), creationMethod());
202 fillAttribute(thePlane, plane());
203 fillAttribute(thePoint, point());
208 //==================================================================================================
209 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
210 const ModelHighAPI_Selection& thePlane2)
212 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
213 fillAttribute(thePlane1, plane1());
214 fillAttribute("", useOffset1());
215 fillAttribute(thePlane2, plane2());
216 fillAttribute("", useOffset2());
221 //==================================================================================================
222 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
223 const ModelHighAPI_Double& theOffset1,
224 const bool theReverseOffset1,
225 const ModelHighAPI_Selection& thePlane2,
226 const ModelHighAPI_Double& theOffset2,
227 const bool theReverseOffset2)
229 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
230 fillAttribute(thePlane1, plane1());
231 fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1());
232 fillAttribute(theOffset1, offset1());
233 fillAttribute(theReverseOffset1, reverseOffset1());
234 fillAttribute(thePlane2, plane2());
235 fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2());
236 fillAttribute(theOffset2, offset2());
237 fillAttribute(theReverseOffset2, reverseOffset2());
242 //==================================================================================================
243 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
244 const ModelHighAPI_Selection& thePlane2,
245 const ModelHighAPI_Double& theOffset2,
246 const bool theReverseOffset2)
248 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
249 fillAttribute(thePlane1, plane1());
250 fillAttribute("", useOffset1());
251 fillAttribute(thePlane2, plane2());
252 fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2());
253 fillAttribute(theOffset2, offset2());
254 fillAttribute(theReverseOffset2, reverseOffset2());
259 //==================================================================================================
260 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
261 const ModelHighAPI_Double& theOffset1,
262 const bool theReverseOffset1,
263 const ModelHighAPI_Selection& thePlane2)
265 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
266 fillAttribute(thePlane1, plane1());
267 fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1());
268 fillAttribute(theOffset1, offset1());
269 fillAttribute(theReverseOffset1, reverseOffset1());
270 fillAttribute(thePlane2, plane2());
271 fillAttribute("", useOffset2());
276 //==================================================================================================
277 void ConstructionAPI_Axis::dump(ModelHighAPI_Dumper& theDumper) const
279 FeaturePtr aBase = feature();
280 const std::string& aDocName = theDumper.name(aBase->document());
282 theDumper << aBase << " = model.addAxis(" << aDocName;
284 std::string aCreationMethod = aBase->string(ConstructionPlugin_Axis::METHOD())->value();
286 if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS()) {
287 AttributeDoublePtr anAttrDX = aBase->real(ConstructionPlugin_Axis::DX());
288 AttributeDoublePtr anAttrDY = aBase->real(ConstructionPlugin_Axis::DY());
289 AttributeDoublePtr anAttrDZ = aBase->real(ConstructionPlugin_Axis::DZ());
291 theDumper << ", " << anAttrDX << ", " << anAttrDY << ", " << anAttrDZ;
292 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS()) {
293 AttributeSelectionPtr anAttrFirstPnt =
294 aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
295 AttributeSelectionPtr anAttrSecondPnt =
296 aBase->selection(ConstructionPlugin_Axis::POINT_SECOND());
298 theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
299 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE()) {
300 AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Axis::LINE());
302 theDumper << ", " << anAttrLine;
303 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE()) {
304 AttributeSelectionPtr anAttrFace =
305 aBase->selection(ConstructionPlugin_Axis::CYLINDRICAL_FACE());
307 theDumper << ", " << anAttrFace;
308 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT()) {
309 AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Axis::PLANE());
310 AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Axis::POINT());
312 theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
313 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES()) {
314 AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Axis::PLANE1());
315 AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Axis::PLANE2());
317 theDumper << ", " << anAttrPlane1;
318 if(aBase->string(ConstructionPlugin_Axis::USE_OFFSET1())->isInitialized()
319 && !aBase->string(ConstructionPlugin_Axis::USE_OFFSET1())->value().empty()) {
320 AttributeDoublePtr anAttrOffset1 = aBase->real(ConstructionPlugin_Axis::OFFSET1());
321 AttributeBooleanPtr anAttrReverseOffset1 =
322 aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET1());
323 theDumper << ", " << anAttrOffset1 << ", " << anAttrReverseOffset1;
326 theDumper << ", " << anAttrPlane2;
327 if(aBase->string(ConstructionPlugin_Axis::USE_OFFSET2())->isInitialized()
328 && !aBase->string(ConstructionPlugin_Axis::USE_OFFSET2())->value().empty()) {
329 AttributeDoublePtr anAttrOffset2 = aBase->real(ConstructionPlugin_Axis::OFFSET2());
330 AttributeBooleanPtr anAttrReverseOffset2 =
331 aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET2());
332 theDumper << ", " << anAttrOffset2 << ", " << anAttrReverseOffset2;
334 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION()) {
335 AttributeSelectionPtr anAttrFirstPnt = aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
336 AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Axis::X_DIRECTION());
337 AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Axis::Y_DIRECTION());
338 AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Axis::Z_DIRECTION());
340 theDumper << ", " << anAttrFirstPnt << ", " << anAttrX << ", " << anAttrY << ", " << anAttrZ;
343 theDumper << ")" << std::endl;
346 //==================================================================================================
347 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
348 const ModelHighAPI_Selection& theObject1,
349 const ModelHighAPI_Selection& theObject2)
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, theObject1, theObject2));
356 //==================================================================================================
357 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
358 const ModelHighAPI_Selection& theObject)
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, theObject));
365 //==================================================================================================
366 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
367 const ModelHighAPI_Selection& thePoint,
368 const ModelHighAPI_Double& theX,
369 const ModelHighAPI_Double& theY,
370 const ModelHighAPI_Double& theZ)
372 // TODO(spo): check that thePart is not empty
373 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
374 return AxisPtr(new ConstructionAPI_Axis(aFeature, thePoint, theX, theY, theZ));
377 //==================================================================================================
378 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
379 const ModelHighAPI_Double& theDX,
380 const ModelHighAPI_Double& theDY,
381 const ModelHighAPI_Double& theDZ)
383 // TODO(spo): check that thePart is not empty
384 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
385 return AxisPtr(new ConstructionAPI_Axis(aFeature, theDX, theDY, theDZ));
388 //==================================================================================================
389 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
390 const ModelHighAPI_Selection& thePlane1,
391 const ModelHighAPI_Double& theOffset1,
392 const bool theReverseOffset1,
393 const ModelHighAPI_Selection& thePlane2,
394 const ModelHighAPI_Double& theOffset2,
395 const bool theReverseOffset2)
397 // TODO(spo): check that thePart is not empty
398 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
399 return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1,
400 thePlane2, theOffset2, theReverseOffset2));
403 //==================================================================================================
404 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
405 const ModelHighAPI_Selection& thePlane1,
406 const ModelHighAPI_Selection& thePlane2,
407 const ModelHighAPI_Double& theOffset2,
408 const bool theReverseOffset2)
410 // TODO(spo): check that thePart is not empty
411 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
412 return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1,
413 thePlane2, theOffset2, theReverseOffset2));
416 //==================================================================================================
417 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
418 const ModelHighAPI_Selection& thePlane1,
419 const ModelHighAPI_Double& theOffset1,
420 const bool theReverseOffset1,
421 const ModelHighAPI_Selection& thePlane2)
423 // TODO(spo): check that thePart is not empty
424 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
425 return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1,