]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_EllipseDriver.cxx
Salome HOME
Bug 0020413: Dump file has many GetMainShape instructions.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_EllipseDriver.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_EllipseDriver.hxx>
25 #include <GEOMImpl_IEllipse.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
28
29 #include <BRepBuilderAPI_MakeEdge.hxx>
30 #include <BRep_Tool.hxx>
31 #include <TopoDS.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <TopAbs.hxx>
36 #include <TopExp.hxx>
37
38 #include <gp_Pnt.hxx>
39 #include <gp_Elips.hxx>
40
41 //=======================================================================
42 //function : GetID
43 //purpose  :
44 //======================================================================= 
45 const Standard_GUID& GEOMImpl_EllipseDriver::GetID()
46 {
47   static Standard_GUID aEllipseDriver("FF1BBB34-5D14-4df2-980B-3A668264EA16");
48   return aEllipseDriver; 
49 }
50
51
52 //=======================================================================
53 //function : GEOMImpl_EllipseDriver
54 //purpose  : 
55 //=======================================================================
56 GEOMImpl_EllipseDriver::GEOMImpl_EllipseDriver() 
57 {
58 }
59
60 //=======================================================================
61 //function : Execute
62 //purpose  :
63 //======================================================================= 
64 Standard_Integer GEOMImpl_EllipseDriver::Execute(TFunction_Logbook& log) const
65 {
66   if (Label().IsNull()) return 0;    
67   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
68
69   GEOMImpl_IEllipse aCI (aFunction);
70   Standard_Integer aType = aFunction->GetType();
71
72   TopoDS_Shape aShape;
73
74   if (aType == ELLIPSE_PNT_VEC_RR) {
75     // Center
76     Handle(GEOM_Function) aRefPoint  = aCI.GetCenter();
77     TopoDS_Shape aShapePnt = aRefPoint->GetValue();
78     if (aShapePnt.ShapeType() != TopAbs_VERTEX) {
79       Standard_ConstructionError::Raise
80         ("Ellipse creation aborted: invalid center argument, must be a point");
81     }
82     gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
83     // Normal
84     Handle(GEOM_Function) aRefVector = aCI.GetVector();
85     TopoDS_Shape aShapeVec = aRefVector->GetValue();
86     if (aShapeVec.ShapeType() != TopAbs_EDGE) {
87       Standard_ConstructionError::Raise
88         ("Ellipse creation aborted: invalid normal vector argument, must be a vector or an edge");
89     }
90     TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
91     TopoDS_Vertex V1, V2;
92     TopExp::Vertices(anE, V1, V2, Standard_True);
93     if (V1.IsNull() || V2.IsNull()) {
94       Standard_ConstructionError::Raise
95         ("Ellipse creation aborted: invalid normal vector argument: cannot retrieve vertices");
96     }
97     gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
98     if (aV.Magnitude() < gp::Resolution()) {
99       Standard_ConstructionError::Raise
100         ("Ellipse creation aborted: normal vector of zero length is given");
101     }
102
103     // Axes
104     gp_Ax2 anAxes (aP, aV);
105
106     // Main Axis vector (optional)
107     Handle(GEOM_Function) aRefVectorMaj = aCI.GetVectorMajor();
108     if (!aRefVectorMaj.IsNull()) {
109       TopoDS_Shape aShapeVec = aRefVectorMaj->GetValue();
110       if (aShapeVec.ShapeType() != TopAbs_EDGE) {
111         Standard_ConstructionError::Raise
112           ("Ellipse creation aborted: invalid major axis vector argument, must be a vector or an edge");
113       }
114       TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
115       TopoDS_Vertex V1, V2;
116       TopExp::Vertices(anE, V1, V2, Standard_True);
117       if (V1.IsNull() || V2.IsNull()) {
118         Standard_ConstructionError::Raise
119           ("Ellipse creation aborted: invalid major axis vector argument: cannot retrieve vertices");
120       }
121       gp_Vec aVM (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
122       if (aVM.Magnitude() < gp::Resolution()) {
123         Standard_ConstructionError::Raise
124           ("Ellipse creation aborted: major axis vector of zero length is given");
125       }
126       if (aV.IsParallel(aVM, Precision::Angular())) {
127         Standard_ConstructionError::Raise
128           ("Ellipse creation aborted: normal and major axis vectors are parallel");
129       }
130       // Axes defined with main axis vector
131       anAxes  = gp_Ax2 (aP, aV, aVM);
132     }
133
134     // Ellipse
135     gp_Elips anEll (anAxes, aCI.GetRMajor(), aCI.GetRMinor());
136     aShape = BRepBuilderAPI_MakeEdge(anEll).Edge();
137   } else {
138   }
139
140   if (aShape.IsNull()) return 0;
141
142   aFunction->SetValue(aShape);
143
144   log.SetTouched(Label()); 
145
146   return 1;    
147 }
148
149
150 //=======================================================================
151 //function :  GEOMImpl_EllipseDriver_Type_
152 //purpose  :
153 //======================================================================= 
154 Standard_EXPORT Handle_Standard_Type& GEOMImpl_EllipseDriver_Type_()
155 {
156
157   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
158   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
159   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
160   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
161   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
162   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
163  
164
165   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
166   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_EllipseDriver",
167                                                          sizeof(GEOMImpl_EllipseDriver),
168                                                          1,
169                                                          (Standard_Address)_Ancestors,
170                                                          (Standard_Address)NULL);
171
172   return _aType;
173 }
174
175 //=======================================================================
176 //function : DownCast
177 //purpose  :
178 //======================================================================= 
179 const Handle(GEOMImpl_EllipseDriver) Handle(GEOMImpl_EllipseDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
180 {
181   Handle(GEOMImpl_EllipseDriver) _anOtherObject;
182
183   if (!AnObject.IsNull()) {
184      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_EllipseDriver))) {
185        _anOtherObject = Handle(GEOMImpl_EllipseDriver)((Handle(GEOMImpl_EllipseDriver)&)AnObject);
186      }
187   }
188
189   return _anOtherObject ;
190 }