1 // Copyright (C) 2013-2023 CEA, EDF, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GraphicsView_Selector.h"
21 #include "GraphicsView_Viewer.h"
22 #include "GraphicsView_ViewPort.h"
23 #include "GraphicsView_ViewFrame.h"
25 int GraphicsView_Selector::appendKey = Qt::ShiftModifier;
27 //=======================================================================
28 // Name : GraphicsView_Selector
29 // Purpose : Constructor
30 //=======================================================================
31 GraphicsView_Selector::GraphicsView_Selector( GraphicsView_Viewer* theViewer )
33 myViewer( theViewer ),
38 //=======================================================================
39 // Name : GraphicsView_Selector
40 // Purpose : Destructor
41 //=======================================================================
42 GraphicsView_Selector::~GraphicsView_Selector()
46 //================================================================
49 //================================================================
50 void GraphicsView_Selector::detect( double x, double y )
55 if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
56 aViewPort->highlight( x, y );
59 //================================================================
60 // Function : undetectAll
62 //================================================================
63 void GraphicsView_Selector::undetectAll()
68 if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
69 aViewPort->clearHighlighted();
72 //================================================================
75 //================================================================
76 void GraphicsView_Selector::select( const QRectF& selRect, bool append )
81 int selBefore = numSelected();
82 if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
84 int aStatus = aViewPort->select( selRect, append );
85 checkSelection( selBefore, append, aStatus );
89 //================================================================
90 // Function : unselectAll
92 //================================================================
93 void GraphicsView_Selector::unselectAll()
98 if ( numSelected() > 0 )
99 emit selSelectionCancel();
102 //================================================================
103 // Function : checkSelection
105 //================================================================
106 void GraphicsView_Selector::checkSelection( int selBefore, bool /*append*/, int theStatus )
108 int selAfter = numSelected();
109 if ( selBefore > 0 && selAfter < 1 )
110 emit selSelectionCancel();
111 else if ( selAfter > 0 )
115 case GVSS_LocalChanged:
116 emit selSelectionDone( GVSCS_Local );
118 case GVSS_GlobalChanged:
119 emit selSelectionDone( GVSCS_Global );
125 //================================================================
126 // Function : numSelected
128 //================================================================
129 int GraphicsView_Selector::numSelected() const
131 if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
132 return aViewPort->nbSelected();