1 // Name : ConstructionAPI_Plane.cpp
5 // 27/05/16 - Sergey POKHODENKO - Creation of the file
7 #include "ConstructionAPI_Plane.h"
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
12 //==================================================================================================
13 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
19 //==================================================================================================
20 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
21 const ModelHighAPI_Selection& theFace,
22 const ModelHighAPI_Double& theDistance,
23 const bool theIsReverse)
24 : ModelHighAPI_Interface(theFeature)
27 setByFaceAndDistance(theFace, theDistance, theIsReverse);
31 //==================================================================================================
32 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
33 const ModelHighAPI_Double& theA,
34 const ModelHighAPI_Double& theB,
35 const ModelHighAPI_Double& theC,
36 const ModelHighAPI_Double& theD)
37 : ModelHighAPI_Interface(theFeature)
40 setByGeneralEquation(theA, theB, theC, theD);
44 //==================================================================================================
45 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
46 const ModelHighAPI_Selection& thePoint1,
47 const ModelHighAPI_Selection& thePoint2,
48 const ModelHighAPI_Selection& thePoint3)
49 : ModelHighAPI_Interface(theFeature)
52 setByThreePoints(thePoint1, thePoint2, thePoint3);
56 //==================================================================================================
57 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
58 const ModelHighAPI_Selection& theLine,
59 const ModelHighAPI_Selection& thePoint,
60 const bool theIsPerpendicular)
61 : ModelHighAPI_Interface(theFeature)
64 setByLineAndPoint(theLine, thePoint, theIsPerpendicular);
68 //==================================================================================================
69 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
70 const ModelHighAPI_Selection& theObject1,
71 const ModelHighAPI_Selection& theObject2)
72 : ModelHighAPI_Interface(theFeature)
75 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
76 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
77 if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) {
78 setByCoincidentToPoint(theObject1, theObject2);
79 } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) {
80 setByTwoParallelPlanes(theObject1, theObject2);
85 //==================================================================================================
86 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
87 const ModelHighAPI_Selection& thePlane,
88 const ModelHighAPI_Selection& theAxis,
89 const ModelHighAPI_Double& theAngle)
90 : ModelHighAPI_Interface(theFeature)
93 setByRotation(thePlane, theAxis, theAngle);
97 //==================================================================================================
98 ConstructionAPI_Plane::~ConstructionAPI_Plane()
102 //==================================================================================================
103 void ConstructionAPI_Plane::setByFaceAndDistance(const ModelHighAPI_Selection& theFace,
104 const ModelHighAPI_Double& theDistance,
105 const bool theIsReverse)
107 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
108 fillAttribute(theFace, myplane);
109 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER(), mycreationMethodByOtherPlane);
110 fillAttribute(theDistance, mydistance);
111 fillAttribute(theIsReverse, myreverse);
116 //==================================================================================================
117 void ConstructionAPI_Plane::setByGeneralEquation(const ModelHighAPI_Double& theA,
118 const ModelHighAPI_Double& theB,
119 const ModelHighAPI_Double& theC,
120 const ModelHighAPI_Double& theD)
122 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION(), mycreationMethod);
123 fillAttribute(theA, myA);
124 fillAttribute(theB, myB);
125 fillAttribute(theC, myC);
126 fillAttribute(theD, myD);
131 //==================================================================================================
132 void ConstructionAPI_Plane::setByThreePoints(const ModelHighAPI_Selection& thePoint1,
133 const ModelHighAPI_Selection& thePoint2,
134 const ModelHighAPI_Selection& thePoint3)
136 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
137 fillAttribute(thePoint1, mypoint1);
138 fillAttribute(thePoint2, mypoint2);
139 fillAttribute(thePoint3, mypoint3);
144 //==================================================================================================
145 void ConstructionAPI_Plane::setByLineAndPoint(const ModelHighAPI_Selection& theLine,
146 const ModelHighAPI_Selection& thePoint,
147 const bool theIsPerpendicular)
149 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT(), mycreationMethod);
150 fillAttribute(theLine, myline);
151 fillAttribute(thePoint, mypoint);
152 fillAttribute(theIsPerpendicular, myperpendicular);
157 //==================================================================================================
158 void ConstructionAPI_Plane::setByTwoParallelPlanes(const ModelHighAPI_Selection& thePlane1,
159 const ModelHighAPI_Selection& thePlane2)
161 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES(), mycreationMethod);
162 fillAttribute(thePlane1, myplane1);
163 fillAttribute(thePlane2, myplane2);
168 //==================================================================================================
169 void ConstructionAPI_Plane::setByCoincidentToPoint(const ModelHighAPI_Selection& thePlane,
170 const ModelHighAPI_Selection& thePoint)
172 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
173 fillAttribute(thePlane, myplane);
174 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT(), mycreationMethodByOtherPlane);
175 fillAttribute(thePoint, mycoincidentPoint);
180 //==================================================================================================
181 void ConstructionAPI_Plane::setByRotation(const ModelHighAPI_Selection& thePlane,
182 const ModelHighAPI_Selection& theAxis,
183 const ModelHighAPI_Double& theAngle)
185 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
186 fillAttribute(thePlane, myplane);
187 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION(), mycreationMethodByOtherPlane);
188 fillAttribute(theAxis, myaxis);
189 fillAttribute(theAngle, myangle);
194 //==================================================================================================
195 void ConstructionAPI_Plane::dump(ModelHighAPI_Dumper& theDumper) const
197 FeaturePtr aBase = feature();
198 const std::string& aDocName = theDumper.name(aBase->document());
200 theDumper << aBase << " = model.addPlane(" << aDocName;
202 std::string aCreationMethod = aBase->string(ConstructionPlugin_Plane::CREATION_METHOD())->value();
204 if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION()) {
205 AttributeDoublePtr anAttrA = aBase->real(ConstructionPlugin_Plane::A());
206 AttributeDoublePtr anAttrB = aBase->real(ConstructionPlugin_Plane::B());
207 AttributeDoublePtr anAttrC = aBase->real(ConstructionPlugin_Plane::C());
208 AttributeDoublePtr anAttrD = aBase->real(ConstructionPlugin_Plane::D());
210 theDumper << ", " << anAttrA << ", " << anAttrB << ", " << anAttrC << ", " << anAttrD;
211 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS()) {
212 AttributeSelectionPtr anAttrPnt1 = aBase->selection(ConstructionPlugin_Plane::POINT1());
213 AttributeSelectionPtr anAttrPnt2 = aBase->selection(ConstructionPlugin_Plane::POINT2());
214 AttributeSelectionPtr anAttrPnt3 = aBase->selection(ConstructionPlugin_Plane::POINT3());
216 theDumper << ", " << anAttrPnt1 << ", " << anAttrPnt2 << ", " << anAttrPnt3;
217 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT()) {
218 AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Plane::LINE());
219 AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Plane::POINT());
220 AttributeBooleanPtr anAttrPerpendicular = aBase->boolean(ConstructionPlugin_Plane::PERPENDICULAR());
222 theDumper << ", " << anAttrLine << ", " << anAttrPoint << ", " << anAttrPerpendicular;
223 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE()) {
224 AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Plane::PLANE());
226 std::string aCreationMethodOption =
227 aBase->string(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
228 if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
229 AttributeDoublePtr anAttrDistance = aBase->real(ConstructionPlugin_Plane::DISTANCE());
230 AttributeBooleanPtr anAttrReverse = aBase->boolean(ConstructionPlugin_Plane::REVERSE());
232 theDumper << ", " << anAttrPlane << ", " << anAttrDistance << ", " << anAttrReverse;
233 } else if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
234 AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Plane::COINCIDENT_POINT());
236 theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
237 } else if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION()) {
238 AttributeSelectionPtr anAttrAxis = aBase->selection(ConstructionPlugin_Plane::AXIS());
239 AttributeDoublePtr anAttrAngle = aBase->real(ConstructionPlugin_Plane::ANGLE());
241 theDumper << ", " << anAttrPlane << ", " << anAttrAxis << ", " << anAttrAngle;
243 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES()) {
244 AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Plane::PLANE1());
245 AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Plane::PLANE2());
247 theDumper << ", " << anAttrPlane1 << ", " << anAttrPlane2;
250 theDumper << ")" << std::endl;
253 //==================================================================================================
254 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
255 const ModelHighAPI_Selection& theFace,
256 const ModelHighAPI_Double& theDistance,
257 const bool theIsReverse)
259 // TODO(spo): check that thePart is not empty
260 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
261 return PlanePtr(new ConstructionAPI_Plane(aFeature, theFace, theDistance, theIsReverse));
264 //==================================================================================================
265 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
266 const ModelHighAPI_Double& theA,
267 const ModelHighAPI_Double& theB,
268 const ModelHighAPI_Double& theC,
269 const ModelHighAPI_Double& theD)
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, theA, theB, theC, theD));
276 //==================================================================================================
277 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
278 const ModelHighAPI_Selection& thePoint1,
279 const ModelHighAPI_Selection& thePoint2,
280 const ModelHighAPI_Selection& thePoint3)
282 // TODO(spo): check that thePart is not empty
283 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
284 return PlanePtr(new ConstructionAPI_Plane(aFeature, thePoint1, thePoint2, thePoint3));
287 //==================================================================================================
288 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
289 const ModelHighAPI_Selection& theLine,
290 const ModelHighAPI_Selection& thePoint,
291 const bool theIsPerpendicular)
293 // TODO(spo): check that thePart is not empty
294 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
295 return PlanePtr(new ConstructionAPI_Plane(aFeature, theLine, thePoint, theIsPerpendicular));
298 //==================================================================================================
299 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
300 const ModelHighAPI_Selection& theObject1,
301 const ModelHighAPI_Selection& theObject2)
303 // TODO(spo): check that thePart is not empty
304 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
305 return PlanePtr(new ConstructionAPI_Plane(aFeature, theObject1, theObject2));
308 //==================================================================================================
309 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
310 const ModelHighAPI_Selection& thePlane,
311 const ModelHighAPI_Selection& theAxis,
312 const ModelHighAPI_Double& theAngle)
314 // TODO(spo): check that thePart is not empty
315 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
316 return PlanePtr(new ConstructionAPI_Plane(aFeature, thePlane, theAxis, theAngle));