0023776: Redesign of MFC samples after V2d viewer removing
[occt.git] / samples / mfc / standard / 01_Geometry / src / ISession2D / ISession2D_Curve.cpp
1 #include "stdafx.h"
2
3 #include <ISession2D_Curve.h>
4 #include "..\\GeometryApp.h"
5
6 IMPLEMENT_STANDARD_HANDLE(ISession2D_Curve,AIS_InteractiveObject)
7 IMPLEMENT_STANDARD_RTTIEXT(ISession2D_Curve,AIS_InteractiveObject)
8
9
10 ISession2D_Curve::ISession2D_Curve(const Handle_Geom2d_Curve aGeom2dCurve,
11                                    const Aspect_TypeOfLine aTypeOfLine,
12                                    const Aspect_WidthOfLine aWidthOfLine,
13                                    const Standard_Integer aColorIndex)
14                                    :AIS_InteractiveObject()
15 {
16   myGeom2dCurve = aGeom2dCurve;
17   myTypeOfLine  = aTypeOfLine ;
18   myWidthOfLine = aWidthOfLine;
19   myColorIndex  = aColorIndex ;
20   myDisplayPole = Standard_True;
21   myDisplayCurbure = Standard_False;
22   myDiscretisation = 20;
23   myradiusmax = 10;
24   myradiusratio = 1;
25 }
26
27 void ISession2D_Curve::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
28                                const Handle(Prs3d_Presentation)& aPresentation,
29                                const Standard_Integer aMode) 
30 {
31
32   Geom2dAdaptor_Curve anAdaptor(myGeom2dCurve);
33   GCPnts_QuasiUniformDeflection anEdgeDistrib(anAdaptor,1.e-2);
34   if(anEdgeDistrib.IsDone())
35   {
36     Handle(Graphic3d_ArrayOfPolylines) aCurve =
37       new Graphic3d_ArrayOfPolylines(anEdgeDistrib.NbPoints()); 
38     for(Standard_Integer i=1;i<=anEdgeDistrib.NbPoints();++i)
39       aCurve->AddVertex(anEdgeDistrib.Value(i));
40
41     Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aCurve);
42   }
43
44   if (myDisplayPole) 
45   {
46     if (anAdaptor.GetType() == GeomAbs_BezierCurve  )
47     {
48       Handle(Geom2d_BezierCurve) aBezier = anAdaptor.Bezier();
49       Handle(Graphic3d_ArrayOfPolylines) anArrayOfVertex = new Graphic3d_ArrayOfPolylines(aBezier->NbPoles());
50       for(int i=1;i<=aBezier->NbPoles();i++)
51       {
52         gp_Pnt2d CurrentPoint = aBezier->Pole(i);
53         anArrayOfVertex->AddVertex(CurrentPoint.X(),CurrentPoint.Y(),0.);
54       }
55       Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(anArrayOfVertex);
56     }
57
58     if (anAdaptor.GetType() == GeomAbs_BSplineCurve  )
59     {
60       Handle(Geom2d_BSplineCurve) aBSpline = anAdaptor.BSpline();
61
62       Handle(Graphic3d_ArrayOfPolylines) anArrayOfVertex = 
63         new Graphic3d_ArrayOfPolylines(aBSpline->NbPoles());
64
65       for(int i=1;i<=aBSpline->NbPoles();i++)
66       {
67         gp_Pnt2d CurrentPoint = aBSpline->Pole(i);
68         anArrayOfVertex->AddVertex(CurrentPoint.X(),CurrentPoint.Y(),0.);
69       }
70       Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(anArrayOfVertex);
71     }
72   }
73
74   if (myDisplayCurbure && (anAdaptor.GetType() != GeomAbs_Line))
75   {
76     Standard_Integer ii;
77     Standard_Integer intrv, nbintv = anAdaptor.NbIntervals(GeomAbs_CN);
78     TColStd_Array1OfReal TI(1,nbintv+1);
79     anAdaptor.Intervals(TI,GeomAbs_CN);
80     Standard_Real Resolution = 1.0e-9, Curvature;
81     Geom2dLProp_CLProps2d LProp(myGeom2dCurve, 2, Resolution);
82     gp_Pnt2d P1, P2;    
83
84     for (intrv = 1; intrv <= nbintv; intrv++) 
85     {
86       Standard_Real t = TI(intrv);
87       Standard_Real step = (TI(intrv+1) - t) / GetDiscretisation();
88       Standard_Real LRad, ratio;
89       for (ii = 1; ii <= myDiscretisation; ii++) 
90       {  
91         LProp.SetParameter(t);
92         if (LProp.IsTangentDefined()) 
93         {
94           Curvature = Abs(LProp.Curvature());
95           if ( Curvature >  Resolution) 
96           {
97             myGeom2dCurve->D0(t, P1);
98             LRad = 1./Curvature;
99             ratio = ( (  LRad > myradiusmax) ? myradiusmax/LRad : 1 );
100             ratio *= myradiusratio;
101             LProp.CentreOfCurvature(P2);
102             gp_Vec2d V(P1, P2);
103             gp_Pnt2d P3 = P1.Translated(ratio*V);
104             Handle(Graphic3d_ArrayOfPolylines) aSegment = new Graphic3d_ArrayOfPolylines(2);
105             aSegment->AddVertex(P1.X(),P1.Y(),0.);
106             aSegment->AddVertex(P3.X(),P3.Y(),0.);
107             Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aSegment);
108           }
109         }
110         t += step;
111       }
112     }
113   }
114 }
115
116 void ISession2D_Curve::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
117                                         const Standard_Integer aMode) 
118
119 }
120
121