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 int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
282 myModeCombo->setCurrentItem(aScalarMode);
284 orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", orient);
293 QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
295 sbX1 = aResourceMgr->doubleValue("VISU", propertyName + "x", sbX1);
296 sbY1 = aResourceMgr->doubleValue("VISU", propertyName + "y", sbY1);
298 sbW = aResourceMgr->doubleValue("VISU", propertyName + "width", sbW);
299 sbH = aResourceMgr->doubleValue("VISU", propertyName + "height",sbH);
301 sbCol = aResourceMgr->integerValue("VISU" ,"scalar_bar_num_colors", sbCol);
302 sbLab = aResourceMgr->integerValue("VISU", "scalar_bar_num_labels", sbLab);
304 int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0);
305 if (rangeType == 1) sbRange = true;
306 sbVmin = aResourceMgr->doubleValue("VISU", "scalar_range_min", sbVmin);
307 sbVmax = aResourceMgr->doubleValue("VISU", "scalar_range_max", sbVmax);
309 bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false);
310 setLogarithmic(isLog);
312 if((sbX1 < 0.) || (sbY1 < 0.) ||
313 ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
326 if(sbCol < 2) sbCol=2;
327 if(sbCol > 64) sbCol=64;
328 if(sbLab < 2) sbLab=2;
329 if(sbLab > 65) sbLab=65;
331 if(sbVmin > sbVmax) {
336 setRange( sbVmin, sbVmax, /*0.0, 0.0,*/ sbRange );
337 setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 0);
338 setScalarBarData( sbCol, sbLab );
341 bool isBold = false, isItalic = false, isShadow = false;
342 int aFontFamily = VTK_ARIAL;
344 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) )
346 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" );
348 if ( f.family() == "Arial" )
349 aFontFamily = VTK_ARIAL;
350 else if ( f.family() == "Courier" )
351 aFontFamily = VTK_COURIER;
352 else if ( f.family() == "Times" )
353 aFontFamily = VTK_TIMES;
356 isItalic = f.italic();
357 isShadow = f.underline();
360 QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
362 myTextDlg->myTitleFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
365 isBold = isItalic = isShadow = false;
366 aFontFamily = VTK_ARIAL;
368 if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) )
370 QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" );
372 if ( f.family() == "Arial" )
373 aFontFamily = VTK_ARIAL;
374 else if ( f.family() == "Courier" )
375 aFontFamily = VTK_COURIER;
376 else if ( f.family() == "Times" )
377 aFontFamily = VTK_TIMES;
380 isItalic = f.italic();
381 isShadow = f.underline();
384 aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
386 myTextDlg->myLabelFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
390 * Stores dialog values to resources
392 void VisuGUI_ScalarBarPane::storeToResources() {
393 int orient = (RBvert->isChecked())? 0 : 1;
394 float sbX1 = XSpin->value();
395 float sbY1 = YSpin->value();
396 float sbW = WidthSpin->value();
397 float sbH = HeightSpin->value();
398 int sbCol = ColorSpin->value();
399 int sbLab = LabelSpin->value();
401 if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
415 bool sbRange = RBIrange->isChecked();
416 float sbVmin = (float)(MinEdit->text().toDouble());
417 float sbVmax = (float)(MaxEdit->text().toDouble());
419 if(sbVmin > sbVmax) {
424 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
426 aResourceMgr->setValue("VISU", "scalar_bar_orientation", orient);
428 QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
430 aResourceMgr->setValue("VISU", propertyName + "x", sbX1);
431 aResourceMgr->setValue("VISU", propertyName + "y", sbY1);
432 aResourceMgr->setValue("VISU", propertyName + "width", sbW);
433 aResourceMgr->setValue("VISU", propertyName + "height", sbH);
435 aResourceMgr->setValue("VISU", "scalar_bar_num_colors", sbCol);
436 aResourceMgr->setValue("VISU", "scalar_bar_num_labels", sbLab);
440 aResourceMgr->setValue("VISU", "scalar_range_type", 1);
441 aResourceMgr->setValue("VISU", "scalar_range_min" ,sbVmin);
442 aResourceMgr->setValue("VISU", "scalar_range_max" ,sbVmax);
445 aResourceMgr->setValue("VISU", "scalar_range_type", 0);
447 aResourceMgr->setValue("VISU", "scalar_bar_logarithmic", isLogarithmic());
451 if (myIsStoreTextProp) {
453 QColor aTitleColor (255, 255, 255);
454 int aTitleFontFamily = VTK_ARIAL;
455 bool isTitleBold = false;
456 bool isTitleItalic = false;
457 bool isTitleShadow = false;
459 myTextDlg->myTitleFont->GetData(aTitleColor, aTitleFontFamily,
460 isTitleBold, isTitleItalic, isTitleShadow);
464 aTitleFont.setBold(isTitleBold);
465 aTitleFont.setItalic(isTitleItalic);
466 aTitleFont.setUnderline(isTitleShadow);
468 QString titleFontFamily;
469 switch (aTitleFontFamily) {
471 titleFontFamily = "Arial";
474 titleFontFamily = "Courier";
477 titleFontFamily = "Times";
480 aTitleFont.setFamily(titleFontFamily);
482 aResourceMgr->setValue("VISU", "scalar_bar_title_font", aTitleFont);
484 aResourceMgr->setValue("VISU", "scalar_bar_title_color", aTitleColor);
487 QColor aLabelColor (255, 255, 255);
488 int aLabelFontFamily = VTK_ARIAL;
489 bool isLabelBold = false;
490 bool isLabelItalic = false;
491 bool isLabelShadow = false;
493 myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
494 isLabelBold, isLabelItalic, isLabelShadow);
499 aLabelFont.setBold(isLabelBold);
500 aLabelFont.setItalic(isLabelItalic);
501 aLabelFont.setUnderline(isLabelShadow);
503 QString labelFontFamily;
504 switch (aLabelFontFamily) {
506 labelFontFamily = "Arial";
509 labelFontFamily = "Courier";
512 labelFontFamily = "Times";
516 aLabelFont.setFamily(labelFontFamily);
518 aResourceMgr->setValue("VISU", "scalar_bar_label_font", aLabelFont);
520 aResourceMgr->setValue("VISU", "scalar_bar_label_color", aLabelColor);
525 * Initialise dialog box from presentation object
527 void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
529 myScalarMap = thePrs;
530 myModeCombo->setCurrentItem(thePrs->GetScalarMode());
531 setPosAndSize( thePrs->GetPosX(),
535 thePrs->GetBarOrientation());
536 switch(thePrs->GetScaling()){
537 case VISU::LOGARITHMIC :
538 setLogarithmic(true);
541 setLogarithmic(false);
544 thePrs->GetScalarMapPL()->GetSourceRange(aRange);
545 Rmin = aRange[0]; Rmax = aRange[1];
546 setRange( thePrs->GetMin(), thePrs->GetMax(),
547 /*0.0, 0.0,*/ thePrs->IsRangeFixed() );
548 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
549 bool isScalarMode = (thePrs->GetField()->myNbComp > 1);
550 myModeLbl->setEnabled(isScalarMode);
551 myModeCombo->setEnabled(isScalarMode);
554 myTextDlg->setTitleText(QString(thePrs->GetTitle()));
557 thePrs->GetTitleColor(&R, &G, &B);
559 myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
560 thePrs->GetTitFontType(),
561 thePrs->IsBoldTitle(),
562 thePrs->IsItalicTitle(),
563 thePrs->IsShadowTitle());
566 thePrs->GetLabelColor(&R, &G, &B);
568 myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
569 thePrs->GetLblFontType(),
570 thePrs->IsBoldLabel(),
571 thePrs->IsItalicLabel(),
572 thePrs->IsShadowLabel());
575 if (myPreviewCheck->isChecked()) {
581 /*! Slot update preview of scalar bar, if preview is checked
583 void VisuGUI_ScalarBarPane::updatePreview()
585 if (myPreviewCheck->isChecked()) {
586 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
594 /*! Creating preview scalar bar
596 void VisuGUI_ScalarBarPane::createScalarBar()
598 if (VISU::GetViewWindow() == NULL) return;
599 if (myPreviewActor != 0) return;
600 if (myScalarMap == NULL) return;
604 if ( myBusy ) return;
609 sbCol = getNbColors();
610 sbLab = getNbLabels();
611 if(sbCol < 2) sbCol=2;
612 if(sbCol > 64) sbCol=64;
613 if(sbLab < 2) sbLab=2;
614 if(sbLab > 65) sbLab=65;
615 myPreviewActor = VISU_ScalarMapAct::New();
616 VISU_ScalarBarActor* aScalarBarActor = myPreviewActor->GetScalarBar();
617 myPreviewActor->GetScalarBar()->VisibilityOn();
618 myPreviewActor->PickableOff();
620 myScalarMap->SetScalarMode(myModeCombo->currentItem());
621 myScalarMap->SetPosition(getX(),getY());
622 myScalarMap->SetSize(getWidth(),getHeight());
623 myScalarMap->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
625 myScalarMap->SetScaling(VISU::LOGARITHMIC);
627 myScalarMap->SetScaling(VISU::LINEAR);
628 if (RBFrange->isChecked()) {
629 myScalarMap->SetSourceRange();
631 myScalarMap->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
633 myScalarMap->SetNbColors(sbCol);
634 myScalarMap->SetLabels(sbLab);
636 myScalarMap->GetScalarMapPL()->SetNbColors(sbCol);
637 myScalarMap->GetScalarMapPL()->Update();
639 aScalarBarActor->SetLookupTable(myScalarMap->GetScalarMapPL()->GetBarTable());
641 if (myTextDlg->getTitleText().latin1() != "")
642 aScalarBarActor->SetTitle(myTextDlg->getTitleText().latin1());
644 aScalarBarActor->SetTitle(myScalarMap->GetTitle());
645 aScalarBarActor->SetOrientation(getOrientation());
646 aScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
647 aScalarBarActor->GetPositionCoordinate()->SetValue(getX(),getY());
648 aScalarBarActor->SetWidth(getWidth());
649 aScalarBarActor->SetHeight(getHeight());
650 aScalarBarActor->SetNumberOfLabels(sbLab);
651 aScalarBarActor->SetMaximumNumberOfColors(sbCol);
653 // title text property
655 int aTitleFontFamily;
659 myTextDlg->myTitleFont->GetData(aTitleColor,aTitleFontFamily,
660 isTitleBold,isTitleItalic,isTitleShadow);
661 vtkTextProperty* aTitleProp = aScalarBarActor->GetTitleTextProperty();
662 aTitleProp->SetFontFamily(aTitleFontFamily);
663 aTitleProp->SetColor(float(aTitleColor.red())/255.,
664 float(aTitleColor.green())/255.,
665 float(aTitleColor.blue())/255.);
666 (isTitleBold)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
667 (isTitleItalic)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
668 (isTitleShadow)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
670 // label text property
672 int aLabelFontFamily;
676 myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
677 isLabelBold, isLabelItalic, isLabelShadow);
678 vtkTextProperty* aLabelProp = aScalarBarActor->GetLabelTextProperty();
679 aLabelProp->SetFontFamily(aLabelFontFamily);
680 aLabelProp->SetColor(float(aLabelColor.red())/255.,
681 float(aLabelColor.green())/255.,
682 float(aLabelColor.blue())/255.);
683 (isLabelBold)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
684 (isLabelItalic)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
685 (isLabelShadow)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
687 aScalarBarActor->Modified();
689 VISU::GetViewWindow()->AddActor(myPreviewActor);
693 /*! Deleting preview scalar bar
695 void VisuGUI_ScalarBarPane::deleteScalarBar()
697 if ( myBusy ) return;
699 if (myPreviewActor == 0) return;
700 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()){
701 vf->RemoveActor(myPreviewActor);
702 myPreviewActor->GetScalarBar()->VisibilityOff();
704 myPreviewActor->Delete();
707 /*! public: Deleting preview scalar bar
709 void VisuGUI_ScalarBarPane::deletePreview()
714 * Store values to presentation object
716 int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
717 thePrs->SetScalarMode(myModeCombo->currentItem());
718 thePrs->SetPosition(XSpin->value(), YSpin->value());
719 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
720 thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
722 thePrs->SetScaling(VISU::LOGARITHMIC);
724 thePrs->SetScaling(VISU::LINEAR);
726 if (RBFrange->isChecked()) {
727 thePrs->SetSourceRange();
729 thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
731 thePrs->SetNbColors(ColorSpin->value());
732 thePrs->SetLabels(LabelSpin->value());
734 if (isToSave()) storeToResources();
736 if (myIsStoreTextProp) {
738 thePrs->SetTitle(myTextDlg->getTitleText().latin1());
740 QColor aTitColor (255, 255, 255);
741 int aTitleFontFamily = VTK_ARIAL;
742 bool isTitleBold = false;
743 bool isTitleItalic = false;
744 bool isTitleShadow = false;
746 myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
747 isTitleBold, isTitleItalic, isTitleShadow);
749 thePrs->SetBoldTitle(isTitleBold);
750 thePrs->SetItalicTitle(isTitleItalic);
751 thePrs->SetShadowTitle(isTitleShadow);
752 thePrs->SetTitFontType(aTitleFontFamily);
753 thePrs->SetTitleColor(aTitColor.red()/255.,
754 aTitColor.green()/255.,
755 aTitColor.blue()/255.);
758 QColor aLblColor (255, 255, 255);
759 int aLabelFontFamily = VTK_ARIAL;
760 bool isLabelBold = false;
761 bool isLabelItalic = false;
762 bool isLabelShadow = false;
764 myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
765 isLabelBold, isLabelItalic, isLabelShadow);
767 thePrs->SetBoldLabel(isLabelBold);
768 thePrs->SetItalicLabel(isLabelItalic);
769 thePrs->SetShadowLabel(isLabelShadow);
770 thePrs->SetLblFontType(aLabelFontFamily);
771 thePrs->SetLabelColor(aLblColor.red()/255.,
772 aLblColor.green()/255.,
773 aLblColor.blue()/255.);
780 Called when orientation is changed
782 void VisuGUI_ScalarBarPane::changeDefaults( int )
784 if ( RBvert->isChecked() ) {
785 XSpin->setValue( myVerX );
786 YSpin->setValue( myVerY );
787 WidthSpin->setValue( myVerW );
788 HeightSpin->setValue( myVerH );
791 XSpin->setValue( myHorX );
792 YSpin->setValue( myHorY );
793 WidthSpin->setValue( myHorW );
794 HeightSpin->setValue( myHorH );
800 Called when Range mode is changed
802 void VisuGUI_ScalarBarPane::changeRange( int )
805 if ( RBFrange->isChecked() )
807 if ( RBIrange->isChecked() )
809 if ( myRangeMode == mode )
811 //MinSpin->setMaxValue( Fmin );
812 //MaxSpin->setMinValue( Fmax );
813 if ( RBFrange->isChecked() ) {
814 //MinLabel->setEnabled( false );
815 MinEdit->setEnabled( false );
816 //MaxLabel->setEnabled( false );
817 MaxEdit->setEnabled( false );
819 Imin = MinEdit->text().toDouble();
820 Imax = MaxEdit->text().toDouble();
822 MinEdit->setText( QString::number( Rmin ) );
823 MaxEdit->setText( QString::number( Rmax ) );
826 //MinLabel->setEnabled( true );
827 MinEdit->setEnabled( true );
828 //MaxLabel->setEnabled( true );
829 MaxEdit->setEnabled( true );
830 MinEdit->setText( QString::number( Imin ) );
831 MaxEdit->setText( QString::number( Imax ) );
838 Called when X,Y position is changed
840 void VisuGUI_ScalarBarPane::XYChanged( double )
842 QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
843 if ( snd == XSpin ) {
844 WidthSpin->setMaxValue( 1.0 - XSpin->value() );
846 if ( snd == YSpin ) {
847 HeightSpin->setMaxValue( 1.0 - YSpin->value() );
853 Sets default values and range mode
855 void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, double fmax*/, bool sbRange )
857 Imin = imin; Imax = imax;// Fmin = fmin; Fmax = fmax;
858 if ( RBIrange->isChecked() ) {
859 MinEdit->setText( QString::number( Imin ) );
860 MaxEdit->setText( QString::number( Imax ) );
863 MinEdit->setText( QString::number( Rmin ) );
864 MaxEdit->setText( QString::number( Rmax ) );
868 RBIrange->setChecked( true );
870 RBFrange->setChecked( true );
875 Sets size and position
877 void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
884 RBvert->setChecked( true );
891 RBhori->setChecked( true );
897 Sets colors and labels number
899 void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels )
901 ColorSpin->setValue( colors );
902 LabelSpin->setValue( labels );
908 int VisuGUI_ScalarBarPane::getOrientation()
910 if (RBvert->isChecked() )
917 Called when <OK> button is clicked, validates data and closes dialog
919 bool VisuGUI_ScalarBarPane::check()
921 double minVal = MinEdit->text().toDouble();
922 double maxVal = MaxEdit->text().toDouble();
923 if ( RBIrange->isChecked() ) {
924 if (minVal >= maxVal) {
925 SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
926 tr("MSG_MINMAX_VALUES"),
931 // check if logarithmic mode is on and check imposed range to not contain negative values
932 if ( CBLog->isChecked() ) {
933 if ( RBIrange->isChecked() ) {
934 if ( (minVal > 0) && (maxVal > 0) ) {
938 SUIT_MessageBox::warn1( this,
940 tr("WRN_LOGARITHMIC_RANGE"),
946 if ( Rmin > 0 && Rmax > 0 ) {
950 SUIT_MessageBox::warn1( this,
952 tr("WRN_LOGARITHMIC_FIELD_RANGE"),
954 RBIrange->setChecked(1);
956 //MinEdit->setText( QString::number( Rmin ) );
957 //MaxEdit->setText( QString::number( Rmax ) );
965 void VisuGUI_ScalarBarPane::onTextPref()
967 myIsStoreTextProp = myTextDlg->exec();
971 void VisuGUI_ScalarBarPane::onPreviewCheck (bool thePreview)
973 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
983 //#######################################################################################
988 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool SetPref)
989 : QDialog(VISU::GetDesktop(theModule), 0, true,
990 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
992 setName("VisuGUI_ScalarBarDlg");
993 setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE"));
994 setSizeGripEnabled(TRUE);
996 QVBoxLayout* TopLayout = new QVBoxLayout(this);
997 TopLayout->setSpacing(6);
998 TopLayout->setMargin(11);
1000 myScalarPane = new VisuGUI_ScalarBarPane(this, SetPref);
1001 TopLayout->addWidget(myScalarPane);
1003 // Common buttons ===========================================================
1004 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1005 GroupButtons->setColumnLayout(0, Qt::Vertical );
1006 GroupButtons->layout()->setSpacing( 0 );
1007 GroupButtons->layout()->setMargin( 0 );
1008 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1009 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1010 GroupButtonsLayout->setSpacing( 6 );
1011 GroupButtonsLayout->setMargin( 11 );
1013 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1014 buttonOk->setAutoDefault( TRUE );
1015 buttonOk->setDefault( TRUE );
1016 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1017 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1019 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1020 buttonCancel->setAutoDefault( TRUE );
1021 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1023 TopLayout->addWidget( GroupButtons );
1025 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
1026 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
1030 Called when <OK> button is clicked, validates data and closes dialog
1032 void VisuGUI_ScalarBarDlg::accept()
1034 myScalarPane->deletePreview();
1035 if (myScalarPane->check()) QDialog::accept();
1039 Called when <Cancel> button is clicked, remove preview and closes dialog
1041 void VisuGUI_ScalarBarDlg::reject()
1043 myScalarPane->deletePreview();
1048 //#######################################################################################
1049 VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
1050 : QDialog(parent, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
1052 setName("VisuGUI_TextPrefDlg");
1053 setCaption(tr("TIT_TEXT_PREF"));
1054 setSizeGripEnabled(TRUE);
1056 QVBoxLayout* TopLayout = new QVBoxLayout(this);
1057 TopLayout->setSpacing(6);
1058 TopLayout->setMargin(11);
1061 QGroupBox* aTitleGrp = new QGroupBox (2, Qt::Vertical, tr("LBL_TITLE"), this);
1064 myTitleEdt = new QLineEdit (aTitleGrp);
1067 QHBox* aHBox = new QHBox (aTitleGrp);
1068 aHBox->setSpacing(5);
1069 myTitleFont = new VisuGUI_FontWg (aHBox);
1071 TopLayout->addWidget(aTitleGrp);
1074 QGroupBox* aLabelsGrp = new QGroupBox (1, Qt::Vertical, tr("LBL_LABELS"), this);
1077 aHBox = new QHBox (aLabelsGrp);
1078 aHBox->setSpacing(5);
1079 myLabelFont = new VisuGUI_FontWg (aHBox);
1081 TopLayout->addWidget(aLabelsGrp);
1083 // Common buttons ===========================================================
1084 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1085 GroupButtons->setColumnLayout(0, Qt::Vertical );
1086 GroupButtons->layout()->setSpacing( 0 );
1087 GroupButtons->layout()->setMargin( 0 );
1088 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1089 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1090 GroupButtonsLayout->setSpacing( 6 );
1091 GroupButtonsLayout->setMargin( 11 );
1093 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
1094 buttonOk->setAutoDefault( TRUE );
1095 buttonOk->setDefault( TRUE );
1096 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
1097 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1099 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
1100 buttonCancel->setAutoDefault( TRUE );
1101 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
1103 TopLayout->addWidget( GroupButtons );
1105 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
1106 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));