Integration of OCCT 6.5.0 from SVN
[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 #include <Graphic2d_SetOfCurves.hxx>
10 #include <Geom2dAdaptor_Curve.hxx>
11 #include <Bnd_Box2d.hxx>
12 #include <BndLib_Add2dCurve.hxx>
13 #include <Precision.hxx>
14 #include <Select2D_SensitiveBox.hxx>
15 #include <Select2D_SensitiveSegment.hxx>
16 #include <gp_Circ2d.hxx>
17 #include <gp_Dir2d.hxx>
18 #include <gp_Ax2d.hxx>
19 #include <Select2D_SensitiveArc.hxx>
20 #include <Geom2d_Curve.hxx>
21 #include <GeomTools_Curve2dSet.hxx>
22 #include <Geom2d_TrimmedCurve.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <GCE2d_MakeSegment.hxx>
25 #include <gp_Vec2d.hxx>
26 #include <OSD_Environment.hxx>
27 #include <Graphic2d_Array1OfVertex.hxx>
28 #include <Graphic2d_PolyLine.hxx>
29 #include <SelectMgr_Selection.hxx>
30 #include <Graphic2d_Segment.hxx>
31 #include <GeomAbs_CurveType.hxx>
32 #include <Graphic2d_Vertex.hxx>
33 #include <Geom2d_BezierCurve.hxx>
34
35  ISession2D_Curve::ISession2D_Curve(const Handle_Geom2d_Curve aGeom2dCurve,
36                                                 const Aspect_TypeOfLine aTypeOfLine,
37                                                 const Aspect_WidthOfLine aWidthOfLine,
38                                                 const Standard_Integer aColorIndex)
39     :AIS_InteractiveObject()
40 {
41   myGeom2dCurve = aGeom2dCurve;
42   myTypeOfLine  = aTypeOfLine ;
43   myWidthOfLine = aWidthOfLine;
44   myColorIndex  = aColorIndex ;
45   myDisplayPole = Standard_True;
46   myDisplayCurbure = Standard_False;
47   myDiscretisation = 20;
48   myradiusmax = 10;
49   myradiusratio = 1;
50 }
51
52 void ISession2D_Curve::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager,
53                              const Handle(Graphic2d_GraphicObject)& aGrObj,
54                              const Standard_Integer aMode) 
55 {
56   Handle(Graphic2d_SetOfCurves) segment;
57   segment = new Graphic2d_SetOfCurves(aGrObj);
58
59
60   segment->Add(myGeom2dCurve);
61   
62   segment->SetColorIndex (myColorIndex);
63   segment->SetWidthIndex (myWidthOfLine + 1);
64   segment->SetTypeIndex  (myTypeOfLine  + 1);
65
66   Geom2dAdaptor_Curve anAdaptor(myGeom2dCurve);
67   if (myDisplayPole) 
68    {
69     if (anAdaptor.GetType() == GeomAbs_BezierCurve  )
70     {
71       Handle(Geom2d_BezierCurve) aBezier = anAdaptor.Bezier();
72       Graphic2d_Array1OfVertex anArrayOfVertex(1,aBezier->NbPoles());
73       for(int i=1;i<=aBezier->NbPoles();i++)
74         {
75           gp_Pnt2d CurrentPoint = aBezier->Pole(i);
76           Graphic2d_Vertex aVertex(CurrentPoint.X(),CurrentPoint.Y());
77           anArrayOfVertex(i)=aVertex;
78         }
79       Handle(Graphic2d_Polyline) aPolyline = new Graphic2d_Polyline(aGrObj,anArrayOfVertex);
80       }
81
82     if (anAdaptor.GetType() == GeomAbs_BSplineCurve  )
83     {
84       Handle(Geom2d_BSplineCurve) aBSpline = anAdaptor.BSpline();
85
86       Graphic2d_Array1OfVertex anArrayOfVertex(1,aBSpline->NbPoles());
87
88       for(int i=1;i<=aBSpline->NbPoles();i++)
89         {
90           gp_Pnt2d CurrentPoint = aBSpline->Pole(i);
91           Graphic2d_Vertex aVertex(CurrentPoint.X(),CurrentPoint.Y());
92           anArrayOfVertex(i)=aVertex;
93         }
94       Handle(Graphic2d_Polyline) aPolyline = new Graphic2d_Polyline(aGrObj,anArrayOfVertex);
95       }
96     }
97
98   if (myDisplayCurbure && (anAdaptor.GetType() != GeomAbs_Line))
99   {
100     Standard_Integer ii;
101     Standard_Integer intrv, nbintv = anAdaptor.NbIntervals(GeomAbs_CN);
102     TColStd_Array1OfReal TI(1,nbintv+1);
103     anAdaptor.Intervals(TI,GeomAbs_CN);
104     Standard_Real Resolution = 1.0e-9, Curvature;
105     Geom2dLProp_CLProps2d LProp(myGeom2dCurve, 2, Resolution);
106     gp_Pnt2d P1, P2;    
107
108     for (intrv = 1; intrv <= nbintv; intrv++) 
109      {
110           Standard_Real t = TI(intrv);
111           Standard_Real step = (TI(intrv+1) - t) / GetDiscretisation();
112           Standard_Real LRad, ratio;
113           for (ii = 1; ii <= myDiscretisation; ii++) 
114        {         
115             LProp.SetParameter(t);
116         if (LProp.IsTangentDefined()) 
117          {
118                Curvature = Abs(LProp.Curvature());
119                if ( Curvature >  Resolution) 
120             {
121                   myGeom2dCurve->D0(t, P1);
122                   LRad = 1./Curvature;
123                   ratio = ( (  LRad > myradiusmax) ? myradiusmax/LRad : 1 );
124                   ratio *= myradiusratio;
125                   LProp.CentreOfCurvature(P2);
126                   gp_Vec2d V(P1, P2);
127               gp_Pnt2d P3 = P1.Translated(ratio*V);
128               Handle(Graphic2d_Segment) aSegment = new Graphic2d_Segment(aGrObj,P1.X(),P1.Y(),P3.X(),P3.Y());
129                 }
130              }
131              t += step;
132           }
133     }
134   }
135 }
136
137
138 void ISession2D_Curve::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
139                                       const Standard_Integer aMode) 
140
141 }
142
143