PageRenderTime 32ms CodeModel.GetById 13ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/geom-5.1.2.7/src/GEOMImpl/GEOMImpl_CylinderDriver.cpp

http://pythonocc.googlecode.com/
C++ | 172 lines | 103 code | 30 blank | 39 comment | 24 complexity | 4f60a0adb4c91b5fae0d8aa3600a7b5b MD5 | raw file
  1// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
  2// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
  3// 
  4// This library is free software; you can redistribute it and/or
  5// modify it under the terms of the GNU Lesser General Public
  6// License as published by the Free Software Foundation; either 
  7// version 2.1 of the License.
  8// 
  9// This library is distributed in the hope that it will be useful 
 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 12// Lesser General Public License for more details.
 13//
 14// You should have received a copy of the GNU Lesser General Public  
 15// License along with this library; if not, write to the Free Software 
 16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 17//
 18// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 19//
 20
 21#include <Standard_Stream.hxx>
 22
 23#include <GEOMImpl_CylinderDriver.hxx>
 24#include <GEOMImpl_ICylinder.hxx>
 25#include <GEOMImpl_Types.hxx>
 26#include <GEOM_Function.hxx>
 27
 28#include <BRepPrimAPI_MakeCylinder.hxx>
 29#include <BRep_Tool.hxx>
 30
 31#include <TopAbs.hxx>
 32#include <TopoDS.hxx>
 33#include <TopoDS_Shape.hxx>
 34#include <TopoDS_Vertex.hxx>
 35#include <TopExp.hxx>
 36
 37#include <Standard_TypeMismatch.hxx>
 38#include <Standard_NullObject.hxx>
 39#include <StdFail_NotDone.hxx>
 40#include <gp_Pnt.hxx>
 41#include <gp.hxx>
 42
 43//=======================================================================
 44//function : GetID
 45//purpose  :
 46//=======================================================================
 47const Standard_GUID& GEOMImpl_CylinderDriver::GetID()
 48{
 49  static Standard_GUID aCylinderDriver("FF1BBB14-5D14-4df2-980B-3A668264EA16");
 50  return aCylinderDriver;
 51}
 52
 53
 54//=======================================================================
 55//function : GEOMImpl_CylinderDriver
 56//purpose  :
 57//=======================================================================
 58GEOMImpl_CylinderDriver::GEOMImpl_CylinderDriver()
 59{
 60}
 61
 62//=======================================================================
 63//function : Execute
 64//purpose  :
 65//=======================================================================
 66Standard_Integer GEOMImpl_CylinderDriver::Execute(TFunction_Logbook& log) const
 67{
 68  if (Label().IsNull()) return 0;
 69  Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
 70
 71  GEOMImpl_ICylinder aCI (aFunction);
 72  Standard_Integer aType = aFunction->GetType();
 73
 74  gp_Pnt aP;
 75  gp_Vec aV;
 76
 77  if (aType == CYLINDER_R_H) {
 78    aP = gp::Origin();
 79    aV = gp::DZ();
 80  }
 81  else if (aType == CYLINDER_PNT_VEC_R_H) {
 82    Handle(GEOM_Function) aRefPoint  = aCI.GetPoint();
 83    Handle(GEOM_Function) aRefVector = aCI.GetVector();
 84    TopoDS_Shape aShapePnt = aRefPoint->GetValue();
 85    TopoDS_Shape aShapeVec = aRefVector->GetValue();
 86    if (aShapePnt.IsNull() || aShapeVec.IsNull()) {
 87      Standard_NullObject::Raise("Cylinder creation aborted: point or vector is not defined");
 88    }
 89    if (aShapePnt.ShapeType() != TopAbs_VERTEX ||
 90        aShapeVec.ShapeType() != TopAbs_EDGE) {
 91      Standard_TypeMismatch::Raise("Cylinder creation aborted: point or vector shapes has wrong type");
 92    }
 93
 94    aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
 95
 96    TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
 97    TopoDS_Vertex V1, V2;
 98    TopExp::Vertices(anE, V1, V2, Standard_True);
 99    if (V1.IsNull() || V2.IsNull()) {
100      Standard_NullObject::Raise("Cylinder creation aborted: vector is not defined");
101    }
102    aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
103  }
104  else {
105    return 0;
106  }
107
108  if (aCI.GetH() < 0.0) aV.Reverse();
109  gp_Ax2 anAxes (aP, aV);
110
111  double theAngle = aCI.GetAngle();
112  if (theAngle == 0.)
113	theAngle = PI*2.;
114
115  BRepPrimAPI_MakeCylinder MC (anAxes, aCI.GetR(), Abs(aCI.GetH()), theAngle);
116  MC.Build();
117  if (!MC.IsDone()) {
118    StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
119  }
120
121  TopoDS_Shape aShape = MC.Shape();
122  if (aShape.IsNull()) return 0;
123
124  aFunction->SetValue(aShape);
125
126  log.SetTouched(Label());
127
128  return 1;
129}
130
131
132//=======================================================================
133//function :  GEOMImpl_CylinderDriver_Type_
134//purpose  :
135//=======================================================================
136Standard_EXPORT Handle_Standard_Type& GEOMImpl_CylinderDriver_Type_()
137{
138
139  static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
140  if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
141  static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
142  if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
143  static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
144  if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
145
146
147  static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
148  static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CylinderDriver",
149			                                 sizeof(GEOMImpl_CylinderDriver),
150			                                 1,
151			                                 (Standard_Address)_Ancestors,
152			                                 (Standard_Address)NULL);
153
154  return _aType;
155}
156
157//=======================================================================
158//function : DownCast
159//purpose  :
160//=======================================================================
161const Handle(GEOMImpl_CylinderDriver) Handle(GEOMImpl_CylinderDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
162{
163  Handle(GEOMImpl_CylinderDriver) _anOtherObject;
164
165  if (!AnObject.IsNull()) {
166     if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CylinderDriver))) {
167       _anOtherObject = Handle(GEOMImpl_CylinderDriver)((Handle(GEOMImpl_CylinderDriver)&)AnObject);
168     }
169  }
170
171  return _anOtherObject ;
172}