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