1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_EllipseDriver.hxx>
26 #include <GEOMImpl_IEllipse.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
30 #include <BRepBuilderAPI_MakeEdge.hxx>
31 #include <BRep_Tool.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Vertex.hxx>
40 #include <gp_Elips.hxx>
42 //=======================================================================
45 //=======================================================================
46 const Standard_GUID& GEOMImpl_EllipseDriver::GetID()
48 static Standard_GUID aEllipseDriver("FF1BBB34-5D14-4df2-980B-3A668264EA16");
49 return aEllipseDriver;
53 //=======================================================================
54 //function : GEOMImpl_EllipseDriver
56 //=======================================================================
57 GEOMImpl_EllipseDriver::GEOMImpl_EllipseDriver()
61 //=======================================================================
64 //=======================================================================
65 Standard_Integer GEOMImpl_EllipseDriver::Execute(LOGBOOK& log) const
67 if (Label().IsNull()) return 0;
68 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
70 GEOMImpl_IEllipse aCI (aFunction);
71 Standard_Integer aType = aFunction->GetType();
75 if (aType == ELLIPSE_PNT_VEC_RR) {
77 gp_Pnt aP = gp::Origin();
78 Handle(GEOM_Function) aRefPoint = aCI.GetCenter();
79 if (!aRefPoint.IsNull()) {
80 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
81 if (aShapePnt.ShapeType() != TopAbs_VERTEX) {
82 Standard_ConstructionError::Raise
83 ("Ellipse creation aborted: invalid center argument, must be a point");
85 aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
89 Handle(GEOM_Function) aRefVector = aCI.GetVector();
90 if (!aRefVector.IsNull()) {
91 TopoDS_Shape aShapeVec = aRefVector->GetValue();
92 if (aShapeVec.ShapeType() != TopAbs_EDGE) {
93 Standard_ConstructionError::Raise
94 ("Ellipse creation aborted: invalid normal vector argument, must be a vector or an edge");
96 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
98 TopExp::Vertices(anE, V1, V2, Standard_True);
99 if (!V1.IsNull() && !V2.IsNull()) {
100 aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
101 if (aV.Magnitude() < gp::Resolution()) {
102 Standard_ConstructionError::Raise
103 ("Ellipse creation aborted: normal vector of zero length is given");
109 gp_Ax2 anAxes (aP, aV);
112 Handle(GEOM_Function) aRefVectorMaj = aCI.GetVectorMajor();
113 if (!aRefVectorMaj.IsNull()) {
114 TopoDS_Shape aShapeVec = aRefVectorMaj->GetValue();
115 if (aShapeVec.ShapeType() != TopAbs_EDGE) {
116 Standard_ConstructionError::Raise
117 ("Ellipse creation aborted: invalid major axis vector argument, must be a vector or an edge");
119 TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
120 TopoDS_Vertex V1, V2;
121 TopExp::Vertices(anE, V1, V2, Standard_True);
122 if (!V1.IsNull() && !V2.IsNull()) {
123 gp_Vec aVM (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
124 if (aVM.Magnitude() < gp::Resolution()) {
125 Standard_ConstructionError::Raise
126 ("Ellipse creation aborted: major axis vector of zero length is given");
128 if (aV.IsParallel(aVM, Precision::Angular())) {
129 Standard_ConstructionError::Raise
130 ("Ellipse creation aborted: normal and major axis vectors are parallel");
132 // Axes defined with main axis vector
133 anAxes = gp_Ax2 (aP, aV, aVM);
137 double radiusMaj = aCI.GetRMajor();
138 double radiusMin = aCI.GetRMinor();
139 if ( radiusMaj < radiusMin )
140 Standard_ConstructionError::Raise
141 ("Ellipse creation aborted: a major radius is less that a minor one");
142 if ( radiusMin < 0.0 )
143 Standard_ConstructionError::Raise
144 ("Ellipse creation aborted: raduis must be positive");
147 gp_Elips anEll (anAxes, radiusMaj, radiusMin);
148 aShape = BRepBuilderAPI_MakeEdge(anEll).Edge();
153 if (aShape.IsNull()) return 0;
155 aFunction->SetValue(aShape);
157 #if OCC_VERSION_MAJOR < 7
158 log.SetTouched(Label());
160 log->SetTouched(Label());
166 //================================================================================
168 * \brief Returns a name of creation operation and names and values of creation parameters
170 //================================================================================
172 bool GEOMImpl_EllipseDriver::
173 GetCreationInformation(std::string& theOperationName,
174 std::vector<GEOM_Param>& theParams)
176 if (Label().IsNull()) return 0;
177 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
179 GEOMImpl_IEllipse aCI( function );
180 Standard_Integer aType = function->GetType();
182 theOperationName = "ELLIPSE";
185 case ELLIPSE_PNT_VEC_RR:
186 AddParam( theParams, "Center", aCI.GetCenter(), "Origin" );
187 AddParam( theParams, "Vector", aCI.GetVector(), "Z axis" );
188 AddParam( theParams, "Major Axis", aCI.GetVectorMajor(), "X axis");
189 AddParam( theParams, "Major radius", aCI.GetRMajor() );
190 AddParam( theParams, "Minor radius", aCI.GetRMinor() );
199 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_EllipseDriver,GEOM_BaseDriver);