2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_CylinderDriver.hxx>
5 #include <GEOMImpl_ICylinder.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepPrimAPI_MakeCylinder.hxx>
10 #include <BRep_Tool.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Vertex.hxx>
18 #include <Standard_TypeMismatch.hxx>
19 #include <Standard_NullObject.hxx>
20 #include <StdFail_NotDone.hxx>
24 //=======================================================================
27 //=======================================================================
28 const Standard_GUID& GEOMImpl_CylinderDriver::GetID()
30 static Standard_GUID aCylinderDriver("FF1BBB14-5D14-4df2-980B-3A668264EA16");
31 return aCylinderDriver;
35 //=======================================================================
36 //function : GEOMImpl_CylinderDriver
38 //=======================================================================
39 GEOMImpl_CylinderDriver::GEOMImpl_CylinderDriver()
43 //=======================================================================
46 //=======================================================================
47 Standard_Integer GEOMImpl_CylinderDriver::Execute(TFunction_Logbook& log) const
49 if (Label().IsNull()) return 0;
50 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
52 GEOMImpl_ICylinder aCI (aFunction);
53 Standard_Integer aType = aFunction->GetType();
58 if (aType == CYLINDER_R_H) {
62 else if (aType == CYLINDER_PNT_VEC_R_H) {
63 Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
64 Handle(GEOM_Function) aRefVector = aCI.GetVector();
65 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
66 TopoDS_Shape aShapeVec = aRefVector->GetValue();
67 if (aShapePnt.IsNull() || aShapeVec.IsNull()) {
68 Standard_NullObject::Raise("Cylinder creation aborted: point or vector is not defined");
70 if (aShapePnt.ShapeType() != TopAbs_VERTEX ||
71 aShapeVec.ShapeType() != TopAbs_EDGE) {
72 Standard_TypeMismatch::Raise("Cylinder creation aborted: point or vector shapes has wrong type");
75 aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
77 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
79 TopExp::Vertices(anE, V1, V2, Standard_True);
80 if (V1.IsNull() || V2.IsNull()) {
81 Standard_NullObject::Raise("Cylinder creation aborted: vector is not defined");
83 aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
89 if (aCI.GetH() < 0.0) aV.Reverse();
90 gp_Ax2 anAxes (aP, aV);
92 BRepPrimAPI_MakeCylinder MC (anAxes, aCI.GetR(), Abs(aCI.GetH()));
95 StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
98 TopoDS_Shape aShape = MC.Shape();
99 if (aShape.IsNull()) return 0;
101 aFunction->SetValue(aShape);
103 log.SetTouched(Label());
109 //=======================================================================
110 //function : GEOMImpl_CylinderDriver_Type_
112 //=======================================================================
113 Standard_EXPORT Handle_Standard_Type& GEOMImpl_CylinderDriver_Type_()
116 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
117 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
118 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
119 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
120 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
121 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
124 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
125 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CylinderDriver",
126 sizeof(GEOMImpl_CylinderDriver),
128 (Standard_Address)_Ancestors,
129 (Standard_Address)NULL);
134 //=======================================================================
135 //function : DownCast
137 //=======================================================================
138 const Handle(GEOMImpl_CylinderDriver) Handle(GEOMImpl_CylinderDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
140 Handle(GEOMImpl_CylinderDriver) _anOtherObject;
142 if (!AnObject.IsNull()) {
143 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CylinderDriver))) {
144 _anOtherObject = Handle(GEOMImpl_CylinderDriver)((Handle(GEOMImpl_CylinderDriver)&)AnObject);
148 return _anOtherObject ;