1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_FilletDriver.hxx>
26 #include <GEOMImpl_IFillet.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOMImpl_ILocalOperations.hxx>
29 #include <GEOM_Function.hxx>
31 #include <BRepFilletAPI_MakeFillet.hxx>
32 #include <BRepCheck_Analyzer.hxx>
33 #include <BRep_Tool.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
39 #include <TopExp_Explorer.hxx>
41 #include <ShapeFix_ShapeTolerance.hxx>
42 #include <ShapeFix_Shape.hxx>
44 #include <Precision.hxx>
46 #include <StdFail_NotDone.hxx>
48 //=======================================================================
51 //=======================================================================
52 const Standard_GUID& GEOMImpl_FilletDriver::GetID()
54 static Standard_GUID aFilletDriver("FF1BBB41-5D14-4df2-980B-3A668264EA16");
59 //=======================================================================
60 //function : GEOMImpl_FilletDriver
62 //=======================================================================
63 GEOMImpl_FilletDriver::GEOMImpl_FilletDriver()
67 //=======================================================================
70 //=======================================================================
71 Standard_Integer GEOMImpl_FilletDriver::Execute(TFunction_Logbook& log) const
73 if (Label().IsNull()) return 0;
74 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
76 GEOMImpl_IFillet aCI (aFunction);
77 Standard_Integer aType = aFunction->GetType();
81 Handle(GEOM_Function) aRefShape = aCI.GetShape();
82 TopoDS_Shape aShapeBase = aRefShape->GetValue();
83 BRepFilletAPI_MakeFillet fill (aShapeBase);
85 if (aType == FILLET_SHAPE_ALL) {
86 TopExp_Explorer Exp (aShapeBase, TopAbs_EDGE);
87 for (; Exp.More(); Exp.Next()) {
88 TopoDS_Edge E = TopoDS::Edge(Exp.Current());
92 else if (aType == FILLET_SHAPE_EDGES || aType == FILLET_SHAPE_EDGES_2R) {
93 int aLen = aCI.GetLength();
95 for (; ind <= aLen; ind++) {
96 TopoDS_Shape aShapeEdge;
97 if (GEOMImpl_ILocalOperations::GetSubShape
98 (aShapeBase, aCI.GetEdge(ind), aShapeEdge)) {
99 fill.Add(TopoDS::Edge(aShapeEdge));
103 else if (aType == FILLET_SHAPE_FACES || aType == FILLET_SHAPE_FACES_2R) {
104 int aLen = aCI.GetLength();
106 for (; ind <= aLen; ind++) {
107 TopoDS_Shape aShapeFace;
108 if (GEOMImpl_ILocalOperations::GetSubShape
109 (aShapeBase, aCI.GetFace(ind), aShapeFace)) {
110 TopExp_Explorer Exp (aShapeFace, TopAbs_EDGE);
111 for (; Exp.More(); Exp.Next()) {
112 fill.Add(TopoDS::Edge(Exp.Current()));
120 if (aType == FILLET_SHAPE_FACES || aType == FILLET_SHAPE_EDGES || aType == FILLET_SHAPE_ALL) {
121 for (int i = 1; i <= fill.NbContours(); i++)
122 fill.SetRadius(aCI.GetR(), i, 1);
124 else if (aType == FILLET_SHAPE_FACES_2R || aType == FILLET_SHAPE_EDGES_2R) {
125 for (int i = 1; i <= fill.NbContours(); i++) {
126 fill.SetRadius(aCI.GetR1(), aCI.GetR2(), i, 1);
131 if (!fill.IsDone()) {
132 StdFail_NotDone::Raise("Fillet can't be computed on the given shape with the given radius");
134 aShape = fill.Shape();
136 if (aShape.IsNull()) return 0;
138 // Check shape validity
139 BRepCheck_Analyzer ana (aShape, false);
140 if (!ana.IsValid()) {
141 // 08.07.2008 added by skl during fixing bug 19761 from Mantis
142 ShapeFix_ShapeTolerance aSFT;
143 aSFT.LimitTolerance(aShape, Precision::Confusion(),
144 Precision::Confusion(), TopAbs_SHAPE);
145 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
147 aShape = aSfs->Shape();
150 StdFail_NotDone::Raise("Fillet algorithm have produced an invalid shape result");
153 aFunction->SetValue(aShape);
155 log.SetTouched(Label());
160 //================================================================================
162 * \brief Returns a name of creation operation and names and values of creation parameters
164 //================================================================================
166 bool GEOMImpl_FilletDriver::
167 GetCreationInformation(std::string& theOperationName,
168 std::vector<GEOM_Param>& theParams)
170 if (Label().IsNull()) return 0;
171 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
173 GEOMImpl_IFillet aCI( function );
174 Standard_Integer aType = function->GetType();
176 theOperationName = "FILLET";
179 case FILLET_SHAPE_ALL:
180 AddParam( theParams, "Main Object", aCI.GetShape() );
181 AddParam( theParams, "Selected edges", "all" );
183 case FILLET_SHAPE_EDGES:
184 case FILLET_SHAPE_EDGES_2R:
185 AddParam( theParams, "Main Object", aCI.GetShape() );
186 AddParam( theParams, "Selected edges" );
187 if ( aCI.GetLength() > 1 )
188 theParams[1] << aCI.GetLength() << " edges: ";
189 for (int i = 1; i <= aCI.GetLength(); ++i )
190 theParams[1] << aCI.GetEdge( i ) << " ";
191 if ( aType == FILLET_SHAPE_EDGES ) {
192 AddParam( theParams, "Radius", aCI.GetR() );
195 AddParam( theParams, "R1", aCI.GetR1() );
196 AddParam( theParams, "R2", aCI.GetR2() );
199 case FILLET_SHAPE_FACES:
200 case FILLET_SHAPE_FACES_2R:
201 AddParam( theParams, "Main Object", aCI.GetShape() );
202 AddParam( theParams, "Selected faces" );
203 if ( aCI.GetLength() > 1 )
204 theParams[1] << aCI.GetLength() << " faces: ";
205 for (int i = 1; i <= aCI.GetLength(); ++i )
206 theParams[1] << aCI.GetFace( i ) << " ";
207 if ( aType == FILLET_SHAPE_FACES ) {
208 AddParam( theParams, "Radius", aCI.GetR() );
211 AddParam( theParams, "R1", aCI.GetR1() );
212 AddParam( theParams, "R2", aCI.GetR2() );
222 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_FilletDriver,GEOM_BaseDriver);
223 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_FilletDriver,GEOM_BaseDriver);