Back to index

salome-gui  6.5.0
OCCViewer_AISSelector.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 #include "OCCViewer_AISSelector.h"
00024 
00028 OCCViewer_AISSelector::OCCViewer_AISSelector( QObject* parent, 
00029                                              const Handle (AIS_InteractiveContext)& aisContext) :
00030   QObject( parent ), 
00031   myNumSelected( 0 ), 
00032   myEnableSelection( true ),
00033   myEnableMultipleSelection( true )
00034 {
00035   myHilightColor = Quantity_NOC_CYAN1;
00036   mySelectColor  = Quantity_NOC_GRAY80;
00037 
00038   setAISContext( aisContext );
00039 }
00040 
00044 OCCViewer_AISSelector::~OCCViewer_AISSelector()
00045 {
00046 }
00047 
00051 void OCCViewer_AISSelector::enableSelection( bool bEnable )
00052 {
00053   myEnableSelection = bEnable;
00054 }
00055 
00060 void OCCViewer_AISSelector::enableMultipleSelection( bool bEnable )
00061 {
00062   myEnableMultipleSelection = bEnable;
00063   if ( bEnable ) myEnableSelection = bEnable;
00064 }
00065 
00069 void OCCViewer_AISSelector::setHilightColor ( Quantity_NameOfColor color )
00070 {
00071   myHilightColor = color;
00072   if ( !myAISContext.IsNull() )
00073     myAISContext->SetHilightColor( myHilightColor );
00074 }
00075 
00079 void OCCViewer_AISSelector::setSelectColor ( Quantity_NameOfColor color )
00080 {
00081   mySelectColor = color;
00082   if ( !myAISContext.IsNull() )
00083     myAISContext->SelectionColor( mySelectColor );
00084 }
00085 
00089 void OCCViewer_AISSelector::setAISContext ( const Handle (AIS_InteractiveContext)& aisContext )
00090 {
00091   myAISContext = aisContext;
00092   if ( ! myAISContext.IsNull() ) { 
00093     myAISContext->SetHilightColor( myHilightColor );
00094     myAISContext->SelectionColor( mySelectColor );
00095     myAISContext->SetSubIntensityColor( Quantity_NOC_CYAN1 );
00096   }
00097 }
00098 
00104 bool OCCViewer_AISSelector::checkSelection ( AIS_StatusOfPick status, 
00105                                              bool hadSelection, 
00106                                              bool addTo )
00107 {
00108   if ( myAISContext.IsNull() )
00109     return false;
00110 
00111   myNumSelected = myAISContext->NbCurrents(); /* update after the last selection */
00112   
00113   if ( status == AIS_SOP_NothingSelected && !hadSelection ) {
00114     emit selSelectionCancel( addTo );
00115   }
00116   else if ( status == AIS_SOP_NothingSelected && hadSelection ) {
00117     emit selSelectionCancel( addTo ); /* unselected now */
00118   }
00119   else if ( status == AIS_SOP_OneSelected || status == AIS_SOP_SeveralSelected )
00120   {
00121     emit selSelectionDone( addTo ); /* selected ( the same object, may be ) */
00122   }
00123   return ( status != AIS_SOP_Error && status != AIS_SOP_NothingSelected );
00124 }
00125 
00130 bool OCCViewer_AISSelector::moveTo ( int x, int y, const Handle (V3d_View)& view )
00131 {
00132   if ( myAISContext.IsNull() )
00133     return false;
00134 
00135   if ( !myEnableSelection )
00136     return false;
00137   
00138   AIS_StatusOfDetection status = AIS_SOD_Error;
00139   status = myAISContext->MoveTo (x, y, view);
00140   
00141   return ( status != AIS_SOD_Error && status != AIS_SOD_AllBad );
00142 }
00143 
00148 bool OCCViewer_AISSelector::select ()
00149 {
00150   if ( myAISContext.IsNull() )
00151     return false;
00152 
00153   if ( !myEnableSelection )
00154     return false;
00155   
00156   bool hadSelection = ( myNumSelected > 0 );
00157   
00158   /* select and send notifications */
00159   return checkSelection ( myAISContext->Select(), hadSelection, false );
00160 }
00161 
00167 bool OCCViewer_AISSelector::select ( int left, int top, int right, int bottom,
00168                                      const Handle (V3d_View)& view )
00169 {
00170   if ( myAISContext.IsNull() )
00171     return false;
00172 
00173   if ( !myEnableSelection || !myEnableMultipleSelection )
00174     return false;  /* selection with rectangle is considered as multiple selection */
00175   
00176   bool hadSelection = ( myNumSelected > 0 );
00177   
00178   /* select and send notifications */
00179   return checkSelection ( myAISContext->Select(left, top, right, bottom, view),
00180                           hadSelection, false );
00181 }
00182 
00188 bool OCCViewer_AISSelector::shiftSelect ()
00189 {
00190   if ( myAISContext.IsNull() )
00191     return false;
00192 
00193   if ( !myEnableSelection )
00194     return false;
00195   
00196   bool hadSelection = ( myNumSelected > 0 ); /* something was selected */
00197   if ( hadSelection && !myEnableMultipleSelection)
00198     return false;
00199   
00200   /* select and send notifications */
00201   return checkSelection ( myAISContext->ShiftSelect(), hadSelection, true );
00202 }
00203 
00210 bool OCCViewer_AISSelector::shiftSelect ( int left, int top, int right, int bottom,
00211                                          const Handle (V3d_View)& view )
00212                                          
00213 {
00214   if ( myAISContext.IsNull() )
00215     return false;
00216 
00217   if ( !myEnableSelection || !myEnableMultipleSelection )
00218     return false;  /* selection with rectangle is considered as multiple selection */
00219   
00220   bool hadSelection = ( myNumSelected > 0 );      /* something was selected */
00221   if ( hadSelection && !myEnableMultipleSelection)
00222     return false;
00223   
00224   /* select and send notifications */
00225   return checkSelection ( myAISContext->ShiftSelect(left,top,right,bottom, view),
00226     hadSelection, true );
00227 }