3 #include "GEOMImpl_CylinderDriver.hxx"
4 #include "GEOMImpl_ICylinder.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepPrimAPI_MakeCylinder.hxx>
9 #include <BRep_Tool.hxx>
13 #include <TopoDS_Shape.hxx>
14 #include <TopoDS_Vertex.hxx>
17 #include <Standard_TypeMismatch.hxx>
18 #include <Standard_NullObject.hxx>
19 #include <StdFail_NotDone.hxx>
23 //=======================================================================
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_CylinderDriver::GetID()
29 static Standard_GUID aCylinderDriver("FF1BBB14-5D14-4df2-980B-3A668264EA16");
30 return aCylinderDriver;
34 //=======================================================================
35 //function : GEOMImpl_CylinderDriver
37 //=======================================================================
38 GEOMImpl_CylinderDriver::GEOMImpl_CylinderDriver()
42 //=======================================================================
45 //=======================================================================
46 Standard_Integer GEOMImpl_CylinderDriver::Execute(TFunction_Logbook& log) const
48 if (Label().IsNull()) return 0;
49 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51 GEOMImpl_ICylinder aCI (aFunction);
52 Standard_Integer aType = aFunction->GetType();
57 if (aType == CYLINDER_R_H) {
61 else if (aType == CYLINDER_PNT_VEC_R_H) {
62 Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
63 Handle(GEOM_Function) aRefVector = aCI.GetVector();
64 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
65 TopoDS_Shape aShapeVec = aRefVector->GetValue();
66 if (aShapePnt.IsNull() || aShapeVec.IsNull()) {
67 Standard_NullObject::Raise("Cylinder creation aborted: point or vector is not defined");
69 if (aShapePnt.ShapeType() != TopAbs_VERTEX ||
70 aShapeVec.ShapeType() != TopAbs_EDGE) {
71 Standard_TypeMismatch::Raise("Cylinder creation aborted: point or vector shapes has wrong type");
74 aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
76 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
78 TopExp::Vertices(anE, V1, V2, Standard_True);
79 if (V1.IsNull() || V2.IsNull()) {
80 Standard_NullObject::Raise("Cylinder creation aborted: vector is not defined");
82 aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
88 if (aCI.GetH() < 0.0) aV.Reverse();
89 gp_Ax2 anAxes (aP, aV);
91 BRepPrimAPI_MakeCylinder MC (anAxes, aCI.GetR(), Abs(aCI.GetH()));
94 StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
97 TopoDS_Shape aShape = MC.Shape();
98 if (aShape.IsNull()) return 0;
100 aFunction->SetValue(aShape);
102 log.SetTouched(Label());
108 //=======================================================================
109 //function : GEOMImpl_CylinderDriver_Type_
111 //=======================================================================
112 Standard_EXPORT Handle_Standard_Type& GEOMImpl_CylinderDriver_Type_()
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);
123 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
124 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CylinderDriver",
125 sizeof(GEOMImpl_CylinderDriver),
127 (Standard_Address)_Ancestors,
128 (Standard_Address)NULL);
133 //=======================================================================
134 //function : DownCast
136 //=======================================================================
137 const Handle(GEOMImpl_CylinderDriver) Handle(GEOMImpl_CylinderDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
139 Handle(GEOMImpl_CylinderDriver) _anOtherObject;
141 if (!AnObject.IsNull()) {
142 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CylinderDriver))) {
143 _anOtherObject = Handle(GEOMImpl_CylinderDriver)((Handle(GEOMImpl_CylinderDriver)&)AnObject);
147 return _anOtherObject ;