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;
42 TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
43 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(
44 BRep_Tool::Surface(aBasis));
45 if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet
48 const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
52 BRepPrimAPI_MakePrism* aBuilder = new BRepPrimAPI_MakePrism(aBasis, aVec);
55 myDone = aBuilder->IsDone() == Standard_True;
57 BRepCheck_Analyzer aChecker(aBuilder->Shape());
58 myDone = aChecker.IsValid() == Standard_True;
62 if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND)
63 aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape());
65 aResult = aBuilder->Shape();
67 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
68 boost::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
69 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
70 myMap.bind(aCurrentShape, aCurrentShape);
73 myShape->setImpl(new TopoDS_Shape(aResult));
74 myFirst->setImpl(new TopoDS_Shape(aBuilder->FirstShape()));
75 myLast->setImpl(new TopoDS_Shape(aBuilder-> LastShape()));
76 myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
81 //============================================================================
82 const bool GeomAlgoAPI_Extrusion::isDone() const
85 //============================================================================
86 const bool GeomAlgoAPI_Extrusion::isValid() const
91 //============================================================================
92 const bool GeomAlgoAPI_Extrusion::hasVolume() const
94 bool hasVolume(false);
96 const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
98 BRepGProp::VolumeProperties(aRShape, aGProp);
99 if(aGProp.Mass() > Precision::Confusion())
105 //============================================================================
106 const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const
109 //============================================================================
110 /*void GeomAlgoAPI_Extrusion::generated(
111 const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
115 const TopTools_ListOfShape& aList = implPtr<BRepPrimAPI_MakePrism>()
116 ->Generated(theShape->impl<TopoDS_Shape>());
117 TopTools_ListIteratorOfListOfShape it(aList);
118 for(;it.More();it.Next()) {
119 boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
120 aShape->setImpl(&(it.Value()));
121 theHistory.push_back(aShape);
126 //============================================================================
127 const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
132 //============================================================================
133 const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
138 //============================================================================
139 void GeomAlgoAPI_Extrusion::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
144 //============================================================================
145 GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const
150 //============================================================================
151 GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion()