1 // Copyright (C) 2007-2016 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 <GEOMImpl_FilletDriver.hxx>
24 #include <GEOMImpl_IFillet.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOMImpl_ILocalOperations.hxx>
27 #include <GEOMUtils.hxx>
28 #include <GEOM_Function.hxx>
30 #include <BRepFilletAPI_MakeFillet.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Edge.hxx>
35 #include <TopExp_Explorer.hxx>
36 #include <StdFail_NotDone.hxx>
38 // Debug PipeTShape function: uncomment the macro below to correct tolerance
39 // of resulting face after fillet creation
40 // VSR 30/12/2014: macro disabled
41 //#define FIX_FACE_TOLERANCE
42 // Debug PipeTShape function: uncomment the macro below to correct tolerance
43 // of resulting curves after fillet creation
44 // VSR 30/12/2014: macro disabled
45 //#define FIX_CURVES_TOLERANCES
47 //=======================================================================
50 //=======================================================================
51 const Standard_GUID& GEOMImpl_FilletDriver::GetID()
53 static Standard_GUID aFilletDriver("FF1BBB41-5D14-4df2-980B-3A668264EA16");
58 //=======================================================================
59 //function : GEOMImpl_FilletDriver
61 //=======================================================================
62 GEOMImpl_FilletDriver::GEOMImpl_FilletDriver()
66 //=======================================================================
69 //=======================================================================
70 Standard_Integer GEOMImpl_FilletDriver::Execute(LOGBOOK& log) const
72 if (Label().IsNull()) return 0;
73 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
75 GEOMImpl_IFillet aCI (aFunction);
76 Standard_Integer aType = aFunction->GetType();
80 Handle(GEOM_Function) aRefShape = aCI.GetShape();
81 TopoDS_Shape aShapeBase = aRefShape->GetValue();
82 BRepFilletAPI_MakeFillet fill (aShapeBase);
84 if (aType == FILLET_SHAPE_ALL) {
85 TopExp_Explorer Exp (aShapeBase, TopAbs_EDGE);
86 for (; Exp.More(); Exp.Next()) {
87 TopoDS_Edge E = TopoDS::Edge(Exp.Current());
91 else if (aType == FILLET_SHAPE_EDGES || aType == FILLET_SHAPE_EDGES_2R) {
92 int aLen = aCI.GetLength();
94 for (; ind <= aLen; ind++) {
95 TopoDS_Shape aShapeEdge;
96 if (GEOMImpl_ILocalOperations::GetSubShape
97 (aShapeBase, aCI.GetEdge(ind), aShapeEdge)) {
98 fill.Add(TopoDS::Edge(aShapeEdge));
102 else if (aType == FILLET_SHAPE_FACES || aType == FILLET_SHAPE_FACES_2R) {
103 int aLen = aCI.GetLength();
105 for (; ind <= aLen; ind++) {
106 TopoDS_Shape aShapeFace;
107 if (GEOMImpl_ILocalOperations::GetSubShape
108 (aShapeBase, aCI.GetFace(ind), aShapeFace)) {
109 TopExp_Explorer Exp (aShapeFace, TopAbs_EDGE);
110 for (; Exp.More(); Exp.Next()) {
111 fill.Add(TopoDS::Edge(Exp.Current()));
119 if (aType == FILLET_SHAPE_FACES || aType == FILLET_SHAPE_EDGES || aType == FILLET_SHAPE_ALL) {
120 for (int i = 1; i <= fill.NbContours(); i++)
121 fill.SetRadius(aCI.GetR(), i, 1);
123 else if (aType == FILLET_SHAPE_FACES_2R || aType == FILLET_SHAPE_EDGES_2R) {
124 for (int i = 1; i <= fill.NbContours(); i++) {
125 fill.SetRadius(aCI.GetR1(), aCI.GetR2(), i, 1);
130 if (!fill.IsDone()) {
131 StdFail_NotDone::Raise("Fillet can't be computed on the given shape with the given radius");
133 aShape = GEOMUtils::ReduceCompound( fill.Shape() );
135 if (aShape.IsNull()) return 0;
137 #if defined(FIX_CURVES_TOLERANCES)
138 bool isOk = GEOMUtils::FixShapeCurves(aShape);
139 #elif defined(FIX_FACE_TOLERANCE)
140 bool isOk = GEOMUtils::FixShapeTolerance(aShape, TopAbs_FACE);
142 // 08.07.2008 added by skl during fixing bug 19761 from Mantis
143 bool isOk = GEOMUtils::CheckShape(aShape) || GEOMUtils::FixShapeTolerance(aShape);
146 StdFail_NotDone::Raise("Fillet algorithm have produced an invalid shape result");
148 aFunction->SetValue(aShape);
150 #if OCC_VERSION_MAJOR < 7
151 log.SetTouched(Label());
153 log->SetTouched(Label());
159 //================================================================================
161 * \brief Returns a name of creation operation and names and values of creation parameters
163 //================================================================================
165 bool GEOMImpl_FilletDriver::
166 GetCreationInformation(std::string& theOperationName,
167 std::vector<GEOM_Param>& theParams)
169 if (Label().IsNull()) return 0;
170 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
172 GEOMImpl_IFillet aCI( function );
173 Standard_Integer aType = function->GetType();
175 theOperationName = "FILLET";
178 case FILLET_SHAPE_ALL:
179 AddParam( theParams, "Main Object", aCI.GetShape() );
180 AddParam( theParams, "Selected edges", "all" );
182 case FILLET_SHAPE_EDGES:
183 case FILLET_SHAPE_EDGES_2R:
184 AddParam( theParams, "Main Object", aCI.GetShape() );
185 AddParam( theParams, "Selected edges" );
186 if ( aCI.GetLength() > 1 )
187 theParams[1] << aCI.GetLength() << " edges: ";
188 for (int i = 1; i <= aCI.GetLength(); ++i )
189 theParams[1] << aCI.GetEdge( i ) << " ";
190 if ( aType == FILLET_SHAPE_EDGES ) {
191 AddParam( theParams, "Radius", aCI.GetR() );
194 AddParam( theParams, "R1", aCI.GetR1() );
195 AddParam( theParams, "R2", aCI.GetR2() );
198 case FILLET_SHAPE_FACES:
199 case FILLET_SHAPE_FACES_2R:
200 AddParam( theParams, "Main Object", aCI.GetShape() );
201 AddParam( theParams, "Selected faces" );
202 if ( aCI.GetLength() > 1 )
203 theParams[1] << aCI.GetLength() << " faces: ";
204 for (int i = 1; i <= aCI.GetLength(); ++i )
205 theParams[1] << aCI.GetFace( i ) << " ";
206 if ( aType == FILLET_SHAPE_FACES ) {
207 AddParam( theParams, "Radius", aCI.GetR() );
210 AddParam( theParams, "R1", aCI.GetR1() );
211 AddParam( theParams, "R2", aCI.GetR2() );
221 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_FilletDriver,GEOM_BaseDriver);