Back to index

salome-geom  6.5.0
GEOMImpl_FilletDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <Standard_Stream.hxx>
00024 
00025 #include <GEOMImpl_FilletDriver.hxx>
00026 #include <GEOMImpl_IFillet.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOMImpl_ILocalOperations.hxx>
00029 #include <GEOM_Function.hxx>
00030 
00031 #include <BRepFilletAPI_MakeFillet.hxx>
00032 #include <BRepCheck_Analyzer.hxx>
00033 #include <BRep_Tool.hxx>
00034 
00035 #include <TopoDS.hxx>
00036 #include <TopoDS_Shape.hxx>
00037 #include <TopoDS_Edge.hxx>
00038 #include <TopAbs.hxx>
00039 #include <TopExp_Explorer.hxx>
00040 
00041 #include <ShapeFix_ShapeTolerance.hxx>
00042 #include <ShapeFix_Shape.hxx>
00043 
00044 #include <Precision.hxx>
00045 #include <gp_Pnt.hxx>
00046 #include <StdFail_NotDone.hxx>
00047 
00048 //=======================================================================
00049 //function : GetID
00050 //purpose  :
00051 //=======================================================================
00052 const Standard_GUID& GEOMImpl_FilletDriver::GetID()
00053 {
00054   static Standard_GUID aFilletDriver("FF1BBB41-5D14-4df2-980B-3A668264EA16");
00055   return aFilletDriver;
00056 }
00057 
00058 
00059 //=======================================================================
00060 //function : GEOMImpl_FilletDriver
00061 //purpose  :
00062 //=======================================================================
00063 GEOMImpl_FilletDriver::GEOMImpl_FilletDriver()
00064 {
00065 }
00066 
00067 //=======================================================================
00068 //function : Execute
00069 //purpose  :
00070 //=======================================================================
00071 Standard_Integer GEOMImpl_FilletDriver::Execute(TFunction_Logbook& log) const
00072 {
00073   if (Label().IsNull()) return 0;
00074   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00075 
00076   GEOMImpl_IFillet aCI (aFunction);
00077   Standard_Integer aType = aFunction->GetType();
00078 
00079   TopoDS_Shape aShape;
00080 
00081   Handle(GEOM_Function) aRefShape = aCI.GetShape();
00082   TopoDS_Shape aShapeBase = aRefShape->GetValue();
00083   BRepFilletAPI_MakeFillet fill (aShapeBase);
00084 
00085   if (aType == FILLET_SHAPE_ALL) {
00086     TopExp_Explorer Exp (aShapeBase, TopAbs_EDGE);
00087     for (; Exp.More(); Exp.Next()) {
00088       TopoDS_Edge E = TopoDS::Edge(Exp.Current());
00089       fill.Add(E);
00090     }
00091   }
00092   else if (aType == FILLET_SHAPE_EDGES || aType == FILLET_SHAPE_EDGES_2R) {
00093     int aLen = aCI.GetLength();
00094     int ind = 1;
00095     for (; ind <= aLen; ind++) {
00096       TopoDS_Shape aShapeEdge;
00097       if (GEOMImpl_ILocalOperations::GetSubShape
00098           (aShapeBase, aCI.GetEdge(ind), aShapeEdge)) {
00099           fill.Add(TopoDS::Edge(aShapeEdge));
00100       }
00101     }
00102   }
00103   else if (aType == FILLET_SHAPE_FACES || aType == FILLET_SHAPE_FACES_2R) {
00104     int aLen = aCI.GetLength();
00105     int ind = 1;
00106     for (; ind <= aLen; ind++) {
00107       TopoDS_Shape aShapeFace;
00108       if (GEOMImpl_ILocalOperations::GetSubShape
00109           (aShapeBase, aCI.GetFace(ind), aShapeFace)) {
00110         TopExp_Explorer Exp (aShapeFace, TopAbs_EDGE);
00111         for (; Exp.More(); Exp.Next()) {
00112           fill.Add(TopoDS::Edge(Exp.Current()));
00113         }
00114       }
00115     }
00116   }
00117   else {
00118   }
00119 
00120   if (aType == FILLET_SHAPE_FACES || aType == FILLET_SHAPE_EDGES || aType == FILLET_SHAPE_ALL) {
00121     for (int i = 1; i <= fill.NbContours(); i++)
00122       fill.SetRadius(aCI.GetR(), i, 1);
00123   }
00124   else if (aType == FILLET_SHAPE_FACES_2R || aType == FILLET_SHAPE_EDGES_2R) {
00125     for (int i = 1; i <= fill.NbContours(); i++) {
00126       fill.SetRadius(aCI.GetR1(), aCI.GetR2(), i, 1);
00127     }
00128   }
00129 
00130   fill.Build();
00131   if (!fill.IsDone()) {
00132     StdFail_NotDone::Raise("Fillet can't be computed on the given shape with the given radius");
00133   }
00134   aShape = fill.Shape();
00135 
00136   if (aShape.IsNull()) return 0;
00137 
00138   // Check shape validity
00139   BRepCheck_Analyzer ana (aShape, false);
00140   if (!ana.IsValid()) {
00141     // 08.07.2008 added by skl during fixing bug 19761 from Mantis
00142     ShapeFix_ShapeTolerance aSFT;
00143     aSFT.LimitTolerance(aShape, Precision::Confusion(),
00144                         Precision::Confusion(), TopAbs_SHAPE);
00145     Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
00146     aSfs->Perform();
00147     aShape = aSfs->Shape();
00148     ana.Init(aShape);
00149     if (!ana.IsValid())
00150       StdFail_NotDone::Raise("Fillet algorithm have produced an invalid shape result");
00151   }
00152 
00153   aFunction->SetValue(aShape);
00154 
00155   log.SetTouched(Label());
00156 
00157   return 1;
00158 }
00159 
00160 
00161 //=======================================================================
00162 //function :  GEOMImpl_FilletDriver_Type_
00163 //purpose  :
00164 //=======================================================================
00165 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FilletDriver_Type_()
00166 {
00167 
00168   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00169   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00170   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00171   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
00172   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00173   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00174 
00175 
00176   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00177   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FilletDriver",
00178                                                          sizeof(GEOMImpl_FilletDriver),
00179                                                          1,
00180                                                          (Standard_Address)_Ancestors,
00181                                                          (Standard_Address)NULL);
00182 
00183   return _aType;
00184 }
00185 
00186 //=======================================================================
00187 //function : DownCast
00188 //purpose  :
00189 //=======================================================================
00190 const Handle(GEOMImpl_FilletDriver) Handle(GEOMImpl_FilletDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00191 {
00192   Handle(GEOMImpl_FilletDriver) _anOtherObject;
00193 
00194   if (!AnObject.IsNull()) {
00195      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FilletDriver))) {
00196        _anOtherObject = Handle(GEOMImpl_FilletDriver)((Handle(GEOMImpl_FilletDriver)&)AnObject);
00197      }
00198   }
00199 
00200   return _anOtherObject ;
00201 }