1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Prism.cpp
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_Plane.hxx>
17 #include <GProp_GProps.hxx>
18 #include <TopExp_Explorer.hxx>
21 //=================================================================================================
22 GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr<GeomAPI_Shape> theBasis,
23 std::shared_ptr<GeomAPI_Shape> theFromShape,
24 std::shared_ptr<GeomAPI_Shape> theToShape)
25 : myFromShape(theFromShape),
26 myToShape(theToShape),
28 myShape(new GeomAPI_Shape()),
29 myFirst(new GeomAPI_Shape()),myLast(new GeomAPI_Shape())
34 //=================================================================================================
35 void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis)
37 if(!theBasis || !myFromShape || !myToShape ||
38 (myFromShape && myToShape && myFromShape->isEqual(myToShape))) {
42 TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
43 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aBasis));
44 if(aPlane.IsNull()) { // non-planar shapes is not supported for extrusion yet
48 const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
49 BRepFeat_MakePrism* aBuilder = new BRepFeat_MakePrism(aBasis, aBasis, aBasis, aNormal, 2, Standard_True);
53 TopoDS_Shape aFromShape = myFromShape->impl<TopoDS_Shape>();
54 TopoDS_Shape aToShape = myToShape->impl<TopoDS_Shape>();
55 aBuilder->Perform(aFromShape, aToShape);
56 myDone = aBuilder->IsDone() == Standard_True;
58 TopoDS_Shape aResult = aBuilder->Shape();
59 TopExp_Explorer anExp(aResult, TopAbs_SOLID);
63 if(aResult.ShapeType() == TopAbs_COMPOUND) {
64 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
66 // fill data map to keep correct orientation of sub-shapes
67 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
68 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
69 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
70 myMap.bind(aCurrentShape, aCurrentShape);
72 myShape->setImpl(new TopoDS_Shape(aResult));
73 myFirst->setImpl(new TopoDS_Shape(aBuilder->Modified(aFromShape).First()));
74 myLast->setImpl(new TopoDS_Shape(aBuilder->Modified(aToShape).First()));
75 myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
80 //=================================================================================================
81 const bool GeomAlgoAPI_Prism::isDone() const
86 //=================================================================================================
87 const bool GeomAlgoAPI_Prism::isValid() const
89 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
90 return (aChecker.IsValid() == Standard_True);
93 //=================================================================================================
94 const bool GeomAlgoAPI_Prism::hasVolume() const
96 bool hasVolume(false);
98 const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
100 BRepGProp::VolumeProperties(aRShape, aGProp);
101 if(aGProp.Mass() > Precision::Confusion())
107 //=================================================================================================
108 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::shape () const
113 //=================================================================================================
114 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::firstShape()
119 //=================================================================================================
120 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::lastShape()
125 //=================================================================================================
126 void GeomAlgoAPI_Prism::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
131 //=================================================================================================
132 GeomAlgoAPI_MakeShape* GeomAlgoAPI_Prism::makeShape() const
137 //=================================================================================================
138 GeomAlgoAPI_Prism::~GeomAlgoAPI_Prism()