Integration of OCCT 6.5.0 from SVN
[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
7IMPLEMENT_STANDARD_HANDLE(ISession2D_SensitiveCurve,Select2D_SensitiveEntity)
8IMPLEMENT_STANDARD_RTTIEXT(ISession2D_SensitiveCurve,Select2D_SensitiveEntity)
9
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"
18
19//=====================================================
20// Function : Create
21// Purpose :Constructor
22//=====================================================
23
24
25ISession2D_SensitiveCurve::
26ISession2D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
27 const Handle(Geom2d_Curve)& C,
28 const Standard_Real CDeflect,
29 const Standard_Integer MaxRect):
30Select2D_SensitiveEntity(OwnerId),
31myMaxRect(MaxRect),
32myCurve(C),
33myCDeflect(CDeflect)
34{
35 Compute();
36}
37
38void ISession2D_SensitiveCurve::Compute()
39{
40 Geom2dAdaptor_Curve Curve (myCurve);
41 Standard_Real ADeflect = 180; //Angular deflection
42
43 GCPnts_TangentialDeflection PointsOnCurve;
44 PointsOnCurve.Initialize (Curve, ADeflect, myCDeflect,myMaxRect,1.0e-9);
45
46
47 myPolyP2d = new TColgp_HArray1OfPnt2d(1,PointsOnCurve.NbPoints());
48
49 gp_Pnt P;
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()));
53 }
54
55}
56
57
58//=====================================================
59// Function : Areas
60// Purpose : return the bounding boxes
61//=====================================================
62void ISession2D_SensitiveCurve::Areas(SelectBasics_ListOfBox2d& boxes)
63{
64 // calcul des Areas --> le nombre voulu est myMaxRect
65 // mais il y a myPolyP2d->Length() segments
66
67 Standard_Integer NbSeg = myPolyP2d->Length()-1;
68 Standard_Integer nbPerBoxes= NbSeg/myMaxRect;
69
70 Standard_Integer CurrentPoint =1;
71 for (Standard_Integer i=1;i<=myMaxRect-1;i++)
72 {
73 Bnd_Box2d abox;
74 abox.Set(myPolyP2d->Value(CurrentPoint));
75 for(Standard_Integer j=1;j<=nbPerBoxes;j++)
76 {
77 CurrentPoint++;
78 abox.Add(myPolyP2d->Value(CurrentPoint));
79 }
80 boxes.Append(abox);
81 }
82 Bnd_Box2d abox;
83 abox.Set(myPolyP2d->Value(CurrentPoint));
84 for(Standard_Integer j=CurrentPoint;j<=myPolyP2d->Length()-1;j++)
85 {
86 CurrentPoint++;
87 abox.Add(myPolyP2d->Value(CurrentPoint));
88 }
89 boxes.Append(abox);
90
91}
92
93//=======================================================
94// Function : Matches
95// Purpose : test : segments in the bounding boxe
96//=======================================================
97Standard_Boolean ISession2D_SensitiveCurve::
98Matches (const Standard_Real XMin,
99 const Standard_Real YMin,
100 const Standard_Real XMax,
101 const Standard_Real YMax,
102 const Standard_Real aTol)
103{
104
105 Bnd_Box2d BoundBox;
106 BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
107
108 for(Standard_Integer j=1;j<=myPolyP2d->Length()-1;j++)
109 {
110 if(BoundBox.IsOut(myPolyP2d->Value(j))) return Standard_False;
111 }
112 return Standard_True;
113
114}
115
116//====================================================
117// Function : Matches
118// Purpose : test the real dist to the segments
119//====================================================
120Standard_Boolean ISession2D_SensitiveCurve::
121 Matches(const Standard_Real X,
122 const Standard_Real Y,
123 const Standard_Real aTol,
124 Standard_Real& DMin)
125{
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 !! )");}
129
130 Standard_Boolean Result = SelectBasics_BasicTool::MatchPolyg2d(myPolyP2d->Array1(),
131 X,Y,
132 aTol,
133 DMin,
134 Rank); // new in 2.0
135 return Result;
136}
137
138
139Handle(TColgp_HArray1OfPnt2d) ISession2D_SensitiveCurve::
140SensitivePolygon()
141{
142 return myPolyP2d;
143}
144
145