1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Prism.h
5 // Author: Dmitry Bobylev
7 #include <GeomAlgoAPI_Prism.h>
9 #include <GeomAlgoAPI_DFLoader.h>
11 #include <BRep_Tool.hxx>
12 #include <BRepCheck_Analyzer.hxx>
13 #include <BRepFeat_MakePrism.hxx>
14 #include <BRepGProp.hxx>
15 #include <Geom_CylindricalSurface.hxx>
16 #include <Geom_Plane.hxx>
17 #include <Geom_RectangularTrimmedSurface.hxx>
18 #include <gp_Cylinder.hxx>
20 #include <GProp_GProps.hxx>
21 #include <LocOpe_FindEdgesInFace.hxx>
22 #include <TopExp_Explorer.hxx>
25 GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr<GeomAPI_Shape> theBasis,
26 std::shared_ptr<GeomAPI_Shape> theFromShape,
27 std::shared_ptr<GeomAPI_Shape> theToShape)
28 : myFromShape(theFromShape),
29 myToShape(theToShape),
30 myShape(new GeomAPI_Shape()),
31 myFirst(new GeomAPI_Shape()),myLast(new GeomAPI_Shape())
36 //============================================================================
37 void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis)
39 TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
40 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(
41 BRep_Tool::Surface(aBasis));
42 if(aPlane.IsNull()) { // non-planar shapes is not supported for extrusion yet
46 const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
47 BRepFeat_MakePrism* aBuilder = new BRepFeat_MakePrism(aBasis, aBasis, aBasis, aNormal, 2, Standard_True);
51 TopoDS_Shape aFromShape = myFromShape->impl<TopoDS_Shape>();
52 TopoDS_Shape aToShape = myToShape->impl<TopoDS_Shape>();
53 aBuilder->Perform(myFromShape->impl<TopoDS_Shape>(), myToShape->impl<TopoDS_Shape>());
54 myDone = aBuilder->IsDone();
57 if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND) {
58 aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape());
61 aResult = aBuilder->Shape();
63 TopExp_Explorer anExp(aResult, TopAbs_SOLID);
67 // fill data map to keep correct orientation of sub-shapes
68 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
69 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
70 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
71 myMap.bind(aCurrentShape, aCurrentShape);
73 myShape->setImpl(new TopoDS_Shape(aResult));
74 myFirst->setImpl(new TopoDS_Shape(aBuilder->Modified(aFromShape).First()));
75 myLast->setImpl(new TopoDS_Shape(aBuilder->Modified(aToShape).First()));
76 myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
81 //============================================================================
82 const bool GeomAlgoAPI_Prism::isDone() const
87 //============================================================================
88 const bool GeomAlgoAPI_Prism::isValid() const
90 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
91 return (aChecker.IsValid() == Standard_True);
94 //============================================================================
95 const bool GeomAlgoAPI_Prism::hasVolume() const
97 bool hasVolume(false);
99 const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
101 BRepGProp::VolumeProperties(aRShape, aGProp);
102 if(aGProp.Mass() > Precision::Confusion())
108 //============================================================================
109 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::shape () const
114 //============================================================================
115 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::firstShape()
120 //============================================================================
121 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::lastShape()
126 //============================================================================
127 void GeomAlgoAPI_Prism::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
132 //============================================================================
133 GeomAlgoAPI_MakeShape* GeomAlgoAPI_Prism::makeShape() const
138 //============================================================================
139 GeomAlgoAPI_Prism::~GeomAlgoAPI_Prism()