1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_SphereDriver.hxx>
24 #include <GEOMImpl_ISphere.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRepPrimAPI_MakeSphere.hxx>
29 #include <BRep_Tool.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
36 //=======================================================================
39 //=======================================================================
40 const Standard_GUID& GEOMImpl_SphereDriver::GetID()
42 static Standard_GUID aSphereDriver("FF1BBB16-5D14-4df2-980B-3A668264EA16");
47 //=======================================================================
48 //function : GEOMImpl_SphereDriver
50 //=======================================================================
51 GEOMImpl_SphereDriver::GEOMImpl_SphereDriver()
55 //=======================================================================
58 //=======================================================================
59 Standard_Integer GEOMImpl_SphereDriver::Execute(TFunction_Logbook& log) const
61 if (Label().IsNull()) return 0;
62 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
64 GEOMImpl_ISphere aCI (aFunction);
65 Standard_Integer aType = aFunction->GetType();
69 if (aType == SPHERE_R) {
70 aShape = BRepPrimAPI_MakeSphere(aCI.GetR()).Shape();
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();
83 if (aShape.IsNull()) return 0;
85 aFunction->SetValue(aShape);
87 log.SetTouched(Label());
93 //=======================================================================
94 //function : GEOMImpl_SphereDriver_Type_
96 //=======================================================================
97 Standard_EXPORT Handle_Standard_Type& GEOMImpl_SphereDriver_Type_()
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);
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),
112 (Standard_Address)_Ancestors,
113 (Standard_Address)NULL);
118 //=======================================================================
119 //function : DownCast
121 //=======================================================================
122 const Handle(GEOMImpl_SphereDriver) Handle(GEOMImpl_SphereDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
124 Handle(GEOMImpl_SphereDriver) _anOtherObject;
126 if (!AnObject.IsNull()) {
127 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_SphereDriver))) {
128 _anOtherObject = Handle(GEOMImpl_SphereDriver)((Handle(GEOMImpl_SphereDriver)&)AnObject);
132 return _anOtherObject ;