1 // Copyright (C) 2007-2008 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.
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
22 // Author : OPEN CASCADE
23 // File: GLViewer_Selector2d.cxx
24 // Created: November, 2004
25 //#include <GLViewerAfx.h>
27 #include "GLViewer_Selector2d.h"
28 #include "GLViewer_Viewer2d.h"
29 #include "GLViewer_Context.h"
30 #include "GLViewer_ViewPort.h"
31 #include "GLViewer_ViewFrame.h"
36 GLViewer_Selector2d::GLViewer_Selector2d( GLViewer_Viewer2d* v2d, GLViewer_Context* glc ) :
37 GLViewer_Selector( v2d ),
40 // myGLContext->SetHighlightColor( Quantity_NOC_CYAN1 );
41 // myGLContext->SetSelectionColor( Quantity_NOC_RED );
47 GLViewer_Selector2d::~GLViewer_Selector2d()
52 Changes hilight color of context
53 \param color - new hilight color
55 void GLViewer_Selector2d::setHilightColor( Quantity_NameOfColor color )
57 myGLContext->SetHighlightColor( color );
61 Changes selection color of context
62 \param color - new selection color
64 void GLViewer_Selector2d::setSelectColor( Quantity_NameOfColor color )
66 myGLContext->SetSelectionColor( color );
70 Detects object at point
71 \param x, y - point co-ordinates
73 void GLViewer_Selector2d::detect( int x, int y )
75 //cout << "GLViewer_Selector2d : detect ( " << x << " , " << y << " )" << endl;
76 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
77 myViewer->getSelectionMode() == GLViewer_Viewer::NoSelection )
80 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
81 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
84 myGLContext->MoveTo( x, y );
90 void GLViewer_Selector2d::undetectAll()
92 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
93 myViewer->getSelectionMode() == GLViewer_Viewer::NoSelection )
96 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
97 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
100 myGLContext->clearHighlighted( true );
104 Selects previously hilighted objects
105 \param append - append objects to selection
107 void GLViewer_Selector2d::select( bool append )
109 //cout << "GLViewer_Selector2d : select ( " << (int)append << " )" << endl;
110 GLViewer_Viewer::SelectionMode selMode = myViewer->getSelectionMode();
111 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
112 selMode == GLViewer_Viewer::NoSelection )
115 int selBefore = numSelected();
116 if ( selBefore && append && selMode != GLViewer_Viewer::Multiple )
119 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
120 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
123 int status = myGLContext->Select( append );
124 checkSelection( selBefore, append, status );
128 Selects objects in rectangle
129 \param selRect - selection rectangle
130 \param append - append objects to selection
132 void GLViewer_Selector2d::select( const QRect& selRect, bool append )
134 GLViewer_Viewer::SelectionMode selMode = myViewer->getSelectionMode();
135 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
136 selMode == GLViewer_Viewer::NoSelection )
139 int selBefore = numSelected();
140 if ( selBefore && append && selMode != GLViewer_Viewer::Multiple )
143 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
144 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
147 int aStatus = myGLContext->SelectByRect( selRect, append );
148 checkSelection( selBefore, append, aStatus );
152 Unselects all objects
154 void GLViewer_Selector2d::unselectAll()
156 if ( myLocked || !myViewer )
159 // bool updateViewer = true;
160 bool hadSelection = ( numSelected() > 0 );
162 // bool lcOpen = ( myAISContext->IndexOfCurrentLocal() != -1 );
163 // lcOpen ? myAISContext->ClearSelected( updateViewer ) :
164 // myAISContext->ClearCurrent( updateViewer );
165 if ( hadSelection ) emit selSelectionCancel();
169 Checks selection state and emits 'selSelectionDone' or 'selSelectionCancel'
170 Should be called by after non-interactive selection.
172 void GLViewer_Selector2d::checkSelection( int selBefore, bool append, int aStatus )
174 int selAfter = numSelected();
175 if ( selBefore > 0 && selAfter < 1 )
176 emit selSelectionCancel();
177 else if ( selAfter > 0 )
181 case SS_LocalChanged:
182 emit selSelectionDone( selAfter > 1, SCS_Local );
184 case SS_GlobalChanged:
185 emit selSelectionDone( selAfter > 1, SCS_Global );
192 \return number of selected objects
194 int GLViewer_Selector2d::numSelected() const
196 return myGLContext->NbSelected();