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"), CheckGroup);
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( 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 myModeCombo->setCurrentItem(thePrs->GetScalarMode());
542 setPosAndSize( thePrs->GetPosX(),
546 thePrs->GetBarOrientation());
547 switch(thePrs->GetScaling()){
548 case VISU::LOGARITHMIC :
549 setLogarithmic(true);
552 setLogarithmic(false);
555 thePrs->GetScalarMapPL()->GetSourceRange(aRange);
556 Rmin = aRange[0]; Rmax = aRange[1];
557 setRange( thePrs->GetMin(), thePrs->GetMax(),
558 /*0.0, 0.0,*/ thePrs->IsRangeFixed() );
559 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
560 bool isScalarMode = (thePrs->GetField()->myNbComp > 1);
561 myModeLbl->setEnabled(isScalarMode);
562 myModeCombo->setEnabled(isScalarMode);
565 myTextDlg->setTitleText(QString(thePrs->GetTitle()));
568 thePrs->GetTitleColor(&R, &G, &B);
570 myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
571 thePrs->GetTitFontType(),
572 thePrs->IsBoldTitle(),
573 thePrs->IsItalicTitle(),
574 thePrs->IsShadowTitle());
577 thePrs->GetLabelColor(&R, &G, &B);
579 myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
580 thePrs->GetLblFontType(),
581 thePrs->IsBoldLabel(),
582 thePrs->IsItalicLabel(),
583 thePrs->IsShadowLabel());
586 if (myPreviewCheck->isChecked()) {
592 /*! Slot update preview of scalar bar, if preview is checked
594 void VisuGUI_ScalarBarPane::updatePreview()
596 if (myPreviewCheck->isChecked()) {
597 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
605 /*! Creating preview scalar bar
607 void VisuGUI_ScalarBarPane::createScalarBar()
609 if (VISU::GetViewWindow() == NULL) return;
610 if (myPreviewActor != 0) return;
611 if (myScalarMap == NULL) return;
613 if (!check()) return;
615 if ( myBusy ) return;
620 sbCol = getNbColors();
621 sbLab = getNbLabels();
622 if(sbCol < 2) sbCol=2;
623 if(sbCol > 64) sbCol=64;
624 if(sbLab < 2) sbLab=2;
625 if(sbLab > 65) sbLab=65;
626 myPreviewActor = VISU_ScalarMapAct::New();
627 VISU_ScalarBarActor* aScalarBarActor = myPreviewActor->GetScalarBar();
628 myPreviewActor->GetScalarBar()->VisibilityOn();
629 myPreviewActor->PickableOff();
631 myScalarMap->SetScalarMode(myModeCombo->currentItem());
632 myScalarMap->SetPosition(getX(),getY());
633 myScalarMap->SetSize(getWidth(),getHeight());
634 myScalarMap->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
636 myScalarMap->SetScaling(VISU::LOGARITHMIC);
638 myScalarMap->SetScaling(VISU::LINEAR);
639 if (RBFrange->isChecked()) {
640 myScalarMap->SetSourceRange();
642 myScalarMap->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
644 myScalarMap->SetNbColors(sbCol);
645 myScalarMap->SetLabels(sbLab);
647 myScalarMap->GetScalarMapPL()->SetNbColors(sbCol);
648 myScalarMap->GetScalarMapPL()->Update();
650 aScalarBarActor->SetLookupTable(myScalarMap->GetScalarMapPL()->GetBarTable());
652 if (myTextDlg->getTitleText().latin1() != "")
653 aScalarBarActor->SetTitle(myTextDlg->getTitleText().latin1());
655 aScalarBarActor->SetTitle(myScalarMap->GetTitle());
656 aScalarBarActor->SetOrientation(getOrientation());
657 aScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
658 aScalarBarActor->GetPositionCoordinate()->SetValue(getX(),getY());
659 aScalarBarActor->SetWidth(getWidth());
660 aScalarBarActor->SetHeight(getHeight());
661 aScalarBarActor->SetNumberOfLabels(sbLab);
662 aScalarBarActor->SetMaximumNumberOfColors(sbCol);
664 // title text property
666 int aTitleFontFamily;
670 myTextDlg->myTitleFont->GetData(aTitleColor,aTitleFontFamily,
671 isTitleBold,isTitleItalic,isTitleShadow);
672 vtkTextProperty* aTitleProp = aScalarBarActor->GetTitleTextProperty();
673 aTitleProp->SetFontFamily(aTitleFontFamily);
674 aTitleProp->SetColor(float(aTitleColor.red())/255.,
675 float(aTitleColor.green())/255.,
676 float(aTitleColor.blue())/255.);
677 (isTitleBold)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
678 (isTitleItalic)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
679 (isTitleShadow)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
681 // label text property
683 int aLabelFontFamily;
687 myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
688 isLabelBold, isLabelItalic, isLabelShadow);
689 vtkTextProperty* aLabelProp = aScalarBarActor->GetLabelTextProperty();
690 aLabelProp->SetFontFamily(aLabelFontFamily);
691 aLabelProp->SetColor(float(aLabelColor.red())/255.,
692 float(aLabelColor.green())/255.,
693 float(aLabelColor.blue())/255.);
694 (isLabelBold)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
695 (isLabelItalic)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
696 (isLabelShadow)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
698 aScalarBarActor->Modified();
700 VISU::GetViewWindow()->AddActor(myPreviewActor);
704 /*! Deleting preview scalar bar
706 void VisuGUI_ScalarBarPane::deleteScalarBar()
708 if ( myBusy ) return;
710 if (myPreviewActor == 0) return;
711 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
712 vf->RemoveActor(myPreviewActor);
713 myPreviewActor->GetScalarBar()->VisibilityOff();
715 myPreviewActor->Delete();
718 /*! public: Deleting preview scalar bar
720 void VisuGUI_ScalarBarPane::deletePreview()
725 * Store values to presentation object
727 int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs)
729 thePrs->SetScalarMode(myModeCombo->currentItem());
730 thePrs->SetPosition(XSpin->value(), YSpin->value());
731 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
732 thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
734 thePrs->SetScaling(VISU::LOGARITHMIC);
736 thePrs->SetScaling(VISU::LINEAR);
738 if (RBFrange->isChecked()) {
739 thePrs->SetSourceRange();
741 thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
743 thePrs->SetNbColors(ColorSpin->value());
744 thePrs->SetLabels(LabelSpin->value());
746 if (isToSave()) storeToResources();
748 if (myIsStoreTextProp) {
750 thePrs->SetTitle(myTextDlg->getTitleText().latin1());
752 QColor aTitColor (255, 255, 255);
753 int aTitleFontFamily = VTK_ARIAL;
754 bool isTitleBold = false;
755 bool isTitleItalic = false;
756 bool isTitleShadow = false;
758 myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
759 isTitleBold, isTitleItalic, isTitleShadow);
761 thePrs->SetBoldTitle(isTitleBold);
762 thePrs->SetItalicTitle(isTitleItalic);
763 thePrs->SetShadowTitle(isTitleShadow);
764 thePrs->SetTitFontType(aTitleFontFamily);
765 thePrs->SetTitleColor(aTitColor.red()/255.,
766 aTitColor.green()/255.,
767 aTitColor.blue()/255.);
770 QColor aLblColor (255, 255, 255);
771 int aLabelFontFamily = VTK_ARIAL;
772 bool isLabelBold = false;
773 bool isLabelItalic = false;
774 bool isLabelShadow = false;
776 myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
777 isLabelBold, isLabelItalic, isLabelShadow);
779 thePrs->SetBoldLabel(isLabelBold);
780 thePrs->SetItalicLabel(isLabelItalic);
781 thePrs->SetShadowLabel(isLabelShadow);
782 thePrs->SetLblFontType(aLabelFontFamily);
783 thePrs->SetLabelColor(aLblColor.red()/255.,
784 aLblColor.green()/255.,
785 aLblColor.blue()/255.);
792 Called when orientation is changed
794 void VisuGUI_ScalarBarPane::changeDefaults( int )
796 if ( RBvert->isChecked() ) {
797 XSpin->setValue( myVerX );
798 YSpin->setValue( myVerY );
799 WidthSpin->setValue( myVerW );
800 HeightSpin->setValue( myVerH );
803 XSpin->setValue( myHorX );
804 YSpin->setValue( myHorY );
805 WidthSpin->setValue( myHorW );
806 HeightSpin->setValue( myHorH );
812 Called when Range mode is changed
814 void VisuGUI_ScalarBarPane::changeRange( int )
817 if ( RBFrange->isChecked() )
819 if ( RBIrange->isChecked() )
821 if ( myRangeMode == mode )
823 //MinSpin->setMaxValue( Fmin );
824 //MaxSpin->setMinValue( Fmax );
825 if ( RBFrange->isChecked() ) {
826 //MinLabel->setEnabled( false );
827 MinEdit->setEnabled( false );
828 //MaxLabel->setEnabled( false );
829 MaxEdit->setEnabled( false );
831 Imin = MinEdit->text().toDouble();
832 Imax = MaxEdit->text().toDouble();
834 MinEdit->setText( QString::number( Rmin ) );
835 MaxEdit->setText( QString::number( Rmax ) );
838 //MinLabel->setEnabled( true );
839 MinEdit->setEnabled( true );
840 //MaxLabel->setEnabled( true );
841 MaxEdit->setEnabled( true );
842 MinEdit->setText( QString::number( Imin ) );
843 MaxEdit->setText( QString::number( Imax ) );
850 Called when X,Y position is changed
852 void VisuGUI_ScalarBarPane::XYChanged( double )
854 QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
855 if ( snd == XSpin ) {
856 WidthSpin->setMaxValue( 1.0 - XSpin->value() );
858 if ( snd == YSpin ) {
859 HeightSpin->setMaxValue( 1.0 - YSpin->value() );
865 Sets default values and range mode
867 void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, double fmax*/, bool sbRange )
869 Imin = imin; Imax = imax;// Fmin = fmin; Fmax = fmax;
870 if ( RBIrange->isChecked() ) {
871 MinEdit->setText( QString::number( Imin ) );
872 MaxEdit->setText( QString::number( Imax ) );
875 MinEdit->setText( QString::number( Rmin ) );
876 MaxEdit->setText( QString::number( Rmax ) );
880 RBIrange->setChecked( true );
882 RBFrange->setChecked( true );
887 Sets size and position
889 void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
896 RBvert->setChecked( true );
903 RBhori->setChecked( true );
909 Sets colors and labels number
911 void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels )
913 ColorSpin->setValue( colors );
914 LabelSpin->setValue( labels );
920 int VisuGUI_ScalarBarPane::getOrientation()
922 if (RBvert->isChecked() )
929 Called when <OK> button is clicked, validates data and closes dialog
931 bool VisuGUI_ScalarBarPane::check()
933 double minVal = MinEdit->text().toDouble();
934 double maxVal = MaxEdit->text().toDouble();
935 if ( RBIrange->isChecked() ) {
936 if (minVal >= maxVal) {
937 SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
938 tr("MSG_MINMAX_VALUES"),
943 // check if logarithmic mode is on and check imposed range to not contain negative values
944 if ( CBLog->isChecked() ) {
945 if ( RBIrange->isChecked() ) {
946 if ( (minVal > 0) && (maxVal > 0) ) {
950 SUIT_MessageBox::warn1( this,
952 tr("WRN_LOGARITHMIC_RANGE"),
958 if ( Rmin > 0 && Rmax > 0 ) {
962 SUIT_MessageBox::warn1( this,
964 tr("WRN_LOGARITHMIC_FIELD_RANGE"),
966 RBIrange->setChecked(1);
968 //MinEdit->setText( QString::number( Rmin ) );
969 //MaxEdit->setText( QString::number( Rmax ) );
977 void VisuGUI_ScalarBarPane::onTextPref()
979 myIsStoreTextProp = myTextDlg->exec();
983 void VisuGUI_ScalarBarPane::onPreviewCheck (bool thePreview)
985 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
995 //#######################################################################################
1000 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool SetPref)
1001 : QDialog(VISU::GetDesktop(theModule), 0, true,
1002 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
1004 setName("VisuGUI_ScalarBarDlg");
1005 setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE"));
1006 setSizeGripEnabled(TRUE);
1008 QVBoxLayout* TopLayout = new QVBoxLayout(this);
1009 TopLayout->setSpacing(6);
1010 TopLayout->setMargin(11);
1012 myScalarPane = new VisuGUI_ScalarBarPane(this, SetPref);
1013 TopLayout->addWidget(myScalarPane);
1015 // Common buttons ===========================================================
1016 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1017 GroupButtons->setColumnLayout(0, Qt::Vertical );
1018 GroupButtons->layout()->setSpacing( 0 );
1019 GroupButtons->layout()->setMargin( 0 );
1020 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1021 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1022 GroupButtonsLayout->setSpacing( 6 );
1023 GroupButtonsLayout->setMargin( 11 );
1025 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1026 buttonOk->setAutoDefault( TRUE );
1027 buttonOk->setDefault( TRUE );
1028 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1029 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1031 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1032 buttonCancel->setAutoDefault( TRUE );
1033 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1035 TopLayout->addWidget( GroupButtons );
1037 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
1038 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
1042 Called when <OK> button is clicked, validates data and closes dialog
1044 void VisuGUI_ScalarBarDlg::accept()
1046 if (myScalarPane->check())
1048 myScalarPane->deletePreview();
1054 Called when <Cancel> button is clicked, remove preview and closes dialog
1056 void VisuGUI_ScalarBarDlg::reject()
1058 myScalarPane->deletePreview();
1063 //#######################################################################################
1064 VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
1065 : QDialog(parent, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
1067 setName("VisuGUI_TextPrefDlg");
1068 setCaption(tr("TIT_TEXT_PREF"));
1069 setSizeGripEnabled(TRUE);
1071 QVBoxLayout* TopLayout = new QVBoxLayout(this);
1072 TopLayout->setSpacing(6);
1073 TopLayout->setMargin(11);
1076 QGroupBox* aTitleGrp = new QGroupBox (2, Qt::Vertical, tr("LBL_TITLE"), this);
1079 myTitleEdt = new QLineEdit (aTitleGrp);
1082 QHBox* aHBox = new QHBox (aTitleGrp);
1083 aHBox->setSpacing(5);
1084 myTitleFont = new VisuGUI_FontWg (aHBox);
1086 TopLayout->addWidget(aTitleGrp);
1089 QGroupBox* aLabelsGrp = new QGroupBox (1, Qt::Vertical, tr("LBL_LABELS"), this);
1092 aHBox = new QHBox (aLabelsGrp);
1093 aHBox->setSpacing(5);
1094 myLabelFont = new VisuGUI_FontWg (aHBox);
1096 TopLayout->addWidget(aLabelsGrp);
1098 // Common buttons ===========================================================
1099 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1100 GroupButtons->setColumnLayout(0, Qt::Vertical );
1101 GroupButtons->layout()->setSpacing( 0 );
1102 GroupButtons->layout()->setMargin( 0 );
1103 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1104 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1105 GroupButtonsLayout->setSpacing( 6 );
1106 GroupButtonsLayout->setMargin( 11 );
1108 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1109 buttonOk->setAutoDefault( TRUE );
1110 buttonOk->setDefault( TRUE );
1111 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1112 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1114 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1115 buttonCancel->setAutoDefault( TRUE );
1116 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1118 TopLayout->addWidget( GroupButtons );
1120 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
1121 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));