1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Extrusion.cpp
4 // Created: 06 Jun 2014
5 // Author: Artem ZHIDKOV
7 #include <GeomAlgoAPI_Extrusion.h>
8 #include <GeomAlgoAPI_MakeShape.h>
9 #include <GeomAlgoAPI_DFLoader.h>
10 #include <GeomAlgoAPI_MakeShape.h>
12 #include <BRepPrimAPI_MakePrism.hxx>
13 #include <BRepBuilderAPI_MakeShape.hxx>
14 #include <Geom_Plane.hxx>
15 #include <Geom_Surface.hxx>
16 #include <TopExp_Explorer.hxx>
17 #include <BRepCheck_Analyzer.hxx>
18 #include <GProp_GProps.hxx>
19 #include <BRepGProp.hxx>
21 #include <TopTools_ListIteratorOfListOfShape.hxx>
22 #include <Precision.hxx>
23 #include <TDF_TagSource.hxx>
25 #include <BRepPrimAPI_MakePrism.hxx>
26 #include <TopoDS_Shape.hxx>
28 const double tolerance = Precision::Angular();
30 GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion(
31 std::shared_ptr<GeomAPI_Shape> theBasis, double theSize)
32 : mySize(theSize), myDone(false), myShape(new GeomAPI_Shape()),
33 myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape())
38 //============================================================================
39 void GeomAlgoAPI_Extrusion::build(const std::shared_ptr<GeomAPI_Shape>& theBasis)
41 bool isFirstNorm = true;
43 TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
44 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(
45 BRep_Tool::Surface(aBasis));
46 if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet
49 const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
53 BRepPrimAPI_MakePrism* aBuilder = new BRepPrimAPI_MakePrism(aBasis, aVec);
56 myDone = aBuilder->IsDone() == Standard_True;
59 if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND)
60 aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape());
62 aResult = aBuilder->Shape();
63 // fill data map to keep correct orientation of sub-shapes
64 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
65 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
66 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
67 myMap.bind(aCurrentShape, aCurrentShape);
69 myShape->setImpl(new TopoDS_Shape(aResult));
70 myFirst->setImpl(new TopoDS_Shape(aBuilder->FirstShape()));
71 myLast->setImpl(new TopoDS_Shape(aBuilder-> LastShape()));
72 myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
77 //============================================================================
78 const bool GeomAlgoAPI_Extrusion::isDone() const
81 //============================================================================
82 const bool GeomAlgoAPI_Extrusion::isValid() const
84 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
85 return (aChecker.IsValid() == Standard_True);
88 //============================================================================
89 const bool GeomAlgoAPI_Extrusion::hasVolume() const
91 bool hasVolume(false);
93 const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
95 BRepGProp::VolumeProperties(aRShape, aGProp);
96 if(aGProp.Mass() > Precision::Confusion())
102 //============================================================================
103 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const
108 //============================================================================
109 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
114 //============================================================================
115 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
120 //============================================================================
121 void GeomAlgoAPI_Extrusion::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
126 //============================================================================
127 GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const
132 //============================================================================
133 GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion()