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_Plane.h"
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 //==================================================================================================
27 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
33 //==================================================================================================
34 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35 const ModelHighAPI_Selection& theFace,
36 const ModelHighAPI_Double& theDistance,
37 const bool theIsReverse)
38 : ModelHighAPI_Interface(theFeature)
41 setByFaceAndDistance(theFace, theDistance, theIsReverse);
45 //==================================================================================================
46 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
47 const ModelHighAPI_Double& theA,
48 const ModelHighAPI_Double& theB,
49 const ModelHighAPI_Double& theC,
50 const ModelHighAPI_Double& theD)
51 : ModelHighAPI_Interface(theFeature)
54 setByGeneralEquation(theA, theB, theC, theD);
58 //==================================================================================================
59 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
60 const ModelHighAPI_Selection& thePoint1,
61 const ModelHighAPI_Selection& thePoint2,
62 const ModelHighAPI_Selection& thePoint3)
63 : ModelHighAPI_Interface(theFeature)
66 setByThreePoints(thePoint1, thePoint2, thePoint3);
70 //==================================================================================================
71 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
72 const ModelHighAPI_Selection& theLine,
73 const ModelHighAPI_Selection& thePoint,
74 const bool theIsPerpendicular)
75 : ModelHighAPI_Interface(theFeature)
78 setByLineAndPoint(theLine, thePoint, theIsPerpendicular);
82 //==================================================================================================
83 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
84 const ModelHighAPI_Selection& theObject1,
85 const ModelHighAPI_Selection& theObject2)
86 : ModelHighAPI_Interface(theFeature)
89 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
90 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
91 if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) {
92 setByCoincidentToPoint(theObject1, theObject2);
93 } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) {
94 setByTwoParallelPlanes(theObject1, theObject2);
99 //==================================================================================================
100 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
101 const ModelHighAPI_Selection& thePlane,
102 const ModelHighAPI_Selection& theAxis,
103 const ModelHighAPI_Double& theAngle)
104 : ModelHighAPI_Interface(theFeature)
107 setByRotation(thePlane, theAxis, theAngle);
111 //==================================================================================================
112 ConstructionAPI_Plane::~ConstructionAPI_Plane()
116 //==================================================================================================
117 void ConstructionAPI_Plane::setByFaceAndDistance(const ModelHighAPI_Selection& theFace,
118 const ModelHighAPI_Double& theDistance,
119 const bool theIsReverse)
121 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
122 fillAttribute(theFace, myplane);
123 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER(),
124 mycreationMethodByOtherPlane);
125 fillAttribute(theDistance, mydistance);
126 fillAttribute(theIsReverse, myreverse);
131 //==================================================================================================
132 void ConstructionAPI_Plane::setByGeneralEquation(const ModelHighAPI_Double& theA,
133 const ModelHighAPI_Double& theB,
134 const ModelHighAPI_Double& theC,
135 const ModelHighAPI_Double& theD)
137 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION(), mycreationMethod);
138 fillAttribute(theA, myA);
139 fillAttribute(theB, myB);
140 fillAttribute(theC, myC);
141 fillAttribute(theD, myD);
146 //==================================================================================================
147 void ConstructionAPI_Plane::setByThreePoints(const ModelHighAPI_Selection& thePoint1,
148 const ModelHighAPI_Selection& thePoint2,
149 const ModelHighAPI_Selection& thePoint3)
151 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
152 fillAttribute(thePoint1, mypoint1);
153 fillAttribute(thePoint2, mypoint2);
154 fillAttribute(thePoint3, mypoint3);
159 //==================================================================================================
160 void ConstructionAPI_Plane::setByLineAndPoint(const ModelHighAPI_Selection& theLine,
161 const ModelHighAPI_Selection& thePoint,
162 const bool theIsPerpendicular)
164 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT(), mycreationMethod);
165 fillAttribute(theLine, myline);
166 fillAttribute(thePoint, mypoint);
167 fillAttribute(theIsPerpendicular, myperpendicular);
172 //==================================================================================================
173 void ConstructionAPI_Plane::setByTwoParallelPlanes(const ModelHighAPI_Selection& thePlane1,
174 const ModelHighAPI_Selection& thePlane2)
176 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES(),
178 fillAttribute(thePlane1, myplane1);
179 fillAttribute(thePlane2, myplane2);
184 //==================================================================================================
185 void ConstructionAPI_Plane::setByCoincidentToPoint(const ModelHighAPI_Selection& thePlane,
186 const ModelHighAPI_Selection& thePoint)
188 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
189 fillAttribute(thePlane, myplane);
190 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT(),
191 mycreationMethodByOtherPlane);
192 fillAttribute(thePoint, mycoincidentPoint);
197 //==================================================================================================
198 void ConstructionAPI_Plane::setByRotation(const ModelHighAPI_Selection& thePlane,
199 const ModelHighAPI_Selection& theAxis,
200 const ModelHighAPI_Double& theAngle)
202 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
203 fillAttribute(thePlane, myplane);
204 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION(),
205 mycreationMethodByOtherPlane);
206 fillAttribute(theAxis, myaxis);
207 fillAttribute(theAngle, myangle);
212 //==================================================================================================
213 void ConstructionAPI_Plane::dump(ModelHighAPI_Dumper& theDumper) const
215 FeaturePtr aBase = feature();
216 const std::string& aDocName = theDumper.name(aBase->document());
218 theDumper << aBase << " = model.addPlane(" << aDocName;
220 std::string aCreationMethod =
221 aBase->string(ConstructionPlugin_Plane::CREATION_METHOD())->value();
223 if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION()) {
224 AttributeDoublePtr anAttrA = aBase->real(ConstructionPlugin_Plane::A());
225 AttributeDoublePtr anAttrB = aBase->real(ConstructionPlugin_Plane::B());
226 AttributeDoublePtr anAttrC = aBase->real(ConstructionPlugin_Plane::C());
227 AttributeDoublePtr anAttrD = aBase->real(ConstructionPlugin_Plane::D());
229 theDumper << ", " << anAttrA << ", " << anAttrB << ", " << anAttrC << ", " << anAttrD;
230 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS()) {
231 AttributeSelectionPtr anAttrPnt1 = aBase->selection(ConstructionPlugin_Plane::POINT1());
232 AttributeSelectionPtr anAttrPnt2 = aBase->selection(ConstructionPlugin_Plane::POINT2());
233 AttributeSelectionPtr anAttrPnt3 = aBase->selection(ConstructionPlugin_Plane::POINT3());
235 theDumper << ", " << anAttrPnt1 << ", " << anAttrPnt2 << ", " << anAttrPnt3;
236 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT()) {
237 AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Plane::LINE());
238 AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Plane::POINT());
239 AttributeBooleanPtr anAttrPerpendicular =
240 aBase->boolean(ConstructionPlugin_Plane::PERPENDICULAR());
242 theDumper << ", " << anAttrLine << ", " << anAttrPoint << ", " << anAttrPerpendicular;
243 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE()) {
244 AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Plane::PLANE());
246 std::string aCreationMethodOption =
247 aBase->string(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
248 if(aCreationMethodOption ==
249 ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
250 AttributeDoublePtr anAttrDistance = aBase->real(ConstructionPlugin_Plane::DISTANCE());
251 AttributeBooleanPtr anAttrReverse = aBase->boolean(ConstructionPlugin_Plane::REVERSE());
253 theDumper << ", " << anAttrPlane << ", " << anAttrDistance << ", " << anAttrReverse;
254 } else if(aCreationMethodOption ==
255 ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
256 AttributeSelectionPtr anAttrPoint =
257 aBase->selection(ConstructionPlugin_Plane::COINCIDENT_POINT());
259 theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
260 } else if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION()) {
261 AttributeSelectionPtr anAttrAxis = aBase->selection(ConstructionPlugin_Plane::AXIS());
262 AttributeDoublePtr anAttrAngle = aBase->real(ConstructionPlugin_Plane::ANGLE());
264 theDumper << ", " << anAttrPlane << ", " << anAttrAxis << ", " << anAttrAngle;
266 } else if(aCreationMethod ==
267 ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES()) {
268 AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Plane::PLANE1());
269 AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Plane::PLANE2());
271 theDumper << ", " << anAttrPlane1 << ", " << anAttrPlane2;
274 theDumper << ")" << std::endl;
277 //==================================================================================================
278 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
279 const ModelHighAPI_Selection& theFace,
280 const ModelHighAPI_Double& theDistance,
281 const bool theIsReverse)
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, theFace, theDistance, theIsReverse));
288 //==================================================================================================
289 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
290 const ModelHighAPI_Double& theA,
291 const ModelHighAPI_Double& theB,
292 const ModelHighAPI_Double& theC,
293 const ModelHighAPI_Double& theD)
295 // TODO(spo): check that thePart is not empty
296 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
297 return PlanePtr(new ConstructionAPI_Plane(aFeature, theA, theB, theC, theD));
300 //==================================================================================================
301 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
302 const ModelHighAPI_Selection& thePoint1,
303 const ModelHighAPI_Selection& thePoint2,
304 const ModelHighAPI_Selection& thePoint3)
306 // TODO(spo): check that thePart is not empty
307 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
308 return PlanePtr(new ConstructionAPI_Plane(aFeature, thePoint1, thePoint2, thePoint3));
311 //==================================================================================================
312 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
313 const ModelHighAPI_Selection& theLine,
314 const ModelHighAPI_Selection& thePoint,
315 const bool theIsPerpendicular)
317 // TODO(spo): check that thePart is not empty
318 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
319 return PlanePtr(new ConstructionAPI_Plane(aFeature, theLine, thePoint, theIsPerpendicular));
322 //==================================================================================================
323 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
324 const ModelHighAPI_Selection& theObject1,
325 const ModelHighAPI_Selection& theObject2)
327 // TODO(spo): check that thePart is not empty
328 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
329 return PlanePtr(new ConstructionAPI_Plane(aFeature, theObject1, theObject2));
332 //==================================================================================================
333 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
334 const ModelHighAPI_Selection& thePlane,
335 const ModelHighAPI_Selection& theAxis,
336 const ModelHighAPI_Double& theAngle)
338 // TODO(spo): check that thePart is not empty
339 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
340 return PlanePtr(new ConstructionAPI_Plane(aFeature, thePlane, theAxis, theAngle));