1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "ConstructionAPI_Axis.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 //==================================================================================================
26 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
32 //==================================================================================================
33 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
34 const ModelHighAPI_Selection& theObject1,
35 const ModelHighAPI_Selection& theObject2)
36 : ModelHighAPI_Interface(theFeature)
39 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
40 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
41 if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::VERTEX) {
42 setByPoints(theObject1, theObject2);
43 } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) {
44 setByPlaneAndPoint(theObject1, theObject2);
45 } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) {
46 setByTwoPlanes(theObject1, theObject2);
51 //==================================================================================================
52 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
53 const ModelHighAPI_Selection& theObject)
54 : ModelHighAPI_Interface(theFeature)
57 GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
58 if(aType == GeomAPI_Shape::EDGE) {
60 } else if(aType == GeomAPI_Shape::FACE) {
61 setByCylindricalFace(theObject);
66 //==================================================================================================
67 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
68 const ModelHighAPI_Selection& thePoint,
69 const ModelHighAPI_Double& theX,
70 const ModelHighAPI_Double& theY,
71 const ModelHighAPI_Double& theZ)
72 : ModelHighAPI_Interface(theFeature)
75 setByPointAndDirection(thePoint, theX, theY, theZ);
79 //==================================================================================================
80 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
81 const ModelHighAPI_Double& theDX,
82 const ModelHighAPI_Double& theDY,
83 const ModelHighAPI_Double& theDZ)
84 : ModelHighAPI_Interface(theFeature)
87 setByDimensions(theDX, theDY, theDZ);
91 //==================================================================================================
92 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
93 const ModelHighAPI_Selection& thePlane1,
94 const ModelHighAPI_Double& theOffset1,
95 const bool theReverseOffset1,
96 const ModelHighAPI_Selection& thePlane2,
97 const ModelHighAPI_Double& theOffset2,
98 const bool theReverseOffset2)
99 : ModelHighAPI_Interface(theFeature)
102 setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1,
103 thePlane2, theOffset2, theReverseOffset2);
107 //==================================================================================================
108 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
109 const ModelHighAPI_Selection& thePlane1,
110 const ModelHighAPI_Selection& thePlane2,
111 const ModelHighAPI_Double& theOffset2,
112 const bool theReverseOffset2)
113 : ModelHighAPI_Interface(theFeature)
116 setByTwoPlanes(thePlane1, thePlane2, theOffset2, theReverseOffset2);
120 //==================================================================================================
121 ConstructionAPI_Axis::ConstructionAPI_Axis(const std::shared_ptr<ModelAPI_Feature>& theFeature,
122 const ModelHighAPI_Selection& thePlane1,
123 const ModelHighAPI_Double& theOffset1,
124 const bool theReverseOffset1,
125 const ModelHighAPI_Selection& thePlane2)
126 : ModelHighAPI_Interface(theFeature)
129 setByTwoPlanes(thePlane1, theOffset1, theReverseOffset1, thePlane2);
133 //==================================================================================================
134 ConstructionAPI_Axis::~ConstructionAPI_Axis()
138 //==================================================================================================
139 void ConstructionAPI_Axis::setByPoints(const ModelHighAPI_Selection& thePoint1,
140 const ModelHighAPI_Selection& thePoint2)
142 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
143 fillAttribute(thePoint1, firstPoint());
144 fillAttribute(thePoint2, secondPoint());
149 //==================================================================================================
150 void ConstructionAPI_Axis::setByCylindricalFace(const ModelHighAPI_Selection& theCylindricalFace)
152 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE(), creationMethod());
153 fillAttribute(theCylindricalFace, cylindricalFace());
158 //==================================================================================================
159 void ConstructionAPI_Axis::setByPointAndDirection(const ModelHighAPI_Selection& thePoint,
160 const ModelHighAPI_Double& theX,
161 const ModelHighAPI_Double& theY,
162 const ModelHighAPI_Double& theZ)
164 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION(),
166 fillAttribute(thePoint, firstPoint());
167 fillAttribute(theX, xDirection());
168 fillAttribute(theY, yDirection());
169 fillAttribute(theZ, zDirection());
174 //==================================================================================================
175 void ConstructionAPI_Axis::setByDimensions(const ModelHighAPI_Double& theDX,
176 const ModelHighAPI_Double& theDY,
177 const ModelHighAPI_Double& theDZ)
179 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
180 fillAttribute(theDX, xDimension());
181 fillAttribute(theDY, yDimension());
182 fillAttribute(theDZ, zDimension());
187 //==================================================================================================
188 void ConstructionAPI_Axis::setByLine(const ModelHighAPI_Selection& theLine)
190 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE(), creationMethod());
191 fillAttribute(theLine, line());
196 //==================================================================================================
197 void ConstructionAPI_Axis::setByPlaneAndPoint(const ModelHighAPI_Selection& thePlane,
198 const ModelHighAPI_Selection& thePoint)
200 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT(), creationMethod());
201 fillAttribute(thePlane, plane());
202 fillAttribute(thePoint, point());
207 //==================================================================================================
208 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
209 const ModelHighAPI_Selection& thePlane2)
211 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
212 fillAttribute(thePlane1, plane1());
213 fillAttribute("", useOffset1());
214 fillAttribute(thePlane2, plane2());
215 fillAttribute("", useOffset2());
220 //==================================================================================================
221 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
222 const ModelHighAPI_Double& theOffset1,
223 const bool theReverseOffset1,
224 const ModelHighAPI_Selection& thePlane2,
225 const ModelHighAPI_Double& theOffset2,
226 const bool theReverseOffset2)
228 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
229 fillAttribute(thePlane1, plane1());
230 fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1());
231 fillAttribute(theOffset1, offset1());
232 fillAttribute(theReverseOffset1, reverseOffset1());
233 fillAttribute(thePlane2, plane2());
234 fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2());
235 fillAttribute(theOffset2, offset2());
236 fillAttribute(theReverseOffset2, reverseOffset2());
241 //==================================================================================================
242 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
243 const ModelHighAPI_Selection& thePlane2,
244 const ModelHighAPI_Double& theOffset2,
245 const bool theReverseOffset2)
247 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
248 fillAttribute(thePlane1, plane1());
249 fillAttribute("", useOffset1());
250 fillAttribute(thePlane2, plane2());
251 fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2());
252 fillAttribute(theOffset2, offset2());
253 fillAttribute(theReverseOffset2, reverseOffset2());
258 //==================================================================================================
259 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
260 const ModelHighAPI_Double& theOffset1,
261 const bool theReverseOffset1,
262 const ModelHighAPI_Selection& thePlane2)
264 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
265 fillAttribute(thePlane1, plane1());
266 fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1());
267 fillAttribute(theOffset1, offset1());
268 fillAttribute(theReverseOffset1, reverseOffset1());
269 fillAttribute(thePlane2, plane2());
270 fillAttribute("", useOffset2());
275 //==================================================================================================
276 void ConstructionAPI_Axis::dump(ModelHighAPI_Dumper& theDumper) const
278 FeaturePtr aBase = feature();
279 const std::string& aDocName = theDumper.name(aBase->document());
281 theDumper << aBase << " = model.addAxis(" << aDocName;
283 std::string aCreationMethod = aBase->string(ConstructionPlugin_Axis::METHOD())->value();
285 if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS()) {
286 AttributeDoublePtr anAttrDX = aBase->real(ConstructionPlugin_Axis::DX());
287 AttributeDoublePtr anAttrDY = aBase->real(ConstructionPlugin_Axis::DY());
288 AttributeDoublePtr anAttrDZ = aBase->real(ConstructionPlugin_Axis::DZ());
290 theDumper << ", " << anAttrDX << ", " << anAttrDY << ", " << anAttrDZ;
291 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS()) {
292 AttributeSelectionPtr anAttrFirstPnt =
293 aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
294 AttributeSelectionPtr anAttrSecondPnt =
295 aBase->selection(ConstructionPlugin_Axis::POINT_SECOND());
297 theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
298 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE()) {
299 AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Axis::LINE());
301 theDumper << ", " << anAttrLine;
302 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE()) {
303 AttributeSelectionPtr anAttrFace =
304 aBase->selection(ConstructionPlugin_Axis::CYLINDRICAL_FACE());
306 theDumper << ", " << anAttrFace;
307 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT()) {
308 AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Axis::PLANE());
309 AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Axis::POINT());
311 theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
312 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES()) {
313 AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Axis::PLANE1());
314 AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Axis::PLANE2());
316 theDumper << ", " << anAttrPlane1;
317 if(aBase->string(ConstructionPlugin_Axis::USE_OFFSET1())->isInitialized()
318 && !aBase->string(ConstructionPlugin_Axis::USE_OFFSET1())->value().empty()) {
319 AttributeDoublePtr anAttrOffset1 = aBase->real(ConstructionPlugin_Axis::OFFSET1());
320 AttributeBooleanPtr anAttrReverseOffset1 =
321 aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET1());
322 theDumper << ", " << anAttrOffset1 << ", " << anAttrReverseOffset1;
325 theDumper << ", " << anAttrPlane2;
326 if(aBase->string(ConstructionPlugin_Axis::USE_OFFSET2())->isInitialized()
327 && !aBase->string(ConstructionPlugin_Axis::USE_OFFSET2())->value().empty()) {
328 AttributeDoublePtr anAttrOffset2 = aBase->real(ConstructionPlugin_Axis::OFFSET2());
329 AttributeBooleanPtr anAttrReverseOffset2 =
330 aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET2());
331 theDumper << ", " << anAttrOffset2 << ", " << anAttrReverseOffset2;
333 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION()) {
334 AttributeSelectionPtr anAttrFirstPnt = aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
335 AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Axis::X_DIRECTION());
336 AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Axis::Y_DIRECTION());
337 AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Axis::Z_DIRECTION());
339 theDumper << ", " << anAttrFirstPnt << ", " << anAttrX << ", " << anAttrY << ", " << anAttrZ;
342 theDumper << ")" << std::endl;
345 //==================================================================================================
346 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
347 const ModelHighAPI_Selection& theObject1,
348 const ModelHighAPI_Selection& theObject2)
350 // TODO(spo): check that thePart is not empty
351 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
352 return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject1, theObject2));
355 //==================================================================================================
356 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
357 const ModelHighAPI_Selection& theObject)
359 // TODO(spo): check that thePart is not empty
360 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
361 return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject));
364 //==================================================================================================
365 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
366 const ModelHighAPI_Selection& thePoint,
367 const ModelHighAPI_Double& theX,
368 const ModelHighAPI_Double& theY,
369 const ModelHighAPI_Double& theZ)
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, thePoint, theX, theY, theZ));
376 //==================================================================================================
377 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
378 const ModelHighAPI_Double& theDX,
379 const ModelHighAPI_Double& theDY,
380 const ModelHighAPI_Double& theDZ)
382 // TODO(spo): check that thePart is not empty
383 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
384 return AxisPtr(new ConstructionAPI_Axis(aFeature, theDX, theDY, theDZ));
387 //==================================================================================================
388 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
389 const ModelHighAPI_Selection& thePlane1,
390 const ModelHighAPI_Double& theOffset1,
391 const bool theReverseOffset1,
392 const ModelHighAPI_Selection& thePlane2,
393 const ModelHighAPI_Double& theOffset2,
394 const bool theReverseOffset2)
396 // TODO(spo): check that thePart is not empty
397 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
398 return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1,
399 thePlane2, theOffset2, theReverseOffset2));
402 //==================================================================================================
403 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
404 const ModelHighAPI_Selection& thePlane1,
405 const ModelHighAPI_Selection& thePlane2,
406 const ModelHighAPI_Double& theOffset2,
407 const bool theReverseOffset2)
409 // TODO(spo): check that thePart is not empty
410 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
411 return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1,
412 thePlane2, theOffset2, theReverseOffset2));
415 //==================================================================================================
416 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
417 const ModelHighAPI_Selection& thePlane1,
418 const ModelHighAPI_Double& theOffset1,
419 const bool theReverseOffset1,
420 const ModelHighAPI_Selection& thePlane2)
422 // TODO(spo): check that thePart is not empty
423 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
424 return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1,