1 // File: GeomAlgoAPI_Extrusion.cpp
2 // Created: 06 Jun 2014
3 // Author: Artem ZHIDKOV
5 #include <GeomAlgoAPI_Extrusion.h>
6 #include <GeomAlgoAPI_MakeShape.h>
7 #include <GeomAlgoAPI_DFLoader.h>
8 #include <GeomAlgoAPI_MakeShape.h>
10 #include <BRepPrimAPI_MakePrism.hxx>
11 #include <BRepBuilderAPI_MakeShape.hxx>
12 #include <Geom_Plane.hxx>
13 #include <Geom_Surface.hxx>
14 #include <TopExp_Explorer.hxx>
15 #include <BRepCheck_Analyzer.hxx>
16 #include <GProp_GProps.hxx>
17 #include <BRepGProp.hxx>
19 #include <TopTools_ListIteratorOfListOfShape.hxx>
20 #include <Precision.hxx>
21 #include <TDF_TagSource.hxx>
22 #include <boost/shared_ptr.hpp>
23 #include <BRepPrimAPI_MakePrism.hxx>
24 #include <TopoDS_Shape.hxx>
26 const double tolerance = Precision::Angular();
28 GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion(
29 boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize)
30 : mySize(theSize), myDone(false), myShape(new GeomAPI_Shape()),
31 myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape())
36 //============================================================================
37 void GeomAlgoAPI_Extrusion::build(const boost::shared_ptr<GeomAPI_Shape>& theBasis)
39 bool isFirstNorm = true;
41 TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
42 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(
43 BRep_Tool::Surface(aBasis));
44 if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet
47 const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
51 BRepPrimAPI_MakePrism* aBuilder = new BRepPrimAPI_MakePrism(aBasis, aVec);
54 myDone = aBuilder->IsDone() == Standard_True;
57 if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND)
58 aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape());
60 aResult = aBuilder->Shape();
61 // fill data map to keep correct orientation of sub-shapes
62 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
63 boost::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
64 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
65 myMap.bind(aCurrentShape, aCurrentShape);
67 myShape->setImpl(new TopoDS_Shape(aResult));
68 myFirst->setImpl(new TopoDS_Shape(aBuilder->FirstShape()));
69 myLast->setImpl(new TopoDS_Shape(aBuilder-> LastShape()));
70 myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
75 //============================================================================
76 const bool GeomAlgoAPI_Extrusion::isDone() const
79 //============================================================================
80 const bool GeomAlgoAPI_Extrusion::isValid() const
82 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
83 return (aChecker.IsValid() == Standard_True);
86 //============================================================================
87 const bool GeomAlgoAPI_Extrusion::hasVolume() const
89 bool hasVolume(false);
91 const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
93 BRepGProp::VolumeProperties(aRShape, aGProp);
94 if(aGProp.Mass() > Precision::Confusion())
100 //============================================================================
101 const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const
106 //============================================================================
107 const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
112 //============================================================================
113 const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
118 //============================================================================
119 void GeomAlgoAPI_Extrusion::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
124 //============================================================================
125 GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const
130 //============================================================================
131 GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion()