1 // Copyright (C) 2007-2010 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_ScalarBarActor.h>
37 #include <SMESH_ControlsDef.hxx>
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_MessageBox.h>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <SALOME_ListIO.hxx>
48 #include <SalomeApp_IntSpinBox.h>
50 #include <QtxColorButton.h>
53 #include <QButtonGroup>
59 #include <QPushButton>
60 #include <QRadioButton>
61 #include <QHBoxLayout>
62 #include <QVBoxLayout>
63 #include <QGridLayout>
64 #include <QDoubleValidator>
67 #include <vtkTextProperty.h>
68 #include <vtkLookupTable.h>
70 #define MINIMUM_WIDTH 70
71 #define MARGIN_SIZE 11
72 #define SPACING_SIZE 6
74 // Only one instance is allowed
75 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
77 //=================================================================================================
79 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
81 * Gets the only instance of "Scalar Bar Properties" dialog box
83 //=================================================================================================
84 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
87 myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule );
92 myDlg->activateWindow();
96 //=================================================================================================
98 * SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
102 //=================================================================================================
103 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule )
104 : QDialog( SMESH::GetDesktop( theModule ) ),
105 mySMESHGUI( theModule ),
106 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
118 setAttribute( Qt::WA_DeleteOnClose, true );
119 setWindowTitle( tr("SMESH_PROPERTIES_SCALARBAR") );
120 setSizeGripEnabled(true);
124 /******************************************************************************/
126 QVBoxLayout* aTopLayout = new QVBoxLayout( this );
127 aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
129 /******************************************************************************/
131 myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this );
132 QHBoxLayout* myRangeGrpLayout = new QHBoxLayout( myRangeGrp );
133 myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
135 myMinEdit = new QLineEdit( myRangeGrp );
136 myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
137 myMinEdit->setValidator( new QDoubleValidator( this ) );
139 myMaxEdit = new QLineEdit( myRangeGrp );
140 myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
141 myMaxEdit->setValidator( new QDoubleValidator( this ) );
143 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp ) );
144 myRangeGrpLayout->addWidget( myMinEdit );
145 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp ) );
146 myRangeGrpLayout->addWidget( myMaxEdit );
148 aTopLayout->addWidget( myRangeGrp );
150 /******************************************************************************/
152 myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this );
153 QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp );
154 myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
156 myTitleColorBtn = new QtxColorButton( myFontGrp );
158 myTitleFontCombo = new QComboBox( myFontGrp );
159 myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
160 myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
161 myTitleFontCombo->addItem( tr( "SMESH_FONT_ARIAL" ) );
162 myTitleFontCombo->addItem( tr( "SMESH_FONT_COURIER" ) );
163 myTitleFontCombo->addItem( tr( "SMESH_FONT_TIMES" ) );
165 myTitleBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp );
166 myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp );
167 myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp );
169 myLabelsColorBtn = new QtxColorButton( myFontGrp );
171 myLabelsFontCombo = new QComboBox( myFontGrp );
172 myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
173 myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
174 myLabelsFontCombo->addItem( tr( "SMESH_FONT_ARIAL" ) );
175 myLabelsFontCombo->addItem( tr( "SMESH_FONT_COURIER" ) );
176 myLabelsFontCombo->addItem( tr( "SMESH_FONT_TIMES" ) );
178 myLabelsBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp );
179 myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp );
180 myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp );
182 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp ), 0, 0 );
183 myFontGrpLayout->addWidget( myTitleColorBtn, 0, 1 );
184 myFontGrpLayout->addWidget( myTitleFontCombo, 0, 2 );
185 myFontGrpLayout->addWidget( myTitleBoldCheck, 0, 3 );
186 myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
187 myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
189 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp ), 1, 0 );
190 myFontGrpLayout->addWidget( myLabelsColorBtn, 1, 1 );
191 myFontGrpLayout->addWidget( myLabelsFontCombo, 1, 2 );
192 myFontGrpLayout->addWidget( myLabelsBoldCheck, 1, 3 );
193 myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
194 myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
196 aTopLayout->addWidget( myFontGrp );
198 /******************************************************************************/
200 myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this );
201 QHBoxLayout* myLabColorGrpLayout = new QHBoxLayout( myLabColorGrp );
202 myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
204 myColorsSpin = new SalomeApp_IntSpinBox( myLabColorGrp );
205 myColorsSpin->setAcceptNames( false ); // No Notebook variables allowed
206 myColorsSpin->setRange( 2, 256 );
207 myColorsSpin->setSingleStep( 1 );
208 myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
209 myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
211 myLabelsSpin = new SalomeApp_IntSpinBox( myLabColorGrp );
212 myLabelsSpin->setAcceptNames( false ); // No Notebook variables allowed
213 myLabelsSpin->setRange( 2, 65 );
214 myLabelsSpin->setSingleStep( 1 );
215 myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
216 myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
218 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp ) );
219 myLabColorGrpLayout->addWidget( myColorsSpin );
220 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp ) );
221 myLabColorGrpLayout->addWidget( myLabelsSpin );
223 aTopLayout->addWidget( myLabColorGrp );
225 /******************************************************************************/
227 myOrientationGrp = new QGroupBox ( tr( "SMESH_ORIENTATION" ), this );
228 QButtonGroup* aOrientationGrp = new QButtonGroup( this );
229 QHBoxLayout* myOrientationGrpLayout = new QHBoxLayout( myOrientationGrp );
230 myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
232 myVertRadioBtn = new QRadioButton( tr( "SMESH_VERTICAL" ), myOrientationGrp );
233 myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp );
234 myVertRadioBtn->setChecked( true );
236 myOrientationGrpLayout->addWidget( myVertRadioBtn );
237 myOrientationGrpLayout->addWidget( myHorizRadioBtn );
238 aOrientationGrp->addButton(myVertRadioBtn);
239 aOrientationGrp->addButton(myHorizRadioBtn);
241 aTopLayout->addWidget( myOrientationGrp );
243 /******************************************************************************/
245 myOriginDimGrp = new QGroupBox ( tr("SMESH_POSITION_SIZE_SCALARBAR"), this );
246 QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp );
247 myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
249 myXSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
250 myXSpin->setAcceptNames( false );
251 myXSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );
252 myXSpin->setMinimumWidth( MINIMUM_WIDTH );
253 myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
255 myYSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
256 myYSpin->setAcceptNames( false );
257 myYSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );
258 myYSpin->setMinimumWidth( MINIMUM_WIDTH );
259 myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
261 myWidthSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
262 myWidthSpin->setAcceptNames( false );
263 myWidthSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );
264 myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
265 myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
267 myHeightSpin = new SMESHGUI_SpinBox(myOriginDimGrp);
268 myHeightSpin->setAcceptNames( false );
269 myHeightSpin->RangeStepAndValidator( 0.0, 1.0, 0.1, "parametric_precision" );
270 myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
271 myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
273 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp ), 0, 0 );
274 myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
275 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp ), 0, 2 );
276 myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
277 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ), myOriginDimGrp ), 1, 0 );
278 myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
279 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp ), 1, 2 );
280 myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
282 aTopLayout->addWidget( myOriginDimGrp );
283 /******************************************************************************/
286 myDistributionGrp = new QGroupBox ( tr( "SMESH_DISTRIBUTION_SCALARBAR" ), this );
287 myDistributionGrp->setCheckable(true);
288 QHBoxLayout* aDistributionGrpLayout = new QHBoxLayout( myDistributionGrp );
289 aDistributionGrpLayout->setSpacing( SPACING_SIZE ); aDistributionGrpLayout->setMargin( MARGIN_SIZE );
291 myDistribColorGrp = new QButtonGroup( this );
293 myDMonoColor = new QRadioButton( tr( "SMESH_MONOCOLOR" ) , myDistributionGrp );
294 myDMultiColor = new QRadioButton( tr( "SMESH_MULTICOLOR" ), myDistributionGrp );
295 myDMonoColor->setChecked( true );
297 myDistribColorGrp->addButton(myDMonoColor);myDistribColorGrp->setId(myDMonoColor,1);
298 myDistribColorGrp->addButton(myDMultiColor);myDistribColorGrp->setId(myDMultiColor,2);
300 aDistributionGrpLayout->addWidget( myDMultiColor );
301 aDistributionGrpLayout->addWidget( myDMonoColor );
303 //Color of the Distribution in monocolor case:
304 myDistributionColorLbl = new QLabel( tr( "SMESH_DISTRIBUTION_COLOR" ), myDistributionGrp );
305 aDistributionGrpLayout->addWidget( myDistributionColorLbl );
306 myMonoColorBtn = new QtxColorButton( myDistributionGrp );
307 aDistributionGrpLayout->addWidget(myMonoColorBtn);
309 aTopLayout->addWidget(myDistributionGrp);
311 /******************************************************************************/
313 myButtonGrp = new QGroupBox( this );
314 QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp );
315 myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
317 myOkBtn = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), myButtonGrp );
318 myOkBtn->setAutoDefault( true ); myOkBtn->setDefault( true );
319 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp );
320 myApplyBtn->setAutoDefault( true );
321 myCancelBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), myButtonGrp );
322 myCancelBtn->setAutoDefault( true );
323 myHelpBtn = new QPushButton( tr("SMESH_BUT_HELP"), myButtonGrp );
324 myHelpBtn->setAutoDefault(true);
326 myButtonGrpLayout->addWidget( myOkBtn );
327 myButtonGrpLayout->addSpacing( 10 );
328 myButtonGrpLayout->addWidget( myApplyBtn );
329 myButtonGrpLayout->addSpacing( 10 );
330 myButtonGrpLayout->addStretch();
331 myButtonGrpLayout->addWidget( myCancelBtn );
332 myButtonGrpLayout->addWidget( myHelpBtn );
334 aTopLayout->addWidget( myButtonGrp );
336 /***************************************************************/
338 // --> first init from preferences
339 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
341 QColor titleColor = mgr->colorValue("SMESH", "scalar_bar_title_color",
342 QColor(255, 255, 255));
343 myTitleColorBtn->setColor(titleColor);
344 myTitleFontCombo->setCurrentIndex(0);
345 if (mgr->hasValue("SMESH", "scalar_bar_title_font")) {
346 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
347 if( f.family()=="Arial" )
348 myTitleFontCombo->setCurrentIndex(0);
349 if( f.family()=="Courier" )
350 myTitleFontCombo->setCurrentIndex(1);
351 if( f.family()=="Times")
352 myTitleFontCombo->setCurrentIndex(2);
354 myTitleBoldCheck->setChecked ( f.bold() );
355 myTitleItalicCheck->setChecked( f.italic() );
356 myTitleShadowCheck->setChecked( f.overline() );
359 QColor labelColor = mgr->colorValue("SMESH", "scalar_bar_label_color",
360 QColor(255, 255, 255));
361 myLabelsColorBtn->setColor(labelColor);
362 myLabelsFontCombo->setCurrentIndex(0);
363 if (mgr->hasValue("SMESH", "scalar_bar_label_font")) {
364 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
365 if (f.family() == "Arial")
366 myLabelsFontCombo->setCurrentIndex(0);
367 if (f.family() == "Courier")
368 myLabelsFontCombo->setCurrentIndex(1);
369 if (f.family() == "Times")
370 myLabelsFontCombo->setCurrentIndex(2);
372 myLabelsBoldCheck ->setChecked( f.bold() );
373 myLabelsItalicCheck->setChecked( f.italic() );
374 myLabelsShadowCheck->setChecked( f.overline() );
377 int aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors", 64);
378 myColorsSpin->setValue(aNbColors);
380 int aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels", 5);
381 myLabelsSpin->setValue(aNbLabels);
383 int aOrientation = mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 );
384 bool isHoriz = aOrientation == 1;
386 myHorizRadioBtn->setChecked(true);
388 myVertRadioBtn->setChecked(true);
389 myIniOrientation = myVertRadioBtn->isChecked();
391 QString name = isHoriz ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
393 myIniX = mgr->doubleValue("SMESH", name.arg( "x" ),
394 myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X);
396 myIniY = mgr->doubleValue("SMESH", name.arg( "y" ),
397 myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y);
399 myIniW = mgr->doubleValue("SMESH", name.arg( "width" ),
400 myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W);
402 myIniH = mgr->doubleValue("SMESH", name.arg( "height" ),
403 myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H);
405 setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
408 bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
409 myDistributionGrp->setChecked(distributionVisibility);
411 int coloringType = mgr->integerValue("SMESH", "distribution_coloring_type", 0);
412 if( coloringType == SMESH_MONOCOLOR_TYPE ) {
413 myDMultiColor->setChecked(true);
414 onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
416 myDMonoColor->setChecked(true);
417 onDistributionChanged(myDistribColorGrp->id(myDMonoColor));
420 QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
421 QColor(255, 255, 255));
422 myMonoColorBtn->setColor(distributionColor);
426 // --> then init from selection if necessary
427 onSelectionChanged();
429 /***************************************************************/
431 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
432 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
433 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
434 connect( myHelpBtn, SIGNAL(clicked()), this, SLOT( onHelp() ) );
435 connect( myXSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
436 connect( myYSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
437 connect( aOrientationGrp, SIGNAL( buttonClicked( int ) ), this, SLOT( onOrientationChanged() ) );
438 connect( myDistribColorGrp, SIGNAL( buttonClicked( int ) ), this, SLOT( onDistributionChanged( int ) ) );
439 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
440 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) );
442 myHelpFileName = "quality_page.html";
445 //=================================================================================================
447 * SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
451 //=================================================================================================
452 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
456 //=================================================================================================
458 * SMESHGUI_Preferences_ScalarBarDlg::onOk
462 //=================================================================================================
463 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
469 //=================================================================================================
471 * SMESHGUI_Preferences_ScalarBarDlg::onApply
475 //=================================================================================================
476 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
478 // Scalar Bar properties
481 SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
483 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
484 QColor aTColor = myTitleColorBtn->color();
485 aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
486 if ( myTitleFontCombo->currentIndex() == 0 )
487 aTitleTextPrp->SetFontFamilyToArial();
488 else if ( myTitleFontCombo->currentIndex() == 1 )
489 aTitleTextPrp->SetFontFamilyToCourier();
491 aTitleTextPrp->SetFontFamilyToTimes();
492 aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
493 aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
494 aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
495 myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
497 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
498 QColor aLColor = myLabelsColorBtn->color();
499 aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
500 if ( myLabelsFontCombo->currentIndex() == 0 )
501 aLabelsTextPrp->SetFontFamilyToArial();
502 else if ( myLabelsFontCombo->currentIndex() == 1 )
503 aLabelsTextPrp->SetFontFamilyToCourier();
505 aLabelsTextPrp->SetFontFamilyToTimes();
506 aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
507 aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
508 aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
509 myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
511 myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
513 if ( myHorizRadioBtn->isChecked() )
514 myScalarBarActor->SetOrientationToHorizontal();
516 myScalarBarActor->SetOrientationToVertical();
518 myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
519 myScalarBarActor->SetWidth( myWidthSpin->value() );
520 myScalarBarActor->SetHeight( myHeightSpin->value() );
523 myScalarBarActor->SetDistributionVisibility((int)myDistributionGrp->isChecked());
524 if( myDistributionGrp->isChecked() ) {
525 int ColoringType = myDMultiColor->isChecked() ? SMESH_MULTICOLOR_TYPE : SMESH_MONOCOLOR_TYPE;
526 myScalarBarActor->SetDistributionColoringType(ColoringType);
527 if( !myDMultiColor->isChecked() ) {
528 QColor aTColor = myMonoColorBtn->color();
530 rgb [0] = aTColor.red()/255.;
531 rgb [1] = aTColor.green()/255.;
532 rgb [2] = aTColor.blue()/255.;
533 myScalarBarActor->SetDistributionColor(rgb);
537 double aMin = myMinEdit->text().toDouble();
538 double aMax = myMaxEdit->text().toDouble();
539 vtkLookupTable* myLookupTable =
540 static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
541 double oldMinMax[2] = { myLookupTable->GetRange()[0], myLookupTable->GetRange()[1] };
542 bool rangeChanges = ( fabs( oldMinMax[0] - aMin ) + fabs( oldMinMax[1] - aMax ) >
543 0.001 * ( aMax-aMin + oldMinMax[1]-oldMinMax[0] ));
545 bool nbColorsChanged = (myColorsSpin->value() != myScalarBarActor->GetMaximumNumberOfColors());
547 myScalarBarActor->SetMaximumNumberOfColors(myColorsSpin->value());
550 myLookupTable->SetRange( aMin, aMax );
551 myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
552 myLookupTable->Build();
554 if( nbColorsChanged || rangeChanges)
555 myActor->UpdateDistribution();
557 SMESH::RepaintCurrentView();
561 //=================================================================================================
563 * SMESHGUI_Preferences_ScalarBarDlg::onCancel
567 //=================================================================================================
568 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
573 //=================================================================================================
575 * SMESHGUI_Preferences_ScalarBarDlg::onHelp
579 //=================================================================================================
580 void SMESHGUI_Preferences_ScalarBarDlg::onHelp()
582 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
584 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
588 platform = "winapplication";
590 platform = "application";
592 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
593 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
594 arg(app->resourceMgr()->stringValue("ExternalBrowser",
596 arg(myHelpFileName));
600 //=================================================================================================
602 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
604 * Called when selection changed
606 //=================================================================================================
607 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
610 mySelectionMgr->selectedObjects(aList);
612 if (aList.Extent() == 1) {
613 Handle(SALOME_InteractiveObject) anIO = aList.First();
614 if( anIO->hasEntry() ) {
615 SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
616 if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
618 SMESH_ScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
620 if ( myScalarBarActor->GetLookupTable() ) {
621 vtkFloatingPointType *range = myScalarBarActor->GetLookupTable()->GetRange();
622 myMinEdit->setText( QString::number( range[0],'g',12 ) );
623 myMaxEdit->setText( QString::number( range[1],'g',12 ) );
626 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
627 vtkFloatingPointType aTColor[3];
628 aTitleTextPrp->GetColor( aTColor );
629 myTitleColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
630 myTitleFontCombo->setCurrentIndex( aTitleTextPrp->GetFontFamily() );
631 myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
632 myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
633 myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
635 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
636 vtkFloatingPointType aLColor[3];
637 aLabelsTextPrp->GetColor( aLColor );
638 myLabelsColorBtn->setColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
639 myLabelsFontCombo->setCurrentIndex( aLabelsTextPrp->GetFontFamily() );
640 myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
641 myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
642 myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
644 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
645 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
647 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
648 myVertRadioBtn->setChecked( true );
650 myHorizRadioBtn->setChecked( true );
651 myIniOrientation = myVertRadioBtn->isChecked();
653 myIniX = myScalarBarActor->GetPosition()[0];
654 myIniY = myScalarBarActor->GetPosition()[1];
655 myIniW = myScalarBarActor->GetWidth();
656 myIniH = myScalarBarActor->GetHeight();
657 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
659 myDistributionGrp->setChecked((bool)myScalarBarActor->GetDistributionVisibility());
660 int coloringType = myScalarBarActor->GetDistributionColoringType();
661 myScalarBarActor->GetDistributionColor( aTColor );
662 myMonoColorBtn->setColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
663 if ( coloringType == SMESH_MONOCOLOR_TYPE ) {
664 myDMonoColor->setChecked(true);
665 onDistributionChanged(myDistribColorGrp->id(myDMonoColor));
667 myDMultiColor->setChecked(true);
668 onDistributionChanged(myDistribColorGrp->id(myDMultiColor));
670 myRangeGrp->setEnabled( true );
671 myFontGrp->setEnabled( true );
672 myLabColorGrp->setEnabled( true );
673 myOrientationGrp->setEnabled( true );
674 myOriginDimGrp->setEnabled( true );
675 myOkBtn->setEnabled( true );
676 myApplyBtn->setEnabled( true );
682 myRangeGrp->setEnabled( false );
683 myFontGrp->setEnabled( false );
684 myLabColorGrp->setEnabled( false );
685 myOrientationGrp->setEnabled( false );
686 myOriginDimGrp->setEnabled( false );
687 myOkBtn->setEnabled( false );
688 myApplyBtn->setEnabled( false );
691 //=================================================================================================
693 * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
695 * Close event handler
697 //=================================================================================================
698 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
701 QDialog::closeEvent( e );
704 //=================================================================================================
706 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
708 * Called when X, Y values are changed
710 //=================================================================================================
711 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
713 myWidthSpin->setMaximum( 1.0 - myXSpin->value() );
714 myHeightSpin->setMaximum( 1.0 - myYSpin->value() );
717 //=================================================================================================
719 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
721 * Called when X, Y values are changed
723 //=================================================================================================
724 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
729 blockSignals( true );
730 myXSpin->setValue( x );
731 myYSpin->setValue( y );
732 myWidthSpin->setMaximum( 1.0 );
733 myWidthSpin->setValue( w );
734 myHeightSpin->setMaximum( 1.0 );
735 myHeightSpin->setValue( h );
736 blockSignals( false );
741 //=================================================================================================
743 * SMESHGUI_Preferences_ScalarBarDlg::onDistributionChanged
745 * Called when coloring type of the distribution is changed
747 //=================================================================================================
748 void SMESHGUI_Preferences_ScalarBarDlg::onDistributionChanged( int id ) {
749 myMonoColorBtn->setEnabled(myDistribColorGrp->id(myDMonoColor) == id);
750 myDistributionColorLbl->setEnabled(myDistribColorGrp->id(myDMonoColor) == id);
753 //=================================================================================================
755 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
757 * Called when orientation is changed
759 //=================================================================================================
760 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
762 initScalarBarFromResources();
764 int aOrientation = myVertRadioBtn->isChecked();
765 if ( aOrientation == myIniOrientation )
766 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
768 setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
769 aOrientation ? DEF_VER_Y : DEF_HOR_Y,
770 aOrientation ? DEF_VER_W : DEF_HOR_W,
771 aOrientation ? DEF_VER_H : DEF_HOR_H );
774 //=================================================================================================
776 * SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
778 * Rereading vertical and horizontal default positions from resources.
780 //=================================================================================================
781 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
783 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
786 // initialize from resoources
789 name = QString("scalar_bar_horizontal_%1");
790 if (mgr->hasValue("SMESH", name.arg( "x" )))
791 DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
792 if (mgr->hasValue("SMESH", name.arg( "y" )))
793 DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
794 if (mgr->hasValue("SMESH", name.arg( "width" )))
795 DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
796 if (mgr->hasValue("SMESH", name.arg( "height" )))
797 DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
800 name = QString("scalar_bar_vertical_%1");
801 if (mgr->hasValue("SMESH", name.arg( "x" )))
802 DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
803 if (mgr->hasValue("SMESH", name.arg( "y" )))
804 DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
805 if (mgr->hasValue("SMESH", name.arg( "width" )))
806 DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
807 if (mgr->hasValue("SMESH", name.arg( "height" )))
808 DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));