Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / GEOMImpl / GEOMImpl_SphereDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_SphereDriver.hxx"
4 #include "GEOMImpl_ISphere.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRepPrimAPI_MakeSphere.hxx>
9 #include <BRep_Tool.hxx>
10 #include <gp_Pnt.hxx>
11 #include <TopoDS.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Vertex.hxx>
14 #include <TopAbs.hxx>
15
16 //=======================================================================
17 //function : GetID
18 //purpose  :
19 //======================================================================= 
20 const Standard_GUID& GEOMImpl_SphereDriver::GetID()
21 {
22   static Standard_GUID aSphereDriver("FF1BBB16-5D14-4df2-980B-3A668264EA16");
23   return aSphereDriver; 
24 }
25
26
27 //=======================================================================
28 //function : GEOMImpl_SphereDriver
29 //purpose  : 
30 //=======================================================================
31 GEOMImpl_SphereDriver::GEOMImpl_SphereDriver() 
32 {
33 }
34
35 //=======================================================================
36 //function : Execute
37 //purpose  :
38 //======================================================================= 
39 Standard_Integer GEOMImpl_SphereDriver::Execute(TFunction_Logbook& log) const
40 {
41   if (Label().IsNull()) return 0;    
42   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
43
44   GEOMImpl_ISphere aCI (aFunction);
45   Standard_Integer aType = aFunction->GetType();
46
47   TopoDS_Shape aShape;
48
49   if (aType == SPHERE_R) {
50     aShape = BRepPrimAPI_MakeSphere(aCI.GetR()).Shape();
51   }
52   else if (aType == SPHERE_PNT_R) {
53     Handle(GEOM_Function) aRefPoint  = aCI.GetPoint();
54     TopoDS_Shape aShapePnt = aRefPoint->GetValue();
55     if (aShapePnt.ShapeType() == TopAbs_VERTEX) {
56       gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
57       aShape = BRepPrimAPI_MakeSphere(aP, aCI.GetR()).Shape();
58     }
59   }
60   else {
61   }
62
63   if (aShape.IsNull()) return 0;
64
65   aFunction->SetValue(aShape);
66
67   log.SetTouched(Label()); 
68
69   return 1;    
70 }
71
72
73 //=======================================================================
74 //function :  GEOMImpl_SphereDriver_Type_
75 //purpose  :
76 //======================================================================= 
77 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SphereDriver_Type_()
78 {
79
80   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
81   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
82   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
83   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
84   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
85   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
86  
87
88   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
89   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SphereDriver",
90                                                          sizeof(GEOMImpl_SphereDriver),
91                                                          1,
92                                                          (Standard_Address)_Ancestors,
93                                                          (Standard_Address)NULL);
94
95   return _aType;
96 }
97
98 //=======================================================================
99 //function : DownCast
100 //purpose  :
101 //======================================================================= 
102 const Handle(GEOMImpl_SphereDriver) Handle(GEOMImpl_SphereDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
103 {
104   Handle(GEOMImpl_SphereDriver) _anOtherObject;
105
106   if (!AnObject.IsNull()) {
107      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SphereDriver))) {
108        _anOtherObject = Handle(GEOMImpl_SphereDriver)((Handle(GEOMImpl_SphereDriver)&)AnObject);
109      }
110   }
111
112   return _anOtherObject ;
113 }