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