Salome HOME
218efdfffd5ec3df68d1a1d014b7a76077cec184
[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_SpinBox.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_Utils.h"
33
34 #include <SMESH_Actor.h>
35
36 // SALOME GUI includes
37 #include <SUIT_Desktop.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_MessageBox.h>
41
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <SALOME_ListIO.hxx>
45 #include <SalomeApp_IntSpinBox.h>
46
47 #include <QtxColorButton.h>
48
49 // Qt includes
50 #include <QButtonGroup>
51 #include <QCheckBox>
52 #include <QComboBox>
53 #include <QGroupBox>
54 #include <QLabel>
55 #include <QLineEdit>
56 #include <QPushButton>
57 #include <QRadioButton>
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 SalomeApp_IntSpinBox( myLabColorGrp );
203   myColorsSpin->setAcceptNames( false ); // No Notebook variables allowed
204   myColorsSpin->setRange( 2, 256 );
205   myColorsSpin->setSingleStep( 1 );
206   myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
207   myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
208
209   myLabelsSpin = new SalomeApp_IntSpinBox( myLabColorGrp );
210   myLabelsSpin->setAcceptNames( false ); // No Notebook variables allowed
211   myLabelsSpin->setRange( 2, 65 );
212   myLabelsSpin->setSingleStep( 1 );
213   myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
214   myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
215
216   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp ) );
217   myLabColorGrpLayout->addWidget( myColorsSpin );
218   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp ) );
219   myLabColorGrpLayout->addWidget( myLabelsSpin );
220
221   aTopLayout->addWidget( myLabColorGrp );
222
223   /******************************************************************************/
224   // Orientation
225   myOrientationGrp = new QGroupBox ( tr( "SMESH_ORIENTATION" ), this );
226   QButtonGroup* aOrientationGrp = new QButtonGroup( this );
227   QHBoxLayout* myOrientationGrpLayout = new QHBoxLayout( myOrientationGrp );
228   myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
229
230   myVertRadioBtn  = new QRadioButton( tr( "SMESH_VERTICAL" ),   myOrientationGrp );
231   myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp );
232   myVertRadioBtn->setChecked( true );
233
234   myOrientationGrpLayout->addWidget( myVertRadioBtn );
235   myOrientationGrpLayout->addWidget( myHorizRadioBtn );
236   aOrientationGrp->addButton(myVertRadioBtn);
237   aOrientationGrp->addButton(myHorizRadioBtn);
238
239   aTopLayout->addWidget( myOrientationGrp );
240
241   /******************************************************************************/
242   // Position & Size
243   myOriginDimGrp = new QGroupBox ( tr("SMESH_POSITION_SIZE_SCALARBAR"), this );
244   QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp );
245   myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
246
247   myXSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
248   myXSpin->setAcceptNames( false );
249   myXSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );
250   myXSpin->setMinimumWidth( MINIMUM_WIDTH );
251   myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
252
253   myYSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
254   myYSpin->setAcceptNames( false );
255   myYSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );  
256   myYSpin->setMinimumWidth( MINIMUM_WIDTH );
257   myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
258
259   myWidthSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
260   myWidthSpin->setAcceptNames( false );
261   myWidthSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );    
262   myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
263   myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
264
265   myHeightSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
266   myHeightSpin->setAcceptNames( false );
267   myHeightSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );    
268   myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
269   myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
270
271   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp ), 0, 0 );
272   myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
273   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp ), 0, 2 );
274   myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
275   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ),  myOriginDimGrp ),  1, 0 );
276   myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
277   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp ), 1, 2 );
278   myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
279
280   aTopLayout->addWidget( myOriginDimGrp );
281
282   /***************************************************************/
283   // Common buttons
284   myButtonGrp = new QGroupBox( this );
285   QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp );
286   myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
287
288   myOkBtn = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), myButtonGrp );
289   myOkBtn->setAutoDefault( true ); myOkBtn->setDefault( true );
290   myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp );
291   myApplyBtn->setAutoDefault( true );
292   myCancelBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), myButtonGrp );
293   myCancelBtn->setAutoDefault( true );
294   myHelpBtn = new QPushButton( tr("SMESH_BUT_HELP"), myButtonGrp );
295   myHelpBtn->setAutoDefault(true);
296
297   myButtonGrpLayout->addWidget( myOkBtn );
298   myButtonGrpLayout->addSpacing( 10 );
299   myButtonGrpLayout->addWidget( myApplyBtn );
300   myButtonGrpLayout->addSpacing( 10 );
301   myButtonGrpLayout->addStretch();
302   myButtonGrpLayout->addWidget( myCancelBtn );
303   myButtonGrpLayout->addWidget( myHelpBtn );
304
305   aTopLayout->addWidget( myButtonGrp );
306
307   /***************************************************************/
308   // Init
309   // --> first init from preferences
310   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
311
312   QColor titleColor = mgr->colorValue("SMESH", "scalar_bar_title_color",
313                                       QColor(255, 255, 255));
314   myTitleColorBtn->setColor(titleColor);
315   myTitleFontCombo->setCurrentIndex(0);
316   if (mgr->hasValue("SMESH", "scalar_bar_title_font")) {
317     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
318     if( f.family()=="Arial" )
319       myTitleFontCombo->setCurrentIndex(0);
320     if( f.family()=="Courier" )
321       myTitleFontCombo->setCurrentIndex(1);
322     if( f.family()=="Times")
323       myTitleFontCombo->setCurrentIndex(2);
324     
325     myTitleBoldCheck->setChecked  ( f.bold() );
326     myTitleItalicCheck->setChecked( f.italic() );
327     myTitleShadowCheck->setChecked( f.overline() );
328   }
329                                       
330   QColor labelColor = mgr->colorValue("SMESH", "scalar_bar_label_color", 
331                                       QColor(255, 255, 255));
332   myLabelsColorBtn->setColor(labelColor);
333   myLabelsFontCombo->setCurrentIndex(0);
334   if (mgr->hasValue("SMESH", "scalar_bar_label_font")) {
335     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
336     if (f.family() == "Arial")
337       myLabelsFontCombo->setCurrentIndex(0);
338     if (f.family() == "Courier")
339       myLabelsFontCombo->setCurrentIndex(1);
340     if (f.family() == "Times")
341       myLabelsFontCombo->setCurrentIndex(2);
342       
343     myLabelsBoldCheck  ->setChecked( f.bold() );
344     myLabelsItalicCheck->setChecked( f.italic() );
345     myLabelsShadowCheck->setChecked( f.overline() );
346   }
347
348   int aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors", 64);
349   myColorsSpin->setValue(aNbColors);
350
351   int aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels", 5);
352   myLabelsSpin->setValue(aNbLabels);
353
354   int aOrientation = mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 );
355   bool isHoriz = aOrientation == 1;
356   if (isHoriz)
357     myHorizRadioBtn->setChecked(true);
358   else
359     myVertRadioBtn->setChecked(true);
360   myIniOrientation = myVertRadioBtn->isChecked();
361
362   QString name = isHoriz ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
363
364   myIniX = mgr->doubleValue("SMESH", name.arg( "x" ), 
365                             myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X);
366
367   myIniY = mgr->doubleValue("SMESH", name.arg( "y" ),
368                             myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y);
369
370   myIniW = mgr->doubleValue("SMESH", name.arg( "width" ),
371                             myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W);
372
373   myIniH = mgr->doubleValue("SMESH", name.arg( "height" ),
374                             myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H);
375
376   setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
377
378   // --> then init from selection if necessary
379   onSelectionChanged();
380
381   /***************************************************************/
382   // Connect section
383   connect( myOkBtn,             SIGNAL( clicked() ), this, SLOT( onOk() ) );
384   connect( myApplyBtn,          SIGNAL( clicked() ), this, SLOT( onApply() ) );
385   connect( myCancelBtn,         SIGNAL( clicked() ), this, SLOT( onCancel() ) );
386   connect( myHelpBtn,           SIGNAL(clicked()),   this, SLOT( onHelp() ) );
387   connect( myXSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
388   connect( myYSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
389   connect( aOrientationGrp,     SIGNAL( buttonClicked( int ) ),   this, SLOT( onOrientationChanged() ) );
390   connect( mySelectionMgr,      SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
391   connect( mySMESHGUI,          SIGNAL( SignalCloseAllDialogs() ),   this, SLOT( onCancel() ) );
392
393   myHelpFileName = "about_quality_controls_page.html";
394 }
395
396 //=================================================================================================
397 /*!
398  *  SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
399  *
400  *  Destructor
401  */
402 //=================================================================================================
403 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
404 {
405 }
406
407 //=================================================================================================
408 /*!
409  *  SMESHGUI_Preferences_ScalarBarDlg::onOk
410  *
411  *  OK button slot
412  */
413 //=================================================================================================
414 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
415 {
416   if ( onApply() )
417     onCancel();
418 }
419
420 //=================================================================================================
421 /*!
422  *  SMESHGUI_Preferences_ScalarBarDlg::onApply
423  *
424  *  Apply button slot
425  */
426 //=================================================================================================
427 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
428 {
429   // Scalar Bar properties
430   if (!myActor)
431     return false;
432   vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
433
434   vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
435   QColor aTColor = myTitleColorBtn->color();
436   aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
437   if ( myTitleFontCombo->currentIndex() == 0 )
438     aTitleTextPrp->SetFontFamilyToArial();
439   else if ( myTitleFontCombo->currentIndex() == 1 )
440     aTitleTextPrp->SetFontFamilyToCourier();
441   else
442     aTitleTextPrp->SetFontFamilyToTimes();
443   aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
444   aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
445   aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
446   myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
447
448   vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
449   QColor aLColor = myLabelsColorBtn->color();
450   aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
451   if ( myLabelsFontCombo->currentIndex() == 0 )
452     aLabelsTextPrp->SetFontFamilyToArial();
453   else if ( myLabelsFontCombo->currentIndex() == 1 )
454     aLabelsTextPrp->SetFontFamilyToCourier();
455   else
456     aLabelsTextPrp->SetFontFamilyToTimes();
457   aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
458   aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
459   aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
460   myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
461
462   myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
463   myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
464
465   if ( myHorizRadioBtn->isChecked() )
466     myScalarBarActor->SetOrientationToHorizontal();
467   else
468     myScalarBarActor->SetOrientationToVertical();
469
470   myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
471   myScalarBarActor->SetWidth( myWidthSpin->value() );
472   myScalarBarActor->SetHeight( myHeightSpin->value() );
473
474   double aMin = myMinEdit->text().toDouble();
475   double aMax = myMaxEdit->text().toDouble();
476   vtkLookupTable* myLookupTable =
477     static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
478   myLookupTable->SetRange( aMin, aMax );
479   myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
480   myLookupTable->Build();
481   SMESH::RepaintCurrentView();
482   return true;
483 }
484
485 //=================================================================================================
486 /*!
487  *  SMESHGUI_Preferences_ScalarBarDlg::onCancel
488  *
489  *  Cancel button slot
490  */
491 //=================================================================================================
492 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
493 {
494   close();
495 }
496
497 //=================================================================================================
498 /*!
499  *  SMESHGUI_Preferences_ScalarBarDlg::onHelp
500  *
501  *  Help button slot
502  */
503 //=================================================================================================
504 void SMESHGUI_Preferences_ScalarBarDlg::onHelp()
505 {
506   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
507   if (app) 
508     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
509   else {
510     QString platform;
511 #ifdef WIN32
512     platform = "winapplication";
513 #else
514     platform = "application";
515 #endif
516     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
517                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
518                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
519                                                                  platform)).
520                              arg(myHelpFileName));
521   }
522 }
523
524 //=================================================================================================
525 /*!
526  *  SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
527  *
528  *  Called when selection changed
529  */
530 //=================================================================================================
531 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
532 {
533   SALOME_ListIO aList;
534   mySelectionMgr->selectedObjects(aList);
535
536   if (aList.Extent() == 1) {
537     Handle(SALOME_InteractiveObject) anIO = aList.First();
538     if( anIO->hasEntry() ) {
539       SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
540       if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
541         myActor = anActor;
542         vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
543
544         if ( myScalarBarActor->GetLookupTable() ) {
545           vtkFloatingPointType *range = myScalarBarActor->GetLookupTable()->GetRange();
546           myMinEdit->setText( QString::number( range[0],'g',12 ) );
547           myMaxEdit->setText( QString::number( range[1],'g',12 ) );
548         }
549
550         vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
551         vtkFloatingPointType aTColor[3];
552         aTitleTextPrp->GetColor( aTColor );
553         myTitleColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
554         myTitleFontCombo->setCurrentIndex( aTitleTextPrp->GetFontFamily() );
555         myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
556         myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
557         myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
558
559         vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
560         vtkFloatingPointType aLColor[3];
561         aLabelsTextPrp->GetColor( aLColor );
562         myLabelsColorBtn->setColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
563         myLabelsFontCombo->setCurrentIndex( aLabelsTextPrp->GetFontFamily() );
564         myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
565         myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
566         myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
567
568         myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
569         myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
570
571         if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
572           myVertRadioBtn->setChecked( true );
573         else
574           myHorizRadioBtn->setChecked( true );
575         myIniOrientation = myVertRadioBtn->isChecked();
576
577         myIniX = myScalarBarActor->GetPosition()[0];
578         myIniY = myScalarBarActor->GetPosition()[1];
579         myIniW = myScalarBarActor->GetWidth();
580         myIniH = myScalarBarActor->GetHeight();
581         setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
582
583         myRangeGrp->setEnabled( true );
584         myFontGrp->setEnabled( true );
585         myLabColorGrp->setEnabled( true );
586         myOrientationGrp->setEnabled( true );
587         myOriginDimGrp->setEnabled( true );
588         myOkBtn->setEnabled( true );
589         myApplyBtn->setEnabled( true );
590         return;
591       }
592     }
593   }
594   myActor = 0;
595   myRangeGrp->setEnabled( false );
596   myFontGrp->setEnabled( false );
597   myLabColorGrp->setEnabled( false );
598   myOrientationGrp->setEnabled( false );
599   myOriginDimGrp->setEnabled( false );
600   myOkBtn->setEnabled( false );
601   myApplyBtn->setEnabled( false );
602 }
603
604 //=================================================================================================
605 /*!
606  *  SMESHGUI_Preferences_ScalarBarDlg::closeEvent
607  *
608  *  Close event handler
609  */
610 //=================================================================================================
611 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
612 {
613   myDlg = 0;
614   QDialog::closeEvent( e );
615 }
616
617 //=================================================================================================
618 /*!
619  *  SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
620  *
621  *  Called when X, Y values are changed
622  */
623 //=================================================================================================
624 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
625 {
626   myWidthSpin->setMaximum( 1.0 - myXSpin->value() );
627   myHeightSpin->setMaximum( 1.0 - myYSpin->value() );
628 }
629
630 //=================================================================================================
631 /*!
632  *  SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
633  *
634  *  Called when X, Y values are changed
635  */
636 //=================================================================================================
637 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
638                                                           const double y,
639                                                           const double w,
640                                                           const double h )
641 {
642   blockSignals( true );
643   myXSpin->setValue( x );
644   myYSpin->setValue( y );
645   myWidthSpin->setMaximum( 1.0 );
646   myWidthSpin->setValue( w );
647   myHeightSpin->setMaximum( 1.0 );
648   myHeightSpin->setValue( h );
649   blockSignals( false );
650   onXYChanged();
651 }
652
653 //=================================================================================================
654 /*!
655  *  SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
656  *
657  *  Called when orientation is changed
658  */
659 //=================================================================================================
660 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
661 {
662   initScalarBarFromResources();
663
664   int aOrientation = myVertRadioBtn->isChecked();
665   if ( aOrientation == myIniOrientation )
666     setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
667   else
668     setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
669                       aOrientation ? DEF_VER_Y : DEF_HOR_Y,
670                       aOrientation ? DEF_VER_W : DEF_HOR_W,
671                       aOrientation ? DEF_VER_H : DEF_HOR_H );
672 }
673
674 //=================================================================================================
675 /*!
676  *  SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
677  *
678  *  Rereading vertical and horizontal default positions from resources.
679  */
680 //=================================================================================================
681 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
682 {
683   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
684   QString name;
685   if (mgr){
686     // initialize from resoources
687     
688     // horizontal
689     name = QString("scalar_bar_horizontal_%1");
690     if (mgr->hasValue("SMESH", name.arg( "x" )))
691       DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
692     if (mgr->hasValue("SMESH", name.arg( "y" )))
693       DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
694     if (mgr->hasValue("SMESH", name.arg( "width" )))
695       DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
696     if (mgr->hasValue("SMESH", name.arg( "height" )))
697       DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
698
699     // vertical
700     name = QString("scalar_bar_vertical_%1");
701     if (mgr->hasValue("SMESH", name.arg( "x" )))
702       DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
703     if (mgr->hasValue("SMESH", name.arg( "y" )))
704       DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
705     if (mgr->hasValue("SMESH", name.arg( "width" )))
706       DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
707     if (mgr->hasValue("SMESH", name.arg( "height" )))
708       DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));
709   }
710 }