Salome HOME
Issue 0020406: Time compilation when recompiling
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Preferences_ScalarBarDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  SMESH SMESHGUI : GUI for SMESH component
23 //  File   : SMESHGUI_Preferences_ScalarBarDlg.cxx
24 //  Author : Nicolas REJNERI
25 //  Module : SMESH
26 //  $Header$
27 //
28 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_Utils.h"
33
34 #include "SMESH_Actor.h"
35
36 #include "SUIT_Desktop.h"
37 #include "SUIT_ResourceMgr.h"
38
39 #include "LightApp_SelectionMgr.h"
40 #include "SALOME_ListIO.hxx"
41
42 #include <QtxDblSpinBox.h>
43
44 #include <qbuttongroup.h>
45 #include <qcheckbox.h>
46 #include <qcombobox.h>
47 #include <qgroupbox.h>
48 #include <qlabel.h>
49 #include <qlineedit.h>
50 #include <qpushbutton.h>
51 #include <qtoolbutton.h>
52 #include <qradiobutton.h>
53 #include <qspinbox.h>
54 #include <qlayout.h>
55 #include <qvalidator.h>
56 #include <qcolordialog.h>
57
58 #include <vtkTextProperty.h>
59 #include <vtkScalarBarActor.h>
60 #include <vtkLookupTable.h>
61
62 #define MINIMUM_WIDTH 70
63 #define MARGIN_SIZE   11
64 #define SPACING_SIZE   6
65
66 using namespace std;
67
68 // Only one instance is allowed
69 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
70
71 //=================================================================================================
72 /*!
73  *  SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
74  *
75  *  Gets the only instance of "Scalar Bar Properties" dialog box
76  */
77 //=================================================================================================
78 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
79 {
80   if (!myDlg) {
81     myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule, true);
82     myDlg->show();
83   } else {
84     myDlg->show();
85     myDlg->setActiveWindow();
86     myDlg->raise();
87     myDlg->setFocus();
88   }
89 }
90
91 //=================================================================================================
92 /*!
93  *  SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
94  *
95  *  Opens "Scalar Bar Preferences" dialog box
96  */
97 //=================================================================================================
98 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( SMESHGUI* theModule )
99 {
100   SMESHGUI_Preferences_ScalarBarDlg* aDlg =
101     new SMESHGUI_Preferences_ScalarBarDlg( theModule, false);
102   aDlg->exec();
103 }
104
105 //=================================================================================================
106 /*!
107  *  SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
108  *
109  *  Constructor
110  */
111 //=================================================================================================
112 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule, bool property, bool modal )
113      : QDialog( SMESH::GetDesktop( theModule ), 0, modal, WStyle_Customize | WStyle_NormalBorder |
114                 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
115        mySMESHGUI( theModule ),
116        mySelectionMgr( property ? SMESH::GetSelectionMgr( theModule ) : 0 )
117 {
118   DEF_VER_X = 0.01;
119   DEF_VER_Y = 0.10;
120   DEF_VER_H = 0.80;
121   DEF_VER_W = 0.10;
122   DEF_HOR_X = 0.20;
123   DEF_HOR_Y = 0.01;
124   DEF_HOR_H = 0.12;
125   DEF_HOR_W = 0.60;
126   setName("SMESHGUI_Preferences_ScalarBarDlg");
127   setCaption( property ? tr("SMESH_PROPERTIES_SCALARBAR") : tr("SMESH_PREFERENCES_SCALARBAR"));
128   setSizeGripEnabled(TRUE);
129
130   myActor = 0;
131
132   /******************************************************************************/
133   // Top layout
134   QGridLayout* aTopLayout = new QGridLayout( this );
135   aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
136   int aRow = 0;
137
138   /******************************************************************************/
139   // Scalar range
140   if ( mySelectionMgr ) {
141     myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this, "myRangeGrp" );
142     myRangeGrp->setColumnLayout( 0, Qt::Vertical );
143     myRangeGrp->layout()->setSpacing( 0 ); myRangeGrp->layout()->setMargin( 0 );
144     QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp->layout() );
145     myRangeGrpLayout->setAlignment( Qt::AlignTop );
146     myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
147
148     myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
149     myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
150     myMinEdit->setValidator( new QDoubleValidator( this ) );
151
152     myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
153     myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
154     myMaxEdit->setValidator( new QDoubleValidator( this ) );
155
156     myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp, "myMinLab" ), 0, 0 );
157     myRangeGrpLayout->addWidget( myMinEdit, 0, 1 );
158     myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp, "myMaxLab" ), 0, 2 );
159     myRangeGrpLayout->addWidget( myMaxEdit, 0, 3 );
160
161     aTopLayout->addWidget( myRangeGrp, aRow, 0 );
162     aRow++;
163   }
164
165   /******************************************************************************/
166   // Text properties
167   myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this, "myFontGrp" );
168   myFontGrp->setColumnLayout( 0, Qt::Vertical );
169   myFontGrp->layout()->setSpacing( 0 ); myFontGrp->layout()->setMargin( 0 );
170   QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp->layout() );
171   myFontGrpLayout->setAlignment( Qt::AlignTop );
172   myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
173
174   myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
175   myTitleColorBtn->setMinimumWidth( 20 );
176
177   myTitleFontCombo = new QComboBox( false, myFontGrp, "myTitleFontCombo" );
178   myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
179   myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
180   myTitleFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
181   myTitleFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
182   myTitleFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
183
184   myTitleBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp, "myTitleBoldCheck" );
185   myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myTitleItalicCheck" );
186   myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myTitleShadowCheck" );
187
188   myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
189   myLabelsColorBtn->setMinimumWidth( 20 );
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_APPLY_AND_CLOSE" ), 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     vtkLookupTable* myLookupTable =
523       static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
524     myLookupTable->SetRange( aMin, aMax );
525     myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
526     myLookupTable->Build();
527     SMESH::RepaintCurrentView();
528   } else {
529     // Scalar Bar preferences
530     SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
531     if (!mgr) return false;
532
533     QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
534     mgr->setValue("SMESH", "scalar_bar_title_color", titleColor );
535
536     QFont f;
537     if (myTitleFontCombo->currentItem() == 0)
538       f.setFamily( "Arial" );
539     else if (myTitleFontCombo->currentItem() == 1)
540       f.setFamily( "Courier" );
541     else
542       f.setFamily( "Times");
543
544     f.setBold( myTitleBoldCheck  ->isChecked() );
545     f.setItalic( myTitleItalicCheck->isChecked() );
546     f.setUnderline( myTitleShadowCheck->isChecked() );
547     mgr->setValue( "SMESH", "scalar_bar_title_font", f );
548
549     QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
550     mgr->setValue("SMESH", "scalar_bar_label_color", labelColor );
551
552     if (myLabelsFontCombo->currentItem() == 0)
553       f.setFamily( "Arial" );
554     else if ( myLabelsFontCombo->currentItem() == 1 )
555       f.setFamily( "Courier");
556     else
557       f.setFamily( "Times");
558
559     f.setBold( myLabelsBoldCheck  ->isChecked() );
560     f.setItalic( myLabelsItalicCheck->isChecked() );
561     f.setUnderline( myLabelsShadowCheck->isChecked() );
562     mgr->setValue( "SMESH", "scalar_bar_label_font", f );
563
564     mgr->setValue("SMESH", "scalar_bar_num_colors", myColorsSpin->value());
565     mgr->setValue("SMESH", "scalar_bar_num_labels", myLabelsSpin->value());
566
567     mgr->setValue("SMESH", "scalar_bar_orientation", myHorizRadioBtn->isChecked() ? 1 : 0 );
568
569     QString name = myHorizRadioBtn->isChecked() ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
570     mgr->setValue("SMESH", name.arg( "x" ), myXSpin->value());
571     mgr->setValue("SMESH", name.arg( "y" ), myYSpin->value());
572     mgr->setValue("SMESH", name.arg( "width" ),     myWidthSpin->value());
573     mgr->setValue("SMESH", name.arg( "height" ),    myHeightSpin->value());
574   }
575   return true;
576 }
577
578 //=================================================================================================
579 /*!
580  *  SMESHGUI_Preferences_ScalarBarDlg::onCancel
581  *
582  *  Cancel button slot
583  */
584 //=================================================================================================
585 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
586 {
587   close();
588 }
589
590 //=================================================================================================
591 /*!
592  *  SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
593  *
594  *  Change Title color button slot
595  */
596 //=================================================================================================
597 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
598 {
599   QColor aColor = myTitleColorBtn->paletteBackgroundColor();
600   aColor = QColorDialog::getColor( aColor, this );
601   if ( aColor.isValid() )
602     myTitleColorBtn->setPaletteBackgroundColor( aColor );
603 }
604
605 //=================================================================================================
606 /*!
607  *  SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
608  *
609  *  Change Labels color button slot
610  */
611 //=================================================================================================
612 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
613 {
614   QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
615   aColor = QColorDialog::getColor( aColor, this );
616   if ( aColor.isValid() )
617     myLabelsColorBtn->setPaletteBackgroundColor( aColor );
618 }
619
620 //=================================================================================================
621 /*!
622  *  SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
623  *
624  *  Called when selection changed
625  */
626 //=================================================================================================
627 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
628 {
629   if (mySelectionMgr) {
630     SALOME_ListIO aList;
631     mySelectionMgr->selectedObjects(aList);
632
633     if (aList.Extent() == 1) {
634       Handle(SALOME_InteractiveObject) anIO = aList.First();
635       if( anIO->hasEntry() ) {
636         SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
637         if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
638           myActor = anActor;
639           vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
640
641           if ( myScalarBarActor->GetLookupTable() ) {
642             vtkFloatingPointType *range = myScalarBarActor->GetLookupTable()->GetRange();
643             myMinEdit->setText( QString::number( range[0],'g',12 ) );
644             myMaxEdit->setText( QString::number( range[1],'g',12 ) );
645           }
646
647           vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
648           vtkFloatingPointType aTColor[3];
649           aTitleTextPrp->GetColor( aTColor );
650           myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
651           myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
652           myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
653           myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
654           myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
655
656           vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
657           vtkFloatingPointType aLColor[3];
658           aLabelsTextPrp->GetColor( aLColor );
659           myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
660           myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
661           myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
662           myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
663           myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
664
665           myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
666           myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
667
668           if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
669             myVertRadioBtn->setChecked( true );
670           else
671             myHorizRadioBtn->setChecked( true );
672           myIniOrientation = myVertRadioBtn->isChecked();
673
674           myIniX = myScalarBarActor->GetPosition()[0];
675           myIniY = myScalarBarActor->GetPosition()[1];
676           myIniW = myScalarBarActor->GetWidth();
677           myIniH = myScalarBarActor->GetHeight();
678           setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
679
680           myRangeGrp->setEnabled( true );
681           myFontGrp->setEnabled( true );
682           myLabColorGrp->setEnabled( true );
683           myOrientationGrp->setEnabled( true );
684           myOriginDimGrp->setEnabled( true );
685           myOkBtn->setEnabled( true );
686           myApplyBtn->setEnabled( true );
687           return;
688         }
689       }
690     }
691     myActor = 0;
692     myRangeGrp->setEnabled( false );
693     myFontGrp->setEnabled( false );
694     myLabColorGrp->setEnabled( false );
695     myOrientationGrp->setEnabled( false );
696     myOriginDimGrp->setEnabled( false );
697     myOkBtn->setEnabled( false );
698     myApplyBtn->setEnabled( false );
699   }
700 }
701
702 //=================================================================================================
703 /*!
704  *  SMESHGUI_Preferences_ScalarBarDlg::closeEvent
705  *
706  *  Close event handler
707  */
708 //=================================================================================================
709 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
710 {
711   if ( mySelectionMgr ) // "Properties" dialog box
712     myDlg = 0;
713   QDialog::closeEvent( e );
714 }
715
716 //=================================================================================================
717 /*!
718  *  SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
719  *
720  *  Called when X, Y values are changed
721  */
722 //=================================================================================================
723 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
724 {
725   myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
726   myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
727 }
728
729 //=================================================================================================
730 /*!
731  *  SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
732  *
733  *  Called when X, Y values are changed
734  */
735 //=================================================================================================
736 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
737                                                           const double y,
738                                                           const double w,
739                                                           const double h )
740 {
741   blockSignals( true );
742   myXSpin->setValue( x );
743   myYSpin->setValue( y );
744   myWidthSpin->setMaxValue( 1.0 );
745   myWidthSpin->setValue( w );
746   myHeightSpin->setMaxValue( 1.0 );
747   myHeightSpin->setValue( h );
748   blockSignals( false );
749   onXYChanged();
750 }
751
752 //=================================================================================================
753 /*!
754  *  SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
755  *
756  *  Called when orientation is changed
757  */
758 //=================================================================================================
759 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
760 {
761   this->initScalarBarFromResources();
762
763   int aOrientation = myVertRadioBtn->isChecked();
764   if ( aOrientation == myIniOrientation )
765     setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
766   else
767     setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
768                       aOrientation ? DEF_VER_Y : DEF_HOR_Y,
769                       aOrientation ? DEF_VER_W : DEF_HOR_W,
770                       aOrientation ? DEF_VER_H : DEF_HOR_H );
771 }
772
773 //=================================================================================================
774 /*!
775  *  SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
776  *
777  *  Rereading vertical and horizontal default positions from resources.
778  */
779 //=================================================================================================
780 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
781 {
782   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
783   QString name;
784   if (mgr){
785     // initialize from resoources
786     
787     // horizontal
788     name = QString("scalar_bar_horizontal_%1");
789     if (mgr->hasValue("SMESH", name.arg( "x" )))
790       DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
791     if (mgr->hasValue("SMESH", name.arg( "y" )))
792       DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
793     if (mgr->hasValue("SMESH", name.arg( "width" )))
794       DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
795     if (mgr->hasValue("SMESH", name.arg( "height" )))
796       DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
797
798     // vertical
799     name = QString("scalar_bar_vertical_%1");
800     if (mgr->hasValue("SMESH", name.arg( "x" )))
801       DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
802     if (mgr->hasValue("SMESH", name.arg( "y" )))
803       DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
804     if (mgr->hasValue("SMESH", name.arg( "width" )))
805       DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
806     if (mgr->hasValue("SMESH", name.arg( "height" )))
807       DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));
808   }
809 }