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"
34 #include "SVTK_FontWidget.h"
36 #include "SVTK_ViewWindow.h"
38 #include "SVTK_ViewWindow.h"
40 #include "VISUConfig.hh"
41 #include "VISU_Convertor.hxx"
43 #include "VISU_ScalarMapPL.hxx"
44 #include "VISU_ScalarMap_i.hh"
45 #include "VISU_ScalarMapAct.h"
47 #include "SalomeApp_Application.h"
49 #include "SUIT_MessageBox.h"
50 #include "SUIT_ResourceMgr.h"
54 #include <qvalidator.h>
55 #include <qcolordialog.h>
57 #include <vtkTextProperty.h>
62 VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref):
63 QVBox(parent), myPreviewActor(0)
65 myVerX = 0.01; myVerY = 0.10; myVerW = 0.10; myVerH = 0.80;
66 myHorX = 0.20; myHorY = 0.01; myHorW = 0.60; myHorH = 0.12;
67 Imin = 0.0; Imax = 0.0; /*Fmin = 0.0; Fmax = 0.0;*/ Rmin = 0.0; Rmax = 0.0;
73 // Range ============================================================
74 RangeGroup = new QButtonGroup (tr("SCALAR_RANGE_GRP"), this, "RangeGroup");
75 RangeGroup->setColumnLayout(0, Qt::Vertical );
76 RangeGroup->layout()->setSpacing( 0 );
77 RangeGroup->layout()->setMargin( 0 );
78 QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() );
79 RangeGroupLayout->setAlignment( Qt::AlignTop );
80 RangeGroupLayout->setSpacing( 6 );
81 RangeGroupLayout->setMargin( 11 );
83 myModeLbl = new QLabel("Scalar Mode", RangeGroup);
85 myModeCombo = new QComboBox(RangeGroup);
87 CBLog = new QCheckBox (tr("LOGARITHMIC_SCALING"), RangeGroup);
88 CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
90 RBFrange = new QRadioButton (tr("FIELD_RANGE_BTN"), RangeGroup, "RBFrange");
91 RBIrange = new QRadioButton (tr("IMPOSED_RANGE_BTN"), RangeGroup, "RBIrange");
92 RBFrange->setChecked( true );
94 MinEdit = new QLineEdit( RangeGroup, "MinEdit" );
95 MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
96 MinEdit->setMinimumWidth( 70 );
97 MinEdit->setValidator( new QDoubleValidator(this) );
98 MinEdit->setText( "0.0" );
99 QLabel* MinLabel = new QLabel (tr("LBL_MIN"), RangeGroup, "MinLabel");
100 MinLabel->setBuddy(MinEdit);
102 MaxEdit = new QLineEdit( RangeGroup, "MaxEdit" );
103 MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
104 MaxEdit->setMinimumWidth( 70 );
105 MaxEdit->setValidator( new QDoubleValidator(this) );
106 MaxEdit->setText( "0.0" );
107 QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), RangeGroup, "MaxLabel");
108 MaxLabel->setBuddy(MaxEdit);
110 RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
111 RangeGroupLayout->addMultiCellWidget( myModeCombo, 0, 0, 1, 3);
112 RangeGroupLayout->addMultiCellWidget( CBLog, 1, 1, 0, 3);
113 RangeGroupLayout->addMultiCellWidget( RBFrange, 2, 2, 0, 1);
114 RangeGroupLayout->addMultiCellWidget( RBIrange, 2, 2, 2, 3);
115 RangeGroupLayout->addWidget( MinLabel, 3, 0 );
116 RangeGroupLayout->addWidget( MinEdit, 3, 1 );
117 RangeGroupLayout->addWidget( MaxLabel, 3, 2 );
118 RangeGroupLayout->addWidget( MaxEdit, 3, 3 );
120 //TopLayout->addWidget( RangeGroup );
122 // Colors and Labels ========================================================
123 QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this, "ColLabGroup");
124 ColLabGroup->setColumnLayout(0, Qt::Vertical );
125 ColLabGroup->layout()->setSpacing( 0 );
126 ColLabGroup->layout()->setMargin( 0 );
127 QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() );
128 ColLabGroupLayout->setAlignment( Qt::AlignTop );
129 ColLabGroupLayout->setSpacing( 6 );
130 ColLabGroupLayout->setMargin( 11 );
132 QLabel* ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup, "ColorLabel");
133 ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup );
134 ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
135 ColorSpin->setMinimumWidth( 70 );
136 ColorSpin->setValue( 64 );
138 QLabel* LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup, "LabelLabel");
139 LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup );
140 LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
141 LabelSpin->setMinimumWidth( 70 );
142 LabelSpin->setValue( 5 );
144 ColLabGroupLayout->addWidget( ColorLabel, 0, 0);
145 ColLabGroupLayout->addWidget( ColorSpin, 0, 1);
146 ColLabGroupLayout->addWidget( LabelLabel, 0, 2);
147 ColLabGroupLayout->addWidget( LabelSpin, 0, 3);
149 //TopLayout->addWidget( ColLabGroup );
151 // Orientation ==========================================================
152 QButtonGroup* OrientGroup = new QButtonGroup (tr("ORIENTATION_GRP"), this, "OrientGroup");
153 OrientGroup->setColumnLayout(0, Qt::Vertical );
154 OrientGroup->layout()->setSpacing( 0 );
155 OrientGroup->layout()->setMargin( 0 );
156 QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() );
157 OrientGroupLayout->setAlignment( Qt::AlignTop );
158 OrientGroupLayout->setSpacing( 6 );
159 OrientGroupLayout->setMargin( 11 );
161 RBvert = new QRadioButton (tr("VERTICAL_BTN"), OrientGroup, "RBvert");
162 RBvert->setChecked( true );
163 RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), OrientGroup, "RBhori");
164 OrientGroupLayout->addWidget( RBvert, 0, 0 );
165 OrientGroupLayout->addWidget( RBhori, 0, 1 );
167 // TopLayout->addWidget( OrientGroup );
169 // Origin ===============================================================
170 QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this, "OriginGroup");
171 OriginGroup->setColumnLayout(0, Qt::Vertical );
172 OriginGroup->layout()->setSpacing( 0 );
173 OriginGroup->layout()->setMargin( 0 );
174 QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() );
175 OriginGroupLayout->setAlignment( Qt::AlignTop );
176 OriginGroupLayout->setSpacing( 6 );
177 OriginGroupLayout->setMargin( 11 );
179 QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup, "XLabel");
180 XSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
181 XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
182 XSpin->setMinimumWidth( 70 );
183 XSpin->setValue( 0.01 );
185 QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup, "YLabel");
186 YSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
187 YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
188 YSpin->setMinimumWidth( 70 );
189 YSpin->setValue( 0.01 );
191 OriginGroupLayout->addWidget( XLabel, 0, 0);
192 OriginGroupLayout->addWidget( XSpin, 0, 1);
193 OriginGroupLayout->addWidget( YLabel, 0, 2);
194 OriginGroupLayout->addWidget( YSpin, 0, 3);
196 //TopLayout->addWidget( OriginGroup );
198 // Dimensions =========================================================
199 QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this, "DimGroup");
200 DimGroup->setColumnLayout(0, Qt::Vertical );
201 DimGroup->layout()->setSpacing( 0 );
202 DimGroup->layout()->setMargin( 0 );
203 QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() );
204 DimGroupLayout->setAlignment( Qt::AlignTop );
205 DimGroupLayout->setSpacing( 6 );
206 DimGroupLayout->setMargin( 11 );
208 QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup, "WidthLabel");
209 WidthSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
210 WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
211 WidthSpin->setMinimumWidth( 70 );
212 WidthSpin->setValue( 0.1 );
214 QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup, "HeightLabel");
215 HeightSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
216 HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
217 HeightSpin->setMinimumWidth( 70 );
218 HeightSpin->setValue( 0.8 );
220 DimGroupLayout->addWidget( WidthLabel, 0, 0);
221 DimGroupLayout->addWidget( WidthSpin, 0, 1);
222 DimGroupLayout->addWidget( HeightLabel, 0, 2);
223 DimGroupLayout->addWidget( HeightSpin, 0, 3);
225 //TopLayout->addWidget( DimGroup );
227 // Save check box ===========================================================
228 QHBox* aSaveBox = new QHBox(this);
230 CBSave = new QCheckBox (tr("SAVE_DEFAULT_CHK"), aSaveBox, "CBSave");
231 //TopLayout->addWidget(CBSave);
236 myTextBtn = new QPushButton("Text properties...", aSaveBox);
237 myTextDlg = new VisuGUI_TextPrefDlg(this);
238 myTextDlg->setTitleVisible(!SetPref);
240 QGroupBox* CheckGroup = new QGroupBox("", this, "CheckGroup");
241 CheckGroup->setColumnLayout(0, Qt::Vertical );
242 CheckGroup->layout()->setSpacing( 0 );
243 CheckGroup->layout()->setMargin( 0 );
244 QGridLayout* CheckGroupLayout = new QGridLayout( CheckGroup->layout() );
246 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), CheckGroup);
247 myPreviewCheck->setChecked(false);
248 CheckGroupLayout->addWidget(myPreviewCheck , 0, 0 );
250 // signals and slots connections ===========================================
251 connect( RangeGroup, SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) );
252 connect( myModeCombo, SIGNAL( activated( int ) ), this, SLOT( changeScalarMode( 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( CBLog, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ));
265 myIsStoreTextProp = false;
270 * Initializes dialog box values from resources
272 void VisuGUI_ScalarBarPane::initFromResources() {
273 int sbCol=64,sbLab=5,orient=0;
274 float sbX1=0.01,sbY1=0.1,sbW=0.1,sbH=0.8;
275 float sbVmin=0., sbVmax=0.;
279 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
281 bool anIsArrangeBar = aResourceMgr->booleanValue("VISU", "scalar_bars_default_position", 0);
284 aPlace = aResourceMgr->integerValue("VISU", "scalar_bar_position_num",0);
287 int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
288 myModeCombo->setCurrentItem(aScalarMode);
290 orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", orient);
299 QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
301 sbX1 = aResourceMgr->doubleValue("VISU", propertyName + "x", sbX1);
302 sbY1 = aResourceMgr->doubleValue("VISU", propertyName + "y", sbY1);
304 sbW = aResourceMgr->doubleValue("VISU", propertyName + "width", sbW);
305 sbH = aResourceMgr->doubleValue("VISU", propertyName + "height",sbH);
308 sbY1 += sbH*(aPlace-1);
310 sbX1 += sbW*(aPlace-1);
312 sbCol = aResourceMgr->integerValue("VISU" ,"scalar_bar_num_colors", sbCol);
313 sbLab = aResourceMgr->integerValue("VISU", "scalar_bar_num_labels", sbLab);
315 int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0);
316 if (rangeType == 1) sbRange = true;
317 sbVmin = aResourceMgr->doubleValue("VISU", "scalar_range_min", sbVmin);
318 sbVmax = aResourceMgr->doubleValue("VISU", "scalar_range_max", sbVmax);
320 bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false);
321 setLogarithmic(isLog);
323 if((sbX1 < 0.) || (sbY1 < 0.) ||
324 ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
337 if(sbCol < 2) sbCol=2;
338 if(sbCol > 64) sbCol=64;
339 if(sbLab < 2) sbLab=2;
340 if(sbLab > 65) sbLab=65;
342 if(sbVmin > sbVmax) {
347 setRange( sbVmin, sbVmax, /*0.0, 0.0,*/ sbRange );
348 setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 0);
349 setScalarBarData( sbCol, sbLab );
352 bool isBold = false, isItalic = false, isShadow = false;
353 int aFontFamily = VTK_ARIAL;
355 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) )
357 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" );
359 if ( f.family() == "Arial" )
360 aFontFamily = VTK_ARIAL;
361 else if ( f.family() == "Courier" )
362 aFontFamily = VTK_COURIER;
363 else if ( f.family() == "Times" )
364 aFontFamily = VTK_TIMES;
367 isItalic = f.italic();
368 isShadow = f.underline();
371 QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
373 myTextDlg->myTitleFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
376 isBold = isItalic = isShadow = false;
377 aFontFamily = VTK_ARIAL;
379 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) )
381 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" );
383 if ( f.family() == "Arial" )
384 aFontFamily = VTK_ARIAL;
385 else if ( f.family() == "Courier" )
386 aFontFamily = VTK_COURIER;
387 else if ( f.family() == "Times" )
388 aFontFamily = VTK_TIMES;
391 isItalic = f.italic();
392 isShadow = f.underline();
395 aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
397 myTextDlg->myLabelFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
401 * Stores dialog values to resources
403 void VisuGUI_ScalarBarPane::storeToResources() {
404 int orient = (RBvert->isChecked())? 0 : 1;
405 float sbX1 = XSpin->value();
406 float sbY1 = YSpin->value();
407 float sbW = WidthSpin->value();
408 float sbH = HeightSpin->value();
409 int sbCol = ColorSpin->value();
410 int sbLab = LabelSpin->value();
412 if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
426 bool sbRange = RBIrange->isChecked();
427 float sbVmin = (float)(MinEdit->text().toDouble());
428 float sbVmax = (float)(MaxEdit->text().toDouble());
430 if(sbVmin > sbVmax) {
435 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
437 aResourceMgr->setValue("VISU", "scalar_bar_orientation", orient);
439 QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
441 aResourceMgr->setValue("VISU", propertyName + "x", sbX1);
442 aResourceMgr->setValue("VISU", propertyName + "y", sbY1);
443 aResourceMgr->setValue("VISU", propertyName + "width", sbW);
444 aResourceMgr->setValue("VISU", propertyName + "height", sbH);
446 aResourceMgr->setValue("VISU", "scalar_bar_num_colors", sbCol);
447 aResourceMgr->setValue("VISU", "scalar_bar_num_labels", sbLab);
451 aResourceMgr->setValue("VISU", "scalar_range_type", 1);
452 aResourceMgr->setValue("VISU", "scalar_range_min" ,sbVmin);
453 aResourceMgr->setValue("VISU", "scalar_range_max" ,sbVmax);
456 aResourceMgr->setValue("VISU", "scalar_range_type", 0);
458 aResourceMgr->setValue("VISU", "scalar_bar_logarithmic", isLogarithmic());
462 if (myIsStoreTextProp) {
464 QColor aTitleColor (255, 255, 255);
465 int aTitleFontFamily = VTK_ARIAL;
466 bool isTitleBold = false;
467 bool isTitleItalic = false;
468 bool isTitleShadow = false;
470 myTextDlg->myTitleFont->GetData(aTitleColor, aTitleFontFamily,
471 isTitleBold, isTitleItalic, isTitleShadow);
475 aTitleFont.setBold(isTitleBold);
476 aTitleFont.setItalic(isTitleItalic);
477 aTitleFont.setUnderline(isTitleShadow);
479 QString titleFontFamily;
480 switch (aTitleFontFamily) {
482 titleFontFamily = "Arial";
485 titleFontFamily = "Courier";
488 titleFontFamily = "Times";
491 aTitleFont.setFamily(titleFontFamily);
493 aResourceMgr->setValue("VISU", "scalar_bar_title_font", aTitleFont);
495 aResourceMgr->setValue("VISU", "scalar_bar_title_color", aTitleColor);
498 QColor aLabelColor (255, 255, 255);
499 int aLabelFontFamily = VTK_ARIAL;
500 bool isLabelBold = false;
501 bool isLabelItalic = false;
502 bool isLabelShadow = false;
504 myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
505 isLabelBold, isLabelItalic, isLabelShadow);
510 aLabelFont.setBold(isLabelBold);
511 aLabelFont.setItalic(isLabelItalic);
512 aLabelFont.setUnderline(isLabelShadow);
514 QString labelFontFamily;
515 switch (aLabelFontFamily) {
517 labelFontFamily = "Arial";
520 labelFontFamily = "Courier";
523 labelFontFamily = "Times";
527 aLabelFont.setFamily(labelFontFamily);
529 aResourceMgr->setValue("VISU", "scalar_bar_label_font", aLabelFont);
531 aResourceMgr->setValue("VISU", "scalar_bar_label_color", aLabelColor);
536 * Initialise dialog box from presentation object
538 void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
540 myScalarMap = thePrs;
541 setPosAndSize( thePrs->GetPosX(),
545 thePrs->GetBarOrientation());
546 switch(thePrs->GetScaling()){
547 case VISU::LOGARITHMIC :
548 setLogarithmic(true);
551 setLogarithmic(false);
554 thePrs->GetScalarMapPL()->GetSourceRange(aRange);
555 Rmin = aRange[0]; Rmax = aRange[1];
556 setRange( thePrs->GetMin(), thePrs->GetMax(),
557 /*0.0, 0.0,*/ thePrs->IsRangeFixed() );
558 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
560 // Update myModeCombo
561 int aNbComp = thePrs->GetField()->myNbComp;
562 bool isScalarMode = (aNbComp > 1);
563 myModeCombo->clear();
564 myModeCombo->insertItem("<Modulus>");
565 const VISU::PField& aField = thePrs->GetField();
566 const VISU::TNames& aCompNames = aField->myCompNames;
567 const VISU::TNames& aUnitNames = aField->myUnitNames;
568 for(int i = 0; i < aNbComp; i++){
569 QString aComponent = QString(aCompNames[i]).simplifyWhiteSpace();
570 if(aComponent.isNull() || aComponent == "")
571 aComponent = "Component " + QString::number(i+1);
573 aComponent = "[" + QString::number(i+1) + "] " + aComponent;
575 QString anUnit = QString(aUnitNames[i]).simplifyWhiteSpace();
576 if(anUnit.isNull() || anUnit == "")
579 aComponent = aComponent + ", " + anUnit;
581 myModeCombo->insertItem(aComponent);
584 myModeCombo->setCurrentItem(thePrs->GetScalarMode());
586 myModeCombo->setCurrentItem(1);
589 myModeLbl->setEnabled(isScalarMode);
590 myModeCombo->setEnabled(isScalarMode);
593 myTextDlg->setTitleText(QString(thePrs->GetTitle()));
596 thePrs->GetTitleColor(&R, &G, &B);
598 myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
599 thePrs->GetTitFontType(),
600 thePrs->IsBoldTitle(),
601 thePrs->IsItalicTitle(),
602 thePrs->IsShadowTitle());
605 thePrs->GetLabelColor(&R, &G, &B);
607 myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
608 thePrs->GetLblFontType(),
609 thePrs->IsBoldLabel(),
610 thePrs->IsItalicLabel(),
611 thePrs->IsShadowLabel());
614 if (myPreviewCheck->isChecked()) {
620 /*! Slot update preview of scalar bar, if preview is checked
622 void VisuGUI_ScalarBarPane::updatePreview()
624 if (myPreviewCheck->isChecked()) {
625 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
633 /*! Creating preview scalar bar
635 void VisuGUI_ScalarBarPane::createScalarBar()
637 if (VISU::GetViewWindow() == NULL) return;
638 if (myPreviewActor != 0) return;
639 if (myScalarMap == NULL) return;
643 if ( myBusy ) return;
648 sbCol = getNbColors();
649 sbLab = getNbLabels();
650 if(sbCol < 2) sbCol=2;
651 if(sbCol > 64) sbCol=64;
652 if(sbLab < 2) sbLab=2;
653 if(sbLab > 65) sbLab=65;
654 myPreviewActor = VISU_ScalarMapAct::New();
655 VISU_ScalarBarActor* aScalarBarActor = myPreviewActor->GetScalarBar();
656 myPreviewActor->GetScalarBar()->VisibilityOn();
657 myPreviewActor->PickableOff();
659 myScalarMap->SetScalarMode(myModeCombo->currentItem());
660 myScalarMap->SetPosition(getX(),getY());
661 myScalarMap->SetSize(getWidth(),getHeight());
662 myScalarMap->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
664 myScalarMap->SetScaling(VISU::LOGARITHMIC);
666 myScalarMap->SetScaling(VISU::LINEAR);
667 if (RBFrange->isChecked()) {
668 myScalarMap->SetSourceRange();
670 myScalarMap->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
672 myScalarMap->SetNbColors(sbCol);
673 myScalarMap->SetLabels(sbLab);
675 myScalarMap->GetScalarMapPL()->SetNbColors(sbCol);
676 myScalarMap->GetScalarMapPL()->Update();
678 aScalarBarActor->SetLookupTable(myScalarMap->GetScalarMapPL()->GetBarTable());
680 if (myTextDlg->getTitleText().latin1() != "")
681 aScalarBarActor->SetTitle(myTextDlg->getTitleText().latin1());
683 aScalarBarActor->SetTitle(myScalarMap->GetTitle());
684 aScalarBarActor->SetOrientation(getOrientation());
685 aScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
686 aScalarBarActor->GetPositionCoordinate()->SetValue(getX(),getY());
687 aScalarBarActor->SetWidth(getWidth());
688 aScalarBarActor->SetHeight(getHeight());
689 aScalarBarActor->SetNumberOfLabels(sbLab);
690 aScalarBarActor->SetMaximumNumberOfColors(sbCol);
692 // title text property
694 int aTitleFontFamily;
698 myTextDlg->myTitleFont->GetData(aTitleColor,aTitleFontFamily,
699 isTitleBold,isTitleItalic,isTitleShadow);
700 vtkTextProperty* aTitleProp = aScalarBarActor->GetTitleTextProperty();
701 aTitleProp->SetFontFamily(aTitleFontFamily);
702 aTitleProp->SetColor(float(aTitleColor.red())/255.,
703 float(aTitleColor.green())/255.,
704 float(aTitleColor.blue())/255.);
705 (isTitleBold)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
706 (isTitleItalic)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
707 (isTitleShadow)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
709 // label text property
711 int aLabelFontFamily;
715 myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
716 isLabelBold, isLabelItalic, isLabelShadow);
717 vtkTextProperty* aLabelProp = aScalarBarActor->GetLabelTextProperty();
718 aLabelProp->SetFontFamily(aLabelFontFamily);
719 aLabelProp->SetColor(float(aLabelColor.red())/255.,
720 float(aLabelColor.green())/255.,
721 float(aLabelColor.blue())/255.);
722 (isLabelBold)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
723 (isLabelItalic)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
724 (isLabelShadow)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
726 aScalarBarActor->Modified();
728 VISU::GetViewWindow()->AddActor(myPreviewActor);
732 /*! Deleting preview scalar bar
734 void VisuGUI_ScalarBarPane::deleteScalarBar()
736 if ( myBusy ) return;
738 if (myPreviewActor == 0) return;
739 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()){
740 vf->RemoveActor(myPreviewActor);
741 myPreviewActor->GetScalarBar()->VisibilityOff();
743 myPreviewActor->Delete();
746 /*! public: Deleting preview scalar bar
748 void VisuGUI_ScalarBarPane::deletePreview()
753 * Store values to presentation object
755 int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
756 thePrs->SetScalarMode(myModeCombo->currentItem());
757 thePrs->SetPosition(XSpin->value(), YSpin->value());
758 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
759 thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
761 thePrs->SetScaling(VISU::LOGARITHMIC);
763 thePrs->SetScaling(VISU::LINEAR);
765 if (RBFrange->isChecked()) {
766 thePrs->SetSourceRange();
768 thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
770 thePrs->SetNbColors(ColorSpin->value());
771 thePrs->SetLabels(LabelSpin->value());
773 if (isToSave()) storeToResources();
775 if (myIsStoreTextProp) {
777 thePrs->SetTitle(myTextDlg->getTitleText().latin1());
779 QColor aTitColor (255, 255, 255);
780 int aTitleFontFamily = VTK_ARIAL;
781 bool isTitleBold = false;
782 bool isTitleItalic = false;
783 bool isTitleShadow = false;
785 myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
786 isTitleBold, isTitleItalic, isTitleShadow);
788 thePrs->SetBoldTitle(isTitleBold);
789 thePrs->SetItalicTitle(isTitleItalic);
790 thePrs->SetShadowTitle(isTitleShadow);
791 thePrs->SetTitFontType(aTitleFontFamily);
792 thePrs->SetTitleColor(aTitColor.red()/255.,
793 aTitColor.green()/255.,
794 aTitColor.blue()/255.);
797 QColor aLblColor (255, 255, 255);
798 int aLabelFontFamily = VTK_ARIAL;
799 bool isLabelBold = false;
800 bool isLabelItalic = false;
801 bool isLabelShadow = false;
803 myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
804 isLabelBold, isLabelItalic, isLabelShadow);
806 thePrs->SetBoldLabel(isLabelBold);
807 thePrs->SetItalicLabel(isLabelItalic);
808 thePrs->SetShadowLabel(isLabelShadow);
809 thePrs->SetLblFontType(aLabelFontFamily);
810 thePrs->SetLabelColor(aLblColor.red()/255.,
811 aLblColor.green()/255.,
812 aLblColor.blue()/255.);
819 Called when orientation is changed
821 void VisuGUI_ScalarBarPane::changeDefaults( int )
823 if ( RBvert->isChecked() ) {
824 XSpin->setValue( myVerX );
825 YSpin->setValue( myVerY );
826 WidthSpin->setValue( myVerW );
827 HeightSpin->setValue( myVerH );
830 XSpin->setValue( myHorX );
831 YSpin->setValue( myHorY );
832 WidthSpin->setValue( myHorW );
833 HeightSpin->setValue( myHorH );
839 Called when Range mode is changed
841 void VisuGUI_ScalarBarPane::changeRange( int )
844 if ( RBFrange->isChecked() )
846 if ( RBIrange->isChecked() )
848 if ( myRangeMode == mode )
850 //MinSpin->setMaxValue( Fmin );
851 //MaxSpin->setMinValue( Fmax );
852 if ( RBFrange->isChecked() ) {
853 //MinLabel->setEnabled( false );
854 MinEdit->setEnabled( false );
855 //MaxLabel->setEnabled( false );
856 MaxEdit->setEnabled( false );
858 Imin = MinEdit->text().toDouble();
859 Imax = MaxEdit->text().toDouble();
861 MinEdit->setText( QString::number( Rmin ) );
862 MaxEdit->setText( QString::number( Rmax ) );
865 //MinLabel->setEnabled( true );
866 MinEdit->setEnabled( true );
867 //MaxLabel->setEnabled( true );
868 MaxEdit->setEnabled( true );
869 MinEdit->setText( QString::number( Imin ) );
870 MaxEdit->setText( QString::number( Imax ) );
877 Called when X,Y position is changed
879 void VisuGUI_ScalarBarPane::XYChanged( double )
881 QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
882 if ( snd == XSpin ) {
883 WidthSpin->setMaxValue( 1.0 - XSpin->value() );
885 if ( snd == YSpin ) {
886 HeightSpin->setMaxValue( 1.0 - YSpin->value() );
892 Called when scalar mode is changed
894 void VisuGUI_ScalarBarPane::changeScalarMode( int theMode )
897 if ( RBFrange->isChecked() ) {
899 myScalarMap->SetScalarMode(theMode);
900 myScalarMap->GetScalarMapPL()->GetSourceRange(aRange);
901 MinEdit->setText( QString::number( aRange[0] ) );
902 MaxEdit->setText( QString::number( aRange[1] ) );
908 Sets default values and range mode
910 void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, double fmax*/, bool sbRange )
912 Imin = imin; Imax = imax;// Fmin = fmin; Fmax = fmax;
913 if ( RBIrange->isChecked() ) {
914 MinEdit->setText( QString::number( Imin ) );
915 MaxEdit->setText( QString::number( Imax ) );
918 MinEdit->setText( QString::number( Rmin ) );
919 MaxEdit->setText( QString::number( Rmax ) );
923 RBIrange->setChecked( true );
925 RBFrange->setChecked( true );
930 Sets default values and range mode
932 void VisuGUI_ScalarBarPane::setDefaultRange(double imin, double imax){
938 Sets size and position
940 void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
947 RBvert->setChecked( true );
954 RBhori->setChecked( true );
960 Sets colors and labels number
962 void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels )
964 ColorSpin->setValue( colors );
965 LabelSpin->setValue( labels );
971 int VisuGUI_ScalarBarPane::getOrientation()
973 if (RBvert->isChecked() )
980 Called when <OK> button is clicked, validates data and closes dialog
982 bool VisuGUI_ScalarBarPane::check()
984 double minVal = MinEdit->text().toDouble();
985 double maxVal = MaxEdit->text().toDouble();
986 if ( RBIrange->isChecked() ) {
987 if (minVal >= maxVal) {
988 SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
989 tr("MSG_MINMAX_VALUES"),
994 // check if logarithmic mode is on and check imposed range to not contain negative values
995 if ( CBLog->isChecked() ) {
996 if ( RBIrange->isChecked() ) {
997 if ( (minVal > 0) && (maxVal > 0) ) {
1001 SUIT_MessageBox::warn1( this,
1003 tr("WRN_LOGARITHMIC_RANGE"),
1009 if ( Rmin > 0 && Rmax > 0 ) {
1013 SUIT_MessageBox::warn1( this,
1015 tr("WRN_LOGARITHMIC_FIELD_RANGE"),
1017 RBIrange->setChecked(1);
1019 //MinEdit->setText( QString::number( Rmin ) );
1020 //MaxEdit->setText( QString::number( Rmax ) );
1028 void VisuGUI_ScalarBarPane::onTextPref()
1030 myIsStoreTextProp = myTextDlg->exec();
1034 void VisuGUI_ScalarBarPane::onPreviewCheck (bool thePreview)
1036 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
1046 //#######################################################################################
1051 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool SetPref)
1052 : QDialog(VISU::GetDesktop(theModule), 0, true,
1053 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
1055 setName("VisuGUI_ScalarBarDlg");
1056 setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE"));
1057 setSizeGripEnabled(TRUE);
1059 QVBoxLayout* TopLayout = new QVBoxLayout(this);
1060 TopLayout->setSpacing(6);
1061 TopLayout->setMargin(11);
1063 myScalarPane = new VisuGUI_ScalarBarPane(this, SetPref);
1064 TopLayout->addWidget(myScalarPane);
1066 // Common buttons ===========================================================
1067 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1068 GroupButtons->setColumnLayout(0, Qt::Vertical );
1069 GroupButtons->layout()->setSpacing( 0 );
1070 GroupButtons->layout()->setMargin( 0 );
1071 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1072 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1073 GroupButtonsLayout->setSpacing( 6 );
1074 GroupButtonsLayout->setMargin( 11 );
1076 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1077 buttonOk->setAutoDefault( TRUE );
1078 buttonOk->setDefault( TRUE );
1079 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1080 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1082 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1083 buttonCancel->setAutoDefault( TRUE );
1084 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1086 TopLayout->addWidget( GroupButtons );
1088 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
1089 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
1093 Called when <OK> button is clicked, validates data and closes dialog
1095 void VisuGUI_ScalarBarDlg::accept()
1097 if (myScalarPane->check())
1099 myScalarPane->deletePreview();
1105 Called when <Cancel> button is clicked, remove preview and closes dialog
1107 void VisuGUI_ScalarBarDlg::reject()
1109 myScalarPane->deletePreview();
1114 //#######################################################################################
1115 VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
1116 : QDialog(parent, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
1118 setName("VisuGUI_TextPrefDlg");
1119 setCaption(tr("TIT_TEXT_PREF"));
1120 setSizeGripEnabled(TRUE);
1122 QVBoxLayout* TopLayout = new QVBoxLayout(this);
1123 TopLayout->setSpacing(6);
1124 TopLayout->setMargin(11);
1127 QGroupBox* aTitleGrp = new QGroupBox (2, Qt::Vertical, tr("LBL_TITLE"), this);
1130 myTitleEdt = new QLineEdit (aTitleGrp);
1133 QHBox* aHBox = new QHBox (aTitleGrp);
1134 aHBox->setSpacing(5);
1135 myTitleFont = new SVTK_FontWidget (aHBox);
1137 TopLayout->addWidget(aTitleGrp);
1140 QGroupBox* aLabelsGrp = new QGroupBox (1, Qt::Vertical, tr("LBL_LABELS"), this);
1143 aHBox = new QHBox (aLabelsGrp);
1144 aHBox->setSpacing(5);
1145 myLabelFont = new SVTK_FontWidget (aHBox);
1147 TopLayout->addWidget(aLabelsGrp);
1149 // Common buttons ===========================================================
1150 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1151 GroupButtons->setColumnLayout(0, Qt::Vertical );
1152 GroupButtons->layout()->setSpacing( 0 );
1153 GroupButtons->layout()->setMargin( 0 );
1154 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1155 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1156 GroupButtonsLayout->setSpacing( 6 );
1157 GroupButtonsLayout->setMargin( 11 );
1159 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1160 buttonOk->setAutoDefault( TRUE );
1161 buttonOk->setDefault( TRUE );
1162 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1163 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1165 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1166 buttonCancel->setAutoDefault( TRUE );
1167 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1169 TopLayout->addWidget( GroupButtons );
1171 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
1172 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));