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