Salome HOME
The selections of elements corrected.
[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, false);
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, true);
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", "ScalarBarTitleColor")) {
333     QStringList aTColor =
334       QStringList::split(":", mgr->stringValue("SMESH", "ScalarBarTitleColor"), 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", "ScalarBarTitleFont")) {
342     if (mgr->stringValue("SMESH", "ScalarBarTitleFont") == "Arial")
343       myTitleFontCombo->setCurrentItem(0);
344     if (mgr->stringValue("SMESH", "ScalarBarTitleFont") == "Courier")
345       myTitleFontCombo->setCurrentItem(1);
346     if (mgr->stringValue("SMESH", "ScalarBarTitleFont") == "Times")
347       myTitleFontCombo->setCurrentItem(2);
348   }
349   myTitleBoldCheck->setChecked  (mgr && mgr->stringValue("SMESH", "ScalarBarTitleBold")   == "true");
350   myTitleItalicCheck->setChecked(mgr && mgr->stringValue("SMESH", "ScalarBarTitleItalic") == "true");
351   myTitleShadowCheck->setChecked(mgr && mgr->stringValue("SMESH", "ScalarBarTitleShadow") == "true");
352
353   QColor labelColor (255, 255, 255);
354   if (mgr && mgr->hasValue("SMESH", "ScalarBarLabelColor")) {
355     QStringList aLColor =
356       QStringList::split(":", mgr->stringValue("SMESH", "ScalarBarLabelColor"), false);
357     labelColor = QColor((aLColor.count() > 0 ? aLColor[0].toInt() : 255),
358                         (aLColor.count() > 1 ? aLColor[1].toInt() : 255),
359                         (aLColor.count() > 2 ? aLColor[2].toInt() : 255));
360   }
361   myLabelsColorBtn->setPaletteBackgroundColor(labelColor);
362   myLabelsFontCombo->setCurrentItem(0);
363   if (mgr && mgr->hasValue("SMESH", "ScalarBarLabelFont")) {
364     if (mgr->stringValue("SMESH", "ScalarBarLabelFont") == "Arial")
365       myLabelsFontCombo->setCurrentItem(0);
366     if (mgr->stringValue("SMESH", "ScalarBarLabelFont") == "Courier")
367       myLabelsFontCombo->setCurrentItem(1);
368     if (mgr->stringValue("SMESH", "ScalarBarLabelFont") == "Times")
369       myLabelsFontCombo->setCurrentItem(2);
370   }
371   myLabelsBoldCheck  ->setChecked(mgr && mgr->stringValue("SMESH", "ScalarBarLabelBold")   == "true");
372   myLabelsItalicCheck->setChecked(mgr && mgr->stringValue("SMESH", "ScalarBarLabelItalic") == "true");
373   myLabelsShadowCheck->setChecked(mgr && mgr->stringValue("SMESH", "ScalarBarLabelShadow") == "true");
374
375   int aNbColors = 64;
376   if (mgr && mgr->hasValue("SMESH", "ScalarBarNbOfColors"))
377     aNbColors = mgr->integerValue("SMESH", "ScalarBarNbOfColors");
378   myColorsSpin->setValue(aNbColors);
379
380   int aNbLabels = 5;
381   if (mgr && mgr->hasValue("SMESH", "ScalarBarNbOfLabels"))
382     aNbLabels = mgr->integerValue("SMESH", "ScalarBarNbOfLabels");
383   myLabelsSpin->setValue(aNbLabels);
384
385   QString aOrientation = (mgr ? mgr->stringValue("SMESH", "ScalarBarOrientation") : "");
386   if (aOrientation == "Horizontal")
387     myHorizRadioBtn->setChecked(true);
388   else
389     myVertRadioBtn->setChecked(true);
390   myIniOrientation = myVertRadioBtn->isChecked();
391
392   if (mgr && mgr->hasValue("SMESH", "ScalarBarXPosition"))
393     myIniX = mgr->doubleValue("SMESH", "ScalarBarXPosition");
394   else
395     myIniX = myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X;
396
397   if (mgr && mgr->hasValue("SMESH", "ScalarBarYPosition"))
398     myIniY = mgr->doubleValue("SMESH", "ScalarBarYPosition");
399   else
400     myIniY = myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y;
401
402   if (mgr && mgr->hasValue("SMESH", "ScalarBarWidth"))
403     myIniW = mgr->doubleValue("SMESH", "ScalarBarWidth");
404   else
405     myIniW = myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W;
406
407   if (mgr && mgr->hasValue("SMESH", "ScalarBarHeight"))
408     myIniH = mgr->doubleValue("SMESH", "ScalarBarHeight");
409   else
410     myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
411
412   setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
413
414   if (mySelectionMgr) {
415     // --> then init from selection if necessary
416     onSelectionChanged();
417   }
418
419   /***************************************************************/
420   // Connect section
421   connect( myTitleColorBtn,     SIGNAL( clicked() ), this, SLOT( onTitleColor() ) );
422   connect( myLabelsColorBtn,    SIGNAL( clicked() ), this, SLOT( onLabelsColor() ) );
423   connect( myOkBtn,             SIGNAL( clicked() ), this, SLOT( onOk() ) );
424   connect( myCancelBtn,         SIGNAL( clicked() ), this, SLOT( onCancel() ) );
425   connect( myXSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
426   connect( myYSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
427   connect( myOrientationGrp,    SIGNAL( clicked( int ) ), this, SLOT( onOrientationChanged() ) );
428   if ( mySelectionMgr ) {
429     connect( myApplyBtn,        SIGNAL( clicked() ), this, SLOT( onApply() ) );
430     connect( mySelectionMgr,    SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
431   }
432   connect( mySMESHGUI,  SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
433 }
434
435 //=================================================================================================
436 /*!
437  *  SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
438  *
439  *  Destructor
440  */
441 //=================================================================================================
442 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
443 {
444 }
445
446 //=================================================================================================
447 /*!
448  *  SMESHGUI_Preferences_ScalarBarDlg::onOk
449  *
450  *  OK button slot
451  */
452 //=================================================================================================
453 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
454 {
455   if ( onApply() )
456     onCancel();
457 }
458
459 //=================================================================================================
460 /*!
461  *  SMESHGUI_Preferences_ScalarBarDlg::onApply
462  *
463  *  Apply button slot
464  */
465 //=================================================================================================
466 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
467 {
468   if (mySelectionMgr) {
469     // Scalar Bar properties
470     if (!myActor)
471       return false;
472     vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
473
474     vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
475     QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
476     aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
477     if ( myTitleFontCombo->currentItem() == 0 )
478       aTitleTextPrp->SetFontFamilyToArial();
479     else if ( myTitleFontCombo->currentItem() == 1 )
480       aTitleTextPrp->SetFontFamilyToCourier();
481     else
482       aTitleTextPrp->SetFontFamilyToTimes();
483     aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
484     aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
485     aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
486     myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
487
488     vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
489     QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
490     aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
491     if ( myLabelsFontCombo->currentItem() == 0 )
492       aLabelsTextPrp->SetFontFamilyToArial();
493     else if ( myLabelsFontCombo->currentItem() == 1 )
494       aLabelsTextPrp->SetFontFamilyToCourier();
495     else
496       aLabelsTextPrp->SetFontFamilyToTimes();
497     aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
498     aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
499     aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
500     myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
501
502     myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
503     myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
504
505     if ( myHorizRadioBtn->isChecked() )
506       myScalarBarActor->SetOrientationToHorizontal();
507     else
508       myScalarBarActor->SetOrientationToVertical();
509
510     myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
511     myScalarBarActor->SetWidth( myWidthSpin->value() );
512     myScalarBarActor->SetHeight( myHeightSpin->value() );
513
514     double aMin = myMinEdit->text().toDouble();
515     double aMax = myMaxEdit->text().toDouble();
516     myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
517     SMESH::RepaintCurrentView();
518   } else {
519     // Scalar Bar preferences
520     SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
521     if (!mgr) return false;
522
523     QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
524     mgr->setValue("SMESH", "ScalarBarTitleColor",
525                   QString().sprintf("%d:%d:%d", titleColor.red(), titleColor.green(), titleColor.blue()));
526     if (myTitleFontCombo->currentItem() == 0)
527       mgr->setValue("SMESH", "ScalarBarTitleFont", "Arial");
528     else if (myTitleFontCombo->currentItem() == 1)
529       mgr->setValue("SMESH", "ScalarBarTitleFont", "Courier");
530     else
531       mgr->setValue("SMESH", "ScalarBarTitleFont", "Times");
532
533     mgr->setValue("SMESH", "ScalarBarTitleBold"  , myTitleBoldCheck  ->isChecked() ? "true" : "false");
534     mgr->setValue("SMESH", "ScalarBarTitleItalic", myTitleItalicCheck->isChecked() ? "true" : "false");
535     mgr->setValue("SMESH", "ScalarBarTitleShadow", myTitleShadowCheck->isChecked() ? "true" : "false");
536
537     QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
538     mgr->setValue("SMESH", "ScalarBarLabelColor",
539                   QString().sprintf("%d:%d:%d", labelColor.red(), labelColor.green(),labelColor. blue()));
540
541     if (myLabelsFontCombo->currentItem() == 0)
542       mgr->setValue("SMESH", "ScalarBarLabelFont", "Arial");
543     else if ( myLabelsFontCombo->currentItem() == 1 )
544       mgr->setValue("SMESH", "ScalarBarLabelFont", "Courier");
545     else
546       mgr->setValue("SMESH", "ScalarBarLabelFont", "Times");
547
548     mgr->setValue("SMESH", "ScalarBarLabelBold",   myLabelsBoldCheck->isChecked()   ? "true" : "false");
549     mgr->setValue("SMESH", "ScalarBarLabelItalic", myLabelsItalicCheck->isChecked() ? "true" : "false");
550     mgr->setValue("SMESH", "ScalarBarLabelShadow", myLabelsShadowCheck->isChecked() ? "true" : "false");
551
552     mgr->setValue("SMESH", "ScalarBarNbOfColors", myColorsSpin->value());
553     mgr->setValue("SMESH", "ScalarBarNbOfLabels", myLabelsSpin->value());
554
555     mgr->setValue("SMESH", "ScalarBarOrientation", myHorizRadioBtn->isChecked() ? "Horizontal" : "Vertical");
556
557     mgr->setValue("SMESH", "ScalarBarXPosition", myXSpin->value());
558     mgr->setValue("SMESH", "ScalarBarYPosition", myYSpin->value());
559     mgr->setValue("SMESH", "ScalarBarWidth",     myWidthSpin->value());
560     mgr->setValue("SMESH", "ScalarBarHeight",    myHeightSpin->value());
561   }
562   return true;
563 }
564
565 //=================================================================================================
566 /*!
567  *  SMESHGUI_Preferences_ScalarBarDlg::onCancel
568  *
569  *  Cancel button slot
570  */
571 //=================================================================================================
572 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
573 {
574   close();
575 }
576
577 //=================================================================================================
578 /*!
579  *  SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
580  *
581  *  Change Title color button slot
582  */
583 //=================================================================================================
584 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
585 {
586   QColor aColor = myTitleColorBtn->paletteBackgroundColor();
587   aColor = QColorDialog::getColor( aColor, this );
588   if ( aColor.isValid() )
589     myTitleColorBtn->setPaletteBackgroundColor( aColor );
590 }
591
592 //=================================================================================================
593 /*!
594  *  SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
595  *
596  *  Change Labels color button slot
597  */
598 //=================================================================================================
599 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
600 {
601   QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
602   aColor = QColorDialog::getColor( aColor, this );
603   if ( aColor.isValid() )
604     myLabelsColorBtn->setPaletteBackgroundColor( aColor );
605 }
606
607 //=================================================================================================
608 /*!
609  *  SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
610  *
611  *  Called when selection changed
612  */
613 //=================================================================================================
614 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
615 {
616   if (mySelectionMgr) {
617     SALOME_ListIO aList;
618     mySelectionMgr->selectedObjects(aList);
619
620     if (aList.Extent() == 1) {
621       Handle(SALOME_InteractiveObject) anIO = aList.First();
622       if( anIO->hasEntry() ) {
623         SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
624         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
625           myActor = anActor;
626           vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
627
628           if ( myScalarBarActor->GetLookupTable() ) {
629             float *range = myScalarBarActor->GetLookupTable()->GetRange();
630             myMinEdit->setText( QString::number( range[0] ) );
631             myMaxEdit->setText( QString::number( range[1] ) );
632           }
633
634           vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
635           float aTColor[3];
636           aTitleTextPrp->GetColor( aTColor );
637           myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
638           myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
639           myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
640           myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
641           myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
642
643           vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
644           float aLColor[3];
645           aLabelsTextPrp->GetColor( aLColor );
646           myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
647           myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
648           myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
649           myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
650           myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
651
652           myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
653           myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
654
655           if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
656             myVertRadioBtn->setChecked( true );
657           else
658             myHorizRadioBtn->setChecked( true );
659           myIniOrientation = myVertRadioBtn->isChecked();
660
661           myIniX = myScalarBarActor->GetPosition()[0];
662           myIniY = myScalarBarActor->GetPosition()[1];
663           myIniW = myScalarBarActor->GetWidth();
664           myIniH = myScalarBarActor->GetHeight();
665           setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
666
667           myRangeGrp->setEnabled( true );
668           myFontGrp->setEnabled( true );
669           myLabColorGrp->setEnabled( true );
670           myOrientationGrp->setEnabled( true );
671           myOriginDimGrp->setEnabled( true );
672           myOkBtn->setEnabled( true );
673           myApplyBtn->setEnabled( true );
674           return;
675         }
676       }
677     }
678     myActor = 0;
679     myRangeGrp->setEnabled( false );
680     myFontGrp->setEnabled( false );
681     myLabColorGrp->setEnabled( false );
682     myOrientationGrp->setEnabled( false );
683     myOriginDimGrp->setEnabled( false );
684     myOkBtn->setEnabled( false );
685     myApplyBtn->setEnabled( false );
686   }
687 }
688
689 //=================================================================================================
690 /*!
691  *  SMESHGUI_Preferences_ScalarBarDlg::closeEvent
692  *
693  *  Close event handler
694  */
695 //=================================================================================================
696 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
697 {
698   if ( mySelectionMgr ) // "Properties" dialog box
699     myDlg = 0;
700   QDialog::closeEvent( e );
701 }
702
703 //=================================================================================================
704 /*!
705  *  SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
706  *
707  *  Called when X, Y values are changed
708  */
709 //=================================================================================================
710 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
711 {
712   myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
713   myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
714 }
715
716 //=================================================================================================
717 /*!
718  *  SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
719  *
720  *  Called when X, Y values are changed
721  */
722 //=================================================================================================
723 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
724                                                           const double y,
725                                                           const double w,
726                                                           const double h )
727 {
728   blockSignals( true );
729   myXSpin->setValue( x );
730   myYSpin->setValue( y );
731   myWidthSpin->setMaxValue( 1.0 );
732   myWidthSpin->setValue( w );
733   myHeightSpin->setMaxValue( 1.0 );
734   myHeightSpin->setValue( h );
735   blockSignals( false );
736   onXYChanged();
737 }
738
739 //=================================================================================================
740 /*!
741  *  SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
742  *
743  *  Called when orientation is changed
744  */
745 //=================================================================================================
746 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
747 {
748   int aOrientation = myVertRadioBtn->isChecked();
749   if ( aOrientation == myIniOrientation )
750     setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
751   else
752     setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
753                       aOrientation ? DEF_VER_Y : DEF_HOR_Y,
754                       aOrientation ? DEF_VER_W : DEF_HOR_W,
755                       aOrientation ? DEF_VER_H : DEF_HOR_H );
756 }