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 <vtkScalarsToColors.h>
63 #define MINIMUM_WIDTH 70
64 #define MARGIN_SIZE 11
65 #define SPACING_SIZE 6
67 #define DEF_VER_X 0.01
68 #define DEF_VER_Y 0.10
69 #define DEF_VER_H 0.80
70 #define DEF_VER_W 0.10
71 #define DEF_HOR_X 0.20
72 #define DEF_HOR_Y 0.01
73 #define DEF_HOR_H 0.12
74 #define DEF_HOR_W 0.60
78 // Only one instance is allowed
79 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
81 //=================================================================================================
83 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
85 * Gets the only instance of "Scalar Bar Properties" dialog box
87 //=================================================================================================
88 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
91 myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule, true);
95 myDlg->setActiveWindow();
101 //=================================================================================================
103 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
105 * Opens "Scalar Bar Preferences" dialog box
107 //=================================================================================================
108 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( SMESHGUI* theModule )
110 SMESHGUI_Preferences_ScalarBarDlg* aDlg =
111 new SMESHGUI_Preferences_ScalarBarDlg( theModule, false);
115 //=================================================================================================
117 * SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
121 //=================================================================================================
122 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule, bool property, bool modal )
123 : QDialog( SMESH::GetDesktop( theModule ), 0, modal, WStyle_Customize | WStyle_NormalBorder |
124 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
125 mySMESHGUI( theModule ),
126 mySelectionMgr( property ? SMESH::GetSelectionMgr( theModule ) : 0 )
128 setName("SMESHGUI_Preferences_ScalarBarDlg");
129 setCaption( property ? tr("SMESH_PROPERTIES_SCALARBAR") : tr("SMESH_PREFERENCES_SCALARBAR"));
130 setSizeGripEnabled(TRUE);
134 /******************************************************************************/
136 QGridLayout* aTopLayout = new QGridLayout( this );
137 aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
140 /******************************************************************************/
142 if ( mySelectionMgr ) {
143 myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this, "myRangeGrp" );
144 myRangeGrp->setColumnLayout( 0, Qt::Vertical );
145 myRangeGrp->layout()->setSpacing( 0 ); myRangeGrp->layout()->setMargin( 0 );
146 QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp->layout() );
147 myRangeGrpLayout->setAlignment( Qt::AlignTop );
148 myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
150 myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
151 myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
152 myMinEdit->setValidator( new QDoubleValidator( this ) );
154 myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
155 myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
156 myMaxEdit->setValidator( new QDoubleValidator( this ) );
158 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp, "myMinLab" ), 0, 0 );
159 myRangeGrpLayout->addWidget( myMinEdit, 0, 1 );
160 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp, "myMaxLab" ), 0, 2 );
161 myRangeGrpLayout->addWidget( myMaxEdit, 0, 3 );
163 aTopLayout->addWidget( myRangeGrp, aRow, 0 );
167 /******************************************************************************/
169 myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this, "myFontGrp" );
170 myFontGrp->setColumnLayout( 0, Qt::Vertical );
171 myFontGrp->layout()->setSpacing( 0 ); myFontGrp->layout()->setMargin( 0 );
172 QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp->layout() );
173 myFontGrpLayout->setAlignment( Qt::AlignTop );
174 myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
176 myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
177 myTitleColorBtn->setMinimumWidth( 20 );
179 myTitleFontCombo = new QComboBox( false, myFontGrp, "myTitleFontCombo" );
180 myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
181 myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
182 myTitleFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
183 myTitleFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
184 myTitleFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
186 myTitleBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myTitleBoldCheck" );
187 myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myTitleItalicCheck" );
188 myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myTitleShadowCheck" );
190 myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
191 myLabelsColorBtn->setMinimumWidth( 20 );
193 myLabelsFontCombo = new QComboBox( false, myFontGrp, "myLabelsFontCombo" );
194 myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
195 myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
196 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
197 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
198 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
200 myLabelsBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myLabelsBoldCheck" );
201 myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myLabelsItalicCheck" );
202 myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myLabelsShadowCheck" );
204 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp, "myFontTitleLab" ), 0, 0 );
205 myFontGrpLayout->addWidget( myTitleColorBtn, 0, 1 );
206 myFontGrpLayout->addWidget( myTitleFontCombo, 0, 2 );
207 myFontGrpLayout->addWidget( myTitleBoldCheck, 0, 3 );
208 myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
209 myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
211 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp, "myFontLabelsLab" ), 1, 0 );
212 myFontGrpLayout->addWidget( myLabelsColorBtn, 1, 1 );
213 myFontGrpLayout->addWidget( myLabelsFontCombo, 1, 2 );
214 myFontGrpLayout->addWidget( myLabelsBoldCheck, 1, 3 );
215 myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
216 myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
218 aTopLayout->addWidget( myFontGrp, aRow, 0 );
221 /******************************************************************************/
223 myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this, "myLabColorGrp" );
224 myLabColorGrp->setColumnLayout( 0, Qt::Vertical );
225 myLabColorGrp->layout()->setSpacing( 0 ); myLabColorGrp->layout()->setMargin( 0 );
226 QGridLayout* myLabColorGrpLayout = new QGridLayout( myLabColorGrp->layout() );
227 myLabColorGrpLayout->setAlignment( Qt::AlignTop );
228 myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
230 myColorsSpin = new QSpinBox( 2, 256, 1, myLabColorGrp, "myColorsSpin" );
231 myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
232 myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
234 myLabelsSpin = new QSpinBox( 2, 65, 1, myLabColorGrp, "myLabelsSpin" );
235 myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
236 myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
238 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp, "myNbColorLab" ), 0, 0 );
239 myLabColorGrpLayout->addWidget( myColorsSpin, 0, 1 );
240 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp, "myNbLabsLab" ), 0, 2 );
241 myLabColorGrpLayout->addWidget( myLabelsSpin, 0, 3 );
243 aTopLayout->addWidget( myLabColorGrp, aRow, 0 );
246 /******************************************************************************/
248 myOrientationGrp = new QButtonGroup ( tr( "SMESH_ORIENTATION" ), this, "myOrientationGrp" );
249 myOrientationGrp->setColumnLayout( 0, Qt::Vertical );
250 myOrientationGrp->layout()->setSpacing( 0 ); myOrientationGrp->layout()->setMargin( 0 );
251 QGridLayout* myOrientationGrpLayout = new QGridLayout( myOrientationGrp->layout() );
252 myOrientationGrpLayout->setAlignment( Qt::AlignTop );
253 myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
255 myVertRadioBtn = new QRadioButton( tr( "SMESH_VERTICAL" ), myOrientationGrp, "myVertRadioBtn" );
256 myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp, "myHorizRadioBtn" );
257 myVertRadioBtn->setChecked( true );
259 myOrientationGrpLayout->addWidget( myVertRadioBtn, 0, 0 );
260 myOrientationGrpLayout->addWidget( myHorizRadioBtn, 0, 1 );
262 aTopLayout->addWidget( myOrientationGrp, aRow, 0 );
265 /******************************************************************************/
267 myOriginDimGrp = new QGroupBox (tr("SMESH_POSITION_SIZE_SCALARBAR"), this, "myOriginDimGrp");
268 myOriginDimGrp->setColumnLayout(0, Qt::Vertical);
269 myOriginDimGrp->layout()->setSpacing( 0 ); myOriginDimGrp->layout()->setMargin( 0 );
270 QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp->layout() );
271 myOriginDimGrpLayout->setAlignment( Qt::AlignTop );
272 myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
274 myXSpin = new QtxDblSpinBox (0.0, 1.0, 0.1, myOriginDimGrp);
275 myXSpin->setMinimumWidth( MINIMUM_WIDTH );
276 myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
278 myYSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
279 myYSpin->setMinimumWidth( MINIMUM_WIDTH );
280 myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
282 myWidthSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
283 myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
284 myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
286 myHeightSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
287 myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
288 myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
290 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp, "myXLab" ), 0, 0 );
291 myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
292 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp, "myYLab" ), 0, 2 );
293 myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
294 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ), myOriginDimGrp, "myWidthLab" ), 1, 0 );
295 myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
296 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp, "myHeightLab" ), 1, 2 );
297 myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
299 aTopLayout->addWidget( myOriginDimGrp, aRow, 0 );
302 /***************************************************************/
304 myButtonGrp = new QGroupBox( this, "myButtonGrp" );
305 myButtonGrp->setColumnLayout(0, Qt::Vertical );
306 myButtonGrp->layout()->setSpacing( 0 ); myButtonGrp->layout()->setMargin( 0 );
307 QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp->layout() );
308 myButtonGrpLayout->setAlignment( Qt::AlignTop );
309 myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
311 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), myButtonGrp, "myOkBtn" );
312 myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
313 myButtonGrpLayout->addWidget( myOkBtn );
314 if ( mySelectionMgr ) {
315 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp, "myApplyBtn" );
316 myApplyBtn->setAutoDefault( TRUE );
317 myButtonGrpLayout->addWidget( myApplyBtn );
319 myButtonGrpLayout->addStretch();
320 myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), myButtonGrp, "myCancelBtn" );
321 if ( mySelectionMgr )
322 myCancelBtn->setText( tr( "SMESH_BUT_CLOSE" ) );
323 myCancelBtn->setAutoDefault( TRUE );
324 myButtonGrpLayout->addWidget( myCancelBtn );
326 aTopLayout->addWidget( myButtonGrp, aRow, 0 );
328 /***************************************************************/
330 // --> first init from preferences
331 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
333 QColor titleColor (255, 255, 255);
334 if (mgr && mgr->hasValue("SMESH", "scalar_bar_title_color")) {
335 QStringList aTColor =
336 QStringList::split(":", mgr->stringValue("SMESH", "scalar_bar_title_color"), false);
337 titleColor = QColor((aTColor.count() > 0 ? aTColor[0].toInt() : 255),
338 (aTColor.count() > 1 ? aTColor[1].toInt() : 255),
339 (aTColor.count() > 2 ? aTColor[2].toInt() : 255));
341 myTitleColorBtn->setPaletteBackgroundColor(titleColor);
342 myTitleFontCombo->setCurrentItem(0);
343 if (mgr && mgr->hasValue("SMESH", "scalar_bar_title_font")) {
344 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
345 if( f.family()=="Arial" )
346 myTitleFontCombo->setCurrentItem(0);
347 if( f.family()=="Courier" )
348 myTitleFontCombo->setCurrentItem(1);
349 if( f.family()=="Times")
350 myTitleFontCombo->setCurrentItem(2);
352 myTitleBoldCheck->setChecked ( f.bold() );
353 myTitleItalicCheck->setChecked( f.italic() );
354 myTitleShadowCheck->setChecked( f.underline() );
357 QColor labelColor (255, 255, 255);
358 if (mgr && mgr->hasValue("SMESH", "scalar_bar_label_color")) {
359 QStringList aLColor =
360 QStringList::split(":", mgr->stringValue("SMESH", "scalar_bar_label_color"), false);
361 labelColor = QColor((aLColor.count() > 0 ? aLColor[0].toInt() : 255),
362 (aLColor.count() > 1 ? aLColor[1].toInt() : 255),
363 (aLColor.count() > 2 ? aLColor[2].toInt() : 255));
365 myLabelsColorBtn->setPaletteBackgroundColor(labelColor);
366 myLabelsFontCombo->setCurrentItem(0);
367 if (mgr && mgr->hasValue("SMESH", "scalar_bar_label_font")) {
368 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
369 if (f.family() == "Arial")
370 myLabelsFontCombo->setCurrentItem(0);
371 if (f.family() == "Courier")
372 myLabelsFontCombo->setCurrentItem(1);
373 if (f.family() == "Times")
374 myLabelsFontCombo->setCurrentItem(2);
376 myLabelsBoldCheck ->setChecked( f.bold() );
377 myLabelsItalicCheck->setChecked( f.italic() );
378 myLabelsShadowCheck->setChecked( f.underline() );
382 if (mgr && mgr->hasValue("SMESH", "scalar_bar_num_colors"))
383 aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors");
384 myColorsSpin->setValue(aNbColors);
387 if (mgr && mgr->hasValue("SMESH", "scalar_bar_num_labels"))
388 aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels");
389 myLabelsSpin->setValue(aNbLabels);
391 int aOrientation = ( mgr ? mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 ) : 1 );
392 bool isHoriz = ( aOrientation==1 );
393 if (aOrientation == 1)
394 myHorizRadioBtn->setChecked(true);
396 myVertRadioBtn->setChecked(true);
397 myIniOrientation = myVertRadioBtn->isChecked();
399 QString name = isHoriz ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
400 if (mgr && mgr->hasValue("SMESH", name.arg( "x" )))
401 myIniX = mgr->doubleValue("SMESH", name.arg( "x" ));
403 myIniX = myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X;
405 if (mgr && mgr->hasValue("SMESH", name.arg( "y" )))
406 myIniY = mgr->doubleValue("SMESH", name.arg( "y" ));
408 myIniY = myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y;
410 if (mgr && mgr->hasValue("SMESH", name.arg( "width" )))
411 myIniW = mgr->doubleValue("SMESH", name.arg( "width" ));
413 myIniW = myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W;
415 if (mgr && mgr->hasValue("SMESH", name.arg( "height" )))
416 myIniH = mgr->doubleValue("SMESH", name.arg( "height" ));
418 myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
420 setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
422 if (mySelectionMgr) {
423 // --> then init from selection if necessary
424 onSelectionChanged();
427 /***************************************************************/
429 connect( myTitleColorBtn, SIGNAL( clicked() ), this, SLOT( onTitleColor() ) );
430 connect( myLabelsColorBtn, SIGNAL( clicked() ), this, SLOT( onLabelsColor() ) );
431 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
432 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
433 connect( myXSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
434 connect( myYSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
435 connect( myOrientationGrp, SIGNAL( clicked( int ) ), this, SLOT( onOrientationChanged() ) );
436 if ( mySelectionMgr ) {
437 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
438 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
440 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
443 //=================================================================================================
445 * SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
449 //=================================================================================================
450 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
454 //=================================================================================================
456 * SMESHGUI_Preferences_ScalarBarDlg::onOk
460 //=================================================================================================
461 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
467 //=================================================================================================
469 * SMESHGUI_Preferences_ScalarBarDlg::onApply
473 //=================================================================================================
474 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
476 if (mySelectionMgr) {
477 // Scalar Bar properties
480 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
482 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
483 QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
484 aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
485 if ( myTitleFontCombo->currentItem() == 0 )
486 aTitleTextPrp->SetFontFamilyToArial();
487 else if ( myTitleFontCombo->currentItem() == 1 )
488 aTitleTextPrp->SetFontFamilyToCourier();
490 aTitleTextPrp->SetFontFamilyToTimes();
491 aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
492 aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
493 aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
494 myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
496 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
497 QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
498 aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
499 if ( myLabelsFontCombo->currentItem() == 0 )
500 aLabelsTextPrp->SetFontFamilyToArial();
501 else if ( myLabelsFontCombo->currentItem() == 1 )
502 aLabelsTextPrp->SetFontFamilyToCourier();
504 aLabelsTextPrp->SetFontFamilyToTimes();
505 aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
506 aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
507 aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
508 myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
510 myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
511 myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->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() );
522 double aMin = myMinEdit->text().toDouble();
523 double aMax = myMaxEdit->text().toDouble();
524 myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
525 SMESH::RepaintCurrentView();
527 // Scalar Bar preferences
528 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
529 if (!mgr) return false;
531 QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
532 mgr->setValue("SMESH", "scalar_bar_title_color", titleColor );
535 if (myTitleFontCombo->currentItem() == 0)
536 f.setFamily( "Arial" );
537 else if (myTitleFontCombo->currentItem() == 1)
538 f.setFamily( "Courier" );
540 f.setFamily( "Times");
542 f.setBold( myTitleBoldCheck ->isChecked() );
543 f.setItalic( myTitleItalicCheck->isChecked() );
544 f.setUnderline( myTitleShadowCheck->isChecked() );
545 mgr->setValue( "SMESH", "scalar_bar_title_font", f );
547 QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
548 mgr->setValue("SMESH", "scalar_bar_label_color", labelColor );
550 if (myLabelsFontCombo->currentItem() == 0)
551 f.setFamily( "Arial" );
552 else if ( myLabelsFontCombo->currentItem() == 1 )
553 f.setFamily( "Courier");
555 f.setFamily( "Times");
557 f.setBold( myLabelsBoldCheck ->isChecked() );
558 f.setItalic( myLabelsItalicCheck->isChecked() );
559 f.setUnderline( myLabelsShadowCheck->isChecked() );
560 mgr->setValue( "SMESH", "scalar_bar_label_font", f );
562 mgr->setValue("SMESH", "scalar_bar_num_colors", myColorsSpin->value());
563 mgr->setValue("SMESH", "scalar_bar_num_labels", myLabelsSpin->value());
565 mgr->setValue("SMESH", "scalar_bar_orientation", myHorizRadioBtn->isChecked() ? 1 : 0 );
567 QString name = myHorizRadioBtn->isChecked() ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
568 mgr->setValue("SMESH", name.arg( "x" ), myXSpin->value());
569 mgr->setValue("SMESH", name.arg( "y" ), myYSpin->value());
570 mgr->setValue("SMESH", name.arg( "width" ), myWidthSpin->value());
571 mgr->setValue("SMESH", name.arg( "height" ), myHeightSpin->value());
576 //=================================================================================================
578 * SMESHGUI_Preferences_ScalarBarDlg::onCancel
582 //=================================================================================================
583 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
588 //=================================================================================================
590 * SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
592 * Change Title color button slot
594 //=================================================================================================
595 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
597 QColor aColor = myTitleColorBtn->paletteBackgroundColor();
598 aColor = QColorDialog::getColor( aColor, this );
599 if ( aColor.isValid() )
600 myTitleColorBtn->setPaletteBackgroundColor( aColor );
603 //=================================================================================================
605 * SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
607 * Change Labels color button slot
609 //=================================================================================================
610 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
612 QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
613 aColor = QColorDialog::getColor( aColor, this );
614 if ( aColor.isValid() )
615 myLabelsColorBtn->setPaletteBackgroundColor( aColor );
618 //=================================================================================================
620 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
622 * Called when selection changed
624 //=================================================================================================
625 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
627 if (mySelectionMgr) {
629 mySelectionMgr->selectedObjects(aList);
631 if (aList.Extent() == 1) {
632 Handle(SALOME_InteractiveObject) anIO = aList.First();
633 if( anIO->hasEntry() ) {
634 SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
635 if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
637 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
639 if ( myScalarBarActor->GetLookupTable() ) {
640 float *range = myScalarBarActor->GetLookupTable()->GetRange();
641 myMinEdit->setText( QString::number( range[0] ) );
642 myMaxEdit->setText( QString::number( range[1] ) );
645 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
647 aTitleTextPrp->GetColor( aTColor );
648 myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
649 myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
650 myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
651 myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
652 myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
654 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
656 aLabelsTextPrp->GetColor( aLColor );
657 myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
658 myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
659 myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
660 myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
661 myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
663 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
664 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
666 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
667 myVertRadioBtn->setChecked( true );
669 myHorizRadioBtn->setChecked( true );
670 myIniOrientation = myVertRadioBtn->isChecked();
672 myIniX = myScalarBarActor->GetPosition()[0];
673 myIniY = myScalarBarActor->GetPosition()[1];
674 myIniW = myScalarBarActor->GetWidth();
675 myIniH = myScalarBarActor->GetHeight();
676 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
678 myRangeGrp->setEnabled( true );
679 myFontGrp->setEnabled( true );
680 myLabColorGrp->setEnabled( true );
681 myOrientationGrp->setEnabled( true );
682 myOriginDimGrp->setEnabled( true );
683 myOkBtn->setEnabled( true );
684 myApplyBtn->setEnabled( true );
690 myRangeGrp->setEnabled( false );
691 myFontGrp->setEnabled( false );
692 myLabColorGrp->setEnabled( false );
693 myOrientationGrp->setEnabled( false );
694 myOriginDimGrp->setEnabled( false );
695 myOkBtn->setEnabled( false );
696 myApplyBtn->setEnabled( false );
700 //=================================================================================================
702 * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
704 * Close event handler
706 //=================================================================================================
707 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
709 if ( mySelectionMgr ) // "Properties" dialog box
711 QDialog::closeEvent( e );
714 //=================================================================================================
716 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
718 * Called when X, Y values are changed
720 //=================================================================================================
721 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
723 myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
724 myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
727 //=================================================================================================
729 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
731 * Called when X, Y values are changed
733 //=================================================================================================
734 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
739 blockSignals( true );
740 myXSpin->setValue( x );
741 myYSpin->setValue( y );
742 myWidthSpin->setMaxValue( 1.0 );
743 myWidthSpin->setValue( w );
744 myHeightSpin->setMaxValue( 1.0 );
745 myHeightSpin->setValue( h );
746 blockSignals( false );
750 //=================================================================================================
752 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
754 * Called when orientation is changed
756 //=================================================================================================
757 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
759 int aOrientation = myVertRadioBtn->isChecked();
760 if ( aOrientation == myIniOrientation )
761 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
763 setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
764 aOrientation ? DEF_VER_Y : DEF_HOR_Y,
765 aOrientation ? DEF_VER_W : DEF_HOR_W,
766 aOrientation ? DEF_VER_H : DEF_HOR_H );