Back to index

salome-geom  6.5.0
GEOMImpl_OffsetDriver.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_OffsetDriver.hxx>
00026 #include <GEOMImpl_IOffset.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 
00030 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
00031 #include <BRep_Tool.hxx>
00032 #include <TopoDS.hxx>
00033 #include <TopoDS_Shape.hxx>
00034 #include <TopoDS_Vertex.hxx>
00035 #include <TopAbs.hxx>
00036 #include <TopExp.hxx>
00037 
00038 #include <Precision.hxx>
00039 #include <gp_Pnt.hxx>
00040 
00041 #include <BRepCheck_Analyzer.hxx>
00042 #include <ShapeFix_ShapeTolerance.hxx>
00043 #include <ShapeFix_Shape.hxx>
00044 
00045 #include <Standard_ConstructionError.hxx>
00046 #include <StdFail_NotDone.hxx>
00047 
00048 //=======================================================================
00049 //function : GetID
00050 //purpose  :
00051 //=======================================================================
00052 const Standard_GUID& GEOMImpl_OffsetDriver::GetID()
00053 {
00054   static Standard_GUID aOffsetDriver("FF1BBB51-5D14-4df2-980B-3A668264EA16");
00055   return aOffsetDriver;
00056 }
00057 
00058 
00059 //=======================================================================
00060 //function : GEOMImpl_OffsetDriver
00061 //purpose  :
00062 //=======================================================================
00063 GEOMImpl_OffsetDriver::GEOMImpl_OffsetDriver()
00064 {
00065 }
00066 
00067 //=======================================================================
00068 //function : Execute
00069 //purpose  :
00070 //=======================================================================
00071 Standard_Integer GEOMImpl_OffsetDriver::Execute(TFunction_Logbook& log) const
00072 {
00073   if (Label().IsNull()) return 0;
00074   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00075 
00076   GEOMImpl_IOffset aCI (aFunction);
00077   Standard_Integer aType = aFunction->GetType();
00078 
00079   TopoDS_Shape aShape;
00080 
00081   if (aType == OFFSET_SHAPE || aType == OFFSET_SHAPE_COPY) {
00082     Handle(GEOM_Function) aRefShape = aCI.GetShape();
00083     TopoDS_Shape aShapeBase = aRefShape->GetValue();
00084     Standard_Real anOffset = aCI.GetValue();
00085     Standard_Real aTol = Precision::Confusion();
00086 
00087     if (Abs(anOffset) < aTol) {
00088       TCollection_AsciiString aMsg ("Absolute value of offset can not be less than the tolerance value (");
00089       aMsg += TCollection_AsciiString(aTol);
00090       aMsg += ")";
00091       StdFail_NotDone::Raise(aMsg.ToCString());
00092     }
00093 
00094     BRepOffsetAPI_MakeOffsetShape MO (aShapeBase,
00095                                       aCI.GetValue(),
00096                                       aTol);
00097     if (MO.IsDone()) {
00098       aShape = MO.Shape();
00099       // 23.04.2010 skl for bug 21699 from Mantis
00100       BRepCheck_Analyzer ana (aShape, Standard_True);
00101       ana.Init(aShape);
00102       if (!ana.IsValid()) {
00103         ShapeFix_ShapeTolerance aSFT;
00104         aSFT.LimitTolerance(aShape, Precision::Confusion(),
00105                             Precision::Confusion(), TopAbs_SHAPE);
00106         Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
00107         aSfs->Perform();
00108         aShape = aSfs->Shape();
00109         ana.Init(aShape);
00110         if (!ana.IsValid())
00111           Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
00112       }
00113     }
00114     else {
00115       StdFail_NotDone::Raise("Offset construction failed");
00116     }
00117   } else {
00118   }
00119 
00120   if (aShape.IsNull()) return 0;
00121 
00122   aFunction->SetValue(aShape);
00123 
00124   log.SetTouched(Label());
00125 
00126   return 1;
00127 }
00128 
00129 
00130 //=======================================================================
00131 //function :  GEOMImpl_OffsetDriver_Type_
00132 //purpose  :
00133 //=======================================================================
00134 Standard_EXPORT Handle_Standard_Type& GEOMImpl_OffsetDriver_Type_()
00135 {
00136 
00137   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00138   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00139   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00140   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
00141   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00142   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00143 
00144 
00145   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00146   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_OffsetDriver",
00147                                                          sizeof(GEOMImpl_OffsetDriver),
00148                                                          1,
00149                                                          (Standard_Address)_Ancestors,
00150                                                          (Standard_Address)NULL);
00151 
00152   return _aType;
00153 }
00154 
00155 //=======================================================================
00156 //function : DownCast
00157 //purpose  :
00158 //=======================================================================
00159 const Handle(GEOMImpl_OffsetDriver) Handle(GEOMImpl_OffsetDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00160 {
00161   Handle(GEOMImpl_OffsetDriver) _anOtherObject;
00162 
00163   if (!AnObject.IsNull()) {
00164      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_OffsetDriver))) {
00165        _anOtherObject = Handle(GEOMImpl_OffsetDriver)((Handle(GEOMImpl_OffsetDriver)&)AnObject);
00166      }
00167   }
00168 
00169   return _anOtherObject ;
00170 }