1 // VISU VISUGUI : GUI of VISU 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 : VisuGUI_ScalarBarDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_ScalarBarDlg.h"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_FontWg.h"
35 #include "SVTK_ViewWindow.h"
37 #include "VISUConfig.hh"
38 #include "VISU_Convertor.hxx"
40 #include "VISU_ScalarMapPL.hxx"
41 #include "VISU_ScalarMap_i.hh"
42 #include "VISU_ScalarMapAct.h"
44 #include "SalomeApp_Application.h"
46 #include "SUIT_MessageBox.h"
47 #include "SUIT_ResourceMgr.h"
51 #include <qvalidator.h>
52 #include <qcolordialog.h>
54 #include <vtkTextProperty.h>
59 VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref):
60 QVBox(parent), myPreviewActor(0)
62 myVerX = 0.01; myVerY = 0.10; myVerW = 0.10; myVerH = 0.80;
63 myHorX = 0.20; myHorY = 0.01; myHorW = 0.60; myHorH = 0.12;
64 Imin = 0.0; Imax = 0.0; /*Fmin = 0.0; Fmax = 0.0;*/ Rmin = 0.0; Rmax = 0.0;
70 // Range ============================================================
71 RangeGroup = new QButtonGroup (tr("SCALAR_RANGE_GRP"), this, "RangeGroup");
72 RangeGroup->setColumnLayout(0, Qt::Vertical );
73 RangeGroup->layout()->setSpacing( 0 );
74 RangeGroup->layout()->setMargin( 0 );
75 QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() );
76 RangeGroupLayout->setAlignment( Qt::AlignTop );
77 RangeGroupLayout->setSpacing( 6 );
78 RangeGroupLayout->setMargin( 11 );
80 myModeLbl = new QLabel("Scalar Mode", RangeGroup);
82 myModeCombo = new QComboBox(RangeGroup);
83 myModeCombo->insertItem("Modulus");
84 myModeCombo->insertItem("Component 1");
85 myModeCombo->insertItem("Component 2");
86 myModeCombo->insertItem("Component 3");
88 CBLog = new QCheckBox (tr("LOGARITHMIC_SCALING"), RangeGroup);
89 CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
91 RBFrange = new QRadioButton (tr("FIELD_RANGE_BTN"), RangeGroup, "RBFrange");
92 RBIrange = new QRadioButton (tr("IMPOSED_RANGE_BTN"), RangeGroup, "RBIrange");
93 RBFrange->setChecked( true );
95 MinEdit = new QLineEdit( RangeGroup, "MinEdit" );
96 MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
97 MinEdit->setMinimumWidth( 70 );
98 MinEdit->setValidator( new QDoubleValidator(this) );
99 MinEdit->setText( "0.0" );
100 QLabel* MinLabel = new QLabel (tr("LBL_MIN"), RangeGroup, "MinLabel");
101 MinLabel->setBuddy(MinEdit);
103 MaxEdit = new QLineEdit( RangeGroup, "MaxEdit" );
104 MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
105 MaxEdit->setMinimumWidth( 70 );
106 MaxEdit->setValidator( new QDoubleValidator(this) );
107 MaxEdit->setText( "0.0" );
108 QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), RangeGroup, "MaxLabel");
109 MaxLabel->setBuddy(MaxEdit);
111 RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
112 RangeGroupLayout->addMultiCellWidget( myModeCombo, 0, 0, 1, 3);
113 RangeGroupLayout->addMultiCellWidget( CBLog, 1, 1, 0, 3);
114 RangeGroupLayout->addMultiCellWidget( RBFrange, 2, 2, 0, 1);
115 RangeGroupLayout->addMultiCellWidget( RBIrange, 2, 2, 2, 3);
116 RangeGroupLayout->addWidget( MinLabel, 3, 0 );
117 RangeGroupLayout->addWidget( MinEdit, 3, 1 );
118 RangeGroupLayout->addWidget( MaxLabel, 3, 2 );
119 RangeGroupLayout->addWidget( MaxEdit, 3, 3 );
121 //TopLayout->addWidget( RangeGroup );
123 // Colors and Labels ========================================================
124 QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this, "ColLabGroup");
125 ColLabGroup->setColumnLayout(0, Qt::Vertical );
126 ColLabGroup->layout()->setSpacing( 0 );
127 ColLabGroup->layout()->setMargin( 0 );
128 QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() );
129 ColLabGroupLayout->setAlignment( Qt::AlignTop );
130 ColLabGroupLayout->setSpacing( 6 );
131 ColLabGroupLayout->setMargin( 11 );
133 QLabel* ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup, "ColorLabel");
134 ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup );
135 ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
136 ColorSpin->setMinimumWidth( 70 );
137 ColorSpin->setValue( 64 );
139 QLabel* LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup, "LabelLabel");
140 LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup );
141 LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
142 LabelSpin->setMinimumWidth( 70 );
143 LabelSpin->setValue( 5 );
145 ColLabGroupLayout->addWidget( ColorLabel, 0, 0);
146 ColLabGroupLayout->addWidget( ColorSpin, 0, 1);
147 ColLabGroupLayout->addWidget( LabelLabel, 0, 2);
148 ColLabGroupLayout->addWidget( LabelSpin, 0, 3);
150 //TopLayout->addWidget( ColLabGroup );
152 // Orientation ==========================================================
153 QButtonGroup* OrientGroup = new QButtonGroup (tr("ORIENTATION_GRP"), this, "OrientGroup");
154 OrientGroup->setColumnLayout(0, Qt::Vertical );
155 OrientGroup->layout()->setSpacing( 0 );
156 OrientGroup->layout()->setMargin( 0 );
157 QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() );
158 OrientGroupLayout->setAlignment( Qt::AlignTop );
159 OrientGroupLayout->setSpacing( 6 );
160 OrientGroupLayout->setMargin( 11 );
162 RBvert = new QRadioButton (tr("VERTICAL_BTN"), OrientGroup, "RBvert");
163 RBvert->setChecked( true );
164 RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), OrientGroup, "RBhori");
165 OrientGroupLayout->addWidget( RBvert, 0, 0 );
166 OrientGroupLayout->addWidget( RBhori, 0, 1 );
168 // TopLayout->addWidget( OrientGroup );
170 // Origin ===============================================================
171 QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this, "OriginGroup");
172 OriginGroup->setColumnLayout(0, Qt::Vertical );
173 OriginGroup->layout()->setSpacing( 0 );
174 OriginGroup->layout()->setMargin( 0 );
175 QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() );
176 OriginGroupLayout->setAlignment( Qt::AlignTop );
177 OriginGroupLayout->setSpacing( 6 );
178 OriginGroupLayout->setMargin( 11 );
180 QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup, "XLabel");
181 XSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
182 XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
183 XSpin->setMinimumWidth( 70 );
184 XSpin->setValue( 0.01 );
186 QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup, "YLabel");
187 YSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
188 YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
189 YSpin->setMinimumWidth( 70 );
190 YSpin->setValue( 0.01 );
192 OriginGroupLayout->addWidget( XLabel, 0, 0);
193 OriginGroupLayout->addWidget( XSpin, 0, 1);
194 OriginGroupLayout->addWidget( YLabel, 0, 2);
195 OriginGroupLayout->addWidget( YSpin, 0, 3);
197 //TopLayout->addWidget( OriginGroup );
199 // Dimensions =========================================================
200 QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this, "DimGroup");
201 DimGroup->setColumnLayout(0, Qt::Vertical );
202 DimGroup->layout()->setSpacing( 0 );
203 DimGroup->layout()->setMargin( 0 );
204 QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() );
205 DimGroupLayout->setAlignment( Qt::AlignTop );
206 DimGroupLayout->setSpacing( 6 );
207 DimGroupLayout->setMargin( 11 );
209 QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup, "WidthLabel");
210 WidthSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
211 WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
212 WidthSpin->setMinimumWidth( 70 );
213 WidthSpin->setValue( 0.1 );
215 QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup, "HeightLabel");
216 HeightSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
217 HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
218 HeightSpin->setMinimumWidth( 70 );
219 HeightSpin->setValue( 0.8 );
221 DimGroupLayout->addWidget( WidthLabel, 0, 0);
222 DimGroupLayout->addWidget( WidthSpin, 0, 1);
223 DimGroupLayout->addWidget( HeightLabel, 0, 2);
224 DimGroupLayout->addWidget( HeightSpin, 0, 3);
226 //TopLayout->addWidget( DimGroup );
228 // Save check box ===========================================================
229 QHBox* aSaveBox = new QHBox(this);
231 CBSave = new QCheckBox (tr("SAVE_DEFAULT_CHK"), aSaveBox, "CBSave");
232 //TopLayout->addWidget(CBSave);
237 myTextBtn = new QPushButton("Text properties...", aSaveBox);
238 myTextDlg = new VisuGUI_TextPrefDlg(this);
239 myTextDlg->setTitleVisible(!SetPref);
241 QGroupBox* CheckGroup = new QGroupBox("", this, "CheckGroup");
242 CheckGroup->setColumnLayout(0, Qt::Vertical );
243 CheckGroup->layout()->setSpacing( 0 );
244 CheckGroup->layout()->setMargin( 0 );
245 QGridLayout* CheckGroupLayout = new QGridLayout( CheckGroup->layout() );
247 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
248 myPreviewCheck->setChecked(false);
249 CheckGroupLayout->addWidget(myPreviewCheck , 0, 0 );
251 // signals and slots connections ===========================================
252 connect( RangeGroup, SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) );
253 connect( OrientGroup, SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) );
254 connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
255 connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
256 connect( myTextBtn, SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
257 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
258 connect( ColorSpin, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ));
259 connect( LabelSpin, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ));
260 connect( WidthSpin, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ));
261 connect( HeightSpin, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ));
262 connect( MinEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updatePreview() ));
263 connect( MaxEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updatePreview() ));
264 connect( CBLog, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ));
267 myIsStoreTextProp = false;
272 * Initializes dialog box values from resources
274 void VisuGUI_ScalarBarPane::initFromResources() {
275 int sbCol=64,sbLab=5,orient=0;
276 float sbX1=0.01,sbY1=0.1,sbW=0.1,sbH=0.8;
277 float sbVmin=0., sbVmax=0.;
281 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
283 int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
284 myModeCombo->setCurrentItem(aScalarMode);
286 orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", orient);
295 QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
297 sbX1 = aResourceMgr->doubleValue("VISU", propertyName + "x", sbX1);
298 sbY1 = aResourceMgr->doubleValue("VISU", propertyName + "y", sbY1);
300 sbW = aResourceMgr->doubleValue("VISU", propertyName + "width", sbW);
301 sbH = aResourceMgr->doubleValue("VISU", propertyName + "height",sbH);
303 sbCol = aResourceMgr->integerValue("VISU" ,"scalar_bar_num_colors", sbCol);
304 sbLab = aResourceMgr->integerValue("VISU", "scalar_bar_num_labels", sbLab);
306 int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0);
307 if (rangeType == 1) sbRange = true;
308 sbVmin = aResourceMgr->doubleValue("VISU", "scalar_range_min", sbVmin);
309 sbVmax = aResourceMgr->doubleValue("VISU", "scalar_range_max", sbVmax);
311 bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false);
312 setLogarithmic(isLog);
314 if((sbX1 < 0.) || (sbY1 < 0.) ||
315 ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
328 if(sbCol < 2) sbCol=2;
329 if(sbCol > 64) sbCol=64;
330 if(sbLab < 2) sbLab=2;
331 if(sbLab > 65) sbLab=65;
333 if(sbVmin > sbVmax) {
338 setRange( sbVmin, sbVmax, /*0.0, 0.0,*/ sbRange );
339 setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 0);
340 setScalarBarData( sbCol, sbLab );
343 bool isBold = false, isItalic = false, isShadow = false;
344 int aFontFamily = VTK_ARIAL;
346 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) )
348 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" );
350 if ( f.family() == "Arial" )
351 aFontFamily = VTK_ARIAL;
352 else if ( f.family() == "Courier" )
353 aFontFamily = VTK_COURIER;
354 else if ( f.family() == "Times" )
355 aFontFamily = VTK_TIMES;
358 isItalic = f.italic();
359 isShadow = f.underline();
362 QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
364 myTextDlg->myTitleFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
367 isBold = isItalic = isShadow = false;
368 aFontFamily = VTK_ARIAL;
370 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) )
372 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" );
374 if ( f.family() == "Arial" )
375 aFontFamily = VTK_ARIAL;
376 else if ( f.family() == "Courier" )
377 aFontFamily = VTK_COURIER;
378 else if ( f.family() == "Times" )
379 aFontFamily = VTK_TIMES;
382 isItalic = f.italic();
383 isShadow = f.underline();
386 aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
388 myTextDlg->myLabelFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
392 * Stores dialog values to resources
394 void VisuGUI_ScalarBarPane::storeToResources() {
395 int orient = (RBvert->isChecked())? 0 : 1;
396 float sbX1 = XSpin->value();
397 float sbY1 = YSpin->value();
398 float sbW = WidthSpin->value();
399 float sbH = HeightSpin->value();
400 int sbCol = ColorSpin->value();
401 int sbLab = LabelSpin->value();
403 if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
417 bool sbRange = RBIrange->isChecked();
418 float sbVmin = (float)(MinEdit->text().toDouble());
419 float sbVmax = (float)(MaxEdit->text().toDouble());
421 if(sbVmin > sbVmax) {
426 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
428 aResourceMgr->setValue("VISU", "scalar_bar_orientation", orient);
430 QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
432 aResourceMgr->setValue("VISU", propertyName + "x", sbX1);
433 aResourceMgr->setValue("VISU", propertyName + "y", sbY1);
434 aResourceMgr->setValue("VISU", propertyName + "width", sbW);
435 aResourceMgr->setValue("VISU", propertyName + "height", sbH);
437 aResourceMgr->setValue("VISU", "scalar_bar_num_colors", sbCol);
438 aResourceMgr->setValue("VISU", "scalar_bar_num_labels", sbLab);
442 aResourceMgr->setValue("VISU", "scalar_range_type", 1);
443 aResourceMgr->setValue("VISU", "scalar_range_min" ,sbVmin);
444 aResourceMgr->setValue("VISU", "scalar_range_max" ,sbVmax);
447 aResourceMgr->setValue("VISU", "scalar_range_type", 0);
449 aResourceMgr->setValue("VISU", "scalar_bar_logarithmic", isLogarithmic());
453 if (myIsStoreTextProp) {
455 QColor aTitleColor (255, 255, 255);
456 int aTitleFontFamily = VTK_ARIAL;
457 bool isTitleBold = false;
458 bool isTitleItalic = false;
459 bool isTitleShadow = false;
461 myTextDlg->myTitleFont->GetData(aTitleColor, aTitleFontFamily,
462 isTitleBold, isTitleItalic, isTitleShadow);
466 aTitleFont.setBold(isTitleBold);
467 aTitleFont.setItalic(isTitleItalic);
468 aTitleFont.setUnderline(isTitleShadow);
470 QString titleFontFamily;
471 switch (aTitleFontFamily) {
473 titleFontFamily = "Arial";
476 titleFontFamily = "Courier";
479 titleFontFamily = "Times";
482 aTitleFont.setFamily(titleFontFamily);
484 aResourceMgr->setValue("VISU", "scalar_bar_title_font", aTitleFont);
486 aResourceMgr->setValue("VISU", "scalar_bar_title_color", aTitleColor);
489 QColor aLabelColor (255, 255, 255);
490 int aLabelFontFamily = VTK_ARIAL;
491 bool isLabelBold = false;
492 bool isLabelItalic = false;
493 bool isLabelShadow = false;
495 myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
496 isLabelBold, isLabelItalic, isLabelShadow);
501 aLabelFont.setBold(isLabelBold);
502 aLabelFont.setItalic(isLabelItalic);
503 aLabelFont.setUnderline(isLabelShadow);
505 QString labelFontFamily;
506 switch (aLabelFontFamily) {
508 labelFontFamily = "Arial";
511 labelFontFamily = "Courier";
514 labelFontFamily = "Times";
518 aLabelFont.setFamily(labelFontFamily);
520 aResourceMgr->setValue("VISU", "scalar_bar_label_font", aLabelFont);
522 aResourceMgr->setValue("VISU", "scalar_bar_label_color", aLabelColor);
527 * Initialise dialog box from presentation object
529 void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
531 myScalarMap = thePrs;
532 myModeCombo->setCurrentItem(thePrs->GetScalarMode());
533 setPosAndSize( thePrs->GetPosX(),
537 thePrs->GetBarOrientation());
538 switch(thePrs->GetScaling()){
539 case VISU::LOGARITHMIC :
540 setLogarithmic(true);
543 setLogarithmic(false);
546 thePrs->GetScalarMapPL()->GetSourceRange(aRange);
547 Rmin = aRange[0]; Rmax = aRange[1];
548 setRange( thePrs->GetMin(), thePrs->GetMax(),
549 /*0.0, 0.0,*/ thePrs->IsRangeFixed() );
550 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
551 bool isScalarMode = (thePrs->GetField()->myNbComp > 1);
552 myModeLbl->setEnabled(isScalarMode);
553 myModeCombo->setEnabled(isScalarMode);
556 myTextDlg->setTitleText(QString(thePrs->GetTitle()));
559 thePrs->GetTitleColor(&R, &G, &B);
561 myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
562 thePrs->GetTitFontType(),
563 thePrs->IsBoldTitle(),
564 thePrs->IsItalicTitle(),
565 thePrs->IsShadowTitle());
568 thePrs->GetLabelColor(&R, &G, &B);
570 myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
571 thePrs->GetLblFontType(),
572 thePrs->IsBoldLabel(),
573 thePrs->IsItalicLabel(),
574 thePrs->IsShadowLabel());
577 if (myPreviewCheck->isChecked()) {
583 /*! Slot update preview of scalar bar, if preview is checked
585 void VisuGUI_ScalarBarPane::updatePreview()
587 if (myPreviewCheck->isChecked()) {
588 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
596 /*! Creating preview scalar bar
598 void VisuGUI_ScalarBarPane::createScalarBar()
600 if (VISU::GetViewWindow() == NULL) return;
601 if (myPreviewActor != 0) return;
602 if (myScalarMap == NULL) return;
605 sbCol = getNbColors();
606 sbLab = getNbLabels();
607 if(sbCol < 2) sbCol=2;
608 if(sbCol > 64) sbCol=64;
609 if(sbLab < 2) sbLab=2;
610 if(sbLab > 65) sbLab=65;
611 myPreviewActor = VISU_ScalarMapAct::New();
612 VISU_ScalarBarActor* aScalarBarActor = myPreviewActor->GetScalarBar();
613 myPreviewActor->GetScalarBar()->VisibilityOn();
614 myPreviewActor->PickableOff();
616 myScalarMap->SetScalarMode(myModeCombo->currentItem());
617 myScalarMap->SetPosition(getX(),getY());
618 myScalarMap->SetSize(getWidth(),getHeight());
619 myScalarMap->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
621 myScalarMap->SetScaling(VISU::LOGARITHMIC);
623 myScalarMap->SetScaling(VISU::LINEAR);
624 if (RBFrange->isChecked()) {
625 myScalarMap->SetSourceRange();
627 myScalarMap->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
629 myScalarMap->SetNbColors(sbCol);
630 myScalarMap->SetLabels(sbLab);
632 myScalarMap->GetScalarMapPL()->SetNbColors(sbCol);
633 myScalarMap->GetScalarMapPL()->Update();
635 aScalarBarActor->SetLookupTable(myScalarMap->GetScalarMapPL()->GetBarTable());
637 if (myTextDlg->getTitleText().latin1() != "")
638 aScalarBarActor->SetTitle(myTextDlg->getTitleText().latin1());
640 aScalarBarActor->SetTitle(myScalarMap->GetTitle());
641 aScalarBarActor->SetOrientation(getOrientation());
642 aScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
643 aScalarBarActor->GetPositionCoordinate()->SetValue(getX(),getY());
644 aScalarBarActor->SetWidth(getWidth());
645 aScalarBarActor->SetHeight(getHeight());
646 aScalarBarActor->SetNumberOfLabels(sbLab);
647 aScalarBarActor->SetMaximumNumberOfColors(sbCol);
649 // title text property
651 int aTitleFontFamily;
655 myTextDlg->myTitleFont->GetData(aTitleColor,aTitleFontFamily,
656 isTitleBold,isTitleItalic,isTitleShadow);
657 vtkTextProperty* aTitleProp = aScalarBarActor->GetTitleTextProperty();
658 aTitleProp->SetFontFamily(aTitleFontFamily);
659 aTitleProp->SetColor(float(aTitleColor.red())/255.,
660 float(aTitleColor.green())/255.,
661 float(aTitleColor.blue())/255.);
662 (isTitleBold)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
663 (isTitleItalic)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
664 (isTitleShadow)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
666 // label text property
668 int aLabelFontFamily;
672 myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
673 isLabelBold, isLabelItalic, isLabelShadow);
674 vtkTextProperty* aLabelProp = aScalarBarActor->GetLabelTextProperty();
675 aLabelProp->SetFontFamily(aLabelFontFamily);
676 aLabelProp->SetColor(float(aLabelColor.red())/255.,
677 float(aLabelColor.green())/255.,
678 float(aLabelColor.blue())/255.);
679 (isLabelBold)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
680 (isLabelItalic)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
681 (isLabelShadow)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
683 aScalarBarActor->Modified();
685 VISU::GetViewWindow()->AddActor(myPreviewActor);
687 /*! Deleting preview scalar bar
689 void VisuGUI_ScalarBarPane::deleteScalarBar()
691 if (myPreviewActor == 0) return;
692 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()){
693 vf->RemoveActor(myPreviewActor);
694 myPreviewActor->GetScalarBar()->VisibilityOff();
696 myPreviewActor->Delete();
699 /*! public: Deleting preview scalar bar
701 void VisuGUI_ScalarBarPane::deletePreview()
706 * Store values to presentation object
708 int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
709 thePrs->SetScalarMode(myModeCombo->currentItem());
710 thePrs->SetPosition(XSpin->value(), YSpin->value());
711 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
712 thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
714 thePrs->SetScaling(VISU::LOGARITHMIC);
716 thePrs->SetScaling(VISU::LINEAR);
718 if (RBFrange->isChecked()) {
719 thePrs->SetSourceRange();
721 thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
723 thePrs->SetNbColors(ColorSpin->value());
724 thePrs->SetLabels(LabelSpin->value());
726 if (isToSave()) storeToResources();
728 if (myIsStoreTextProp) {
730 thePrs->SetTitle(myTextDlg->getTitleText().latin1());
732 QColor aTitColor (255, 255, 255);
733 int aTitleFontFamily = VTK_ARIAL;
734 bool isTitleBold = false;
735 bool isTitleItalic = false;
736 bool isTitleShadow = false;
738 myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
739 isTitleBold, isTitleItalic, isTitleShadow);
741 thePrs->SetBoldTitle(isTitleBold);
742 thePrs->SetItalicTitle(isTitleItalic);
743 thePrs->SetShadowTitle(isTitleShadow);
744 thePrs->SetTitFontType(aTitleFontFamily);
745 thePrs->SetTitleColor(aTitColor.red()/255.,
746 aTitColor.green()/255.,
747 aTitColor.blue()/255.);
750 QColor aLblColor (255, 255, 255);
751 int aLabelFontFamily = VTK_ARIAL;
752 bool isLabelBold = false;
753 bool isLabelItalic = false;
754 bool isLabelShadow = false;
756 myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
757 isLabelBold, isLabelItalic, isLabelShadow);
759 thePrs->SetBoldLabel(isLabelBold);
760 thePrs->SetItalicLabel(isLabelItalic);
761 thePrs->SetShadowLabel(isLabelShadow);
762 thePrs->SetLblFontType(aLabelFontFamily);
763 thePrs->SetLabelColor(aLblColor.red()/255.,
764 aLblColor.green()/255.,
765 aLblColor.blue()/255.);
772 Called when orientation is changed
774 void VisuGUI_ScalarBarPane::changeDefaults( int )
776 if ( RBvert->isChecked() ) {
777 XSpin->setValue( myVerX );
778 YSpin->setValue( myVerY );
779 WidthSpin->setValue( myVerW );
780 HeightSpin->setValue( myVerH );
783 XSpin->setValue( myHorX );
784 YSpin->setValue( myHorY );
785 WidthSpin->setValue( myHorW );
786 HeightSpin->setValue( myHorH );
792 Called when Range mode is changed
794 void VisuGUI_ScalarBarPane::changeRange( int )
797 if ( RBFrange->isChecked() )
799 if ( RBIrange->isChecked() )
801 if ( myRangeMode == mode )
803 //MinSpin->setMaxValue( Fmin );
804 //MaxSpin->setMinValue( Fmax );
805 if ( RBFrange->isChecked() ) {
806 //MinLabel->setEnabled( false );
807 MinEdit->setEnabled( false );
808 //MaxLabel->setEnabled( false );
809 MaxEdit->setEnabled( false );
811 Imin = MinEdit->text().toDouble();
812 Imax = MaxEdit->text().toDouble();
814 MinEdit->setText( QString::number( Rmin ) );
815 MaxEdit->setText( QString::number( Rmax ) );
818 //MinLabel->setEnabled( true );
819 MinEdit->setEnabled( true );
820 //MaxLabel->setEnabled( true );
821 MaxEdit->setEnabled( true );
822 MinEdit->setText( QString::number( Imin ) );
823 MaxEdit->setText( QString::number( Imax ) );
830 Called when X,Y position is changed
832 void VisuGUI_ScalarBarPane::XYChanged( double )
834 QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
835 if ( snd == XSpin ) {
836 WidthSpin->setMaxValue( 1.0 - XSpin->value() );
838 if ( snd == YSpin ) {
839 HeightSpin->setMaxValue( 1.0 - YSpin->value() );
845 Sets default values and range mode
847 void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, double fmax*/, bool sbRange )
849 Imin = imin; Imax = imax;// Fmin = fmin; Fmax = fmax;
850 if ( RBIrange->isChecked() ) {
851 MinEdit->setText( QString::number( Imin ) );
852 MaxEdit->setText( QString::number( Imax ) );
855 MinEdit->setText( QString::number( Rmin ) );
856 MaxEdit->setText( QString::number( Rmax ) );
860 RBIrange->setChecked( true );
862 RBFrange->setChecked( true );
867 Sets size and position
869 void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
876 RBvert->setChecked( true );
883 RBhori->setChecked( true );
889 Sets colors and labels number
891 void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels )
893 ColorSpin->setValue( colors );
894 LabelSpin->setValue( labels );
900 int VisuGUI_ScalarBarPane::getOrientation()
902 if (RBvert->isChecked() )
909 Called when <OK> button is clicked, validates data and closes dialog
911 bool VisuGUI_ScalarBarPane::check()
913 double minVal = MinEdit->text().toDouble();
914 double maxVal = MaxEdit->text().toDouble();
915 if ( RBIrange->isChecked() ) {
916 if (minVal >= maxVal) {
917 SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
918 tr("MSG_MINMAX_VALUES"),
923 // check if logarithmic mode is on and check imposed range to not contain negative values
924 if ( CBLog->isChecked() ) {
925 if ( RBIrange->isChecked() ) {
926 if ( (minVal > 0) && (maxVal > 0) ) {
930 SUIT_MessageBox::warn1( this,
932 tr("WRN_LOGARITHMIC_RANGE"),
938 if ( Rmin > 0 && Rmax > 0 ) {
942 SUIT_MessageBox::warn1( this,
944 tr("WRN_LOGARITHMIC_FIELD_RANGE"),
946 RBIrange->setChecked(1);
948 //MinEdit->setText( QString::number( Rmin ) );
949 //MaxEdit->setText( QString::number( Rmax ) );
957 void VisuGUI_ScalarBarPane::onTextPref()
959 myIsStoreTextProp = myTextDlg->exec();
963 void VisuGUI_ScalarBarPane::onPreviewCheck (bool thePreview)
965 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
975 //#######################################################################################
980 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool SetPref)
981 : QDialog(VISU::GetDesktop(theModule), 0, true,
982 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
984 setName("VisuGUI_ScalarBarDlg");
985 setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE"));
986 setSizeGripEnabled(TRUE);
988 QVBoxLayout* TopLayout = new QVBoxLayout(this);
989 TopLayout->setSpacing(6);
990 TopLayout->setMargin(11);
992 myScalarPane = new VisuGUI_ScalarBarPane(this, SetPref);
993 TopLayout->addWidget(myScalarPane);
995 // Common buttons ===========================================================
996 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
997 GroupButtons->setColumnLayout(0, Qt::Vertical );
998 GroupButtons->layout()->setSpacing( 0 );
999 GroupButtons->layout()->setMargin( 0 );
1000 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1001 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1002 GroupButtonsLayout->setSpacing( 6 );
1003 GroupButtonsLayout->setMargin( 11 );
1005 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1006 buttonOk->setAutoDefault( TRUE );
1007 buttonOk->setDefault( TRUE );
1008 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1009 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1011 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1012 buttonCancel->setAutoDefault( TRUE );
1013 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1015 TopLayout->addWidget( GroupButtons );
1017 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
1018 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
1022 Called when <OK> button is clicked, validates data and closes dialog
1024 void VisuGUI_ScalarBarDlg::accept()
1026 myScalarPane->deletePreview();
1027 if (myScalarPane->check()) QDialog::accept();
1031 Called when <Cancel> button is clicked, remove preview and closes dialog
1033 void VisuGUI_ScalarBarDlg::reject()
1035 myScalarPane->deletePreview();
1040 //#######################################################################################
1041 VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
1042 : QDialog(parent, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
1044 setName("VisuGUI_TextPrefDlg");
1045 setCaption(tr("TIT_TEXT_PREF"));
1046 setSizeGripEnabled(TRUE);
1048 QVBoxLayout* TopLayout = new QVBoxLayout(this);
1049 TopLayout->setSpacing(6);
1050 TopLayout->setMargin(11);
1053 QGroupBox* aTitleGrp = new QGroupBox (2, Qt::Vertical, tr("LBL_TITLE"), this);
1056 myTitleEdt = new QLineEdit (aTitleGrp);
1059 QHBox* aHBox = new QHBox (aTitleGrp);
1060 aHBox->setSpacing(5);
1061 myTitleFont = new VisuGUI_FontWg (aHBox);
1063 TopLayout->addWidget(aTitleGrp);
1066 QGroupBox* aLabelsGrp = new QGroupBox (1, Qt::Vertical, tr("LBL_LABELS"), this);
1069 aHBox = new QHBox (aLabelsGrp);
1070 aHBox->setSpacing(5);
1071 myLabelFont = new VisuGUI_FontWg (aHBox);
1073 TopLayout->addWidget(aLabelsGrp);
1075 // Common buttons ===========================================================
1076 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1077 GroupButtons->setColumnLayout(0, Qt::Vertical );
1078 GroupButtons->layout()->setSpacing( 0 );
1079 GroupButtons->layout()->setMargin( 0 );
1080 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1081 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1082 GroupButtonsLayout->setSpacing( 6 );
1083 GroupButtonsLayout->setMargin( 11 );
1085 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1086 buttonOk->setAutoDefault( TRUE );
1087 buttonOk->setDefault( TRUE );
1088 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1089 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1091 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1092 buttonCancel->setAutoDefault( TRUE );
1093 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1095 TopLayout->addWidget( GroupButtons );
1097 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
1098 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));