1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_CylinderDriver.hxx>
26 #include <GEOMImpl_ICylinder.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
30 #include <BRepPrimAPI_MakeCylinder.hxx>
31 #include <BRep_Tool.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Vertex.hxx>
39 #include <Standard_TypeMismatch.hxx>
40 #include <Standard_NullObject.hxx>
41 #include <StdFail_NotDone.hxx>
45 //=======================================================================
48 //=======================================================================
49 const Standard_GUID& GEOMImpl_CylinderDriver::GetID()
51 static Standard_GUID aCylinderDriver("FF1BBB14-5D14-4df2-980B-3A668264EA16");
52 return aCylinderDriver;
56 //=======================================================================
57 //function : GEOMImpl_CylinderDriver
59 //=======================================================================
60 GEOMImpl_CylinderDriver::GEOMImpl_CylinderDriver()
64 //=======================================================================
67 //=======================================================================
68 Standard_Integer GEOMImpl_CylinderDriver::Execute(TFunction_Logbook& log) const
70 if (Label().IsNull()) return 0;
71 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
73 GEOMImpl_ICylinder aCI (aFunction);
74 Standard_Integer aType = aFunction->GetType();
79 if (aType == CYLINDER_R_H) {
83 else if (aType == CYLINDER_PNT_VEC_R_H) {
84 Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
85 Handle(GEOM_Function) aRefVector = aCI.GetVector();
86 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
87 TopoDS_Shape aShapeVec = aRefVector->GetValue();
88 if (aShapePnt.IsNull() || aShapeVec.IsNull()) {
89 Standard_NullObject::Raise("Cylinder creation aborted: point or vector is not defined");
91 if (aShapePnt.ShapeType() != TopAbs_VERTEX ||
92 aShapeVec.ShapeType() != TopAbs_EDGE) {
93 Standard_TypeMismatch::Raise("Cylinder creation aborted: point or vector shapes has wrong type");
96 aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
98 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
100 TopExp::Vertices(anE, V1, V2, Standard_True);
101 if (V1.IsNull() || V2.IsNull()) {
102 Standard_NullObject::Raise("Cylinder creation aborted: vector is not defined");
104 aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
110 if (aCI.GetH() < 0.0) aV.Reverse();
111 gp_Ax2 anAxes (aP, aV);
113 BRepPrimAPI_MakeCylinder MC (anAxes, aCI.GetR(), Abs(aCI.GetH()));
116 StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
119 TopoDS_Shape aShape = MC.Shape();
120 if (aShape.IsNull()) return 0;
122 aFunction->SetValue(aShape);
124 log.SetTouched(Label());
130 //=======================================================================
131 //function : GEOMImpl_CylinderDriver_Type_
133 //=======================================================================
134 Standard_EXPORT Handle_Standard_Type& GEOMImpl_CylinderDriver_Type_()
137 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
138 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
139 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
140 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
141 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
142 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
145 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
146 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CylinderDriver",
147 sizeof(GEOMImpl_CylinderDriver),
149 (Standard_Address)_Ancestors,
150 (Standard_Address)NULL);
155 //=======================================================================
156 //function : DownCast
158 //=======================================================================
159 const Handle(GEOMImpl_CylinderDriver) Handle(GEOMImpl_CylinderDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
161 Handle(GEOMImpl_CylinderDriver) _anOtherObject;
163 if (!AnObject.IsNull()) {
164 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CylinderDriver))) {
165 _anOtherObject = Handle(GEOMImpl_CylinderDriver)((Handle(GEOMImpl_CylinderDriver)&)AnObject);
169 return _anOtherObject ;