Salome HOME
Get rid of compilation warnings. Part I.
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Plane.cpp
1 // Copyright (C) 2014-2020  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ConstructionPlugin_Plane.h"
21
22 #include <Config_PropManager.h>
23
24 #include <GeomAlgoAPI_FaceBuilder.h>
25 #include <GeomAlgoAPI_Rotation.h>
26 #include <GeomAlgoAPI_ShapeTools.h>
27 #include <GeomAlgoAPI_Tools.h>
28
29 #include <GeomAPI_Ax1.h>
30 #include <GeomAPI_Edge.h>
31 #include <GeomAPI_Face.h>
32 #include <GeomAPI_Lin.h>
33 #include <GeomAPI_Pln.h>
34 #include <GeomAPI_Pnt.h>
35 #include <GeomAPI_Pnt2d.h>
36 #include <GeomAPI_ShapeIterator.h>
37 #include <GeomAPI_Vertex.h>
38 #include <GeomAPI_XYZ.h>
39
40 #include <ModelAPI_AttributeDouble.h>
41 #include <ModelAPI_AttributeIntArray.h>
42 #include <ModelAPI_AttributeSelection.h>
43 #include <ModelAPI_AttributeString.h>
44 #include <ModelAPI_AttributeBoolean.h>
45 #include <ModelAPI_ResultConstruction.h>
46 #include <ModelAPI_Session.h>
47 #include <ModelAPI_Validator.h>
48
49
50 static GeomShapePtr faceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theV1,
51                                         const std::shared_ptr<GeomAPI_Vertex> theV2,
52                                         const std::shared_ptr<GeomAPI_Vertex> theV3);
53 static std::shared_ptr<GeomAPI_Face> makeRectangularFace(
54   const std::shared_ptr<GeomAPI_Face> theFace,
55   const std::shared_ptr<GeomAPI_Pln> thePln);
56
57 //==================================================================================================
58 ConstructionPlugin_Plane::ConstructionPlugin_Plane()
59 {
60 }
61
62 //==================================================================================================
63 void ConstructionPlugin_Plane::initAttributes()
64 {
65   data()->addAttribute(ConstructionPlugin_Plane::CREATION_METHOD(),
66                        ModelAPI_AttributeString::typeId());
67
68   data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
69   data()->addAttribute(DISTANCE(), ModelAPI_AttributeDouble::typeId());
70   // By general equation.
71   data()->addAttribute(A(), ModelAPI_AttributeDouble::typeId());
72   data()->addAttribute(B(), ModelAPI_AttributeDouble::typeId());
73   data()->addAttribute(C(), ModelAPI_AttributeDouble::typeId());
74   data()->addAttribute(D(), ModelAPI_AttributeDouble::typeId());
75   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), A());
76   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), B());
77   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), C());
78   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), D());
79
80   // By three points.
81   data()->addAttribute(POINT1(), ModelAPI_AttributeSelection::typeId());
82   data()->addAttribute(POINT2(), ModelAPI_AttributeSelection::typeId());
83   data()->addAttribute(POINT3(), ModelAPI_AttributeSelection::typeId());
84
85   // By line and point.
86   data()->addAttribute(LINE(), ModelAPI_AttributeSelection::typeId());
87   data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
88   data()->addAttribute(PERPENDICULAR(), ModelAPI_AttributeBoolean::typeId());
89
90   // By other plane.
91   data()->addAttribute(CREATION_METHOD_BY_OTHER_PLANE_OPTION(), ModelAPI_AttributeString::typeId());
92   data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
93   data()->addAttribute(COINCIDENT_POINT(), ModelAPI_AttributeSelection::typeId());
94   data()->addAttribute(AXIS(), ModelAPI_AttributeSelection::typeId());
95   data()->addAttribute(ANGLE(), ModelAPI_AttributeDouble::typeId());
96
97   // By two parallel planes.
98   data()->addAttribute(PLANE1(), ModelAPI_AttributeSelection::typeId());
99   data()->addAttribute(PLANE2(), ModelAPI_AttributeSelection::typeId());
100 }
101
102 //==================================================================================================
103 void ConstructionPlugin_Plane::execute()
104 {
105   GeomShapePtr aShape;
106
107   std::string aCreationMethod = string(CREATION_METHOD())->value();
108   if(aCreationMethod == CREATION_METHOD_BY_GENERAL_EQUATION() ||
109       aCreationMethod == "PlaneByGeneralEquation") {
110     aShape = createByGeneralEquation();
111   } else if(aCreationMethod == CREATION_METHOD_BY_THREE_POINTS()) {
112     aShape = createByThreePoints();
113   } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_POINT()) {
114     aShape = createByLineAndPoint();
115   } else if(aCreationMethod == CREATION_METHOD_BY_OTHER_PLANE()) {
116     std::string aCreationMethodOption = string(CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
117     if(aCreationMethodOption == CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
118       aShape = createByDistanceFromOther();
119     } else if(aCreationMethodOption == CREATION_METHOD_BY_COINCIDENT_TO_POINT()) {
120       aShape = createByCoincidentPoint();
121     } else if(aCreationMethodOption == CREATION_METHOD_BY_ROTATION()) {
122       aShape = createByRotation();
123     }
124   } else if(aCreationMethod == CREATION_METHOD_BY_TWO_PARALLEL_PLANES()) {
125     aShape = createByTwoParallelPlanes();
126   } else {
127     setError("Error: Plane creation method \"" + aCreationMethod + "\" not supported.");
128     return;
129   }
130
131   if(!aShape.get()) {
132     setError("Error: Could not create a plane.");
133     return;
134   }
135
136   ResultConstructionPtr aConstr = document()->createConstruction(data());
137   aConstr->setInfinite(true);
138   aConstr->setShape(aShape);
139   setResult(aConstr);
140 }
141
142 //==================================================================================================
143 bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
144                                                 std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
145 {
146   std::vector<int> aColor;
147   // get color from the attribute of the result
148   if (theResult.get() != NULL &&
149       theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
150     AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
151     if (aColorAttr.get() && aColorAttr->size()) {
152       aColor.push_back(aColorAttr->value(0));
153       aColor.push_back(aColorAttr->value(1));
154       aColor.push_back(aColorAttr->value(2));
155     }
156   }
157   if (aColor.empty())
158     aColor = Config_PropManager::color("Visualization", "construction_plane_color");
159
160   bool isCustomized = false;
161   if (aColor.size() == 3)
162     isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
163
164   isCustomized = thePrs->setTransparensy(0.6) || isCustomized;
165
166   return isCustomized;
167 }
168
169 //==================================================================================================
170 std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByGeneralEquation()
171 {
172   AttributeDoublePtr anAttrA = real(ConstructionPlugin_Plane::A());
173   AttributeDoublePtr anAttrB = real(ConstructionPlugin_Plane::B());
174   AttributeDoublePtr anAttrC = real(ConstructionPlugin_Plane::C());
175   AttributeDoublePtr anAttrD = real(ConstructionPlugin_Plane::D());
176   std::shared_ptr<GeomAPI_Shape> aPlaneFace;
177   if ((anAttrA.get() != NULL) && (anAttrB.get() != NULL) &&
178       (anAttrC.get() != NULL) && (anAttrD.get() != NULL) &&
179       anAttrA->isInitialized() && anAttrB->isInitialized() &&
180       anAttrC->isInitialized() && anAttrD->isInitialized() ) {
181     double aA = anAttrA->value(), aB = anAttrB->value(),
182            aC = anAttrC->value(), aD = anAttrD->value();
183     std::shared_ptr<GeomAPI_Pln> aPlane =
184       std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
185     double aSize = Config_PropManager::real(SKETCH_TAB_NAME, "planes_size");
186     if (aSize <= 1.e-7)
187       aSize = 200;  // Set default value
188     aSize *= 4.;
189     aPlaneFace = GeomAlgoAPI_FaceBuilder::squareFace(aPlane, aSize);
190   }
191   return aPlaneFace;
192 }
193
194 //==================================================================================================
195 std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByThreePoints()
196 {
197   // Get first point.
198   AttributeSelectionPtr aPointSelection1 = selection(POINT1());
199   GeomShapePtr aPointShape1 = aPointSelection1->value();
200   if(!aPointShape1.get()) {
201     aPointShape1 = aPointSelection1->context()->shape();
202   }
203   std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
204
205   // Get second point.
206   AttributeSelectionPtr aPointSelection2 = selection(POINT2());
207   GeomShapePtr aPointShape2 = aPointSelection2->value();
208   if(!aPointShape2.get()) {
209     aPointShape2 = aPointSelection2->context()->shape();
210   }
211   std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
212
213   // Get third point.
214   AttributeSelectionPtr aPointSelection3 = selection(POINT3());
215   GeomShapePtr aPointShape3 = aPointSelection3->value();
216   if(!aPointShape3.get()) {
217     aPointShape3 = aPointSelection3->context()->shape();
218   }
219   std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
220
221   GeomShapePtr aRes = faceByThreeVertices(aVertex1, aVertex2, aVertex3);
222
223   return aRes;
224 }
225
226 //==================================================================================================
227 std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByLineAndPoint()
228 {
229   // Get edge.
230   AttributeSelectionPtr anEdgeSelection = selection(LINE());
231   GeomShapePtr aLineShape = anEdgeSelection->value();
232   if(!aLineShape.get()) {
233     aLineShape = anEdgeSelection->context()->shape();
234   }
235   std::shared_ptr<GeomAPI_Edge> anEdge;
236   if (aLineShape->isEdge()) {
237     anEdge = aLineShape->edge();
238   }
239   else if (aLineShape->isCompound()) {
240     GeomAPI_ShapeIterator anIt(aLineShape);
241     anEdge = anIt.current()->edge();
242   }
243   if (!anEdge)
244     return GeomShapePtr();
245
246   // Get point.
247   AttributeSelectionPtr aPointSelection = selection(POINT());
248   GeomShapePtr aPointShape = aPointSelection->value();
249   if(!aPointShape.get()) {
250     aPointShape = aPointSelection->context()->shape();
251   }
252   std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
253
254   // Get perpendicular flag.
255   bool anIsPerpendicular= boolean(PERPENDICULAR())->value();
256
257   GeomShapePtr aRes;
258   if(anIsPerpendicular) {
259     std::shared_ptr<GeomAPI_Lin> aLin = anEdge->line();
260     std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
261     std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(aPnt, aLin->direction()));
262     double aSize = aLin->distance(aPnt) * 2;
263     // point may belong to line, so for the face size use maximum distance between point and line
264     // and the line size (distance between the start and end point)
265     double aDistance = anEdge->firstPoint()->distance(anEdge->lastPoint());
266     aRes = GeomAlgoAPI_FaceBuilder::squareFace(aNewPln, aSize > aDistance ? aSize : aDistance);
267   } else {
268     std::shared_ptr<GeomAPI_Vertex> aV1, aV2;
269     GeomAlgoAPI_ShapeTools::findBounds(anEdge, aV1, aV2);
270     aRes = faceByThreeVertices(aV1, aV2, aVertex);
271   }
272
273   return aRes;
274 }
275
276 //==================================================================================================
277 std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByDistanceFromOther()
278 {
279   AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::PLANE());
280   AttributeDoublePtr aDistAttr = data()->real(ConstructionPlugin_Plane::DISTANCE());
281   std::shared_ptr<GeomAPI_Shape> aPlane;
282   if ((aFaceAttr.get() != NULL) &&
283       (aDistAttr.get() != NULL) &&
284       aFaceAttr->isInitialized() && aDistAttr->isInitialized()) {
285
286     double aDist = aDistAttr->value();
287     bool anIsReverse = boolean(REVERSE())->value();
288     if(anIsReverse) aDist = -aDist;
289     GeomShapePtr aShape = aFaceAttr->value();
290     if (!aShape.get() && aFaceAttr->context()) {
291       aShape = aFaceAttr->context()->shape();
292     }
293
294     if(!aShape.get()) {
295       return aPlane;
296     }
297
298     std::shared_ptr<GeomAPI_Face> aFace;
299     if (aShape->isFace()) {
300       aFace = aShape->face();
301     }
302     else if (aShape->isCompound()) {
303       GeomAPI_ShapeIterator anIt(aShape);
304       aFace = anIt.current()->face();
305     }
306     if (!aFace)
307       return GeomShapePtr();
308
309     std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
310     std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
311     std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
312
313     aOrig->translate(aDir, aDist);
314     std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(aOrig, aDir));
315
316     aPlane = makeRectangularFace(aFace, aNewPln);
317   }
318   return aPlane;
319 }
320
321 //==================================================================================================
322 std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByCoincidentPoint()
323 {
324   // Get face.
325   AttributeSelectionPtr aFaceSelection = selection(PLANE());
326   GeomShapePtr aFaceShape = aFaceSelection->value();
327   if(!aFaceShape.get()) {
328     aFaceShape = aFaceSelection->context()->shape();
329   }
330   std::shared_ptr<GeomAPI_Face> aFace;
331   if (aFaceShape->isFace()) {
332     aFace = aFaceShape->face();
333   }
334   else if (aFaceShape->isCompound()) {
335     GeomAPI_ShapeIterator anIt(aFaceShape);
336     aFace = anIt.current()->face();
337   }
338
339   // Get point.
340   AttributeSelectionPtr aPointSelection = selection(COINCIDENT_POINT());
341   GeomShapePtr aPointShape = aPointSelection->value();
342   if(!aPointShape.get()) {
343     aPointShape = aPointSelection->context()->shape();
344   }
345   std::shared_ptr<GeomAPI_Vertex> aVertex = aPointShape->vertex();
346   if (!aVertex)
347     return GeomShapePtr();
348
349   std::shared_ptr<GeomAPI_Pnt> anOrig = aVertex->point();
350   std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
351   std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
352
353   std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(anOrig, aDir));
354
355   return makeRectangularFace(aFace, aNewPln);
356 }
357
358 //==================================================================================================
359 std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByRotation()
360 {
361   // Get face.
362   AttributeSelectionPtr aFaceSelection = selection(PLANE());
363   GeomShapePtr aFaceShape = aFaceSelection->value();
364   if(!aFaceShape.get()) {
365     aFaceShape = aFaceSelection->context()->shape();
366   }
367   std::shared_ptr<GeomAPI_Face> aFace;
368   if (aFaceShape->isFace()) {
369     aFace = aFaceShape->face();
370   }
371   else if (aFaceShape->isCompound()) {
372     GeomAPI_ShapeIterator anIt(aFaceShape);
373     aFace = anIt.current()->face();
374   }
375   if (!aFace)
376     return GeomShapePtr();
377   aFace = makeRectangularFace(aFace, aFace->getPlane());
378
379   // Get axis.
380   AttributeSelectionPtr anAxisSelection = selection(AXIS());
381   GeomShapePtr anAxisShape = anAxisSelection->value();
382   if(!anAxisShape.get()) {
383     anAxisShape = anAxisSelection->context()->shape();
384   }
385   std::shared_ptr<GeomAPI_Edge> anEdge;
386   if (anAxisShape->isEdge()) {
387     anEdge = anAxisShape->edge();
388   }
389   else if (anAxisShape->isCompound()) {
390     GeomAPI_ShapeIterator anIt(anAxisShape);
391     anEdge = anIt.current()->edge();
392   }
393   if (!anEdge)
394     return GeomShapePtr();
395
396   std::shared_ptr<GeomAPI_Ax1> anAxis =
397     std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
398                                                  anEdge->line()->direction()));
399
400   // Getting angle.
401   double anAngle = real(ANGLE())->value();
402
403   std::shared_ptr<GeomAlgoAPI_Rotation> aRotationAlgo(
404       new GeomAlgoAPI_Rotation(aFace, anAxis, anAngle));
405   // Checking that the algorithm worked properly.
406   std::string anError;
407   if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aRotationAlgo, getKind(), anError)) {
408     setError("Error: Failed to rotate plane");
409     return GeomShapePtr();
410   }
411
412   std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face(aRotationAlgo->shape()));
413   return aRes;
414 }
415
416 //==================================================================================================
417 std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByTwoParallelPlanes()
418 {
419   // Get plane 1.
420   AttributeSelectionPtr aFaceSelection1 = selection(PLANE1());
421   GeomShapePtr aFaceShape1 = aFaceSelection1->value();
422   if(!aFaceShape1.get()) {
423     aFaceShape1 = aFaceSelection1->context()->shape();
424   }
425   std::shared_ptr<GeomAPI_Face> aFace1;
426   if (aFaceShape1->isFace()) {
427     aFace1 = aFaceShape1->face();
428   }
429   else if (aFaceShape1->isCompound()) {
430     GeomAPI_ShapeIterator anIt(aFaceShape1);
431     aFace1 = anIt.current()->face();
432   }
433   if (!aFace1)
434     return GeomShapePtr();
435   std::shared_ptr<GeomAPI_Pln> aPln1 = aFace1->getPlane();
436
437   // Get plane 2.
438   AttributeSelectionPtr aFaceSelection2 = selection(PLANE2());
439   GeomShapePtr aFaceShape2 = aFaceSelection2->value();
440   if(!aFaceShape2.get()) {
441     aFaceShape2 = aFaceSelection2->context()->shape();
442   }
443   std::shared_ptr<GeomAPI_Face> aFace2;
444   if (aFaceShape2->isFace()) {
445     aFace2 = aFaceShape2->face();
446   }
447   else if (aFaceShape2->isCompound()) {
448     GeomAPI_ShapeIterator anIt(aFaceShape2);
449     aFace2 = anIt.current()->face();
450   }
451   if (!aFace2)
452     return GeomShapePtr();
453   std::shared_ptr<GeomAPI_Pln> aPln2 = aFace2->getPlane();
454
455   std::shared_ptr<GeomAPI_Pnt> anOrig1 = aPln1->location();
456   std::shared_ptr<GeomAPI_Pnt> aPntOnPln2 = aPln2->project(anOrig1);
457
458   std::shared_ptr<GeomAPI_Pnt> aNewOrig(new GeomAPI_Pnt(anOrig1->xyz()->added(
459     aPntOnPln2->xyz())->multiplied(0.5)));
460
461   std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(aNewOrig, aPln1->direction()));
462
463   std::shared_ptr<GeomAPI_Face> aRes = makeRectangularFace(aFace1, aNewPln);
464
465   return aRes;
466 }
467
468 //==================================================================================================
469 GeomShapePtr faceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theV1,
470                                  const std::shared_ptr<GeomAPI_Vertex> theV2,
471                                  const std::shared_ptr<GeomAPI_Vertex> theV3)
472 {
473   std::shared_ptr<GeomAPI_Face> aFace =
474     GeomAlgoAPI_FaceBuilder::planarFaceByThreeVertices(theV1, theV2, theV3);
475
476   ListOfShape anObjects;
477   anObjects.push_back(theV1);
478   anObjects.push_back(theV2);
479   anObjects.push_back(theV3);
480   std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints =
481     GeomAlgoAPI_ShapeTools::getBoundingBox(anObjects, 1.0);
482   GeomShapePtr aRes = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aFace, aBoundingPoints);
483
484   return aRes;
485 }
486
487 //==================================================================================================
488 std::shared_ptr<GeomAPI_Face> makeRectangularFace(const std::shared_ptr<GeomAPI_Face> theFace,
489                                                   const std::shared_ptr<GeomAPI_Pln> thePln)
490 {
491   // Create rectangular face close to the selected
492   double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax;
493   theFace->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax);
494
495   // use all 8 points of the bounding box to find the 2D bounds
496   bool isFirst = true;
497   double aMinX2d = DBL_MAX, aMaxX2d = -DBL_MAX;
498   double aMinY2d = DBL_MAX, aMaxY2d = -DBL_MAX;
499   for(int aXIsMin = 0; aXIsMin < 2; aXIsMin++) {
500     for(int aYIsMin = 0; aYIsMin < 2; aYIsMin++) {
501       for(int aZIsMin = 0; aZIsMin < 2; aZIsMin++) {
502         std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(
503           aXIsMin ? aXmin : aXmax, aYIsMin ? aYmin : aYmax, aZIsMin ? Zmin : Zmax));
504         std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aPnt->to2D(thePln);
505         if (isFirst || aPnt2d->x() < aMinX2d)
506           aMinX2d = aPnt2d->x();
507         if (isFirst || aPnt2d->y() < aMinY2d)
508           aMinY2d = aPnt2d->y();
509         if (isFirst || aPnt2d->x() > aMaxX2d)
510           aMaxX2d = aPnt2d->x();
511         if (isFirst || aPnt2d->y() > aMaxY2d)
512           aMaxY2d = aPnt2d->y();
513         if (isFirst)
514           isFirst = !isFirst;
515       }
516     }
517   }
518   double aWgap = (aMaxX2d - aMinX2d) * 0.1;
519   double aHgap = (aMaxY2d - aMinY2d) * 0.1;
520   std::shared_ptr<GeomAPI_Face> aResFace = GeomAlgoAPI_FaceBuilder::planarFace(thePln,
521     aMinX2d - aWgap, aMinY2d - aHgap, aMaxX2d - aMinX2d + 2. * aWgap,
522     aMaxY2d - aMinY2d + 2. * aHgap);
523
524   return aResFace;
525 }