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()
98 //==================================================================================================
99 void ConstructionAPI_Axis::setByPoints(const ModelHighAPI_Selection& thePoint1,
100 const ModelHighAPI_Selection& thePoint2)
102 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
103 fillAttribute(thePoint1, firstPoint());
104 fillAttribute(thePoint2, secondPoint());
109 //==================================================================================================
110 void ConstructionAPI_Axis::setByCylindricalFace(const ModelHighAPI_Selection& theCylindricalFace)
112 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE(), creationMethod());
113 fillAttribute(theCylindricalFace, cylindricalFace());
118 //==================================================================================================
119 void ConstructionAPI_Axis::setByPointAndDirection(const ModelHighAPI_Selection& thePoint,
120 const ModelHighAPI_Double& theX,
121 const ModelHighAPI_Double& theY,
122 const ModelHighAPI_Double& theZ)
124 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION(), creationMethod());
125 fillAttribute(thePoint, firstPoint());
126 fillAttribute(theX, xDirection());
127 fillAttribute(theY, yDirection());
128 fillAttribute(theZ, zDirection());
133 //==================================================================================================
134 void ConstructionAPI_Axis::setByDimensions(const ModelHighAPI_Double& theDX,
135 const ModelHighAPI_Double& theDY,
136 const ModelHighAPI_Double& theDZ)
138 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
139 fillAttribute(theDX, xDimension());
140 fillAttribute(theDY, yDimension());
141 fillAttribute(theDZ, zDimension());
146 //==================================================================================================
147 void ConstructionAPI_Axis::setByLine(const ModelHighAPI_Selection& theLine)
149 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE(), creationMethod());
150 fillAttribute(theLine, line());
155 //==================================================================================================
156 void ConstructionAPI_Axis::setByPlaneAndPoint(const ModelHighAPI_Selection& thePlane,
157 const ModelHighAPI_Selection& thePoint)
159 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT(), creationMethod());
160 fillAttribute(thePlane, plane());
161 fillAttribute(thePoint, point());
166 //==================================================================================================
167 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
168 const ModelHighAPI_Selection& thePlane2)
170 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
171 fillAttribute(thePlane1, plane1());
172 fillAttribute("", useOffset1());
173 fillAttribute(thePlane2, plane2());
174 fillAttribute("", useOffset2());
179 //==================================================================================================
180 void ConstructionAPI_Axis::setByTwoPlanes(const ModelHighAPI_Selection& thePlane1,
181 const ModelHighAPI_Double& theOffset1,
182 const bool theReverseOffset1,
183 const ModelHighAPI_Selection& thePlane2,
184 const ModelHighAPI_Double& theOffset2,
185 const bool theReverseOffset2)
187 fillAttribute(ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES(), creationMethod());
188 fillAttribute(thePlane1, plane1());
189 fillAttribute(ConstructionPlugin_Axis::USE_OFFSET1(), useOffset1());
190 fillAttribute(theOffset1, offset1());
191 fillAttribute(theReverseOffset1, reverseOffset1());
192 fillAttribute(thePlane2, plane2());
193 fillAttribute(ConstructionPlugin_Axis::USE_OFFSET2(), useOffset2());
194 fillAttribute(theOffset2, offset2());
195 fillAttribute(theReverseOffset2, reverseOffset2());
200 //==================================================================================================
201 void ConstructionAPI_Axis::dump(ModelHighAPI_Dumper& theDumper) const
203 FeaturePtr aBase = feature();
204 const std::string& aDocName = theDumper.name(aBase->document());
206 theDumper << aBase << " = model.addAxis(" << aDocName;
208 std::string aCreationMethod = aBase->string(ConstructionPlugin_Axis::METHOD())->value();
210 if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_DIMENSIONS()) {
211 AttributeDoublePtr anAttrDX = aBase->real(ConstructionPlugin_Axis::DX());
212 AttributeDoublePtr anAttrDY = aBase->real(ConstructionPlugin_Axis::DY());
213 AttributeDoublePtr anAttrDZ = aBase->real(ConstructionPlugin_Axis::DZ());
215 theDumper << ", " << anAttrDX << ", " << anAttrDY << ", " << anAttrDZ;
216 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_POINTS()) {
217 AttributeSelectionPtr anAttrFirstPnt = aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
218 AttributeSelectionPtr anAttrSecondPnt = aBase->selection(ConstructionPlugin_Axis::POINT_SECOND());
220 theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
221 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_LINE()) {
222 AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Axis::LINE());
224 theDumper << ", " << anAttrLine;
225 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_CYLINDRICAL_FACE()) {
226 AttributeSelectionPtr anAttrFace = aBase->selection(ConstructionPlugin_Axis::CYLINDRICAL_FACE());
228 theDumper << ", " << anAttrFace;
229 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_PLANE_AND_POINT()) {
230 AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Axis::PLANE());
231 AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Axis::POINT());
233 theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
234 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_TWO_PLANES()) {
235 AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Axis::PLANE1());
236 AttributeDoublePtr anAttrOffset1 = aBase->real(ConstructionPlugin_Axis::OFFSET1());
237 AttributeBooleanPtr anAttrReverseOffset1 = aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET1());
238 AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Axis::PLANE2());
239 AttributeDoublePtr anAttrOffset2 = aBase->real(ConstructionPlugin_Axis::OFFSET2());
240 AttributeBooleanPtr anAttrReverseOffset2 = aBase->boolean(ConstructionPlugin_Axis::REVERSE_OFFSET2());
242 theDumper << ", " << anAttrPlane1 << ", " << anAttrOffset1 << ", " << anAttrReverseOffset1
243 << ", " << anAttrPlane2 << ", " << anAttrOffset2 << ", " << anAttrReverseOffset2;
244 } else if(aCreationMethod == ConstructionPlugin_Axis::CREATION_METHOD_BY_POINT_AND_DIRECTION()) {
245 AttributeSelectionPtr anAttrFirstPnt = aBase->selection(ConstructionPlugin_Axis::POINT_FIRST());
246 AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Axis::X_DIRECTION());
247 AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Axis::Y_DIRECTION());
248 AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Axis::Z_DIRECTION());
250 theDumper << ", " << anAttrFirstPnt << ", " << anAttrX << ", " << anAttrY << ", " << anAttrZ;
253 theDumper << ")" << std::endl;
256 //==================================================================================================
257 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
258 const ModelHighAPI_Selection& theObject1,
259 const ModelHighAPI_Selection& theObject2)
261 // TODO(spo): check that thePart is not empty
262 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
263 return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject1, theObject2));
266 //==================================================================================================
267 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
268 const ModelHighAPI_Selection& theObject)
270 // TODO(spo): check that thePart is not empty
271 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
272 return AxisPtr(new ConstructionAPI_Axis(aFeature, theObject));
275 //==================================================================================================
276 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
277 const ModelHighAPI_Selection& thePoint,
278 const ModelHighAPI_Double& theX,
279 const ModelHighAPI_Double& theY,
280 const ModelHighAPI_Double& theZ)
282 // TODO(spo): check that thePart is not empty
283 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
284 return AxisPtr(new ConstructionAPI_Axis(aFeature, thePoint, theX, theY, theZ));
287 //==================================================================================================
288 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
289 const ModelHighAPI_Double& theDX,
290 const ModelHighAPI_Double& theDY,
291 const ModelHighAPI_Double& theDZ)
293 // TODO(spo): check that thePart is not empty
294 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
295 return AxisPtr(new ConstructionAPI_Axis(aFeature, theDX, theDY, theDZ));
298 //==================================================================================================
299 AxisPtr addAxis(const std::shared_ptr<ModelAPI_Document>& thePart,
300 const ModelHighAPI_Selection& thePlane1,
301 const ModelHighAPI_Double& theOffset1,
302 const bool theReverseOffset1,
303 const ModelHighAPI_Selection& thePlane2,
304 const ModelHighAPI_Double& theOffset2,
305 const bool theReverseOffset2)
307 // TODO(spo): check that thePart is not empty
308 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Axis::ID());
309 return AxisPtr(new ConstructionAPI_Axis(aFeature, thePlane1, theOffset1, theReverseOffset1,
310 thePlane2, theOffset2, theReverseOffset2));