0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / MeshVS / MeshVS_SensitiveSegment.cxx
1 // Created on: 2003-09-29
2 // Created by: Alexander SOLOVYOV and Sergey LITONIN
3 // Copyright (c) 2003-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21 #include <MeshVS_SensitiveSegment.ixx>
22 #include <Select3D_Projector.hxx>
23 #include <Bnd_Box2d.hxx>
24 #include <CSLib_Class2d.hxx>
25 #include <TopLoc_Location.hxx>
26
27 //=======================================================================
28 // name    : MeshVS_SensitiveSegment::MeshVS_SensitiveSegment
29 // Purpose :
30 //=======================================================================
31 MeshVS_SensitiveSegment::MeshVS_SensitiveSegment (
32              const Handle(SelectBasics_EntityOwner)& theOwnerId,
33              const gp_Pnt&                           theFirstP,
34              const gp_Pnt&                           theLastP,
35              const Standard_Integer                  theMaxRect )
36 : Select3D_SensitiveSegment( theOwnerId, theFirstP, theLastP, theMaxRect )
37 {
38   myCentre.SetXYZ( ( theFirstP.XYZ() + theLastP.XYZ() ) / 2 );
39 }
40
41 //=======================================================================
42 // name    : MeshVS_SensitiveSegment::Project
43 // Purpose :
44 //=======================================================================
45 void MeshVS_SensitiveSegment::Project( const Handle(Select3D_Projector)& aProj )
46 {
47   Select3D_SensitiveSegment::Project( aProj );
48   if ( HasLocation() )
49     aProj->Project( myCentre.Transformed( Location().Transformation() ), myProjCentre );
50   else
51     aProj->Project( myCentre, myProjCentre );
52 }
53
54 //=======================================================================
55 // name    : MeshVS_SensitiveSegment::Matches
56 // Purpose :
57 //=======================================================================
58 Standard_Boolean MeshVS_SensitiveSegment::Matches( const Standard_Real XMin,
59                                                    const Standard_Real YMin,
60                                                    const Standard_Real XMax,
61                                                    const Standard_Real YMax,
62                                                    const Standard_Real aTol )
63 {
64   Bnd_Box2d aBox;
65   aBox.Update( XMin-aTol, YMin-aTol, XMax+aTol, YMax+aTol );
66   return !aBox.IsOut( myProjCentre );
67 }
68
69 //=======================================================================
70 // name    : MeshVS_SensitiveSegment::Matches
71 // Purpose :
72 //=======================================================================
73 Standard_Boolean MeshVS_SensitiveSegment::Matches( const TColgp_Array1OfPnt2d& Polyline,
74                                                    const Bnd_Box2d&            aBox,
75                                                    const Standard_Real         aTol )
76 {
77   Standard_Real Umin, Vmin, Umax, Vmax;
78   aBox.Get ( Umin,Vmin,Umax,Vmax );
79   CSLib_Class2d aClassifier2d( Polyline, aTol, aTol, Umin, Vmin, Umax, Vmax );
80   Standard_Integer aRes = aClassifier2d.SiDans( myProjCentre );
81
82   return ( aRes == 1) ;
83 }