2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_ConeDriver.hxx>
5 #include <GEOMImpl_ICone.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
9 #include <BRepPrimAPI_MakeCone.hxx>
10 #include <BRepPrimAPI_MakeCylinder.hxx>
11 #include <BRep_Tool.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <TopoDS_Vertex.hxx>
19 #include <Standard_TypeMismatch.hxx>
20 #include <Standard_NullObject.hxx>
21 #include <StdFail_NotDone.hxx>
22 #include <Precision.hxx>
26 //=======================================================================
29 //=======================================================================
30 const Standard_GUID& GEOMImpl_ConeDriver::GetID()
32 static Standard_GUID aConeDriver("FF1BBB15-5D14-4df2-980B-3A668264EA16");
37 //=======================================================================
38 //function : GEOMImpl_ConeDriver
40 //=======================================================================
41 GEOMImpl_ConeDriver::GEOMImpl_ConeDriver()
45 //=======================================================================
48 //=======================================================================
49 Standard_Integer GEOMImpl_ConeDriver::Execute(TFunction_Logbook& log) const
51 if (Label().IsNull()) return 0;
52 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
54 GEOMImpl_ICone aCI (aFunction);
55 Standard_Integer aType = aFunction->GetType();
60 Standard_Real aR1 = aCI.GetR1();
61 Standard_Real aR2 = aCI.GetR2();
63 if (aType == CONE_R1_R2_H) {
67 } else if (aType == CONE_PNT_VEC_R1_R2_H) {
68 Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
69 Handle(GEOM_Function) aRefVector = aCI.GetVector();
70 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
71 TopoDS_Shape aShapeVec = aRefVector->GetValue();
72 if (aShapePnt.IsNull() || aShapeVec.IsNull()) {
73 Standard_NullObject::Raise
74 ("Cone creation aborted: point or vector is not defined");
76 if (aShapePnt.ShapeType() != TopAbs_VERTEX ||
77 aShapeVec.ShapeType() != TopAbs_EDGE) {
78 Standard_TypeMismatch::Raise
79 ("Cone creation aborted: point or vector shapes has wrong type");
82 aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
84 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
86 TopExp::Vertices(anE, V1, V2, Standard_True);
87 if (V1.IsNull() || V2.IsNull()) {
88 Standard_NullObject::Raise
89 ("Cylinder creation aborted: vector is not defined");
91 aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
97 if (aCI.GetH() < 0.0) aV.Reverse();
98 gp_Ax2 anAxes (aP, aV);
101 // Cone does not work if same radius
102 if (fabs(aR1 - aR2) <= Precision::Confusion()) {
103 BRepPrimAPI_MakeCylinder MC (anAxes, (aR1 + aR2)/2.0, Abs(aCI.GetH()));
106 StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
110 BRepPrimAPI_MakeCone MC (anAxes, aCI.GetR1(), aCI.GetR2(), Abs(aCI.GetH()));
113 StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
117 if (aShape.IsNull()) return 0;
119 log.SetTouched(Label());
121 aFunction->SetValue(aShape);
126 //=======================================================================
127 //function : GEOMImpl_ConeDriver_Type_
129 //=======================================================================
130 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ConeDriver_Type_()
133 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
134 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
135 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
136 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
137 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
138 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
141 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
142 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ConeDriver",
143 sizeof(GEOMImpl_ConeDriver),
145 (Standard_Address)_Ancestors,
146 (Standard_Address)NULL);
151 //=======================================================================
152 //function : DownCast
154 //=======================================================================
155 const Handle(GEOMImpl_ConeDriver) Handle(GEOMImpl_ConeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
157 Handle(GEOMImpl_ConeDriver) _anOtherObject;
159 if (!AnObject.IsNull()) {
160 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ConeDriver))) {
161 _anOtherObject = Handle(GEOMImpl_ConeDriver)((Handle(GEOMImpl_ConeDriver)&)AnObject);
165 return _anOtherObject ;