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_EllipseDriver.hxx>
24 #include <GEOMImpl_IEllipse.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRepBuilderAPI_MakeEdge.hxx>
29 #include <BRep_Tool.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Vertex.hxx>
38 #include <gp_Elips.hxx>
40 //=======================================================================
43 //=======================================================================
44 const Standard_GUID& GEOMImpl_EllipseDriver::GetID()
46 static Standard_GUID aEllipseDriver("FF1BBB34-5D14-4df2-980B-3A668264EA16");
47 return aEllipseDriver;
51 //=======================================================================
52 //function : GEOMImpl_EllipseDriver
54 //=======================================================================
55 GEOMImpl_EllipseDriver::GEOMImpl_EllipseDriver()
59 //=======================================================================
62 //=======================================================================
63 Standard_Integer GEOMImpl_EllipseDriver::Execute(TFunction_Logbook& log) const
65 if (Label().IsNull()) return 0;
66 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
68 GEOMImpl_IEllipse aCI (aFunction);
69 Standard_Integer aType = aFunction->GetType();
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);
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();
94 if (aShape.IsNull()) return 0;
96 aFunction->SetValue(aShape);
98 log.SetTouched(Label());
104 //=======================================================================
105 //function : GEOMImpl_EllipseDriver_Type_
107 //=======================================================================
108 Standard_EXPORT Handle_Standard_Type& GEOMImpl_EllipseDriver_Type_()
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);
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),
123 (Standard_Address)_Ancestors,
124 (Standard_Address)NULL);
129 //=======================================================================
130 //function : DownCast
132 //=======================================================================
133 const Handle(GEOMImpl_EllipseDriver) Handle(GEOMImpl_EllipseDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
135 Handle(GEOMImpl_EllipseDriver) _anOtherObject;
137 if (!AnObject.IsNull()) {
138 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_EllipseDriver))) {
139 _anOtherObject = Handle(GEOMImpl_EllipseDriver)((Handle(GEOMImpl_EllipseDriver)&)AnObject);
143 return _anOtherObject ;