]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp
Salome HOME
[Code coverage GeomAlgoAPI]: Improve coverage of Prism and Revolution algorithms...
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Prism.cpp
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "GeomAlgoAPI_Prism.h"
22
23 #include <GeomAPI_Face.h>
24 #include <GeomAPI_Pln.h>
25 #include <GeomAPI_Pnt.h>
26 #include <GeomAPI_ShapeExplorer.h>
27 #include <GeomAPI_XYZ.h>
28 #include <GeomAlgoAPI_DFLoader.h>
29 #include <GeomAlgoAPI_FaceBuilder.h>
30 #include <GeomAlgoAPI_ShapeTools.h>
31
32 #include <Bnd_Box.hxx>
33 #include <BRep_Builder.hxx>
34 #include <BRepAlgoAPI_Cut.hxx>
35 #include <BRepBndLib.hxx>
36 #include <BRepBuilderAPI_FindPlane.hxx>
37 #include <BRepBuilderAPI_Transform.hxx>
38 #include <BRepTools.hxx>
39 #include <Geom_Curve.hxx>
40 #include <Geom2d_Curve.hxx>
41 #include <BRepLib_CheckCurveOnSurface.hxx>
42 #include <BRepPrimAPI_MakePrism.hxx>
43 #include <Geom_Plane.hxx>
44 #include <Geom_RectangularTrimmedSurface.hxx>
45 #include <gp_Pln.hxx>
46 #include <IntAna_IntConicQuad.hxx>
47 #include <IntAna_Quadric.hxx>
48 #include <IntTools_Context.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <TopoDS.hxx>
51 #include <TopoDS_Edge.hxx>
52 #include <TopoDS_Shell.hxx>
53 #include <TopoDS_Solid.hxx>
54 #include <TopTools_ListIteratorOfListOfShape.hxx>
55
56
57 static void storeGenerationHistory(GeomAlgoAPI_Prism* thePrismAlgo,
58                                    const TopoDS_Shape& theBase,
59                                    const TopAbs_ShapeEnum theType,
60                                    BRepPrimAPI_MakePrism* thePrismBuilder);
61
62 static void storeGenerationHistory(GeomAlgoAPI_Prism* thePrismAlgo,
63                                    const TopoDS_Shape& theResult,
64                                    const TopAbs_ShapeEnum theType,
65                                    const TopoDS_Face& theToFace,
66                                    const TopoDS_Face& theFromFace);
67
68
69 //==================================================================================================
70 GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const GeomShapePtr                 theBaseShape,
71                                      const std::shared_ptr<GeomAPI_Dir> theDirection,
72                                      const GeomShapePtr                 theToShape,
73                                      const double                       theToSize,
74                                      const GeomShapePtr                 theFromShape,
75                                      const double                       theFromSize)
76 {
77   build(theBaseShape, theDirection, theToShape, theToSize, theFromShape, theFromSize);
78 }
79
80 //==================================================================================================
81 void GeomAlgoAPI_Prism::build(const GeomShapePtr&                theBaseShape,
82                               const std::shared_ptr<GeomAPI_Dir> theDirection,
83                               const GeomShapePtr&                theToShape,
84                               const double                       theToSize,
85                               const GeomShapePtr&                theFromShape,
86                               const double                       theFromSize)
87 {
88   if(!theBaseShape.get() ||
89     (((!theFromShape.get() && !theToShape.get()) ||
90     (theFromShape.get() && theToShape.get() && theFromShape->isEqual(theToShape)))
91     && (theFromSize == -theToSize))) {
92     return;
93   }
94
95   // Getting base shape.
96   const TopoDS_Shape& aBaseShape = theBaseShape->impl<TopoDS_Shape>();
97   TopAbs_ShapeEnum aShapeTypeToExp;
98   switch(aBaseShape.ShapeType()) {
99     case TopAbs_VERTEX:
100       aShapeTypeToExp = TopAbs_VERTEX;
101       break;
102     case TopAbs_EDGE:
103     case TopAbs_WIRE:
104       aShapeTypeToExp = TopAbs_EDGE;
105       break;
106     case TopAbs_FACE:
107     case TopAbs_SHELL:
108       aShapeTypeToExp = TopAbs_FACE;
109       break;
110     case TopAbs_COMPOUND:
111       aShapeTypeToExp = TopAbs_COMPOUND;
112       break;
113     default:
114       return;
115   }
116
117   // Getting direction.
118   gp_Vec aBaseVec;
119   std::shared_ptr<GeomAPI_Pnt> aBaseLoc;
120   std::shared_ptr<GeomAPI_Dir> aBaseDir;
121   BRepBuilderAPI_FindPlane aFindPlane(aBaseShape);
122   if(aFindPlane.Found() == Standard_True)
123   {
124     Handle(Geom_Plane) aPlane;
125     if(aBaseShape.ShapeType() == TopAbs_FACE || aBaseShape.ShapeType() == TopAbs_SHELL) {
126       TopExp_Explorer anExp(aBaseShape, TopAbs_FACE);
127       const TopoDS_Shape& aFace = anExp.Current();
128       Handle(Geom_Surface) aSurface = BRep_Tool::Surface(TopoDS::Face(aFace));
129       if(aSurface->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
130         Handle(Geom_RectangularTrimmedSurface) aTrimSurface =
131           Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
132         aSurface = aTrimSurface->BasisSurface();
133       }
134       if(aSurface->DynamicType() != STANDARD_TYPE(Geom_Plane)) {
135         return;
136       }
137       aPlane = Handle(Geom_Plane)::DownCast(aSurface);
138     } else {
139       aPlane = aFindPlane.Plane();
140     }
141     gp_Pnt aLoc = aPlane->Axis().Location();
142     aBaseVec = aPlane->Axis().Direction();
143     aBaseLoc.reset(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
144     aBaseDir.reset(new GeomAPI_Dir(aBaseVec.X(), aBaseVec.Y(), aBaseVec.Z()));
145   }
146   else if (theDirection.get())
147   {
148     aBaseDir = theDirection;
149     aBaseVec = theDirection->impl<gp_Dir>();
150   }
151   else
152   {
153     return;
154   }
155
156   if(!aBaseLoc.get()) {
157     gp_Pnt aLoc;
158     gp_XYZ aDirXYZ = aBaseVec.XYZ();
159     Standard_Real aMinParam = Precision::Infinite();
160     for(TopExp_Explorer anExp(aBaseShape, TopAbs_VERTEX); anExp.More(); anExp.Next()) {
161       const TopoDS_Shape& aVertex = anExp.Current();
162       gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aVertex));
163       double aParam = aDirXYZ.Dot(aPnt.XYZ());
164       if(aParam < aMinParam) {
165         aMinParam = aParam;
166         aLoc = aPnt;
167       }
168     }
169     aBaseLoc.reset(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
170   }
171
172   GeomShapePtr aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir);
173
174   gp_Vec anExtVec;
175   std::shared_ptr<GeomAPI_Dir> anExtDir;
176   if (theDirection.get())
177   {
178     anExtDir = theDirection;
179     anExtVec = theDirection->impl<gp_Dir>();
180   }
181   else
182   {
183     anExtDir = aBaseDir;
184     anExtVec = aBaseDir->impl<gp_Dir>();
185   }
186
187
188   TopoDS_Shape aResult;
189   const bool isBoundingShapesSet = theFromShape.get() || theToShape.get();
190   if(!isBoundingShapesSet) {
191     // Moving base shape.
192     gp_Trsf aTrsf;
193     aTrsf.SetTranslation(anExtVec * -theFromSize);
194     BRepBuilderAPI_Transform* aTransformBuilder =
195       new BRepBuilderAPI_Transform(aBaseShape, aTrsf);
196     if(!aTransformBuilder) {
197       return;
198     }
199     this->appendAlgo(std::shared_ptr<GeomAlgoAPI_MakeShape>(
200       new GeomAlgoAPI_MakeShape(aTransformBuilder)));
201     if(!aTransformBuilder->IsDone()) {
202       return;
203     }
204     TopoDS_Shape aMovedBase = aTransformBuilder->Shape();
205
206     // Making prism.
207     BRepPrimAPI_MakePrism* aPrismBuilder =
208       new BRepPrimAPI_MakePrism(aMovedBase, anExtVec * (theFromSize + theToSize));
209     if(!aPrismBuilder) {
210       return;
211     }
212     this->appendAlgo(std::shared_ptr<GeomAlgoAPI_MakeShape>(
213       new GeomAlgoAPI_MakeShape(aPrismBuilder)));
214     if(!aPrismBuilder->IsDone()) {
215       return;
216     }
217     aResult = aPrismBuilder->Shape();
218
219     // Setting naming.
220     if(aShapeTypeToExp == TopAbs_COMPOUND) {
221       storeGenerationHistory(this, aMovedBase, TopAbs_EDGE, aPrismBuilder);
222       storeGenerationHistory(this, aMovedBase, TopAbs_FACE, aPrismBuilder);
223     } else {
224       storeGenerationHistory(this, aMovedBase, aShapeTypeToExp, aPrismBuilder);
225     }
226   } else {
227     GeomShapePtr aBoundingFromShape = theFromShape ? theFromShape : aBasePlane;
228     GeomShapePtr aBoundingToShape   = theToShape   ? theToShape   : aBasePlane;
229
230     // Moving prism bounding faces according to "from" and "to" sizes.
231     std::shared_ptr<GeomAPI_Pln> aFromPln = GeomAPI_Face(aBoundingFromShape).getPlane();
232     std::shared_ptr<GeomAPI_Pnt> aFromLoc = aFromPln->location();
233     std::shared_ptr<GeomAPI_Dir> aFromDir = aFromPln->direction();
234
235     std::shared_ptr<GeomAPI_Pln> aToPln = GeomAPI_Face(aBoundingToShape).getPlane();
236     std::shared_ptr<GeomAPI_Pnt> aToLoc = aToPln->location();
237     std::shared_ptr<GeomAPI_Dir> aToDir = aToPln->direction();
238
239     bool aSign = aFromLoc->xyz()->dot(anExtDir->xyz()) > aToLoc->xyz()->dot(anExtDir->xyz());
240
241     std::shared_ptr<GeomAPI_Pnt> aFromPnt(
242       new GeomAPI_Pnt(aFromLoc->xyz()->added(anExtDir->xyz()->multiplied(
243                       aSign ? theFromSize : -theFromSize))));
244     aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
245
246     std::shared_ptr<GeomAPI_Pnt> aToPnt(
247       new GeomAPI_Pnt(aToLoc->xyz()->added(anExtDir->xyz()->multiplied(
248                       aSign ? -theToSize : theToSize))));
249     aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
250
251     // Getting bounding box for base shape.
252     Bnd_Box aBndBox;
253     BRepBndLib::Add(aBaseShape, aBndBox);
254     Standard_Real aXArr[2] = {aBndBox.CornerMin().X(), aBndBox.CornerMax().X()};
255     Standard_Real aYArr[2] = {aBndBox.CornerMin().Y(), aBndBox.CornerMax().Y()};
256     Standard_Real aZArr[2] = {aBndBox.CornerMin().Z(), aBndBox.CornerMax().Z()};
257     gp_Pnt aPoints[8];
258     int aNum = 0;
259     for(int i = 0; i < 2; i++) {
260       for(int j = 0; j < 2; j++) {
261         for(int k = 0; k < 2; k++) {
262           aPoints[aNum] = gp_Pnt(aXArr[i], aYArr[j], aZArr[k]);
263           aNum++;
264         }
265       }
266     }
267
268     // Project points to bounding planes. Search max distance to them.
269     IntAna_Quadric aBndToQuadric(gp_Pln(aToPnt->impl<gp_Pnt>(), aToDir->impl<gp_Dir>()));
270     IntAna_Quadric aBndFromQuadric(gp_Pln(aFromPnt->impl<gp_Pnt>(), aFromDir->impl<gp_Dir>()));
271     Standard_Real aMaxToDist = 0, aMaxFromDist = 0;
272     for(int i = 0; i < 8; i++) {
273       gp_Lin aLine(aPoints[i], anExtVec);
274       IntAna_IntConicQuad aToIntAna(aLine, aBndToQuadric);
275       IntAna_IntConicQuad aFromIntAna(aLine, aBndFromQuadric);
276       if(aToIntAna.NbPoints() == 0 || aFromIntAna.NbPoints() == 0) {
277         return;
278       }
279       const gp_Pnt& aPntOnToFace = aToIntAna.Point(1);
280       const gp_Pnt& aPntOnFromFace = aFromIntAna.Point(1);
281       if(aPoints[i].Distance(aPntOnToFace) > aMaxToDist) {
282         aMaxToDist = aPoints[i].Distance(aPntOnToFace);
283       }
284       if(aPoints[i].Distance(aPntOnFromFace) > aMaxFromDist) {
285         aMaxFromDist = aPoints[i].Distance(aPntOnFromFace);
286       }
287     }
288
289     // We added 1 just to be sure that prism is long enough for boolean operation.
290     double aPrismLength = aMaxToDist + aMaxFromDist + 1;
291
292     // Moving base shape.
293     gp_Trsf aTrsf;
294     aTrsf.SetTranslation(anExtVec * -aPrismLength);
295     BRepBuilderAPI_Transform* aTransformBuilder = new BRepBuilderAPI_Transform(aBaseShape, aTrsf);
296     if(!aTransformBuilder) {
297       return;
298     }
299     this->appendAlgo(std::shared_ptr<GeomAlgoAPI_MakeShape>(
300       new GeomAlgoAPI_MakeShape(aTransformBuilder)));
301     if(!aTransformBuilder->IsDone()) {
302       return;
303     }
304     TopoDS_Shape aMovedBase = aTransformBuilder->Shape();
305
306     // Making prism.
307     BRepPrimAPI_MakePrism* aPrismBuilder =
308       new BRepPrimAPI_MakePrism(aMovedBase, anExtVec * 2 * aPrismLength);
309     if(!aPrismBuilder) {
310       return;
311     }
312     this->appendAlgo(std::shared_ptr<GeomAlgoAPI_MakeShape>(
313       new GeomAlgoAPI_MakeShape(aPrismBuilder)));
314     if(!aPrismBuilder->IsDone()) {
315       return;
316     }
317     aResult = aPrismBuilder->Shape();
318
319     // Orienting bounding planes.
320     std::shared_ptr<GeomAPI_Pnt> aCentreOfMass = GeomAlgoAPI_ShapeTools::centreOfMass(theBaseShape);
321     const gp_Pnt& aCentrePnt = aCentreOfMass->impl<gp_Pnt>();
322     gp_Lin aLine(aCentrePnt, anExtVec);
323     IntAna_IntConicQuad aToIntAna(aLine, aBndToQuadric);
324     IntAna_IntConicQuad aFromIntAna(aLine, aBndFromQuadric);
325     Standard_Real aToParameter = aToIntAna.ParamOnConic(1);
326     Standard_Real aFromParameter = aFromIntAna.ParamOnConic(1);
327     if(aToParameter > aFromParameter) {
328       gp_Vec aVec = aToDir->impl<gp_Dir>();
329       if((aVec * anExtVec) > 0) {
330         aToDir->setImpl(new gp_Dir(aVec.Reversed()));
331         aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
332       }
333       aVec = aFromDir->impl<gp_Dir>();
334       if((aVec * anExtVec) < 0) {
335         aFromDir->setImpl(new gp_Dir(aVec.Reversed()));
336         aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
337       }
338     } else {
339       gp_Vec aVec = aToDir->impl<gp_Dir>();
340       if((aVec * anExtVec) < 0) {
341         aToDir->setImpl(new gp_Dir(aVec.Reversed()));
342         aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
343       }
344       aVec = aFromDir->impl<gp_Dir>();
345       if((aVec * anExtVec) > 0) {
346         aFromDir->setImpl(new gp_Dir(aVec.Reversed()));
347         aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
348       }
349     }
350
351     // Making solids from bounding planes.
352     TopoDS_Shell aToShell, aFromShell;
353     TopoDS_Solid aToSolid, aFromSolid;
354     const TopoDS_Shape& aToShape   = aBoundingToShape->impl<TopoDS_Shape>();
355     const TopoDS_Shape& aFromShape = aBoundingFromShape->impl<TopoDS_Shape>();
356     TopoDS_Face aToFace   = TopoDS::Face(aToShape);
357     TopoDS_Face aFromFace = TopoDS::Face(aFromShape);
358     BRep_Builder aBoundingBuilder;
359     aBoundingBuilder.MakeShell(aToShell);
360     aBoundingBuilder.Add(aToShell, aToShape);
361     aBoundingBuilder.MakeShell(aFromShell);
362     aBoundingBuilder.Add(aFromShell, aFromShape);
363     aBoundingBuilder.MakeSolid(aToSolid);
364     aBoundingBuilder.Add(aToSolid, aToShell);
365     aBoundingBuilder.MakeSolid(aFromSolid);
366     aBoundingBuilder.Add(aFromSolid, aFromShell);
367
368     // Cutting with to plane.
369     BRepAlgoAPI_Cut* aToCutBuilder = new BRepAlgoAPI_Cut(aResult, aToSolid);
370     aToCutBuilder->Build();
371     if(!aToCutBuilder->IsDone()) {
372       return;
373     }
374     this->appendAlgo(std::shared_ptr<GeomAlgoAPI_MakeShape>(
375       new GeomAlgoAPI_MakeShape(aToCutBuilder)));
376     aResult = aToCutBuilder->Shape();
377     if(aResult.ShapeType() == TopAbs_COMPOUND) {
378       aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
379     }
380     if(aShapeTypeToExp == TopAbs_FACE || aShapeTypeToExp == TopAbs_COMPOUND) {
381       const TopTools_ListOfShape& aToShapes = aToCutBuilder->Modified(aToShape);
382       for(TopTools_ListIteratorOfListOfShape anIt(aToShapes); anIt.More(); anIt.Next()) {
383         GeomShapePtr aGeomSh(new GeomAPI_Shape());
384         aGeomSh->setImpl(new TopoDS_Shape(anIt.Value()));
385         fixOrientation(aGeomSh);
386         this->addToShape(aGeomSh);
387       }
388     }
389
390     // Cutting with from plane.
391     BRepAlgoAPI_Cut* aFromCutBuilder = new BRepAlgoAPI_Cut(aResult, aFromSolid);
392     aFromCutBuilder->Build();
393     if(!aFromCutBuilder->IsDone()) {
394       return;
395     }
396     this->appendAlgo(std::shared_ptr<GeomAlgoAPI_MakeShape>(
397       new GeomAlgoAPI_MakeShape(aFromCutBuilder)));
398     aResult = aFromCutBuilder->Shape();
399     TopoDS_Iterator aCheckIt(aResult);
400     if(!aCheckIt.More()) {
401       return;
402     }
403     if(aResult.ShapeType() == TopAbs_COMPOUND) {
404       aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
405     }
406     if(aShapeTypeToExp == TopAbs_FACE || aShapeTypeToExp == TopAbs_COMPOUND) {
407       const TopTools_ListOfShape& aFromShapes = aFromCutBuilder->Modified(aFromShape);
408       for(TopTools_ListIteratorOfListOfShape anIt(aFromShapes); anIt.More(); anIt.Next()) {
409         GeomShapePtr aGeomSh(new GeomAPI_Shape());
410         aGeomSh->setImpl(new TopoDS_Shape(anIt.Value()));
411         fixOrientation(aGeomSh);
412         this->addFromShape(aGeomSh);
413       }
414     }
415
416     // Naming for extrusion from vertex, edge.
417     if(aShapeTypeToExp == TopAbs_COMPOUND) {
418       storeGenerationHistory(this, aResult, TopAbs_EDGE, aToFace, aFromFace);
419       storeGenerationHistory(this, aResult, TopAbs_FACE, aToFace, aFromFace);
420     } else {
421       storeGenerationHistory(this, aResult, aShapeTypeToExp, aToFace, aFromFace);
422     }
423
424     if(aResult.ShapeType() == TopAbs_COMPOUND) {
425       std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
426       aGeomShape->setImpl(new TopoDS_Shape(aResult));
427       ListOfShape aCompSolids, aFreeSolids;
428       aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
429                                                          GeomAPI_Shape::COMPSOLID,
430                                                          aCompSolids,
431                                                          aFreeSolids);
432       aResult = aGeomShape->impl<TopoDS_Shape>();
433     }
434   }
435
436   // Setting result.
437   if(aResult.IsNull()) {
438     return;
439   }
440   aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
441   GeomShapePtr aGeomSh(new GeomAPI_Shape());
442   aGeomSh->setImpl(new TopoDS_Shape(aResult));
443   this->setShape(aGeomSh);
444   this->setDone(true);
445 }
446
447 // Auxilary functions:
448 //==================================================================================================
449 void storeGenerationHistory(GeomAlgoAPI_Prism* thePrismAlgo,
450                             const TopoDS_Shape& theBase,
451                             const TopAbs_ShapeEnum theType,
452                             BRepPrimAPI_MakePrism* thePrismBuilder)
453 {
454   for(TopExp_Explorer anExp(theBase, theType); anExp.More(); anExp.Next()) {
455     const TopoDS_Shape& aShape = anExp.Current();
456     GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape);
457     aFromShape->setImpl(new TopoDS_Shape(thePrismBuilder->FirstShape(aShape)));
458     aToShape->setImpl(new TopoDS_Shape(thePrismBuilder->LastShape(aShape)));
459     thePrismAlgo->fixOrientation(aFromShape);
460     thePrismAlgo->fixOrientation(aToShape);
461     thePrismAlgo->addFromShape(aFromShape);
462     thePrismAlgo->addToShape(aToShape);
463   }
464 }
465
466 //==================================================================================================
467 void storeGenerationHistory(GeomAlgoAPI_Prism* thePrismAlgo,
468                             const TopoDS_Shape& theResult,
469                             const TopAbs_ShapeEnum theType,
470                             const TopoDS_Face& theToFace,
471                             const TopoDS_Face& theFromFace)
472 {
473   for(TopExp_Explorer anExp(theResult, theType); anExp.More(); anExp.Next()) {
474     const TopoDS_Shape& aShape = anExp.Current();
475     GeomShapePtr aGeomSh(new GeomAPI_Shape());
476     if(theType == TopAbs_VERTEX) {
477       gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
478       IntTools_Context anIntTools;
479       if(anIntTools.IsValidPointForFace(aPnt,
480           theToFace, Precision::Confusion()) == Standard_True) {
481         aGeomSh->setImpl(new TopoDS_Shape(aShape));
482         thePrismAlgo->fixOrientation(aGeomSh);
483         thePrismAlgo->addToShape(aGeomSh);
484       }
485       if(anIntTools.IsValidPointForFace(aPnt,
486           theFromFace, Precision::Confusion()) == Standard_True) {
487         aGeomSh->setImpl(new TopoDS_Shape(aShape));
488         thePrismAlgo->fixOrientation(aGeomSh);
489         thePrismAlgo->addFromShape(aGeomSh);
490       }
491     } else if(theType == TopAbs_EDGE) {
492       TopoDS_Edge anEdge = TopoDS::Edge(aShape);
493       BRepLib_CheckCurveOnSurface anEdgeCheck(anEdge, theToFace);
494       anEdgeCheck.Perform();
495       if(anEdgeCheck.MaxDistance() < Precision::Confusion()) {
496         aGeomSh->setImpl(new TopoDS_Shape(aShape));
497         thePrismAlgo->fixOrientation(aGeomSh);
498         thePrismAlgo->addToShape(aGeomSh);
499       }
500       anEdgeCheck.Init(anEdge, theFromFace);
501       anEdgeCheck.Perform();
502       if(anEdgeCheck.MaxDistance() < Precision::Confusion()) {
503         aGeomSh->setImpl(new TopoDS_Shape(aShape));
504         thePrismAlgo->fixOrientation(aGeomSh);
505         thePrismAlgo->addFromShape(aGeomSh);
506       }
507     } else {
508       break;
509     }
510   }
511 }