summaryrefslogtreecommitdiff
path: root/src/AIS/AIS_EllipseRadiusDimension.cxx
blob: 8e28e73feb80b7a122b68f9f373b5871d47090cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// File:	AIS_EllipseRadiusDimension.cxx
// Created:	Thu Jan 22 10:24:00 1998
// Author:	Sergey ZARITCHNY
//		<szy@androx.nnov.matra-dtv.fr>


#include <AIS_EllipseRadiusDimension.ixx>

#include <TCollection_ExtendedString.hxx>

#include <ElCLib.hxx>
#include <ElSLib.hxx>

#include <TopoDS.hxx>

#include <BRepAdaptor_Surface.hxx>
#include <BRepAdaptor_Curve.hxx>

#include <Geom_Ellipse.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Surface.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_SurfaceOfRevolution.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_SurfaceOfLinearExtrusion.hxx>
#include <GeomAPI_ExtremaCurveCurve.hxx>
#include <Geom_Line.hxx>
#include <GeomAPI.hxx>

#include <gp_Pln.hxx>
#include <gp_Pnt.hxx>
#include <gp_Lin.hxx>
#include <gp_Ax1.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Elips.hxx>

#include <AIS.hxx>

#include <Precision.hxx>

#include <TopExp_Explorer.hxx>

//=======================================================================
//function : AIS_EllipseRadiusDimension
//purpose  : 
//=======================================================================

AIS_EllipseRadiusDimension::AIS_EllipseRadiusDimension(const TopoDS_Shape& aShape, 
						       const TCollection_ExtendedString& aText)
:AIS_Relation()
{
  myFShape = aShape;
  myText = aText;
//  ComputeGeometry( );
}

//=======================================================================
//function : ComputeGeometry
//purpose  : 
//=======================================================================

void AIS_EllipseRadiusDimension::ComputeGeometry()
{

 switch (myFShape.ShapeType()) {
  case TopAbs_FACE :
    {
      // compute one face case
      ComputeFaceGeometry ();
      break;
    }
  case TopAbs_EDGE:
    {
      ComputeEdgeGeometry ();
      break;
    }
  default:
    break;
  }
 while (myFirstPar > 2*PI) myFirstPar -= 2*PI;
 while (myLastPar > 2*PI)  myLastPar  -= 2*PI;
 while (myFirstPar < 0.0)  myFirstPar += 2*PI;
 while (myLastPar  < 0.0)  myLastPar  += 2*PI;
}

//=======================================================================
//function : ComputeFaceGeometry
//purpose  : 
//=======================================================================

void AIS_EllipseRadiusDimension::ComputeFaceGeometry()
{

  gp_Pln aPln;
  Handle( Geom_Surface ) aBasisSurf;
  AIS_KindOfSurface aSurfType;
  Standard_Real Offset;
  AIS::GetPlaneFromFace( TopoDS::Face(  myFShape),
					aPln,
					aBasisSurf,
				        aSurfType,
					Offset ) ;

  if ( aSurfType == AIS_KOS_Plane )
    ComputePlanarFaceGeometry( );
  else 
    ComputeCylFaceGeometry( aSurfType, aBasisSurf, Offset );

}

//=======================================================================
//function : ComputeCylFaceGeometry
//purpose  : defines Ellipse and plane of dimension
//=======================================================================

void AIS_EllipseRadiusDimension::ComputeCylFaceGeometry(const AIS_KindOfSurface  aSurfType,
							const Handle( Geom_Surface )&  aBasisSurf,
							const Standard_Real Offset)
{

  BRepAdaptor_Surface surf1(TopoDS::Face(myFShape));
  Standard_Real vFirst, vLast;
  vFirst = surf1.FirstVParameter();
  vLast  = surf1.LastVParameter();
  Standard_Real vMid = (vFirst + vLast)*0.5;
  gp_Pln aPlane;
  gp_Ax1 Axis;
//  Standard_Real Param;
  if (aSurfType == AIS_KOS_Extrusion)
    {
      Axis.SetDirection((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
			->Direction() );
      Axis.SetLocation( gp_Pnt((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
			       ->Direction().XYZ() ) );
      
      aPlane.SetAxis(Axis);
      aPlane.SetLocation(myEllipse.Location());
      myPlane = new Geom_Plane(aPlane);
      
      Handle(Geom_Curve) aCurve;
      aCurve =   aBasisSurf->VIso(vMid);
      if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) 
	{
	  myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)-> Elips();//gp_Elips
	  myIsAnArc = Standard_False;
	}
      else if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
	Handle(Geom_TrimmedCurve) tCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve); 
	aCurve = tCurve->BasisCurve();
	myFirstPar = tCurve->FirstParameter();
	myLastPar  = tCurve->LastParameter();
	myIsAnArc = Standard_True;
	if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) 
	  {
	    myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)->Elips();//gp_Elips
	  }
      }
      else 
	{
	  Standard_ConstructionError::Raise("AIS:: Not expected type of surface") ;
	    return;
	  }
      
// Offset  

      if(surf1.GetType() ==  GeomAbs_OffsetSurface)
	{
	  if(Offset <0.0 && Abs(Offset) > myEllipse.MinorRadius ())
	    {
	      Standard_ConstructionError::Raise("AIS:: Absolute value of negative offset is larger than MinorRadius");
		return;
	      }
	  
	  myOffsetCurve = new Geom_OffsetCurve(new Geom_Ellipse(myEllipse), Offset, 
					       myPlane->Pln().Axis().Direction());
	  myOffset = Offset;
	  myIsOffset = Standard_True;
	  gp_Elips elips = myEllipse;
	  Standard_Real Val = Offset + elips.MajorRadius ();//simulation
	  myEllipse.SetMajorRadius (Val);
	  Val = Offset + elips.MinorRadius ();
	  myEllipse.SetMinorRadius (Val);
	}
      else 
	myIsOffset = Standard_False;
    }
}


//=======================================================================
//function : ComputePlanarFaceGeometry
//purpose  : 
//=======================================================================

void AIS_EllipseRadiusDimension::ComputePlanarFaceGeometry()
{

  Standard_Boolean find = Standard_False;
  gp_Pnt ptfirst,ptend;
  TopExp_Explorer ExploEd( TopoDS::Face(myFShape), TopAbs_EDGE );
  for ( ; ExploEd.More(); ExploEd.Next())
    {
      TopoDS_Edge curedge =  TopoDS::Edge( ExploEd.Current() );
      Handle(Geom_Curve) curv;
      Handle(Geom_Ellipse) ellips;
      if (AIS::ComputeGeometry(curedge,curv,ptfirst,ptend)) 
	{ 
	  if (curv->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
	    {
	      ellips = Handle(Geom_Ellipse)::DownCast(curv);
	      if ( !ellips.IsNull() ) {
		myEllipse = ellips->Elips();
		find = Standard_True;
		break;
	      }
	    }
	}
    }
  if( !find )
    {
      Standard_ConstructionError::Raise("AIS:: Curve is not an ellipsee or is Null") ;
	return;
      }
  
  if ( !ptfirst.IsEqual(ptend, Precision::Confusion()) )
    {
      myIsAnArc = Standard_True;
      myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
      myLastPar  = ElCLib::Parameter(myEllipse, ptend); 
    }
  else
    myIsAnArc = Standard_False;

  BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
  myPlane  = new Geom_Plane( surfAlgo.Plane() );
  
}

 

//=======================================================================
//function : ComputeEdgeGeometry
//purpose  : 
//=======================================================================

void AIS_EllipseRadiusDimension::ComputeEdgeGeometry()
{
  gp_Pnt ptfirst,ptend;
  Handle(Geom_Curve) curv;
  if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),curv,ptfirst,ptend)) return;
  
  Handle(Geom_Ellipse) elips = Handle(Geom_Ellipse)::DownCast(curv);
  if ( elips.IsNull()) return;
  
  myEllipse =  elips->Elips();
  gp_Pln aPlane;
  aPlane.SetPosition(gp_Ax3(myEllipse.Position()));
  myPlane  = new Geom_Plane(aPlane);
  
  
  if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) {
    myIsAnArc = Standard_False;
  }
  else {
    myIsAnArc = Standard_True;
    myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
    myLastPar  = ElCLib::Parameter(myEllipse, ptend); 
  }
}
//=======================================================================
//function : KindOfDimension
//purpose  : 
//=======================================================================
 AIS_KindOfDimension AIS_EllipseRadiusDimension::KindOfDimension() const 
{
  return AIS_KOD_ELLIPSERADIUS;
}

//=======================================================================
//function : IsMovable
//purpose  : 
//=======================================================================
 Standard_Boolean AIS_EllipseRadiusDimension::IsMovable() const 
{
  return Standard_True;
}