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