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