Back to index

salome-smesh  6.5.0
SMESHGUI_Preferences_ScalarBarDlg.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 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_Preferences_ScalarBarDlg.cxx
00025 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_SpinBox.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_Utils.h"
00034 
00035 #include <SMESH_Actor.h>
00036 #include <SMESH_ActorUtils.h>
00037 #include <SMESH_ScalarBarActor.h>
00038 #include <SMESH_ControlsDef.hxx>
00039 
00040 // SALOME GUI includes
00041 #include <SUIT_Desktop.h>
00042 #include <SUIT_ResourceMgr.h>
00043 #include <SUIT_Session.h>
00044 #include <SUIT_MessageBox.h>
00045 
00046 #include <LightApp_Application.h>
00047 #include <LightApp_SelectionMgr.h>
00048 #include <SALOME_ListIO.hxx>
00049 #include <SalomeApp_IntSpinBox.h>
00050 
00051 #include <QtxColorButton.h>
00052 
00053 // Qt includes
00054 #include <QButtonGroup>
00055 #include <QCheckBox>
00056 #include <QComboBox>
00057 #include <QGroupBox>
00058 #include <QLabel>
00059 #include <QLineEdit>
00060 #include <QPushButton>
00061 #include <QRadioButton>
00062 #include <QHBoxLayout>
00063 #include <QVBoxLayout>
00064 #include <QGridLayout>
00065 #include <QDoubleValidator>
00066 
00067 // VTK includes
00068 #include <vtkTextProperty.h>
00069 #include <vtkLookupTable.h>
00070 
00071 #define MINIMUM_WIDTH 70
00072 #define MARGIN_SIZE   11
00073 #define SPACING_SIZE   6
00074 
00075 // Only one instance is allowed
00076 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
00077 
00078 //=================================================================================================
00084 //=================================================================================================
00085 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
00086 {
00087   if (!myDlg) {
00088     myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule );
00089     myDlg->show();
00090   } else {
00091     myDlg->show();
00092     myDlg->raise();
00093     myDlg->activateWindow();
00094   }
00095 }
00096 
00097 //=================================================================================================
00103 //=================================================================================================
00104 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule )
00105   : QDialog( SMESH::GetDesktop( theModule ) ),
00106     mySMESHGUI( theModule ),
00107     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
00108 {
00109   DEF_VER_X = 0.01;
00110   DEF_VER_Y = 0.10;
00111   DEF_VER_H = 0.80;
00112   DEF_VER_W = 0.10;
00113   DEF_HOR_X = 0.20;
00114   DEF_HOR_Y = 0.01;
00115   DEF_HOR_H = 0.12;
00116   DEF_HOR_W = 0.60;
00117 
00118   setModal( false );
00119   setAttribute( Qt::WA_DeleteOnClose, true );
00120   setWindowTitle( tr("SMESH_PROPERTIES_SCALARBAR") );
00121   setSizeGripEnabled(true);
00122 
00123   myActor = 0;
00124 
00125   /******************************************************************************/
00126   // Top layout
00127   QVBoxLayout* aTopLayout = new QVBoxLayout( this );
00128   aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
00129 
00130   /******************************************************************************/
00131   // Scalar range
00132   myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this );
00133   QHBoxLayout* myRangeGrpLayout = new QHBoxLayout( myRangeGrp );
00134   myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
00135   
00136   myMinEdit = new QLineEdit( myRangeGrp );
00137   myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
00138   myMinEdit->setValidator( new QDoubleValidator( this ) );
00139   
00140   myMaxEdit = new QLineEdit( myRangeGrp );
00141   myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
00142   myMaxEdit->setValidator( new QDoubleValidator( this ) );
00143   
00144   myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp ) );
00145   myRangeGrpLayout->addWidget( myMinEdit );
00146   myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp ) );
00147   myRangeGrpLayout->addWidget( myMaxEdit );
00148   
00149   aTopLayout->addWidget( myRangeGrp );
00150 
00151   /******************************************************************************/
00152   // Text properties
00153   myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this  );
00154   QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp );
00155   myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
00156 
00157   myTitleColorBtn = new QtxColorButton( myFontGrp  );
00158 
00159   myTitleFontCombo = new QComboBox( myFontGrp );
00160   myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
00161   myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00162   myTitleFontCombo->addItem( tr( "SMESH_FONT_ARIAL" ) );
00163   myTitleFontCombo->addItem( tr( "SMESH_FONT_COURIER" ) );
00164   myTitleFontCombo->addItem( tr( "SMESH_FONT_TIMES" ) );
00165 
00166   myTitleBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp );
00167   myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp );
00168   myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp );
00169 
00170   myLabelsColorBtn = new QtxColorButton( myFontGrp );
00171 
00172   myLabelsFontCombo = new QComboBox( myFontGrp );
00173   myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
00174   myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00175   myLabelsFontCombo->addItem( tr( "SMESH_FONT_ARIAL" ) );
00176   myLabelsFontCombo->addItem( tr( "SMESH_FONT_COURIER" ) );
00177   myLabelsFontCombo->addItem( tr( "SMESH_FONT_TIMES" ) );
00178 
00179   myLabelsBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp );
00180   myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp );
00181   myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp );
00182 
00183   myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp ), 0, 0 );
00184   myFontGrpLayout->addWidget( myTitleColorBtn,    0, 1 );
00185   myFontGrpLayout->addWidget( myTitleFontCombo,   0, 2 );
00186   myFontGrpLayout->addWidget( myTitleBoldCheck,   0, 3 );
00187   myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
00188   myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
00189 
00190   myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp ), 1, 0 );
00191   myFontGrpLayout->addWidget( myLabelsColorBtn,    1, 1 );
00192   myFontGrpLayout->addWidget( myLabelsFontCombo,   1, 2 );
00193   myFontGrpLayout->addWidget( myLabelsBoldCheck,   1, 3 );
00194   myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
00195   myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
00196 
00197   aTopLayout->addWidget( myFontGrp );
00198 
00199   /******************************************************************************/
00200   // Labels & Colors
00201   myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this );
00202   QHBoxLayout* myLabColorGrpLayout = new QHBoxLayout( myLabColorGrp );
00203   myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
00204 
00205   myColorsSpin = new SalomeApp_IntSpinBox( myLabColorGrp );
00206   myColorsSpin->setAcceptNames( false ); // No Notebook variables allowed
00207   myColorsSpin->setRange( 2, 256 );
00208   myColorsSpin->setSingleStep( 1 );
00209   myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
00210   myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00211 
00212   myLabelsSpin = new SalomeApp_IntSpinBox( myLabColorGrp );
00213   myLabelsSpin->setAcceptNames( false ); // No Notebook variables allowed
00214   myLabelsSpin->setRange( 2, 65 );
00215   myLabelsSpin->setSingleStep( 1 );
00216   myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
00217   myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00218 
00219   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp ) );
00220   myLabColorGrpLayout->addWidget( myColorsSpin );
00221   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp ) );
00222   myLabColorGrpLayout->addWidget( myLabelsSpin );
00223 
00224   aTopLayout->addWidget( myLabColorGrp );
00225 
00226   /******************************************************************************/
00227   // Orientation
00228   myOrientationGrp = new QGroupBox ( tr( "SMESH_ORIENTATION" ), this );
00229   QButtonGroup* aOrientationGrp = new QButtonGroup( this );
00230   QHBoxLayout* myOrientationGrpLayout = new QHBoxLayout( myOrientationGrp );
00231   myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
00232 
00233   myVertRadioBtn  = new QRadioButton( tr( "SMESH_VERTICAL" ),   myOrientationGrp );
00234   myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp );
00235   myVertRadioBtn->setChecked( true );
00236 
00237   myOrientationGrpLayout->addWidget( myVertRadioBtn );
00238   myOrientationGrpLayout->addWidget( myHorizRadioBtn );
00239   aOrientationGrp->addButton(myVertRadioBtn);
00240   aOrientationGrp->addButton(myHorizRadioBtn);
00241 
00242   aTopLayout->addWidget( myOrientationGrp );
00243 
00244   /******************************************************************************/
00245   // Position & Size
00246   myOriginDimGrp = new QGroupBox ( tr("SMESH_POSITION_SIZE_SCALARBAR"), this );
00247   QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp );
00248   myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
00249 
00250   myXSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
00251   myXSpin->setAcceptNames( false );
00252   myXSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );
00253   myXSpin->setMinimumWidth( MINIMUM_WIDTH );
00254   myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00255 
00256   myYSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
00257   myYSpin->setAcceptNames( false );
00258   myYSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );  
00259   myYSpin->setMinimumWidth( MINIMUM_WIDTH );
00260   myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00261 
00262   myWidthSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
00263   myWidthSpin->setAcceptNames( false );
00264   myWidthSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );    
00265   myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
00266   myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00267 
00268   myHeightSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
00269   myHeightSpin->setAcceptNames( false );
00270   myHeightSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );    
00271   myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
00272   myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00273 
00274   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp ), 0, 0 );
00275   myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
00276   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp ), 0, 2 );
00277   myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
00278   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ),  myOriginDimGrp ),  1, 0 );
00279   myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
00280   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp ), 1, 2 );
00281   myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
00282 
00283   aTopLayout->addWidget( myOriginDimGrp );
00284   /******************************************************************************/
00285 
00286   // Destribution
00287   myDistributionGrp = new QGroupBox ( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), this );
00288   myDistributionGrp->setCheckable(true);
00289   QHBoxLayout* aDistributionGrpLayout = new QHBoxLayout( myDistributionGrp );
00290   aDistributionGrpLayout->setSpacing( SPACING_SIZE ); aDistributionGrpLayout->setMargin( MARGIN_SIZE );
00291 
00292   myDistribColorGrp = new QButtonGroup( this );
00293 
00294   myDMonoColor  = new QRadioButton( tr( "SMESH_MONOCOLOR" ) ,  myDistributionGrp );
00295   myDMultiColor = new QRadioButton( tr( "SMESH_MULTICOLOR" ),  myDistributionGrp );
00296   myDMonoColor->setChecked( true );
00297 
00298   myDistribColorGrp->addButton(myDMonoColor);myDistribColorGrp->setId(myDMonoColor,1);
00299   myDistribColorGrp->addButton(myDMultiColor);myDistribColorGrp->setId(myDMultiColor,2);
00300   
00301   aDistributionGrpLayout->addWidget( myDMultiColor );
00302   aDistributionGrpLayout->addWidget( myDMonoColor );
00303   
00304   //Color of the Distribution in monocolor case:
00305   myDistributionColorLbl = new QLabel( tr( "SMESH_DISTRIBUTION_COLOR" ), myDistributionGrp );
00306   aDistributionGrpLayout->addWidget( myDistributionColorLbl );
00307   myMonoColorBtn = new QtxColorButton( myDistributionGrp  );
00308   aDistributionGrpLayout->addWidget(myMonoColorBtn);
00309   
00310   aTopLayout->addWidget(myDistributionGrp);
00311   
00312   /******************************************************************************/
00313   // Common buttons
00314   myButtonGrp = new QGroupBox( this );
00315   QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp );
00316   myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
00317 
00318   myOkBtn = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), myButtonGrp );
00319   myOkBtn->setAutoDefault( true ); myOkBtn->setDefault( true );
00320   myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp );
00321   myApplyBtn->setAutoDefault( true );
00322   myCancelBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), myButtonGrp );
00323   myCancelBtn->setAutoDefault( true );
00324   myHelpBtn = new QPushButton( tr("SMESH_BUT_HELP"), myButtonGrp );
00325   myHelpBtn->setAutoDefault(true);
00326 
00327   myButtonGrpLayout->addWidget( myOkBtn );
00328   myButtonGrpLayout->addSpacing( 10 );
00329   myButtonGrpLayout->addWidget( myApplyBtn );
00330   myButtonGrpLayout->addSpacing( 10 );
00331   myButtonGrpLayout->addStretch();
00332   myButtonGrpLayout->addWidget( myCancelBtn );
00333   myButtonGrpLayout->addWidget( myHelpBtn );
00334 
00335   aTopLayout->addWidget( myButtonGrp );
00336 
00337   /***************************************************************/
00338   // Init
00339   // --> first init from preferences
00340   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
00341 
00342   QColor titleColor = mgr->colorValue("SMESH", "scalar_bar_title_color",
00343                                       QColor(255, 255, 255));
00344   myTitleColorBtn->setColor(titleColor);
00345   myTitleFontCombo->setCurrentIndex(0);
00346   if (mgr->hasValue("SMESH", "scalar_bar_title_font")) {
00347     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
00348     if( f.family()=="Arial" )
00349       myTitleFontCombo->setCurrentIndex(0);
00350     if( f.family()=="Courier" )
00351       myTitleFontCombo->setCurrentIndex(1);
00352     if( f.family()=="Times")
00353       myTitleFontCombo->setCurrentIndex(2);
00354     
00355     myTitleBoldCheck->setChecked  ( f.bold() );
00356     myTitleItalicCheck->setChecked( f.italic() );
00357     myTitleShadowCheck->setChecked( f.overline() );
00358   }
00359                                       
00360   QColor labelColor = mgr->colorValue("SMESH", "scalar_bar_label_color", 
00361                                       QColor(255, 255, 255));
00362   myLabelsColorBtn->setColor(labelColor);
00363   myLabelsFontCombo->setCurrentIndex(0);
00364   if (mgr->hasValue("SMESH", "scalar_bar_label_font")) {
00365     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
00366     if (f.family() == "Arial")
00367       myLabelsFontCombo->setCurrentIndex(0);
00368     if (f.family() == "Courier")
00369       myLabelsFontCombo->setCurrentIndex(1);
00370     if (f.family() == "Times")
00371       myLabelsFontCombo->setCurrentIndex(2);
00372       
00373     myLabelsBoldCheck  ->setChecked( f.bold() );
00374     myLabelsItalicCheck->setChecked( f.italic() );
00375     myLabelsShadowCheck->setChecked( f.overline() );
00376   }
00377 
00378   int aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors", 64);
00379   myColorsSpin->setValue(aNbColors);
00380 
00381   int aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels", 5);
00382   myLabelsSpin->setValue(aNbLabels);
00383 
00384   int aOrientation = mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 );
00385   bool isHoriz = aOrientation == 1;
00386   if (isHoriz)
00387     myHorizRadioBtn->setChecked(true);
00388   else
00389     myVertRadioBtn->setChecked(true);
00390   myIniOrientation = myVertRadioBtn->isChecked();
00391 
00392   QString name = isHoriz ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
00393 
00394   myIniX = mgr->doubleValue("SMESH", name.arg( "x" ), 
00395                             myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X);
00396 
00397   myIniY = mgr->doubleValue("SMESH", name.arg( "y" ),
00398                             myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y);
00399 
00400   myIniW = mgr->doubleValue("SMESH", name.arg( "width" ),
00401                             myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W);
00402 
00403   myIniH = mgr->doubleValue("SMESH", name.arg( "height" ),
00404                             myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H);
00405 
00406   setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
00407 
00408 
00409   bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
00410   myDistributionGrp->setChecked(distributionVisibility);
00411 
00412   int coloringType = mgr->integerValue("SMESH", "distribution_coloring_type", 0);
00413   if( coloringType == SMESH_MONOCOLOR_TYPE ) {
00414     myDMonoColor->setChecked(true);
00415     onDistributionChanged(myDistribColorGrp->id(myDMonoColor));    
00416   } else {
00417     myDMultiColor->setChecked(true);
00418     onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
00419 
00420   }
00421   
00422   QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
00423                                              QColor(255, 255, 255));
00424   myMonoColorBtn->setColor(distributionColor);
00425   
00426   
00427 
00428   // --> then init from selection if necessary
00429   onSelectionChanged();
00430 
00431   /***************************************************************/
00432   // Connect section
00433   connect( myOkBtn,             SIGNAL( clicked() ), this, SLOT( onOk() ) );
00434   connect( myApplyBtn,          SIGNAL( clicked() ), this, SLOT( onApply() ) );
00435   connect( myCancelBtn,         SIGNAL( clicked() ), this, SLOT( onCancel() ) );
00436   connect( myHelpBtn,           SIGNAL(clicked()),   this, SLOT( onHelp() ) );
00437   connect( myXSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
00438   connect( myYSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
00439   connect( aOrientationGrp,     SIGNAL( buttonClicked( int ) ),   this, SLOT( onOrientationChanged() ) );
00440   connect( myDistributionGrp,   SIGNAL( toggled(bool) ), this, SLOT(onDistributionActivated(bool)) );
00441   connect( myDistribColorGrp,   SIGNAL( buttonClicked( int ) ),   this, SLOT( onDistributionChanged( int ) ) );
00442   connect( mySelectionMgr,      SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
00443   connect( mySMESHGUI,          SIGNAL( SignalCloseAllDialogs() ),   this, SLOT( onCancel() ) );
00444 
00445   myHelpFileName = "quality_page.html";
00446 }
00447 
00448 //=================================================================================================
00454 //=================================================================================================
00455 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
00456 {
00457 }
00458 
00459 //=================================================================================================
00465 //=================================================================================================
00466 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
00467 {
00468   if ( onApply() )
00469     onCancel();
00470 }
00471 
00472 //=================================================================================================
00478 //=================================================================================================
00479 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
00480 {
00481   // Scalar Bar properties
00482   if (!myActor)
00483     return false;
00484   SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
00485 
00486   vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
00487   QColor aTColor = myTitleColorBtn->color();
00488   aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
00489   if ( myTitleFontCombo->currentIndex() == 0 )
00490     aTitleTextPrp->SetFontFamilyToArial();
00491   else if ( myTitleFontCombo->currentIndex() == 1 )
00492     aTitleTextPrp->SetFontFamilyToCourier();
00493   else
00494     aTitleTextPrp->SetFontFamilyToTimes();
00495   aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
00496   aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
00497   aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
00498   myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
00499 
00500   vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
00501   QColor aLColor = myLabelsColorBtn->color();
00502   aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
00503   if ( myLabelsFontCombo->currentIndex() == 0 )
00504     aLabelsTextPrp->SetFontFamilyToArial();
00505   else if ( myLabelsFontCombo->currentIndex() == 1 )
00506     aLabelsTextPrp->SetFontFamilyToCourier();
00507   else
00508     aLabelsTextPrp->SetFontFamilyToTimes();
00509   aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
00510   aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
00511   aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
00512   myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
00513 
00514   myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
00515 
00516   if ( myHorizRadioBtn->isChecked() )
00517     myScalarBarActor->SetOrientationToHorizontal();
00518   else
00519     myScalarBarActor->SetOrientationToVertical();
00520 
00521   myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
00522   myScalarBarActor->SetWidth( myWidthSpin->value() );
00523   myScalarBarActor->SetHeight( myHeightSpin->value() );
00524 
00525   // Distribution
00526   bool distributionTypeChanged = false, colorChanged=false;
00527   myScalarBarActor->SetDistributionVisibility((int)myDistributionGrp->isChecked());
00528   if( myDistributionGrp->isChecked() ) {
00529     int ColoringType = myDMultiColor->isChecked() ? SMESH_MULTICOLOR_TYPE : SMESH_MONOCOLOR_TYPE;
00530     distributionTypeChanged = (ColoringType != myScalarBarActor->GetDistributionColoringType());
00531     if(distributionTypeChanged)      
00532       myScalarBarActor->SetDistributionColoringType(ColoringType);
00533     
00534     if( !myDMultiColor->isChecked() ) {
00535       QColor aTColor = myMonoColorBtn->color();
00536       double rgb[3], oldRgb[3];;
00537       rgb [0] = aTColor.red()/255.;
00538       rgb [1] = aTColor.green()/255.;
00539       rgb [2] = aTColor.blue()/255.;
00540       myScalarBarActor->GetDistributionColor(oldRgb);
00541       colorChanged = (rgb[0] != oldRgb[0] || rgb[1] != oldRgb[1] || rgb[2] != oldRgb[2]);
00542       if(colorChanged)
00543         myScalarBarActor->SetDistributionColor(rgb);
00544     }
00545   }
00546 
00547   double aMin = myMinEdit->text().toDouble();
00548   double aMax = myMaxEdit->text().toDouble();
00549   vtkLookupTable* myLookupTable =
00550     static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
00551   double oldMinMax[2] = { myLookupTable->GetRange()[0], myLookupTable->GetRange()[1] };
00552   bool rangeChanges = ( fabs( oldMinMax[0] - aMin ) + fabs( oldMinMax[1] - aMax ) >
00553                         0.001 * ( aMax-aMin + oldMinMax[1]-oldMinMax[0] ));
00554   
00555   bool nbColorsChanged = (myColorsSpin->value() != myScalarBarActor->GetMaximumNumberOfColors());
00556   if(nbColorsChanged)
00557     myScalarBarActor->SetMaximumNumberOfColors(myColorsSpin->value());
00558   
00559 
00560   myLookupTable->SetRange( aMin, aMax );
00561   myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
00562   myLookupTable->Build();
00563 
00564   if( nbColorsChanged || rangeChanges)
00565     myActor->UpdateDistribution();
00566   
00567 #ifndef DISABLE_PLOT2DVIEWER
00568   if( myActor->GetPlot2Histogram() && 
00569       (nbColorsChanged || 
00570        rangeChanges ||
00571        distributionTypeChanged || 
00572        colorChanged ))
00573     SMESH::ProcessIn2DViewers(myActor);
00574 #endif
00575     
00576     
00577 
00578   SMESH::RepaintCurrentView();
00579   return true;
00580 }
00581 
00582 //=================================================================================================
00588 //=================================================================================================
00589 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
00590 {
00591   close();
00592 }
00593 
00594 //=================================================================================================
00600 //=================================================================================================
00601 void SMESHGUI_Preferences_ScalarBarDlg::onHelp()
00602 {
00603   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00604   if (app) 
00605     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00606   else {
00607     QString platform;
00608 #ifdef WIN32
00609     platform = "winapplication";
00610 #else
00611     platform = "application";
00612 #endif
00613     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00614                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00615                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
00616                                                                  platform)).
00617                              arg(myHelpFileName));
00618   }
00619 }
00620 
00621 //=================================================================================================
00627 //=================================================================================================
00628 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
00629 {
00630   SALOME_ListIO aList;
00631   mySelectionMgr->selectedObjects(aList);
00632 
00633   if (aList.Extent() == 1) {
00634     Handle(SALOME_InteractiveObject) anIO = aList.First();
00635     if( anIO->hasEntry() ) {
00636       SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
00637       if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
00638         myActor = anActor;
00639         SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
00640 
00641         if ( myScalarBarActor->GetLookupTable() ) {
00642           vtkFloatingPointType *range = myScalarBarActor->GetLookupTable()->GetRange();
00643           myMinEdit->setText( QString::number( range[0],'g',12 ) );
00644           myMaxEdit->setText( QString::number( range[1],'g',12 ) );
00645         }
00646 
00647         vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
00648         vtkFloatingPointType aTColor[3];
00649         aTitleTextPrp->GetColor( aTColor );
00650         myTitleColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
00651         myTitleFontCombo->setCurrentIndex( aTitleTextPrp->GetFontFamily() );
00652         myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
00653         myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
00654         myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
00655 
00656         vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
00657         vtkFloatingPointType aLColor[3];
00658         aLabelsTextPrp->GetColor( aLColor );
00659         myLabelsColorBtn->setColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
00660         myLabelsFontCombo->setCurrentIndex( aLabelsTextPrp->GetFontFamily() );
00661         myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
00662         myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
00663         myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
00664 
00665         myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
00666         myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
00667 
00668         if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
00669           myVertRadioBtn->setChecked( true );
00670         else
00671           myHorizRadioBtn->setChecked( true );
00672         myIniOrientation = myVertRadioBtn->isChecked();
00673 
00674         myIniX = myScalarBarActor->GetPosition()[0];
00675         myIniY = myScalarBarActor->GetPosition()[1];
00676         myIniW = myScalarBarActor->GetWidth();
00677         myIniH = myScalarBarActor->GetHeight();
00678         setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
00679 
00680         int coloringType = myScalarBarActor->GetDistributionColoringType();
00681         myScalarBarActor->GetDistributionColor( aTColor );
00682         myMonoColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
00683         if ( coloringType == SMESH_MONOCOLOR_TYPE ) {
00684           myDMonoColor->setChecked(true);
00685           onDistributionChanged(myDistribColorGrp->id(myDMonoColor));    
00686         } else {
00687           myDMultiColor->setChecked(true);
00688           onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
00689         }
00690         myDistributionGrp->setChecked((bool)myScalarBarActor->GetDistributionVisibility());
00691         onDistributionActivated(myScalarBarActor->GetDistributionVisibility());
00692         
00693         
00694         myRangeGrp->setEnabled( true );
00695         myFontGrp->setEnabled( true );
00696         myLabColorGrp->setEnabled( true );
00697         myOrientationGrp->setEnabled( true );
00698         myOriginDimGrp->setEnabled( true );
00699         myOkBtn->setEnabled( true );
00700         myApplyBtn->setEnabled( true );
00701         myDistributionGrp->setEnabled( true );
00702         return;
00703       }
00704     }
00705   }
00706   myActor = 0;
00707   myRangeGrp->setEnabled( false );
00708   myFontGrp->setEnabled( false );
00709   myLabColorGrp->setEnabled( false );
00710   myOrientationGrp->setEnabled( false );
00711   myOriginDimGrp->setEnabled( false );
00712   myOkBtn->setEnabled( false );
00713   myApplyBtn->setEnabled( false );
00714   myDistributionGrp->setEnabled( false );
00715 }
00716 
00717 //=================================================================================================
00723 //=================================================================================================
00724 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
00725 {
00726   myDlg = 0;
00727   QDialog::closeEvent( e );
00728 }
00729 
00730 //=================================================================================================
00736 //=================================================================================================
00737 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
00738 {
00739   myWidthSpin->setMaximum( 1.0 - myXSpin->value() );
00740   myHeightSpin->setMaximum( 1.0 - myYSpin->value() );
00741 }
00742 
00743 //=================================================================================================
00749 //=================================================================================================
00750 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
00751                                                           const double y,
00752                                                           const double w,
00753                                                           const double h )
00754 {
00755   blockSignals( true );
00756   myXSpin->setValue( x );
00757   myYSpin->setValue( y );
00758   myWidthSpin->setMaximum( 1.0 );
00759   myWidthSpin->setValue( w );
00760   myHeightSpin->setMaximum( 1.0 );
00761   myHeightSpin->setValue( h );
00762   blockSignals( false );
00763   onXYChanged();
00764 }
00765 
00766 
00767 //=================================================================================================
00773 //=================================================================================================
00774 void SMESHGUI_Preferences_ScalarBarDlg::onDistributionChanged( int id ) {
00775 
00776   bool isActive = myDistribColorGrp->id(myDMonoColor) == id;
00777 
00778   myMonoColorBtn->setEnabled(isActive);
00779   myDistributionColorLbl->setEnabled(isActive);
00780 }
00781 //=================================================================================================
00787 //=================================================================================================
00788 void SMESHGUI_Preferences_ScalarBarDlg::onDistributionActivated(bool on) {
00789   if(on) {
00790     if(myDMonoColor->isChecked())
00791       onDistributionChanged(myDistribColorGrp->id(myDMonoColor)  );
00792     else if(myDMultiColor->isChecked())
00793       onDistributionChanged(myDistribColorGrp->id(myDMultiColor) );
00794   }
00795   else {
00796     myMonoColorBtn->setEnabled(false);
00797     myDistributionColorLbl->setEnabled(false);
00798   }
00799 }
00800 
00801 
00802 //=================================================================================================
00808 //=================================================================================================
00809 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
00810 {
00811   initScalarBarFromResources();
00812 
00813   int aOrientation = myVertRadioBtn->isChecked();
00814   if ( aOrientation == myIniOrientation )
00815     setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
00816   else
00817     setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
00818                       aOrientation ? DEF_VER_Y : DEF_HOR_Y,
00819                       aOrientation ? DEF_VER_W : DEF_HOR_W,
00820                       aOrientation ? DEF_VER_H : DEF_HOR_H );
00821 }
00822 
00823 //=================================================================================================
00829 //=================================================================================================
00830 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
00831 {
00832   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
00833   QString name;
00834   if (mgr){
00835     // initialize from resoources
00836     
00837     // horizontal
00838     name = QString("scalar_bar_horizontal_%1");
00839     if (mgr->hasValue("SMESH", name.arg( "x" )))
00840       DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
00841     if (mgr->hasValue("SMESH", name.arg( "y" )))
00842       DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
00843     if (mgr->hasValue("SMESH", name.arg( "width" )))
00844       DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
00845     if (mgr->hasValue("SMESH", name.arg( "height" )))
00846       DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
00847 
00848     // vertical
00849     name = QString("scalar_bar_vertical_%1");
00850     if (mgr->hasValue("SMESH", name.arg( "x" )))
00851       DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
00852     if (mgr->hasValue("SMESH", name.arg( "y" )))
00853       DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
00854     if (mgr->hasValue("SMESH", name.arg( "width" )))
00855       DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
00856     if (mgr->hasValue("SMESH", name.arg( "height" )))
00857       DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));
00858   }
00859 }