Salome HOME
PR: synchro V6_main tag mergeto_V7_main_11Feb13
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Preferences_ScalarBarDlg.cxx
1 // Copyright (C) 2007-2012  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, Open CASCADE S.A.S.
25 // SMESH includes
26
27 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_Utils.h"
33
34 #include <SMESH_Actor.h>
35 #include <SMESH_ActorUtils.h>
36 #include <SMESH_ScalarBarActor.h>
37 #include <SMESH_ControlsDef.hxx>
38
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_MessageBox.h>
44
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <SALOME_ListIO.hxx>
48 #include <SalomeApp_IntSpinBox.h>
49
50 #include <QtxColorButton.h>
51
52 // Qt includes
53 #include <QButtonGroup>
54 #include <QCheckBox>
55 #include <QComboBox>
56 #include <QGroupBox>
57 #include <QLabel>
58 #include <QLineEdit>
59 #include <QPushButton>
60 #include <QRadioButton>
61 #include <QHBoxLayout>
62 #include <QVBoxLayout>
63 #include <QGridLayout>
64 #include <QDoubleValidator>
65
66 // VTK includes
67 #include <vtkTextProperty.h>
68 #include <vtkLookupTable.h>
69
70 #define MINIMUM_WIDTH 70
71 #define MARGIN_SIZE   11
72 #define SPACING_SIZE   6
73
74 // Only one instance is allowed
75 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
76
77 //=================================================================================================
78 /*!
79  *  SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
80  *
81  *  Gets the only instance of "Scalar Bar Properties" dialog box
82  */
83 //=================================================================================================
84 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
85 {
86   if (!myDlg) {
87     myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule );
88     myDlg->show();
89   } else {
90     myDlg->show();
91     myDlg->raise();
92     myDlg->activateWindow();
93   }
94 }
95
96 //=================================================================================================
97 /*!
98  *  SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
99  *
100  *  Constructor
101  */
102 //=================================================================================================
103 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule )
104   : QDialog( SMESH::GetDesktop( theModule ) ),
105     mySMESHGUI( theModule ),
106     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
107 {
108   DEF_VER_X = 0.01;
109   DEF_VER_Y = 0.10;
110   DEF_VER_H = 0.80;
111   DEF_VER_W = 0.10;
112   DEF_HOR_X = 0.20;
113   DEF_HOR_Y = 0.01;
114   DEF_HOR_H = 0.12;
115   DEF_HOR_W = 0.60;
116
117   setModal( false );
118   setAttribute( Qt::WA_DeleteOnClose, true );
119   setWindowTitle( tr("SMESH_PROPERTIES_SCALARBAR") );
120   setSizeGripEnabled(true);
121
122   myActor = 0;
123
124   /******************************************************************************/
125   // Top layout
126   QVBoxLayout* aTopLayout = new QVBoxLayout( this );
127   aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
128
129   /******************************************************************************/
130   // Scalar range
131   myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this );
132   //QHBoxLayout* myRangeGrpLayout = new QHBoxLayout( myRangeGrp );
133   QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp );
134   myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
135
136   myMinEdit = new QLineEdit( myRangeGrp );
137   myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
138   myMinEdit->setValidator( new QDoubleValidator( this ) );
139
140   myMaxEdit = new QLineEdit( myRangeGrp );
141   myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
142   myMaxEdit->setValidator( new QDoubleValidator( this ) );
143
144   myLogarithmicCheck = new QCheckBox (myRangeGrp);
145   myLogarithmicCheck->setText(tr("SMESH_LOGARITHMIC_SCALARBAR"));
146   myLogarithmicCheck->setChecked(false);
147
148   myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp ), 0, 0, 1, 1 );
149   myRangeGrpLayout->addWidget( myMinEdit, 0, 1, 1, 1 );
150   myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp ), 0, 2, 1, 1 );
151   myRangeGrpLayout->addWidget( myMaxEdit, 0, 3, 1, 1 );
152   myRangeGrpLayout->addWidget( myLogarithmicCheck, 1, 0, 1, 4 );
153
154   aTopLayout->addWidget( myRangeGrp );
155
156   /******************************************************************************/
157   // Text properties
158   myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this  );
159   QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp );
160   myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
161
162   myTitleColorBtn = new QtxColorButton( myFontGrp  );
163
164   myTitleFontCombo = new QComboBox( myFontGrp );
165   myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
166   myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
167   myTitleFontCombo->addItem( tr( "SMESH_FONT_ARIAL" ) );
168   myTitleFontCombo->addItem( tr( "SMESH_FONT_COURIER" ) );
169   myTitleFontCombo->addItem( tr( "SMESH_FONT_TIMES" ) );
170
171   myTitleBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp );
172   myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp );
173   myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp );
174
175   myLabelsColorBtn = new QtxColorButton( myFontGrp );
176
177   myLabelsFontCombo = new QComboBox( myFontGrp );
178   myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
179   myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
180   myLabelsFontCombo->addItem( tr( "SMESH_FONT_ARIAL" ) );
181   myLabelsFontCombo->addItem( tr( "SMESH_FONT_COURIER" ) );
182   myLabelsFontCombo->addItem( tr( "SMESH_FONT_TIMES" ) );
183
184   myLabelsBoldCheck   = new QCheckBox( tr( "SMESH_FONT_BOLD" ),   myFontGrp );
185   myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp );
186   myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp );
187
188   myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp ), 0, 0 );
189   myFontGrpLayout->addWidget( myTitleColorBtn,    0, 1 );
190   myFontGrpLayout->addWidget( myTitleFontCombo,   0, 2 );
191   myFontGrpLayout->addWidget( myTitleBoldCheck,   0, 3 );
192   myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
193   myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
194
195   myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp ), 1, 0 );
196   myFontGrpLayout->addWidget( myLabelsColorBtn,    1, 1 );
197   myFontGrpLayout->addWidget( myLabelsFontCombo,   1, 2 );
198   myFontGrpLayout->addWidget( myLabelsBoldCheck,   1, 3 );
199   myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
200   myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
201
202   aTopLayout->addWidget( myFontGrp );
203
204   /******************************************************************************/
205   // Labels & Colors
206   myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this );
207   QHBoxLayout* myLabColorGrpLayout = new QHBoxLayout( myLabColorGrp );
208   myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
209
210   myColorsSpin = new SalomeApp_IntSpinBox( myLabColorGrp );
211   myColorsSpin->setAcceptNames( false ); // No Notebook variables allowed
212   myColorsSpin->setRange( 2, 256 );
213   myColorsSpin->setSingleStep( 1 );
214   myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
215   myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
216
217   myLabelsSpin = new SalomeApp_IntSpinBox( myLabColorGrp );
218   myLabelsSpin->setAcceptNames( false ); // No Notebook variables allowed
219   myLabelsSpin->setRange( 2, 65 );
220   myLabelsSpin->setSingleStep( 1 );
221   myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
222   myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
223
224   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp ) );
225   myLabColorGrpLayout->addWidget( myColorsSpin );
226   myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp ) );
227   myLabColorGrpLayout->addWidget( myLabelsSpin );
228
229   aTopLayout->addWidget( myLabColorGrp );
230
231   /******************************************************************************/
232   // Orientation
233   myOrientationGrp = new QGroupBox ( tr( "SMESH_ORIENTATION" ), this );
234   QButtonGroup* aOrientationGrp = new QButtonGroup( this );
235   QHBoxLayout* myOrientationGrpLayout = new QHBoxLayout( myOrientationGrp );
236   myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
237
238   myVertRadioBtn  = new QRadioButton( tr( "SMESH_VERTICAL" ),   myOrientationGrp );
239   myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp );
240   myVertRadioBtn->setChecked( true );
241
242   myOrientationGrpLayout->addWidget( myVertRadioBtn );
243   myOrientationGrpLayout->addWidget( myHorizRadioBtn );
244   aOrientationGrp->addButton(myVertRadioBtn);
245   aOrientationGrp->addButton(myHorizRadioBtn);
246
247   aTopLayout->addWidget( myOrientationGrp );
248
249   /******************************************************************************/
250   // Position & Size
251   myOriginDimGrp = new QGroupBox ( tr("SMESH_POSITION_SIZE_SCALARBAR"), this );
252   QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp );
253   myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
254
255   myXSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
256   myXSpin->setAcceptNames( false );
257   myXSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );
258   myXSpin->setMinimumWidth( MINIMUM_WIDTH );
259   myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
260
261   myYSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
262   myYSpin->setAcceptNames( false );
263   myYSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );
264   myYSpin->setMinimumWidth( MINIMUM_WIDTH );
265   myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
266
267   myWidthSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
268   myWidthSpin->setAcceptNames( false );
269   myWidthSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );
270   myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
271   myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
272
273   myHeightSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
274   myHeightSpin->setAcceptNames( false );
275   myHeightSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );
276   myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
277   myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
278
279   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp ), 0, 0 );
280   myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
281   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp ), 0, 2 );
282   myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
283   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ),  myOriginDimGrp ),  1, 0 );
284   myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
285   myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp ), 1, 2 );
286   myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
287
288   aTopLayout->addWidget( myOriginDimGrp );
289   /******************************************************************************/
290
291   // Destribution
292   myDistributionGrp = new QGroupBox ( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), this );
293   myDistributionGrp->setCheckable(true);
294   QHBoxLayout* aDistributionGrpLayout = new QHBoxLayout( myDistributionGrp );
295   aDistributionGrpLayout->setSpacing( SPACING_SIZE ); aDistributionGrpLayout->setMargin( MARGIN_SIZE );
296
297   myDistribColorGrp = new QButtonGroup( this );
298
299   myDMonoColor  = new QRadioButton( tr( "SMESH_MONOCOLOR" ) ,  myDistributionGrp );
300   myDMultiColor = new QRadioButton( tr( "SMESH_MULTICOLOR" ),  myDistributionGrp );
301   myDMonoColor->setChecked( true );
302
303   myDistribColorGrp->addButton(myDMonoColor);myDistribColorGrp->setId(myDMonoColor,1);
304   myDistribColorGrp->addButton(myDMultiColor);myDistribColorGrp->setId(myDMultiColor,2);
305
306   aDistributionGrpLayout->addWidget( myDMultiColor );
307   aDistributionGrpLayout->addWidget( myDMonoColor );
308
309   //Color of the Distribution in monocolor case:
310   myDistributionColorLbl = new QLabel( tr( "SMESH_DISTRIBUTION_COLOR" ), myDistributionGrp );
311   aDistributionGrpLayout->addWidget( myDistributionColorLbl );
312   myMonoColorBtn = new QtxColorButton( myDistributionGrp  );
313   aDistributionGrpLayout->addWidget(myMonoColorBtn);
314
315   aTopLayout->addWidget(myDistributionGrp);
316
317   /******************************************************************************/
318   // Common buttons
319   myButtonGrp = new QGroupBox( this );
320   QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp );
321   myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
322
323   myOkBtn = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), myButtonGrp );
324   myOkBtn->setAutoDefault( true ); myOkBtn->setDefault( true );
325   myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp );
326   myApplyBtn->setAutoDefault( true );
327   myCancelBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), myButtonGrp );
328   myCancelBtn->setAutoDefault( true );
329   myHelpBtn = new QPushButton( tr("SMESH_BUT_HELP"), myButtonGrp );
330   myHelpBtn->setAutoDefault(true);
331
332   myButtonGrpLayout->addWidget( myOkBtn );
333   myButtonGrpLayout->addSpacing( 10 );
334   myButtonGrpLayout->addWidget( myApplyBtn );
335   myButtonGrpLayout->addSpacing( 10 );
336   myButtonGrpLayout->addStretch();
337   myButtonGrpLayout->addWidget( myCancelBtn );
338   myButtonGrpLayout->addWidget( myHelpBtn );
339
340   aTopLayout->addWidget( myButtonGrp );
341
342   /***************************************************************/
343   // Init
344   // --> first init from preferences
345   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
346
347   QColor titleColor = mgr->colorValue("SMESH", "scalar_bar_title_color",
348                                       QColor(255, 255, 255));
349   myTitleColorBtn->setColor(titleColor);
350   myTitleFontCombo->setCurrentIndex(0);
351   if (mgr->hasValue("SMESH", "scalar_bar_title_font")) {
352     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
353     if( f.family()=="Arial" )
354       myTitleFontCombo->setCurrentIndex(0);
355     if( f.family()=="Courier" )
356       myTitleFontCombo->setCurrentIndex(1);
357     if( f.family()=="Times")
358       myTitleFontCombo->setCurrentIndex(2);
359
360     myTitleBoldCheck->setChecked  ( f.bold() );
361     myTitleItalicCheck->setChecked( f.italic() );
362     myTitleShadowCheck->setChecked( f.overline() );
363   }
364
365   QColor labelColor = mgr->colorValue("SMESH", "scalar_bar_label_color",
366                                       QColor(255, 255, 255));
367   myLabelsColorBtn->setColor(labelColor);
368   myLabelsFontCombo->setCurrentIndex(0);
369   if (mgr->hasValue("SMESH", "scalar_bar_label_font")) {
370     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
371     if (f.family() == "Arial")
372       myLabelsFontCombo->setCurrentIndex(0);
373     if (f.family() == "Courier")
374       myLabelsFontCombo->setCurrentIndex(1);
375     if (f.family() == "Times")
376       myLabelsFontCombo->setCurrentIndex(2);
377
378     myLabelsBoldCheck  ->setChecked( f.bold() );
379     myLabelsItalicCheck->setChecked( f.italic() );
380     myLabelsShadowCheck->setChecked( f.overline() );
381   }
382
383   int aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors", 64);
384   myColorsSpin->setValue(aNbColors);
385
386   int aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels", 5);
387   myLabelsSpin->setValue(aNbLabels);
388
389   int aOrientation = mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 );
390   bool isHoriz = aOrientation == 1;
391   if (isHoriz)
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
399   myIniX = mgr->doubleValue("SMESH", name.arg( "x" ),
400                             myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X);
401
402   myIniY = mgr->doubleValue("SMESH", name.arg( "y" ),
403                             myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y);
404
405   myIniW = mgr->doubleValue("SMESH", name.arg( "width" ),
406                             myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W);
407
408   myIniH = mgr->doubleValue("SMESH", name.arg( "height" ),
409                             myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H);
410
411   setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
412
413
414   bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
415   myDistributionGrp->setChecked(distributionVisibility);
416
417   int coloringType = mgr->integerValue("SMESH", "distribution_coloring_type", 0);
418   if( coloringType == SMESH_MONOCOLOR_TYPE ) {
419     myDMonoColor->setChecked(true);
420     onDistributionChanged(myDistribColorGrp->id(myDMonoColor));
421   } else {
422     myDMultiColor->setChecked(true);
423     onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
424
425   }
426
427   QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
428                                              QColor(255, 255, 255));
429   myMonoColorBtn->setColor(distributionColor);
430
431   // --> then init from selection if necessary
432   onSelectionChanged();
433
434   /***************************************************************/
435   // Connect section
436   connect( myOkBtn,             SIGNAL( clicked() ), this, SLOT( onOk() ) );
437   connect( myApplyBtn,          SIGNAL( clicked() ), this, SLOT( onApply() ) );
438   connect( myCancelBtn,         SIGNAL( clicked() ), this, SLOT( onCancel() ) );
439   connect( myHelpBtn,           SIGNAL(clicked()),   this, SLOT( onHelp() ) );
440   connect( myMinEdit,           SIGNAL( textChanged(const QString &) ), this, SLOT( onMinMaxChanged() ) );
441   connect( myMaxEdit,           SIGNAL( textChanged(const QString &) ), this, SLOT( onMinMaxChanged() ) );
442   connect( myXSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
443   connect( myYSpin,             SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
444   connect( aOrientationGrp,     SIGNAL( buttonClicked( int ) ),   this, SLOT( onOrientationChanged() ) );
445   connect( myDistributionGrp,   SIGNAL( toggled(bool) ), this, SLOT(onDistributionActivated(bool)) );
446   connect( myDistribColorGrp,   SIGNAL( buttonClicked( int ) ),   this, SLOT( onDistributionChanged( int ) ) );
447   connect( mySelectionMgr,      SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
448   connect( mySMESHGUI,          SIGNAL( SignalCloseAllDialogs() ),   this, SLOT( onCancel() ) );
449
450   myHelpFileName = "quality_page.html";
451 }
452
453 //=================================================================================================
454 /*!
455  *  SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
456  *
457  *  Destructor
458  */
459 //=================================================================================================
460 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
461 {
462 }
463
464 //=================================================================================================
465 /*!
466  *  SMESHGUI_Preferences_ScalarBarDlg::onOk
467  *
468  *  OK button slot
469  */
470 //=================================================================================================
471 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
472 {
473   if ( onApply() )
474     onCancel();
475 }
476
477 //=================================================================================================
478 /*!
479  *  SMESHGUI_Preferences_ScalarBarDlg::onApply
480  *
481  *  Apply button slot
482  */
483 //=================================================================================================
484 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
485 {
486   // Scalar Bar properties
487   if (!myActor)
488     return false;
489   SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
490
491   vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
492   QColor aTColor = myTitleColorBtn->color();
493   aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
494   if ( myTitleFontCombo->currentIndex() == 0 )
495     aTitleTextPrp->SetFontFamilyToArial();
496   else if ( myTitleFontCombo->currentIndex() == 1 )
497     aTitleTextPrp->SetFontFamilyToCourier();
498   else
499     aTitleTextPrp->SetFontFamilyToTimes();
500   aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
501   aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
502   aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
503   myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
504
505   vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
506   QColor aLColor = myLabelsColorBtn->color();
507   aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
508   if ( myLabelsFontCombo->currentIndex() == 0 )
509     aLabelsTextPrp->SetFontFamilyToArial();
510   else if ( myLabelsFontCombo->currentIndex() == 1 )
511     aLabelsTextPrp->SetFontFamilyToCourier();
512   else
513     aLabelsTextPrp->SetFontFamilyToTimes();
514   aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
515   aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
516   aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
517   myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
518
519   myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
520
521   if ( myHorizRadioBtn->isChecked() )
522     myScalarBarActor->SetOrientationToHorizontal();
523   else
524     myScalarBarActor->SetOrientationToVertical();
525
526   myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
527   myScalarBarActor->SetWidth( myWidthSpin->value() );
528   myScalarBarActor->SetHeight( myHeightSpin->value() );
529
530   // Distribution
531   bool distributionTypeChanged = false, colorChanged=false;
532   myScalarBarActor->SetDistributionVisibility((int)myDistributionGrp->isChecked());
533   if( myDistributionGrp->isChecked() ) {
534     int ColoringType = myDMultiColor->isChecked() ? SMESH_MULTICOLOR_TYPE : SMESH_MONOCOLOR_TYPE;
535     distributionTypeChanged = (ColoringType != myScalarBarActor->GetDistributionColoringType());
536     if (distributionTypeChanged)
537       myScalarBarActor->SetDistributionColoringType(ColoringType);
538
539     if( !myDMultiColor->isChecked() ) {
540       QColor aTColor = myMonoColorBtn->color();
541       double rgb[3], oldRgb[3];;
542       rgb [0] = aTColor.red()/255.;
543       rgb [1] = aTColor.green()/255.;
544       rgb [2] = aTColor.blue()/255.;
545       myScalarBarActor->GetDistributionColor(oldRgb);
546       colorChanged = (rgb[0] != oldRgb[0] || rgb[1] != oldRgb[1] || rgb[2] != oldRgb[2]);
547       if(colorChanged)
548         myScalarBarActor->SetDistributionColor(rgb);
549     }
550   }
551
552   double aMin = myMinEdit->text().toDouble();
553   double aMax = myMaxEdit->text().toDouble();
554   vtkLookupTable* myLookupTable =
555     static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
556   double oldMinMax[2] = { myLookupTable->GetRange()[0], myLookupTable->GetRange()[1] };
557   bool rangeChanges = ( fabs( oldMinMax[0] - aMin ) + fabs( oldMinMax[1] - aMax ) >
558                         0.001 * ( aMax-aMin + oldMinMax[1]-oldMinMax[0] ));
559
560   bool nbColorsChanged = (myColorsSpin->value() != myScalarBarActor->GetMaximumNumberOfColors());
561   if(nbColorsChanged)
562     myScalarBarActor->SetMaximumNumberOfColors(myColorsSpin->value());
563
564   myLookupTable->SetRange( aMin, aMax );
565   myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
566
567   bool scaleChanged = (myLogarithmicCheck->isChecked() != (myLookupTable->GetScale() == VTK_SCALE_LOG10));
568   if (scaleChanged)
569     myLookupTable->SetScale(myLogarithmicCheck->isChecked() ? VTK_SCALE_LOG10 : VTK_SCALE_LINEAR);
570
571   myLookupTable->Build();
572
573   if (nbColorsChanged || rangeChanges || scaleChanged)
574     myActor->UpdateDistribution();
575
576 #ifndef DISABLE_PLOT2DVIEWER
577   if( myActor->GetPlot2Histogram() &&
578       (nbColorsChanged ||
579        rangeChanges ||
580        distributionTypeChanged ||
581        colorChanged ))
582     SMESH::ProcessIn2DViewers(myActor);
583 #endif
584
585   SMESH::RepaintCurrentView();
586   return true;
587 }
588
589 //=================================================================================================
590 /*!
591  *  SMESHGUI_Preferences_ScalarBarDlg::onCancel
592  *
593  *  Cancel button slot
594  */
595 //=================================================================================================
596 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
597 {
598   close();
599 }
600
601 //=================================================================================================
602 /*!
603  *  SMESHGUI_Preferences_ScalarBarDlg::onHelp
604  *
605  *  Help button slot
606  */
607 //=================================================================================================
608 void SMESHGUI_Preferences_ScalarBarDlg::onHelp()
609 {
610   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
611   if (app)
612     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
613   else {
614     QString platform;
615 #ifdef WIN32
616     platform = "winapplication";
617 #else
618     platform = "application";
619 #endif
620     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
621                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
622                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
623                                                                  platform)).
624                              arg(myHelpFileName));
625   }
626 }
627
628 //=================================================================================================
629 /*!
630  *  SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
631  *
632  *  Called when selection changed
633  */
634 //=================================================================================================
635 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
636 {
637   SALOME_ListIO aList;
638   mySelectionMgr->selectedObjects(aList);
639
640   if (aList.Extent() == 1) {
641     Handle(SALOME_InteractiveObject) anIO = aList.First();
642     if( anIO->hasEntry() ) {
643       SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
644       if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
645         myActor = anActor;
646         SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
647
648         if ( myScalarBarActor->GetLookupTable() ) {
649           vtkLookupTable* aLookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
650
651           vtkFloatingPointType *range = aLookupTable->GetRange();
652           myMinEdit->setText( QString::number( range[0],'g',12 ) );
653           myMaxEdit->setText( QString::number( range[1],'g',12 ) );
654           myLogarithmicCheck->setChecked(aLookupTable->GetScale() == VTK_SCALE_LOG10);
655           myLogarithmicCheck->setEnabled(range[0] > 1e-07 && range[1] > 1e-07);
656         }
657
658         vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
659         vtkFloatingPointType aTColor[3];
660         aTitleTextPrp->GetColor( aTColor );
661         myTitleColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
662         myTitleFontCombo->setCurrentIndex( aTitleTextPrp->GetFontFamily() );
663         myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
664         myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
665         myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
666
667         vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
668         vtkFloatingPointType aLColor[3];
669         aLabelsTextPrp->GetColor( aLColor );
670         myLabelsColorBtn->setColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
671         myLabelsFontCombo->setCurrentIndex( aLabelsTextPrp->GetFontFamily() );
672         myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
673         myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
674         myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
675
676         myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
677         myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
678
679         if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
680           myVertRadioBtn->setChecked( true );
681         else
682           myHorizRadioBtn->setChecked( true );
683         myIniOrientation = myVertRadioBtn->isChecked();
684
685         myIniX = myScalarBarActor->GetPosition()[0];
686         myIniY = myScalarBarActor->GetPosition()[1];
687         myIniW = myScalarBarActor->GetWidth();
688         myIniH = myScalarBarActor->GetHeight();
689         setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
690
691         int coloringType = myScalarBarActor->GetDistributionColoringType();
692         myScalarBarActor->GetDistributionColor( aTColor );
693         myMonoColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
694         if ( coloringType == SMESH_MONOCOLOR_TYPE ) {
695           myDMonoColor->setChecked(true);
696           onDistributionChanged(myDistribColorGrp->id(myDMonoColor));
697         } else {
698           myDMultiColor->setChecked(true);
699           onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
700         }
701         myDistributionGrp->setChecked((bool)myScalarBarActor->GetDistributionVisibility());
702         onDistributionActivated(myScalarBarActor->GetDistributionVisibility());
703
704         myRangeGrp->setEnabled( true );
705         myFontGrp->setEnabled( true );
706         myLabColorGrp->setEnabled( true );
707         myOrientationGrp->setEnabled( true );
708         myOriginDimGrp->setEnabled( true );
709         myOkBtn->setEnabled( true );
710         myApplyBtn->setEnabled( true );
711         myDistributionGrp->setEnabled( true );
712         return;
713       }
714     }
715   }
716   myActor = 0;
717   myRangeGrp->setEnabled( false );
718   myFontGrp->setEnabled( false );
719   myLabColorGrp->setEnabled( false );
720   myOrientationGrp->setEnabled( false );
721   myOriginDimGrp->setEnabled( false );
722   myOkBtn->setEnabled( false );
723   myApplyBtn->setEnabled( false );
724   myDistributionGrp->setEnabled( false );
725 }
726
727 //=================================================================================================
728 /*!
729  *  SMESHGUI_Preferences_ScalarBarDlg::closeEvent
730  *
731  *  Close event handler
732  */
733 //=================================================================================================
734 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
735 {
736   myDlg = 0;
737   QDialog::closeEvent( e );
738 }
739
740 //=================================================================================================
741 /*!
742  *  SMESHGUI_Preferences_ScalarBarDlg::onMinMaxChanged
743  *
744  *  Called when Scalar Range values are changed
745  */
746 //=================================================================================================
747 void SMESHGUI_Preferences_ScalarBarDlg::onMinMaxChanged()
748 {
749   double aMin = myMinEdit->text().toDouble();
750   double aMax = myMaxEdit->text().toDouble();
751   bool isLogarithmicEnabled = (aMin > 1e-07 && aMax > 1e-07);
752   myLogarithmicCheck->setChecked(isLogarithmicEnabled);
753   myLogarithmicCheck->setEnabled(isLogarithmicEnabled);
754 }
755
756 //=================================================================================================
757 /*!
758  *  SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
759  *
760  *  Called when X, Y values are changed
761  */
762 //=================================================================================================
763 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
764 {
765   myWidthSpin->setMaximum( 1.0 - myXSpin->value() );
766   myHeightSpin->setMaximum( 1.0 - myYSpin->value() );
767 }
768
769 //=================================================================================================
770 /*!
771  *  SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
772  *
773  *  Called when X, Y values are changed
774  */
775 //=================================================================================================
776 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
777                                                           const double y,
778                                                           const double w,
779                                                           const double h )
780 {
781   blockSignals( true );
782   myXSpin->setValue( x );
783   myYSpin->setValue( y );
784   myWidthSpin->setMaximum( 1.0 );
785   myWidthSpin->setValue( w );
786   myHeightSpin->setMaximum( 1.0 );
787   myHeightSpin->setValue( h );
788   blockSignals( false );
789   onXYChanged();
790 }
791
792
793 //=================================================================================================
794 /*!
795  *  SMESHGUI_Preferences_ScalarBarDlg::onDistributionChanged
796  *
797  *  Called when coloring type of the distribution is changed
798  */
799 //=================================================================================================
800 void SMESHGUI_Preferences_ScalarBarDlg::onDistributionChanged( int id ) {
801
802   bool isActive = myDistribColorGrp->id(myDMonoColor) == id;
803
804   myMonoColorBtn->setEnabled(isActive);
805   myDistributionColorLbl->setEnabled(isActive);
806 }
807 //=================================================================================================
808 /*!
809  *  SMESHGUI_Preferences_ScalarBarDlg::onDistributionActivated
810  *
811  *  Called when distribution group check box is changed
812  */
813 //=================================================================================================
814 void SMESHGUI_Preferences_ScalarBarDlg::onDistributionActivated(bool on) {
815   if(on) {
816     if(myDMonoColor->isChecked())
817       onDistributionChanged(myDistribColorGrp->id(myDMonoColor)  );
818     else if(myDMultiColor->isChecked())
819       onDistributionChanged(myDistribColorGrp->id(myDMultiColor) );
820   }
821   else {
822     myMonoColorBtn->setEnabled(false);
823     myDistributionColorLbl->setEnabled(false);
824   }
825 }
826
827
828 //=================================================================================================
829 /*!
830  *  SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
831  *
832  *  Called when orientation is changed
833  */
834 //=================================================================================================
835 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
836 {
837   initScalarBarFromResources();
838
839   int aOrientation = myVertRadioBtn->isChecked();
840   if ( aOrientation == myIniOrientation )
841     setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
842   else
843     setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
844                       aOrientation ? DEF_VER_Y : DEF_HOR_Y,
845                       aOrientation ? DEF_VER_W : DEF_HOR_W,
846                       aOrientation ? DEF_VER_H : DEF_HOR_H );
847 }
848
849 //=================================================================================================
850 /*!
851  *  SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
852  *
853  *  Rereading vertical and horizontal default positions from resources.
854  */
855 //=================================================================================================
856 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
857 {
858   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
859   QString name;
860   if (mgr){
861     // initialize from resoources
862
863     // horizontal
864     name = QString("scalar_bar_horizontal_%1");
865     if (mgr->hasValue("SMESH", name.arg( "x" )))
866       DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
867     if (mgr->hasValue("SMESH", name.arg( "y" )))
868       DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
869     if (mgr->hasValue("SMESH", name.arg( "width" )))
870       DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
871     if (mgr->hasValue("SMESH", name.arg( "height" )))
872       DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
873
874     // vertical
875     name = QString("scalar_bar_vertical_%1");
876     if (mgr->hasValue("SMESH", name.arg( "x" )))
877       DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
878     if (mgr->hasValue("SMESH", name.arg( "y" )))
879       DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
880     if (mgr->hasValue("SMESH", name.arg( "width" )))
881       DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
882     if (mgr->hasValue("SMESH", name.arg( "height" )))
883       DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));
884   }
885 }