Version: 6.3.1

src/SMESHGUI/SMESHGUI_Preferences_ColorDlg.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_Preferences_ColorDlg.cxx
00025 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_Preferences_ColorDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_SpinBox.h"
00032 #include "SMESHGUI_Utils.h"
00033 
00034 // SALOME GUI includes
00035 #include <SUIT_Desktop.h>
00036 #include <SUIT_MessageBox.h>
00037 #include <SUIT_ResourceMgr.h>
00038 #include <SUIT_Session.h>
00039 #include <QtxColorButton.h>
00040 #include <VTKViewer_MarkerWidget.h>
00041 #include <LightApp_Application.h>
00042 #include <SalomeApp_IntSpinBox.h>
00043 
00044 // Qt includes
00045 #include <QGroupBox>
00046 #include <QLabel>
00047 #include <QPushButton>
00048 #include <QVBoxLayout>
00049 #include <QHBoxLayout>
00050 #include <QGridLayout>
00051 #include <QCheckBox>
00052 #include <QKeyEvent>
00053 
00054 #define SPACING 6
00055 #define MARGIN  11
00056 
00057 //=================================================================================
00058 // function : SMESHGUI_Preferences_ColorDlg()
00059 // purpose  : Constructs a SMESHGUI_Preferences_ColorDlg which is a child
00060 //            of 'parent', with the name 'name' and widget flags set to 'f'
00061 //            The dialog will by default be modeless, unless you
00062 //            set'modal' to true to construct a modal dialog.
00063 //=================================================================================
00064 SMESHGUI_Preferences_ColorDlg::SMESHGUI_Preferences_ColorDlg( SMESHGUI* theModule )
00065   : QDialog( SMESH::GetDesktop( theModule ) ),
00066     mySMESHGUI( theModule )
00067 {
00068   setModal( true );
00069   setWindowTitle( tr( "Preferences - Set Color" ) );
00070   setSizeGripEnabled( true );
00071 
00072   // -------------------------------
00073   QVBoxLayout* topLayout = new QVBoxLayout( this );
00074   topLayout->setSpacing( SPACING );
00075   topLayout->setMargin( MARGIN );
00076 
00077   // -------------------------------
00078   QGroupBox* ButtonGroup1 = new QGroupBox( tr( "Elements" ), this );
00079   QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1 );
00080   ButtonGroup1Layout->setSpacing( SPACING );
00081   ButtonGroup1Layout->setMargin( MARGIN );
00082 
00083   QLabel* TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1 );
00084   btnFillColor = new QtxColorButton( ButtonGroup1 );
00085 
00086   QLabel* TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1 );
00087   btnBackFaceColor = new QtxColorButton( ButtonGroup1 );
00088 
00089   QLabel* TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
00090   btnOutlineColor = new QtxColorButton( ButtonGroup1 );
00091 
00092   QLabel* TextLabel_0DElements_Color = new QLabel( tr( "0D elements" ), ButtonGroup1 );
00093   btn0DElementsColor = new QtxColorButton( ButtonGroup1 );
00094 
00095   QLabel* TextLabel_0DElements_Size = new QLabel( tr( "Size of 0D elements" ), ButtonGroup1 );
00096   SpinBox_0DElements_Size = new SalomeApp_IntSpinBox( ButtonGroup1 );
00097   SpinBox_0DElements_Size->setAcceptNames( false ); // No Notebook variables allowed
00098   SpinBox_0DElements_Size->setRange( 1, 10 );
00099   SpinBox_0DElements_Size->setSingleStep( 1 );
00100   SpinBox_0DElements_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00101   SpinBox_0DElements_Size->setButtonSymbols( QSpinBox::PlusMinus );
00102 
00103   QLabel* TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1 );
00104   SpinBox_Width = new SalomeApp_IntSpinBox( ButtonGroup1 );
00105   SpinBox_Width->setAcceptNames( false ); // No Notebook variables allowed
00106   SpinBox_Width->setRange( 0, 5 );
00107   SpinBox_Width->setSingleStep( 1 );
00108   SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00109   SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
00110 
00111   QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
00112   SpinBox_Shrink = new SalomeApp_IntSpinBox( ButtonGroup1 );
00113   SpinBox_Shrink->setAcceptNames( false ); // No Notebook variables allowed
00114   SpinBox_Shrink->setRange( 20, 100 );
00115   SpinBox_Shrink->setSingleStep( 1 );
00116   SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00117   SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
00118 
00119   ButtonGroup1Layout->addWidget( TextLabel_Fill,             0, 0 );
00120   ButtonGroup1Layout->addWidget( btnFillColor,               0, 1 );
00121   ButtonGroup1Layout->addWidget( TextLabel_BackFace,         0, 2 );
00122   ButtonGroup1Layout->addWidget( btnBackFaceColor,           0, 3 );
00123   ButtonGroup1Layout->addWidget( TextLabel_Outine,           1, 0 );
00124   ButtonGroup1Layout->addWidget( btnOutlineColor,            1, 1 );
00125   ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 1, 2 );
00126   ButtonGroup1Layout->addWidget( btn0DElementsColor,         1, 3 );
00127   ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size,  2, 0 );
00128   ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size,    2, 1 );
00129   ButtonGroup1Layout->addWidget( TextLabel_Width,            3, 0 );
00130   ButtonGroup1Layout->addWidget( SpinBox_Width,              3, 1 );
00131   ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff,      3, 2 );
00132   ButtonGroup1Layout->addWidget( SpinBox_Shrink,             3, 3 );
00133 
00134   // -------------------------------
00135   QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
00136   QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
00137   ButtonGroup2Layout->setSpacing( SPACING );
00138   ButtonGroup2Layout->setMargin( MARGIN );
00139 
00140   QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
00141   btnNodeColor = new QtxColorButton( ButtonGroup2 );
00142 
00143   QGroupBox* MarkerGroup = new QGroupBox( tr( "Marker" ), ButtonGroup2 );
00144   QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
00145   MarkerGroupLayout->setSpacing( 0 );
00146   MarkerGroupLayout->setMargin( 0 );
00147 
00148   MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
00149 
00150   MarkerGroupLayout->addWidget( MarkerWidget );
00151 
00152   ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
00153   ButtonGroup2Layout->addWidget( btnNodeColor,          0, 1 );
00154   ButtonGroup2Layout->addWidget( MarkerGroup,           1, 0, 1, 3 );
00155   ButtonGroup2Layout->setColumnStretch( 2, 1 );
00156 
00157   // -------------------------------
00158   QGroupBox* ButtonGroup3 = new QGroupBox( tr( "Orientation of faces" ), this );
00159   QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
00160   ButtonGroup3Layout->setSpacing( SPACING );
00161   ButtonGroup3Layout->setMargin( MARGIN );
00162 
00163   QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
00164   btnOrientationColor = new QtxColorButton( ButtonGroup3 );
00165 
00166   QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "Scale" ), ButtonGroup3 );
00167   SpinBox_Orientation_Scale = new SMESHGUI_SpinBox( ButtonGroup3 );
00168   SpinBox_Orientation_Scale->setAcceptNames( false ); // No Notebook variables allowed
00169   SpinBox_Orientation_Scale->RangeStepAndValidator( .05, .5, .05, "parametric_precision" );
00170   SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00171   SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
00172 
00173   CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
00174 
00175   ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color,    0, 0 );
00176   ButtonGroup3Layout->addWidget( btnOrientationColor,            0, 1 );
00177   ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale,    0, 2 );
00178   ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale,      0, 3 );
00179   ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
00180 
00181   // -------------------------------
00182   QGroupBox* GroupButtons = new QGroupBox( this );
00183   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
00184   GroupButtonsLayout->setSpacing( SPACING );
00185   GroupButtonsLayout->setMargin( MARGIN );
00186 
00187   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
00188   buttonOk->setAutoDefault( true );
00189   buttonOk->setDefault( true );
00190 
00191   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
00192   buttonCancel->setAutoDefault( true );
00193 
00194   QPushButton* buttonHelp = new QPushButton( tr( "&Help" ), GroupButtons );
00195   buttonHelp->setAutoDefault( true );
00196 
00197   GroupButtonsLayout->addWidget( buttonOk );
00198   GroupButtonsLayout->addSpacing( 10 );
00199   GroupButtonsLayout->addStretch();
00200   GroupButtonsLayout->addWidget( buttonCancel );
00201   GroupButtonsLayout->addWidget( buttonHelp );
00202 
00203   // -------------------------------
00204   topLayout->addWidget( ButtonGroup1 );
00205   topLayout->addWidget( ButtonGroup2 );
00206   topLayout->addWidget( ButtonGroup3 );
00207   topLayout->addWidget( GroupButtons );
00208 
00209   // -------------------------------
00210   mySMESHGUI->SetActiveDialogBox( this );
00211 
00212   myHelpFileName = "colors_size_page.html";
00213 
00214   /* signals and slots connections */
00215   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00216   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
00217   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
00218 
00219   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
00220            this,       SLOT( DeactivateActiveDialog() ) );
00221   /* to close dialog if study change */
00222   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
00223            this,       SLOT( ClickOnCancel() ) );
00224 }
00225 
00226 //=================================================================================
00227 // function : ~SMESHGUI_Preferences_ColorDlg()
00228 // purpose  : Destructor
00229 //=================================================================================
00230 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
00231 {
00232 }
00233 
00234 //=================================================================================
00235 // function : ClickOnOk()
00236 // purpose  :
00237 //=================================================================================
00238 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
00239 {
00240   mySMESHGUI->ResetState();
00241   accept();
00242 }
00243 
00244 //=================================================================================
00245 // function : ClickOnCancel()
00246 // purpose  :
00247 //=================================================================================
00248 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
00249 {
00250   mySMESHGUI->ResetState();
00251   reject();
00252 }
00253 
00254 //=================================================================================
00255 // function : ClickOnHelp()
00256 // purpose  :
00257 //=================================================================================
00258 void SMESHGUI_Preferences_ColorDlg::ClickOnHelp()
00259 {
00260   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00261   if (app) 
00262     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00263   else {
00264     QString platform;
00265 #ifdef WIN32
00266     platform = "winapplication";
00267 #else
00268     platform = "application";
00269 #endif
00270     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00271                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00272                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00273                                                                  platform)).
00274                              arg(myHelpFileName));
00275   }
00276 }
00277 
00278 //=================================================================================
00279 // function : DeactivateActiveDialog()
00280 // purpose  :
00281 //=================================================================================
00282 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
00283 {
00284 }
00285 
00286 //=================================================================================
00287 // function : closeEvent()
00288 // purpose  :
00289 //=================================================================================
00290 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
00291 {
00292   ClickOnCancel(); /* same than click on cancel button */
00293 }
00294 
00295 //=================================================================================
00296 // function : ActivateThisDialog()
00297 // purpose  :
00298 //=================================================================================
00299 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
00300 {
00301   /* Emit a signal to deactivate any active dialog */
00302   mySMESHGUI->EmitSignalDeactivateDialog();
00303 }
00304 
00305 //=================================================================================
00306 // function : SetColor()
00307 // purpose  :
00308 //=================================================================================
00309 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
00310 {
00311   switch ( type ) {
00312   case 1 : btnFillColor->setColor( color );        break; // fill
00313   case 2 : btnOutlineColor->setColor( color );     break; // outline
00314   case 3 : btnNodeColor->setColor( color );        break; // node
00315   case 4 : btnBackFaceColor->setColor( color );    break; // back face
00316   case 5 : btn0DElementsColor->setColor( color );  break; // 0d elements
00317   case 6 : btnOrientationColor->setColor( color ); break; // orientation of faces
00318   default: break;
00319   }
00320 }
00321 
00322 //=================================================================================
00323 // function : GetColor()
00324 // purpose  :
00325 //=================================================================================
00326 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
00327 {
00328   QColor color;
00329   switch ( type ) {
00330   case 1 : color = btnFillColor->color();        break; // fill
00331   case 2 : color = btnOutlineColor->color();     break; // outline
00332   case 3 : color = btnNodeColor->color();        break; // node
00333   case 4 : color = btnBackFaceColor->color();    break; // back face
00334   case 5 : color = btn0DElementsColor->color();  break; // 0d elements
00335   case 6 : color = btnOrientationColor->color(); break; // orientation of faces
00336   default: break;
00337   }
00338   return color;
00339 }
00340 
00341 //=================================================================================
00342 // function : SetIntValue()
00343 // purpose  :
00344 //=================================================================================
00345 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
00346 {
00347   switch ( type ) {
00348   case 1 : SpinBox_Width->setValue( value );           break; // width
00349   case 2 : SpinBox_Shrink->setValue( value );          break; // shrink coeff
00350   case 3 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
00351   default: break;
00352   }
00353 }
00354 
00355 //=================================================================================
00356 // function : GetIntValue()
00357 // purpose  :
00358 //=================================================================================
00359 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
00360 {
00361   int res = 0;
00362   switch ( type ) {
00363   case 1 : res = SpinBox_Width->value();           break; // width
00364   case 2 : res = SpinBox_Shrink->value();          break; // shrink coeff
00365   case 3 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
00366   default: break;
00367   }
00368   return res;
00369 }
00370 
00371 //=================================================================================
00372 // function : SetDoubleValue()
00373 // purpose  :
00374 //=================================================================================
00375 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
00376 {
00377   switch ( type ) {
00378   case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
00379   default: break;
00380   }
00381 }
00382 
00383 //=================================================================================
00384 // function : GetDoubleValue()
00385 // purpose  :
00386 //=================================================================================
00387 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
00388 {
00389   double res = 0;
00390   switch ( type ) {
00391   case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
00392   default: break;
00393   }
00394   return res;
00395 }
00396 
00397 //=================================================================================
00398 // function : SetBooleanValue()
00399 // purpose  :
00400 //=================================================================================
00401 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
00402 {
00403   switch ( type ) {
00404   case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
00405   default: break;
00406   }
00407 }
00408 
00409 //=================================================================================
00410 // function : GetBooleanValue()
00411 // purpose  :
00412 //=================================================================================
00413 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
00414 {
00415   bool res = false;
00416   switch ( type ) {
00417   case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
00418   default: break;
00419   }
00420   return res;
00421 }
00422 
00423 //=================================================================================
00424 // function : setCustomMarkerMap()
00425 // purpose  :
00426 //=================================================================================
00427 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
00428 {
00429   MarkerWidget->setCustomMarkerMap( theMarkerMap );
00430 }
00431 
00432 //=================================================================================
00433 // function : getCustomMarkerMap()
00434 // purpose  :
00435 //=================================================================================
00436 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
00437 {
00438   return MarkerWidget->getCustomMarkerMap();
00439 }
00440 
00441 //=================================================================================
00442 // function : setStandardMarker()
00443 // purpose  :
00444 //=================================================================================
00445 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
00446                                                        VTK::MarkerScale theMarkerScale )
00447 {
00448   MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
00449 }
00450 
00451 //=================================================================================
00452 // function : setCustomMarker()
00453 // purpose  :
00454 //=================================================================================
00455 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
00456 {
00457   MarkerWidget->setCustomMarker( theId );
00458 }
00459 
00460 //=================================================================================
00461 // function : getMarkerType()
00462 // purpose  :
00463 //=================================================================================
00464 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
00465 {
00466   return MarkerWidget->getMarkerType();
00467 }
00468 
00469 //=================================================================================
00470 // function : getStandardMarkerScale()
00471 // purpose  :
00472 //=================================================================================
00473 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
00474 {
00475   return MarkerWidget->getStandardMarkerScale();
00476 }
00477 
00478 //=================================================================================
00479 // function : getCustomMarkerID()
00480 // purpose  :
00481 //=================================================================================
00482 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
00483 {
00484   return MarkerWidget->getCustomMarkerID();
00485 }
00486 
00487 //=================================================================================
00488 // function : keyPressEvent()
00489 // purpose  :
00490 //=================================================================================
00491 void SMESHGUI_Preferences_ColorDlg::keyPressEvent( QKeyEvent* e )
00492 {
00493   QDialog::keyPressEvent( e );
00494   if ( e->isAccepted() )
00495     return;
00496 
00497   if ( e->key() == Qt::Key_F1 ) {
00498     e->accept();
00499     ClickOnHelp();
00500   }
00501 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS