Integration of OCCT 6.5.0 from SVN
[occt.git] / src / MeshVS / MeshVS_SensitiveSegment.cxx
1 // File:        MeshVS_SensitiveSegment.cxx
2 // Created:     Mon Sep 29 2003
3 // Author:      Alexander SOLOVYOV and Sergey LITONIN
4 // Copyright:    Open CASCADE 2003
5
6 #include <MeshVS_SensitiveSegment.ixx>
7 #include <Select3D_Projector.hxx>
8 #include <Bnd_Box2d.hxx>
9 #include <CSLib_Class2d.hxx>
10 #include <TopLoc_Location.hxx>
11
12 //=======================================================================
13 // name    : MeshVS_SensitiveSegment::MeshVS_SensitiveSegment
14 // Purpose :
15 //=======================================================================
16 MeshVS_SensitiveSegment::MeshVS_SensitiveSegment (
17              const Handle(SelectBasics_EntityOwner)& theOwnerId,
18              const gp_Pnt&                           theFirstP,
19              const gp_Pnt&                           theLastP,
20              const Standard_Integer                  theMaxRect )
21 : Select3D_SensitiveSegment( theOwnerId, theFirstP, theLastP, theMaxRect )
22 {
23   myCentre.SetXYZ( ( theFirstP.XYZ() + theLastP.XYZ() ) / 2 );
24 }
25
26 //=======================================================================
27 // name    : MeshVS_SensitiveSegment::Project
28 // Purpose :
29 //=======================================================================
30 void MeshVS_SensitiveSegment::Project( const Select3D_Projector& aProj )
31 {
32   Select3D_SensitiveSegment::Project( aProj );
33   if ( HasLocation() )
34     aProj.Project( myCentre.Transformed( Location().Transformation() ), myProjCentre );
35   else
36     aProj.Project( myCentre, myProjCentre );
37 }
38
39 //=======================================================================
40 // name    : MeshVS_SensitiveSegment::Matches
41 // Purpose :
42 //=======================================================================
43 Standard_Boolean MeshVS_SensitiveSegment::Matches( const Standard_Real XMin,
44                                                    const Standard_Real YMin,
45                                                    const Standard_Real XMax,
46                                                    const Standard_Real YMax,
47                                                    const Standard_Real aTol )
48 {
49   Bnd_Box2d aBox;
50   aBox.Update( XMin-aTol, YMin-aTol, XMax+aTol, YMax+aTol );
51   return !aBox.IsOut( myProjCentre );
52 }
53
54 //=======================================================================
55 // name    : MeshVS_SensitiveSegment::Matches
56 // Purpose :
57 //=======================================================================
58 Standard_Boolean MeshVS_SensitiveSegment::Matches( const TColgp_Array1OfPnt2d& Polyline,
59                                                    const Bnd_Box2d&            aBox,
60                                                    const Standard_Real         aTol )
61 {
62   Standard_Real Umin, Vmin, Umax, Vmax;
63   aBox.Get ( Umin,Vmin,Umax,Vmax );
64   CSLib_Class2d aClassifier2d( Polyline, aTol, aTol, Umin, Vmin, Umax, Vmax );
65   Standard_Integer aRes = aClassifier2d.SiDans( myProjCentre );
66
67   return ( aRes == 1) ;
68 }