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