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