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