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_ViewTools.h"
35 #include "SVTK_ViewWindow.h"
36 #include "SVTK_FontWidget.h"
38 #include "VISUConfig.hh"
39 #include "VISU_Convertor.hxx"
41 #include "VISU_ScalarMapPL.hxx"
42 #include "VISU_ScalarMap_i.hh"
43 #include "VISU_ScalarMapAct.h"
45 #include "SalomeApp_Application.h"
47 #include "SUIT_MessageBox.h"
48 #include "SUIT_ResourceMgr.h"
52 #include <qvalidator.h>
53 #include <qcolordialog.h>
55 #include <vtkTextProperty.h>
60 VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref):
61 QVBox(parent), myPreviewActor(0)
63 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
65 propertyName = QString("scalar_bar_vertical_");
66 myVerX = aResourceMgr->doubleValue("VISU", propertyName + "x", myVerX);
67 myVerY = aResourceMgr->doubleValue("VISU", propertyName + "y", myVerY);
68 myVerW = aResourceMgr->doubleValue("VISU", propertyName + "width", myVerW);
69 myVerH = aResourceMgr->doubleValue("VISU", propertyName + "height",myVerH);
71 propertyName = QString("scalar_bar_horizontal_");
72 myHorX = aResourceMgr->doubleValue("VISU", propertyName + "x", myHorX);
73 myHorY = aResourceMgr->doubleValue("VISU", propertyName + "y", myHorY);
74 myHorW = aResourceMgr->doubleValue("VISU", propertyName + "width", myHorW);
75 myHorH = aResourceMgr->doubleValue("VISU", propertyName + "height",myHorH);
77 Imin = 0.0; Imax = 0.0; /*Fmin = 0.0; Fmax = 0.0;*/ Rmin = 0.0; Rmax = 0.0;
83 // Range ============================================================
84 RangeGroup = new QButtonGroup (tr("SCALAR_RANGE_GRP"), this, "RangeGroup");
85 RangeGroup->setColumnLayout(0, Qt::Vertical );
86 RangeGroup->layout()->setSpacing( 0 );
87 RangeGroup->layout()->setMargin( 0 );
88 QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() );
89 RangeGroupLayout->setAlignment( Qt::AlignTop );
90 RangeGroupLayout->setSpacing( 6 );
91 RangeGroupLayout->setMargin( 11 );
93 myModeLbl = new QLabel("Scalar Mode", RangeGroup);
95 myModeCombo = new QComboBox(RangeGroup);
97 CBLog = new QCheckBox (tr("LOGARITHMIC_SCALING"), RangeGroup);
98 CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
100 RBFrange = new QRadioButton (tr("FIELD_RANGE_BTN"), RangeGroup, "RBFrange");
101 RBIrange = new QRadioButton (tr("IMPOSED_RANGE_BTN"), RangeGroup, "RBIrange");
102 RBFrange->setChecked( true );
104 MinEdit = new QLineEdit( RangeGroup, "MinEdit" );
105 MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
106 MinEdit->setMinimumWidth( 70 );
107 MinEdit->setValidator( new QDoubleValidator(this) );
108 MinEdit->setText( "0.0" );
109 QLabel* MinLabel = new QLabel (tr("LBL_MIN"), RangeGroup, "MinLabel");
110 MinLabel->setBuddy(MinEdit);
112 MaxEdit = new QLineEdit( RangeGroup, "MaxEdit" );
113 MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
114 MaxEdit->setMinimumWidth( 70 );
115 MaxEdit->setValidator( new QDoubleValidator(this) );
116 MaxEdit->setText( "0.0" );
117 QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), RangeGroup, "MaxLabel");
118 MaxLabel->setBuddy(MaxEdit);
120 RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
121 RangeGroupLayout->addMultiCellWidget( myModeCombo, 0, 0, 1, 3);
122 RangeGroupLayout->addMultiCellWidget( CBLog, 1, 1, 0, 3);
123 RangeGroupLayout->addMultiCellWidget( RBFrange, 2, 2, 0, 1);
124 RangeGroupLayout->addMultiCellWidget( RBIrange, 2, 2, 2, 3);
125 RangeGroupLayout->addWidget( MinLabel, 3, 0 );
126 RangeGroupLayout->addWidget( MinEdit, 3, 1 );
127 RangeGroupLayout->addWidget( MaxLabel, 3, 2 );
128 RangeGroupLayout->addWidget( MaxEdit, 3, 3 );
130 //TopLayout->addWidget( RangeGroup );
132 // Colors and Labels ========================================================
133 QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this, "ColLabGroup");
134 ColLabGroup->setColumnLayout(0, Qt::Vertical );
135 ColLabGroup->layout()->setSpacing( 0 );
136 ColLabGroup->layout()->setMargin( 0 );
137 QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() );
138 ColLabGroupLayout->setAlignment( Qt::AlignTop );
139 ColLabGroupLayout->setSpacing( 6 );
140 ColLabGroupLayout->setMargin( 11 );
142 QLabel* ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup, "ColorLabel");
143 ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup );
144 ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
145 ColorSpin->setMinimumWidth( 70 );
146 ColorSpin->setValue( 64 );
148 QLabel* LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup, "LabelLabel");
149 LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup );
150 LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
151 LabelSpin->setMinimumWidth( 70 );
152 LabelSpin->setValue( 5 );
154 ColLabGroupLayout->addWidget( ColorLabel, 0, 0);
155 ColLabGroupLayout->addWidget( ColorSpin, 0, 1);
156 ColLabGroupLayout->addWidget( LabelLabel, 0, 2);
157 ColLabGroupLayout->addWidget( LabelSpin, 0, 3);
159 //TopLayout->addWidget( ColLabGroup );
161 // Orientation ==========================================================
162 QButtonGroup* OrientGroup = new QButtonGroup (tr("ORIENTATION_GRP"), this, "OrientGroup");
163 OrientGroup->setColumnLayout(0, Qt::Vertical );
164 OrientGroup->layout()->setSpacing( 0 );
165 OrientGroup->layout()->setMargin( 0 );
166 QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() );
167 OrientGroupLayout->setAlignment( Qt::AlignTop );
168 OrientGroupLayout->setSpacing( 6 );
169 OrientGroupLayout->setMargin( 11 );
171 RBvert = new QRadioButton (tr("VERTICAL_BTN"), OrientGroup, "RBvert");
172 RBvert->setChecked( true );
173 RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), OrientGroup, "RBhori");
174 OrientGroupLayout->addWidget( RBvert, 0, 0 );
175 OrientGroupLayout->addWidget( RBhori, 0, 1 );
177 // TopLayout->addWidget( OrientGroup );
179 // Origin ===============================================================
180 QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this, "OriginGroup");
181 OriginGroup->setColumnLayout(0, Qt::Vertical );
182 OriginGroup->layout()->setSpacing( 0 );
183 OriginGroup->layout()->setMargin( 0 );
184 QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() );
185 OriginGroupLayout->setAlignment( Qt::AlignTop );
186 OriginGroupLayout->setSpacing( 6 );
187 OriginGroupLayout->setMargin( 11 );
189 QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup, "XLabel");
190 XSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
191 XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
192 XSpin->setMinimumWidth( 70 );
193 XSpin->setValue( 0.01 );
195 QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup, "YLabel");
196 YSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
197 YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
198 YSpin->setMinimumWidth( 70 );
199 YSpin->setValue( 0.01 );
201 OriginGroupLayout->addWidget( XLabel, 0, 0);
202 OriginGroupLayout->addWidget( XSpin, 0, 1);
203 OriginGroupLayout->addWidget( YLabel, 0, 2);
204 OriginGroupLayout->addWidget( YSpin, 0, 3);
206 //TopLayout->addWidget( OriginGroup );
208 // Dimensions =========================================================
209 QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this, "DimGroup");
210 DimGroup->setColumnLayout(0, Qt::Vertical );
211 DimGroup->layout()->setSpacing( 0 );
212 DimGroup->layout()->setMargin( 0 );
213 QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() );
214 DimGroupLayout->setAlignment( Qt::AlignTop );
215 DimGroupLayout->setSpacing( 6 );
216 DimGroupLayout->setMargin( 11 );
218 QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup, "WidthLabel");
219 WidthSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
220 WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
221 WidthSpin->setMinimumWidth( 70 );
222 WidthSpin->setValue( 0.1 );
224 QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup, "HeightLabel");
225 HeightSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
226 HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
227 HeightSpin->setMinimumWidth( 70 );
228 HeightSpin->setValue( 0.8 );
230 DimGroupLayout->addWidget( WidthLabel, 0, 0);
231 DimGroupLayout->addWidget( WidthSpin, 0, 1);
232 DimGroupLayout->addWidget( HeightLabel, 0, 2);
233 DimGroupLayout->addWidget( HeightSpin, 0, 3);
235 //TopLayout->addWidget( DimGroup );
237 // Save check box ===========================================================
238 QHBox* aSaveBox = new QHBox(this);
240 CBSave = new QCheckBox (tr("SAVE_DEFAULT_CHK"), aSaveBox, "CBSave");
241 //TopLayout->addWidget(CBSave);
246 myTextBtn = new QPushButton("Text properties...", aSaveBox);
247 myTextDlg = new VisuGUI_TextPrefDlg(this);
248 myTextDlg->setTitleVisible(!SetPref);
250 QGroupBox* CheckGroup = new QGroupBox("", this, "CheckGroup");
251 CheckGroup->setColumnLayout(0, Qt::Vertical );
252 CheckGroup->layout()->setSpacing( 0 );
253 CheckGroup->layout()->setMargin( 0 );
254 QGridLayout* CheckGroupLayout = new QGridLayout( CheckGroup->layout() );
256 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), CheckGroup);
257 myPreviewCheck->setChecked(false);
258 CheckGroupLayout->addWidget(myPreviewCheck , 0, 0 );
260 // signals and slots connections ===========================================
261 connect( RangeGroup, SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) );
262 connect( myModeCombo, SIGNAL( activated( int ) ), this, SLOT( changeScalarMode( int ) ) );
263 connect( OrientGroup, SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) );
264 connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
265 connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
266 connect( myTextBtn, SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
267 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
268 connect( ColorSpin, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ));
269 connect( LabelSpin, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ));
270 connect( WidthSpin, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ));
271 connect( HeightSpin, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ));
272 connect( CBLog, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ));
275 myIsStoreTextProp = false;
280 * Initializes dialog box values from resources
282 void VisuGUI_ScalarBarPane::initFromResources() {
283 int sbCol=64,sbLab=5,orient=0;
284 float sbX1=0.01,sbY1=0.1,sbW=0.1,sbH=0.8;
285 float sbVmin=0., sbVmax=0.;
289 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
291 bool anIsArrangeBar = aResourceMgr->booleanValue("VISU", "scalar_bars_default_position", 0);
294 aPlace = aResourceMgr->integerValue("VISU", "scalar_bar_position_num",0);
297 int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
298 myModeCombo->setCurrentItem(aScalarMode);
300 orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", orient);
309 QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
311 sbX1 = aResourceMgr->doubleValue("VISU", propertyName + "x", sbX1);
312 sbY1 = aResourceMgr->doubleValue("VISU", propertyName + "y", sbY1);
314 sbW = aResourceMgr->doubleValue("VISU", propertyName + "width", sbW);
315 sbH = aResourceMgr->doubleValue("VISU", propertyName + "height",sbH);
318 sbY1 += sbH*(aPlace-1);
320 sbX1 += sbW*(aPlace-1);
322 sbCol = aResourceMgr->integerValue("VISU" ,"scalar_bar_num_colors", sbCol);
323 sbLab = aResourceMgr->integerValue("VISU", "scalar_bar_num_labels", sbLab);
325 int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0);
326 if (rangeType == 1) sbRange = true;
327 sbVmin = aResourceMgr->doubleValue("VISU", "scalar_range_min", sbVmin);
328 sbVmax = aResourceMgr->doubleValue("VISU", "scalar_range_max", sbVmax);
330 bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false);
331 setLogarithmic(isLog);
333 if((sbX1 < 0.) || (sbY1 < 0.) ||
334 ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
347 if(sbCol < 2) sbCol=2;
348 if(sbCol > 64) sbCol=64;
349 if(sbLab < 2) sbLab=2;
350 if(sbLab > 65) sbLab=65;
352 if(sbVmin > sbVmax) {
357 setRange( sbVmin, sbVmax, /*0.0, 0.0,*/ sbRange );
358 setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 0);
359 setScalarBarData( sbCol, sbLab );
362 bool isBold = false, isItalic = false, isShadow = false;
363 int aFontFamily = VTK_ARIAL;
365 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) )
367 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" );
369 if ( f.family() == "Arial" )
370 aFontFamily = VTK_ARIAL;
371 else if ( f.family() == "Courier" )
372 aFontFamily = VTK_COURIER;
373 else if ( f.family() == "Times" )
374 aFontFamily = VTK_TIMES;
377 isItalic = f.italic();
378 isShadow = f.underline();
381 QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
383 myTextDlg->myTitleFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
386 isBold = isItalic = isShadow = false;
387 aFontFamily = VTK_ARIAL;
389 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) )
391 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" );
393 if ( f.family() == "Arial" )
394 aFontFamily = VTK_ARIAL;
395 else if ( f.family() == "Courier" )
396 aFontFamily = VTK_COURIER;
397 else if ( f.family() == "Times" )
398 aFontFamily = VTK_TIMES;
401 isItalic = f.italic();
402 isShadow = f.underline();
405 aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
407 myTextDlg->myLabelFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
411 * Stores dialog values to resources
413 void VisuGUI_ScalarBarPane::storeToResources() {
414 int orient = (RBvert->isChecked())? 0 : 1;
415 float sbX1 = XSpin->value();
416 float sbY1 = YSpin->value();
417 float sbW = WidthSpin->value();
418 float sbH = HeightSpin->value();
419 int sbCol = ColorSpin->value();
420 int sbLab = LabelSpin->value();
422 if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
436 bool sbRange = RBIrange->isChecked();
437 float sbVmin = (float)(MinEdit->text().toDouble());
438 float sbVmax = (float)(MaxEdit->text().toDouble());
440 if(sbVmin > sbVmax) {
445 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
447 aResourceMgr->setValue("VISU", "scalar_bar_orientation", orient);
449 QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
451 aResourceMgr->setValue("VISU", propertyName + "x", sbX1);
452 aResourceMgr->setValue("VISU", propertyName + "y", sbY1);
453 aResourceMgr->setValue("VISU", propertyName + "width", sbW);
454 aResourceMgr->setValue("VISU", propertyName + "height", sbH);
456 aResourceMgr->setValue("VISU", "scalar_bar_num_colors", sbCol);
457 aResourceMgr->setValue("VISU", "scalar_bar_num_labels", sbLab);
461 aResourceMgr->setValue("VISU", "scalar_range_type", 1);
462 aResourceMgr->setValue("VISU", "scalar_range_min" ,sbVmin);
463 aResourceMgr->setValue("VISU", "scalar_range_max" ,sbVmax);
466 aResourceMgr->setValue("VISU", "scalar_range_type", 0);
468 aResourceMgr->setValue("VISU", "scalar_bar_logarithmic", isLogarithmic());
472 if (myIsStoreTextProp) {
474 QColor aTitleColor (255, 255, 255);
475 int aTitleFontFamily = VTK_ARIAL;
476 bool isTitleBold = false;
477 bool isTitleItalic = false;
478 bool isTitleShadow = false;
480 myTextDlg->myTitleFont->GetData(aTitleColor, aTitleFontFamily,
481 isTitleBold, isTitleItalic, isTitleShadow);
485 aTitleFont.setBold(isTitleBold);
486 aTitleFont.setItalic(isTitleItalic);
487 aTitleFont.setUnderline(isTitleShadow);
489 QString titleFontFamily;
490 switch (aTitleFontFamily) {
492 titleFontFamily = "Arial";
495 titleFontFamily = "Courier";
498 titleFontFamily = "Times";
501 aTitleFont.setFamily(titleFontFamily);
503 aResourceMgr->setValue("VISU", "scalar_bar_title_font", aTitleFont);
505 aResourceMgr->setValue("VISU", "scalar_bar_title_color", aTitleColor);
508 QColor aLabelColor (255, 255, 255);
509 int aLabelFontFamily = VTK_ARIAL;
510 bool isLabelBold = false;
511 bool isLabelItalic = false;
512 bool isLabelShadow = false;
514 myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
515 isLabelBold, isLabelItalic, isLabelShadow);
520 aLabelFont.setBold(isLabelBold);
521 aLabelFont.setItalic(isLabelItalic);
522 aLabelFont.setUnderline(isLabelShadow);
524 QString labelFontFamily;
525 switch (aLabelFontFamily) {
527 labelFontFamily = "Arial";
530 labelFontFamily = "Courier";
533 labelFontFamily = "Times";
537 aLabelFont.setFamily(labelFontFamily);
539 aResourceMgr->setValue("VISU", "scalar_bar_label_font", aLabelFont);
541 aResourceMgr->setValue("VISU", "scalar_bar_label_color", aLabelColor);
546 * Initialise dialog box from presentation object
548 void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
550 myScalarMap = thePrs;
551 setPosAndSize( thePrs->GetPosX(),
555 thePrs->GetBarOrientation());
556 switch(thePrs->GetScaling()){
557 case VISU::LOGARITHMIC :
558 setLogarithmic(true);
561 setLogarithmic(false);
564 thePrs->GetScalarMapPL()->GetSourceRange(aRange);
565 Rmin = aRange[0]; Rmax = aRange[1];
566 setRange( thePrs->GetMin(), thePrs->GetMax(),
567 /*0.0, 0.0,*/ thePrs->IsRangeFixed() );
568 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
570 // Update myModeCombo
571 int aNbComp = thePrs->GetField()->myNbComp;
572 bool isScalarMode = (aNbComp > 1);
573 myModeCombo->clear();
574 myModeCombo->insertItem("<Modulus>");
575 const VISU::PField& aField = thePrs->GetField();
576 const VISU::TNames& aCompNames = aField->myCompNames;
577 const VISU::TNames& aUnitNames = aField->myUnitNames;
578 for(int i = 0; i < aNbComp; i++){
579 QString aComponent = QString(aCompNames[i]).simplifyWhiteSpace();
580 if(aComponent.isNull() || aComponent == "")
581 aComponent = "Component " + QString::number(i+1);
583 aComponent = "[" + QString::number(i+1) + "] " + aComponent;
585 QString anUnit = QString(aUnitNames[i]).simplifyWhiteSpace();
586 if(anUnit.isNull() || anUnit == "")
589 aComponent = aComponent + ", " + anUnit;
591 myModeCombo->insertItem(aComponent);
594 myModeCombo->setCurrentItem(thePrs->GetScalarMode());
596 myModeCombo->setCurrentItem(1);
599 myModeLbl->setEnabled(isScalarMode);
600 myModeCombo->setEnabled(isScalarMode);
603 myTextDlg->setTitleText(QString(thePrs->GetTitle()));
606 thePrs->GetTitleColor(&R, &G, &B);
608 myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
609 thePrs->GetTitFontType(),
610 thePrs->IsBoldTitle(),
611 thePrs->IsItalicTitle(),
612 thePrs->IsShadowTitle());
615 thePrs->GetLabelColor(&R, &G, &B);
617 myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
618 thePrs->GetLblFontType(),
619 thePrs->IsBoldLabel(),
620 thePrs->IsItalicLabel(),
621 thePrs->IsShadowLabel());
624 if (myPreviewCheck->isChecked()) {
630 /*! Slot update preview of scalar bar, if preview is checked
632 void VisuGUI_ScalarBarPane::updatePreview()
634 if (myPreviewCheck->isChecked()) {
635 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
643 /*! Creating preview scalar bar
645 void VisuGUI_ScalarBarPane::createScalarBar()
647 if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
648 if (myPreviewActor != 0) return;
649 if (myScalarMap == NULL) return;
651 if (!check()) return;
653 if ( myBusy ) return;
658 sbCol = getNbColors();
659 sbLab = getNbLabels();
660 if(sbCol < 2) sbCol=2;
661 if(sbCol > 64) sbCol=64;
662 if(sbLab < 2) sbLab=2;
663 if(sbLab > 65) sbLab=65;
664 myPreviewActor = VISU_ScalarMapAct::New();
665 VISU_ScalarBarActor* aScalarBarActor = myPreviewActor->GetScalarBar();
666 myPreviewActor->GetScalarBar()->VisibilityOn();
667 myPreviewActor->PickableOff();
669 myScalarMap->SetScalarMode(myModeCombo->currentItem());
670 myScalarMap->SetPosition(getX(),getY());
671 myScalarMap->SetSize(getWidth(),getHeight());
672 myScalarMap->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
674 myScalarMap->SetScaling(VISU::LOGARITHMIC);
676 myScalarMap->SetScaling(VISU::LINEAR);
677 if (RBFrange->isChecked()) {
678 myScalarMap->SetSourceRange();
680 myScalarMap->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
682 myScalarMap->SetNbColors(sbCol);
683 myScalarMap->SetLabels(sbLab);
685 myScalarMap->GetScalarMapPL()->SetNbColors(sbCol);
686 myScalarMap->GetScalarMapPL()->Update();
688 aScalarBarActor->SetLookupTable(myScalarMap->GetScalarMapPL()->GetBarTable());
690 if (myTextDlg->getTitleText().latin1() != "")
691 aScalarBarActor->SetTitle(myTextDlg->getTitleText().latin1());
693 aScalarBarActor->SetTitle(myScalarMap->GetTitle());
694 aScalarBarActor->SetOrientation(getOrientation());
695 aScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
696 aScalarBarActor->GetPositionCoordinate()->SetValue(getX(),getY());
697 aScalarBarActor->SetWidth(getWidth());
698 aScalarBarActor->SetHeight(getHeight());
699 aScalarBarActor->SetNumberOfLabels(sbLab);
700 aScalarBarActor->SetMaximumNumberOfColors(sbCol);
702 // title text property
704 int aTitleFontFamily;
708 myTextDlg->myTitleFont->GetData(aTitleColor,aTitleFontFamily,
709 isTitleBold,isTitleItalic,isTitleShadow);
710 vtkTextProperty* aTitleProp = aScalarBarActor->GetTitleTextProperty();
711 aTitleProp->SetFontFamily(aTitleFontFamily);
712 aTitleProp->SetColor(float(aTitleColor.red())/255.,
713 float(aTitleColor.green())/255.,
714 float(aTitleColor.blue())/255.);
715 (isTitleBold)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
716 (isTitleItalic)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
717 (isTitleShadow)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
719 // label text property
721 int aLabelFontFamily;
725 myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
726 isLabelBold, isLabelItalic, isLabelShadow);
727 vtkTextProperty* aLabelProp = aScalarBarActor->GetLabelTextProperty();
728 aLabelProp->SetFontFamily(aLabelFontFamily);
729 aLabelProp->SetColor(float(aLabelColor.red())/255.,
730 float(aLabelColor.green())/255.,
731 float(aLabelColor.blue())/255.);
732 (isLabelBold)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
733 (isLabelItalic)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
734 (isLabelShadow)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
736 aScalarBarActor->Modified();
738 VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
742 /*! Deleting preview scalar bar
744 void VisuGUI_ScalarBarPane::deleteScalarBar()
746 if ( myBusy ) return;
748 if (myPreviewActor == 0) return;
749 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()){
750 vf->RemoveActor(myPreviewActor);
751 myPreviewActor->GetScalarBar()->VisibilityOff();
753 myPreviewActor->Delete();
756 /*! public: Deleting preview scalar bar
758 void VisuGUI_ScalarBarPane::deletePreview()
763 * Store values to presentation object
765 int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
766 thePrs->SetScalarMode(myModeCombo->currentItem());
767 thePrs->SetPosition(XSpin->value(), YSpin->value());
768 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
769 thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
771 thePrs->SetScaling(VISU::LOGARITHMIC);
773 thePrs->SetScaling(VISU::LINEAR);
775 if (RBFrange->isChecked()) {
776 thePrs->SetSourceRange();
778 thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
780 thePrs->SetNbColors(ColorSpin->value());
781 thePrs->SetLabels(LabelSpin->value());
783 if (isToSave()) storeToResources();
785 if (myIsStoreTextProp) {
787 thePrs->SetTitle(myTextDlg->getTitleText().latin1());
789 QColor aTitColor (255, 255, 255);
790 int aTitleFontFamily = VTK_ARIAL;
791 bool isTitleBold = false;
792 bool isTitleItalic = false;
793 bool isTitleShadow = false;
795 myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
796 isTitleBold, isTitleItalic, isTitleShadow);
798 thePrs->SetBoldTitle(isTitleBold);
799 thePrs->SetItalicTitle(isTitleItalic);
800 thePrs->SetShadowTitle(isTitleShadow);
801 thePrs->SetTitFontType(aTitleFontFamily);
802 thePrs->SetTitleColor(aTitColor.red()/255.,
803 aTitColor.green()/255.,
804 aTitColor.blue()/255.);
807 QColor aLblColor (255, 255, 255);
808 int aLabelFontFamily = VTK_ARIAL;
809 bool isLabelBold = false;
810 bool isLabelItalic = false;
811 bool isLabelShadow = false;
813 myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
814 isLabelBold, isLabelItalic, isLabelShadow);
816 thePrs->SetBoldLabel(isLabelBold);
817 thePrs->SetItalicLabel(isLabelItalic);
818 thePrs->SetShadowLabel(isLabelShadow);
819 thePrs->SetLblFontType(aLabelFontFamily);
820 thePrs->SetLabelColor(aLblColor.red()/255.,
821 aLblColor.green()/255.,
822 aLblColor.blue()/255.);
829 Called when orientation is changed
831 void VisuGUI_ScalarBarPane::changeDefaults( int )
833 if ( RBvert->isChecked() ) {
834 XSpin->setValue( myVerX );
835 YSpin->setValue( myVerY );
836 WidthSpin->setValue( myVerW );
837 HeightSpin->setValue( myVerH );
840 XSpin->setValue( myHorX );
841 YSpin->setValue( myHorY );
842 WidthSpin->setValue( myHorW );
843 HeightSpin->setValue( myHorH );
849 Called when Range mode is changed
851 void VisuGUI_ScalarBarPane::changeRange( int )
854 if ( RBFrange->isChecked() )
856 if ( RBIrange->isChecked() )
858 if ( myRangeMode == mode )
860 //MinSpin->setMaxValue( Fmin );
861 //MaxSpin->setMinValue( Fmax );
862 if ( RBFrange->isChecked() ) {
863 //MinLabel->setEnabled( false );
864 MinEdit->setEnabled( false );
865 //MaxLabel->setEnabled( false );
866 MaxEdit->setEnabled( false );
868 Imin = MinEdit->text().toDouble();
869 Imax = MaxEdit->text().toDouble();
871 MinEdit->setText( QString::number( Rmin ) );
872 MaxEdit->setText( QString::number( Rmax ) );
875 //MinLabel->setEnabled( true );
876 MinEdit->setEnabled( true );
877 //MaxLabel->setEnabled( true );
878 MaxEdit->setEnabled( true );
879 MinEdit->setText( QString::number( Imin ) );
880 MaxEdit->setText( QString::number( Imax ) );
887 Called when X,Y position is changed
889 void VisuGUI_ScalarBarPane::XYChanged( double )
891 QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
892 if ( snd == XSpin ) {
893 WidthSpin->setMaxValue( 1.0 - XSpin->value() );
895 if ( snd == YSpin ) {
896 HeightSpin->setMaxValue( 1.0 - YSpin->value() );
902 Called when scalar mode is changed
904 void VisuGUI_ScalarBarPane::changeScalarMode( int theMode )
907 if ( RBFrange->isChecked() ) {
909 myScalarMap->SetScalarMode(theMode);
910 myScalarMap->GetScalarMapPL()->GetSourceRange(aRange);
911 MinEdit->setText( QString::number( aRange[0] ) );
912 MaxEdit->setText( QString::number( aRange[1] ) );
918 Sets default values and range mode
920 void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, double fmax*/, bool sbRange )
922 Imin = imin; Imax = imax;// Fmin = fmin; Fmax = fmax;
923 if ( RBIrange->isChecked() ) {
924 MinEdit->setText( QString::number( Imin ) );
925 MaxEdit->setText( QString::number( Imax ) );
928 MinEdit->setText( QString::number( Rmin ) );
929 MaxEdit->setText( QString::number( Rmax ) );
933 RBIrange->setChecked( true );
935 RBFrange->setChecked( true );
940 Sets default values and range mode
942 void VisuGUI_ScalarBarPane::setDefaultRange(double imin, double imax){
948 Sets size and position
950 void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
957 RBvert->setChecked( true );
964 RBhori->setChecked( true );
970 Sets colors and labels number
972 void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels )
974 ColorSpin->setValue( colors );
975 LabelSpin->setValue( labels );
981 int VisuGUI_ScalarBarPane::getOrientation()
983 if (RBvert->isChecked() )
990 Called when <OK> button is clicked, validates data and closes dialog
992 bool VisuGUI_ScalarBarPane::check()
994 double minVal = MinEdit->text().toDouble();
995 double maxVal = MaxEdit->text().toDouble();
996 if ( RBIrange->isChecked() ) {
997 if (minVal >= maxVal) {
998 SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
999 tr("MSG_MINMAX_VALUES"),
1004 // check if logarithmic mode is on and check imposed range to not contain negative values
1005 if ( CBLog->isChecked() ) {
1006 if ( RBIrange->isChecked() ) {
1007 if ( (minVal > 0) && (maxVal > 0) ) {
1011 SUIT_MessageBox::warn1( this,
1013 tr("WRN_LOGARITHMIC_RANGE"),
1019 if ( Rmin > 0 && Rmax > 0 ) {
1023 SUIT_MessageBox::warn1( this,
1025 tr("WRN_LOGARITHMIC_FIELD_RANGE"),
1027 RBIrange->setChecked(1);
1029 //MinEdit->setText( QString::number( Rmin ) );
1030 //MaxEdit->setText( QString::number( Rmax ) );
1038 void VisuGUI_ScalarBarPane::onTextPref()
1040 myIsStoreTextProp = myTextDlg->exec();
1044 void VisuGUI_ScalarBarPane::onPreviewCheck (bool thePreview)
1046 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
1056 //#######################################################################################
1061 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool SetPref)
1062 : QDialog(VISU::GetDesktop(theModule), 0, true,
1063 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
1065 setName("VisuGUI_ScalarBarDlg");
1066 setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE"));
1067 setSizeGripEnabled(TRUE);
1069 QVBoxLayout* TopLayout = new QVBoxLayout(this);
1070 TopLayout->setSpacing(6);
1071 TopLayout->setMargin(11);
1073 myScalarPane = new VisuGUI_ScalarBarPane(this, SetPref);
1074 TopLayout->addWidget(myScalarPane);
1076 // Common buttons ===========================================================
1077 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1078 GroupButtons->setColumnLayout(0, Qt::Vertical );
1079 GroupButtons->layout()->setSpacing( 0 );
1080 GroupButtons->layout()->setMargin( 0 );
1081 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1082 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1083 GroupButtonsLayout->setSpacing( 6 );
1084 GroupButtonsLayout->setMargin( 11 );
1086 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1087 buttonOk->setAutoDefault( TRUE );
1088 buttonOk->setDefault( TRUE );
1089 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1090 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1092 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1093 buttonCancel->setAutoDefault( TRUE );
1094 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1096 TopLayout->addWidget( GroupButtons );
1098 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
1099 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
1103 Called when <OK> button is clicked, validates data and closes dialog
1105 void VisuGUI_ScalarBarDlg::accept()
1107 if (myScalarPane->check())
1109 myScalarPane->deletePreview();
1115 Called when <Cancel> button is clicked, remove preview and closes dialog
1117 void VisuGUI_ScalarBarDlg::reject()
1119 myScalarPane->deletePreview();
1124 //#######################################################################################
1125 VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
1126 : QDialog(parent, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
1128 setName("VisuGUI_TextPrefDlg");
1129 setCaption(tr("TIT_TEXT_PREF"));
1130 setSizeGripEnabled(TRUE);
1132 QVBoxLayout* TopLayout = new QVBoxLayout(this);
1133 TopLayout->setSpacing(6);
1134 TopLayout->setMargin(11);
1137 QGroupBox* aTitleGrp = new QGroupBox (2, Qt::Vertical, tr("LBL_TITLE"), this);
1140 myTitleEdt = new QLineEdit (aTitleGrp);
1143 QHBox* aHBox = new QHBox (aTitleGrp);
1144 aHBox->setSpacing(5);
1145 myTitleFont = new SVTK_FontWidget (aHBox);
1147 TopLayout->addWidget(aTitleGrp);
1150 QGroupBox* aLabelsGrp = new QGroupBox (1, Qt::Vertical, tr("LBL_LABELS"), this);
1153 aHBox = new QHBox (aLabelsGrp);
1154 aHBox->setSpacing(5);
1155 myLabelFont = new SVTK_FontWidget (aHBox);
1157 TopLayout->addWidget(aLabelsGrp);
1159 // Common buttons ===========================================================
1160 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1161 GroupButtons->setColumnLayout(0, Qt::Vertical );
1162 GroupButtons->layout()->setSpacing( 0 );
1163 GroupButtons->layout()->setMargin( 0 );
1164 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1165 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1166 GroupButtonsLayout->setSpacing( 6 );
1167 GroupButtonsLayout->setMargin( 11 );
1169 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1170 buttonOk->setAutoDefault( TRUE );
1171 buttonOk->setDefault( TRUE );
1172 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1173 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1175 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1176 buttonCancel->setAutoDefault( TRUE );
1177 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1179 TopLayout->addWidget( GroupButtons );
1181 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
1182 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));