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