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