1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, 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.
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>
54 #include <QButtonGroup>
60 #include <QPushButton>
61 #include <QRadioButton>
62 #include <QHBoxLayout>
63 #include <QVBoxLayout>
64 #include <QGridLayout>
65 #include <QDoubleValidator>
68 #include <vtkTextProperty.h>
69 #include <vtkLookupTable.h>
71 #define MINIMUM_WIDTH 70
72 #define MARGIN_SIZE 11
73 #define SPACING_SIZE 6
75 // Only one instance is allowed
76 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
78 //=================================================================================================
80 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
82 * Gets the only instance of "Scalar Bar Properties" dialog box
84 //=================================================================================================
85 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
88 myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule );
93 myDlg->activateWindow();
97 //=================================================================================================
99 * SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
103 //=================================================================================================
104 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule )
105 : QDialog( SMESH::GetDesktop( theModule ) ),
106 mySMESHGUI( theModule ),
107 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
119 setAttribute( Qt::WA_DeleteOnClose, true );
120 setWindowTitle( tr("SMESH_PROPERTIES_SCALARBAR") );
121 setSizeGripEnabled(true);
125 /******************************************************************************/
127 QVBoxLayout* aTopLayout = new QVBoxLayout( this );
128 aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
130 /******************************************************************************/
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 );
137 myMinEdit = new QLineEdit( myRangeGrp );
138 myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
139 myMinEdit->setValidator( new QDoubleValidator( this ) );
141 myMaxEdit = new QLineEdit( myRangeGrp );
142 myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
143 myMaxEdit->setValidator( new QDoubleValidator( this ) );
145 myLogarithmicCheck = new QCheckBox (myRangeGrp);
146 myLogarithmicCheck->setText(tr("SMESH_LOGARITHMIC_SCALARBAR"));
147 myLogarithmicCheck->setChecked(false);
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 );
155 aTopLayout->addWidget( myRangeGrp );
157 /******************************************************************************/
159 myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this );
160 QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp );
161 myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
163 myTitleColorBtn = new QtxColorButton( myFontGrp );
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" ) );
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 );
176 myLabelsColorBtn = new QtxColorButton( myFontGrp );
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" ) );
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 );
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 );
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 );
203 aTopLayout->addWidget( myFontGrp );
205 /******************************************************************************/
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 );
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 ) );
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 ) );
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 );
230 aTopLayout->addWidget( myLabColorGrp );
232 /******************************************************************************/
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 );
239 myVertRadioBtn = new QRadioButton( tr( "SMESH_VERTICAL" ), myOrientationGrp );
240 myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp );
241 myVertRadioBtn->setChecked( true );
243 myOrientationGrpLayout->addWidget( myVertRadioBtn );
244 myOrientationGrpLayout->addWidget( myHorizRadioBtn );
245 aOrientationGrp->addButton(myVertRadioBtn);
246 aOrientationGrp->addButton(myHorizRadioBtn);
248 aTopLayout->addWidget( myOrientationGrp );
250 /******************************************************************************/
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 );
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 ) );
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 ) );
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 ) );
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 ) );
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 );
289 aTopLayout->addWidget( myOriginDimGrp );
290 /******************************************************************************/
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 );
298 myDistribColorGrp = new QButtonGroup( this );
300 myDMonoColor = new QRadioButton( tr( "SMESH_MONOCOLOR" ) , myDistributionGrp );
301 myDMultiColor = new QRadioButton( tr( "SMESH_MULTICOLOR" ), myDistributionGrp );
302 myDMonoColor->setChecked( true );
304 myDistribColorGrp->addButton(myDMonoColor);myDistribColorGrp->setId(myDMonoColor,1);
305 myDistribColorGrp->addButton(myDMultiColor);myDistribColorGrp->setId(myDMultiColor,2);
307 aDistributionGrpLayout->addWidget( myDMultiColor );
308 aDistributionGrpLayout->addWidget( myDMonoColor );
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);
316 aTopLayout->addWidget(myDistributionGrp);
318 /******************************************************************************/
320 myButtonGrp = new QGroupBox( this );
321 QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp );
322 myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
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);
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 );
341 aTopLayout->addWidget( myButtonGrp );
343 /***************************************************************/
345 // --> first init from preferences
346 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
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);
361 myTitleBoldCheck->setChecked ( f.bold() );
362 myTitleItalicCheck->setChecked( f.italic() );
363 myTitleShadowCheck->setChecked( f.overline() );
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);
379 myLabelsBoldCheck ->setChecked( f.bold() );
380 myLabelsItalicCheck->setChecked( f.italic() );
381 myLabelsShadowCheck->setChecked( f.overline() );
384 int aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors", 64);
385 myColorsSpin->setValue(aNbColors);
387 int aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels", 5);
388 myLabelsSpin->setValue(aNbLabels);
390 int aOrientation = mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 );
391 bool isHoriz = aOrientation == 1;
393 myHorizRadioBtn->setChecked(true);
395 myVertRadioBtn->setChecked(true);
396 myIniOrientation = myVertRadioBtn->isChecked();
398 QString name = isHoriz ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
400 myIniX = mgr->doubleValue("SMESH", name.arg( "x" ),
401 myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X);
403 myIniY = mgr->doubleValue("SMESH", name.arg( "y" ),
404 myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y);
406 myIniW = mgr->doubleValue("SMESH", name.arg( "width" ),
407 myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W);
409 myIniH = mgr->doubleValue("SMESH", name.arg( "height" ),
410 myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H);
412 setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
415 bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
416 myDistributionGrp->setChecked(distributionVisibility);
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));
423 myDMultiColor->setChecked(true);
424 onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
428 QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
429 QColor(255, 255, 255));
430 myMonoColorBtn->setColor(distributionColor);
432 // --> then init from selection if necessary
433 onSelectionChanged();
435 /***************************************************************/
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() ) );
451 myHelpFileName = "quality_page.html";
454 //=================================================================================================
456 * SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
460 //=================================================================================================
461 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
465 //=================================================================================================
467 * SMESHGUI_Preferences_ScalarBarDlg::onOk
471 //=================================================================================================
472 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
478 //=================================================================================================
480 * SMESHGUI_Preferences_ScalarBarDlg::onApply
484 //=================================================================================================
485 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
487 // Scalar Bar properties
490 SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
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();
500 aTitleTextPrp->SetFontFamilyToTimes();
501 aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
502 aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
503 aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
504 myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
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();
514 aLabelsTextPrp->SetFontFamilyToTimes();
515 aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
516 aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
517 aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
518 myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
520 myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
522 if ( myHorizRadioBtn->isChecked() )
523 myScalarBarActor->SetOrientationToHorizontal();
525 myScalarBarActor->SetOrientationToVertical();
527 myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
528 myScalarBarActor->SetWidth( myWidthSpin->value() );
529 myScalarBarActor->SetHeight( myHeightSpin->value() );
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);
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]);
549 myScalarBarActor->SetDistributionColor(rgb);
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] ));
561 bool nbColorsChanged = (myColorsSpin->value() != myScalarBarActor->GetMaximumNumberOfColors());
563 myScalarBarActor->SetMaximumNumberOfColors(myColorsSpin->value());
565 myLookupTable->SetRange( aMin, aMax );
566 myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
568 bool scaleChanged = (myLogarithmicCheck->isChecked() != (myLookupTable->GetScale() == VTK_SCALE_LOG10));
570 myLookupTable->SetScale(myLogarithmicCheck->isChecked() ? VTK_SCALE_LOG10 : VTK_SCALE_LINEAR);
572 myLookupTable->Build();
574 if (nbColorsChanged || rangeChanges || scaleChanged)
575 myActor->UpdateDistribution();
577 #ifndef DISABLE_PLOT2DVIEWER
578 if( myActor->GetPlot2Histogram() &&
581 distributionTypeChanged ||
583 SMESH::ProcessIn2DViewers(myActor);
586 SMESH::RepaintCurrentView();
590 //=================================================================================================
592 * SMESHGUI_Preferences_ScalarBarDlg::reject
596 //=================================================================================================
597 void SMESHGUI_Preferences_ScalarBarDlg::reject()
603 //=================================================================================================
605 * SMESHGUI_Preferences_ScalarBarDlg::onHelp
609 //=================================================================================================
610 void SMESHGUI_Preferences_ScalarBarDlg::onHelp()
612 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
614 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
618 platform = "winapplication";
620 platform = "application";
622 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
623 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
624 arg(app->resourceMgr()->stringValue("ExternalBrowser",
626 arg(myHelpFileName));
630 //=================================================================================================
632 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
634 * Called when selection changed
636 //=================================================================================================
637 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
640 mySelectionMgr->selectedObjects(aList);
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 ) {
648 SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
650 if ( myScalarBarActor->GetLookupTable() ) {
651 vtkLookupTable* aLookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
653 vtkFloatingPointType *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);
660 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
661 vtkFloatingPointType aTColor[3];
662 aTitleTextPrp->GetColor( aTColor );
663 myTitleColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
664 myTitleFontCombo->setCurrentIndex( aTitleTextPrp->GetFontFamily() );
665 myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
666 myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
667 myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
669 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
670 vtkFloatingPointType aLColor[3];
671 aLabelsTextPrp->GetColor( aLColor );
672 myLabelsColorBtn->setColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
673 myLabelsFontCombo->setCurrentIndex( aLabelsTextPrp->GetFontFamily() );
674 myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
675 myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
676 myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
678 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
679 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
681 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
682 myVertRadioBtn->setChecked( true );
684 myHorizRadioBtn->setChecked( true );
685 myIniOrientation = myVertRadioBtn->isChecked();
687 myIniX = myScalarBarActor->GetPosition()[0];
688 myIniY = myScalarBarActor->GetPosition()[1];
689 myIniW = myScalarBarActor->GetWidth();
690 myIniH = myScalarBarActor->GetHeight();
691 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
693 int coloringType = myScalarBarActor->GetDistributionColoringType();
694 myScalarBarActor->GetDistributionColor( aTColor );
695 myMonoColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
696 if ( coloringType == SMESH_MONOCOLOR_TYPE ) {
697 myDMonoColor->setChecked(true);
698 onDistributionChanged(myDistribColorGrp->id(myDMonoColor));
700 myDMultiColor->setChecked(true);
701 onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
703 myDistributionGrp->setChecked((bool)myScalarBarActor->GetDistributionVisibility());
704 onDistributionActivated(myScalarBarActor->GetDistributionVisibility());
706 myRangeGrp->setEnabled( true );
707 myFontGrp->setEnabled( true );
708 myLabColorGrp->setEnabled( true );
709 myOrientationGrp->setEnabled( true );
710 myOriginDimGrp->setEnabled( true );
711 myOkBtn->setEnabled( true );
712 myApplyBtn->setEnabled( true );
713 myDistributionGrp->setEnabled( true );
719 myRangeGrp->setEnabled( false );
720 myFontGrp->setEnabled( false );
721 myLabColorGrp->setEnabled( false );
722 myOrientationGrp->setEnabled( false );
723 myOriginDimGrp->setEnabled( false );
724 myOkBtn->setEnabled( false );
725 myApplyBtn->setEnabled( false );
726 myDistributionGrp->setEnabled( false );
729 //=================================================================================================
731 * SMESHGUI_Preferences_ScalarBarDlg::onMinMaxChanged
733 * Called when Scalar Range values are changed
735 //=================================================================================================
736 void SMESHGUI_Preferences_ScalarBarDlg::onMinMaxChanged()
738 double aMin = myMinEdit->text().toDouble();
739 double aMax = myMaxEdit->text().toDouble();
740 bool isLogarithmicEnabled = (aMin > 1e-07 && aMax > 1e-07);
741 myLogarithmicCheck->setChecked(isLogarithmicEnabled);
742 myLogarithmicCheck->setEnabled(isLogarithmicEnabled);
745 //=================================================================================================
747 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
749 * Called when X, Y values are changed
751 //=================================================================================================
752 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
754 myWidthSpin->setMaximum( 1.0 - myXSpin->value() );
755 myHeightSpin->setMaximum( 1.0 - myYSpin->value() );
758 //=================================================================================================
760 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
762 * Called when X, Y values are changed
764 //=================================================================================================
765 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
770 blockSignals( true );
771 myXSpin->setValue( x );
772 myYSpin->setValue( y );
773 myWidthSpin->setMaximum( 1.0 );
774 myWidthSpin->setValue( w );
775 myHeightSpin->setMaximum( 1.0 );
776 myHeightSpin->setValue( h );
777 blockSignals( false );
782 //=================================================================================================
784 * SMESHGUI_Preferences_ScalarBarDlg::onDistributionChanged
786 * Called when coloring type of the distribution is changed
788 //=================================================================================================
789 void SMESHGUI_Preferences_ScalarBarDlg::onDistributionChanged( int id ) {
791 bool isActive = myDistribColorGrp->id(myDMonoColor) == id;
793 myMonoColorBtn->setEnabled(isActive);
794 myDistributionColorLbl->setEnabled(isActive);
796 //=================================================================================================
798 * SMESHGUI_Preferences_ScalarBarDlg::onDistributionActivated
800 * Called when distribution group check box is changed
802 //=================================================================================================
803 void SMESHGUI_Preferences_ScalarBarDlg::onDistributionActivated(bool on) {
805 if(myDMonoColor->isChecked())
806 onDistributionChanged(myDistribColorGrp->id(myDMonoColor) );
807 else if(myDMultiColor->isChecked())
808 onDistributionChanged(myDistribColorGrp->id(myDMultiColor) );
811 myMonoColorBtn->setEnabled(false);
812 myDistributionColorLbl->setEnabled(false);
817 //=================================================================================================
819 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
821 * Called when orientation is changed
823 //=================================================================================================
824 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
826 initScalarBarFromResources();
828 int aOrientation = myVertRadioBtn->isChecked();
829 if ( aOrientation == myIniOrientation )
830 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
832 setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
833 aOrientation ? DEF_VER_Y : DEF_HOR_Y,
834 aOrientation ? DEF_VER_W : DEF_HOR_W,
835 aOrientation ? DEF_VER_H : DEF_HOR_H );
838 //=================================================================================================
840 * SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
842 * Rereading vertical and horizontal default positions from resources.
844 //=================================================================================================
845 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
847 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
850 // initialize from resoources
853 name = QString("scalar_bar_horizontal_%1");
854 if (mgr->hasValue("SMESH", name.arg( "x" )))
855 DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
856 if (mgr->hasValue("SMESH", name.arg( "y" )))
857 DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
858 if (mgr->hasValue("SMESH", name.arg( "width" )))
859 DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
860 if (mgr->hasValue("SMESH", name.arg( "height" )))
861 DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
864 name = QString("scalar_bar_vertical_%1");
865 if (mgr->hasValue("SMESH", name.arg( "x" )))
866 DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
867 if (mgr->hasValue("SMESH", name.arg( "y" )))
868 DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
869 if (mgr->hasValue("SMESH", name.arg( "width" )))
870 DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
871 if (mgr->hasValue("SMESH", name.arg( "height" )))
872 DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));