1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_Preferences_ScalarBarDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_Utils.h"
35 #include "SMESH_Actor.h"
37 #include "SUIT_Desktop.h"
38 #include "SUIT_ResourceMgr.h"
40 #include "LightApp_SelectionMgr.h"
41 #include "SALOME_ListIO.hxx"
43 #include <QtxDblSpinBox.h>
45 #include <qbuttongroup.h>
46 #include <qcheckbox.h>
47 #include <qcombobox.h>
48 #include <qgroupbox.h>
50 #include <qlineedit.h>
51 #include <qpushbutton.h>
52 #include <qtoolbutton.h>
53 #include <qradiobutton.h>
56 #include <qvalidator.h>
57 #include <qcolordialog.h>
59 #include <vtkTextProperty.h>
60 #include <vtkScalarBarActor.h>
61 #include <vtkLookupTable.h>
63 #define MINIMUM_WIDTH 70
64 #define MARGIN_SIZE 11
65 #define SPACING_SIZE 6
69 // Only one instance is allowed
70 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
72 //=================================================================================================
74 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
76 * Gets the only instance of "Scalar Bar Properties" dialog box
78 //=================================================================================================
79 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
82 myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule, true);
86 myDlg->setActiveWindow();
92 //=================================================================================================
94 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
96 * Opens "Scalar Bar Preferences" dialog box
98 //=================================================================================================
99 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( SMESHGUI* theModule )
101 SMESHGUI_Preferences_ScalarBarDlg* aDlg =
102 new SMESHGUI_Preferences_ScalarBarDlg( theModule, false);
106 //=================================================================================================
108 * SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
112 //=================================================================================================
113 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule, bool property, bool modal )
114 : QDialog( SMESH::GetDesktop( theModule ), 0, modal, WStyle_Customize | WStyle_NormalBorder |
115 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
116 mySMESHGUI( theModule ),
117 mySelectionMgr( property ? SMESH::GetSelectionMgr( theModule ) : 0 )
127 setName("SMESHGUI_Preferences_ScalarBarDlg");
128 setCaption( property ? tr("SMESH_PROPERTIES_SCALARBAR") : tr("SMESH_PREFERENCES_SCALARBAR"));
129 setSizeGripEnabled(TRUE);
133 /******************************************************************************/
135 QGridLayout* aTopLayout = new QGridLayout( this );
136 aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
139 /******************************************************************************/
141 if ( mySelectionMgr ) {
142 myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this, "myRangeGrp" );
143 myRangeGrp->setColumnLayout( 0, Qt::Vertical );
144 myRangeGrp->layout()->setSpacing( 0 ); myRangeGrp->layout()->setMargin( 0 );
145 QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp->layout() );
146 myRangeGrpLayout->setAlignment( Qt::AlignTop );
147 myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
149 myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
150 myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
151 myMinEdit->setValidator( new QDoubleValidator( this ) );
153 myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
154 myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
155 myMaxEdit->setValidator( new QDoubleValidator( this ) );
157 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp, "myMinLab" ), 0, 0 );
158 myRangeGrpLayout->addWidget( myMinEdit, 0, 1 );
159 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp, "myMaxLab" ), 0, 2 );
160 myRangeGrpLayout->addWidget( myMaxEdit, 0, 3 );
162 aTopLayout->addWidget( myRangeGrp, aRow, 0 );
166 /******************************************************************************/
168 myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this, "myFontGrp" );
169 myFontGrp->setColumnLayout( 0, Qt::Vertical );
170 myFontGrp->layout()->setSpacing( 0 ); myFontGrp->layout()->setMargin( 0 );
171 QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp->layout() );
172 myFontGrpLayout->setAlignment( Qt::AlignTop );
173 myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
175 myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
176 myTitleColorBtn->setMinimumWidth( 20 );
178 myTitleFontCombo = new QComboBox( false, myFontGrp, "myTitleFontCombo" );
179 myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
180 myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
181 myTitleFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
182 myTitleFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
183 myTitleFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
185 myTitleBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myTitleBoldCheck" );
186 myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myTitleItalicCheck" );
187 myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myTitleShadowCheck" );
189 myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
190 myLabelsColorBtn->setMinimumWidth( 20 );
192 myLabelsFontCombo = new QComboBox( false, myFontGrp, "myLabelsFontCombo" );
193 myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
194 myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
195 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
196 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
197 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
199 myLabelsBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myLabelsBoldCheck" );
200 myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myLabelsItalicCheck" );
201 myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myLabelsShadowCheck" );
203 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp, "myFontTitleLab" ), 0, 0 );
204 myFontGrpLayout->addWidget( myTitleColorBtn, 0, 1 );
205 myFontGrpLayout->addWidget( myTitleFontCombo, 0, 2 );
206 myFontGrpLayout->addWidget( myTitleBoldCheck, 0, 3 );
207 myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
208 myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
210 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp, "myFontLabelsLab" ), 1, 0 );
211 myFontGrpLayout->addWidget( myLabelsColorBtn, 1, 1 );
212 myFontGrpLayout->addWidget( myLabelsFontCombo, 1, 2 );
213 myFontGrpLayout->addWidget( myLabelsBoldCheck, 1, 3 );
214 myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
215 myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
217 aTopLayout->addWidget( myFontGrp, aRow, 0 );
220 /******************************************************************************/
222 myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this, "myLabColorGrp" );
223 myLabColorGrp->setColumnLayout( 0, Qt::Vertical );
224 myLabColorGrp->layout()->setSpacing( 0 ); myLabColorGrp->layout()->setMargin( 0 );
225 QGridLayout* myLabColorGrpLayout = new QGridLayout( myLabColorGrp->layout() );
226 myLabColorGrpLayout->setAlignment( Qt::AlignTop );
227 myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
229 myColorsSpin = new QSpinBox( 2, 256, 1, myLabColorGrp, "myColorsSpin" );
230 myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
231 myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
233 myLabelsSpin = new QSpinBox( 2, 65, 1, myLabColorGrp, "myLabelsSpin" );
234 myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
235 myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
237 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp, "myNbColorLab" ), 0, 0 );
238 myLabColorGrpLayout->addWidget( myColorsSpin, 0, 1 );
239 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp, "myNbLabsLab" ), 0, 2 );
240 myLabColorGrpLayout->addWidget( myLabelsSpin, 0, 3 );
242 aTopLayout->addWidget( myLabColorGrp, aRow, 0 );
245 /******************************************************************************/
247 myOrientationGrp = new QButtonGroup ( tr( "SMESH_ORIENTATION" ), this, "myOrientationGrp" );
248 myOrientationGrp->setColumnLayout( 0, Qt::Vertical );
249 myOrientationGrp->layout()->setSpacing( 0 ); myOrientationGrp->layout()->setMargin( 0 );
250 QGridLayout* myOrientationGrpLayout = new QGridLayout( myOrientationGrp->layout() );
251 myOrientationGrpLayout->setAlignment( Qt::AlignTop );
252 myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
254 myVertRadioBtn = new QRadioButton( tr( "SMESH_VERTICAL" ), myOrientationGrp, "myVertRadioBtn" );
255 myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp, "myHorizRadioBtn" );
256 myVertRadioBtn->setChecked( true );
258 myOrientationGrpLayout->addWidget( myVertRadioBtn, 0, 0 );
259 myOrientationGrpLayout->addWidget( myHorizRadioBtn, 0, 1 );
261 aTopLayout->addWidget( myOrientationGrp, aRow, 0 );
264 /******************************************************************************/
266 myOriginDimGrp = new QGroupBox (tr("SMESH_POSITION_SIZE_SCALARBAR"), this, "myOriginDimGrp");
267 myOriginDimGrp->setColumnLayout(0, Qt::Vertical);
268 myOriginDimGrp->layout()->setSpacing( 0 ); myOriginDimGrp->layout()->setMargin( 0 );
269 QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp->layout() );
270 myOriginDimGrpLayout->setAlignment( Qt::AlignTop );
271 myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
273 myXSpin = new QtxDblSpinBox (0.0, 1.0, 0.1, myOriginDimGrp);
274 myXSpin->setMinimumWidth( MINIMUM_WIDTH );
275 myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
277 myYSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
278 myYSpin->setMinimumWidth( MINIMUM_WIDTH );
279 myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
281 myWidthSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
282 myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
283 myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
285 myHeightSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
286 myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
287 myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
289 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp, "myXLab" ), 0, 0 );
290 myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
291 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp, "myYLab" ), 0, 2 );
292 myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
293 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ), myOriginDimGrp, "myWidthLab" ), 1, 0 );
294 myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
295 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp, "myHeightLab" ), 1, 2 );
296 myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
298 aTopLayout->addWidget( myOriginDimGrp, aRow, 0 );
301 /***************************************************************/
303 myButtonGrp = new QGroupBox( this, "myButtonGrp" );
304 myButtonGrp->setColumnLayout(0, Qt::Vertical );
305 myButtonGrp->layout()->setSpacing( 0 ); myButtonGrp->layout()->setMargin( 0 );
306 QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp->layout() );
307 myButtonGrpLayout->setAlignment( Qt::AlignTop );
308 myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
310 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), myButtonGrp, "myOkBtn" );
311 myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
312 myButtonGrpLayout->addWidget( myOkBtn );
313 if ( mySelectionMgr ) {
314 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp, "myApplyBtn" );
315 myApplyBtn->setAutoDefault( TRUE );
316 myButtonGrpLayout->addWidget( myApplyBtn );
318 myButtonGrpLayout->addStretch();
319 myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), myButtonGrp, "myCancelBtn" );
320 if ( mySelectionMgr )
321 myCancelBtn->setText( tr( "SMESH_BUT_CLOSE" ) );
322 myCancelBtn->setAutoDefault( TRUE );
323 myButtonGrpLayout->addWidget( myCancelBtn );
325 aTopLayout->addWidget( myButtonGrp, aRow, 0 );
327 /***************************************************************/
329 // --> first init from preferences
330 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
332 QColor titleColor (255, 255, 255);
333 if (mgr && mgr->hasValue("SMESH", "scalar_bar_title_color")) {
334 QStringList aTColor =
335 QStringList::split(":", mgr->stringValue("SMESH", "scalar_bar_title_color"), false);
336 titleColor = QColor((aTColor.count() > 0 ? aTColor[0].toInt() : 255),
337 (aTColor.count() > 1 ? aTColor[1].toInt() : 255),
338 (aTColor.count() > 2 ? aTColor[2].toInt() : 255));
340 myTitleColorBtn->setPaletteBackgroundColor(titleColor);
341 myTitleFontCombo->setCurrentItem(0);
342 if (mgr && mgr->hasValue("SMESH", "scalar_bar_title_font")) {
343 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
344 if( f.family()=="Arial" )
345 myTitleFontCombo->setCurrentItem(0);
346 if( f.family()=="Courier" )
347 myTitleFontCombo->setCurrentItem(1);
348 if( f.family()=="Times")
349 myTitleFontCombo->setCurrentItem(2);
351 myTitleBoldCheck->setChecked ( f.bold() );
352 myTitleItalicCheck->setChecked( f.italic() );
353 myTitleShadowCheck->setChecked( f.underline() );
356 QColor labelColor (255, 255, 255);
357 if (mgr && mgr->hasValue("SMESH", "scalar_bar_label_color")) {
358 QStringList aLColor =
359 QStringList::split(":", mgr->stringValue("SMESH", "scalar_bar_label_color"), false);
360 labelColor = QColor((aLColor.count() > 0 ? aLColor[0].toInt() : 255),
361 (aLColor.count() > 1 ? aLColor[1].toInt() : 255),
362 (aLColor.count() > 2 ? aLColor[2].toInt() : 255));
364 myLabelsColorBtn->setPaletteBackgroundColor(labelColor);
365 myLabelsFontCombo->setCurrentItem(0);
366 if (mgr && mgr->hasValue("SMESH", "scalar_bar_label_font")) {
367 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
368 if (f.family() == "Arial")
369 myLabelsFontCombo->setCurrentItem(0);
370 if (f.family() == "Courier")
371 myLabelsFontCombo->setCurrentItem(1);
372 if (f.family() == "Times")
373 myLabelsFontCombo->setCurrentItem(2);
375 myLabelsBoldCheck ->setChecked( f.bold() );
376 myLabelsItalicCheck->setChecked( f.italic() );
377 myLabelsShadowCheck->setChecked( f.underline() );
381 if (mgr && mgr->hasValue("SMESH", "scalar_bar_num_colors"))
382 aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors");
383 myColorsSpin->setValue(aNbColors);
386 if (mgr && mgr->hasValue("SMESH", "scalar_bar_num_labels"))
387 aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels");
388 myLabelsSpin->setValue(aNbLabels);
390 int aOrientation = ( mgr ? mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 ) : 1 );
391 bool isHoriz = ( aOrientation==1 );
392 if (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";
399 if (mgr && mgr->hasValue("SMESH", name.arg( "x" )))
400 myIniX = mgr->doubleValue("SMESH", name.arg( "x" ));
402 myIniX = myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X;
404 if (mgr && mgr->hasValue("SMESH", name.arg( "y" )))
405 myIniY = mgr->doubleValue("SMESH", name.arg( "y" ));
407 myIniY = myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y;
409 if (mgr && mgr->hasValue("SMESH", name.arg( "width" )))
410 myIniW = mgr->doubleValue("SMESH", name.arg( "width" ));
412 myIniW = myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W;
414 if (mgr && mgr->hasValue("SMESH", name.arg( "height" )))
415 myIniH = mgr->doubleValue("SMESH", name.arg( "height" ));
417 myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
419 setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
421 if (mySelectionMgr) {
422 // --> then init from selection if necessary
423 onSelectionChanged();
426 /***************************************************************/
428 connect( myTitleColorBtn, SIGNAL( clicked() ), this, SLOT( onTitleColor() ) );
429 connect( myLabelsColorBtn, SIGNAL( clicked() ), this, SLOT( onLabelsColor() ) );
430 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
431 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
432 connect( myXSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
433 connect( myYSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
434 connect( myOrientationGrp, SIGNAL( clicked( int ) ), this, SLOT( onOrientationChanged() ) );
435 if ( mySelectionMgr ) {
436 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
437 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
439 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
442 //=================================================================================================
444 * SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
448 //=================================================================================================
449 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
453 //=================================================================================================
455 * SMESHGUI_Preferences_ScalarBarDlg::onOk
459 //=================================================================================================
460 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
466 //=================================================================================================
468 * SMESHGUI_Preferences_ScalarBarDlg::onApply
472 //=================================================================================================
473 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
475 if (mySelectionMgr) {
476 // Scalar Bar properties
479 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
481 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
482 QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
483 aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
484 if ( myTitleFontCombo->currentItem() == 0 )
485 aTitleTextPrp->SetFontFamilyToArial();
486 else if ( myTitleFontCombo->currentItem() == 1 )
487 aTitleTextPrp->SetFontFamilyToCourier();
489 aTitleTextPrp->SetFontFamilyToTimes();
490 aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
491 aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
492 aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
493 myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
495 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
496 QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
497 aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
498 if ( myLabelsFontCombo->currentItem() == 0 )
499 aLabelsTextPrp->SetFontFamilyToArial();
500 else if ( myLabelsFontCombo->currentItem() == 1 )
501 aLabelsTextPrp->SetFontFamilyToCourier();
503 aLabelsTextPrp->SetFontFamilyToTimes();
504 aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
505 aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
506 aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
507 myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
509 myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
510 myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
512 if ( myHorizRadioBtn->isChecked() )
513 myScalarBarActor->SetOrientationToHorizontal();
515 myScalarBarActor->SetOrientationToVertical();
517 myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
518 myScalarBarActor->SetWidth( myWidthSpin->value() );
519 myScalarBarActor->SetHeight( myHeightSpin->value() );
521 double aMin = myMinEdit->text().toDouble();
522 double aMax = myMaxEdit->text().toDouble();
523 vtkLookupTable* myLookupTable =
524 static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
525 myLookupTable->SetRange( aMin, aMax );
526 myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
527 myLookupTable->Build();
528 SMESH::RepaintCurrentView();
530 // Scalar Bar preferences
531 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
532 if (!mgr) return false;
534 QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
535 mgr->setValue("SMESH", "scalar_bar_title_color", titleColor );
538 if (myTitleFontCombo->currentItem() == 0)
539 f.setFamily( "Arial" );
540 else if (myTitleFontCombo->currentItem() == 1)
541 f.setFamily( "Courier" );
543 f.setFamily( "Times");
545 f.setBold( myTitleBoldCheck ->isChecked() );
546 f.setItalic( myTitleItalicCheck->isChecked() );
547 f.setUnderline( myTitleShadowCheck->isChecked() );
548 mgr->setValue( "SMESH", "scalar_bar_title_font", f );
550 QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
551 mgr->setValue("SMESH", "scalar_bar_label_color", labelColor );
553 if (myLabelsFontCombo->currentItem() == 0)
554 f.setFamily( "Arial" );
555 else if ( myLabelsFontCombo->currentItem() == 1 )
556 f.setFamily( "Courier");
558 f.setFamily( "Times");
560 f.setBold( myLabelsBoldCheck ->isChecked() );
561 f.setItalic( myLabelsItalicCheck->isChecked() );
562 f.setUnderline( myLabelsShadowCheck->isChecked() );
563 mgr->setValue( "SMESH", "scalar_bar_label_font", f );
565 mgr->setValue("SMESH", "scalar_bar_num_colors", myColorsSpin->value());
566 mgr->setValue("SMESH", "scalar_bar_num_labels", myLabelsSpin->value());
568 mgr->setValue("SMESH", "scalar_bar_orientation", myHorizRadioBtn->isChecked() ? 1 : 0 );
570 QString name = myHorizRadioBtn->isChecked() ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
571 mgr->setValue("SMESH", name.arg( "x" ), myXSpin->value());
572 mgr->setValue("SMESH", name.arg( "y" ), myYSpin->value());
573 mgr->setValue("SMESH", name.arg( "width" ), myWidthSpin->value());
574 mgr->setValue("SMESH", name.arg( "height" ), myHeightSpin->value());
579 //=================================================================================================
581 * SMESHGUI_Preferences_ScalarBarDlg::onCancel
585 //=================================================================================================
586 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
591 //=================================================================================================
593 * SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
595 * Change Title color button slot
597 //=================================================================================================
598 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
600 QColor aColor = myTitleColorBtn->paletteBackgroundColor();
601 aColor = QColorDialog::getColor( aColor, this );
602 if ( aColor.isValid() )
603 myTitleColorBtn->setPaletteBackgroundColor( aColor );
606 //=================================================================================================
608 * SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
610 * Change Labels color button slot
612 //=================================================================================================
613 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
615 QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
616 aColor = QColorDialog::getColor( aColor, this );
617 if ( aColor.isValid() )
618 myLabelsColorBtn->setPaletteBackgroundColor( aColor );
621 //=================================================================================================
623 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
625 * Called when selection changed
627 //=================================================================================================
628 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
630 if (mySelectionMgr) {
632 mySelectionMgr->selectedObjects(aList);
634 if (aList.Extent() == 1) {
635 Handle(SALOME_InteractiveObject) anIO = aList.First();
636 if( anIO->hasEntry() ) {
637 SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
638 if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
640 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
642 if ( myScalarBarActor->GetLookupTable() ) {
643 vtkFloatingPointType *range = myScalarBarActor->GetLookupTable()->GetRange();
644 myMinEdit->setText( QString::number( range[0],'g',12 ) );
645 myMaxEdit->setText( QString::number( range[1],'g',12 ) );
648 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
649 vtkFloatingPointType aTColor[3];
650 aTitleTextPrp->GetColor( aTColor );
651 myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
652 myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
653 myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
654 myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
655 myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
657 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
658 vtkFloatingPointType aLColor[3];
659 aLabelsTextPrp->GetColor( aLColor );
660 myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
661 myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
662 myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
663 myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
664 myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
666 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
667 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
669 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
670 myVertRadioBtn->setChecked( true );
672 myHorizRadioBtn->setChecked( true );
673 myIniOrientation = myVertRadioBtn->isChecked();
675 myIniX = myScalarBarActor->GetPosition()[0];
676 myIniY = myScalarBarActor->GetPosition()[1];
677 myIniW = myScalarBarActor->GetWidth();
678 myIniH = myScalarBarActor->GetHeight();
679 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
681 myRangeGrp->setEnabled( true );
682 myFontGrp->setEnabled( true );
683 myLabColorGrp->setEnabled( true );
684 myOrientationGrp->setEnabled( true );
685 myOriginDimGrp->setEnabled( true );
686 myOkBtn->setEnabled( true );
687 myApplyBtn->setEnabled( true );
693 myRangeGrp->setEnabled( false );
694 myFontGrp->setEnabled( false );
695 myLabColorGrp->setEnabled( false );
696 myOrientationGrp->setEnabled( false );
697 myOriginDimGrp->setEnabled( false );
698 myOkBtn->setEnabled( false );
699 myApplyBtn->setEnabled( false );
703 //=================================================================================================
705 * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
707 * Close event handler
709 //=================================================================================================
710 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
712 if ( mySelectionMgr ) // "Properties" dialog box
714 QDialog::closeEvent( e );
717 //=================================================================================================
719 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
721 * Called when X, Y values are changed
723 //=================================================================================================
724 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
726 myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
727 myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
730 //=================================================================================================
732 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
734 * Called when X, Y values are changed
736 //=================================================================================================
737 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
742 blockSignals( true );
743 myXSpin->setValue( x );
744 myYSpin->setValue( y );
745 myWidthSpin->setMaxValue( 1.0 );
746 myWidthSpin->setValue( w );
747 myHeightSpin->setMaxValue( 1.0 );
748 myHeightSpin->setValue( h );
749 blockSignals( false );
753 //=================================================================================================
755 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
757 * Called when orientation is changed
759 //=================================================================================================
760 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
762 this->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" ));