/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. #include <Standard_Stream.hxx>
  21. #include <GEOMImpl_CylinderDriver.hxx>
  22. #include <GEOMImpl_ICylinder.hxx>
  23. #include <GEOMImpl_Types.hxx>
  24. #include <GEOM_Function.hxx>
  25. #include <BRepPrimAPI_MakeCylinder.hxx>
  26. #include <BRep_Tool.hxx>
  27. #include <TopAbs.hxx>
  28. #include <TopoDS.hxx>
  29. #include <TopoDS_Shape.hxx>
  30. #include <TopoDS_Vertex.hxx>
  31. #include <TopExp.hxx>
  32. #include <Standard_TypeMismatch.hxx>
  33. #include <Standard_NullObject.hxx>
  34. #include <StdFail_NotDone.hxx>
  35. #include <gp_Pnt.hxx>
  36. #include <gp.hxx>
  37. //=======================================================================
  38. //function : GetID
  39. //purpose :
  40. //=======================================================================
  41. const Standard_GUID& GEOMImpl_CylinderDriver::GetID()
  42. {
  43. static Standard_GUID aCylinderDriver("FF1BBB14-5D14-4df2-980B-3A668264EA16");
  44. return aCylinderDriver;
  45. }
  46. //=======================================================================
  47. //function : GEOMImpl_CylinderDriver
  48. //purpose :
  49. //=======================================================================
  50. GEOMImpl_CylinderDriver::GEOMImpl_CylinderDriver()
  51. {
  52. }
  53. //=======================================================================
  54. //function : Execute
  55. //purpose :
  56. //=======================================================================
  57. Standard_Integer GEOMImpl_CylinderDriver::Execute(TFunction_Logbook& log) const
  58. {
  59. if (Label().IsNull()) return 0;
  60. Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
  61. GEOMImpl_ICylinder aCI (aFunction);
  62. Standard_Integer aType = aFunction->GetType();
  63. gp_Pnt aP;
  64. gp_Vec aV;
  65. if (aType == CYLINDER_R_H) {
  66. aP = gp::Origin();
  67. aV = gp::DZ();
  68. }
  69. else if (aType == CYLINDER_PNT_VEC_R_H) {
  70. Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
  71. Handle(GEOM_Function) aRefVector = aCI.GetVector();
  72. TopoDS_Shape aShapePnt = aRefPoint->GetValue();
  73. TopoDS_Shape aShapeVec = aRefVector->GetValue();
  74. if (aShapePnt.IsNull() || aShapeVec.IsNull()) {
  75. Standard_NullObject::Raise("Cylinder creation aborted: point or vector is not defined");
  76. }
  77. if (aShapePnt.ShapeType() != TopAbs_VERTEX ||
  78. aShapeVec.ShapeType() != TopAbs_EDGE) {
  79. Standard_TypeMismatch::Raise("Cylinder creation aborted: point or vector shapes has wrong type");
  80. }
  81. aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
  82. TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
  83. TopoDS_Vertex V1, V2;
  84. TopExp::Vertices(anE, V1, V2, Standard_True);
  85. if (V1.IsNull() || V2.IsNull()) {
  86. Standard_NullObject::Raise("Cylinder creation aborted: vector is not defined");
  87. }
  88. aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
  89. }
  90. else {
  91. return 0;
  92. }
  93. if (aCI.GetH() < 0.0) aV.Reverse();
  94. gp_Ax2 anAxes (aP, aV);
  95. double theAngle = aCI.GetAngle();
  96. if (theAngle == 0.)
  97. theAngle = PI*2.;
  98. BRepPrimAPI_MakeCylinder MC (anAxes, aCI.GetR(), Abs(aCI.GetH()), theAngle);
  99. MC.Build();
  100. if (!MC.IsDone()) {
  101. StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
  102. }
  103. TopoDS_Shape aShape = MC.Shape();
  104. if (aShape.IsNull()) return 0;
  105. aFunction->SetValue(aShape);
  106. log.SetTouched(Label());
  107. return 1;
  108. }
  109. //=======================================================================
  110. //function : GEOMImpl_CylinderDriver_Type_
  111. //purpose :
  112. //=======================================================================
  113. Standard_EXPORT Handle_Standard_Type& GEOMImpl_CylinderDriver_Type_()
  114. {
  115. static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
  116. if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
  117. static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
  118. if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
  119. static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
  120. if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
  121. static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
  122. static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CylinderDriver",
  123. sizeof(GEOMImpl_CylinderDriver),
  124. 1,
  125. (Standard_Address)_Ancestors,
  126. (Standard_Address)NULL);
  127. return _aType;
  128. }
  129. //=======================================================================
  130. //function : DownCast
  131. //purpose :
  132. //=======================================================================
  133. const Handle(GEOMImpl_CylinderDriver) Handle(GEOMImpl_CylinderDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
  134. {
  135. Handle(GEOMImpl_CylinderDriver) _anOtherObject;
  136. if (!AnObject.IsNull()) {
  137. if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CylinderDriver))) {
  138. _anOtherObject = Handle(GEOMImpl_CylinderDriver)((Handle(GEOMImpl_CylinderDriver)&)AnObject);
  139. }
  140. }
  141. return _anOtherObject ;
  142. }