Back to index

salome-geom  6.5.0
GEOMImpl_CylinderDriver.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_CylinderDriver.hxx>
00026 #include <GEOMImpl_ICylinder.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 
00030 #include <BRepPrimAPI_MakeCylinder.hxx>
00031 #include <BRep_Tool.hxx>
00032 
00033 #include <TopAbs.hxx>
00034 #include <TopoDS.hxx>
00035 #include <TopoDS_Shape.hxx>
00036 #include <TopoDS_Vertex.hxx>
00037 #include <TopExp.hxx>
00038 
00039 #include <Standard_TypeMismatch.hxx>
00040 #include <Standard_NullObject.hxx>
00041 #include <StdFail_NotDone.hxx>
00042 #include <gp_Pnt.hxx>
00043 #include <gp.hxx>
00044 
00045 //=======================================================================
00046 //function : GetID
00047 //purpose  :
00048 //=======================================================================
00049 const Standard_GUID& GEOMImpl_CylinderDriver::GetID()
00050 {
00051   static Standard_GUID aCylinderDriver("FF1BBB14-5D14-4df2-980B-3A668264EA16");
00052   return aCylinderDriver;
00053 }
00054 
00055 
00056 //=======================================================================
00057 //function : GEOMImpl_CylinderDriver
00058 //purpose  :
00059 //=======================================================================
00060 GEOMImpl_CylinderDriver::GEOMImpl_CylinderDriver()
00061 {
00062 }
00063 
00064 //=======================================================================
00065 //function : Execute
00066 //purpose  :
00067 //=======================================================================
00068 Standard_Integer GEOMImpl_CylinderDriver::Execute(TFunction_Logbook& log) const
00069 {
00070   if (Label().IsNull()) return 0;
00071   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00072 
00073   GEOMImpl_ICylinder aCI (aFunction);
00074   Standard_Integer aType = aFunction->GetType();
00075 
00076   gp_Pnt aP;
00077   gp_Vec aV;
00078 
00079   if (aType == CYLINDER_R_H) {
00080     aP = gp::Origin();
00081     aV = gp::DZ();
00082   }
00083   else if (aType == CYLINDER_PNT_VEC_R_H) {
00084     Handle(GEOM_Function) aRefPoint  = aCI.GetPoint();
00085     Handle(GEOM_Function) aRefVector = aCI.GetVector();
00086     TopoDS_Shape aShapePnt = aRefPoint->GetValue();
00087     TopoDS_Shape aShapeVec = aRefVector->GetValue();
00088     if (aShapePnt.IsNull() || aShapeVec.IsNull()) {
00089       Standard_NullObject::Raise("Cylinder creation aborted: point or vector is not defined");
00090     }
00091     if (aShapePnt.ShapeType() != TopAbs_VERTEX ||
00092         aShapeVec.ShapeType() != TopAbs_EDGE) {
00093       Standard_TypeMismatch::Raise("Cylinder creation aborted: point or vector shapes has wrong type");
00094     }
00095 
00096     aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
00097 
00098     TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
00099     TopoDS_Vertex V1, V2;
00100     TopExp::Vertices(anE, V1, V2, Standard_True);
00101     if (V1.IsNull() || V2.IsNull()) {
00102       Standard_NullObject::Raise("Cylinder creation aborted: vector is not defined");
00103     }
00104     aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
00105   }
00106   else {
00107     return 0;
00108   }
00109 
00110   if (aCI.GetH() < 0.0) aV.Reverse();
00111   gp_Ax2 anAxes (aP, aV);
00112 
00113   BRepPrimAPI_MakeCylinder MC (anAxes, aCI.GetR(), Abs(aCI.GetH()));
00114   MC.Build();
00115   if (!MC.IsDone()) {
00116     StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
00117   }
00118 
00119   TopoDS_Shape aShape = MC.Shape();
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_CylinderDriver_Type_
00132 //purpose  :
00133 //=======================================================================
00134 Standard_EXPORT Handle_Standard_Type& GEOMImpl_CylinderDriver_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_CylinderDriver",
00147                                                          sizeof(GEOMImpl_CylinderDriver),
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_CylinderDriver) Handle(GEOMImpl_CylinderDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00160 {
00161   Handle(GEOMImpl_CylinderDriver) _anOtherObject;
00162 
00163   if (!AnObject.IsNull()) {
00164      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CylinderDriver))) {
00165        _anOtherObject = Handle(GEOMImpl_CylinderDriver)((Handle(GEOMImpl_CylinderDriver)&)AnObject);
00166      }
00167   }
00168 
00169   return _anOtherObject ;
00170 }