Back to index

salome-gui  6.5.0
GLViewer_Selector2d.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  Author : OPEN CASCADE
00024 // File:      GLViewer_Selector2d.cxx
00025 // Created:   November, 2004
00026 //#include <GLViewerAfx.h>
00027 //
00028 #include "GLViewer_Selector2d.h"
00029 #include "GLViewer_Viewer2d.h"
00030 #include "GLViewer_Context.h"
00031 #include "GLViewer_ViewPort.h"
00032 #include "GLViewer_ViewFrame.h"
00033 
00037 GLViewer_Selector2d::GLViewer_Selector2d( GLViewer_Viewer2d* v2d, GLViewer_Context* glc ) :
00038 GLViewer_Selector( v2d ),
00039 myGLContext( glc )
00040 {   
00041 //  myGLContext->SetHighlightColor( Quantity_NOC_CYAN1 );
00042 //  myGLContext->SetSelectionColor( Quantity_NOC_RED );
00043 }
00044 
00048 GLViewer_Selector2d::~GLViewer_Selector2d()
00049 {
00050 }
00051 
00056 void GLViewer_Selector2d::setHilightColor( Quantity_NameOfColor color )
00057 {
00058   myGLContext->SetHighlightColor( color );
00059 }
00060 
00065 void GLViewer_Selector2d::setSelectColor( Quantity_NameOfColor color )
00066 {
00067   myGLContext->SetSelectionColor( color );
00068 }
00069 
00074 void GLViewer_Selector2d::detect( int x, int y )
00075 {
00076   //cout << "GLViewer_Selector2d    : detect ( " << x << " , " << y << " )" << endl;
00077   if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() || 
00078        myViewer->getSelectionMode() == GLViewer_Viewer::NoSelection )
00079     return;
00080 
00081   GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
00082   if( !vp->inherits( "GLViewer_ViewPort2d" ) )
00083     return;
00084 
00085   myGLContext->MoveTo( x, y );
00086 }
00087 
00091 void GLViewer_Selector2d::undetectAll()
00092 {
00093   if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() || 
00094        myViewer->getSelectionMode() == GLViewer_Viewer::NoSelection )
00095     return;
00096 
00097   GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
00098   if( !vp->inherits( "GLViewer_ViewPort2d" ) )
00099     return;
00100 
00101   myGLContext->clearHighlighted( true );
00102 }
00103 
00108 void GLViewer_Selector2d::select( bool append )
00109 {
00110   //cout << "GLViewer_Selector2d    : select ( " << (int)append << " )" << endl;
00111   GLViewer_Viewer::SelectionMode selMode = myViewer->getSelectionMode();
00112   if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
00113        selMode == GLViewer_Viewer::NoSelection ) 
00114     return;
00115 
00116   int selBefore = numSelected();
00117   if ( selBefore && append && selMode != GLViewer_Viewer::Multiple )
00118     return;    
00119 
00120   GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
00121   if( !vp->inherits( "GLViewer_ViewPort2d" ) )
00122       return;
00123 
00124   int status = myGLContext->Select( append );
00125   checkSelection( selBefore, append, status );
00126 }
00127 
00133 void GLViewer_Selector2d::select( const QRect& selRect, bool append )
00134 {
00135     GLViewer_Viewer::SelectionMode selMode = myViewer->getSelectionMode();
00136     if ( myLocked || !myGLContext || !myViewer || !myViewer->getActiveView() ||
00137        selMode == GLViewer_Viewer::NoSelection ) 
00138     return;
00139 
00140     int selBefore = numSelected();
00141     if ( selBefore && append && selMode != GLViewer_Viewer::Multiple )
00142         return;    
00143 
00144     GLViewer_ViewPort* vp = myViewer->getActiveView()->getViewPort();
00145     if( !vp->inherits( "GLViewer_ViewPort2d" ) )
00146         return;
00147 
00148     int aStatus = myGLContext->SelectByRect( selRect, append );
00149     checkSelection( selBefore, append, aStatus );
00150 }
00151 
00155 void GLViewer_Selector2d::unselectAll()
00156 {
00157   if ( myLocked || !myViewer ) 
00158     return;
00159 
00160 //  bool updateViewer = true;
00161   bool hadSelection = ( numSelected() > 0 );
00162      
00163 //     bool lcOpen = ( myAISContext->IndexOfCurrentLocal() != -1 );
00164 //     lcOpen ? myAISContext->ClearSelected( updateViewer ) :    
00165 //              myAISContext->ClearCurrent( updateViewer );     
00166   if ( hadSelection ) emit selSelectionCancel();
00167 }
00168 
00173 void GLViewer_Selector2d::checkSelection( int selBefore, bool append, int aStatus )
00174 {
00175     int selAfter = numSelected();
00176     if ( selBefore > 0 && selAfter < 1 )     
00177         emit selSelectionCancel();
00178     else if ( selAfter > 0 )
00179     {
00180         switch( aStatus )
00181         {
00182         case SS_LocalChanged:
00183             emit selSelectionDone( selAfter > 1, SCS_Local );
00184             break;
00185         case SS_GlobalChanged:
00186             emit selSelectionDone( selAfter > 1, SCS_Global );
00187             break;
00188         }
00189     }
00190 }
00191 
00195 int GLViewer_Selector2d::numSelected() const
00196 {
00197   return myGLContext->NbSelected();
00198 }
00199