Back to index

salome-geom  6.5.0
GEOMImpl_TorusDriver.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_TorusDriver.hxx>
00026 #include <GEOMImpl_ITorus.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 
00030 #include <BRepPrimAPI_MakeTorus.hxx>
00031 #include <BRep_Tool.hxx>
00032 #include <TopoDS.hxx>
00033 #include <TopoDS_Shape.hxx>
00034 #include <TopoDS_Edge.hxx>
00035 #include <TopoDS_Vertex.hxx>
00036 #include <TopAbs.hxx>
00037 #include <TopExp.hxx>
00038 
00039 #include <gp_Pnt.hxx>
00040 #include <Precision.hxx>
00041 #include <StdFail_NotDone.hxx>
00042 #include <Standard_TypeMismatch.hxx>
00043 #include <Standard_ConstructionError.hxx>
00044 
00045 //=======================================================================
00046 //function : GetID
00047 //purpose  :
00048 //======================================================================= 
00049 const Standard_GUID& GEOMImpl_TorusDriver::GetID()
00050 {
00051   static Standard_GUID aTorusDriver("FF1BBB12-5D14-4df2-980B-3A668264EA16");
00052   return aTorusDriver; 
00053 }
00054 
00055 
00056 //=======================================================================
00057 //function : GEOMImpl_TorusDriver
00058 //purpose  : 
00059 //=======================================================================
00060 GEOMImpl_TorusDriver::GEOMImpl_TorusDriver() 
00061 {
00062 }
00063 
00064 //=======================================================================
00065 //function : Execute
00066 //purpose  :
00067 //======================================================================= 
00068 Standard_Integer GEOMImpl_TorusDriver::Execute(TFunction_Logbook& log) const
00069 {
00070   if (Label().IsNull()) return 0;    
00071   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00072 
00073   GEOMImpl_ITorus aCI (aFunction);
00074   Standard_Integer aType = aFunction->GetType();
00075 
00076   TopoDS_Shape aShape;
00077 
00078   if (aType == TORUS_RR) {
00079     aShape = BRepPrimAPI_MakeTorus(aCI.GetRMajor(), aCI.GetRMinor()).Shape();
00080 
00081   } else if (aType == TORUS_PNT_VEC_RR) {
00082     Handle(GEOM_Function) aRefPoint  = aCI.GetCenter();
00083     Handle(GEOM_Function) aRefVector = aCI.GetVector();
00084     TopoDS_Shape aShapePnt = aRefPoint->GetValue();
00085     TopoDS_Shape aShapeVec = aRefVector->GetValue();
00086     if (aShapePnt.ShapeType() != TopAbs_VERTEX) {
00087       Standard_TypeMismatch::Raise("Torus Center must be a vertex");
00088     }
00089     if (aShapeVec.ShapeType() != TopAbs_EDGE) {
00090       Standard_TypeMismatch::Raise("Torus Axis must be an edge");
00091     }
00092 
00093     gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
00094     TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
00095     TopoDS_Vertex V1, V2;
00096     TopExp::Vertices(anE, V1, V2, Standard_True);
00097     if (V1.IsNull() || V2.IsNull()) {
00098       Standard_ConstructionError::Raise("Bad edge for the Torus Axis given");
00099     }
00100 
00101     gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
00102     if (aV.Magnitude() < Precision::Confusion()) {
00103       Standard_ConstructionError::Raise
00104         ("End vertices of edge, defining the Torus Axis, are too close");
00105     }
00106 
00107     gp_Ax2 anAxes (aP, aV);
00108     BRepPrimAPI_MakeTorus MT (anAxes, aCI.GetRMajor(), aCI.GetRMinor());
00109     if (!MT.IsDone()) MT.Build();
00110     if (!MT.IsDone()) StdFail_NotDone::Raise("Torus construction algorithm has failed");
00111     aShape = MT.Shape();
00112   } else {
00113   }
00114 
00115   if (aShape.IsNull()) return 0;
00116   aFunction->SetValue(aShape);
00117 
00118   log.SetTouched(Label()); 
00119 
00120   return 1;    
00121 }
00122 
00123 
00124 //=======================================================================
00125 //function :  GEOMImpl_TorusDriver_Type_
00126 //purpose  :
00127 //======================================================================= 
00128 Standard_EXPORT Handle_Standard_Type& GEOMImpl_TorusDriver_Type_()
00129 {
00130 
00131   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00132   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00133   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00134   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
00135   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00136   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00137  
00138 
00139   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00140   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_TorusDriver",
00141                                                          sizeof(GEOMImpl_TorusDriver),
00142                                                          1,
00143                                                          (Standard_Address)_Ancestors,
00144                                                          (Standard_Address)NULL);
00145 
00146   return _aType;
00147 }
00148 
00149 //=======================================================================
00150 //function : DownCast
00151 //purpose  :
00152 //======================================================================= 
00153 const Handle(GEOMImpl_TorusDriver) Handle(GEOMImpl_TorusDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00154 {
00155   Handle(GEOMImpl_TorusDriver) _anOtherObject;
00156 
00157   if (!AnObject.IsNull()) {
00158      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_TorusDriver))) {
00159        _anOtherObject = Handle(GEOMImpl_TorusDriver)((Handle(GEOMImpl_TorusDriver)&)AnObject);
00160      }
00161   }
00162 
00163   return _anOtherObject ;
00164 }