1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_Preferences_ScalarBarDlg.cxx
24 // Author : Nicolas REJNERI
28 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_Utils.h"
34 #include "SMESH_Actor.h"
36 #include "SUIT_Desktop.h"
37 #include "SUIT_ResourceMgr.h"
39 #include "LightApp_SelectionMgr.h"
40 #include "SALOME_ListIO.hxx"
42 #include <QtxDblSpinBox.h>
44 #include <qbuttongroup.h>
45 #include <qcheckbox.h>
46 #include <qcombobox.h>
47 #include <qgroupbox.h>
49 #include <qlineedit.h>
50 #include <qpushbutton.h>
51 #include <qtoolbutton.h>
52 #include <qradiobutton.h>
55 #include <qvalidator.h>
56 #include <qcolordialog.h>
58 #include <vtkTextProperty.h>
59 #include <vtkScalarBarActor.h>
60 #include <vtkLookupTable.h>
62 #define MINIMUM_WIDTH 70
63 #define MARGIN_SIZE 11
64 #define SPACING_SIZE 6
68 // Only one instance is allowed
69 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
71 //=================================================================================================
73 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
75 * Gets the only instance of "Scalar Bar Properties" dialog box
77 //=================================================================================================
78 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
81 myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule, true);
85 myDlg->setActiveWindow();
91 //=================================================================================================
93 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
95 * Opens "Scalar Bar Preferences" dialog box
97 //=================================================================================================
98 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( SMESHGUI* theModule )
100 SMESHGUI_Preferences_ScalarBarDlg* aDlg =
101 new SMESHGUI_Preferences_ScalarBarDlg( theModule, false);
105 //=================================================================================================
107 * SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
111 //=================================================================================================
112 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule, bool property, bool modal )
113 : QDialog( SMESH::GetDesktop( theModule ), 0, modal, WStyle_Customize | WStyle_NormalBorder |
114 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
115 mySMESHGUI( theModule ),
116 mySelectionMgr( property ? SMESH::GetSelectionMgr( theModule ) : 0 )
126 setName("SMESHGUI_Preferences_ScalarBarDlg");
127 setCaption( property ? tr("SMESH_PROPERTIES_SCALARBAR") : tr("SMESH_PREFERENCES_SCALARBAR"));
128 setSizeGripEnabled(TRUE);
132 /******************************************************************************/
134 QGridLayout* aTopLayout = new QGridLayout( this );
135 aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
138 /******************************************************************************/
140 if ( mySelectionMgr ) {
141 myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this, "myRangeGrp" );
142 myRangeGrp->setColumnLayout( 0, Qt::Vertical );
143 myRangeGrp->layout()->setSpacing( 0 ); myRangeGrp->layout()->setMargin( 0 );
144 QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp->layout() );
145 myRangeGrpLayout->setAlignment( Qt::AlignTop );
146 myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
148 myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
149 myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
150 myMinEdit->setValidator( new QDoubleValidator( this ) );
152 myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
153 myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
154 myMaxEdit->setValidator( new QDoubleValidator( this ) );
156 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp, "myMinLab" ), 0, 0 );
157 myRangeGrpLayout->addWidget( myMinEdit, 0, 1 );
158 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp, "myMaxLab" ), 0, 2 );
159 myRangeGrpLayout->addWidget( myMaxEdit, 0, 3 );
161 aTopLayout->addWidget( myRangeGrp, aRow, 0 );
165 /******************************************************************************/
167 myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this, "myFontGrp" );
168 myFontGrp->setColumnLayout( 0, Qt::Vertical );
169 myFontGrp->layout()->setSpacing( 0 ); myFontGrp->layout()->setMargin( 0 );
170 QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp->layout() );
171 myFontGrpLayout->setAlignment( Qt::AlignTop );
172 myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
174 myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
175 myTitleColorBtn->setMinimumWidth( 20 );
177 myTitleFontCombo = new QComboBox( false, myFontGrp, "myTitleFontCombo" );
178 myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
179 myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
180 myTitleFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
181 myTitleFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
182 myTitleFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
184 myTitleBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myTitleBoldCheck" );
185 myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myTitleItalicCheck" );
186 myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myTitleShadowCheck" );
188 myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
189 myLabelsColorBtn->setMinimumWidth( 20 );
191 myLabelsFontCombo = new QComboBox( false, myFontGrp, "myLabelsFontCombo" );
192 myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
193 myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
194 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
195 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
196 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
198 myLabelsBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myLabelsBoldCheck" );
199 myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myLabelsItalicCheck" );
200 myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myLabelsShadowCheck" );
202 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp, "myFontTitleLab" ), 0, 0 );
203 myFontGrpLayout->addWidget( myTitleColorBtn, 0, 1 );
204 myFontGrpLayout->addWidget( myTitleFontCombo, 0, 2 );
205 myFontGrpLayout->addWidget( myTitleBoldCheck, 0, 3 );
206 myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
207 myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
209 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp, "myFontLabelsLab" ), 1, 0 );
210 myFontGrpLayout->addWidget( myLabelsColorBtn, 1, 1 );
211 myFontGrpLayout->addWidget( myLabelsFontCombo, 1, 2 );
212 myFontGrpLayout->addWidget( myLabelsBoldCheck, 1, 3 );
213 myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
214 myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
216 aTopLayout->addWidget( myFontGrp, aRow, 0 );
219 /******************************************************************************/
221 myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this, "myLabColorGrp" );
222 myLabColorGrp->setColumnLayout( 0, Qt::Vertical );
223 myLabColorGrp->layout()->setSpacing( 0 ); myLabColorGrp->layout()->setMargin( 0 );
224 QGridLayout* myLabColorGrpLayout = new QGridLayout( myLabColorGrp->layout() );
225 myLabColorGrpLayout->setAlignment( Qt::AlignTop );
226 myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
228 myColorsSpin = new QSpinBox( 2, 256, 1, myLabColorGrp, "myColorsSpin" );
229 myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
230 myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
232 myLabelsSpin = new QSpinBox( 2, 65, 1, myLabColorGrp, "myLabelsSpin" );
233 myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
234 myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
236 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp, "myNbColorLab" ), 0, 0 );
237 myLabColorGrpLayout->addWidget( myColorsSpin, 0, 1 );
238 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp, "myNbLabsLab" ), 0, 2 );
239 myLabColorGrpLayout->addWidget( myLabelsSpin, 0, 3 );
241 aTopLayout->addWidget( myLabColorGrp, aRow, 0 );
244 /******************************************************************************/
246 myOrientationGrp = new QButtonGroup ( tr( "SMESH_ORIENTATION" ), this, "myOrientationGrp" );
247 myOrientationGrp->setColumnLayout( 0, Qt::Vertical );
248 myOrientationGrp->layout()->setSpacing( 0 ); myOrientationGrp->layout()->setMargin( 0 );
249 QGridLayout* myOrientationGrpLayout = new QGridLayout( myOrientationGrp->layout() );
250 myOrientationGrpLayout->setAlignment( Qt::AlignTop );
251 myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
253 myVertRadioBtn = new QRadioButton( tr( "SMESH_VERTICAL" ), myOrientationGrp, "myVertRadioBtn" );
254 myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp, "myHorizRadioBtn" );
255 myVertRadioBtn->setChecked( true );
257 myOrientationGrpLayout->addWidget( myVertRadioBtn, 0, 0 );
258 myOrientationGrpLayout->addWidget( myHorizRadioBtn, 0, 1 );
260 aTopLayout->addWidget( myOrientationGrp, aRow, 0 );
263 /******************************************************************************/
265 myOriginDimGrp = new QGroupBox (tr("SMESH_POSITION_SIZE_SCALARBAR"), this, "myOriginDimGrp");
266 myOriginDimGrp->setColumnLayout(0, Qt::Vertical);
267 myOriginDimGrp->layout()->setSpacing( 0 ); myOriginDimGrp->layout()->setMargin( 0 );
268 QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp->layout() );
269 myOriginDimGrpLayout->setAlignment( Qt::AlignTop );
270 myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
272 myXSpin = new QtxDblSpinBox (0.0, 1.0, 0.1, myOriginDimGrp);
273 myXSpin->setMinimumWidth( MINIMUM_WIDTH );
274 myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
276 myYSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
277 myYSpin->setMinimumWidth( MINIMUM_WIDTH );
278 myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
280 myWidthSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
281 myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
282 myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
284 myHeightSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
285 myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
286 myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
288 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp, "myXLab" ), 0, 0 );
289 myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
290 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp, "myYLab" ), 0, 2 );
291 myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
292 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ), myOriginDimGrp, "myWidthLab" ), 1, 0 );
293 myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
294 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp, "myHeightLab" ), 1, 2 );
295 myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
297 aTopLayout->addWidget( myOriginDimGrp, aRow, 0 );
300 /***************************************************************/
302 myButtonGrp = new QGroupBox( this, "myButtonGrp" );
303 myButtonGrp->setColumnLayout(0, Qt::Vertical );
304 myButtonGrp->layout()->setSpacing( 0 ); myButtonGrp->layout()->setMargin( 0 );
305 QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp->layout() );
306 myButtonGrpLayout->setAlignment( Qt::AlignTop );
307 myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
309 myOkBtn = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), myButtonGrp, "myOkBtn" );
310 myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
311 myButtonGrpLayout->addWidget( myOkBtn );
312 if ( mySelectionMgr ) {
313 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp, "myApplyBtn" );
314 myApplyBtn->setAutoDefault( TRUE );
315 myButtonGrpLayout->addWidget( myApplyBtn );
317 myButtonGrpLayout->addStretch();
318 myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), myButtonGrp, "myCancelBtn" );
319 if ( mySelectionMgr )
320 myCancelBtn->setText( tr( "SMESH_BUT_CLOSE" ) );
321 myCancelBtn->setAutoDefault( TRUE );
322 myButtonGrpLayout->addWidget( myCancelBtn );
324 aTopLayout->addWidget( myButtonGrp, aRow, 0 );
326 /***************************************************************/
328 // --> first init from preferences
329 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
331 QColor titleColor (255, 255, 255);
332 if (mgr && mgr->hasValue("SMESH", "scalar_bar_title_color")) {
333 QStringList aTColor =
334 QStringList::split(":", mgr->stringValue("SMESH", "scalar_bar_title_color"), false);
335 titleColor = QColor((aTColor.count() > 0 ? aTColor[0].toInt() : 255),
336 (aTColor.count() > 1 ? aTColor[1].toInt() : 255),
337 (aTColor.count() > 2 ? aTColor[2].toInt() : 255));
339 myTitleColorBtn->setPaletteBackgroundColor(titleColor);
340 myTitleFontCombo->setCurrentItem(0);
341 if (mgr && mgr->hasValue("SMESH", "scalar_bar_title_font")) {
342 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
343 if( f.family()=="Arial" )
344 myTitleFontCombo->setCurrentItem(0);
345 if( f.family()=="Courier" )
346 myTitleFontCombo->setCurrentItem(1);
347 if( f.family()=="Times")
348 myTitleFontCombo->setCurrentItem(2);
350 myTitleBoldCheck->setChecked ( f.bold() );
351 myTitleItalicCheck->setChecked( f.italic() );
352 myTitleShadowCheck->setChecked( f.underline() );
355 QColor labelColor (255, 255, 255);
356 if (mgr && mgr->hasValue("SMESH", "scalar_bar_label_color")) {
357 QStringList aLColor =
358 QStringList::split(":", mgr->stringValue("SMESH", "scalar_bar_label_color"), false);
359 labelColor = QColor((aLColor.count() > 0 ? aLColor[0].toInt() : 255),
360 (aLColor.count() > 1 ? aLColor[1].toInt() : 255),
361 (aLColor.count() > 2 ? aLColor[2].toInt() : 255));
363 myLabelsColorBtn->setPaletteBackgroundColor(labelColor);
364 myLabelsFontCombo->setCurrentItem(0);
365 if (mgr && mgr->hasValue("SMESH", "scalar_bar_label_font")) {
366 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
367 if (f.family() == "Arial")
368 myLabelsFontCombo->setCurrentItem(0);
369 if (f.family() == "Courier")
370 myLabelsFontCombo->setCurrentItem(1);
371 if (f.family() == "Times")
372 myLabelsFontCombo->setCurrentItem(2);
374 myLabelsBoldCheck ->setChecked( f.bold() );
375 myLabelsItalicCheck->setChecked( f.italic() );
376 myLabelsShadowCheck->setChecked( f.underline() );
380 if (mgr && mgr->hasValue("SMESH", "scalar_bar_num_colors"))
381 aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors");
382 myColorsSpin->setValue(aNbColors);
385 if (mgr && mgr->hasValue("SMESH", "scalar_bar_num_labels"))
386 aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels");
387 myLabelsSpin->setValue(aNbLabels);
389 int aOrientation = ( mgr ? mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 ) : 1 );
390 bool isHoriz = ( aOrientation==1 );
391 if (aOrientation == 1)
392 myHorizRadioBtn->setChecked(true);
394 myVertRadioBtn->setChecked(true);
395 myIniOrientation = myVertRadioBtn->isChecked();
397 QString name = isHoriz ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
398 if (mgr && mgr->hasValue("SMESH", name.arg( "x" )))
399 myIniX = mgr->doubleValue("SMESH", name.arg( "x" ));
401 myIniX = myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X;
403 if (mgr && mgr->hasValue("SMESH", name.arg( "y" )))
404 myIniY = mgr->doubleValue("SMESH", name.arg( "y" ));
406 myIniY = myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y;
408 if (mgr && mgr->hasValue("SMESH", name.arg( "width" )))
409 myIniW = mgr->doubleValue("SMESH", name.arg( "width" ));
411 myIniW = myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W;
413 if (mgr && mgr->hasValue("SMESH", name.arg( "height" )))
414 myIniH = mgr->doubleValue("SMESH", name.arg( "height" ));
416 myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
418 setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
420 if (mySelectionMgr) {
421 // --> then init from selection if necessary
422 onSelectionChanged();
425 /***************************************************************/
427 connect( myTitleColorBtn, SIGNAL( clicked() ), this, SLOT( onTitleColor() ) );
428 connect( myLabelsColorBtn, SIGNAL( clicked() ), this, SLOT( onLabelsColor() ) );
429 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
430 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
431 connect( myXSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
432 connect( myYSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
433 connect( myOrientationGrp, SIGNAL( clicked( int ) ), this, SLOT( onOrientationChanged() ) );
434 if ( mySelectionMgr ) {
435 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
436 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
438 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
441 //=================================================================================================
443 * SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
447 //=================================================================================================
448 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
452 //=================================================================================================
454 * SMESHGUI_Preferences_ScalarBarDlg::onOk
458 //=================================================================================================
459 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
465 //=================================================================================================
467 * SMESHGUI_Preferences_ScalarBarDlg::onApply
471 //=================================================================================================
472 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
474 if (mySelectionMgr) {
475 // Scalar Bar properties
478 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
480 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
481 QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
482 aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
483 if ( myTitleFontCombo->currentItem() == 0 )
484 aTitleTextPrp->SetFontFamilyToArial();
485 else if ( myTitleFontCombo->currentItem() == 1 )
486 aTitleTextPrp->SetFontFamilyToCourier();
488 aTitleTextPrp->SetFontFamilyToTimes();
489 aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
490 aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
491 aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
492 myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
494 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
495 QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
496 aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
497 if ( myLabelsFontCombo->currentItem() == 0 )
498 aLabelsTextPrp->SetFontFamilyToArial();
499 else if ( myLabelsFontCombo->currentItem() == 1 )
500 aLabelsTextPrp->SetFontFamilyToCourier();
502 aLabelsTextPrp->SetFontFamilyToTimes();
503 aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
504 aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
505 aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
506 myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
508 myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
509 myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
511 if ( myHorizRadioBtn->isChecked() )
512 myScalarBarActor->SetOrientationToHorizontal();
514 myScalarBarActor->SetOrientationToVertical();
516 myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
517 myScalarBarActor->SetWidth( myWidthSpin->value() );
518 myScalarBarActor->SetHeight( myHeightSpin->value() );
520 double aMin = myMinEdit->text().toDouble();
521 double aMax = myMaxEdit->text().toDouble();
522 vtkLookupTable* myLookupTable =
523 static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
524 myLookupTable->SetRange( aMin, aMax );
525 myLookupTable->SetNumberOfTableValues(myColorsSpin->value());
526 myLookupTable->Build();
527 SMESH::RepaintCurrentView();
529 // Scalar Bar preferences
530 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
531 if (!mgr) return false;
533 QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
534 mgr->setValue("SMESH", "scalar_bar_title_color", titleColor );
537 if (myTitleFontCombo->currentItem() == 0)
538 f.setFamily( "Arial" );
539 else if (myTitleFontCombo->currentItem() == 1)
540 f.setFamily( "Courier" );
542 f.setFamily( "Times");
544 f.setBold( myTitleBoldCheck ->isChecked() );
545 f.setItalic( myTitleItalicCheck->isChecked() );
546 f.setUnderline( myTitleShadowCheck->isChecked() );
547 mgr->setValue( "SMESH", "scalar_bar_title_font", f );
549 QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
550 mgr->setValue("SMESH", "scalar_bar_label_color", labelColor );
552 if (myLabelsFontCombo->currentItem() == 0)
553 f.setFamily( "Arial" );
554 else if ( myLabelsFontCombo->currentItem() == 1 )
555 f.setFamily( "Courier");
557 f.setFamily( "Times");
559 f.setBold( myLabelsBoldCheck ->isChecked() );
560 f.setItalic( myLabelsItalicCheck->isChecked() );
561 f.setUnderline( myLabelsShadowCheck->isChecked() );
562 mgr->setValue( "SMESH", "scalar_bar_label_font", f );
564 mgr->setValue("SMESH", "scalar_bar_num_colors", myColorsSpin->value());
565 mgr->setValue("SMESH", "scalar_bar_num_labels", myLabelsSpin->value());
567 mgr->setValue("SMESH", "scalar_bar_orientation", myHorizRadioBtn->isChecked() ? 1 : 0 );
569 QString name = myHorizRadioBtn->isChecked() ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
570 mgr->setValue("SMESH", name.arg( "x" ), myXSpin->value());
571 mgr->setValue("SMESH", name.arg( "y" ), myYSpin->value());
572 mgr->setValue("SMESH", name.arg( "width" ), myWidthSpin->value());
573 mgr->setValue("SMESH", name.arg( "height" ), myHeightSpin->value());
578 //=================================================================================================
580 * SMESHGUI_Preferences_ScalarBarDlg::onCancel
584 //=================================================================================================
585 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
590 //=================================================================================================
592 * SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
594 * Change Title color button slot
596 //=================================================================================================
597 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
599 QColor aColor = myTitleColorBtn->paletteBackgroundColor();
600 aColor = QColorDialog::getColor( aColor, this );
601 if ( aColor.isValid() )
602 myTitleColorBtn->setPaletteBackgroundColor( aColor );
605 //=================================================================================================
607 * SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
609 * Change Labels color button slot
611 //=================================================================================================
612 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
614 QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
615 aColor = QColorDialog::getColor( aColor, this );
616 if ( aColor.isValid() )
617 myLabelsColorBtn->setPaletteBackgroundColor( aColor );
620 //=================================================================================================
622 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
624 * Called when selection changed
626 //=================================================================================================
627 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
629 if (mySelectionMgr) {
631 mySelectionMgr->selectedObjects(aList);
633 if (aList.Extent() == 1) {
634 Handle(SALOME_InteractiveObject) anIO = aList.First();
635 if( anIO->hasEntry() ) {
636 SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
637 if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
639 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
641 if ( myScalarBarActor->GetLookupTable() ) {
642 vtkFloatingPointType *range = myScalarBarActor->GetLookupTable()->GetRange();
643 myMinEdit->setText( QString::number( range[0],'g',12 ) );
644 myMaxEdit->setText( QString::number( range[1],'g',12 ) );
647 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
648 vtkFloatingPointType aTColor[3];
649 aTitleTextPrp->GetColor( aTColor );
650 myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
651 myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
652 myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
653 myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
654 myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
656 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
657 vtkFloatingPointType aLColor[3];
658 aLabelsTextPrp->GetColor( aLColor );
659 myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
660 myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
661 myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
662 myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
663 myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
665 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
666 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
668 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
669 myVertRadioBtn->setChecked( true );
671 myHorizRadioBtn->setChecked( true );
672 myIniOrientation = myVertRadioBtn->isChecked();
674 myIniX = myScalarBarActor->GetPosition()[0];
675 myIniY = myScalarBarActor->GetPosition()[1];
676 myIniW = myScalarBarActor->GetWidth();
677 myIniH = myScalarBarActor->GetHeight();
678 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
680 myRangeGrp->setEnabled( true );
681 myFontGrp->setEnabled( true );
682 myLabColorGrp->setEnabled( true );
683 myOrientationGrp->setEnabled( true );
684 myOriginDimGrp->setEnabled( true );
685 myOkBtn->setEnabled( true );
686 myApplyBtn->setEnabled( true );
692 myRangeGrp->setEnabled( false );
693 myFontGrp->setEnabled( false );
694 myLabColorGrp->setEnabled( false );
695 myOrientationGrp->setEnabled( false );
696 myOriginDimGrp->setEnabled( false );
697 myOkBtn->setEnabled( false );
698 myApplyBtn->setEnabled( false );
702 //=================================================================================================
704 * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
706 * Close event handler
708 //=================================================================================================
709 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
711 if ( mySelectionMgr ) // "Properties" dialog box
713 QDialog::closeEvent( e );
716 //=================================================================================================
718 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
720 * Called when X, Y values are changed
722 //=================================================================================================
723 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
725 myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
726 myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
729 //=================================================================================================
731 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
733 * Called when X, Y values are changed
735 //=================================================================================================
736 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
741 blockSignals( true );
742 myXSpin->setValue( x );
743 myYSpin->setValue( y );
744 myWidthSpin->setMaxValue( 1.0 );
745 myWidthSpin->setValue( w );
746 myHeightSpin->setMaxValue( 1.0 );
747 myHeightSpin->setValue( h );
748 blockSignals( false );
752 //=================================================================================================
754 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
756 * Called when orientation is changed
758 //=================================================================================================
759 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
761 this->initScalarBarFromResources();
763 int aOrientation = myVertRadioBtn->isChecked();
764 if ( aOrientation == myIniOrientation )
765 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
767 setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
768 aOrientation ? DEF_VER_Y : DEF_HOR_Y,
769 aOrientation ? DEF_VER_W : DEF_HOR_W,
770 aOrientation ? DEF_VER_H : DEF_HOR_H );
773 //=================================================================================================
775 * SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
777 * Rereading vertical and horizontal default positions from resources.
779 //=================================================================================================
780 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
782 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
785 // initialize from resoources
788 name = QString("scalar_bar_horizontal_%1");
789 if (mgr->hasValue("SMESH", name.arg( "x" )))
790 DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
791 if (mgr->hasValue("SMESH", name.arg( "y" )))
792 DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
793 if (mgr->hasValue("SMESH", name.arg( "width" )))
794 DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
795 if (mgr->hasValue("SMESH", name.arg( "height" )))
796 DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
799 name = QString("scalar_bar_vertical_%1");
800 if (mgr->hasValue("SMESH", name.arg( "x" )))
801 DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
802 if (mgr->hasValue("SMESH", name.arg( "y" )))
803 DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
804 if (mgr->hasValue("SMESH", name.arg( "width" )))
805 DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
806 if (mgr->hasValue("SMESH", name.arg( "height" )))
807 DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));