1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_Preferences_ScalarBarDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
28 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_Utils.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
37 #include <SMESH_ScalarBarActor.h>
38 #include <SMESH_ControlsDef.hxx>
40 // SALOME GUI includes
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
48 #include <SALOME_ListIO.hxx>
49 #include <SalomeApp_IntSpinBox.h>
51 #include <QtxColorButton.h>
53 #include "utilities.h"
56 #include <QButtonGroup>
62 #include <QPushButton>
63 #include <QRadioButton>
64 #include <QHBoxLayout>
65 #include <QVBoxLayout>
66 #include <QGridLayout>
67 #include <QDoubleValidator>
70 #include <vtkTextProperty.h>
71 #include <vtkLookupTable.h>
73 #define MINIMUM_WIDTH 70
74 #define MARGIN_SIZE 11
75 #define SPACING_SIZE 6
77 // Only one instance is allowed
78 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
80 //=================================================================================================
82 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
84 * Gets the only instance of "Scalar Bar Properties" dialog box
86 //=================================================================================================
87 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
90 myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule );
95 myDlg->activateWindow();
99 //=================================================================================================
101 * SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
105 //=================================================================================================
106 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule )
107 : QDialog( SMESH::GetDesktop( theModule ) ),
108 mySMESHGUI( theModule ),
109 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
121 setAttribute( Qt::WA_DeleteOnClose, true );
122 setWindowTitle( tr("SMESH_PROPERTIES_SCALARBAR") );
123 setSizeGripEnabled(true);
127 /******************************************************************************/
129 QVBoxLayout* aTopLayout = new QVBoxLayout( this );
130 aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
132 /******************************************************************************/
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 );
139 myMinEdit = new QLineEdit( myRangeGrp );
140 myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
141 myMinEdit->setValidator( new QDoubleValidator( this ) );
143 myMaxEdit = new QLineEdit( myRangeGrp );
144 myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
145 myMaxEdit->setValidator( new QDoubleValidator( this ) );
147 myLogarithmicCheck = new QCheckBox (myRangeGrp);
148 myLogarithmicCheck->setText(tr("SMESH_LOGARITHMIC_SCALARBAR"));
149 myLogarithmicCheck->setChecked(false);
151 myThresholdCheck = new QCheckBox (myRangeGrp);
152 myThresholdCheck->setText(tr("SMESH_TRESHOLD_SCALARBAR"));
153 myThresholdCheck->setChecked(false);
155 myWireframeOffCheck = new QCheckBox (myRangeGrp);
156 myWireframeOffCheck->setText(tr("SMESH_WIREFRAME_OFF_SCALARBAR"));
157 myWireframeOffCheck->setChecked(false);
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 );
167 aTopLayout->addWidget( myRangeGrp );
169 /******************************************************************************/
171 myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this );
172 QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp );
173 myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
175 myTitleColorBtn = new QtxColorButton( myFontGrp );
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" ) );
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 );
188 myLabelsColorBtn = new QtxColorButton( myFontGrp );
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" ) );
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 );
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 );
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 );
215 aTopLayout->addWidget( myFontGrp );
217 /******************************************************************************/
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 );
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 ) );
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 ) );
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 );
242 aTopLayout->addWidget( myLabColorGrp );
244 /******************************************************************************/
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 );
251 myVertRadioBtn = new QRadioButton( tr( "SMESH_VERTICAL" ), myOrientationGrp );
252 myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp );
253 myVertRadioBtn->setChecked( true );
255 myOrientationGrpLayout->addWidget( myVertRadioBtn );
256 myOrientationGrpLayout->addWidget( myHorizRadioBtn );
257 aOrientationGrp->addButton(myVertRadioBtn);
258 aOrientationGrp->addButton(myHorizRadioBtn);
260 aTopLayout->addWidget( myOrientationGrp );
262 /******************************************************************************/
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 );
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 ) );
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 ) );
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 ) );
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 ) );
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 );
301 aTopLayout->addWidget( myOriginDimGrp );
302 /******************************************************************************/
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 );
310 myDistribColorGrp = new QButtonGroup( this );
312 myDMonoColor = new QRadioButton( tr( "SMESH_MONOCOLOR" ) , myDistributionGrp );
313 myDMultiColor = new QRadioButton( tr( "SMESH_MULTICOLOR" ), myDistributionGrp );
314 myDMonoColor->setChecked( true );
316 myDistribColorGrp->addButton(myDMonoColor);myDistribColorGrp->setId(myDMonoColor,1);
317 myDistribColorGrp->addButton(myDMultiColor);myDistribColorGrp->setId(myDMultiColor,2);
319 aDistributionGrpLayout->addWidget( myDMultiColor );
320 aDistributionGrpLayout->addWidget( myDMonoColor );
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);
328 aTopLayout->addWidget(myDistributionGrp);
330 /******************************************************************************/
332 myButtonGrp = new QGroupBox( this );
333 QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp );
334 myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
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);
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 );
353 aTopLayout->addWidget( myButtonGrp );
355 /***************************************************************/
357 // --> first init from preferences
358 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
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);
373 myTitleBoldCheck->setChecked ( f.bold() );
374 myTitleItalicCheck->setChecked( f.italic() );
375 myTitleShadowCheck->setChecked( f.overline() );
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);
391 myLabelsBoldCheck ->setChecked( f.bold() );
392 myLabelsItalicCheck->setChecked( f.italic() );
393 myLabelsShadowCheck->setChecked( f.overline() );
396 int aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors", 64);
397 myColorsSpin->setValue(aNbColors);
399 int aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels", 5);
400 myLabelsSpin->setValue(aNbLabels);
402 int aOrientation = mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 );
403 bool isHoriz = aOrientation == 1;
405 myHorizRadioBtn->setChecked(true);
407 myVertRadioBtn->setChecked(true);
408 myIniOrientation = myVertRadioBtn->isChecked();
410 QString name = isHoriz ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
412 myIniX = mgr->doubleValue("SMESH", name.arg( "x" ),
413 myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X);
415 myIniY = mgr->doubleValue("SMESH", name.arg( "y" ),
416 myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y);
418 myIniW = mgr->doubleValue("SMESH", name.arg( "width" ),
419 myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W);
421 myIniH = mgr->doubleValue("SMESH", name.arg( "height" ),
422 myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H);
424 setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
427 bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
428 myDistributionGrp->setChecked(distributionVisibility);
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));
435 myDMultiColor->setChecked(true);
436 onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
440 QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
441 QColor(255, 255, 255));
442 myMonoColorBtn->setColor(distributionColor);
444 // --> then init from selection if necessary
445 onSelectionChanged();
447 /***************************************************************/
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() ) );
463 myHelpFileName = "scalar_bar.html";
466 //=================================================================================================
468 * SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
472 //=================================================================================================
473 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
477 //=================================================================================================
479 * SMESHGUI_Preferences_ScalarBarDlg::onOk
483 //=================================================================================================
484 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
490 //=================================================================================================
492 * SMESHGUI_Preferences_ScalarBarDlg::onApply
496 //=================================================================================================
497 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
499 // Scalar Bar properties
502 SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
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();
512 aTitleTextPrp->SetFontFamilyToTimes();
513 aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
514 aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
515 aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
516 myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
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();
526 aLabelsTextPrp->SetFontFamilyToTimes();
527 aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
528 aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
529 aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
530 myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
532 myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
534 if ( myHorizRadioBtn->isChecked() )
535 myScalarBarActor->SetOrientationToHorizontal();
537 myScalarBarActor->SetOrientationToVertical();
539 myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
540 myScalarBarActor->SetWidth( myWidthSpin->value() );
541 myScalarBarActor->SetHeight( myHeightSpin->value() );
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);
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]);
561 myScalarBarActor->SetDistributionColor(rgb);
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] ));
573 bool nbColorsChanged = (myColorsSpin->value() != myScalarBarActor->GetMaximumNumberOfColors());
575 myScalarBarActor->SetMaximumNumberOfColors(myColorsSpin->value());
577 myLookupTable->SetRange( aMin, aMax );
578 myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
579 applyThreshold(aMin, aMax);
583 bool scaleChanged = (myLogarithmicCheck->isChecked() != (myLookupTable->GetScale() == VTK_SCALE_LOG10));
585 myLookupTable->SetScale(myLogarithmicCheck->isChecked() ? VTK_SCALE_LOG10 : VTK_SCALE_LINEAR);
587 myLookupTable->Build();
589 if (nbColorsChanged || rangeChanges || scaleChanged)
590 myActor->UpdateDistribution();
592 #ifndef DISABLE_PLOT2DVIEWER
593 if( myActor->GetPlot2Histogram() &&
596 distributionTypeChanged ||
598 SMESH::ProcessIn2DViewers(myActor);
601 SMESH::RepaintCurrentView();
605 //=================================================================================================
607 * SMESHGUI_Preferences_ScalarBarDlg::reject
611 //=================================================================================================
612 void SMESHGUI_Preferences_ScalarBarDlg::reject()
618 //=================================================================================================
620 * SMESHGUI_Preferences_ScalarBarDlg::onHelp
624 //=================================================================================================
625 void SMESHGUI_Preferences_ScalarBarDlg::onHelp()
627 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
629 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
633 platform = "winapplication";
635 platform = "application";
637 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
638 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
639 arg(app->resourceMgr()->stringValue("ExternalBrowser",
641 arg(myHelpFileName));
645 //=================================================================================================
647 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
649 * Called when selection changed
651 //=================================================================================================
652 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
655 mySelectionMgr->selectedObjects(aList);
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 ) {
663 SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
665 if ( myScalarBarActor->GetLookupTable() ) {
666 vtkLookupTable* aLookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
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]);
675 myThresholdCheck->setChecked(myActor->IsClipThresholdOn());
676 applyThreshold(range[0], range[1]);
678 myWireframeOffCheck->setChecked(myActor->IsWireframeOff());
683 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
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() );
692 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
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() );
701 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
702 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
704 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
705 myVertRadioBtn->setChecked( true );
707 myHorizRadioBtn->setChecked( true );
708 myIniOrientation = myVertRadioBtn->isChecked();
710 myIniX = myScalarBarActor->GetPosition()[0];
711 myIniY = myScalarBarActor->GetPosition()[1];
712 myIniW = myScalarBarActor->GetWidth();
713 myIniH = myScalarBarActor->GetHeight();
714 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
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));
723 myDMultiColor->setChecked(true);
724 onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
726 myDistributionGrp->setChecked((bool)myScalarBarActor->GetDistributionVisibility());
727 onDistributionActivated(myScalarBarActor->GetDistributionVisibility());
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 );
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 );
752 //=================================================================================================
754 * SMESHGUI_Preferences_ScalarBarDlg::onMinMaxChanged
756 * Called when Scalar Range values are changed
758 //=================================================================================================
759 void SMESHGUI_Preferences_ScalarBarDlg::onMinMaxChanged()
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?
766 // The checkbox should be enabled only when the range is valid for it
767 myLogarithmicCheck->setEnabled(isLogarithmicEnabled);
769 // Change checkbox only if the range is not valid. Otherwise it's on the user decision.
770 if (!isLogarithmicEnabled)
772 myLogarithmicCheck->setChecked(isLogarithmicEnabled);
776 //=================================================================================================
778 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
780 * Called when X, Y values are changed
782 //=================================================================================================
783 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
785 myWidthSpin->setMaximum( 1.0 - myXSpin->value() );
786 myHeightSpin->setMaximum( 1.0 - myYSpin->value() );
789 //=================================================================================================
791 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
793 * Called when X, Y values are changed
795 //=================================================================================================
796 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
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 );
813 //=================================================================================================
815 * SMESHGUI_Preferences_ScalarBarDlg::onDistributionChanged
817 * Called when coloring type of the distribution is changed
819 //=================================================================================================
820 void SMESHGUI_Preferences_ScalarBarDlg::onDistributionChanged( int id ) {
822 bool isActive = myDistribColorGrp->id(myDMonoColor) == id;
824 myMonoColorBtn->setEnabled(isActive);
825 myDistributionColorLbl->setEnabled(isActive);
827 //=================================================================================================
829 * SMESHGUI_Preferences_ScalarBarDlg::onDistributionActivated
831 * Called when distribution group check box is changed
833 //=================================================================================================
834 void SMESHGUI_Preferences_ScalarBarDlg::onDistributionActivated(bool on) {
836 if(myDMonoColor->isChecked())
837 onDistributionChanged(myDistribColorGrp->id(myDMonoColor) );
838 else if(myDMultiColor->isChecked())
839 onDistributionChanged(myDistribColorGrp->id(myDMultiColor) );
842 myMonoColorBtn->setEnabled(false);
843 myDistributionColorLbl->setEnabled(false);
848 //=================================================================================================
850 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
852 * Called when orientation is changed
854 //=================================================================================================
855 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
857 initScalarBarFromResources();
859 int aOrientation = myVertRadioBtn->isChecked();
860 if ( aOrientation == myIniOrientation )
861 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
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 );
869 //=================================================================================================
871 * SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
873 * Rereading vertical and horizontal default positions from resources.
875 //=================================================================================================
876 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
878 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
881 // initialize from resources
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" ));
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" ));
907 //=================================================================================================
909 * SMESHGUI_Preferences_ScalarBarDlg::applyThreshold()
911 * Hides and shows elements beyond the given min - max range by threshold filter inside the actor.
913 //=================================================================================================
914 void SMESHGUI_Preferences_ScalarBarDlg::applyThreshold(double min, double max)
916 myActor->ClipThreshold(myThresholdCheck->isChecked(), min, max);
919 //=================================================================================================
921 * SMESHGUI_Preferences_ScalarBarDlg::applyWireframeOff()
923 * Hides and shows edges' lines.
925 //=================================================================================================
926 void SMESHGUI_Preferences_ScalarBarDlg::applyWireframeOff()
928 myActor->SetWireframeOff(myWireframeOffCheck->isChecked());