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