Back to index

salome-geom  6.5.0
GEOMImpl_ThruSectionsDriver.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_ThruSectionsDriver.hxx>
00026 #include <GEOMImpl_IThruSections.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 
00030 #include <TColStd_HSequenceOfTransient.hxx>
00031 #include <Precision.hxx>
00032 #include <BRepCheck_Analyzer.hxx>
00033 #include <BRepOffsetAPI_ThruSections.hxx>
00034 #include <BRepBuilderAPI_MakeWire.hxx>
00035 #include <TopExp_Explorer.hxx>
00036 #include <TopoDS.hxx>
00037 
00038 #include <TopAbs.hxx>
00039 #include <TopoDS.hxx>
00040 #include <TopoDS_Wire.hxx>
00041 #include <TopoDS_Edge.hxx>
00042 #include <TopoDS_Shape.hxx>
00043 
00044 #include <Standard_NullObject.hxx>
00045 #include <Standard_TypeMismatch.hxx>
00046 #include <Standard_ConstructionError.hxx>
00047 #include <ShapeFix_Shape.hxx>
00048 #include <ShapeFix_ShapeTolerance.hxx>
00049 #include <Precision.hxx>
00050 //=======================================================================
00051 //function : GetID
00052 //purpose  :
00053 //=======================================================================
00054 const Standard_GUID& GEOMImpl_ThruSectionsDriver::GetID()
00055 {
00056   static Standard_GUID aThruSectionsDriver("FF1BB971-E99C-4f89-B989-5B48E061049B");
00057   return aThruSectionsDriver;
00058 }
00059 
00060 
00061 //=======================================================================
00062 //function : GEOMImpl_ThruSectionsDriver
00063 //purpose  :
00064 //=======================================================================
00065 GEOMImpl_ThruSectionsDriver::GEOMImpl_ThruSectionsDriver()
00066 {
00067 }
00068 
00069 //=======================================================================
00070 //function : Execute
00071 //purpose  :
00072 //=======================================================================
00073 Standard_Integer GEOMImpl_ThruSectionsDriver::Execute(TFunction_Logbook& log) const
00074 {
00075   if (Label().IsNull()) return 0;
00076   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00077 
00078   GEOMImpl_IThruSections aCI (aFunction);
00079   Standard_Integer aType = aFunction->GetType();
00080 
00081   Standard_Boolean isSolid = (aCI.GetSolidMode() == 1);
00082   Handle(TColStd_HSequenceOfTransient) aSeqSections = aCI.GetSections();
00083 
00084   if( aSeqSections.IsNull())
00085     return 0;
00086 
00087   Standard_Integer aNbSections = aSeqSections->Length();
00088   Standard_Real aPreci = Max(aCI.GetPrecision(),Precision::Confusion());
00089   if(!aNbSections )
00090     return 0;
00091 
00092   BRepOffsetAPI_ThruSections aBuilder(isSolid,aType ==THRUSECTIONS_RULED,aPreci);
00093   
00094  
00095   aBuilder.CheckCompatibility(Standard_False);
00096   //added sections for building surface
00097   Standard_Integer i =1;
00098   Standard_Integer nbAdded =0;
00099   for( ; i <= aNbSections; i++,nbAdded++)
00100   {
00101     Handle(Standard_Transient) anItem = aSeqSections->Value(i);
00102     if(anItem.IsNull())
00103       continue;
00104 
00105     Handle(GEOM_Function) aSection = Handle(GEOM_Function)::DownCast(anItem);
00106     if(aSection.IsNull())
00107       continue;
00108 
00109     TopoDS_Shape aShapeSection = aSection->GetValue();
00110     TopAbs_ShapeEnum aTypeSect = aShapeSection.ShapeType();
00111     if(aTypeSect == TopAbs_WIRE)
00112       aBuilder.AddWire(TopoDS::Wire(aShapeSection));
00113 
00114     else if(aTypeSect == TopAbs_EDGE) {
00115       TopoDS_Edge anEdge = TopoDS::Edge(aShapeSection);
00116       TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge);
00117       aBuilder.AddWire(aWire);
00118     }
00119     else if(aTypeSect == TopAbs_VERTEX) {
00120       TopoDS_Vertex aVert = TopoDS::Vertex(aShapeSection);
00121       aBuilder.AddVertex(aVert);
00122     }
00123     else
00124        nbAdded--; 
00125   }  
00126   if(!nbAdded)
00127      Standard_TypeMismatch::Raise("ThruSections aborted : invalid types of sections");
00128   //make surface by sections
00129   aBuilder.Build();
00130   TopoDS_Shape aShape = aBuilder.Shape();
00131   if (aShape.IsNull()) {
00132     return 0;
00133   }
00134 
00135   BRepCheck_Analyzer ana (aShape, Standard_False);
00136   if (!ana.IsValid()) {
00137     //algoritm thru section creats on the arcs invalid shapes gka
00138     ShapeFix_ShapeTolerance aSFT;
00139     aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
00140     Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
00141     aSfs->SetPrecision(Precision::Confusion());
00142     aSfs->Perform();
00143     aShape = aSfs->Shape();
00144     //ana.Init(aShape, Standard_False);
00145     //if (!ana.IsValid()) 
00146     //  Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
00147   }
00148 
00149 
00150   aFunction->SetValue(aShape);
00151 
00152   log.SetTouched(Label());
00153 
00154   return 1;
00155 }
00156 
00157 
00158 //=======================================================================
00159 //function :  GEOMImpl_ThruSectionsDriver_Type_
00160 //purpose  :
00161 //=======================================================================
00162 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ThruSectionsDriver_Type_()
00163 {
00164 
00165   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00166   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00167   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00168   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
00169   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00170   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00171 
00172 
00173   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00174   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ThruSectionsDriver",
00175                                                          sizeof(GEOMImpl_ThruSectionsDriver),
00176                                                          1,
00177                                                          (Standard_Address)_Ancestors,
00178                                                          (Standard_Address)NULL);
00179 
00180   return _aType;
00181 }
00182 
00183 //=======================================================================
00184 //function : DownCast
00185 //purpose  :
00186 //=======================================================================
00187 const Handle(GEOMImpl_ThruSectionsDriver) Handle(GEOMImpl_ThruSectionsDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00188 {
00189   Handle(GEOMImpl_ThruSectionsDriver) _anOtherObject;
00190 
00191   if (!AnObject.IsNull()) {
00192      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ThruSectionsDriver))) {
00193        _anOtherObject = Handle(GEOMImpl_ThruSectionsDriver)((Handle(GEOMImpl_ThruSectionsDriver)&)AnObject);
00194      }
00195   }
00196 
00197   return _anOtherObject ;
00198 }