1 // Copyright (C) 2014-2023 CEA, EDF
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 const ModelHighAPI_Integer& theNbCopy)
38 : ModelHighAPI_Interface(theFeature)
41 setByFaceAndDistance(theFace, theDistance, theIsReverse, theNbCopy);
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 const ModelHighAPI_Integer& theNbCopy)
105 : ModelHighAPI_Interface(theFeature)
108 setByRotation(thePlane, theAxis, theAngle, theNbCopy);
112 //==================================================================================================
113 ConstructionAPI_Plane::~ConstructionAPI_Plane()
117 //==================================================================================================
118 void ConstructionAPI_Plane::setByFaceAndDistance(const ModelHighAPI_Selection& theFace,
119 const ModelHighAPI_Double& theDistance,
120 const bool theIsReverse,
121 const ModelHighAPI_Integer& theNbCopy)
123 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
124 fillAttribute(theFace, myplane);
125 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER(),
126 mycreationMethodByOtherPlane);
127 fillAttribute(theDistance, mydistance);
128 fillAttribute(theIsReverse, myreverse);
129 fillAttribute(theNbCopy, mynbcopy);
134 //==================================================================================================
135 void ConstructionAPI_Plane::setByGeneralEquation(const ModelHighAPI_Double& theA,
136 const ModelHighAPI_Double& theB,
137 const ModelHighAPI_Double& theC,
138 const ModelHighAPI_Double& theD)
140 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION(), mycreationMethod);
141 fillAttribute(theA, myA);
142 fillAttribute(theB, myB);
143 fillAttribute(theC, myC);
144 fillAttribute(theD, myD);
149 //==================================================================================================
150 void ConstructionAPI_Plane::setByThreePoints(const ModelHighAPI_Selection& thePoint1,
151 const ModelHighAPI_Selection& thePoint2,
152 const ModelHighAPI_Selection& thePoint3)
154 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS(), mycreationMethod);
155 fillAttribute(thePoint1, mypoint1);
156 fillAttribute(thePoint2, mypoint2);
157 fillAttribute(thePoint3, mypoint3);
162 //==================================================================================================
163 void ConstructionAPI_Plane::setByLineAndPoint(const ModelHighAPI_Selection& theLine,
164 const ModelHighAPI_Selection& thePoint,
165 const bool theIsPerpendicular)
167 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT(), mycreationMethod);
168 fillAttribute(theLine, myline);
169 fillAttribute(thePoint, mypoint);
170 fillAttribute(theIsPerpendicular, myperpendicular);
175 //==================================================================================================
176 void ConstructionAPI_Plane::setByTwoParallelPlanes(const ModelHighAPI_Selection& thePlane1,
177 const ModelHighAPI_Selection& thePlane2)
179 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES(),
181 fillAttribute(thePlane1, myplane1);
182 fillAttribute(thePlane2, myplane2);
187 //==================================================================================================
188 void ConstructionAPI_Plane::setByCoincidentToPoint(const ModelHighAPI_Selection& thePlane,
189 const ModelHighAPI_Selection& thePoint)
191 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
192 fillAttribute(thePlane, myplane);
193 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT(),
194 mycreationMethodByOtherPlane);
195 fillAttribute(thePoint, mycoincidentPoint);
200 //==================================================================================================
201 void ConstructionAPI_Plane::setByRotation(const ModelHighAPI_Selection& thePlane,
202 const ModelHighAPI_Selection& theAxis,
203 const ModelHighAPI_Double& theAngle,
204 const ModelHighAPI_Integer& theNbCopy)
206 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE(), mycreationMethod);
207 fillAttribute(thePlane, myplane);
208 fillAttribute(ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION(),
209 mycreationMethodByOtherPlane);
210 fillAttribute(theAxis, myaxis);
211 fillAttribute(theAngle, myangle);
212 fillAttribute(theNbCopy, mynbcopy);
217 //==================================================================================================
218 void ConstructionAPI_Plane::dump(ModelHighAPI_Dumper& theDumper) const
220 FeaturePtr aBase = feature();
221 const std::string& aDocName = theDumper.name(aBase->document());
223 theDumper << aBase << " = model.addPlane(" << aDocName;
225 std::string aCreationMethod =
226 aBase->string(ConstructionPlugin_Plane::CREATION_METHOD())->value();
228 if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_GENERAL_EQUATION()) {
229 AttributeDoublePtr anAttrA = aBase->real(ConstructionPlugin_Plane::A());
230 AttributeDoublePtr anAttrB = aBase->real(ConstructionPlugin_Plane::B());
231 AttributeDoublePtr anAttrC = aBase->real(ConstructionPlugin_Plane::C());
232 AttributeDoublePtr anAttrD = aBase->real(ConstructionPlugin_Plane::D());
234 theDumper << ", " << anAttrA << ", " << anAttrB << ", " << anAttrC << ", " << anAttrD;
235 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_THREE_POINTS()) {
236 AttributeSelectionPtr anAttrPnt1 = aBase->selection(ConstructionPlugin_Plane::POINT1());
237 AttributeSelectionPtr anAttrPnt2 = aBase->selection(ConstructionPlugin_Plane::POINT2());
238 AttributeSelectionPtr anAttrPnt3 = aBase->selection(ConstructionPlugin_Plane::POINT3());
240 theDumper << ", " << anAttrPnt1 << ", " << anAttrPnt2 << ", " << anAttrPnt3;
241 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_LINE_AND_POINT()) {
242 AttributeSelectionPtr anAttrLine = aBase->selection(ConstructionPlugin_Plane::LINE());
243 AttributeSelectionPtr anAttrPoint = aBase->selection(ConstructionPlugin_Plane::POINT());
244 AttributeBooleanPtr anAttrPerpendicular =
245 aBase->boolean(ConstructionPlugin_Plane::PERPENDICULAR());
247 theDumper << ", " << anAttrLine << ", " << anAttrPoint << ", " << anAttrPerpendicular;
248 } else if(aCreationMethod == ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE()) {
249 AttributeSelectionPtr anAttrPlane = aBase->selection(ConstructionPlugin_Plane::PLANE());
251 std::string aCreationMethodOption =
252 aBase->string(ConstructionPlugin_Plane::CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
253 if(aCreationMethodOption ==
254 ConstructionPlugin_Plane::CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
255 AttributeDoublePtr anAttrDistance = aBase->real(ConstructionPlugin_Plane::DISTANCE());
256 AttributeBooleanPtr anAttrReverse = aBase->boolean(ConstructionPlugin_Plane::REVERSE());
257 AttributeIntegerPtr anAttrNbCopy = aBase->integer(ConstructionPlugin_Plane::NB_COPIES());
259 theDumper << ", " << anAttrPlane << ", " << anAttrDistance << ", " << anAttrReverse;
260 if(anAttrNbCopy.get() && anAttrNbCopy->value() > 1)
261 theDumper << ", " << anAttrNbCopy;
262 } else if(aCreationMethodOption ==
263 ConstructionPlugin_Plane::CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
264 AttributeSelectionPtr anAttrPoint =
265 aBase->selection(ConstructionPlugin_Plane::COINCIDENT_POINT());
267 theDumper << ", " << anAttrPlane << ", " << anAttrPoint;
268 } else if(aCreationMethodOption == ConstructionPlugin_Plane::CREATION_METHOD_BY_ROTATION()) {
269 AttributeSelectionPtr anAttrAxis = aBase->selection(ConstructionPlugin_Plane::AXIS());
270 AttributeDoublePtr anAttrAngle = aBase->real(ConstructionPlugin_Plane::ANGLE());
271 AttributeIntegerPtr anAttrNbCopy = aBase->integer(ConstructionPlugin_Plane::NB_COPIES());
273 theDumper << ", " << anAttrPlane << ", " << anAttrAxis << ", " << anAttrAngle;
274 if (anAttrNbCopy.get() && anAttrNbCopy->value() > 1)
275 theDumper << ", " << anAttrNbCopy;
277 } else if(aCreationMethod ==
278 ConstructionPlugin_Plane::CREATION_METHOD_BY_TWO_PARALLEL_PLANES()) {
279 AttributeSelectionPtr anAttrPlane1 = aBase->selection(ConstructionPlugin_Plane::PLANE1());
280 AttributeSelectionPtr anAttrPlane2 = aBase->selection(ConstructionPlugin_Plane::PLANE2());
282 theDumper << ", " << anAttrPlane1 << ", " << anAttrPlane2;
285 theDumper << ")" << std::endl;
288 //==================================================================================================
289 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
290 const ModelHighAPI_Selection& theFace,
291 const ModelHighAPI_Double& theDistance,
292 const bool theIsReverse,
293 const ModelHighAPI_Integer& theNbCopies)
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, theFace, theDistance,
298 theIsReverse, theNbCopies));
301 //==================================================================================================
302 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
303 const ModelHighAPI_Double& theA,
304 const ModelHighAPI_Double& theB,
305 const ModelHighAPI_Double& theC,
306 const ModelHighAPI_Double& theD)
308 // TODO(spo): check that thePart is not empty
309 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
310 return PlanePtr(new ConstructionAPI_Plane(aFeature, theA, theB, theC, theD));
313 //==================================================================================================
314 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
315 const ModelHighAPI_Selection& thePoint1,
316 const ModelHighAPI_Selection& thePoint2,
317 const ModelHighAPI_Selection& thePoint3)
319 // TODO(spo): check that thePart is not empty
320 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
321 return PlanePtr(new ConstructionAPI_Plane(aFeature, thePoint1, thePoint2, thePoint3));
324 //==================================================================================================
325 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
326 const ModelHighAPI_Selection& theLine,
327 const ModelHighAPI_Selection& thePoint,
328 const bool theIsPerpendicular)
330 // TODO(spo): check that thePart is not empty
331 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
332 return PlanePtr(new ConstructionAPI_Plane(aFeature, theLine, thePoint, theIsPerpendicular));
335 //==================================================================================================
336 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
337 const ModelHighAPI_Selection& theObject1,
338 const ModelHighAPI_Selection& theObject2)
340 // TODO(spo): check that thePart is not empty
341 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
342 return PlanePtr(new ConstructionAPI_Plane(aFeature, theObject1, theObject2));
345 //==================================================================================================
346 PlanePtr addPlane(const std::shared_ptr<ModelAPI_Document>& thePart,
347 const ModelHighAPI_Selection& thePlane,
348 const ModelHighAPI_Selection& theAxis,
349 const ModelHighAPI_Double& theAngle,
350 const ModelHighAPI_Integer& theNbCopies)
352 // TODO(spo): check that thePart is not empty
353 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Plane::ID());
354 return PlanePtr(new ConstructionAPI_Plane(aFeature, thePlane, theAxis, theAngle, theNbCopies));