Salome HOME
c8d175adc02b0eee9fcc9aa7c4685db6ec3d3c2a
[modules/geom.git] / src / GEOMImpl / GEOMImpl_SphereDriver.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_SphereDriver.hxx>
24 #include <GEOMImpl_ISphere.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <BRepPrimAPI_MakeSphere.hxx>
29 #include <BRep_Tool.hxx>
30 #include <gp_Pnt.hxx>
31 #include <TopoDS.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <TopAbs.hxx>
35
36 //=======================================================================
37 //function : GetID
38 //purpose  :
39 //======================================================================= 
40 const Standard_GUID& GEOMImpl_SphereDriver::GetID()
41 {
42   static Standard_GUID aSphereDriver("FF1BBB16-5D14-4df2-980B-3A668264EA16");
43   return aSphereDriver; 
44 }
45
46
47 //=======================================================================
48 //function : GEOMImpl_SphereDriver
49 //purpose  : 
50 //=======================================================================
51 GEOMImpl_SphereDriver::GEOMImpl_SphereDriver() 
52 {
53 }
54
55 //=======================================================================
56 //function : Execute
57 //purpose  :
58 //======================================================================= 
59 Standard_Integer GEOMImpl_SphereDriver::Execute(TFunction_Logbook& log) const
60 {
61   if (Label().IsNull()) return 0;    
62   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
63
64   GEOMImpl_ISphere aCI (aFunction);
65   Standard_Integer aType = aFunction->GetType();
66
67   TopoDS_Shape aShape;
68
69   if (aType == SPHERE_R) {
70     aShape = BRepPrimAPI_MakeSphere(aCI.GetR()).Shape();
71   }
72   else if (aType == SPHERE_PNT_R) {
73     Handle(GEOM_Function) aRefPoint  = aCI.GetPoint();
74     TopoDS_Shape aShapePnt = aRefPoint->GetValue();
75     if (aShapePnt.ShapeType() == TopAbs_VERTEX) {
76       gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
77       aShape = BRepPrimAPI_MakeSphere(aP, aCI.GetR()).Shape();
78     }
79   }
80   else {
81   }
82
83   if (aShape.IsNull()) return 0;
84
85   aFunction->SetValue(aShape);
86
87   log.SetTouched(Label()); 
88
89   return 1;    
90 }
91
92
93 //=======================================================================
94 //function :  GEOMImpl_SphereDriver_Type_
95 //purpose  :
96 //======================================================================= 
97 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SphereDriver_Type_()
98 {
99
100   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
101   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
102   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
103   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
104   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
105   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
106  
107
108   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
109   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_SphereDriver",
110                                                          sizeof(GEOMImpl_SphereDriver),
111                                                          1,
112                                                          (Standard_Address)_Ancestors,
113                                                          (Standard_Address)NULL);
114
115   return _aType;
116 }
117
118 //=======================================================================
119 //function : DownCast
120 //purpose  :
121 //======================================================================= 
122 const Handle(GEOMImpl_SphereDriver) Handle(GEOMImpl_SphereDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
123 {
124   Handle(GEOMImpl_SphereDriver) _anOtherObject;
125
126   if (!AnObject.IsNull()) {
127      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SphereDriver))) {
128        _anOtherObject = Handle(GEOMImpl_SphereDriver)((Handle(GEOMImpl_SphereDriver)&)AnObject);
129      }
130   }
131
132   return _anOtherObject ;
133 }