3 #include "GEOMImpl_ConeDriver.hxx"
4 #include "GEOMImpl_ICone.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <BRepPrimAPI_MakeCone.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>
21 #include <Precision.hxx>
25 //=======================================================================
28 //=======================================================================
29 const Standard_GUID& GEOMImpl_ConeDriver::GetID()
31 static Standard_GUID aConeDriver("FF1BBB15-5D14-4df2-980B-3A668264EA16");
36 //=======================================================================
37 //function : GEOMImpl_ConeDriver
39 //=======================================================================
40 GEOMImpl_ConeDriver::GEOMImpl_ConeDriver()
44 //=======================================================================
47 //=======================================================================
48 Standard_Integer GEOMImpl_ConeDriver::Execute(TFunction_Logbook& log) const
50 if (Label().IsNull()) return 0;
51 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
53 GEOMImpl_ICone aCI (aFunction);
54 Standard_Integer aType = aFunction->GetType();
59 Standard_Real aR1 = aCI.GetR1();
60 Standard_Real aR2 = aCI.GetR2();
62 if (aType == CONE_R1_R2_H) {
66 } else if (aType == CONE_PNT_VEC_R1_R2_H) {
67 Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
68 Handle(GEOM_Function) aRefVector = aCI.GetVector();
69 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
70 TopoDS_Shape aShapeVec = aRefVector->GetValue();
71 if (aShapePnt.IsNull() || aShapeVec.IsNull()) {
72 Standard_NullObject::Raise
73 ("Cone creation aborted: point or vector is not defined");
75 if (aShapePnt.ShapeType() != TopAbs_VERTEX ||
76 aShapeVec.ShapeType() != TopAbs_EDGE) {
77 Standard_TypeMismatch::Raise
78 ("Cone creation aborted: point or vector shapes has wrong type");
81 aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
83 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
85 TopExp::Vertices(anE, V1, V2, Standard_True);
86 if (V1.IsNull() || V2.IsNull()) {
87 Standard_NullObject::Raise
88 ("Cylinder creation aborted: vector is not defined");
90 aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
96 if (aCI.GetH() < 0.0) aV.Reverse();
97 gp_Ax2 anAxes (aP, aV);
100 // Cone does not work if same radius
101 if (fabs(aR1 - aR2) <= Precision::Confusion()) {
102 BRepPrimAPI_MakeCylinder MC (anAxes, (aR1 + aR2)/2.0, Abs(aCI.GetH()));
105 StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
109 BRepPrimAPI_MakeCone MC (anAxes, aCI.GetR1(), aCI.GetR2(), Abs(aCI.GetH()));
112 StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
116 if (aShape.IsNull()) return 0;
118 log.SetTouched(Label());
120 aFunction->SetValue(aShape);
125 //=======================================================================
126 //function : GEOMImpl_ConeDriver_Type_
128 //=======================================================================
129 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ConeDriver_Type_()
132 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
133 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
134 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
135 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
136 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
137 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
140 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
141 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ConeDriver",
142 sizeof(GEOMImpl_ConeDriver),
144 (Standard_Address)_Ancestors,
145 (Standard_Address)NULL);
150 //=======================================================================
151 //function : DownCast
153 //=======================================================================
154 const Handle(GEOMImpl_ConeDriver) Handle(GEOMImpl_ConeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
156 Handle(GEOMImpl_ConeDriver) _anOtherObject;
158 if (!AnObject.IsNull()) {
159 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ConeDriver))) {
160 _anOtherObject = Handle(GEOMImpl_ConeDriver)((Handle(GEOMImpl_ConeDriver)&)AnObject);
164 return _anOtherObject ;