Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 <vtkLookupTable.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     vtkLookupTable* myLookupTable =
524       static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
525     myLookupTable->SetRange( aMin, aMax );
526     myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
527     myLookupTable->Build();
528     SMESH::RepaintCurrentView();
529   } else {
530     // Scalar Bar preferences
531     SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
532     if (!mgr) return false;
533
534     QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
535     mgr->setValue("SMESH", "scalar_bar_title_color", titleColor );
536
537     QFont f;
538     if (myTitleFontCombo->currentItem() == 0)
539       f.setFamily( "Arial" );
540     else if (myTitleFontCombo->currentItem() == 1)
541       f.setFamily( "Courier" );
542     else
543       f.setFamily( "Times");
544
545     f.setBold( myTitleBoldCheck  ->isChecked() );
546     f.setItalic( myTitleItalicCheck->isChecked() );
547     f.setUnderline( myTitleShadowCheck->isChecked() );
548     mgr->setValue( "SMESH", "scalar_bar_title_font", f );
549
550     QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
551     mgr->setValue("SMESH", "scalar_bar_label_color", labelColor );
552
553     if (myLabelsFontCombo->currentItem() == 0)
554       f.setFamily( "Arial" );
555     else if ( myLabelsFontCombo->currentItem() == 1 )
556       f.setFamily( "Courier");
557     else
558       f.setFamily( "Times");
559
560     f.setBold( myLabelsBoldCheck  ->isChecked() );
561     f.setItalic( myLabelsItalicCheck->isChecked() );
562     f.setUnderline( myLabelsShadowCheck->isChecked() );
563     mgr->setValue( "SMESH", "scalar_bar_label_font", f );
564
565     mgr->setValue("SMESH", "scalar_bar_num_colors", myColorsSpin->value());
566     mgr->setValue("SMESH", "scalar_bar_num_labels", myLabelsSpin->value());
567
568     mgr->setValue("SMESH", "scalar_bar_orientation", myHorizRadioBtn->isChecked() ? 1 : 0 );
569
570     QString name = myHorizRadioBtn->isChecked() ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
571     mgr->setValue("SMESH", name.arg( "x" ), myXSpin->value());
572     mgr->setValue("SMESH", name.arg( "y" ), myYSpin->value());
573     mgr->setValue("SMESH", name.arg( "width" ),     myWidthSpin->value());
574     mgr->setValue("SMESH", name.arg( "height" ),    myHeightSpin->value());
575   }
576   return true;
577 }
578
579 //=================================================================================================
580 /*!
581  *  SMESHGUI_Preferences_ScalarBarDlg::onCancel
582  *
583  *  Cancel button slot
584  */
585 //=================================================================================================
586 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
587 {
588   close();
589 }
590
591 //=================================================================================================
592 /*!
593  *  SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
594  *
595  *  Change Title color button slot
596  */
597 //=================================================================================================
598 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
599 {
600   QColor aColor = myTitleColorBtn->paletteBackgroundColor();
601   aColor = QColorDialog::getColor( aColor, this );
602   if ( aColor.isValid() )
603     myTitleColorBtn->setPaletteBackgroundColor( aColor );
604 }
605
606 //=================================================================================================
607 /*!
608  *  SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
609  *
610  *  Change Labels color button slot
611  */
612 //=================================================================================================
613 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
614 {
615   QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
616   aColor = QColorDialog::getColor( aColor, this );
617   if ( aColor.isValid() )
618     myLabelsColorBtn->setPaletteBackgroundColor( aColor );
619 }
620
621 //=================================================================================================
622 /*!
623  *  SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
624  *
625  *  Called when selection changed
626  */
627 //=================================================================================================
628 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
629 {
630   if (mySelectionMgr) {
631     SALOME_ListIO aList;
632     mySelectionMgr->selectedObjects(aList);
633
634     if (aList.Extent() == 1) {
635       Handle(SALOME_InteractiveObject) anIO = aList.First();
636       if( anIO->hasEntry() ) {
637         SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
638         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
639           myActor = anActor;
640           vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
641
642           if ( myScalarBarActor->GetLookupTable() ) {
643             vtkFloatingPointType *range = myScalarBarActor->GetLookupTable()->GetRange();
644             myMinEdit->setText( QString::number( range[0],'g',12 ) );
645             myMaxEdit->setText( QString::number( range[1],'g',12 ) );
646           }
647
648           vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
649           vtkFloatingPointType aTColor[3];
650           aTitleTextPrp->GetColor( aTColor );
651           myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
652           myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
653           myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
654           myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
655           myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
656
657           vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
658           vtkFloatingPointType aLColor[3];
659           aLabelsTextPrp->GetColor( aLColor );
660           myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
661           myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
662           myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
663           myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
664           myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
665
666           myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
667           myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
668
669           if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
670             myVertRadioBtn->setChecked( true );
671           else
672             myHorizRadioBtn->setChecked( true );
673           myIniOrientation = myVertRadioBtn->isChecked();
674
675           myIniX = myScalarBarActor->GetPosition()[0];
676           myIniY = myScalarBarActor->GetPosition()[1];
677           myIniW = myScalarBarActor->GetWidth();
678           myIniH = myScalarBarActor->GetHeight();
679           setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
680
681           myRangeGrp->setEnabled( true );
682           myFontGrp->setEnabled( true );
683           myLabColorGrp->setEnabled( true );
684           myOrientationGrp->setEnabled( true );
685           myOriginDimGrp->setEnabled( true );
686           myOkBtn->setEnabled( true );
687           myApplyBtn->setEnabled( true );
688           return;
689         }
690       }
691     }
692     myActor = 0;
693     myRangeGrp->setEnabled( false );
694     myFontGrp->setEnabled( false );
695     myLabColorGrp->setEnabled( false );
696     myOrientationGrp->setEnabled( false );
697     myOriginDimGrp->setEnabled( false );
698     myOkBtn->setEnabled( false );
699     myApplyBtn->setEnabled( false );
700   }
701 }
702
703 //=================================================================================================
704 /*!
705  *  SMESHGUI_Preferences_ScalarBarDlg::closeEvent
706  *
707  *  Close event handler
708  */
709 //=================================================================================================
710 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
711 {
712   if ( mySelectionMgr ) // "Properties" dialog box
713     myDlg = 0;
714   QDialog::closeEvent( e );
715 }
716
717 //=================================================================================================
718 /*!
719  *  SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
720  *
721  *  Called when X, Y values are changed
722  */
723 //=================================================================================================
724 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
725 {
726   myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
727   myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
728 }
729
730 //=================================================================================================
731 /*!
732  *  SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
733  *
734  *  Called when X, Y values are changed
735  */
736 //=================================================================================================
737 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
738                                                           const double y,
739                                                           const double w,
740                                                           const double h )
741 {
742   blockSignals( true );
743   myXSpin->setValue( x );
744   myYSpin->setValue( y );
745   myWidthSpin->setMaxValue( 1.0 );
746   myWidthSpin->setValue( w );
747   myHeightSpin->setMaxValue( 1.0 );
748   myHeightSpin->setValue( h );
749   blockSignals( false );
750   onXYChanged();
751 }
752
753 //=================================================================================================
754 /*!
755  *  SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
756  *
757  *  Called when orientation is changed
758  */
759 //=================================================================================================
760 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
761 {
762   this->initScalarBarFromResources();
763
764   int aOrientation = myVertRadioBtn->isChecked();
765   if ( aOrientation == myIniOrientation )
766     setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
767   else
768     setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
769                       aOrientation ? DEF_VER_Y : DEF_HOR_Y,
770                       aOrientation ? DEF_VER_W : DEF_HOR_W,
771                       aOrientation ? DEF_VER_H : DEF_HOR_H );
772 }
773
774 //=================================================================================================
775 /*!
776  *  SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
777  *
778  *  Rereading vertical and horizontal default positions from resources.
779  */
780 //=================================================================================================
781 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
782 {
783   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
784   QString name;
785   if (mgr){
786     // initialize from resoources
787     
788     // horizontal
789     name = QString("scalar_bar_horizontal_%1");
790     if (mgr->hasValue("SMESH", name.arg( "x" )))
791       DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
792     if (mgr->hasValue("SMESH", name.arg( "y" )))
793       DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
794     if (mgr->hasValue("SMESH", name.arg( "width" )))
795       DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
796     if (mgr->hasValue("SMESH", name.arg( "height" )))
797       DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
798
799     // vertical
800     name = QString("scalar_bar_vertical_%1");
801     if (mgr->hasValue("SMESH", name.arg( "x" )))
802       DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
803     if (mgr->hasValue("SMESH", name.arg( "y" )))
804       DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
805     if (mgr->hasValue("SMESH", name.arg( "width" )))
806       DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
807     if (mgr->hasValue("SMESH", name.arg( "height" )))
808       DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));
809   }
810 }