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