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 "SalomeApp_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" );
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" );
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_OK" ), 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 myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
523 SMESH::RepaintCurrentView();
525 // Scalar Bar preferences
526 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
527 if (!mgr) return false;
529 QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
530 mgr->setValue("SMESH", "scalar_bar_title_color", titleColor );
533 if (myTitleFontCombo->currentItem() == 0)
534 f.setFamily( "Arial" );
535 else if (myTitleFontCombo->currentItem() == 1)
536 f.setFamily( "Courier" );
538 f.setFamily( "Times");
540 f.setBold( myTitleBoldCheck ->isChecked() );
541 f.setItalic( myTitleItalicCheck->isChecked() );
542 f.setUnderline( myTitleShadowCheck->isChecked() );
543 mgr->setValue( "SMESH", "scalar_bar_title_font", f );
545 QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
546 mgr->setValue("SMESH", "scalar_bar_label_color", labelColor );
548 if (myLabelsFontCombo->currentItem() == 0)
549 f.setFamily( "Arial" );
550 else if ( myLabelsFontCombo->currentItem() == 1 )
551 f.setFamily( "Courier");
553 f.setFamily( "Times");
555 f.setBold( myLabelsBoldCheck ->isChecked() );
556 f.setItalic( myLabelsItalicCheck->isChecked() );
557 f.setUnderline( myLabelsShadowCheck->isChecked() );
558 mgr->setValue( "SMESH", "scalar_bar_label_font", f );
560 mgr->setValue("SMESH", "scalar_bar_num_colors", myColorsSpin->value());
561 mgr->setValue("SMESH", "scalar_bar_num_labels", myLabelsSpin->value());
563 mgr->setValue("SMESH", "scalar_bar_orientation", myHorizRadioBtn->isChecked() ? 1 : 0 );
565 QString name = myHorizRadioBtn->isChecked() ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
566 mgr->setValue("SMESH", name.arg( "x" ), myXSpin->value());
567 mgr->setValue("SMESH", name.arg( "y" ), myYSpin->value());
568 mgr->setValue("SMESH", name.arg( "width" ), myWidthSpin->value());
569 mgr->setValue("SMESH", name.arg( "height" ), myHeightSpin->value());
574 //=================================================================================================
576 * SMESHGUI_Preferences_ScalarBarDlg::onCancel
580 //=================================================================================================
581 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
586 //=================================================================================================
588 * SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
590 * Change Title color button slot
592 //=================================================================================================
593 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
595 QColor aColor = myTitleColorBtn->paletteBackgroundColor();
596 aColor = QColorDialog::getColor( aColor, this );
597 if ( aColor.isValid() )
598 myTitleColorBtn->setPaletteBackgroundColor( aColor );
601 //=================================================================================================
603 * SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
605 * Change Labels color button slot
607 //=================================================================================================
608 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
610 QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
611 aColor = QColorDialog::getColor( aColor, this );
612 if ( aColor.isValid() )
613 myLabelsColorBtn->setPaletteBackgroundColor( aColor );
616 //=================================================================================================
618 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
620 * Called when selection changed
622 //=================================================================================================
623 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
625 if (mySelectionMgr) {
627 mySelectionMgr->selectedObjects(aList);
629 if (aList.Extent() == 1) {
630 Handle(SALOME_InteractiveObject) anIO = aList.First();
631 if( anIO->hasEntry() ) {
632 SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
633 if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
635 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
637 if ( myScalarBarActor->GetLookupTable() ) {
638 float *range = myScalarBarActor->GetLookupTable()->GetRange();
639 myMinEdit->setText( QString::number( range[0] ) );
640 myMaxEdit->setText( QString::number( range[1] ) );
643 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
645 aTitleTextPrp->GetColor( aTColor );
646 myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
647 myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
648 myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
649 myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
650 myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
652 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
654 aLabelsTextPrp->GetColor( aLColor );
655 myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
656 myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
657 myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
658 myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
659 myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
661 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
662 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
664 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
665 myVertRadioBtn->setChecked( true );
667 myHorizRadioBtn->setChecked( true );
668 myIniOrientation = myVertRadioBtn->isChecked();
670 myIniX = myScalarBarActor->GetPosition()[0];
671 myIniY = myScalarBarActor->GetPosition()[1];
672 myIniW = myScalarBarActor->GetWidth();
673 myIniH = myScalarBarActor->GetHeight();
674 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
676 myRangeGrp->setEnabled( true );
677 myFontGrp->setEnabled( true );
678 myLabColorGrp->setEnabled( true );
679 myOrientationGrp->setEnabled( true );
680 myOriginDimGrp->setEnabled( true );
681 myOkBtn->setEnabled( true );
682 myApplyBtn->setEnabled( true );
688 myRangeGrp->setEnabled( false );
689 myFontGrp->setEnabled( false );
690 myLabColorGrp->setEnabled( false );
691 myOrientationGrp->setEnabled( false );
692 myOriginDimGrp->setEnabled( false );
693 myOkBtn->setEnabled( false );
694 myApplyBtn->setEnabled( false );
698 //=================================================================================================
700 * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
702 * Close event handler
704 //=================================================================================================
705 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
707 if ( mySelectionMgr ) // "Properties" dialog box
709 QDialog::closeEvent( e );
712 //=================================================================================================
714 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
716 * Called when X, Y values are changed
718 //=================================================================================================
719 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
721 myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
722 myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
725 //=================================================================================================
727 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
729 * Called when X, Y values are changed
731 //=================================================================================================
732 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
737 blockSignals( true );
738 myXSpin->setValue( x );
739 myYSpin->setValue( y );
740 myWidthSpin->setMaxValue( 1.0 );
741 myWidthSpin->setValue( w );
742 myHeightSpin->setMaxValue( 1.0 );
743 myHeightSpin->setValue( h );
744 blockSignals( false );
748 //=================================================================================================
750 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
752 * Called when orientation is changed
754 //=================================================================================================
755 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
757 int aOrientation = myVertRadioBtn->isChecked();
758 if ( aOrientation == myIniOrientation )
759 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
761 setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
762 aOrientation ? DEF_VER_Y : DEF_HOR_Y,
763 aOrientation ? DEF_VER_W : DEF_HOR_W,
764 aOrientation ? DEF_VER_H : DEF_HOR_H );