Salome HOME
fb4753aeee387f36bc7b3f426837c7fcae3106ed
[modules/gui.git] / src / GraphicsView / GraphicsView_Selector.cxx
1 // Copyright (C) 2013-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "GraphicsView_Selector.h"
21 #include "GraphicsView_Viewer.h"
22 #include "GraphicsView_ViewPort.h"
23 #include "GraphicsView_ViewFrame.h"
24
25 int GraphicsView_Selector::appendKey = Qt::ShiftModifier;
26
27 //=======================================================================
28 // Name    : GraphicsView_Selector
29 // Purpose : Constructor
30 //=======================================================================
31 GraphicsView_Selector::GraphicsView_Selector( GraphicsView_Viewer* theViewer )
32 : QObject( 0 ),
33   myViewer( theViewer ),
34   myLocked( false )
35 {   
36 }
37
38 //=======================================================================
39 // Name    : GraphicsView_Selector
40 // Purpose : Destructor
41 //=======================================================================
42 GraphicsView_Selector::~GraphicsView_Selector()
43 {
44 }
45
46 //================================================================
47 // Function : detect
48 // Purpose  : 
49 //================================================================
50 void GraphicsView_Selector::detect( double x, double y )
51 {
52   if ( myLocked )
53     return;
54
55   if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
56     aViewPort->highlight( x, y );
57 }
58
59 //================================================================
60 // Function : undetectAll
61 // Purpose  : 
62 //================================================================
63 void GraphicsView_Selector::undetectAll()
64 {
65   if ( myLocked )
66     return;
67
68   if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
69     aViewPort->clearHighlighted();
70 }
71
72 //================================================================
73 // Function : select
74 // Purpose  : 
75 //================================================================
76 void GraphicsView_Selector::select( const QRectF& selRect, bool append )
77 {
78   if ( myLocked ) 
79     return;
80
81   int selBefore = numSelected();
82   if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
83   {
84     int aStatus = aViewPort->select( selRect, append );
85     checkSelection( selBefore, append, aStatus );
86   }
87 }
88
89 //================================================================
90 // Function : unselectAll
91 // Purpose  : 
92 //================================================================
93 void GraphicsView_Selector::unselectAll()
94 {
95   if ( myLocked ) 
96     return;
97
98   if ( numSelected() > 0 )
99     emit selSelectionCancel();
100 }
101
102 //================================================================
103 // Function : checkSelection
104 // Purpose  : 
105 //================================================================
106 void GraphicsView_Selector::checkSelection( int selBefore, bool /*append*/, int theStatus )
107 {
108   int selAfter = numSelected();
109   if ( selBefore > 0 && selAfter < 1 )     
110     emit selSelectionCancel();
111   else if ( selAfter > 0 )
112   {
113     switch( theStatus )
114     {
115       case GVSS_LocalChanged:
116         emit selSelectionDone( GVSCS_Local );
117         break;
118       case GVSS_GlobalChanged:
119         emit selSelectionDone( GVSCS_Global );
120         break;
121     }
122   }
123 }
124
125 //================================================================
126 // Function : numSelected
127 // Purpose  : 
128 //================================================================
129 int GraphicsView_Selector::numSelected() const
130 {
131   if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
132     return aViewPort->nbSelected();
133   return 0;
134 }
135