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_Plane.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 //==================================================================================================
26 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
32 //==================================================================================================
33 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
34 const ModelHighAPI_Selection& theFace,
35 const ModelHighAPI_Double& theDistance,
36 const bool theIsReverse)
37 : ModelHighAPI_Interface(theFeature)
40 setByFaceAndDistance(theFace, theDistance, theIsReverse);
44 //==================================================================================================
45 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
46 const ModelHighAPI_Double& theA,
47 const ModelHighAPI_Double& theB,
48 const ModelHighAPI_Double& theC,
49 const ModelHighAPI_Double& theD)
50 : ModelHighAPI_Interface(theFeature)
53 setByGeneralEquation(theA, theB, theC, theD);
57 //==================================================================================================
58 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
59 const ModelHighAPI_Selection& thePoint1,
60 const ModelHighAPI_Selection& thePoint2,
61 const ModelHighAPI_Selection& thePoint3)
62 : ModelHighAPI_Interface(theFeature)
65 setByThreePoints(thePoint1, thePoint2, thePoint3);
69 //==================================================================================================
70 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
71 const ModelHighAPI_Selection& theLine,
72 const ModelHighAPI_Selection& thePoint,
73 const bool theIsPerpendicular)
74 : ModelHighAPI_Interface(theFeature)
77 setByLineAndPoint(theLine, thePoint, theIsPerpendicular);
81 //==================================================================================================
82 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
83 const ModelHighAPI_Selection& theObject1,
84 const ModelHighAPI_Selection& theObject2)
85 : ModelHighAPI_Interface(theFeature)
88 GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
89 GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
90 if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::VERTEX) {
91 setByCoincidentToPoint(theObject1, theObject2);
92 } else if(aType1 == GeomAPI_Shape::FACE && aType2 == GeomAPI_Shape::FACE) {
93 setByTwoParallelPlanes(theObject1, theObject2);
98 //==================================================================================================
99 ConstructionAPI_Plane::ConstructionAPI_Plane(const std::shared_ptr<ModelAPI_Feature>& theFeature,
100 const ModelHighAPI_Selection& thePlane,
101 const ModelHighAPI_Selection& theAxis,
102 const ModelHighAPI_Double& theAngle)
103 : ModelHighAPI_Interface(theFeature)
106 setByRotation(thePlane, theAxis, theAngle);
110 //==================================================================================================
111 ConstructionAPI_Plane::~ConstructionAPI_Plane()
115 //==================================================================================================
116 void ConstructionAPI_Plane::setByFaceAndDistance(const ModelHighAPI_Selection& theFace,
117 const ModelHighAPI_Double& theDistance,
118 const bool theIsReverse)
120 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
121 fillAttribute(theFace, myplane);
122 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER(),
123 mycreationMethodByOtherPlane);
124 fillAttribute(theDistance, mydistance);
125 fillAttribute(theIsReverse, myreverse);
130 //==================================================================================================
131 void ConstructionAPI_Plane::setByGeneralEquation(const ModelHighAPI_Double& theA,
132 const ModelHighAPI_Double& theB,
133 const ModelHighAPI_Double& theC,
134 const ModelHighAPI_Double& theD)
136 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION(), mycreationMethod);
137 fillAttribute(theA, myA);
138 fillAttribute(theB, myB);
139 fillAttribute(theC, myC);
140 fillAttribute(theD, myD);
145 //==================================================================================================
146 void ConstructionAPI_Plane::setByThreePoints(const ModelHighAPI_Selection& thePoint1,
147 const ModelHighAPI_Selection& thePoint2,
148 const ModelHighAPI_Selection& thePoint3)
150 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
151 fillAttribute(thePoint1, mypoint1);
152 fillAttribute(thePoint2, mypoint2);
153 fillAttribute(thePoint3, mypoint3);
158 //==================================================================================================
159 void ConstructionAPI_Plane::setByLineAndPoint(const ModelHighAPI_Selection& theLine,
160 const ModelHighAPI_Selection& thePoint,
161 const bool theIsPerpendicular)
163 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT(), mycreationMethod);
164 fillAttribute(theLine, myline);
165 fillAttribute(thePoint, mypoint);
166 fillAttribute(theIsPerpendicular, myperpendicular);
171 //==================================================================================================
172 void ConstructionAPI_Plane::setByTwoParallelPlanes(const ModelHighAPI_Selection& thePlane1,
173 const ModelHighAPI_Selection& thePlane2)
175 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES(),
177 fillAttribute(thePlane1, myplane1);
178 fillAttribute(thePlane2, myplane2);
183 //==================================================================================================
184 void ConstructionAPI_Plane::setByCoincidentToPoint(const ModelHighAPI_Selection& thePlane,
185 const ModelHighAPI_Selection& thePoint)
187 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
188 fillAttribute(thePlane, myplane);
189 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT(),
190 mycreationMethodByOtherPlane);
191 fillAttribute(thePoint, mycoincidentPoint);
196 //==================================================================================================
197 void ConstructionAPI_Plane::setByRotation(const ModelHighAPI_Selection& thePlane,
198 const ModelHighAPI_Selection& theAxis,
199 const ModelHighAPI_Double& theAngle)
201 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
202 fillAttribute(thePlane, myplane);
203 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION(),
204 mycreationMethodByOtherPlane);
205 fillAttribute(theAxis, myaxis);
206 fillAttribute(theAngle, myangle);
211 //==================================================================================================
212 void ConstructionAPI_Plane::dump(ModelHighAPI_Dumper& theDumper) const
214 FeaturePtr aBase = feature();
215 const std::string& aDocName = theDumper.name(aBase->document());
217 theDumper << aBase << " = model.addPlane(" << aDocName;
219 std::string aCreationMethod =
220 aBase->string(ConstructionPlugin_Plane::CREATION_METHOD())->value();
222 if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION()) {
223 AttributeDoublePtr anAttrA = aBase->real(ConstructionPlugin_Plane::A());
224 AttributeDoublePtr anAttrB = aBase->real(ConstructionPlugin_Plane::B());
225 AttributeDoublePtr anAttrC = aBase->real(ConstructionPlugin_Plane::C());
226 AttributeDoublePtr anAttrD = aBase->real(ConstructionPlugin_Plane::D());
228 theDumper << ", " << anAttrA << ", " << anAttrB << ", " << anAttrC << ", " << anAttrD;
229 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS()) {
230 AttributeSelectionPtr anAttrPnt1 = aBase->selection(ConstructionPlugin_Plane::POINT1());
231 AttributeSelectionPtr anAttrPnt2 = aBase->selection(ConstructionPlugin_Plane::POINT2());
232 AttributeSelectionPtr anAttrPnt3 = aBase->selection(ConstructionPlugin_Plane::POINT3());
234 theDumper << ", " << anAttrPnt1 << ", " << anAttrPnt2 << ", " << anAttrPnt3;
235 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT()) {
236 AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Plane::LINE());
237 AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Plane::POINT());
238 AttributeBooleanPtr anAttrPerpendicular =
239 aBase->boolean(ConstructionPlugin_Plane::PERPENDICULAR());
241 theDumper << ", " << anAttrLine << ", " << anAttrPoint << ", " << anAttrPerpendicular;
242 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE()) {
243 AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Plane::PLANE());
245 std::string aCreationMethodOption =
246 aBase->string(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
247 if(aCreationMethodOption ==
248 ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
249 AttributeDoublePtr anAttrDistance = aBase->real(ConstructionPlugin_Plane::DISTANCE());
250 AttributeBooleanPtr anAttrReverse = aBase->boolean(ConstructionPlugin_Plane::REVERSE());
252 theDumper << ", " << anAttrPlane << ", " << anAttrDistance << ", " << anAttrReverse;
253 } else if(aCreationMethodOption ==
254 ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
255 AttributeSelectionPtr anAttrPoint =
256 aBase->selection(ConstructionPlugin_Plane::COINCIDENT_POINT());
258 theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
259 } else if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION()) {
260 AttributeSelectionPtr anAttrAxis = aBase->selection(ConstructionPlugin_Plane::AXIS());
261 AttributeDoublePtr anAttrAngle = aBase->real(ConstructionPlugin_Plane::ANGLE());
263 theDumper << ", " << anAttrPlane << ", " << anAttrAxis << ", " << anAttrAngle;
265 } else if(aCreationMethod ==
266 ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES()) {
267 AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Plane::PLANE1());
268 AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Plane::PLANE2());
270 theDumper << ", " << anAttrPlane1 << ", " << anAttrPlane2;
273 theDumper << ")" << std::endl;
276 //==================================================================================================
277 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
278 const ModelHighAPI_Selection& theFace,
279 const ModelHighAPI_Double& theDistance,
280 const bool theIsReverse)
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, theFace, theDistance, theIsReverse));
287 //==================================================================================================
288 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
289 const ModelHighAPI_Double& theA,
290 const ModelHighAPI_Double& theB,
291 const ModelHighAPI_Double& theC,
292 const ModelHighAPI_Double& theD)
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, theA, theB, theC, theD));
299 //==================================================================================================
300 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
301 const ModelHighAPI_Selection& thePoint1,
302 const ModelHighAPI_Selection& thePoint2,
303 const ModelHighAPI_Selection& thePoint3)
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, thePoint1, thePoint2, thePoint3));
310 //==================================================================================================
311 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
312 const ModelHighAPI_Selection& theLine,
313 const ModelHighAPI_Selection& thePoint,
314 const bool theIsPerpendicular)
316 // TODO(spo): check that thePart is not empty
317 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
318 return PlanePtr(new ConstructionAPI_Plane(aFeature, theLine, thePoint, theIsPerpendicular));
321 //==================================================================================================
322 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
323 const ModelHighAPI_Selection& theObject1,
324 const ModelHighAPI_Selection& theObject2)
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, theObject1, theObject2));
331 //==================================================================================================
332 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
333 const ModelHighAPI_Selection& thePlane,
334 const ModelHighAPI_Selection& theAxis,
335 const ModelHighAPI_Double& theAngle)
337 // TODO(spo): check that thePart is not empty
338 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
339 return PlanePtr(new ConstructionAPI_Plane(aFeature, thePlane, theAxis, theAngle));