1 // Copyright (C) 2005 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.
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
19 // Author : OPEN CASCADE
22 // File: GLViewer_Selector2d.cxx
23 // Created: November, 2004
25 //#include <GLViewerAfx.h>
26 #include "GLViewer_Selector2d.h"
27 #include "GLViewer_Viewer2d.h"
28 #include "GLViewer_Context.h"
29 #include "GLViewer_ViewPort2d.h"
34 GLViewer_Selector2d::GLViewer_Selector2d( GLViewer_Viewer2d* v2d, GLViewer_Context* glc ) :
35 GLViewer_Selector( v2d ),
38 // myGLContext->SetHighlightColor( Quantity_NOC_CYAN1 );
39 // myGLContext->SetSelectionColor( Quantity_NOC_RED );
45 GLViewer_Selector2d::~GLViewer_Selector2d()
50 Changes hilight color of context
51 \param color - new hilight color
53 void GLViewer_Selector2d::setHilightColor( Quantity_NameOfColor color )
55 myGLContext->SetHighlightColor( color );
59 Changes selection color of context
60 \param color - new selection color
62 void GLViewer_Selector2d::setSelectColor( Quantity_NameOfColor color )
64 myGLContext->SetSelectionColor( color );
68 Detects object at point
69 \param x, y - point co-ordinates
71 void GLViewer_Selector2d::detect( int x, int y )
73 //cout << "GLViewer_Selector2d : detect ( " << x << " , " << y << " )" << endl;
74 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
75 myViewer->getSelectionMode() == GLViewer_Viewer::NoSelection )
78 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
79 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
82 myGLContext->MoveTo( x, y );
88 void GLViewer_Selector2d::undetectAll()
90 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
91 myViewer->getSelectionMode() == GLViewer_Viewer::NoSelection )
94 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
95 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
98 myGLContext->clearHighlighted( true );
102 Selects previously hilighted objects
103 \param append - append objects to selection
105 void GLViewer_Selector2d::select( bool append )
107 //cout << "GLViewer_Selector2d : select ( " << (int)append << " )" << endl;
108 GLViewer_Viewer::SelectionMode selMode = myViewer->getSelectionMode();
109 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
110 selMode == GLViewer_Viewer::NoSelection )
113 int selBefore = numSelected();
114 if ( selBefore && append && selMode != GLViewer_Viewer::Multiple )
117 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
118 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
121 int status = myGLContext->Select( append );
122 checkSelection( selBefore, append, status );
126 Selects objects in rectangle
127 \param selRect - selection rectangle
128 \param append - append objects to selection
130 void GLViewer_Selector2d::select( const QRect& selRect, bool append )
132 GLViewer_Viewer::SelectionMode selMode = myViewer->getSelectionMode();
133 if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
134 selMode == GLViewer_Viewer::NoSelection )
137 int selBefore = numSelected();
138 if ( selBefore && append && selMode != GLViewer_Viewer::Multiple )
141 GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
142 if( !vp->inherits( "GLViewer_ViewPort2d" ) )
145 int aStatus = myGLContext->SelectByRect( selRect, append );
146 checkSelection( selBefore, append, aStatus );
150 Unselects all objects
152 void GLViewer_Selector2d::unselectAll()
154 if ( myLocked || !myViewer )
157 // bool updateViewer = true;
158 bool hadSelection = ( numSelected() > 0 );
160 // bool lcOpen = ( myAISContext->IndexOfCurrentLocal() != -1 );
161 // lcOpen ? myAISContext->ClearSelected( updateViewer ) :
162 // myAISContext->ClearCurrent( updateViewer );
163 if ( hadSelection ) emit selSelectionCancel();
167 Checks selection state and emits 'selSelectionDone' or 'selSelectionCancel'
168 Should be called by after non-interactive selection.
170 void GLViewer_Selector2d::checkSelection( int selBefore, bool append, int aStatus )
172 int selAfter = numSelected();
173 if ( selBefore > 0 && selAfter < 1 )
174 emit selSelectionCancel();
175 else if ( selAfter > 0 )
179 case SS_LocalChanged:
180 emit selSelectionDone( selAfter > 1, SCS_Local );
182 case SS_GlobalChanged:
183 emit selSelectionDone( selAfter > 1, SCS_Global );
190 \return number of selected objects
192 int GLViewer_Selector2d::numSelected() const
194 return myGLContext->NbSelected();