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