0024428: Implementation of LGPL license
[occt.git] / src / AIS / AIS_EllipseRadiusDimension.cxx
CommitLineData
b311480e 1// Created on: 1998-01-22
2// Created by: Sergey ZARITCHNY
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <AIS_EllipseRadiusDimension.ixx>
18
19#include <TCollection_ExtendedString.hxx>
20
21#include <ElCLib.hxx>
22#include <ElSLib.hxx>
23
24#include <TopoDS.hxx>
25
26#include <BRepAdaptor_Surface.hxx>
27#include <BRepAdaptor_Curve.hxx>
28
29#include <Geom_Ellipse.hxx>
30#include <Geom_TrimmedCurve.hxx>
31#include <Geom_Plane.hxx>
32#include <Geom_Surface.hxx>
33#include <Geom_CylindricalSurface.hxx>
34#include <Geom_SurfaceOfRevolution.hxx>
35#include <Geom_CylindricalSurface.hxx>
36#include <Geom_SurfaceOfLinearExtrusion.hxx>
37#include <GeomAPI_ExtremaCurveCurve.hxx>
38#include <Geom_Line.hxx>
39#include <GeomAPI.hxx>
40
41#include <gp_Pln.hxx>
42#include <gp_Pnt.hxx>
43#include <gp_Lin.hxx>
44#include <gp_Ax1.hxx>
45#include <gp_Dir.hxx>
46#include <gp_Vec.hxx>
47#include <gp_Elips.hxx>
48
49#include <AIS.hxx>
50
51#include <Precision.hxx>
52
53#include <TopExp_Explorer.hxx>
54
55//=======================================================================
56//function : AIS_EllipseRadiusDimension
57//purpose :
58//=======================================================================
59
60AIS_EllipseRadiusDimension::AIS_EllipseRadiusDimension(const TopoDS_Shape& aShape,
61 const TCollection_ExtendedString& aText)
62:AIS_Relation()
63{
64 myFShape = aShape;
65 myText = aText;
66// ComputeGeometry( );
67}
68
69//=======================================================================
70//function : ComputeGeometry
71//purpose :
72//=======================================================================
73
74void AIS_EllipseRadiusDimension::ComputeGeometry()
75{
76
77 switch (myFShape.ShapeType()) {
78 case TopAbs_FACE :
79 {
80 // compute one face case
81 ComputeFaceGeometry ();
82 break;
83 }
84 case TopAbs_EDGE:
85 {
86 ComputeEdgeGeometry ();
87 break;
88 }
89 default:
90 break;
91 }
c6541a0c
D
92 while (myFirstPar > 2*M_PI) myFirstPar -= 2*M_PI;
93 while (myLastPar > 2*M_PI) myLastPar -= 2*M_PI;
94 while (myFirstPar < 0.0) myFirstPar += 2*M_PI;
95 while (myLastPar < 0.0) myLastPar += 2*M_PI;
7fd59977 96}
97
98//=======================================================================
99//function : ComputeFaceGeometry
100//purpose :
101//=======================================================================
102
103void AIS_EllipseRadiusDimension::ComputeFaceGeometry()
104{
105
106 gp_Pln aPln;
107 Handle( Geom_Surface ) aBasisSurf;
108 AIS_KindOfSurface aSurfType;
109 Standard_Real Offset;
110 AIS::GetPlaneFromFace( TopoDS::Face( myFShape),
111 aPln,
112 aBasisSurf,
113 aSurfType,
114 Offset ) ;
115
116 if ( aSurfType == AIS_KOS_Plane )
117 ComputePlanarFaceGeometry( );
118 else
119 ComputeCylFaceGeometry( aSurfType, aBasisSurf, Offset );
120
121}
122
123//=======================================================================
124//function : ComputeCylFaceGeometry
125//purpose : defines Ellipse and plane of dimension
126//=======================================================================
127
128void AIS_EllipseRadiusDimension::ComputeCylFaceGeometry(const AIS_KindOfSurface aSurfType,
129 const Handle( Geom_Surface )& aBasisSurf,
130 const Standard_Real Offset)
131{
132
133 BRepAdaptor_Surface surf1(TopoDS::Face(myFShape));
134 Standard_Real vFirst, vLast;
135 vFirst = surf1.FirstVParameter();
136 vLast = surf1.LastVParameter();
137 Standard_Real vMid = (vFirst + vLast)*0.5;
138 gp_Pln aPlane;
139 gp_Ax1 Axis;
140// Standard_Real Param;
141 if (aSurfType == AIS_KOS_Extrusion)
142 {
143 Axis.SetDirection((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
144 ->Direction() );
145 Axis.SetLocation( gp_Pnt((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
146 ->Direction().XYZ() ) );
147
148 aPlane.SetAxis(Axis);
149 aPlane.SetLocation(myEllipse.Location());
150 myPlane = new Geom_Plane(aPlane);
151
152 Handle(Geom_Curve) aCurve;
153 aCurve = aBasisSurf->VIso(vMid);
154 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
155 {
156 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)-> Elips();//gp_Elips
157 myIsAnArc = Standard_False;
158 }
159 else if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
160 Handle(Geom_TrimmedCurve) tCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
161 aCurve = tCurve->BasisCurve();
162 myFirstPar = tCurve->FirstParameter();
163 myLastPar = tCurve->LastParameter();
164 myIsAnArc = Standard_True;
165 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
166 {
167 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)->Elips();//gp_Elips
168 }
169 }
170 else
171 {
172 Standard_ConstructionError::Raise("AIS:: Not expected type of surface") ;
173 return;
174 }
175
176// Offset
177
178 if(surf1.GetType() == GeomAbs_OffsetSurface)
179 {
180 if(Offset <0.0 && Abs(Offset) > myEllipse.MinorRadius ())
181 {
182 Standard_ConstructionError::Raise("AIS:: Absolute value of negative offset is larger than MinorRadius");
183 return;
184 }
185
186 myOffsetCurve = new Geom_OffsetCurve(new Geom_Ellipse(myEllipse), Offset,
187 myPlane->Pln().Axis().Direction());
188 myOffset = Offset;
189 myIsOffset = Standard_True;
190 gp_Elips elips = myEllipse;
191 Standard_Real Val = Offset + elips.MajorRadius ();//simulation
192 myEllipse.SetMajorRadius (Val);
193 Val = Offset + elips.MinorRadius ();
194 myEllipse.SetMinorRadius (Val);
195 }
196 else
197 myIsOffset = Standard_False;
198 }
199}
200
201
202//=======================================================================
203//function : ComputePlanarFaceGeometry
204//purpose :
205//=======================================================================
206
207void AIS_EllipseRadiusDimension::ComputePlanarFaceGeometry()
208{
209
210 Standard_Boolean find = Standard_False;
211 gp_Pnt ptfirst,ptend;
212 TopExp_Explorer ExploEd( TopoDS::Face(myFShape), TopAbs_EDGE );
213 for ( ; ExploEd.More(); ExploEd.Next())
214 {
215 TopoDS_Edge curedge = TopoDS::Edge( ExploEd.Current() );
216 Handle(Geom_Curve) curv;
217 Handle(Geom_Ellipse) ellips;
218 if (AIS::ComputeGeometry(curedge,curv,ptfirst,ptend))
219 {
220 if (curv->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
221 {
222 ellips = Handle(Geom_Ellipse)::DownCast(curv);
223 if ( !ellips.IsNull() ) {
224 myEllipse = ellips->Elips();
225 find = Standard_True;
226 break;
227 }
228 }
229 }
230 }
231 if( !find )
232 {
233 Standard_ConstructionError::Raise("AIS:: Curve is not an ellipsee or is Null") ;
234 return;
235 }
236
237 if ( !ptfirst.IsEqual(ptend, Precision::Confusion()) )
238 {
239 myIsAnArc = Standard_True;
240 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
241 myLastPar = ElCLib::Parameter(myEllipse, ptend);
242 }
243 else
244 myIsAnArc = Standard_False;
245
246 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
247 myPlane = new Geom_Plane( surfAlgo.Plane() );
248
249}
250
251
252
253//=======================================================================
254//function : ComputeEdgeGeometry
255//purpose :
256//=======================================================================
257
258void AIS_EllipseRadiusDimension::ComputeEdgeGeometry()
259{
260 gp_Pnt ptfirst,ptend;
261 Handle(Geom_Curve) curv;
262 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),curv,ptfirst,ptend)) return;
263
264 Handle(Geom_Ellipse) elips = Handle(Geom_Ellipse)::DownCast(curv);
265 if ( elips.IsNull()) return;
266
267 myEllipse = elips->Elips();
268 gp_Pln aPlane;
269 aPlane.SetPosition(gp_Ax3(myEllipse.Position()));
270 myPlane = new Geom_Plane(aPlane);
271
272
273 if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) {
274 myIsAnArc = Standard_False;
275 }
276 else {
277 myIsAnArc = Standard_True;
278 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
279 myLastPar = ElCLib::Parameter(myEllipse, ptend);
280 }
281}
282//=======================================================================
283//function : KindOfDimension
284//purpose :
285//=======================================================================
286 AIS_KindOfDimension AIS_EllipseRadiusDimension::KindOfDimension() const
287{
288 return AIS_KOD_ELLIPSERADIUS;
289}
290
291//=======================================================================
292//function : IsMovable
293//purpose :
294//=======================================================================
295 Standard_Boolean AIS_EllipseRadiusDimension::IsMovable() const
296{
297 return Standard_True;
298}