1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // Author : OPEN CASCADE
24 // File: GLViewer_Selector2d.cxx
25 // Created: November, 2004
26 //#include <GLViewerAfx.h>
28 #include "GLViewer_Selector2d.h"
29 #include "GLViewer_Viewer2d.h"
30 #include "GLViewer_Context.h"
31 #include "GLViewer_ViewPort.h"
32 #include "GLViewer_ViewFrame.h"
37 GLViewer_Selector2d::GLViewer_Selector2d( GLViewer_Viewer2d* v2d, GLViewer_Context* glc ) :
38 GLViewer_Selector( v2d ),
41 // myGLContext->SetHighlightColor( Quantity_NOC_CYAN1 );
42 // myGLContext->SetSelectionColor( Quantity_NOC_RED );
48 GLViewer_Selector2d::~GLViewer_Selector2d()
53 Changes hilight color of context
54 \param color - new hilight color
56 void GLViewer_Selector2d::setHilightColor( Quantity_NameOfColor color )
58 myGLContext->SetHighlightColor( color );
62 Changes selection color of context
63 \param color - new selection color
65 void GLViewer_Selector2d::setSelectColor( Quantity_NameOfColor color )
67 myGLContext->SetSelectionColor( color );
71 Detects object at point
72 \param x, y - point co-ordinates
74 void GLViewer_Selector2d::detect( int x, int y )
76 //cout << "GLViewer_Selector2d : detect ( " << x << " , " << y << " )" << endl;
77 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
78 myViewer->getSelectionMode() == GLViewer_Viewer::NoSelection )
81 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
82 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
85 myGLContext->MoveTo( x, y );
91 void GLViewer_Selector2d::undetectAll()
93 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
94 myViewer->getSelectionMode() == GLViewer_Viewer::NoSelection )
97 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
98 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
101 myGLContext->clearHighlighted( true );
105 Selects previously hilighted objects
106 \param append - append objects to selection
108 void GLViewer_Selector2d::select( bool append )
110 //cout << "GLViewer_Selector2d : select ( " << (int)append << " )" << endl;
111 GLViewer_Viewer::SelectionMode selMode = myViewer->getSelectionMode();
112 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
113 selMode == GLViewer_Viewer::NoSelection )
116 int selBefore = numSelected();
117 if ( selBefore && append && selMode != GLViewer_Viewer::Multiple )
120 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
121 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
124 int status = myGLContext->Select( append );
125 checkSelection( selBefore, append, status );
129 Selects objects in rectangle
130 \param selRect - selection rectangle
131 \param append - append objects to selection
133 void GLViewer_Selector2d::select( const QRect& selRect, bool append )
135 GLViewer_Viewer::SelectionMode selMode = myViewer->getSelectionMode();
136 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
137 selMode == GLViewer_Viewer::NoSelection )
140 int selBefore = numSelected();
141 if ( selBefore && append && selMode != GLViewer_Viewer::Multiple )
144 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
145 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
148 int aStatus = myGLContext->SelectByRect( selRect, append );
149 checkSelection( selBefore, append, aStatus );
153 Unselects all objects
155 void GLViewer_Selector2d::unselectAll()
157 if ( myLocked || !myViewer )
160 // bool updateViewer = true;
161 bool hadSelection = ( numSelected() > 0 );
163 // bool lcOpen = ( myAISContext->IndexOfCurrentLocal() != -1 );
164 // lcOpen ? myAISContext->ClearSelected( updateViewer ) :
165 // myAISContext->ClearCurrent( updateViewer );
166 if ( hadSelection ) emit selSelectionCancel();
170 Checks selection state and emits 'selSelectionDone' or 'selSelectionCancel'
171 Should be called by after non-interactive selection.
173 void GLViewer_Selector2d::checkSelection( int selBefore, bool append, int aStatus )
175 int selAfter = numSelected();
176 if ( selBefore > 0 && selAfter < 1 )
177 emit selSelectionCancel();
178 else if ( selAfter > 0 )
182 case SS_LocalChanged:
183 emit selSelectionDone( selAfter > 1, SCS_Local );
185 case SS_GlobalChanged:
186 emit selSelectionDone( selAfter > 1, SCS_Global );
193 \return number of selected objects
195 int GLViewer_Selector2d::numSelected() const
197 return myGLContext->NbSelected();