Salome HOME
Compsolids creation in revolution
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Revolution.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_Revolution.cpp
4 // Created:     12 May 2015
5 // Author:      Dmitry Bobylev
6
7 #include <GeomAlgoAPI_Revolution.h>
8
9 #include <GeomAPI_Face.h>
10 #include <GeomAPI_ShapeExplorer.h>
11 #include <GeomAlgoAPI_DFLoader.h>
12 #include <GeomAlgoAPI_MakeShapeList.h>
13 #include <GeomAlgoAPI_Rotation.h>
14 #include <GeomAlgoAPI_ShapeTools.h>
15
16 #include <BRep_Builder.hxx>
17 #include <BRep_Tool.hxx>
18 #include <BRepAlgoAPI_Cut.hxx>
19 #include <BRepBuilderAPI_MakeEdge.hxx>
20 #include <BRepBuilderAPI_MakeFace.hxx>
21 #include <BRepBuilderAPI_Transform.hxx>
22 #include <BRepBuilderAPI_MakeWire.hxx>
23 #include <BRepCheck_Analyzer.hxx>
24 #include <BRepPrimAPI_MakeRevol.hxx>
25 #include <BRepGProp.hxx>
26 #include <BRepOffsetAPI_MakePipe.hxx>
27 #include <BRepTools.hxx>
28 #include <Geom_Circle.hxx>
29 #include <Geom_Line.hxx>
30 #include <Geom_Plane.hxx>
31 #include <GeomAPI_ProjectPointOnCurve.hxx>
32 #include <GeomLib_IsPlanarSurface.hxx>
33 #include <gp_Circ.hxx>
34 #include <gp_Pln.hxx>
35 #include <GProp_GProps.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <TopoDS.hxx>
38 #include <TopTools_ListIteratorOfListOfShape.hxx>
39
40 //=================================================================================================
41 GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(std::shared_ptr<GeomAPI_Shape> theBasis,
42                                                std::shared_ptr<GeomAPI_Ax1>   theAxis,
43                                                double                         theToAngle,
44                                                double                         theFromAngle)
45 : myDone(false)
46 {
47   build(theBasis, theAxis, std::shared_ptr<GeomAPI_Shape>(), theToAngle, std::shared_ptr<GeomAPI_Shape>(), theFromAngle);
48 }
49
50 //=================================================================================================
51 GeomAlgoAPI_Revolution::GeomAlgoAPI_Revolution(std::shared_ptr<GeomAPI_Shape> theBasis,
52                                                std::shared_ptr<GeomAPI_Ax1>   theAxis,
53                                                std::shared_ptr<GeomAPI_Shape> theToShape,
54                                                double                         theToAngle,
55                                                std::shared_ptr<GeomAPI_Shape> theFromShape,
56                                                double                         theFromAngle)
57 : myDone(false)
58 {
59   build(theBasis, theAxis, theToShape, theToAngle, theFromShape, theFromAngle);
60 }
61
62 //=================================================================================================
63 TopoDS_Face GeomAlgoAPI_Revolution::makeFaceFromPlane(gp_Pln& thePlane, const gp_Pnt& thePoint)
64 {
65   gp_XYZ aVec = thePoint.XYZ() - thePlane.Location().XYZ();
66   double aSign = aVec * thePlane.Axis().Direction().XYZ();
67   if(aSign < 0) thePlane.SetAxis(thePlane.Axis().Reversed());
68
69   BRepBuilderAPI_MakeFace aMakeFace(thePlane);
70   TopoDS_Face aResultFace = TopoDS::Face(aMakeFace.Shape());
71
72   return aResultFace;
73 }
74
75 //=================================================================================================
76 TopoDS_Solid GeomAlgoAPI_Revolution::makeSolidFromShape(const TopoDS_Shape& theShape)
77 {
78   TopoDS_Shell aShell;
79   TopoDS_Solid aSolid;
80
81   BRep_Builder aBoundingBuilder;
82   if(theShape.ShapeType() == TopAbs_SHELL) {
83     aShell = TopoDS::Shell(theShape);
84   } else {
85     aBoundingBuilder.MakeShell(aShell);
86     aBoundingBuilder.Add(aShell, theShape);
87   }
88   aBoundingBuilder.MakeSolid(aSolid);
89   aBoundingBuilder.Add(aSolid, aShell);
90
91   return aSolid;
92 }
93
94 //=================================================================================================
95 TopoDS_Shape GeomAlgoAPI_Revolution::findClosest(const TopoDS_Shape& theShape, const gp_Pnt& thePoint)
96 {
97   TopoDS_Shape aResult = theShape;
98
99   if(theShape.ShapeType() == TopAbs_COMPOUND) {
100     double aMinDistance = Precision::Infinite();
101     double aCurDistance;
102     GProp_GProps aGProps;
103     gp_Pnt aCentr;
104
105     for (TopoDS_Iterator anItr(theShape); anItr.More(); anItr.Next()) {
106       TopoDS_Shape aValue = anItr.Value();
107       BRepGProp::VolumeProperties(aValue, aGProps);
108       aCentr = aGProps.CentreOfMass();
109       aCurDistance = aCentr.Distance(thePoint);
110
111       if(aCurDistance < aMinDistance) {
112         aMinDistance = aCurDistance;
113         aResult = aValue;
114       }
115     }
116   }
117
118   return aResult;
119 }
120
121 //=================================================================================================
122 void GeomAlgoAPI_Revolution::build(const std::shared_ptr<GeomAPI_Shape>& theBasis,
123                                    const std::shared_ptr<GeomAPI_Ax1>&   theAxis,
124                                    const std::shared_ptr<GeomAPI_Shape>& theToShape,
125                                    double                                theToAngle,
126                                    const std::shared_ptr<GeomAPI_Shape>& theFromShape,
127                                    double                                theFromAngle)
128 {
129   if(!theBasis || !theAxis ||
130     (((!theFromShape && !theToShape) || (theFromShape && theToShape && theFromShape->isEqual(theToShape)))
131     && (theFromAngle == -theToAngle))) {
132     return;
133   }
134
135   // Checking that shell is planar.
136   TopoDS_Shape aBasis = theBasis->impl<TopoDS_Shape>();
137   // TODO: fix planar checking
138   //TopExp_Explorer aBasisExp(aBasis, TopAbs_FACE);
139   //for(; aBasisExp.More(); aBasisExp.Next()) {
140   //  const TopoDS_Shape& aCurSh = aBasisExp.Current();
141   //}
142
143   // Geting base plane.
144   std::shared_ptr<GeomAPI_Face> aBaseFace;
145   if(theBasis->shapeType() == GeomAPI_Shape::SHELL) {
146     GeomAPI_ShapeExplorer anExp(theBasis, GeomAPI_Shape::FACE);
147     if(anExp.more()) {
148       std::shared_ptr<GeomAPI_Shape> aFaceOnShell = anExp.current();
149       aBaseFace = std::shared_ptr<GeomAPI_Face>(new GeomAPI_Face(aFaceOnShell));
150     }
151   } else {
152     aBaseFace = std::shared_ptr<GeomAPI_Face>(new GeomAPI_Face(theBasis));
153   }
154   if(!aBaseFace.get()) {
155     return;
156   }
157   TopoDS_Face aBasisFace = TopoDS::Face(aBaseFace->impl<TopoDS_Shape>());
158   GeomLib_IsPlanarSurface isBasisPlanar(BRep_Tool::Surface(aBasisFace));
159   gp_Pln aBasisPln = isBasisPlanar.Plan();
160   Geom_Plane aBasisPlane(aBasisPln);
161
162   // Creating circle for pipe.
163   gp_Pnt aBasisCentre = GeomAlgoAPI_ShapeTools::centreOfMass(theBasis)->impl<gp_Pnt>();
164   const TopoDS_Shape& aBasisShape = theBasis->impl<TopoDS_Shape>();
165   gp_Ax1 anAxis = theAxis->impl<gp_Ax1>();
166   gp_Lin anAxisLin(anAxis);
167   Handle(Geom_Line) anAxisLine = new Geom_Line(anAxis);
168   GeomAPI_ProjectPointOnCurve aProjection(aBasisCentre, anAxisLine);
169   if(aProjection.NbPoints() != 1) {
170     return;
171   }
172   Standard_Real aRadius = aProjection.Distance(1);
173   gp_Circ aCircle(gp_Ax2(aProjection.NearestPoint(), anAxis.Direction()), aRadius);
174
175   TopoDS_Shape aResult;
176   ListOfMakeShape aListOfMakeShape;
177   if(!theFromShape && !theToShape) { // Case 1: When only angles was set.
178     // Rotating base face with the negative value of "from angle".
179     gp_Trsf aBaseTrsf;
180     aBaseTrsf.SetRotation(anAxis, -theFromAngle / 180.0 * M_PI);
181     gp_Pnt aFromPnt = aBasisCentre.Transformed(aBaseTrsf);
182     aCircle = gp_Circ(gp_Ax2(aProjection.NearestPoint(), anAxis.Direction(), gp_Vec(aProjection.NearestPoint(), aFromPnt)),
183                       aRadius);
184     BRepBuilderAPI_Transform* aBaseTransform = new BRepBuilderAPI_Transform(aBasisShape,
185                                                                             aBaseTrsf,
186                                                                             true);
187     if(!aBaseTransform || !aBaseTransform->IsDone()) {
188       return;
189     }
190     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aBaseTransform)));
191     TopoDS_Shape aRotatedBaseShape = aBaseTransform->Shape();
192
193     // Making wire for pipe.
194     TopoDS_Edge aPipeEdge = BRepBuilderAPI_MakeEdge(aCircle, 0, (theFromAngle + theToAngle) / 180.0 * M_PI);
195     TopoDS_Wire aPipeWire = BRepBuilderAPI_MakeWire(aPipeEdge).Wire();
196
197     // Making pipe.
198     BRepOffsetAPI_MakePipe* aPipeBuilder = new BRepOffsetAPI_MakePipe(aPipeWire, aRotatedBaseShape);
199     if(!aPipeBuilder || !aPipeBuilder->IsDone()) {
200       return;
201     }
202     std::shared_ptr<GeomAPI_Shape> aWire(new GeomAPI_Shape);
203     std::shared_ptr<GeomAPI_Shape> aBShape(new GeomAPI_Shape);
204     aWire->setImpl(new TopoDS_Shape(aPipeWire));
205     aBShape->setImpl(new TopoDS_Shape(aRotatedBaseShape));
206     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aPipeBuilder, aWire, aBShape)));
207     aResult = aPipeBuilder->Shape();
208     TopoDS_Shape aToShape = aPipeBuilder->LastShape();
209     TopoDS_Shape aFromShape = aPipeBuilder->FirstShape();
210
211     // Setting naming.
212     TopExp_Explorer anExp(aToShape, TopAbs_FACE);
213     for(; anExp.More(); anExp.Next()) {
214       std::shared_ptr<GeomAPI_Shape> aTSHape(new GeomAPI_Shape);
215       aTSHape->setImpl(new TopoDS_Shape(anExp.Current()));
216       myToFaces.push_back(aTSHape);
217     }
218     anExp.Init(aFromShape, TopAbs_FACE);
219     for(; anExp.More(); anExp.Next()) {
220       std::shared_ptr<GeomAPI_Shape> aFSHape(new GeomAPI_Shape);
221       aFSHape->setImpl(new TopoDS_Shape(anExp.Current()));
222       myFromFaces.push_back(aFSHape);
223     }
224   } else if(theFromShape && theToShape) { // Case 2: When both bounding planes were set.
225     // Getting bounding faces.
226     TopoDS_Face aFromFace = TopoDS::Face(theFromShape->impl<TopoDS_Shape>());
227     TopoDS_Face aToFace   = TopoDS::Face(theToShape->impl<TopoDS_Shape>());
228
229     // Getting planes from bounding face.
230     GeomLib_IsPlanarSurface isFromPlanar(BRep_Tool::Surface(aFromFace));
231     GeomLib_IsPlanarSurface isToPlanar(BRep_Tool::Surface(aToFace));
232     if(!isFromPlanar.IsPlanar() || !isToPlanar.IsPlanar()) {// non-planar shapes is not supported for revolution bounding
233       return;
234     }
235     gp_Pln aFromPln = isFromPlanar.Plan();
236     gp_Pln aToPln   = isToPlanar.Plan();
237
238     // Orienting bounding planes properly so that the center of mass of the base face stays
239     // on the result shape after cut.
240     aFromFace = makeFaceFromPlane(aFromPln, aBasisCentre);
241     aToFace   = makeFaceFromPlane(aToPln, aBasisCentre);
242
243     // Making solids from bounding planes and putting them in compound.
244     TopoDS_Shape aFromSolid = makeSolidFromShape(aFromFace);
245     TopoDS_Shape aToSolid   = makeSolidFromShape(aToFace);
246
247     // Rotating bounding planes to the specified angle.
248     gp_Trsf aFromTrsf;
249     gp_Trsf aToTrsf;
250     double aFromRotAngle = ((aFromPln.Axis().Direction() * aBasisPln.Axis().Direction()) > 0) ? -theFromAngle : theFromAngle;
251     double aToRotAngle = ((aToPln.Axis().Direction() * aBasisPln.Axis().Direction()) > 0) ? -theToAngle : theToAngle;
252     aFromTrsf.SetRotation(anAxis,aFromRotAngle / 180.0 * M_PI);
253     aToTrsf.SetRotation(anAxis, aToRotAngle / 180.0 * M_PI);
254     BRepBuilderAPI_Transform aFromTransform(aFromSolid, aFromTrsf, true);
255     BRepBuilderAPI_Transform aToTransform(aToSolid, aToTrsf, true);
256     TopoDS_Shape aRotatedFromFace = aFromTransform.Modified(aFromFace).First();
257     TopoDS_Shape aRotatedToFace = aToTransform.Modified(aToFace).First();
258     aFromSolid = aFromTransform.Shape();
259     aToSolid = aToTransform.Shape();
260
261     // Making wire for pipe.
262     TopoDS_Edge aPipeEdge = BRepBuilderAPI_MakeEdge(aCircle, 0, 2 * M_PI);
263     TopoDS_Wire aPipeWire = BRepBuilderAPI_MakeWire(aPipeEdge).Wire();
264
265     // Making pipe.
266     BRepOffsetAPI_MakePipe* aPipeBuilder = new BRepOffsetAPI_MakePipe(aPipeWire, aBasisShape);
267     if(!aPipeBuilder || !aPipeBuilder->IsDone()) {
268       return;
269     }
270     std::shared_ptr<GeomAPI_Shape> aWire(new GeomAPI_Shape);
271     std::shared_ptr<GeomAPI_Shape> aBShape(new GeomAPI_Shape);
272     aWire->setImpl(new TopoDS_Shape(aPipeWire));
273     aBShape->setImpl(new TopoDS_Shape(aBasisShape));
274     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aPipeBuilder, aWire, aBShape)));
275     aResult = aPipeBuilder->Shape();
276
277     // Cutting revolution with from plane.
278     BRepAlgoAPI_Cut* aFromCutBuilder = new BRepAlgoAPI_Cut(aResult, aFromSolid);
279     aFromCutBuilder->Build();
280     if(!aFromCutBuilder->IsDone()) {
281       return;
282     }
283     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aFromCutBuilder)));
284     aResult = aFromCutBuilder->Shape();
285
286     // Cutting revolution with to plane.
287     BRepAlgoAPI_Cut* aToCutBuilder = new BRepAlgoAPI_Cut(aResult, aToSolid);
288     aToCutBuilder->Build();
289     if(!aToCutBuilder->IsDone()) {
290       return;
291     }
292     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aToCutBuilder)));
293     aResult = aToCutBuilder->Shape();
294
295     // If after cut we got more than one solids then take closest to the center of mass of the base face.
296     //aResult = findClosest(aResult, aBasisCentre);
297
298     // Setting naming.
299     for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) {
300       const TopoDS_Shape& aFaceOnResult = anExp.Current();
301       Handle(Geom_Surface) aFaceSurface = BRep_Tool::Surface(TopoDS::Face(aFaceOnResult));
302       Handle(Geom_Surface) aFromSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedFromFace));
303       Handle(Geom_Surface) aToSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedToFace));
304       if(aFaceSurface == aFromSurface) {
305         std::shared_ptr<GeomAPI_Shape> aFSHape(new GeomAPI_Shape);
306         aFSHape->setImpl(new TopoDS_Shape(aFaceOnResult));
307         myFromFaces.push_back(aFSHape);
308       }
309       if(aFaceSurface == aToSurface) {
310         std::shared_ptr<GeomAPI_Shape> aTSHape(new GeomAPI_Shape);
311         aTSHape->setImpl(new TopoDS_Shape(aFaceOnResult));
312         myToFaces.push_back(aTSHape);
313       }
314     }
315   } else { //Case 3: When only one bounding plane was set.
316     // Getting bounding face.
317     TopoDS_Face aBoundingFace;
318     bool isFromFaceSet = false;
319     if(theFromShape) {
320       aBoundingFace = TopoDS::Face(theFromShape->impl<TopoDS_Shape>());
321       isFromFaceSet = true;
322     } else if(theToShape) {
323       aBoundingFace = TopoDS::Face(theToShape->impl<TopoDS_Shape>());
324     }
325
326     // Getting plane from bounding face.
327     GeomLib_IsPlanarSurface isBoundingPlanar(BRep_Tool::Surface(aBoundingFace));
328     if(!isBoundingPlanar.IsPlanar()) { // non-planar shapes is not supported for revolution bounding
329       return;
330     }
331     gp_Pln aBoundingPln = isBoundingPlanar.Plan();
332
333     // Orienting bounding plane properly so that the center of mass of the base face stays
334     // on the result shape after cut.
335     gp_Pnt aBasisCentr = GeomAlgoAPI_ShapeTools::centreOfMass(theBasis)->impl<gp_Pnt>();
336     aBoundingFace = makeFaceFromPlane(aBoundingPln, aBasisCentr);
337
338     // Making solid from bounding plane.
339     TopoDS_Shape aBoundingSolid = makeSolidFromShape(aBoundingFace);
340
341     // Rotating bounding plane to the specified angle.
342     double aBoundingRotAngle = isFromFaceSet ? theFromAngle : theToAngle;
343     if(aBoundingPln.Axis().IsParallel(aBasisPln.Axis(), Precision::Confusion())) {
344       if(isFromFaceSet) aBoundingRotAngle = -aBoundingRotAngle;
345     } else {
346       double aSign = (aBoundingPln.Axis().Direction() ^ aBasisPln.Axis().Direction()) *
347                      anAxis.Direction();
348       if((aSign <= 0 && !isFromFaceSet) || (aSign > 0 && isFromFaceSet)) {
349         aBoundingRotAngle = -aBoundingRotAngle;
350       }
351     }
352     gp_Trsf aBoundingTrsf;
353     aBoundingTrsf.SetRotation(anAxis, aBoundingRotAngle / 180.0 * M_PI);
354     BRepBuilderAPI_Transform aBoundingTransform(aBoundingSolid, aBoundingTrsf, true);
355     TopoDS_Shape aRotatedBoundingFace = aBoundingTransform.Modified(aBoundingFace).First();
356     aBoundingSolid = aBoundingTransform.Shape();
357
358     // Making wire for pipe.
359     TopoDS_Edge aPipeEdge = BRepBuilderAPI_MakeEdge(aCircle, 0, 2 * M_PI);
360     TopoDS_Wire aPipeWire = BRepBuilderAPI_MakeWire(aPipeEdge).Wire();
361
362     // Making pipe.
363     BRepOffsetAPI_MakePipe* aPipeBuilder = new BRepOffsetAPI_MakePipe(aPipeWire, aBasisShape);
364     if(!aPipeBuilder || !aPipeBuilder->IsDone()) {
365       return;
366     }
367     std::shared_ptr<GeomAPI_Shape> aWire(new GeomAPI_Shape);
368     std::shared_ptr<GeomAPI_Shape> aBShape(new GeomAPI_Shape);
369     aWire->setImpl(new TopoDS_Shape(aPipeWire));
370     aBShape->setImpl(new TopoDS_Shape(aBasisShape));
371     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aPipeBuilder, aWire, aBShape)));
372     aResult = aPipeBuilder->Shape();
373
374     // Cutting revolution with bounding plane.
375     BRepAlgoAPI_Cut* aBoundingCutBuilder = new BRepAlgoAPI_Cut(aResult, aBoundingSolid);
376     aBoundingCutBuilder->Build();
377     if(!aBoundingCutBuilder->IsDone()) {
378       return;
379     }
380     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aBoundingCutBuilder)));
381     aResult = aBoundingCutBuilder->Shape();
382
383     // Setting naming.
384     const TopTools_ListOfShape& aBndShapes = aBoundingCutBuilder->Modified(aBoundingFace);
385     for(TopTools_ListIteratorOfListOfShape anIt(aBndShapes); anIt.More(); anIt.Next()) {
386       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
387       aShape->setImpl(new TopoDS_Shape(anIt.Value()));
388       isFromFaceSet ? myFromFaces.push_back(aShape) : myToFaces.push_back(aShape);
389     }
390
391     // Try to cut with base face. If it can not be done then keep result of cut with bounding plane.
392     if(isFromFaceSet) {
393       gp_Trsf aMirrorTrsf;
394       aMirrorTrsf.SetMirror(aBasisPlane.Position().Ax2());
395       BRepBuilderAPI_Transform aMirrorTransform(aBasis, aMirrorTrsf, true);
396       aBasis = aMirrorTransform.Shape();
397     }
398
399     // Making solid from basis face.
400     TopoDS_Shape aBasisSolid = makeSolidFromShape(aBasis);
401
402     // Rotating basis face to the specified angle.
403     gp_Trsf aBasisTrsf;
404     double aBasisRotAngle = isFromFaceSet ? theToAngle : -theFromAngle;
405     aBasisTrsf.SetRotation(anAxis, aBasisRotAngle / 180.0 * M_PI);
406     BRepBuilderAPI_Transform aBasisTransform(aBasisSolid, aBasisTrsf, true);
407     TopoDS_Shape aRotatedBasis = aBasisTransform.Modified(aBasis).First();
408     aBasisSolid = aBasisTransform.Shape();
409
410     // Cutting revolution with basis.
411     BRepAlgoAPI_Cut* aBasisCutBuilder = new BRepAlgoAPI_Cut(aResult, aBasisSolid);
412     aBasisCutBuilder->Build();
413     if(aBasisCutBuilder->IsDone()) {
414       TopoDS_Shape aCutResult = aBasisCutBuilder->Shape();
415       TopExp_Explorer anExp(aCutResult, TopAbs_SOLID);
416       if(anExp.More()) {
417         aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aBasisCutBuilder)));
418         aResult = aCutResult;
419       }
420     }
421
422     const TopTools_ListOfShape& aBsShapes = aBasisCutBuilder->Modified(aBoundingFace);
423     for(TopTools_ListIteratorOfListOfShape anIt(aBsShapes); anIt.More(); anIt.Next()) {
424       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
425       aShape->setImpl(new TopoDS_Shape(anIt.Value()));
426       isFromFaceSet ? myToFaces.push_back(aShape) : myFromFaces.push_back(aShape);
427     }
428
429     // If after cut we got more than one solids then take closest to the center of mass of the base face.
430     //aResult = findClosest(aResult, aBasisCentr);
431
432     // Setting naming.
433     for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) {
434       const TopoDS_Shape& aFaceOnResult = anExp.Current();
435       Handle(Geom_Surface) aFaceSurface = BRep_Tool::Surface(TopoDS::Face(aFaceOnResult));
436       Handle(Geom_Surface) aBoundingSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedBoundingFace));
437       if(aFaceSurface == aBoundingSurface) {
438         std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
439         aShape->setImpl(new TopoDS_Shape(aFaceOnResult));
440         isFromFaceSet ? myFromFaces.push_back(aShape) : myToFaces.push_back(aShape);
441       }
442     }
443   }
444
445   TopExp_Explorer anExp(aResult, TopAbs_SOLID);
446   if(!anExp.More()) {
447     return;
448   }
449
450   // fill data map to keep correct orientation of sub-shapes
451   myMap = std::shared_ptr<GeomAPI_DataMapOfShapeShape>(new GeomAPI_DataMapOfShapeShape());
452   for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
453     std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
454     aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
455     myMap->bind(aCurrentShape, aCurrentShape);
456   }
457   myShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
458   myShape->setImpl(new TopoDS_Shape(aResult));
459   myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
460   myDone = true;
461   return;
462 }
463
464 //=================================================================================================
465 const bool GeomAlgoAPI_Revolution::isDone() const
466 {
467   return myDone;
468 }
469
470 //=================================================================================================
471 const bool GeomAlgoAPI_Revolution::isValid() const
472 {
473   BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
474   return (aChecker.IsValid() == Standard_True);
475 }
476
477 //=================================================================================================
478 const bool GeomAlgoAPI_Revolution::hasVolume() const
479 {
480   bool hasVolume(false);
481   if(isValid()) {
482     const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
483     GProp_GProps aGProp;
484     BRepGProp::VolumeProperties(aRShape, aGProp);
485     if(aGProp.Mass() > Precision::Confusion())
486       hasVolume = true;
487   }
488   return hasVolume;
489 }
490
491 //=================================================================================================
492 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Revolution::shape () const
493 {
494   return myShape;
495 }
496
497 //=================================================================================================
498 const ListOfShape& GeomAlgoAPI_Revolution::fromFaces() const
499 {
500   return myFromFaces;
501 }
502
503 //=================================================================================================
504 const ListOfShape& GeomAlgoAPI_Revolution::toFaces() const
505 {
506   return myToFaces;
507 }
508
509 //=================================================================================================
510 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Revolution::mapOfShapes() const
511 {
512   return myMap;
513 }
514
515 //=================================================================================================
516 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Revolution::makeShape() const
517 {
518   return myMkShape;
519 }