1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
3 // Name : ConstructionAPI_Plane.cpp
7 // 27/05/16 - Sergey POKHODENKO - Creation of the file
9 #include "ConstructionAPI_Plane.h"
11 #include <ModelHighAPI_Dumper.h>
12 #include <ModelHighAPI_Tools.h>
14 //==================================================================================================
15 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature)
16 : ModelHighAPI_Interface(theFeature)
21 //==================================================================================================
22 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
23 const ModelHighAPI_Selection& theFace,
24 const ModelHighAPI_Double& theDistance,
25 const bool theIsReverse)
26 : ModelHighAPI_Interface(theFeature)
29 setByFaceAndDistance(theFace, theDistance, theIsReverse);
33 //==================================================================================================
34 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35 const ModelHighAPI_Double& theA,
36 const ModelHighAPI_Double& theB,
37 const ModelHighAPI_Double& theC,
38 const ModelHighAPI_Double& theD)
39 : ModelHighAPI_Interface(theFeature)
42 setByGeneralEquation(theA, theB, theC, theD);
46 //==================================================================================================
47 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
48 const ModelHighAPI_Selection& thePoint1,
49 const ModelHighAPI_Selection& thePoint2,
50 const ModelHighAPI_Selection& thePoint3)
51 : ModelHighAPI_Interface(theFeature)
54 setByThreePoints(thePoint1, thePoint2, thePoint3);
58 //==================================================================================================
59 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
60 const ModelHighAPI_Selection& theLine,
61 const ModelHighAPI_Selection& thePoint,
62 const bool theIsPerpendicular)
63 : ModelHighAPI_Interface(theFeature)
66 setByLineAndPoint(theLine, thePoint, theIsPerpendicular);
70 //==================================================================================================
71 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
72 const ModelHighAPI_Selection& theObject1,
73 const ModelHighAPI_Selection& theObject2)
74 : ModelHighAPI_Interface(theFeature)
77 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
78 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
79 if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) {
80 setByCoincidentToPoint(theObject1, theObject2);
81 } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) {
82 setByTwoParallelPlanes(theObject1, theObject2);
87 //==================================================================================================
88 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
89 const ModelHighAPI_Selection& thePlane,
90 const ModelHighAPI_Selection& theAxis,
91 const ModelHighAPI_Double& theAngle)
92 : ModelHighAPI_Interface(theFeature)
95 setByRotation(thePlane, theAxis, theAngle);
99 //==================================================================================================
100 ConstructionAPI_Plane::~ConstructionAPI_Plane()
104 //==================================================================================================
105 void ConstructionAPI_Plane::setByFaceAndDistance(const ModelHighAPI_Selection& theFace,
106 const ModelHighAPI_Double& theDistance,
107 const bool theIsReverse)
109 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
110 fillAttribute(theFace, myplane);
111 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER(),
112 mycreationMethodByOtherPlane);
113 fillAttribute(theDistance, mydistance);
114 fillAttribute(theIsReverse, myreverse);
119 //==================================================================================================
120 void ConstructionAPI_Plane::setByGeneralEquation(const ModelHighAPI_Double& theA,
121 const ModelHighAPI_Double& theB,
122 const ModelHighAPI_Double& theC,
123 const ModelHighAPI_Double& theD)
125 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION(), mycreationMethod);
126 fillAttribute(theA, myA);
127 fillAttribute(theB, myB);
128 fillAttribute(theC, myC);
129 fillAttribute(theD, myD);
134 //==================================================================================================
135 void ConstructionAPI_Plane::setByThreePoints(const ModelHighAPI_Selection& thePoint1,
136 const ModelHighAPI_Selection& thePoint2,
137 const ModelHighAPI_Selection& thePoint3)
139 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
140 fillAttribute(thePoint1, mypoint1);
141 fillAttribute(thePoint2, mypoint2);
142 fillAttribute(thePoint3, mypoint3);
147 //==================================================================================================
148 void ConstructionAPI_Plane::setByLineAndPoint(const ModelHighAPI_Selection& theLine,
149 const ModelHighAPI_Selection& thePoint,
150 const bool theIsPerpendicular)
152 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT(), mycreationMethod);
153 fillAttribute(theLine, myline);
154 fillAttribute(thePoint, mypoint);
155 fillAttribute(theIsPerpendicular, myperpendicular);
160 //==================================================================================================
161 void ConstructionAPI_Plane::setByTwoParallelPlanes(const ModelHighAPI_Selection& thePlane1,
162 const ModelHighAPI_Selection& thePlane2)
164 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES(),
166 fillAttribute(thePlane1, myplane1);
167 fillAttribute(thePlane2, myplane2);
172 //==================================================================================================
173 void ConstructionAPI_Plane::setByCoincidentToPoint(const ModelHighAPI_Selection& thePlane,
174 const ModelHighAPI_Selection& thePoint)
176 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
177 fillAttribute(thePlane, myplane);
178 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT(),
179 mycreationMethodByOtherPlane);
180 fillAttribute(thePoint, mycoincidentPoint);
185 //==================================================================================================
186 void ConstructionAPI_Plane::setByRotation(const ModelHighAPI_Selection& thePlane,
187 const ModelHighAPI_Selection& theAxis,
188 const ModelHighAPI_Double& theAngle)
190 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
191 fillAttribute(thePlane, myplane);
192 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION(),
193 mycreationMethodByOtherPlane);
194 fillAttribute(theAxis, myaxis);
195 fillAttribute(theAngle, myangle);
200 //==================================================================================================
201 void ConstructionAPI_Plane::dump(ModelHighAPI_Dumper& theDumper) const
203 FeaturePtr aBase = feature();
204 const std::string& aDocName = theDumper.name(aBase->document());
206 theDumper << aBase << " = model.addPlane(" << aDocName;
208 std::string aCreationMethod =
209 aBase->string(ConstructionPlugin_Plane::CREATION_METHOD())->value();
211 if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION()) {
212 AttributeDoublePtr anAttrA = aBase->real(ConstructionPlugin_Plane::A());
213 AttributeDoublePtr anAttrB = aBase->real(ConstructionPlugin_Plane::B());
214 AttributeDoublePtr anAttrC = aBase->real(ConstructionPlugin_Plane::C());
215 AttributeDoublePtr anAttrD = aBase->real(ConstructionPlugin_Plane::D());
217 theDumper << ", " << anAttrA << ", " << anAttrB << ", " << anAttrC << ", " << anAttrD;
218 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS()) {
219 AttributeSelectionPtr anAttrPnt1 = aBase->selection(ConstructionPlugin_Plane::POINT1());
220 AttributeSelectionPtr anAttrPnt2 = aBase->selection(ConstructionPlugin_Plane::POINT2());
221 AttributeSelectionPtr anAttrPnt3 = aBase->selection(ConstructionPlugin_Plane::POINT3());
223 theDumper << ", " << anAttrPnt1 << ", " << anAttrPnt2 << ", " << anAttrPnt3;
224 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT()) {
225 AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Plane::LINE());
226 AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Plane::POINT());
227 AttributeBooleanPtr anAttrPerpendicular =
228 aBase->boolean(ConstructionPlugin_Plane::PERPENDICULAR());
230 theDumper << ", " << anAttrLine << ", " << anAttrPoint << ", " << anAttrPerpendicular;
231 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE()) {
232 AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Plane::PLANE());
234 std::string aCreationMethodOption =
235 aBase->string(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
236 if(aCreationMethodOption ==
237 ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
238 AttributeDoublePtr anAttrDistance = aBase->real(ConstructionPlugin_Plane::DISTANCE());
239 AttributeBooleanPtr anAttrReverse = aBase->boolean(ConstructionPlugin_Plane::REVERSE());
241 theDumper << ", " << anAttrPlane << ", " << anAttrDistance << ", " << anAttrReverse;
242 } else if(aCreationMethodOption ==
243 ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
244 AttributeSelectionPtr anAttrPoint =
245 aBase->selection(ConstructionPlugin_Plane::COINCIDENT_POINT());
247 theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
248 } else if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION()) {
249 AttributeSelectionPtr anAttrAxis = aBase->selection(ConstructionPlugin_Plane::AXIS());
250 AttributeDoublePtr anAttrAngle = aBase->real(ConstructionPlugin_Plane::ANGLE());
252 theDumper << ", " << anAttrPlane << ", " << anAttrAxis << ", " << anAttrAngle;
254 } else if(aCreationMethod ==
255 ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES()) {
256 AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Plane::PLANE1());
257 AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Plane::PLANE2());
259 theDumper << ", " << anAttrPlane1 << ", " << anAttrPlane2;
262 theDumper << ")" << std::endl;
265 //==================================================================================================
266 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
267 const ModelHighAPI_Selection& theFace,
268 const ModelHighAPI_Double& theDistance,
269 const bool theIsReverse)
271 // TODO(spo): check that thePart is not empty
272 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
273 return PlanePtr(new ConstructionAPI_Plane(aFeature, theFace, theDistance, theIsReverse));
276 //==================================================================================================
277 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
278 const ModelHighAPI_Double& theA,
279 const ModelHighAPI_Double& theB,
280 const ModelHighAPI_Double& theC,
281 const ModelHighAPI_Double& theD)
283 // TODO(spo): check that thePart is not empty
284 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
285 return PlanePtr(new ConstructionAPI_Plane(aFeature, theA, theB, theC, theD));
288 //==================================================================================================
289 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
290 const ModelHighAPI_Selection& thePoint1,
291 const ModelHighAPI_Selection& thePoint2,
292 const ModelHighAPI_Selection& thePoint3)
294 // TODO(spo): check that thePart is not empty
295 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
296 return PlanePtr(new ConstructionAPI_Plane(aFeature, thePoint1, thePoint2, thePoint3));
299 //==================================================================================================
300 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
301 const ModelHighAPI_Selection& theLine,
302 const ModelHighAPI_Selection& thePoint,
303 const bool theIsPerpendicular)
305 // TODO(spo): check that thePart is not empty
306 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
307 return PlanePtr(new ConstructionAPI_Plane(aFeature, theLine, thePoint, theIsPerpendicular));
310 //==================================================================================================
311 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
312 const ModelHighAPI_Selection& theObject1,
313 const ModelHighAPI_Selection& theObject2)
315 // TODO(spo): check that thePart is not empty
316 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
317 return PlanePtr(new ConstructionAPI_Plane(aFeature, theObject1, theObject2));
320 //==================================================================================================
321 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
322 const ModelHighAPI_Selection& thePlane,
323 const ModelHighAPI_Selection& theAxis,
324 const ModelHighAPI_Double& theAngle)
326 // TODO(spo): check that thePart is not empty
327 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
328 return PlanePtr(new ConstructionAPI_Plane(aFeature, thePlane, theAxis, theAngle));