Salome HOME
Update mail address
[modules/geom.git] / src / GEOMImpl / GEOMImpl_EllipseDriver.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_EllipseDriver.hxx>
24 #include <GEOMImpl_IEllipse.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <BRepBuilderAPI_MakeEdge.hxx>
29 #include <BRep_Tool.hxx>
30 #include <TopoDS.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <TopAbs.hxx>
35 #include <TopExp.hxx>
36
37 #include <gp_Pnt.hxx>
38 #include <gp_Elips.hxx>
39
40 //=======================================================================
41 //function : GetID
42 //purpose  :
43 //======================================================================= 
44 const Standard_GUID& GEOMImpl_EllipseDriver::GetID()
45 {
46   static Standard_GUID aEllipseDriver("FF1BBB34-5D14-4df2-980B-3A668264EA16");
47   return aEllipseDriver; 
48 }
49
50
51 //=======================================================================
52 //function : GEOMImpl_EllipseDriver
53 //purpose  : 
54 //=======================================================================
55 GEOMImpl_EllipseDriver::GEOMImpl_EllipseDriver() 
56 {
57 }
58
59 //=======================================================================
60 //function : Execute
61 //purpose  :
62 //======================================================================= 
63 Standard_Integer GEOMImpl_EllipseDriver::Execute(TFunction_Logbook& log) const
64 {
65   if (Label().IsNull()) return 0;    
66   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
67
68   GEOMImpl_IEllipse aCI (aFunction);
69   Standard_Integer aType = aFunction->GetType();
70
71   TopoDS_Shape aShape;
72
73   if (aType == ELLIPSE_PNT_VEC_RR) {
74     Handle(GEOM_Function) aRefPoint  = aCI.GetCenter();
75     Handle(GEOM_Function) aRefVector = aCI.GetVector();
76     TopoDS_Shape aShapePnt = aRefPoint->GetValue();
77     TopoDS_Shape aShapeVec = aRefVector->GetValue();
78     if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
79         aShapeVec.ShapeType() == TopAbs_EDGE) {
80       gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
81       TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
82       TopoDS_Vertex V1, V2;
83       TopExp::Vertices(anE, V1, V2, Standard_True);
84       if (!V1.IsNull() && !V2.IsNull()) {
85         gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
86         gp_Ax2 anAxes (aP, aV);
87         gp_Elips anEll (anAxes, aCI.GetRMajor(), aCI.GetRMinor());
88         aShape = BRepBuilderAPI_MakeEdge(anEll).Edge();
89       }
90     }
91   } else {
92   }
93
94   if (aShape.IsNull()) return 0;
95
96   aFunction->SetValue(aShape);
97
98   log.SetTouched(Label()); 
99
100   return 1;    
101 }
102
103
104 //=======================================================================
105 //function :  GEOMImpl_EllipseDriver_Type_
106 //purpose  :
107 //======================================================================= 
108 Standard_EXPORT Handle_Standard_Type& GEOMImpl_EllipseDriver_Type_()
109 {
110
111   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
112   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
113   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
114   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
115   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
116   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
117  
118
119   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
120   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_EllipseDriver",
121                                                          sizeof(GEOMImpl_EllipseDriver),
122                                                          1,
123                                                          (Standard_Address)_Ancestors,
124                                                          (Standard_Address)NULL);
125
126   return _aType;
127 }
128
129 //=======================================================================
130 //function : DownCast
131 //purpose  :
132 //======================================================================= 
133 const Handle(GEOMImpl_EllipseDriver) Handle(GEOMImpl_EllipseDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
134 {
135   Handle(GEOMImpl_EllipseDriver) _anOtherObject;
136
137   if (!AnObject.IsNull()) {
138      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_EllipseDriver))) {
139        _anOtherObject = Handle(GEOMImpl_EllipseDriver)((Handle(GEOMImpl_EllipseDriver)&)AnObject);
140      }
141   }
142
143   return _anOtherObject ;
144 }