1 // Copyright: Matra-Datavision 1995
5 #include <ISession2D_SensitiveCurve.h>
7 IMPLEMENT_STANDARD_HANDLE(ISession2D_SensitiveCurve,Select2D_SensitiveEntity)
8 IMPLEMENT_STANDARD_RTTIEXT(ISession2D_SensitiveCurve,Select2D_SensitiveEntity)
10 #include <Bnd_Box2d.hxx>
11 #include <gp_Lin2d.hxx>
12 #include <gp_Dir2d.hxx>
13 #include <gp_Vec2d.hxx>
14 #include <TColgp_Array1OfPnt2d.hxx>
15 #include <SelectBasics_BasicTool.hxx>
16 #include "GCPnts_TangentialDeflection.hxx"
17 #include "Geom2dAdaptor_Curve.hxx"
19 //=====================================================
21 // Purpose :Constructor
22 //=====================================================
25 ISession2D_SensitiveCurve::
26 ISession2D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
27 const Handle(Geom2d_Curve)& C,
28 const Standard_Real CDeflect,
29 const Standard_Integer MaxRect):
30 Select2D_SensitiveEntity(OwnerId),
38 void ISession2D_SensitiveCurve::Compute()
40 Geom2dAdaptor_Curve Curve (myCurve);
41 Standard_Real ADeflect = 180; //Angular deflection
43 GCPnts_TangentialDeflection PointsOnCurve;
44 PointsOnCurve.Initialize (Curve, ADeflect, myCDeflect,myMaxRect,1.0e-9);
47 myPolyP2d = new TColgp_HArray1OfPnt2d(1,PointsOnCurve.NbPoints());
50 for (Standard_Integer i=1; i<=PointsOnCurve.NbPoints();i++) {
51 P = PointsOnCurve.Value (i);
52 myPolyP2d->SetValue(i,gp_Pnt2d(P.X(),P.Y()));
58 //=====================================================
60 // Purpose : return the bounding boxes
61 //=====================================================
62 void ISession2D_SensitiveCurve::Areas(SelectBasics_ListOfBox2d& boxes)
64 // calcul des Areas --> le nombre voulu est myMaxRect
65 // mais il y a myPolyP2d->Length() segments
67 Standard_Integer NbSeg = myPolyP2d->Length()-1;
68 Standard_Integer nbPerBoxes= NbSeg/myMaxRect;
70 Standard_Integer CurrentPoint =1;
71 for (Standard_Integer i=1;i<=myMaxRect-1;i++)
74 abox.Set(myPolyP2d->Value(CurrentPoint));
75 for(Standard_Integer j=1;j<=nbPerBoxes;j++)
78 abox.Add(myPolyP2d->Value(CurrentPoint));
83 abox.Set(myPolyP2d->Value(CurrentPoint));
84 for(Standard_Integer j=CurrentPoint;j<=myPolyP2d->Length()-1;j++)
87 abox.Add(myPolyP2d->Value(CurrentPoint));
93 //=======================================================
95 // Purpose : test : segments in the bounding boxe
96 //=======================================================
97 Standard_Boolean ISession2D_SensitiveCurve::
98 Matches (const Standard_Real XMin,
99 const Standard_Real YMin,
100 const Standard_Real XMax,
101 const Standard_Real YMax,
102 const Standard_Real aTol)
106 BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
108 for(Standard_Integer j=1;j<=myPolyP2d->Length()-1;j++)
110 if(BoundBox.IsOut(myPolyP2d->Value(j))) return Standard_False;
112 return Standard_True;
116 //====================================================
117 // Function : Matches
118 // Purpose : test the real dist to the segments
119 //====================================================
120 Standard_Boolean ISession2D_SensitiveCurve::
121 Matches(const Standard_Real X,
122 const Standard_Real Y,
123 const Standard_Real aTol,
126 // VERY VERY IMPORTANT : set the selector sensibility !!! ( it's aTol !! )
127 Standard_Integer Rank=0; // New in 2.0
128 if (aTol == 0) {TRACE0("VERY VERY IMPORTANT : set the selector sensibility !!! ( it's aTol !! )");}
130 Standard_Boolean Result = SelectBasics_BasicTool::MatchPolyg2d(myPolyP2d->Array1(),
139 Handle(TColgp_HArray1OfPnt2d) ISession2D_SensitiveCurve::