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