3 #include <ISession2D_Curve.h>
4 #include "..\\GeometryApp.h"
5 #include <Graphic3d_ArrayOfPolylines.hxx>
6 #include <Geom2d_BezierCurve.hxx>
7 #include <Geom2dLProp_CLProps2d.hxx>
8 #include <TColStd_Array1OfReal.hxx>
9 #include <Geom2d_BSplineCurve.hxx>
11 IMPLEMENT_STANDARD_RTTIEXT(ISession2D_Curve,AIS_InteractiveObject)
14 ISession2D_Curve::ISession2D_Curve(const Handle(Geom2d_Curve) aGeom2dCurve,
15 const Aspect_TypeOfLine aTypeOfLine,
16 const Aspect_WidthOfLine aWidthOfLine,
17 const Standard_Integer aColorIndex)
18 :AIS_InteractiveObject()
20 myGeom2dCurve = aGeom2dCurve;
21 myTypeOfLine = aTypeOfLine ;
22 myWidthOfLine = aWidthOfLine;
23 myColorIndex = aColorIndex ;
24 myDisplayPole = Standard_True;
25 myDisplayCurbure = Standard_False;
26 myDiscretisation = 20;
31 void ISession2D_Curve::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
32 const Handle(Prs3d_Presentation)& aPresentation,
33 const Standard_Integer /*aMode*/)
36 Geom2dAdaptor_Curve anAdaptor(myGeom2dCurve);
37 GCPnts_QuasiUniformDeflection anEdgeDistrib(anAdaptor,1.e-2);
38 if(anEdgeDistrib.IsDone())
40 Handle(Graphic3d_ArrayOfPolylines) aCurve =
41 new Graphic3d_ArrayOfPolylines(anEdgeDistrib.NbPoints());
42 for(Standard_Integer i=1;i<=anEdgeDistrib.NbPoints();++i)
43 aCurve->AddVertex(anEdgeDistrib.Value(i));
45 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aCurve);
50 if (anAdaptor.GetType() == GeomAbs_BezierCurve )
52 Handle(Geom2d_BezierCurve) aBezier = anAdaptor.Bezier();
53 Handle(Graphic3d_ArrayOfPolylines) anArrayOfVertex = new Graphic3d_ArrayOfPolylines(aBezier->NbPoles());
54 for(int i=1;i<=aBezier->NbPoles();i++)
56 gp_Pnt2d CurrentPoint = aBezier->Pole(i);
57 anArrayOfVertex->AddVertex(CurrentPoint.X(),CurrentPoint.Y(),0.);
59 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(anArrayOfVertex);
62 if (anAdaptor.GetType() == GeomAbs_BSplineCurve )
64 Handle(Geom2d_BSplineCurve) aBSpline = anAdaptor.BSpline();
66 Handle(Graphic3d_ArrayOfPolylines) anArrayOfVertex =
67 new Graphic3d_ArrayOfPolylines(aBSpline->NbPoles());
69 for(int i=1;i<=aBSpline->NbPoles();i++)
71 gp_Pnt2d CurrentPoint = aBSpline->Pole(i);
72 anArrayOfVertex->AddVertex(CurrentPoint.X(),CurrentPoint.Y(),0.);
74 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(anArrayOfVertex);
78 if (myDisplayCurbure && (anAdaptor.GetType() != GeomAbs_Line))
81 Standard_Integer intrv, nbintv = anAdaptor.NbIntervals(GeomAbs_CN);
82 TColStd_Array1OfReal TI(1,nbintv+1);
83 anAdaptor.Intervals(TI,GeomAbs_CN);
84 Standard_Real Resolution = 1.0e-9, Curvature;
85 Geom2dLProp_CLProps2d LProp(myGeom2dCurve, 2, Resolution);
88 for (intrv = 1; intrv <= nbintv; intrv++)
90 Standard_Real t = TI(intrv);
91 Standard_Real step = (TI(intrv+1) - t) / GetDiscretisation();
92 Standard_Real LRad, ratio;
93 for (ii = 1; ii <= myDiscretisation; ii++)
95 LProp.SetParameter(t);
96 if (LProp.IsTangentDefined())
98 Curvature = Abs(LProp.Curvature());
99 if ( Curvature > Resolution)
101 myGeom2dCurve->D0(t, P1);
103 ratio = ( ( LRad > myradiusmax) ? myradiusmax/LRad : 1 );
104 ratio *= myradiusratio;
105 LProp.CentreOfCurvature(P2);
107 gp_Pnt2d P3 = P1.Translated(ratio*V);
108 Handle(Graphic3d_ArrayOfPolylines) aSegment = new Graphic3d_ArrayOfPolylines(2);
109 aSegment->AddVertex(P1.X(),P1.Y(),0.);
110 aSegment->AddVertex(P3.X(),P3.Y(),0.);
111 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aSegment);
120 void ISession2D_Curve::ComputeSelection(const Handle(SelectMgr_Selection)& /*aSelection*/,
121 const Standard_Integer /*aMode*/)