Salome HOME
PAL6938
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Preferences_ScalarBarDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_Preferences_ScalarBarDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_VTKUtils.h"
33
34 #include <qbuttongroup.h>
35 #include <qcheckbox.h>
36 #include <qcombobox.h>
37 #include <qgroupbox.h>
38 #include <qlabel.h>
39 #include <qlineedit.h>
40 #include <qpushbutton.h>
41 #include <qtoolbutton.h>
42 #include <qradiobutton.h>
43 #include <qspinbox.h>
44 #include <qlayout.h>
45 #include <qvalidator.h>
46 #include <qcolordialog.h>
47
48 #include <vtkTextProperty.h>
49 #include <vtkScalarBarActor.h>
50 #include <vtkScalarsToColors.h>
51
52 #include "QAD_SpinBoxDbl.h"
53 #include "QAD_Config.h"
54 #include "SALOME_Selection.h"
55 #include "SMESHGUI.h"
56 #include "SMESH_Actor.h"
57
58 #define MINIMUM_WIDTH 70
59 #define MARGIN_SIZE   11
60 #define SPACING_SIZE   6
61
62 #define DEF_VER_X  0.01
63 #define DEF_VER_Y  0.10
64 #define DEF_VER_H  0.80
65 #define DEF_VER_W  0.10
66 #define DEF_HOR_X  0.20
67 #define DEF_HOR_Y  0.01
68 #define DEF_HOR_H  0.12
69 #define DEF_HOR_W  0.60
70
71 using namespace std;
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(QWidget* parent, 
84                                                             SALOME_Selection* Sel)
85 {
86   if ( !myDlg ) {
87     myDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, Sel, false );
88     myDlg->show();
89   }
90   else {
91     myDlg->show();
92     myDlg->setActiveWindow();
93     myDlg->raise();
94     myDlg->setFocus();
95   }
96 }
97
98 //=================================================================================================
99 /*!
100  *  SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
101  *
102  *  Opens "Scalar Bar Preferences" dialog box
103  */
104 //=================================================================================================
105 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( QWidget* parent )
106 {
107   SMESHGUI_Preferences_ScalarBarDlg* aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, 0, true );
108   aDlg->exec();
109 }
110
111 //=================================================================================================
112 /*!
113  *  SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
114  *
115  *  Constructor
116  */
117 //=================================================================================================
118 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg(QWidget* parent, 
119                                                                      SALOME_Selection* Sel, 
120                                                                      bool modal)
121      : QDialog( parent, 0, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
122 {
123   setName( "SMESHGUI_Preferences_ScalarBarDlg" );
124   setCaption( Sel ? tr( "SMESH_PROPERTIES_SCALARBAR" ) : tr( "SMESH_PREFERENCES_SCALARBAR" ) );
125   setSizeGripEnabled( TRUE );
126
127   mySelection = Sel;
128   myActor = 0;
129
130   /******************************************************************************/
131   // Top layout
132   QGridLayout* aTopLayout = new QGridLayout( this );
133   aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
134   int aRow = 0;
135
136   /******************************************************************************/
137   // Scalar range
138   if ( mySelection ) {
139     myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this, "myRangeGrp" );
140     myRangeGrp->setColumnLayout( 0, Qt::Vertical );
141     myRangeGrp->layout()->setSpacing( 0 ); myRangeGrp->layout()->setMargin( 0 );
142     QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp->layout() );
143     myRangeGrpLayout->setAlignment( Qt::AlignTop );
144     myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
145     
146     myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
147     myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
148     myMinEdit->setValidator( new QDoubleValidator( this ) );
149
150     myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
151     myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
152     myMaxEdit->setValidator( new QDoubleValidator( this ) );
153
154     myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp, "myMinLab" ), 0, 0 );
155     myRangeGrpLayout->addWidget( myMinEdit, 0, 1 );
156     myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp, "myMaxLab" ), 0, 2 );
157     myRangeGrpLayout->addWidget( myMaxEdit, 0, 3 );
158
159     aTopLayout->addWidget( myRangeGrp, aRow, 0 );
160     aRow++;
161   }
162
163   /******************************************************************************/
164   // Text properties
165   myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this, "myFontGrp" );
166   myFontGrp->setColumnLayout( 0, Qt::Vertical );
167   myFontGrp->layout()->setSpacing( 0 ); myFontGrp->layout()->setMargin( 0 );
168   QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp->layout() );
169   myFontGrpLayout->setAlignment( Qt::AlignTop );
170   myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
171     
172   myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
173   
174   myTitleFontCombo = new QComboBox( false, myFontGrp, "myTitleFontCombo" );
175   myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
176   myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
177   myTitleFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
178   myTitleFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
179   myTitleFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
180   
181   myTitleBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp, "myTitleBoldCheck" );
182   myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myTitleItalicCheck" );
183   myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myTitleShadowCheck" );
184
185   myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
186   
187   myLabelsFontCombo = new QComboBox( false, myFontGrp, "myLabelsFontCombo" );
188   myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
189   myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
190   myLabelsFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
191   myLabelsFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
192   myLabelsFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
193   
194   myLabelsBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp, "myLabelsBoldCheck" );
195   myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myLabelsItalicCheck" );
196   myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myLabelsShadowCheck" );
197
198   myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp, "myFontTitleLab" ), 0, 0 );
199   myFontGrpLayout->addWidget( myTitleColorBtn,    0, 1 );
200   myFontGrpLayout->addWidget( myTitleFontCombo,   0, 2 );
201   myFontGrpLayout->addWidget( myTitleBoldCheck,   0, 3 );
202   myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
203   myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
204   
205   myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp, "myFontLabelsLab" ), 1, 0 );
206   myFontGrpLayout->addWidget( myLabelsColorBtn,    1, 1 );
207   myFontGrpLayout->addWidget( myLabelsFontCombo,   1, 2 );
208   myFontGrpLayout->addWidget( myLabelsBoldCheck,   1, 3 );
209   myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
210   myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
211
212   aTopLayout->addWidget( myFontGrp, aRow, 0 );
213   aRow++;
214
215   /******************************************************************************/
216   // Labels & Colors
217   myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this, "myLabColorGrp" );
218   myLabColorGrp->setColumnLayout( 0, Qt::Vertical );
219   myLabColorGrp->layout()->setSpacing( 0 ); myLabColorGrp->layout()->setMargin( 0 );
220   QGridLayout* myLabColorGrpLayout = new QGridLayout( myLabColorGrp->layout() );
221   myLabColorGrpLayout->setAlignment( Qt::AlignTop );
222   myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
223     
224   myColorsSpin = new QSpinBox( 2, 256, 1, myLabColorGrp, "myColorsSpin" );
225   myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
226   myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
227
228   myLabelsSpin = new QSpinBox( 2, 65, 1, myLabColorGrp, "myLabelsSpin" );
229   myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
230   myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
231
232   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp, "myNbColorLab" ), 0, 0 );
233   myLabColorGrpLayout->addWidget( myColorsSpin, 0, 1 );
234   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp, "myNbLabsLab" ), 0, 2 );
235   myLabColorGrpLayout->addWidget( myLabelsSpin, 0, 3 );
236
237   aTopLayout->addWidget( myLabColorGrp, aRow, 0 );
238   aRow++;
239
240   /******************************************************************************/
241   // Orientation
242   myOrientationGrp = new QButtonGroup ( tr( "SMESH_ORIENTATION" ), this, "myOrientationGrp" );
243   myOrientationGrp->setColumnLayout( 0, Qt::Vertical );
244   myOrientationGrp->layout()->setSpacing( 0 ); myOrientationGrp->layout()->setMargin( 0 );
245   QGridLayout* myOrientationGrpLayout = new QGridLayout( myOrientationGrp->layout() );
246   myOrientationGrpLayout->setAlignment( Qt::AlignTop );
247   myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
248     
249   myVertRadioBtn  = new QRadioButton( tr( "SMESH_VERTICAL" ),   myOrientationGrp, "myVertRadioBtn" );
250   myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp, "myHorizRadioBtn" );
251   myVertRadioBtn->setChecked( true );
252
253   myOrientationGrpLayout->addWidget( myVertRadioBtn,  0, 0 );
254   myOrientationGrpLayout->addWidget( myHorizRadioBtn, 0, 1 );
255
256   aTopLayout->addWidget( myOrientationGrp, aRow, 0 );
257   aRow++;
258
259   /******************************************************************************/
260   // Position & Size
261   myOriginDimGrp = new QGroupBox ( tr( "SMESH_POSITION_SIZE_SCALARBAR" ), this, "myOriginDimGrp" );
262   myOriginDimGrp->setColumnLayout( 0, Qt::Vertical );
263   myOriginDimGrp->layout()->setSpacing( 0 ); myOriginDimGrp->layout()->setMargin( 0 );
264   QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp->layout() );
265   myOriginDimGrpLayout->setAlignment( Qt::AlignTop );
266   myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
267     
268   myXSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
269   myXSpin->setMinimumWidth( MINIMUM_WIDTH );
270   myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
271
272   myYSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
273   myYSpin->setMinimumWidth( MINIMUM_WIDTH );
274   myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
275
276   myWidthSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
277   myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
278   myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
279
280   myHeightSpin = new QAD_SpinBoxDbl( myOriginDimGrp, 0.0, 1.0, 0.1 );
281   myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
282   myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
283
284   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp, "myXLab" ), 0, 0 );
285   myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
286   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp, "myYLab" ), 0, 2 );
287   myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
288   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ),  myOriginDimGrp, "myWidthLab" ),  1, 0 );
289   myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
290   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp, "myHeightLab" ), 1, 2 );
291   myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
292
293   aTopLayout->addWidget( myOriginDimGrp, aRow, 0 );
294   aRow++;
295
296   /***************************************************************/
297   // Common buttons
298   myButtonGrp = new QGroupBox( this, "myButtonGrp" );
299   myButtonGrp->setColumnLayout(0, Qt::Vertical );
300   myButtonGrp->layout()->setSpacing( 0 ); myButtonGrp->layout()->setMargin( 0 );
301   QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp->layout() );
302   myButtonGrpLayout->setAlignment( Qt::AlignTop );
303   myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
304
305   myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), myButtonGrp, "myOkBtn" );
306   myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
307   myButtonGrpLayout->addWidget( myOkBtn );
308   if ( mySelection ) {
309     myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp, "myApplyBtn" );
310     myApplyBtn->setAutoDefault( TRUE );
311     myButtonGrpLayout->addWidget( myApplyBtn );
312   }
313   myButtonGrpLayout->addStretch();
314   myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), myButtonGrp, "myCancelBtn" );
315   if ( mySelection )
316     myCancelBtn->setText( tr( "SMESH_BUT_CLOSE" ) );
317   myCancelBtn->setAutoDefault( TRUE );
318   myButtonGrpLayout->addWidget( myCancelBtn );
319
320   aTopLayout->addWidget( myButtonGrp, aRow, 0 );
321
322   /***************************************************************/
323   // Init
324   // --> first init from preferences
325   QColor titleColor( 255, 255, 255 );
326   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleColor" ) ) {
327     QStringList aTColor = QStringList::split(  ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleColor" ), false );
328     titleColor = QColor( ( aTColor.count() > 0 ? aTColor[0].toInt() : 255 ), 
329                          ( aTColor.count() > 1 ? aTColor[1].toInt() : 255 ), 
330                          ( aTColor.count() > 2 ? aTColor[2].toInt() : 255 ) );
331   }
332   myTitleColorBtn->setPaletteBackgroundColor( titleColor );
333   myTitleFontCombo->setCurrentItem( 0 );
334   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleFont" ) ) {
335     if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Arial" )
336       myTitleFontCombo->setCurrentItem( 0 );
337     if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Courier" )
338       myTitleFontCombo->setCurrentItem( 1 );
339     if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Times" )
340       myTitleFontCombo->setCurrentItem( 2 );
341   }
342   myTitleBoldCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleBold" ) == "true" );
343   myTitleItalicCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleItalic" ) == "true" );
344   myTitleShadowCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleShadow" ) == "true" );
345
346   QColor labelColor( 255, 255, 255 );
347   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelColor" ) ) {
348     QStringList aLColor = QStringList::split( ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelColor" ), false );
349     labelColor = QColor( ( aLColor.count() > 0 ? aLColor[0].toInt() : 255 ), 
350                          ( aLColor.count() > 1 ? aLColor[1].toInt() : 255 ), 
351                          ( aLColor.count() > 2 ? aLColor[2].toInt() : 255 ) );
352   }
353   myLabelsColorBtn->setPaletteBackgroundColor( labelColor );
354   myLabelsFontCombo->setCurrentItem( 0 );
355   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelFont" ) ) {
356     if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Arial" )
357       myLabelsFontCombo->setCurrentItem( 0 );
358     if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Courier" )
359       myLabelsFontCombo->setCurrentItem( 1 );
360     if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Times" )
361       myLabelsFontCombo->setCurrentItem( 2 );
362   }
363   myLabelsBoldCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelBold" ) == "true" );
364   myLabelsItalicCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelItalic" ) == "true" );
365   myLabelsShadowCheck->setChecked( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelShadow" ) == "true" );
366
367   int aNbColors = 64;
368   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfColors" ) )
369     aNbColors = QAD_CONFIG->getSetting( "SMESH:ScalarBarNbOfColors" ).toInt();
370   myColorsSpin->setValue( aNbColors );
371   int aNbLabels = 5;
372   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfLabels" ) )
373     aNbLabels = QAD_CONFIG->getSetting( "SMESH:ScalarBarNbOfLabels" ).toInt();
374   myLabelsSpin->setValue( aNbLabels );
375
376   QString aOrientation = QAD_CONFIG->getSetting( "SMESH:ScalarBarOrientation" );
377   if ( aOrientation == "Horizontal" )
378     myHorizRadioBtn->setChecked( true );
379   else
380     myVertRadioBtn->setChecked( true );
381   myIniOrientation = myVertRadioBtn->isChecked();
382
383   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarXPosition" ) )
384     myIniX = QAD_CONFIG->getSetting( "SMESH:ScalarBarXPosition" ).toDouble();
385   else
386     myIniX = myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X;
387   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarYPosition" ) )
388     myIniY = QAD_CONFIG->getSetting( "SMESH:ScalarBarYPosition" ).toDouble();
389   else
390     myIniY = myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y;
391   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarWidth" ) )
392     myIniW = QAD_CONFIG->getSetting( "SMESH:ScalarBarWidth" ).toDouble();
393   else
394     myIniW = myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W;
395   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarHeight" ) )
396     myIniH = QAD_CONFIG->getSetting( "SMESH:ScalarBarHeight" ).toDouble();
397   else
398     myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
399   setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
400
401   if ( mySelection ) {
402     // --> then init from selection if necessary
403     onSelectionChanged();
404   }
405   
406   /***************************************************************/
407   // Connect section
408   connect( myTitleColorBtn,     SIGNAL( clicked() ), this, SLOT( onTitleColor() ) );
409   connect( myLabelsColorBtn,    SIGNAL( clicked() ), this, SLOT( onLabelsColor() ) );
410   connect( myOkBtn,             SIGNAL( clicked() ), this, SLOT( onOk() ) );
411   connect( myCancelBtn,         SIGNAL( clicked() ), this, SLOT( onCancel() ) );
412   connect( myXSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
413   connect( myYSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
414   connect( myOrientationGrp,    SIGNAL( clicked( int ) ), this, SLOT( onOrientationChanged() ) );
415   if ( mySelection ) {
416     connect( myApplyBtn,        SIGNAL( clicked() ), this, SLOT( onApply() ) );
417     connect( mySelection,       SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
418   }
419   connect( SMESHGUI::GetSMESHGUI(),  SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
420 }
421
422 //=================================================================================================
423 /*!
424  *  SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
425  *
426  *  Destructor
427  */
428 //=================================================================================================
429 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
430 {
431 }
432
433 //=================================================================================================
434 /*!
435  *  SMESHGUI_Preferences_ScalarBarDlg::onOk
436  *
437  *  OK button slot
438  */
439 //=================================================================================================
440 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
441 {
442   if ( onApply() )
443     onCancel();
444 }
445
446 //=================================================================================================
447 /*!
448  *  SMESHGUI_Preferences_ScalarBarDlg::onApply
449  *
450  *  Apply button slot
451  */
452 //=================================================================================================
453 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
454 {
455   if ( mySelection ) {
456     // Scalar Bar properties
457     if ( !myActor )
458       return false;
459     vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
460
461     vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
462     QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
463     aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
464     if ( myTitleFontCombo->currentItem() == 0 )
465       aTitleTextPrp->SetFontFamilyToArial();
466     else if ( myTitleFontCombo->currentItem() == 1 )
467       aTitleTextPrp->SetFontFamilyToCourier();
468     else
469       aTitleTextPrp->SetFontFamilyToTimes();
470     aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
471     aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
472     aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
473     myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
474
475     vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
476     QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
477     aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
478     if ( myLabelsFontCombo->currentItem() == 0 )
479       aLabelsTextPrp->SetFontFamilyToArial();
480     else if ( myLabelsFontCombo->currentItem() == 1 )
481       aLabelsTextPrp->SetFontFamilyToCourier();
482     else
483       aLabelsTextPrp->SetFontFamilyToTimes();
484     aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
485     aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
486     aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
487     myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
488
489     myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
490     myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
491
492     if ( myHorizRadioBtn->isChecked() )
493       myScalarBarActor->SetOrientationToHorizontal();
494     else
495       myScalarBarActor->SetOrientationToVertical();
496
497     myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
498     myScalarBarActor->SetWidth( myWidthSpin->value() );
499     myScalarBarActor->SetHeight( myHeightSpin->value() );
500
501     double aMin = myMinEdit->text().toDouble();
502     double aMax = myMaxEdit->text().toDouble();
503     myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
504     SMESH::RepaintCurrentView();
505   }
506   else {
507     // Scalar Bar preferences
508     QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
509     QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleColor",  QString().sprintf( "%d:%d:%d", titleColor.red(), titleColor.green(), titleColor.blue() ) );
510     if ( myTitleFontCombo->currentItem() == 0 )
511       QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Arial" );
512     else if ( myTitleFontCombo->currentItem() == 1 )
513       QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Courier" );
514     else
515       QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleFont", "Times" );
516     QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleBold",   myTitleBoldCheck->isChecked() ?   "true" : "false" );
517     QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleItalic", myTitleItalicCheck->isChecked() ? "true" : "false" );
518     QAD_CONFIG->addSetting( "SMESH:ScalarBarTitleShadow", myTitleShadowCheck->isChecked() ? "true" : "false" );
519
520     QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
521     QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelColor",  QString().sprintf( "%d:%d:%d", labelColor.red(), labelColor.green(),labelColor. blue() ) );
522     if ( myLabelsFontCombo->currentItem() == 0 )
523       QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Arial" );
524     else if ( myLabelsFontCombo->currentItem() == 1 )
525       QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Courier" );
526     else
527       QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelFont", "Times" );
528     QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelBold",   myLabelsBoldCheck->isChecked() ?   "true" : "false" );
529     QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelItalic", myLabelsItalicCheck->isChecked() ? "true" : "false" );
530     QAD_CONFIG->addSetting( "SMESH:ScalarBarLabelShadow", myLabelsShadowCheck->isChecked() ? "true" : "false" );
531
532     QAD_CONFIG->addSetting( "SMESH:ScalarBarNbOfColors", myColorsSpin->value() );
533     QAD_CONFIG->addSetting( "SMESH:ScalarBarNbOfLabels", myLabelsSpin->value() );
534
535     QAD_CONFIG->addSetting( "SMESH:ScalarBarOrientation", myHorizRadioBtn->isChecked() ? "Horizontal" : "Vertical" );
536     
537     QAD_CONFIG->addSetting( "SMESH:ScalarBarXPosition", myXSpin->value() );
538     QAD_CONFIG->addSetting( "SMESH:ScalarBarYPosition", myYSpin->value() );
539     QAD_CONFIG->addSetting( "SMESH:ScalarBarWidth",     myWidthSpin->value() );
540     QAD_CONFIG->addSetting( "SMESH:ScalarBarHeight",    myHeightSpin->value() );
541   }
542   return true;
543 }
544
545 //=================================================================================================
546 /*!
547  *  SMESHGUI_Preferences_ScalarBarDlg::onCancel
548  *
549  *  Cancel button slot
550  */
551 //=================================================================================================
552 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
553 {
554   close();
555 }
556
557 //=================================================================================================
558 /*!
559  *  SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
560  *
561  *  Change Title color button slot
562  */
563 //=================================================================================================
564 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
565 {
566   QColor aColor = myTitleColorBtn->paletteBackgroundColor();
567   aColor = QColorDialog::getColor( aColor, this );
568   if ( aColor.isValid() ) 
569     myTitleColorBtn->setPaletteBackgroundColor( aColor );
570 }
571
572 //=================================================================================================
573 /*!
574  *  SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
575  *
576  *  Change Labels color button slot
577  */
578 //=================================================================================================
579 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
580 {
581   QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
582   aColor = QColorDialog::getColor( aColor, this );
583   if ( aColor.isValid() ) 
584     myLabelsColorBtn->setPaletteBackgroundColor( aColor );
585 }
586
587 //=================================================================================================
588 /*!
589  *  SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
590  *
591  *  Called when selection changed
592  */
593 //=================================================================================================
594 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
595 {
596   if( mySelection ) {
597     if ( mySelection->IObjectCount() == 1 ) {
598       Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
599       if( anIO->hasEntry() ) {
600         SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
601         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
602           myActor = anActor;
603           vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
604           
605           if ( myScalarBarActor->GetLookupTable() ) {
606             float *range = myScalarBarActor->GetLookupTable()->GetRange();
607             myMinEdit->setText( QString::number( range[0] ) );
608             myMaxEdit->setText( QString::number( range[1] ) );
609           }
610
611           vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
612           float aTColor[3];
613           aTitleTextPrp->GetColor( aTColor );
614           myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
615           myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
616           myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
617           myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
618           myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
619
620           vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
621           float aLColor[3];
622           aLabelsTextPrp->GetColor( aLColor );
623           myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
624           myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
625           myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
626           myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
627           myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
628
629           myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
630           myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
631
632           if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
633             myVertRadioBtn->setChecked( true );
634           else
635             myHorizRadioBtn->setChecked( true );
636           myIniOrientation = myVertRadioBtn->isChecked();
637           
638           myIniX = myScalarBarActor->GetPosition()[0];
639           myIniY = myScalarBarActor->GetPosition()[1];
640           myIniW = myScalarBarActor->GetWidth();
641           myIniH = myScalarBarActor->GetHeight();
642           setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
643
644           myRangeGrp->setEnabled( true );
645           myFontGrp->setEnabled( true );
646           myLabColorGrp->setEnabled( true );
647           myOrientationGrp->setEnabled( true );
648           myOriginDimGrp->setEnabled( true );
649           myOkBtn->setEnabled( true );
650           myApplyBtn->setEnabled( true );
651           return;
652         }
653       }
654     }
655     myActor = 0;
656     myRangeGrp->setEnabled( false );
657     myFontGrp->setEnabled( false );
658     myLabColorGrp->setEnabled( false );
659     myOrientationGrp->setEnabled( false );
660     myOriginDimGrp->setEnabled( false );
661     myOkBtn->setEnabled( false );
662     myApplyBtn->setEnabled( false );
663   }
664 }
665
666 //=================================================================================================
667 /*!
668  *  SMESHGUI_Preferences_ScalarBarDlg::closeEvent
669  *
670  *  Close event handler
671  */
672 //=================================================================================================
673 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
674 {
675   if ( mySelection ) // "Properties" dialog box
676     myDlg = 0;
677   QDialog::closeEvent( e );
678 }
679
680 //=================================================================================================
681 /*!
682  *  SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
683  *
684  *  Called when X, Y values are changed
685  */
686 //=================================================================================================
687 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
688 {
689   myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
690   myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
691 }
692
693 //=================================================================================================
694 /*!
695  *  SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
696  *
697  *  Called when X, Y values are changed
698  */
699 //=================================================================================================
700 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
701                                                           const double y,
702                                                           const double w,
703                                                           const double h )
704 {
705   blockSignals( true );
706   myXSpin->setValue( x );
707   myYSpin->setValue( y );
708   myWidthSpin->setMaxValue( 1.0 );
709   myWidthSpin->setValue( w );
710   myHeightSpin->setMaxValue( 1.0 );
711   myHeightSpin->setValue( h );
712   blockSignals( false );
713   onXYChanged();
714 }
715
716 //=================================================================================================
717 /*!
718  *  SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
719  *
720  *  Called when orientation is changed
721  */
722 //=================================================================================================
723 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged() 
724 {
725   int aOrientation = myVertRadioBtn->isChecked();
726   if ( aOrientation == myIniOrientation )
727     setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
728   else
729     setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X, 
730                       aOrientation ? DEF_VER_Y : DEF_HOR_Y, 
731                       aOrientation ? DEF_VER_W : DEF_HOR_W, 
732                       aOrientation ? DEF_VER_H : DEF_HOR_H );
733 }