b311480e |
1 | // Created on: 2003-09-29 |
2 | // Created by: Alexander SOLOVYOV and Sergey LITONIN |
973c2be1 |
3 | // Copyright (c) 2003-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
973c2be1 |
7 | // This library is free software; you can redistribute it and / or modify it |
8 | // under the terms of the GNU Lesser General Public version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #include <MeshVS_SensitiveFace.ixx> |
17 | |
18 | #include <TColgp_Array1OfPnt.hxx> |
19 | #include <Select3D_Projector.hxx> |
20 | #include <CSLib_Class2d.hxx> |
21 | #include <TopLoc_Location.hxx> |
22 | |
23 | //======================================================================= |
24 | // name : MeshVS_SensitiveFace::MeshVS_SensitiveFace |
25 | // Purpose : |
26 | //======================================================================= |
27 | MeshVS_SensitiveFace::MeshVS_SensitiveFace ( |
28 | const Handle(SelectBasics_EntityOwner)& theOwnerId, |
29 | const TColgp_Array1OfPnt& thePnts, |
30 | const Select3D_TypeOfSensitivity theSensitivity ) |
31 | : Select3D_SensitiveFace( theOwnerId, thePnts, theSensitivity ) |
32 | { |
33 | gp_XYZ c( 0, 0, 0 ); |
34 | Standard_Integer nbPnts = thePnts.Upper() - thePnts.Lower() + 1; |
35 | for ( Standard_Integer i = thePnts.Lower(); i <= thePnts.Upper(); i++ ) |
36 | c += thePnts( i ).XYZ(); |
37 | myCentre.SetXYZ( c / nbPnts ); |
38 | } |
39 | |
40 | //======================================================================= |
41 | // name : MeshVS_SensitiveFace::Project |
42 | // Purpose : |
43 | //======================================================================= |
4952a30a |
44 | void MeshVS_SensitiveFace::Project( const Handle(Select3D_Projector)& aProj ) |
7fd59977 |
45 | { |
46 | Select3D_SensitiveFace::Project( aProj ); |
47 | if ( HasLocation() ) |
4952a30a |
48 | aProj->Project( myCentre.Transformed( Location().Transformation() ), myProjCentre ); |
7fd59977 |
49 | else |
4952a30a |
50 | aProj->Project( myCentre, myProjCentre ); |
7fd59977 |
51 | } |
52 | |
53 | //======================================================================= |
54 | // name : MeshVS_SensitiveFace::Matches |
55 | // Purpose : |
56 | //======================================================================= |
57 | Standard_Boolean MeshVS_SensitiveFace::Matches( const Standard_Real XMin, |
58 | const Standard_Real YMin, |
59 | const Standard_Real XMax, |
60 | const Standard_Real YMax, |
61 | const Standard_Real aTol ) |
62 | { |
63 | Bnd_Box2d aBox; |
64 | aBox.Update( XMin-aTol, YMin-aTol, XMax+aTol, YMax+aTol ); |
65 | return !aBox.IsOut( myProjCentre ); |
66 | } |
67 | |
68 | //======================================================================= |
69 | // name : MeshVS_SensitiveFace::Matches |
70 | // Purpose : |
71 | //======================================================================= |
72 | Standard_Boolean MeshVS_SensitiveFace::Matches( const TColgp_Array1OfPnt2d& Polyline, |
73 | const Bnd_Box2d& aBox, |
74 | const Standard_Real aTol ) |
75 | { |
76 | Standard_Real Umin, Vmin, Umax, Vmax; |
77 | aBox.Get ( Umin,Vmin,Umax,Vmax ); |
78 | CSLib_Class2d aClassifier2d( Polyline, aTol, aTol, Umin, Vmin, Umax, Vmax ); |
79 | Standard_Integer aRes = aClassifier2d.SiDans( myProjCentre ); |
80 | |
81 | return ( aRes == 1) ; |
82 | } |