1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <GeomAlgoAPI_ConeSegment.h>
26 #include <TopoDS_Edge.hxx>
28 #include <BRepPrimAPI_MakeRevol.hxx>
29 #include <BRepBuilderAPI_MakeEdge.hxx>
30 #include <BRepBuilderAPI_MakeWire.hxx>
31 #include <BRepBuilderAPI_MakeFace.hxx>
32 #include <Precision.hxx>
36 //=================================================================================================
38 GeomAlgoAPI_ConeSegment::GeomAlgoAPI_ConeSegment(const double theRMin1,
39 const double theRMax1,
40 const double theRMin2,
41 const double theRMax2,
43 const double theStartPhi,
44 const double theDeltaPhi)
51 myStartPhi = theStartPhi;
52 myDeltaPhi = theDeltaPhi;
55 //=================================================================================================
56 bool GeomAlgoAPI_ConeSegment::check()
60 myError = "Cone Segment builder :: rmin1 is negative.";
65 myError = "Cone Segment builder :: rmin2 is negative.";
68 if ((myRMax1-myRMin1) < Precision::Confusion())
70 myError = "Cone Segment builder :: rmin1 is larger than rmax1.";
73 if ((myRMax2-myRMin2) < Precision::Confusion())
75 myError = "Cone Segment builder :: rmin2 is larger than rmax2.";
78 if (myZ < Precision::Confusion())
80 myError = "Cone Segment builder :: z is negative or null.";
83 if (myDeltaPhi < Precision::Angular() * 180./M_PI)
85 myError = "Cone Segment builder :: deltaphi is negative or null.";
90 myError = "Cone Segment builder :: deltaphi is larger than 360 degree.";
96 //=================================================================================================
97 void GeomAlgoAPI_ConeSegment::build()
99 myCreatedFaces.clear();
101 const double aStartPhiRad = myStartPhi * M_PI/180.;
102 BRepBuilderAPI_MakeWire aWireBuilder;
104 // Define the section from the 4 vertices
105 gp_Pnt aPointOuterBase(myRMax1 * cos(aStartPhiRad), myRMax1 * sin(aStartPhiRad), -myZ/2.);
106 gp_Pnt aPointInnerBase(myRMin1 * cos(aStartPhiRad), myRMin1 * sin(aStartPhiRad), -myZ/2.);
107 gp_Pnt aPointOuterTop(myRMax2 * cos(aStartPhiRad), myRMax2 * sin(aStartPhiRad), myZ/2.);
108 gp_Pnt aPointInnerTop(myRMin2 * cos(aStartPhiRad), myRMin2 * sin(aStartPhiRad), myZ/2.);
110 if ((myRMax1 - myRMin1) >= Precision::Confusion()){
111 BRepBuilderAPI_MakeEdge anEdgeBuilderBase(aPointOuterBase, aPointInnerBase);
112 anEdgeBuilderBase.Build();
113 aWireBuilder.Add(anEdgeBuilderBase.Edge());
116 BRepBuilderAPI_MakeEdge anEdgeBuilderOuter(aPointOuterBase, aPointOuterTop);
117 anEdgeBuilderOuter.Build();
118 aWireBuilder.Add(anEdgeBuilderOuter.Edge());
119 if ((myRMax2 - myRMin2) >= Precision::Confusion()){
120 BRepBuilderAPI_MakeEdge anEdgeBuilderTop(aPointOuterTop, aPointInnerTop);
121 anEdgeBuilderTop.Build();
122 aWireBuilder.Add(anEdgeBuilderTop.Edge());
125 BRepBuilderAPI_MakeEdge anEdgeBuilderInner(aPointInnerTop, aPointInnerBase);
126 anEdgeBuilderInner.Build();
127 aWireBuilder.Add(anEdgeBuilderInner.Edge());
129 aWireBuilder.Build();
130 BRepBuilderAPI_MakeFace aFaceBuilder(aWireBuilder.Wire());
131 aFaceBuilder.Build();
133 if (!aFaceBuilder.IsDone()){
134 myError = "Cone Segment builder :: section is not valid";
138 // Perform a revolution based on the section to build the solid
139 gp_Dir aZDir(0., 0., 1.);
140 gp_Pnt anOrigin(0., 0., 0.);
141 gp_Ax1 aZAxis(anOrigin, aZDir);
142 BRepPrimAPI_MakeRevol* aRevolBuilder =
143 new BRepPrimAPI_MakeRevol(aFaceBuilder.Face(), aZAxis, myDeltaPhi * M_PI/180., Standard_True);
146 myError = "Cone Segment builder :: section revolution did not succeed";
148 if(!aRevolBuilder->IsDone()) {
149 myError = "Cone Segment builder :: section revolution did not succeed";
153 setImpl(aRevolBuilder);
154 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
156 std::shared_ptr<GeomAPI_Shape> aResultShape =
157 std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
158 aResultShape->setImpl(new TopoDS_Shape(aRevolBuilder->Shape()));
160 // Test on the shapes
161 if (!(aResultShape).get() || aResultShape->isNull()) {
162 myError = "Cone Segment builder :: resulting shape is null.";
166 setShape(aResultShape);