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