Salome HOME
Merge from BR_phase16 branch (09/12/09)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Preferences_ScalarBarDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_Preferences_ScalarBarDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_Utils.h"
32
33 #include <SMESH_Actor.h>
34
35 // SALOME GUI includes
36 #include <SUIT_Desktop.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40
41 #include <LightApp_Application.h>
42 #include <LightApp_SelectionMgr.h>
43 #include <SALOME_ListIO.hxx>
44
45 #include <QtxDoubleSpinBox.h>
46 #include <QtxColorButton.h>
47
48 // Qt includes
49 #include <QButtonGroup>
50 #include <QCheckBox>
51 #include <QComboBox>
52 #include <QGroupBox>
53 #include <QLabel>
54 #include <QLineEdit>
55 #include <QPushButton>
56 #include <QRadioButton>
57 #include <QSpinBox>
58 #include <QHBoxLayout>
59 #include <QVBoxLayout>
60 #include <QGridLayout>
61 #include <QDoubleValidator>
62
63 // VTK includes
64 #include <vtkTextProperty.h>
65 #include <vtkScalarBarActor.h>
66 #include <vtkLookupTable.h>
67
68 #define MINIMUM_WIDTH 70
69 #define MARGIN_SIZE   11
70 #define SPACING_SIZE   6
71
72 // Only one instance is allowed
73 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
74
75 //=================================================================================================
76 /*!
77  *  SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
78  *
79  *  Gets the only instance of "Scalar Bar Properties" dialog box
80  */
81 //=================================================================================================
82 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
83 {
84   if (!myDlg) {
85     myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule );
86     myDlg->show();
87   } else {
88     myDlg->show();
89     myDlg->raise();
90     myDlg->activateWindow();
91   }
92 }
93
94 //=================================================================================================
95 /*!
96  *  SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
97  *
98  *  Constructor
99  */
100 //=================================================================================================
101 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule )
102   : QDialog( SMESH::GetDesktop( theModule ) ),
103     mySMESHGUI( theModule ),
104     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
105 {
106   DEF_VER_X = 0.01;
107   DEF_VER_Y = 0.10;
108   DEF_VER_H = 0.80;
109   DEF_VER_W = 0.10;
110   DEF_HOR_X = 0.20;
111   DEF_HOR_Y = 0.01;
112   DEF_HOR_H = 0.12;
113   DEF_HOR_W = 0.60;
114
115   setModal( false );
116   setAttribute( Qt::WA_DeleteOnClose, true );
117   setWindowTitle( tr("SMESH_PROPERTIES_SCALARBAR") );
118   setSizeGripEnabled(true);
119
120   myActor = 0;
121
122   /******************************************************************************/
123   // Top layout
124   QVBoxLayout* aTopLayout = new QVBoxLayout( this );
125   aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
126
127   /******************************************************************************/
128   // Scalar range
129   myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this );
130   QHBoxLayout* myRangeGrpLayout = new QHBoxLayout( myRangeGrp );
131   myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
132   
133   myMinEdit = new QLineEdit( myRangeGrp );
134   myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
135   myMinEdit->setValidator( new QDoubleValidator( this ) );
136   
137   myMaxEdit = new QLineEdit( myRangeGrp );
138   myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
139   myMaxEdit->setValidator( new QDoubleValidator( this ) );
140   
141   myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp ) );
142   myRangeGrpLayout->addWidget( myMinEdit );
143   myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp ) );
144   myRangeGrpLayout->addWidget( myMaxEdit );
145   
146   aTopLayout->addWidget( myRangeGrp );
147
148   /******************************************************************************/
149   // Text properties
150   myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this  );
151   QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp );
152   myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
153
154   myTitleColorBtn = new QtxColorButton( myFontGrp  );
155
156   myTitleFontCombo = new QComboBox( myFontGrp );
157   myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
158   myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
159   myTitleFontCombo->addItem( tr( "SMESH_FONT_ARIAL" ) );
160   myTitleFontCombo->addItem( tr( "SMESH_FONT_COURIER" ) );
161   myTitleFontCombo->addItem( tr( "SMESH_FONT_TIMES" ) );
162
163   myTitleBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp );
164   myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp );
165   myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp );
166
167   myLabelsColorBtn = new QtxColorButton( myFontGrp );
168
169   myLabelsFontCombo = new QComboBox( myFontGrp );
170   myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
171   myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
172   myLabelsFontCombo->addItem( tr( "SMESH_FONT_ARIAL" ) );
173   myLabelsFontCombo->addItem( tr( "SMESH_FONT_COURIER" ) );
174   myLabelsFontCombo->addItem( tr( "SMESH_FONT_TIMES" ) );
175
176   myLabelsBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp );
177   myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp );
178   myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp );
179
180   myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp ), 0, 0 );
181   myFontGrpLayout->addWidget( myTitleColorBtn,    0, 1 );
182   myFontGrpLayout->addWidget( myTitleFontCombo,   0, 2 );
183   myFontGrpLayout->addWidget( myTitleBoldCheck,   0, 3 );
184   myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
185   myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
186
187   myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp ), 1, 0 );
188   myFontGrpLayout->addWidget( myLabelsColorBtn,    1, 1 );
189   myFontGrpLayout->addWidget( myLabelsFontCombo,   1, 2 );
190   myFontGrpLayout->addWidget( myLabelsBoldCheck,   1, 3 );
191   myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
192   myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
193
194   aTopLayout->addWidget( myFontGrp );
195
196   /******************************************************************************/
197   // Labels & Colors
198   myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this );
199   QHBoxLayout* myLabColorGrpLayout = new QHBoxLayout( myLabColorGrp );
200   myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
201
202   myColorsSpin = new QSpinBox( myLabColorGrp );
203   myColorsSpin->setRange( 2, 256 );
204   myColorsSpin->setSingleStep( 1 );
205   myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
206   myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
207
208   myLabelsSpin = new QSpinBox( myLabColorGrp );
209   myLabelsSpin->setRange( 2, 65 );
210   myLabelsSpin->setSingleStep( 1 );
211   myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
212   myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
213
214   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp ) );
215   myLabColorGrpLayout->addWidget( myColorsSpin );
216   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp ) );
217   myLabColorGrpLayout->addWidget( myLabelsSpin );
218
219   aTopLayout->addWidget( myLabColorGrp );
220
221   /******************************************************************************/
222   // Orientation
223   myOrientationGrp = new QGroupBox ( tr( "SMESH_ORIENTATION" ), this );
224   QButtonGroup* aOrientationGrp = new QButtonGroup( this );
225   QHBoxLayout* myOrientationGrpLayout = new QHBoxLayout( myOrientationGrp );
226   myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
227
228   myVertRadioBtn  = new QRadioButton( tr( "SMESH_VERTICAL" ),   myOrientationGrp );
229   myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp );
230   myVertRadioBtn->setChecked( true );
231
232   myOrientationGrpLayout->addWidget( myVertRadioBtn );
233   myOrientationGrpLayout->addWidget( myHorizRadioBtn );
234   aOrientationGrp->addButton(myVertRadioBtn);
235   aOrientationGrp->addButton(myHorizRadioBtn);
236
237   aTopLayout->addWidget( myOrientationGrp );
238
239   /******************************************************************************/
240   // Position & Size
241   myOriginDimGrp = new QGroupBox ( tr("SMESH_POSITION_SIZE_SCALARBAR"), this );
242   QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp );
243   myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
244
245   myXSpin = new QtxDoubleSpinBox (0.0, 1.0, 0.1, myOriginDimGrp);
246   myXSpin->setMinimumWidth( MINIMUM_WIDTH );
247   myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
248
249   myYSpin = new QtxDoubleSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
250   myYSpin->setMinimumWidth( MINIMUM_WIDTH );
251   myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
252
253   myWidthSpin = new QtxDoubleSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
254   myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
255   myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
256
257   myHeightSpin = new QtxDoubleSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
258   myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
259   myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
260
261   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp ), 0, 0 );
262   myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
263   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp ), 0, 2 );
264   myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
265   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ),  myOriginDimGrp ),  1, 0 );
266   myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
267   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp ), 1, 2 );
268   myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
269
270   aTopLayout->addWidget( myOriginDimGrp );
271
272   /***************************************************************/
273   // Common buttons
274   myButtonGrp = new QGroupBox( this );
275   QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp );
276   myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
277
278   myOkBtn = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), myButtonGrp );
279   myOkBtn->setAutoDefault( true ); myOkBtn->setDefault( true );
280   myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp );
281   myApplyBtn->setAutoDefault( true );
282   myCancelBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), myButtonGrp );
283   myCancelBtn->setAutoDefault( true );
284   myHelpBtn = new QPushButton( tr("SMESH_BUT_HELP"), myButtonGrp );
285   myHelpBtn->setAutoDefault(true);
286
287   myButtonGrpLayout->addWidget( myOkBtn );
288   myButtonGrpLayout->addSpacing( 10 );
289   myButtonGrpLayout->addWidget( myApplyBtn );
290   myButtonGrpLayout->addSpacing( 10 );
291   myButtonGrpLayout->addStretch();
292   myButtonGrpLayout->addWidget( myCancelBtn );
293   myButtonGrpLayout->addWidget( myHelpBtn );
294
295   aTopLayout->addWidget( myButtonGrp );
296
297   /***************************************************************/
298   // Init
299   // --> first init from preferences
300   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
301
302   QColor titleColor = mgr->colorValue("SMESH", "scalar_bar_title_color",
303                                       QColor(255, 255, 255));
304   myTitleColorBtn->setColor(titleColor);
305   myTitleFontCombo->setCurrentIndex(0);
306   if (mgr->hasValue("SMESH", "scalar_bar_title_font")) {
307     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
308     if( f.family()=="Arial" )
309       myTitleFontCombo->setCurrentIndex(0);
310     if( f.family()=="Courier" )
311       myTitleFontCombo->setCurrentIndex(1);
312     if( f.family()=="Times")
313       myTitleFontCombo->setCurrentIndex(2);
314     
315     myTitleBoldCheck->setChecked  ( f.bold() );
316     myTitleItalicCheck->setChecked( f.italic() );
317     myTitleShadowCheck->setChecked( f.overline() );
318   }
319                                       
320   QColor labelColor = mgr->colorValue("SMESH", "scalar_bar_label_color", 
321                                       QColor(255, 255, 255));
322   myLabelsColorBtn->setColor(labelColor);
323   myLabelsFontCombo->setCurrentIndex(0);
324   if (mgr->hasValue("SMESH", "scalar_bar_label_font")) {
325     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
326     if (f.family() == "Arial")
327       myLabelsFontCombo->setCurrentIndex(0);
328     if (f.family() == "Courier")
329       myLabelsFontCombo->setCurrentIndex(1);
330     if (f.family() == "Times")
331       myLabelsFontCombo->setCurrentIndex(2);
332       
333     myLabelsBoldCheck  ->setChecked( f.bold() );
334     myLabelsItalicCheck->setChecked( f.italic() );
335     myLabelsShadowCheck->setChecked( f.overline() );
336   }
337
338   int aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors", 64);
339   myColorsSpin->setValue(aNbColors);
340
341   int aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels", 5);
342   myLabelsSpin->setValue(aNbLabels);
343
344   int aOrientation = mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 );
345   bool isHoriz = aOrientation == 1;
346   if (isHoriz)
347     myHorizRadioBtn->setChecked(true);
348   else
349     myVertRadioBtn->setChecked(true);
350   myIniOrientation = myVertRadioBtn->isChecked();
351
352   QString name = isHoriz ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
353
354   myIniX = mgr->doubleValue("SMESH", name.arg( "x" ), 
355                             myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X);
356
357   myIniY = mgr->doubleValue("SMESH", name.arg( "y" ),
358                             myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y);
359
360   myIniW = mgr->doubleValue("SMESH", name.arg( "width" ),
361                             myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W);
362
363   myIniH = mgr->doubleValue("SMESH", name.arg( "height" ),
364                             myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H);
365
366   setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
367
368   // --> then init from selection if necessary
369   onSelectionChanged();
370
371   /***************************************************************/
372   // Connect section
373   connect( myOkBtn,             SIGNAL( clicked() ), this, SLOT( onOk() ) );
374   connect( myApplyBtn,          SIGNAL( clicked() ), this, SLOT( onApply() ) );
375   connect( myCancelBtn,         SIGNAL( clicked() ), this, SLOT( onCancel() ) );
376   connect( myHelpBtn,           SIGNAL(clicked()),   this, SLOT( onHelp() ) );
377   connect( myXSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
378   connect( myYSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
379   connect( aOrientationGrp,     SIGNAL( buttonClicked( int ) ),   this, SLOT( onOrientationChanged() ) );
380   connect( mySelectionMgr,      SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
381   connect( mySMESHGUI,          SIGNAL( SignalCloseAllDialogs() ),   this, SLOT( onCancel() ) );
382
383   myHelpFileName = "about_quality_controls_page.html";
384 }
385
386 //=================================================================================================
387 /*!
388  *  SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
389  *
390  *  Destructor
391  */
392 //=================================================================================================
393 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
394 {
395 }
396
397 //=================================================================================================
398 /*!
399  *  SMESHGUI_Preferences_ScalarBarDlg::onOk
400  *
401  *  OK button slot
402  */
403 //=================================================================================================
404 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
405 {
406   if ( onApply() )
407     onCancel();
408 }
409
410 //=================================================================================================
411 /*!
412  *  SMESHGUI_Preferences_ScalarBarDlg::onApply
413  *
414  *  Apply button slot
415  */
416 //=================================================================================================
417 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
418 {
419   // Scalar Bar properties
420   if (!myActor)
421     return false;
422   vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
423
424   vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
425   QColor aTColor = myTitleColorBtn->color();
426   aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
427   if ( myTitleFontCombo->currentIndex() == 0 )
428     aTitleTextPrp->SetFontFamilyToArial();
429   else if ( myTitleFontCombo->currentIndex() == 1 )
430     aTitleTextPrp->SetFontFamilyToCourier();
431   else
432     aTitleTextPrp->SetFontFamilyToTimes();
433   aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
434   aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
435   aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
436   myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
437
438   vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
439   QColor aLColor = myLabelsColorBtn->color();
440   aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
441   if ( myLabelsFontCombo->currentIndex() == 0 )
442     aLabelsTextPrp->SetFontFamilyToArial();
443   else if ( myLabelsFontCombo->currentIndex() == 1 )
444     aLabelsTextPrp->SetFontFamilyToCourier();
445   else
446     aLabelsTextPrp->SetFontFamilyToTimes();
447   aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
448   aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
449   aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
450   myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
451
452   myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
453   myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
454
455   if ( myHorizRadioBtn->isChecked() )
456     myScalarBarActor->SetOrientationToHorizontal();
457   else
458     myScalarBarActor->SetOrientationToVertical();
459
460   myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
461   myScalarBarActor->SetWidth( myWidthSpin->value() );
462   myScalarBarActor->SetHeight( myHeightSpin->value() );
463
464   double aMin = myMinEdit->text().toDouble();
465   double aMax = myMaxEdit->text().toDouble();
466   vtkLookupTable* myLookupTable =
467     static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
468   myLookupTable->SetRange( aMin, aMax );
469   myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
470   myLookupTable->Build();
471   SMESH::RepaintCurrentView();
472   return true;
473 }
474
475 //=================================================================================================
476 /*!
477  *  SMESHGUI_Preferences_ScalarBarDlg::onCancel
478  *
479  *  Cancel button slot
480  */
481 //=================================================================================================
482 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
483 {
484   close();
485 }
486
487 //=================================================================================================
488 /*!
489  *  SMESHGUI_Preferences_ScalarBarDlg::onHelp
490  *
491  *  Help button slot
492  */
493 //=================================================================================================
494 void SMESHGUI_Preferences_ScalarBarDlg::onHelp()
495 {
496   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
497   if (app) 
498     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
499   else {
500     QString platform;
501 #ifdef WIN32
502     platform = "winapplication";
503 #else
504     platform = "application";
505 #endif
506     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
507                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
508                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
509                                                                  platform)).
510                              arg(myHelpFileName));
511   }
512 }
513
514 //=================================================================================================
515 /*!
516  *  SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
517  *
518  *  Called when selection changed
519  */
520 //=================================================================================================
521 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
522 {
523   SALOME_ListIO aList;
524   mySelectionMgr->selectedObjects(aList);
525
526   if (aList.Extent() == 1) {
527     Handle(SALOME_InteractiveObject) anIO = aList.First();
528     if( anIO->hasEntry() ) {
529       SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
530       if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
531         myActor = anActor;
532         vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
533
534         if ( myScalarBarActor->GetLookupTable() ) {
535           vtkFloatingPointType *range = myScalarBarActor->GetLookupTable()->GetRange();
536           myMinEdit->setText( QString::number( range[0],'g',12 ) );
537           myMaxEdit->setText( QString::number( range[1],'g',12 ) );
538         }
539
540         vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
541         vtkFloatingPointType aTColor[3];
542         aTitleTextPrp->GetColor( aTColor );
543         myTitleColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
544         myTitleFontCombo->setCurrentIndex( aTitleTextPrp->GetFontFamily() );
545         myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
546         myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
547         myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
548
549         vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
550         vtkFloatingPointType aLColor[3];
551         aLabelsTextPrp->GetColor( aLColor );
552         myLabelsColorBtn->setColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
553         myLabelsFontCombo->setCurrentIndex( aLabelsTextPrp->GetFontFamily() );
554         myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
555         myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
556         myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
557
558         myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
559         myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
560
561         if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
562           myVertRadioBtn->setChecked( true );
563         else
564           myHorizRadioBtn->setChecked( true );
565         myIniOrientation = myVertRadioBtn->isChecked();
566
567         myIniX = myScalarBarActor->GetPosition()[0];
568         myIniY = myScalarBarActor->GetPosition()[1];
569         myIniW = myScalarBarActor->GetWidth();
570         myIniH = myScalarBarActor->GetHeight();
571         setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
572
573         myRangeGrp->setEnabled( true );
574         myFontGrp->setEnabled( true );
575         myLabColorGrp->setEnabled( true );
576         myOrientationGrp->setEnabled( true );
577         myOriginDimGrp->setEnabled( true );
578         myOkBtn->setEnabled( true );
579         myApplyBtn->setEnabled( true );
580         return;
581       }
582     }
583   }
584   myActor = 0;
585   myRangeGrp->setEnabled( false );
586   myFontGrp->setEnabled( false );
587   myLabColorGrp->setEnabled( false );
588   myOrientationGrp->setEnabled( false );
589   myOriginDimGrp->setEnabled( false );
590   myOkBtn->setEnabled( false );
591   myApplyBtn->setEnabled( false );
592 }
593
594 //=================================================================================================
595 /*!
596  *  SMESHGUI_Preferences_ScalarBarDlg::closeEvent
597  *
598  *  Close event handler
599  */
600 //=================================================================================================
601 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
602 {
603   myDlg = 0;
604   QDialog::closeEvent( e );
605 }
606
607 //=================================================================================================
608 /*!
609  *  SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
610  *
611  *  Called when X, Y values are changed
612  */
613 //=================================================================================================
614 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
615 {
616   myWidthSpin->setMaximum( 1.0 - myXSpin->value() );
617   myHeightSpin->setMaximum( 1.0 - myYSpin->value() );
618 }
619
620 //=================================================================================================
621 /*!
622  *  SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
623  *
624  *  Called when X, Y values are changed
625  */
626 //=================================================================================================
627 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
628                                                           const double y,
629                                                           const double w,
630                                                           const double h )
631 {
632   blockSignals( true );
633   myXSpin->setValue( x );
634   myYSpin->setValue( y );
635   myWidthSpin->setMaximum( 1.0 );
636   myWidthSpin->setValue( w );
637   myHeightSpin->setMaximum( 1.0 );
638   myHeightSpin->setValue( h );
639   blockSignals( false );
640   onXYChanged();
641 }
642
643 //=================================================================================================
644 /*!
645  *  SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
646  *
647  *  Called when orientation is changed
648  */
649 //=================================================================================================
650 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
651 {
652   initScalarBarFromResources();
653
654   int aOrientation = myVertRadioBtn->isChecked();
655   if ( aOrientation == myIniOrientation )
656     setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
657   else
658     setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
659                       aOrientation ? DEF_VER_Y : DEF_HOR_Y,
660                       aOrientation ? DEF_VER_W : DEF_HOR_W,
661                       aOrientation ? DEF_VER_H : DEF_HOR_H );
662 }
663
664 //=================================================================================================
665 /*!
666  *  SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
667  *
668  *  Rereading vertical and horizontal default positions from resources.
669  */
670 //=================================================================================================
671 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
672 {
673   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
674   QString name;
675   if (mgr){
676     // initialize from resoources
677     
678     // horizontal
679     name = QString("scalar_bar_horizontal_%1");
680     if (mgr->hasValue("SMESH", name.arg( "x" )))
681       DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
682     if (mgr->hasValue("SMESH", name.arg( "y" )))
683       DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
684     if (mgr->hasValue("SMESH", name.arg( "width" )))
685       DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
686     if (mgr->hasValue("SMESH", name.arg( "height" )))
687       DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
688
689     // vertical
690     name = QString("scalar_bar_vertical_%1");
691     if (mgr->hasValue("SMESH", name.arg( "x" )))
692       DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
693     if (mgr->hasValue("SMESH", name.arg( "y" )))
694       DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
695     if (mgr->hasValue("SMESH", name.arg( "width" )))
696       DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
697     if (mgr->hasValue("SMESH", name.arg( "height" )))
698       DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));
699   }
700 }