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