Salome HOME
Combine solids in compounds after extrusion/revolution to compsolids
[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   gp_Ax1 anAxis = theAxis->impl<gp_Ax1>();
162   if(aBasisPlane.Axis().Angle(anAxis) < Precision::Confusion()) {
163     return;
164   }
165   gp_Lin anAxisLin(anAxis);
166
167   // Creating circle for pipe.
168   gp_Pnt aBasisCentre = GeomAlgoAPI_ShapeTools::centreOfMass(theBasis)->impl<gp_Pnt>();
169   gp_Pnt aStartPnt = aBasisCentre;
170   const TopoDS_Shape& aBasisShape = theBasis->impl<TopoDS_Shape>();
171   Handle(Geom_Line) anAxisLine = new Geom_Line(anAxis);
172   if(anAxisLin.Contains(aStartPnt, Precision::Confusion())) {
173     aStartPnt.Translate(anAxis.Direction() ^ aBasisPln.Axis().Direction());
174   }
175   GeomAPI_ProjectPointOnCurve aProjection(aStartPnt, anAxisLine);
176   if(aProjection.NbPoints() != 1) {
177     return;
178   }
179   Standard_Real aRadius = aProjection.Distance(1);
180   gp_Circ aCircle(gp_Ax2(aProjection.NearestPoint(), anAxis.Direction()), aRadius);
181
182   TopoDS_Shape aResult;
183   ListOfMakeShape aListOfMakeShape;
184   if(!theFromShape && !theToShape) { // Case 1: When only angles was set.
185     // Rotating base face with the negative value of "from angle".
186     gp_Trsf aBaseTrsf;
187     aBaseTrsf.SetRotation(anAxis, -theFromAngle / 180.0 * M_PI);
188     gp_Pnt aFromPnt = aStartPnt.Transformed(aBaseTrsf);
189     aCircle = gp_Circ(gp_Ax2(aProjection.NearestPoint(), anAxis.Direction(), gp_Vec(aProjection.NearestPoint(), aFromPnt)),
190                       aRadius);
191     BRepBuilderAPI_Transform* aBaseTransform = new BRepBuilderAPI_Transform(aBasisShape,
192                                                                             aBaseTrsf,
193                                                                             true);
194     if(!aBaseTransform || !aBaseTransform->IsDone()) {
195       return;
196     }
197     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aBaseTransform)));
198     TopoDS_Shape aRotatedBaseShape = aBaseTransform->Shape();
199
200     // Making wire for pipe.
201     TopoDS_Edge aPipeEdge = BRepBuilderAPI_MakeEdge(aCircle, 0, (theFromAngle + theToAngle) / 180.0 * M_PI);
202     TopoDS_Wire aPipeWire = BRepBuilderAPI_MakeWire(aPipeEdge).Wire();
203
204     // Making pipe.
205     BRepOffsetAPI_MakePipe* aPipeBuilder = new BRepOffsetAPI_MakePipe(aPipeWire, aRotatedBaseShape);
206     if(!aPipeBuilder || !aPipeBuilder->IsDone()) {
207       return;
208     }
209     std::shared_ptr<GeomAPI_Shape> aWire(new GeomAPI_Shape);
210     std::shared_ptr<GeomAPI_Shape> aBShape(new GeomAPI_Shape);
211     aWire->setImpl(new TopoDS_Shape(aPipeWire));
212     aBShape->setImpl(new TopoDS_Shape(aRotatedBaseShape));
213     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aPipeBuilder, aWire, aBShape)));
214     aResult = aPipeBuilder->Shape();
215     TopoDS_Shape aToShape = aPipeBuilder->LastShape();
216     TopoDS_Shape aFromShape = aPipeBuilder->FirstShape();
217
218     // Setting naming.
219     TopExp_Explorer anExp(aToShape, TopAbs_FACE);
220     for(; anExp.More(); anExp.Next()) {
221       std::shared_ptr<GeomAPI_Shape> aTSHape(new GeomAPI_Shape);
222       aTSHape->setImpl(new TopoDS_Shape(anExp.Current()));
223       myToFaces.push_back(aTSHape);
224     }
225     anExp.Init(aFromShape, TopAbs_FACE);
226     for(; anExp.More(); anExp.Next()) {
227       std::shared_ptr<GeomAPI_Shape> aFSHape(new GeomAPI_Shape);
228       aFSHape->setImpl(new TopoDS_Shape(anExp.Current()));
229       myFromFaces.push_back(aFSHape);
230     }
231   } else if(theFromShape && theToShape) { // Case 2: When both bounding planes were set.
232     // Getting bounding faces.
233     TopoDS_Face aFromFace = TopoDS::Face(theFromShape->impl<TopoDS_Shape>());
234     TopoDS_Face aToFace   = TopoDS::Face(theToShape->impl<TopoDS_Shape>());
235
236     // Getting planes from bounding face.
237     GeomLib_IsPlanarSurface isFromPlanar(BRep_Tool::Surface(aFromFace));
238     GeomLib_IsPlanarSurface isToPlanar(BRep_Tool::Surface(aToFace));
239     if(!isFromPlanar.IsPlanar() || !isToPlanar.IsPlanar()) {// non-planar shapes is not supported for revolution bounding
240       return;
241     }
242     gp_Pln aFromPln = isFromPlanar.Plan();
243     gp_Pln aToPln   = isToPlanar.Plan();
244
245     // Orienting bounding planes properly so that the center of mass of the base face stays
246     // on the result shape after cut.
247     aFromFace = makeFaceFromPlane(aFromPln, aBasisCentre);
248     aToFace   = makeFaceFromPlane(aToPln, aBasisCentre);
249
250     // Making solids from bounding planes and putting them in compound.
251     TopoDS_Shape aFromSolid = makeSolidFromShape(aFromFace);
252     TopoDS_Shape aToSolid   = makeSolidFromShape(aToFace);
253
254     // Rotating bounding planes to the specified angle.
255     gp_Trsf aFromTrsf;
256     gp_Trsf aToTrsf;
257     double aFromRotAngle = ((aFromPln.Axis().Direction() * aBasisPln.Axis().Direction()) > 0) ? -theFromAngle : theFromAngle;
258     double aToRotAngle = ((aToPln.Axis().Direction() * aBasisPln.Axis().Direction()) > 0) ? -theToAngle : theToAngle;
259     aFromTrsf.SetRotation(anAxis,aFromRotAngle / 180.0 * M_PI);
260     aToTrsf.SetRotation(anAxis, aToRotAngle / 180.0 * M_PI);
261     BRepBuilderAPI_Transform aFromTransform(aFromSolid, aFromTrsf, true);
262     BRepBuilderAPI_Transform aToTransform(aToSolid, aToTrsf, true);
263     TopoDS_Shape aRotatedFromFace = aFromTransform.Modified(aFromFace).First();
264     TopoDS_Shape aRotatedToFace = aToTransform.Modified(aToFace).First();
265     aFromSolid = aFromTransform.Shape();
266     aToSolid = aToTransform.Shape();
267
268     // Making wire for pipe.
269     TopoDS_Edge aPipeEdge = BRepBuilderAPI_MakeEdge(aCircle, 0, 2 * M_PI);
270     TopoDS_Wire aPipeWire = BRepBuilderAPI_MakeWire(aPipeEdge).Wire();
271
272     // Making pipe.
273     BRepOffsetAPI_MakePipe* aPipeBuilder = new BRepOffsetAPI_MakePipe(aPipeWire, aBasisShape);
274     if(!aPipeBuilder || !aPipeBuilder->IsDone()) {
275       return;
276     }
277     std::shared_ptr<GeomAPI_Shape> aWire(new GeomAPI_Shape);
278     std::shared_ptr<GeomAPI_Shape> aBShape(new GeomAPI_Shape);
279     aWire->setImpl(new TopoDS_Shape(aPipeWire));
280     aBShape->setImpl(new TopoDS_Shape(aBasisShape));
281     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aPipeBuilder, aWire, aBShape)));
282     aResult = aPipeBuilder->Shape();
283
284     // Cutting revolution with from plane.
285     BRepAlgoAPI_Cut* aFromCutBuilder = new BRepAlgoAPI_Cut(aResult, aFromSolid);
286     aFromCutBuilder->Build();
287     if(!aFromCutBuilder->IsDone()) {
288       return;
289     }
290     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aFromCutBuilder)));
291     aResult = aFromCutBuilder->Shape();
292
293     // Cutting revolution with to plane.
294     BRepAlgoAPI_Cut* aToCutBuilder = new BRepAlgoAPI_Cut(aResult, aToSolid);
295     aToCutBuilder->Build();
296     if(!aToCutBuilder->IsDone()) {
297       return;
298     }
299     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aToCutBuilder)));
300     aResult = aToCutBuilder->Shape();
301
302     // If after cut we got more than one solids then take closest to the center of mass of the base face.
303     //aResult = findClosest(aResult, aBasisCentre);
304
305     // Setting naming.
306     for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) {
307       const TopoDS_Shape& aFaceOnResult = anExp.Current();
308       Handle(Geom_Surface) aFaceSurface = BRep_Tool::Surface(TopoDS::Face(aFaceOnResult));
309       Handle(Geom_Surface) aFromSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedFromFace));
310       Handle(Geom_Surface) aToSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedToFace));
311       if(aFaceSurface == aFromSurface) {
312         std::shared_ptr<GeomAPI_Shape> aFSHape(new GeomAPI_Shape);
313         aFSHape->setImpl(new TopoDS_Shape(aFaceOnResult));
314         myFromFaces.push_back(aFSHape);
315       }
316       if(aFaceSurface == aToSurface) {
317         std::shared_ptr<GeomAPI_Shape> aTSHape(new GeomAPI_Shape);
318         aTSHape->setImpl(new TopoDS_Shape(aFaceOnResult));
319         myToFaces.push_back(aTSHape);
320       }
321     }
322   } else { //Case 3: When only one bounding plane was set.
323     // Getting bounding face.
324     TopoDS_Face aBoundingFace;
325     bool isFromFaceSet = false;
326     if(theFromShape) {
327       aBoundingFace = TopoDS::Face(theFromShape->impl<TopoDS_Shape>());
328       isFromFaceSet = true;
329     } else if(theToShape) {
330       aBoundingFace = TopoDS::Face(theToShape->impl<TopoDS_Shape>());
331     }
332
333     // Getting plane from bounding face.
334     GeomLib_IsPlanarSurface isBoundingPlanar(BRep_Tool::Surface(aBoundingFace));
335     if(!isBoundingPlanar.IsPlanar()) { // non-planar shapes is not supported for revolution bounding
336       return;
337     }
338     gp_Pln aBoundingPln = isBoundingPlanar.Plan();
339
340     // Orienting bounding plane properly so that the center of mass of the base face stays
341     // on the result shape after cut.
342     gp_Pnt aBasisCentr = GeomAlgoAPI_ShapeTools::centreOfMass(theBasis)->impl<gp_Pnt>();
343     aBoundingFace = makeFaceFromPlane(aBoundingPln, aBasisCentr);
344
345     // Making solid from bounding plane.
346     TopoDS_Shape aBoundingSolid = makeSolidFromShape(aBoundingFace);
347
348     // Rotating bounding plane to the specified angle.
349     double aBoundingRotAngle = isFromFaceSet ? theFromAngle : theToAngle;
350     if(aBoundingPln.Axis().IsParallel(aBasisPln.Axis(), Precision::Confusion())) {
351       if(isFromFaceSet) aBoundingRotAngle = -aBoundingRotAngle;
352     } else {
353       double aSign = (aBoundingPln.Axis().Direction() ^ aBasisPln.Axis().Direction()) *
354                      anAxis.Direction();
355       if((aSign <= 0 && !isFromFaceSet) || (aSign > 0 && isFromFaceSet)) {
356         aBoundingRotAngle = -aBoundingRotAngle;
357       }
358     }
359     gp_Trsf aBoundingTrsf;
360     aBoundingTrsf.SetRotation(anAxis, aBoundingRotAngle / 180.0 * M_PI);
361     BRepBuilderAPI_Transform aBoundingTransform(aBoundingSolid, aBoundingTrsf, true);
362     TopoDS_Shape aRotatedBoundingFace = aBoundingTransform.Modified(aBoundingFace).First();
363     aBoundingSolid = aBoundingTransform.Shape();
364
365     // Making wire for pipe.
366     TopoDS_Edge aPipeEdge = BRepBuilderAPI_MakeEdge(aCircle, 0, 2 * M_PI);
367     TopoDS_Wire aPipeWire = BRepBuilderAPI_MakeWire(aPipeEdge).Wire();
368
369     // Making pipe.
370     BRepOffsetAPI_MakePipe* aPipeBuilder = new BRepOffsetAPI_MakePipe(aPipeWire, aBasisShape);
371     if(!aPipeBuilder || !aPipeBuilder->IsDone()) {
372       return;
373     }
374     std::shared_ptr<GeomAPI_Shape> aWire(new GeomAPI_Shape);
375     std::shared_ptr<GeomAPI_Shape> aBShape(new GeomAPI_Shape);
376     aWire->setImpl(new TopoDS_Shape(aPipeWire));
377     aBShape->setImpl(new TopoDS_Shape(aBasisShape));
378     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aPipeBuilder, aWire, aBShape)));
379     aResult = aPipeBuilder->Shape();
380
381     // Cutting revolution with bounding plane.
382     BRepAlgoAPI_Cut* aBoundingCutBuilder = new BRepAlgoAPI_Cut(aResult, aBoundingSolid);
383     aBoundingCutBuilder->Build();
384     if(!aBoundingCutBuilder->IsDone()) {
385       return;
386     }
387     aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aBoundingCutBuilder)));
388     aResult = aBoundingCutBuilder->Shape();
389
390     // Setting naming.
391     const TopTools_ListOfShape& aBndShapes = aBoundingCutBuilder->Modified(aBoundingFace);
392     for(TopTools_ListIteratorOfListOfShape anIt(aBndShapes); anIt.More(); anIt.Next()) {
393       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
394       aShape->setImpl(new TopoDS_Shape(anIt.Value()));
395       isFromFaceSet ? myFromFaces.push_back(aShape) : myToFaces.push_back(aShape);
396     }
397
398     // Try to cut with base face. If it can not be done then keep result of cut with bounding plane.
399     if(isFromFaceSet) {
400       gp_Trsf aMirrorTrsf;
401       aMirrorTrsf.SetMirror(aBasisPlane.Position().Ax2());
402       BRepBuilderAPI_Transform aMirrorTransform(aBasis, aMirrorTrsf, true);
403       aBasis = aMirrorTransform.Shape();
404     }
405
406     // Making solid from basis face.
407     TopoDS_Shape aBasisSolid = makeSolidFromShape(aBasis);
408
409     // Rotating basis face to the specified angle.
410     gp_Trsf aBasisTrsf;
411     double aBasisRotAngle = isFromFaceSet ? theToAngle : -theFromAngle;
412     aBasisTrsf.SetRotation(anAxis, aBasisRotAngle / 180.0 * M_PI);
413     BRepBuilderAPI_Transform aBasisTransform(aBasisSolid, aBasisTrsf, true);
414     TopoDS_Shape aRotatedBasis = aBasisTransform.Modified(aBasis).First();
415     aBasisSolid = aBasisTransform.Shape();
416
417     // Cutting revolution with basis.
418     BRepAlgoAPI_Cut* aBasisCutBuilder = new BRepAlgoAPI_Cut(aResult, aBasisSolid);
419     aBasisCutBuilder->Build();
420     if(aBasisCutBuilder->IsDone()) {
421       TopoDS_Shape aCutResult = aBasisCutBuilder->Shape();
422       TopExp_Explorer anExp(aCutResult, TopAbs_SOLID);
423       if(anExp.More()) {
424         aListOfMakeShape.push_back(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aBasisCutBuilder)));
425         aResult = aCutResult;
426       }
427     }
428
429     const TopTools_ListOfShape& aBsShapes = aBasisCutBuilder->Modified(aBoundingFace);
430     for(TopTools_ListIteratorOfListOfShape anIt(aBsShapes); anIt.More(); anIt.Next()) {
431       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
432       aShape->setImpl(new TopoDS_Shape(anIt.Value()));
433       isFromFaceSet ? myToFaces.push_back(aShape) : myFromFaces.push_back(aShape);
434     }
435
436     // If after cut we got more than one solids then take closest to the center of mass of the base face.
437     //aResult = findClosest(aResult, aBasisCentr);
438
439     // Setting naming.
440     for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) {
441       const TopoDS_Shape& aFaceOnResult = anExp.Current();
442       Handle(Geom_Surface) aFaceSurface = BRep_Tool::Surface(TopoDS::Face(aFaceOnResult));
443       Handle(Geom_Surface) aBoundingSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedBoundingFace));
444       if(aFaceSurface == aBoundingSurface) {
445         std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
446         aShape->setImpl(new TopoDS_Shape(aFaceOnResult));
447         isFromFaceSet ? myFromFaces.push_back(aShape) : myToFaces.push_back(aShape);
448       }
449     }
450   }
451
452   TopExp_Explorer anExp(aResult, TopAbs_SOLID);
453   if(!anExp.More()) {
454     return;
455   }
456   if(aResult.ShapeType() == TopAbs_COMPOUND) {
457     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
458   }
459   if(aResult.ShapeType() == TopAbs_COMPOUND) {
460     std::shared_ptr<GeomAPI_Shape> aCompound(new GeomAPI_Shape);
461     aCompound->setImpl(new TopoDS_Shape(aResult));
462     ListOfShape aCompSolids, aFreeSolids;
463     GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids);
464     if(aCompSolids.size() == 1 && aFreeSolids.size() == 0) {
465       aResult = aCompSolids.front()->impl<TopoDS_Shape>();
466     } else if (aCompSolids.size() > 1 || (aCompSolids.size() >= 1 && aFreeSolids.size() >= 1)) {
467       TopoDS_Compound aResultComp;
468       TopoDS_Builder aBuilder;
469       aBuilder.MakeCompound(aResultComp);
470       for(ListOfShape::const_iterator anIter = aCompSolids.cbegin(); anIter != aCompSolids.cend(); anIter++) {
471         aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
472       }
473       for(ListOfShape::const_iterator anIter = aFreeSolids.cbegin(); anIter != aFreeSolids.cend(); anIter++) {
474         aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
475       }
476       aResult = aResultComp;
477     }
478   }
479
480   // fill data map to keep correct orientation of sub-shapes
481   myMap = std::shared_ptr<GeomAPI_DataMapOfShapeShape>(new GeomAPI_DataMapOfShapeShape());
482   for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
483     std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
484     aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
485     myMap->bind(aCurrentShape, aCurrentShape);
486   }
487   myShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
488   myShape->setImpl(new TopoDS_Shape(aResult));
489   myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
490   myDone = true;
491 }
492
493 //=================================================================================================
494 const bool GeomAlgoAPI_Revolution::isDone() const
495 {
496   return myDone;
497 }
498
499 //=================================================================================================
500 const bool GeomAlgoAPI_Revolution::isValid() const
501 {
502   BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
503   return (aChecker.IsValid() == Standard_True);
504 }
505
506 //=================================================================================================
507 const bool GeomAlgoAPI_Revolution::hasVolume() const
508 {
509   bool hasVolume(false);
510   if(isValid()) {
511     const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
512     GProp_GProps aGProp;
513     BRepGProp::VolumeProperties(aRShape, aGProp);
514     if(aGProp.Mass() > Precision::Confusion())
515       hasVolume = true;
516   }
517   return hasVolume;
518 }
519
520 //=================================================================================================
521 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Revolution::shape () const
522 {
523   return myShape;
524 }
525
526 //=================================================================================================
527 const ListOfShape& GeomAlgoAPI_Revolution::fromFaces() const
528 {
529   return myFromFaces;
530 }
531
532 //=================================================================================================
533 const ListOfShape& GeomAlgoAPI_Revolution::toFaces() const
534 {
535   return myToFaces;
536 }
537
538 //=================================================================================================
539 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Revolution::mapOfShapes() const
540 {
541   return myMap;
542 }
543
544 //=================================================================================================
545 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Revolution::makeShape() const
546 {
547   return myMkShape;
548 }