Back to index

salome-geom  6.5.0
GEOMImpl_SphereDriver.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_SphereDriver.hxx>
00026 #include <GEOMImpl_ISphere.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 
00030 #include <BRepPrimAPI_MakeSphere.hxx>
00031 #include <BRep_Tool.hxx>
00032 #include <gp_Pnt.hxx>
00033 #include <TopoDS.hxx>
00034 #include <TopoDS_Shape.hxx>
00035 #include <TopoDS_Vertex.hxx>
00036 #include <TopAbs.hxx>
00037 
00038 //=======================================================================
00039 //function : GetID
00040 //purpose  :
00041 //======================================================================= 
00042 const Standard_GUID& GEOMImpl_SphereDriver::GetID()
00043 {
00044   static Standard_GUID aSphereDriver("FF1BBB16-5D14-4df2-980B-3A668264EA16");
00045   return aSphereDriver; 
00046 }
00047 
00048 
00049 //=======================================================================
00050 //function : GEOMImpl_SphereDriver
00051 //purpose  : 
00052 //=======================================================================
00053 GEOMImpl_SphereDriver::GEOMImpl_SphereDriver() 
00054 {
00055 }
00056 
00057 //=======================================================================
00058 //function : Execute
00059 //purpose  :
00060 //======================================================================= 
00061 Standard_Integer GEOMImpl_SphereDriver::Execute(TFunction_Logbook& log) const
00062 {
00063   if (Label().IsNull()) return 0;    
00064   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00065 
00066   GEOMImpl_ISphere aCI (aFunction);
00067   Standard_Integer aType = aFunction->GetType();
00068 
00069   TopoDS_Shape aShape;
00070 
00071   char aMsg[] = "Sphere creation aborted: radius value less than 1e-07 is not acceptable";
00072 
00073   if (aType == SPHERE_R) {
00074     double anR = aCI.GetR();
00075     if (anR < Precision::Confusion())
00076       Standard_ConstructionError::Raise(aMsg);
00077 
00078     aShape = BRepPrimAPI_MakeSphere(anR).Shape();
00079   }
00080   else if (aType == SPHERE_PNT_R) {
00081     double anR = aCI.GetR();
00082     if (anR < Precision::Confusion())
00083       Standard_ConstructionError::Raise(aMsg);
00084 
00085     Handle(GEOM_Function) aRefPoint  = aCI.GetPoint();
00086     TopoDS_Shape aShapePnt = aRefPoint->GetValue();
00087     if (aShapePnt.ShapeType() != TopAbs_VERTEX)
00088       Standard_ConstructionError::Raise("Invalid shape given for sphere center: it must be a point");
00089     gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
00090 
00091     aShape = BRepPrimAPI_MakeSphere(aP, anR).Shape();
00092   }
00093   else {
00094   }
00095 
00096   if (aShape.IsNull()) return 0;
00097 
00098   aFunction->SetValue(aShape);
00099 
00100   log.SetTouched(Label()); 
00101 
00102   return 1;    
00103 }
00104 
00105 
00106 //=======================================================================
00107 //function :  GEOMImpl_SphereDriver_Type_
00108 //purpose  :
00109 //======================================================================= 
00110 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SphereDriver_Type_()
00111 {
00112 
00113   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00114   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00115   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00116   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
00117   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00118   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00119  
00120 
00121   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00122   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SphereDriver",
00123                                                          sizeof(GEOMImpl_SphereDriver),
00124                                                          1,
00125                                                          (Standard_Address)_Ancestors,
00126                                                          (Standard_Address)NULL);
00127 
00128   return _aType;
00129 }
00130 
00131 //=======================================================================
00132 //function : DownCast
00133 //purpose  :
00134 //======================================================================= 
00135 const Handle(GEOMImpl_SphereDriver) Handle(GEOMImpl_SphereDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00136 {
00137   Handle(GEOMImpl_SphereDriver) _anOtherObject;
00138 
00139   if (!AnObject.IsNull()) {
00140      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SphereDriver))) {
00141        _anOtherObject = Handle(GEOMImpl_SphereDriver)((Handle(GEOMImpl_SphereDriver)&)AnObject);
00142      }
00143   }
00144 
00145   return _anOtherObject ;
00146 }