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
69 // Only one instance is allowed
70 SMESHGUI_Preferences_ScalarBarDlg* SMESHGUI_Preferences_ScalarBarDlg::myDlg = 0;
72 //=================================================================================================
74 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties
76 * Gets the only instance of "Scalar Bar Properties" dialog box
78 //=================================================================================================
79 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( SMESHGUI* theModule )
82 myDlg = new SMESHGUI_Preferences_ScalarBarDlg( theModule, true);
86 myDlg->setActiveWindow();
92 //=================================================================================================
94 * SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences
96 * Opens "Scalar Bar Preferences" dialog box
98 //=================================================================================================
99 void SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( SMESHGUI* theModule )
101 SMESHGUI_Preferences_ScalarBarDlg* aDlg =
102 new SMESHGUI_Preferences_ScalarBarDlg( theModule, false);
106 //=================================================================================================
108 * SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg
112 //=================================================================================================
113 SMESHGUI_Preferences_ScalarBarDlg::SMESHGUI_Preferences_ScalarBarDlg( SMESHGUI* theModule, bool property, bool modal )
114 : QDialog( SMESH::GetDesktop( theModule ), 0, modal, WStyle_Customize | WStyle_NormalBorder |
115 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
116 mySMESHGUI( theModule ),
117 mySelectionMgr( property ? SMESH::GetSelectionMgr( theModule ) : 0 )
127 setName("SMESHGUI_Preferences_ScalarBarDlg");
128 setCaption( property ? tr("SMESH_PROPERTIES_SCALARBAR") : tr("SMESH_PREFERENCES_SCALARBAR"));
129 setSizeGripEnabled(TRUE);
133 /******************************************************************************/
135 QGridLayout* aTopLayout = new QGridLayout( this );
136 aTopLayout->setSpacing( SPACING_SIZE ); aTopLayout->setMargin( MARGIN_SIZE );
139 /******************************************************************************/
141 if ( mySelectionMgr ) {
142 myRangeGrp = new QGroupBox ( tr( "SMESH_RANGE_SCALARBAR" ), this, "myRangeGrp" );
143 myRangeGrp->setColumnLayout( 0, Qt::Vertical );
144 myRangeGrp->layout()->setSpacing( 0 ); myRangeGrp->layout()->setMargin( 0 );
145 QGridLayout* myRangeGrpLayout = new QGridLayout( myRangeGrp->layout() );
146 myRangeGrpLayout->setAlignment( Qt::AlignTop );
147 myRangeGrpLayout->setSpacing( SPACING_SIZE ); myRangeGrpLayout->setMargin( MARGIN_SIZE );
149 myMinEdit = new QLineEdit( myRangeGrp, "myMinEdit" );
150 myMinEdit->setMinimumWidth( MINIMUM_WIDTH );
151 myMinEdit->setValidator( new QDoubleValidator( this ) );
153 myMaxEdit = new QLineEdit( myRangeGrp, "myMaxEdit" );
154 myMaxEdit->setMinimumWidth( MINIMUM_WIDTH );
155 myMaxEdit->setValidator( new QDoubleValidator( this ) );
157 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MIN" ), myRangeGrp, "myMinLab" ), 0, 0 );
158 myRangeGrpLayout->addWidget( myMinEdit, 0, 1 );
159 myRangeGrpLayout->addWidget( new QLabel( tr( "SMESH_RANGE_MAX" ), myRangeGrp, "myMaxLab" ), 0, 2 );
160 myRangeGrpLayout->addWidget( myMaxEdit, 0, 3 );
162 aTopLayout->addWidget( myRangeGrp, aRow, 0 );
166 /******************************************************************************/
168 myFontGrp = new QGroupBox ( tr( "SMESH_FONT_SCALARBAR" ), this, "myFontGrp" );
169 myFontGrp->setColumnLayout( 0, Qt::Vertical );
170 myFontGrp->layout()->setSpacing( 0 ); myFontGrp->layout()->setMargin( 0 );
171 QGridLayout* myFontGrpLayout = new QGridLayout( myFontGrp->layout() );
172 myFontGrpLayout->setAlignment( Qt::AlignTop );
173 myFontGrpLayout->setSpacing( SPACING_SIZE ); myFontGrpLayout->setMargin( MARGIN_SIZE );
175 myTitleColorBtn = new QToolButton( myFontGrp, "myTitleColorBtn" );
176 myTitleColorBtn->setMinimumWidth( 20 );
178 myTitleFontCombo = new QComboBox( false, myFontGrp, "myTitleFontCombo" );
179 myTitleFontCombo->setMinimumWidth( MINIMUM_WIDTH );
180 myTitleFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
181 myTitleFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
182 myTitleFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
183 myTitleFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
185 myTitleBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myTitleBoldCheck" );
186 myTitleItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myTitleItalicCheck" );
187 myTitleShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myTitleShadowCheck" );
189 myLabelsColorBtn = new QToolButton( myFontGrp, "myLabelsColorBtn" );
190 myLabelsColorBtn->setMinimumWidth( 20 );
192 myLabelsFontCombo = new QComboBox( false, myFontGrp, "myLabelsFontCombo" );
193 myLabelsFontCombo->setMinimumWidth( MINIMUM_WIDTH );
194 myLabelsFontCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
195 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_ARIAL" ) );
196 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_COURIER" ) );
197 myLabelsFontCombo->insertItem( tr( "SMESH_FONT_TIMES" ) );
199 myLabelsBoldCheck = new QCheckBox( tr( "SMESH_FONT_BOLD" ), myFontGrp, "myLabelsBoldCheck" );
200 myLabelsItalicCheck = new QCheckBox( tr( "SMESH_FONT_ITALIC" ), myFontGrp, "myLabelsItalicCheck" );
201 myLabelsShadowCheck = new QCheckBox( tr( "SMESH_FONT_SHADOW" ), myFontGrp, "myLabelsShadowCheck" );
203 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_TITLE" ), myFontGrp, "myFontTitleLab" ), 0, 0 );
204 myFontGrpLayout->addWidget( myTitleColorBtn, 0, 1 );
205 myFontGrpLayout->addWidget( myTitleFontCombo, 0, 2 );
206 myFontGrpLayout->addWidget( myTitleBoldCheck, 0, 3 );
207 myFontGrpLayout->addWidget( myTitleItalicCheck, 0, 4 );
208 myFontGrpLayout->addWidget( myTitleShadowCheck, 0, 5 );
210 myFontGrpLayout->addWidget( new QLabel( tr( "SMESH_LABELS" ), myFontGrp, "myFontLabelsLab" ), 1, 0 );
211 myFontGrpLayout->addWidget( myLabelsColorBtn, 1, 1 );
212 myFontGrpLayout->addWidget( myLabelsFontCombo, 1, 2 );
213 myFontGrpLayout->addWidget( myLabelsBoldCheck, 1, 3 );
214 myFontGrpLayout->addWidget( myLabelsItalicCheck, 1, 4 );
215 myFontGrpLayout->addWidget( myLabelsShadowCheck, 1, 5 );
217 aTopLayout->addWidget( myFontGrp, aRow, 0 );
220 /******************************************************************************/
222 myLabColorGrp = new QGroupBox ( tr( "SMESH_LABELS_COLORS_SCALARBAR" ), this, "myLabColorGrp" );
223 myLabColorGrp->setColumnLayout( 0, Qt::Vertical );
224 myLabColorGrp->layout()->setSpacing( 0 ); myLabColorGrp->layout()->setMargin( 0 );
225 QGridLayout* myLabColorGrpLayout = new QGridLayout( myLabColorGrp->layout() );
226 myLabColorGrpLayout->setAlignment( Qt::AlignTop );
227 myLabColorGrpLayout->setSpacing( SPACING_SIZE ); myLabColorGrpLayout->setMargin( MARGIN_SIZE );
229 myColorsSpin = new QSpinBox( 2, 256, 1, myLabColorGrp, "myColorsSpin" );
230 myColorsSpin->setMinimumWidth( MINIMUM_WIDTH );
231 myColorsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
233 myLabelsSpin = new QSpinBox( 2, 65, 1, myLabColorGrp, "myLabelsSpin" );
234 myLabelsSpin->setMinimumWidth( MINIMUM_WIDTH );
235 myLabelsSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
237 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFCOLORS" ), myLabColorGrp, "myNbColorLab" ), 0, 0 );
238 myLabColorGrpLayout->addWidget( myColorsSpin, 0, 1 );
239 myLabColorGrpLayout->addWidget( new QLabel( tr( "SMESH_NUMBEROFLABELS" ), myLabColorGrp, "myNbLabsLab" ), 0, 2 );
240 myLabColorGrpLayout->addWidget( myLabelsSpin, 0, 3 );
242 aTopLayout->addWidget( myLabColorGrp, aRow, 0 );
245 /******************************************************************************/
247 myOrientationGrp = new QButtonGroup ( tr( "SMESH_ORIENTATION" ), this, "myOrientationGrp" );
248 myOrientationGrp->setColumnLayout( 0, Qt::Vertical );
249 myOrientationGrp->layout()->setSpacing( 0 ); myOrientationGrp->layout()->setMargin( 0 );
250 QGridLayout* myOrientationGrpLayout = new QGridLayout( myOrientationGrp->layout() );
251 myOrientationGrpLayout->setAlignment( Qt::AlignTop );
252 myOrientationGrpLayout->setSpacing( SPACING_SIZE ); myOrientationGrpLayout->setMargin( MARGIN_SIZE );
254 myVertRadioBtn = new QRadioButton( tr( "SMESH_VERTICAL" ), myOrientationGrp, "myVertRadioBtn" );
255 myHorizRadioBtn = new QRadioButton( tr( "SMESH_HORIZONTAL" ), myOrientationGrp, "myHorizRadioBtn" );
256 myVertRadioBtn->setChecked( true );
258 myOrientationGrpLayout->addWidget( myVertRadioBtn, 0, 0 );
259 myOrientationGrpLayout->addWidget( myHorizRadioBtn, 0, 1 );
261 aTopLayout->addWidget( myOrientationGrp, aRow, 0 );
264 /******************************************************************************/
266 myOriginDimGrp = new QGroupBox (tr("SMESH_POSITION_SIZE_SCALARBAR"), this, "myOriginDimGrp");
267 myOriginDimGrp->setColumnLayout(0, Qt::Vertical);
268 myOriginDimGrp->layout()->setSpacing( 0 ); myOriginDimGrp->layout()->setMargin( 0 );
269 QGridLayout* myOriginDimGrpLayout = new QGridLayout( myOriginDimGrp->layout() );
270 myOriginDimGrpLayout->setAlignment( Qt::AlignTop );
271 myOriginDimGrpLayout->setSpacing( SPACING_SIZE ); myOriginDimGrpLayout->setMargin( MARGIN_SIZE );
273 myXSpin = new QtxDblSpinBox (0.0, 1.0, 0.1, myOriginDimGrp);
274 myXSpin->setMinimumWidth( MINIMUM_WIDTH );
275 myXSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
277 myYSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
278 myYSpin->setMinimumWidth( MINIMUM_WIDTH );
279 myYSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
281 myWidthSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
282 myWidthSpin->setMinimumWidth( MINIMUM_WIDTH );
283 myWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
285 myHeightSpin = new QtxDblSpinBox(0.0, 1.0, 0.1, myOriginDimGrp);
286 myHeightSpin->setMinimumWidth( MINIMUM_WIDTH );
287 myHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
289 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_X_SCALARBAR" ), myOriginDimGrp, "myXLab" ), 0, 0 );
290 myOriginDimGrpLayout->addWidget( myXSpin, 0, 1 );
291 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_Y_SCALARBAR" ), myOriginDimGrp, "myYLab" ), 0, 2 );
292 myOriginDimGrpLayout->addWidget( myYSpin, 0, 3 );
293 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_WIDTH" ), myOriginDimGrp, "myWidthLab" ), 1, 0 );
294 myOriginDimGrpLayout->addWidget( myWidthSpin, 1, 1 );
295 myOriginDimGrpLayout->addWidget( new QLabel( tr( "SMESH_HEIGHT" ), myOriginDimGrp, "myHeightLab" ), 1, 2 );
296 myOriginDimGrpLayout->addWidget( myHeightSpin, 1, 3 );
298 aTopLayout->addWidget( myOriginDimGrp, aRow, 0 );
301 /***************************************************************/
303 myButtonGrp = new QGroupBox( this, "myButtonGrp" );
304 myButtonGrp->setColumnLayout(0, Qt::Vertical );
305 myButtonGrp->layout()->setSpacing( 0 ); myButtonGrp->layout()->setMargin( 0 );
306 QHBoxLayout* myButtonGrpLayout = new QHBoxLayout( myButtonGrp->layout() );
307 myButtonGrpLayout->setAlignment( Qt::AlignTop );
308 myButtonGrpLayout->setSpacing( SPACING_SIZE ); myButtonGrpLayout->setMargin( MARGIN_SIZE );
310 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), myButtonGrp, "myOkBtn" );
311 myOkBtn->setAutoDefault( TRUE ); myOkBtn->setDefault( TRUE );
312 myButtonGrpLayout->addWidget( myOkBtn );
313 if ( mySelectionMgr ) {
314 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), myButtonGrp, "myApplyBtn" );
315 myApplyBtn->setAutoDefault( TRUE );
316 myButtonGrpLayout->addWidget( myApplyBtn );
318 myButtonGrpLayout->addStretch();
319 myCancelBtn = new QPushButton( tr( "SMESH_BUT_CANCEL" ), myButtonGrp, "myCancelBtn" );
320 if ( mySelectionMgr )
321 myCancelBtn->setText( tr( "SMESH_BUT_CLOSE" ) );
322 myCancelBtn->setAutoDefault( TRUE );
323 myButtonGrpLayout->addWidget( myCancelBtn );
325 aTopLayout->addWidget( myButtonGrp, aRow, 0 );
327 /***************************************************************/
329 // --> first init from preferences
330 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
332 QColor titleColor (255, 255, 255);
333 if (mgr && mgr->hasValue("SMESH", "scalar_bar_title_color")) {
334 QStringList aTColor =
335 QStringList::split(":", mgr->stringValue("SMESH", "scalar_bar_title_color"), false);
336 titleColor = QColor((aTColor.count() > 0 ? aTColor[0].toInt() : 255),
337 (aTColor.count() > 1 ? aTColor[1].toInt() : 255),
338 (aTColor.count() > 2 ? aTColor[2].toInt() : 255));
340 myTitleColorBtn->setPaletteBackgroundColor(titleColor);
341 myTitleFontCombo->setCurrentItem(0);
342 if (mgr && mgr->hasValue("SMESH", "scalar_bar_title_font")) {
343 QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
344 if( f.family()=="Arial" )
345 myTitleFontCombo->setCurrentItem(0);
346 if( f.family()=="Courier" )
347 myTitleFontCombo->setCurrentItem(1);
348 if( f.family()=="Times")
349 myTitleFontCombo->setCurrentItem(2);
351 myTitleBoldCheck->setChecked ( f.bold() );
352 myTitleItalicCheck->setChecked( f.italic() );
353 myTitleShadowCheck->setChecked( f.underline() );
356 QColor labelColor (255, 255, 255);
357 if (mgr && mgr->hasValue("SMESH", "scalar_bar_label_color")) {
358 QStringList aLColor =
359 QStringList::split(":", mgr->stringValue("SMESH", "scalar_bar_label_color"), false);
360 labelColor = QColor((aLColor.count() > 0 ? aLColor[0].toInt() : 255),
361 (aLColor.count() > 1 ? aLColor[1].toInt() : 255),
362 (aLColor.count() > 2 ? aLColor[2].toInt() : 255));
364 myLabelsColorBtn->setPaletteBackgroundColor(labelColor);
365 myLabelsFontCombo->setCurrentItem(0);
366 if (mgr && mgr->hasValue("SMESH", "scalar_bar_label_font")) {
367 QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
368 if (f.family() == "Arial")
369 myLabelsFontCombo->setCurrentItem(0);
370 if (f.family() == "Courier")
371 myLabelsFontCombo->setCurrentItem(1);
372 if (f.family() == "Times")
373 myLabelsFontCombo->setCurrentItem(2);
375 myLabelsBoldCheck ->setChecked( f.bold() );
376 myLabelsItalicCheck->setChecked( f.italic() );
377 myLabelsShadowCheck->setChecked( f.underline() );
381 if (mgr && mgr->hasValue("SMESH", "scalar_bar_num_colors"))
382 aNbColors = mgr->integerValue("SMESH", "scalar_bar_num_colors");
383 myColorsSpin->setValue(aNbColors);
386 if (mgr && mgr->hasValue("SMESH", "scalar_bar_num_labels"))
387 aNbLabels = mgr->integerValue("SMESH", "scalar_bar_num_labels");
388 myLabelsSpin->setValue(aNbLabels);
390 int aOrientation = ( mgr ? mgr->integerValue( "SMESH", "scalar_bar_orientation", 1 ) : 1 );
391 bool isHoriz = ( aOrientation==1 );
392 if (aOrientation == 1)
393 myHorizRadioBtn->setChecked(true);
395 myVertRadioBtn->setChecked(true);
396 myIniOrientation = myVertRadioBtn->isChecked();
398 QString name = isHoriz ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
399 if (mgr && mgr->hasValue("SMESH", name.arg( "x" )))
400 myIniX = mgr->doubleValue("SMESH", name.arg( "x" ));
402 myIniX = myHorizRadioBtn->isChecked() ? DEF_HOR_X : DEF_VER_X;
404 if (mgr && mgr->hasValue("SMESH", name.arg( "y" )))
405 myIniY = mgr->doubleValue("SMESH", name.arg( "y" ));
407 myIniY = myHorizRadioBtn->isChecked() ? DEF_HOR_Y : DEF_VER_Y;
409 if (mgr && mgr->hasValue("SMESH", name.arg( "width" )))
410 myIniW = mgr->doubleValue("SMESH", name.arg( "width" ));
412 myIniW = myHorizRadioBtn->isChecked() ? DEF_HOR_W : DEF_VER_W;
414 if (mgr && mgr->hasValue("SMESH", name.arg( "height" )))
415 myIniH = mgr->doubleValue("SMESH", name.arg( "height" ));
417 myIniH = myHorizRadioBtn->isChecked() ? DEF_HOR_H : DEF_VER_H;
419 setOriginAndSize(myIniX, myIniY, myIniW, myIniH);
421 if (mySelectionMgr) {
422 // --> then init from selection if necessary
423 onSelectionChanged();
426 /***************************************************************/
428 connect( myTitleColorBtn, SIGNAL( clicked() ), this, SLOT( onTitleColor() ) );
429 connect( myLabelsColorBtn, SIGNAL( clicked() ), this, SLOT( onLabelsColor() ) );
430 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( onOk() ) );
431 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
432 connect( myXSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
433 connect( myYSpin, SIGNAL( valueChanged( double ) ), this, SLOT( onXYChanged() ) );
434 connect( myOrientationGrp, SIGNAL( clicked( int ) ), this, SLOT( onOrientationChanged() ) );
435 if ( mySelectionMgr ) {
436 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
437 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
439 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onCancel() ) ) ;
442 //=================================================================================================
444 * SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg
448 //=================================================================================================
449 SMESHGUI_Preferences_ScalarBarDlg::~SMESHGUI_Preferences_ScalarBarDlg()
453 //=================================================================================================
455 * SMESHGUI_Preferences_ScalarBarDlg::onOk
459 //=================================================================================================
460 void SMESHGUI_Preferences_ScalarBarDlg::onOk()
466 //=================================================================================================
468 * SMESHGUI_Preferences_ScalarBarDlg::onApply
472 //=================================================================================================
473 bool SMESHGUI_Preferences_ScalarBarDlg::onApply()
475 if (mySelectionMgr) {
476 // Scalar Bar properties
479 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
481 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
482 QColor aTColor = myTitleColorBtn->paletteBackgroundColor();
483 aTitleTextPrp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
484 if ( myTitleFontCombo->currentItem() == 0 )
485 aTitleTextPrp->SetFontFamilyToArial();
486 else if ( myTitleFontCombo->currentItem() == 1 )
487 aTitleTextPrp->SetFontFamilyToCourier();
489 aTitleTextPrp->SetFontFamilyToTimes();
490 aTitleTextPrp->SetBold( myTitleBoldCheck->isChecked() );
491 aTitleTextPrp->SetItalic( myTitleItalicCheck->isChecked() );
492 aTitleTextPrp->SetShadow( myTitleShadowCheck->isChecked() );
493 myScalarBarActor->SetTitleTextProperty( aTitleTextPrp );
495 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
496 QColor aLColor = myLabelsColorBtn->paletteBackgroundColor();
497 aLabelsTextPrp->SetColor( aLColor.red()/255., aLColor.green()/255., aLColor.blue()/255. );
498 if ( myLabelsFontCombo->currentItem() == 0 )
499 aLabelsTextPrp->SetFontFamilyToArial();
500 else if ( myLabelsFontCombo->currentItem() == 1 )
501 aLabelsTextPrp->SetFontFamilyToCourier();
503 aLabelsTextPrp->SetFontFamilyToTimes();
504 aLabelsTextPrp->SetBold( myLabelsBoldCheck->isChecked() );
505 aLabelsTextPrp->SetItalic( myLabelsItalicCheck->isChecked() );
506 aLabelsTextPrp->SetShadow( myLabelsShadowCheck->isChecked() );
507 myScalarBarActor->SetLabelTextProperty( aLabelsTextPrp );
509 myScalarBarActor->SetNumberOfLabels( myLabelsSpin->value() );
510 myScalarBarActor->SetMaximumNumberOfColors( myColorsSpin->value() );
512 if ( myHorizRadioBtn->isChecked() )
513 myScalarBarActor->SetOrientationToHorizontal();
515 myScalarBarActor->SetOrientationToVertical();
517 myScalarBarActor->SetPosition( myXSpin->value(), myYSpin->value() );
518 myScalarBarActor->SetWidth( myWidthSpin->value() );
519 myScalarBarActor->SetHeight( myHeightSpin->value() );
521 double aMin = myMinEdit->text().toDouble();
522 double aMax = myMaxEdit->text().toDouble();
523 myScalarBarActor->GetLookupTable()->SetRange( aMin, aMax );
524 SMESH::RepaintCurrentView();
526 // Scalar Bar preferences
527 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
528 if (!mgr) return false;
530 QColor titleColor = myTitleColorBtn->paletteBackgroundColor();
531 mgr->setValue("SMESH", "scalar_bar_title_color", titleColor );
534 if (myTitleFontCombo->currentItem() == 0)
535 f.setFamily( "Arial" );
536 else if (myTitleFontCombo->currentItem() == 1)
537 f.setFamily( "Courier" );
539 f.setFamily( "Times");
541 f.setBold( myTitleBoldCheck ->isChecked() );
542 f.setItalic( myTitleItalicCheck->isChecked() );
543 f.setUnderline( myTitleShadowCheck->isChecked() );
544 mgr->setValue( "SMESH", "scalar_bar_title_font", f );
546 QColor labelColor = myLabelsColorBtn->paletteBackgroundColor();
547 mgr->setValue("SMESH", "scalar_bar_label_color", labelColor );
549 if (myLabelsFontCombo->currentItem() == 0)
550 f.setFamily( "Arial" );
551 else if ( myLabelsFontCombo->currentItem() == 1 )
552 f.setFamily( "Courier");
554 f.setFamily( "Times");
556 f.setBold( myLabelsBoldCheck ->isChecked() );
557 f.setItalic( myLabelsItalicCheck->isChecked() );
558 f.setUnderline( myLabelsShadowCheck->isChecked() );
559 mgr->setValue( "SMESH", "scalar_bar_label_font", f );
561 mgr->setValue("SMESH", "scalar_bar_num_colors", myColorsSpin->value());
562 mgr->setValue("SMESH", "scalar_bar_num_labels", myLabelsSpin->value());
564 mgr->setValue("SMESH", "scalar_bar_orientation", myHorizRadioBtn->isChecked() ? 1 : 0 );
566 QString name = myHorizRadioBtn->isChecked() ? "scalar_bar_horizontal_%1" : "scalar_bar_vertical_%1";
567 mgr->setValue("SMESH", name.arg( "x" ), myXSpin->value());
568 mgr->setValue("SMESH", name.arg( "y" ), myYSpin->value());
569 mgr->setValue("SMESH", name.arg( "width" ), myWidthSpin->value());
570 mgr->setValue("SMESH", name.arg( "height" ), myHeightSpin->value());
575 //=================================================================================================
577 * SMESHGUI_Preferences_ScalarBarDlg::onCancel
581 //=================================================================================================
582 void SMESHGUI_Preferences_ScalarBarDlg::onCancel()
587 //=================================================================================================
589 * SMESHGUI_Preferences_ScalarBarDlg::onTitleColor
591 * Change Title color button slot
593 //=================================================================================================
594 void SMESHGUI_Preferences_ScalarBarDlg::onTitleColor()
596 QColor aColor = myTitleColorBtn->paletteBackgroundColor();
597 aColor = QColorDialog::getColor( aColor, this );
598 if ( aColor.isValid() )
599 myTitleColorBtn->setPaletteBackgroundColor( aColor );
602 //=================================================================================================
604 * SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor
606 * Change Labels color button slot
608 //=================================================================================================
609 void SMESHGUI_Preferences_ScalarBarDlg::onLabelsColor()
611 QColor aColor = myLabelsColorBtn->paletteBackgroundColor();
612 aColor = QColorDialog::getColor( aColor, this );
613 if ( aColor.isValid() )
614 myLabelsColorBtn->setPaletteBackgroundColor( aColor );
617 //=================================================================================================
619 * SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged
621 * Called when selection changed
623 //=================================================================================================
624 void SMESHGUI_Preferences_ScalarBarDlg::onSelectionChanged()
626 if (mySelectionMgr) {
628 mySelectionMgr->selectedObjects(aList);
630 if (aList.Extent() == 1) {
631 Handle(SALOME_InteractiveObject) anIO = aList.First();
632 if( anIO->hasEntry() ) {
633 SMESH_Actor* anActor = SMESH::FindActorByEntry(anIO->getEntry());
634 if ( anActor && anActor->GetScalarBarActor() && anActor->GetControlMode() != SMESH_Actor::eNone ) {
636 vtkScalarBarActor* myScalarBarActor = myActor->GetScalarBarActor();
638 if ( myScalarBarActor->GetLookupTable() ) {
639 float *range = myScalarBarActor->GetLookupTable()->GetRange();
640 myMinEdit->setText( QString::number( range[0],'g',12 ) );
641 myMaxEdit->setText( QString::number( range[1],'g',12 ) );
644 vtkTextProperty* aTitleTextPrp = myScalarBarActor->GetTitleTextProperty();
646 aTitleTextPrp->GetColor( aTColor );
647 myTitleColorBtn->setPaletteBackgroundColor( QColor( (int)( aTColor[0]*255 ), (int)( aTColor[1]*255 ), (int)( aTColor[2]*255 ) ) );
648 myTitleFontCombo->setCurrentItem( aTitleTextPrp->GetFontFamily() );
649 myTitleBoldCheck->setChecked( aTitleTextPrp->GetBold() );
650 myTitleItalicCheck->setChecked( aTitleTextPrp->GetItalic() );
651 myTitleShadowCheck->setChecked( aTitleTextPrp->GetShadow() );
653 vtkTextProperty* aLabelsTextPrp = myScalarBarActor->GetLabelTextProperty();
655 aLabelsTextPrp->GetColor( aLColor );
656 myLabelsColorBtn->setPaletteBackgroundColor( QColor( (int)( aLColor[0]*255 ), (int)( aLColor[1]*255 ), (int)( aLColor[2]*255 ) ) );
657 myLabelsFontCombo->setCurrentItem( aLabelsTextPrp->GetFontFamily() );
658 myLabelsBoldCheck->setChecked( aLabelsTextPrp->GetBold() );
659 myLabelsItalicCheck->setChecked( aLabelsTextPrp->GetItalic() );
660 myLabelsShadowCheck->setChecked( aLabelsTextPrp->GetShadow() );
662 myLabelsSpin->setValue( myScalarBarActor->GetNumberOfLabels() );
663 myColorsSpin->setValue( myScalarBarActor->GetMaximumNumberOfColors() );
665 if ( myScalarBarActor->GetOrientation() == VTK_ORIENT_VERTICAL )
666 myVertRadioBtn->setChecked( true );
668 myHorizRadioBtn->setChecked( true );
669 myIniOrientation = myVertRadioBtn->isChecked();
671 myIniX = myScalarBarActor->GetPosition()[0];
672 myIniY = myScalarBarActor->GetPosition()[1];
673 myIniW = myScalarBarActor->GetWidth();
674 myIniH = myScalarBarActor->GetHeight();
675 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
677 myRangeGrp->setEnabled( true );
678 myFontGrp->setEnabled( true );
679 myLabColorGrp->setEnabled( true );
680 myOrientationGrp->setEnabled( true );
681 myOriginDimGrp->setEnabled( true );
682 myOkBtn->setEnabled( true );
683 myApplyBtn->setEnabled( true );
689 myRangeGrp->setEnabled( false );
690 myFontGrp->setEnabled( false );
691 myLabColorGrp->setEnabled( false );
692 myOrientationGrp->setEnabled( false );
693 myOriginDimGrp->setEnabled( false );
694 myOkBtn->setEnabled( false );
695 myApplyBtn->setEnabled( false );
699 //=================================================================================================
701 * SMESHGUI_Preferences_ScalarBarDlg::closeEvent
703 * Close event handler
705 //=================================================================================================
706 void SMESHGUI_Preferences_ScalarBarDlg::closeEvent( QCloseEvent* e )
708 if ( mySelectionMgr ) // "Properties" dialog box
710 QDialog::closeEvent( e );
713 //=================================================================================================
715 * SMESHGUI_Preferences_ScalarBarDlg::onXYChanged
717 * Called when X, Y values are changed
719 //=================================================================================================
720 void SMESHGUI_Preferences_ScalarBarDlg::onXYChanged()
722 myWidthSpin->setMaxValue( 1.0 - myXSpin->value() );
723 myHeightSpin->setMaxValue( 1.0 - myYSpin->value() );
726 //=================================================================================================
728 * SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize
730 * Called when X, Y values are changed
732 //=================================================================================================
733 void SMESHGUI_Preferences_ScalarBarDlg::setOriginAndSize( const double x,
738 blockSignals( true );
739 myXSpin->setValue( x );
740 myYSpin->setValue( y );
741 myWidthSpin->setMaxValue( 1.0 );
742 myWidthSpin->setValue( w );
743 myHeightSpin->setMaxValue( 1.0 );
744 myHeightSpin->setValue( h );
745 blockSignals( false );
749 //=================================================================================================
751 * SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged
753 * Called when orientation is changed
755 //=================================================================================================
756 void SMESHGUI_Preferences_ScalarBarDlg::onOrientationChanged()
758 this->initScalarBarFromResources();
760 int aOrientation = myVertRadioBtn->isChecked();
761 if ( aOrientation == myIniOrientation )
762 setOriginAndSize( myIniX, myIniY, myIniW, myIniH );
764 setOriginAndSize( aOrientation ? DEF_VER_X : DEF_HOR_X,
765 aOrientation ? DEF_VER_Y : DEF_HOR_Y,
766 aOrientation ? DEF_VER_W : DEF_HOR_W,
767 aOrientation ? DEF_VER_H : DEF_HOR_H );
770 //=================================================================================================
772 * SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
774 * Rereading vertical and horizontal default positions from resources.
776 //=================================================================================================
777 void SMESHGUI_Preferences_ScalarBarDlg::initScalarBarFromResources()
779 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
782 // initialize from resoources
785 name = QString("scalar_bar_horizontal_%1");
786 if (mgr->hasValue("SMESH", name.arg( "x" )))
787 DEF_HOR_X = mgr->doubleValue("SMESH", name.arg( "x" ));
788 if (mgr->hasValue("SMESH", name.arg( "y" )))
789 DEF_HOR_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
790 if (mgr->hasValue("SMESH", name.arg( "width" )))
791 DEF_HOR_W = mgr->doubleValue("SMESH", name.arg( "width" ));
792 if (mgr->hasValue("SMESH", name.arg( "height" )))
793 DEF_HOR_H = mgr->doubleValue("SMESH", name.arg( "height" ));
796 name = QString("scalar_bar_vertical_%1");
797 if (mgr->hasValue("SMESH", name.arg( "x" )))
798 DEF_VER_X = mgr->doubleValue("SMESH", name.arg( "x" ));
799 if (mgr->hasValue("SMESH", name.arg( "y" )))
800 DEF_VER_Y = mgr->doubleValue("SMESH", name.arg( "y" ));
801 if (mgr->hasValue("SMESH", name.arg( "width" )))
802 DEF_VER_W = mgr->doubleValue("SMESH", name.arg( "width" ));
803 if (mgr->hasValue("SMESH", name.arg( "height" )))
804 DEF_VER_H = mgr->doubleValue("SMESH", name.arg( "height" ));