7fd59977 |
1 | // Copyright: Matra-Datavision 1995 |
2 | |
3 | #include "stdafx.h" |
4 | |
5 | #include <ISession2D_SensitiveCurve.h> |
234e52be |
6 | #include <GCPnts_TangentialDeflection.hxx> |
7 | #include <SelectBasics_BasicTool.hxx> |
7fd59977 |
8 | |
5c1f974e |
9 | IMPLEMENT_STANDARD_HANDLE(ISession2D_SensitiveCurve,Select3D_SensitiveEntity) |
10 | IMPLEMENT_STANDARD_RTTIEXT(ISession2D_SensitiveCurve,Select3D_SensitiveEntity) |
7fd59977 |
11 | |
12 | //===================================================== |
13 | // Function : Create |
14 | // Purpose :Constructor |
15 | //===================================================== |
16 | |
17 | |
18 | ISession2D_SensitiveCurve:: |
19 | ISession2D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId, |
20 | const Handle(Geom2d_Curve)& C, |
21 | const Standard_Real CDeflect, |
22 | const Standard_Integer MaxRect): |
5c1f974e |
23 | Select3D_SensitiveEntity(OwnerId), |
7fd59977 |
24 | myMaxRect(MaxRect), |
25 | myCurve(C), |
26 | myCDeflect(CDeflect) |
27 | { |
28 | Compute(); |
29 | } |
30 | |
31 | void ISession2D_SensitiveCurve::Compute() |
32 | { |
33 | Geom2dAdaptor_Curve Curve (myCurve); |
34 | Standard_Real ADeflect = 180; //Angular deflection |
35 | |
36 | GCPnts_TangentialDeflection PointsOnCurve; |
37 | PointsOnCurve.Initialize (Curve, ADeflect, myCDeflect,myMaxRect,1.0e-9); |
38 | |
39 | |
40 | myPolyP2d = new TColgp_HArray1OfPnt2d(1,PointsOnCurve.NbPoints()); |
41 | |
42 | gp_Pnt P; |
43 | for (Standard_Integer i=1; i<=PointsOnCurve.NbPoints();i++) { |
44 | P = PointsOnCurve.Value (i); |
45 | myPolyP2d->SetValue(i,gp_Pnt2d(P.X(),P.Y())); |
46 | } |
47 | |
48 | } |
49 | |
50 | |
51 | //===================================================== |
52 | // Function : Areas |
53 | // Purpose : return the bounding boxes |
54 | //===================================================== |
55 | void ISession2D_SensitiveCurve::Areas(SelectBasics_ListOfBox2d& boxes) |
56 | { |
57 | // calcul des Areas --> le nombre voulu est myMaxRect |
58 | // mais il y a myPolyP2d->Length() segments |
59 | |
60 | Standard_Integer NbSeg = myPolyP2d->Length()-1; |
61 | Standard_Integer nbPerBoxes= NbSeg/myMaxRect; |
62 | |
63 | Standard_Integer CurrentPoint =1; |
64 | for (Standard_Integer i=1;i<=myMaxRect-1;i++) |
65 | { |
66 | Bnd_Box2d abox; |
67 | abox.Set(myPolyP2d->Value(CurrentPoint)); |
68 | for(Standard_Integer j=1;j<=nbPerBoxes;j++) |
69 | { |
70 | CurrentPoint++; |
71 | abox.Add(myPolyP2d->Value(CurrentPoint)); |
72 | } |
73 | boxes.Append(abox); |
74 | } |
75 | Bnd_Box2d abox; |
76 | abox.Set(myPolyP2d->Value(CurrentPoint)); |
77 | for(Standard_Integer j=CurrentPoint;j<=myPolyP2d->Length()-1;j++) |
78 | { |
79 | CurrentPoint++; |
80 | abox.Add(myPolyP2d->Value(CurrentPoint)); |
81 | } |
82 | boxes.Append(abox); |
83 | |
84 | } |
85 | |
86 | //======================================================= |
87 | // Function : Matches |
88 | // Purpose : test : segments in the bounding boxe |
89 | //======================================================= |
90 | Standard_Boolean ISession2D_SensitiveCurve:: |
91 | Matches (const Standard_Real XMin, |
92 | const Standard_Real YMin, |
93 | const Standard_Real XMax, |
94 | const Standard_Real YMax, |
95 | const Standard_Real aTol) |
96 | { |
97 | |
98 | Bnd_Box2d BoundBox; |
99 | BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol); |
100 | |
101 | for(Standard_Integer j=1;j<=myPolyP2d->Length()-1;j++) |
102 | { |
103 | if(BoundBox.IsOut(myPolyP2d->Value(j))) return Standard_False; |
104 | } |
105 | return Standard_True; |
106 | |
107 | } |
108 | |
109 | //==================================================== |
110 | // Function : Matches |
111 | // Purpose : test the real dist to the segments |
112 | //==================================================== |
113 | Standard_Boolean ISession2D_SensitiveCurve:: |
114 | Matches(const Standard_Real X, |
115 | const Standard_Real Y, |
116 | const Standard_Real aTol, |
117 | Standard_Real& DMin) |
118 | { |
119 | // VERY VERY IMPORTANT : set the selector sensibility !!! ( it's aTol !! ) |
120 | Standard_Integer Rank=0; // New in 2.0 |
121 | if (aTol == 0) {TRACE0("VERY VERY IMPORTANT : set the selector sensibility !!! ( it's aTol !! )");} |
122 | |
123 | Standard_Boolean Result = SelectBasics_BasicTool::MatchPolyg2d(myPolyP2d->Array1(), |
124 | X,Y, |
125 | aTol, |
126 | DMin, |
127 | Rank); // new in 2.0 |
128 | return Result; |
129 | } |
130 | |
131 | |
132 | Handle(TColgp_HArray1OfPnt2d) ISession2D_SensitiveCurve:: |
133 | SensitivePolygon() |
134 | { |
135 | return myPolyP2d; |
136 | } |
137 | |
138 | |