2 // File : VisuGUI_ScalarBarDlg.cxx
3 // Created : Wed Aug 01 10:23:06 2001
4 // Author : Laurent CORNABE & Hubert ROLLAND
7 // Copyright : PRINCIPIA
10 #include "VisuGUI_ScalarBarDlg.h"
12 #include "QAD_Application.h"
13 #include "QAD_Desktop.h"
14 #include "QAD_Config.h"
15 #include "VISU_Convertor.hxx"
18 static double MAXVALUE = 1.0E+300;
22 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg(bool SetPref)
23 : QDialog( QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
25 setName( "VisuGUI_ScalarBarDlg" );
26 setCaption( SetPref ? tr( "Scalar Bar Preferences" ) : tr( "Scalar Bar Properties" ) );
27 setSizeGripEnabled( TRUE );
29 myVerX = 0.01; myVerY = 0.10; myVerW = 0.10; myVerH = 0.80;
30 myHorX = 0.20; myHorY = 0.01; myHorW = 0.60; myHorH = 0.12;
32 QVBoxLayout* TopLayout = new QVBoxLayout( this );
33 TopLayout->setSpacing( 6 );
34 TopLayout->setMargin( 11 );
36 // Range ============================================================
37 QButtonGroup* RangeGroup = new QButtonGroup( tr( "Scalar range" ), this, "RangeGroup" );
38 RangeGroup->setColumnLayout(0, Qt::Vertical );
39 RangeGroup->layout()->setSpacing( 0 );
40 RangeGroup->layout()->setMargin( 0 );
41 QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() );
42 RangeGroupLayout->setAlignment( Qt::AlignTop );
43 RangeGroupLayout->setSpacing( 6 );
44 RangeGroupLayout->setMargin( 11 );
46 myModeLbl = new QLabel("Scalar Mode", RangeGroup);
48 myModeCombo = new QComboBox(RangeGroup);
49 myModeCombo->insertItem("Modulus");
50 myModeCombo->insertItem("Component 1");
51 myModeCombo->insertItem("Component 2");
52 myModeCombo->insertItem("Component 3");
54 CBLog = new QCheckBox( tr( "Logarithmic scaling" ), RangeGroup );
55 CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
57 RBFrange = new QRadioButton( tr( "Use field range" ), RangeGroup, "RBFrange" );
58 RBIrange = new QRadioButton( tr( "Use imposed range" ), RangeGroup, "RBIrange" );
59 RBIrange->setChecked( true );
61 MinSpin = new QAD_SpinBoxDbl( RangeGroup, -MAXVALUE, MAXVALUE, 0.1 );
62 MinSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
63 MinSpin->setMinimumWidth( 70 );
64 MinSpin->setValue( 0 );
65 QLabel* MinLabel = new QLabel( tr( "Min:" ), RangeGroup, "MinLabel" );
66 MinLabel->setBuddy(MinSpin);
68 MaxSpin = new QAD_SpinBoxDbl( RangeGroup, -MAXVALUE, MAXVALUE, 0.1 );
69 MaxSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
70 MaxSpin->setMinimumWidth( 70 );
71 MaxSpin->setValue( 0 );
72 QLabel* MaxLabel = new QLabel( tr( "Max:" ), RangeGroup, "MaxLabel" );
73 MaxLabel->setBuddy(MaxSpin);
75 RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
76 RangeGroupLayout->addMultiCellWidget( myModeCombo, 0, 0, 1, 3);
77 RangeGroupLayout->addMultiCellWidget( CBLog, 1, 1, 0, 3);
78 RangeGroupLayout->addMultiCellWidget( RBFrange, 2, 2, 0, 1);
79 RangeGroupLayout->addMultiCellWidget( RBIrange, 2, 2, 2, 3);
80 RangeGroupLayout->addWidget( MinLabel, 3, 0 );
81 RangeGroupLayout->addWidget( MinSpin, 3, 1 );
82 RangeGroupLayout->addWidget( MaxLabel, 3, 2 );
83 RangeGroupLayout->addWidget( MaxSpin, 3, 3 );
85 TopLayout->addWidget( RangeGroup );
87 // Colors and Labels ========================================================
88 QGroupBox* ColLabGroup = new QGroupBox( tr( "Colors and labels" ), this, "ColLabGroup" );
89 ColLabGroup->setColumnLayout(0, Qt::Vertical );
90 ColLabGroup->layout()->setSpacing( 0 );
91 ColLabGroup->layout()->setMargin( 0 );
92 QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() );
93 ColLabGroupLayout->setAlignment( Qt::AlignTop );
94 ColLabGroupLayout->setSpacing( 6 );
95 ColLabGroupLayout->setMargin( 11 );
97 QLabel* ColorLabel = new QLabel( tr( "Nb. of colors:" ), ColLabGroup, "ColorLabel" );
98 ColorSpin = new QSpinBox( 2, 64, 1, ColLabGroup );
99 ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
100 ColorSpin->setMinimumWidth( 70 );
101 ColorSpin->setValue( 64 );
103 QLabel* LabelLabel = new QLabel( tr( "Nb. of labels:" ), ColLabGroup, "LabelLabel" );
104 LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup );
105 LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
106 LabelSpin->setMinimumWidth( 70 );
107 LabelSpin->setValue( 5 );
109 ColLabGroupLayout->addWidget( ColorLabel, 0, 0);
110 ColLabGroupLayout->addWidget( ColorSpin, 0, 1);
111 ColLabGroupLayout->addWidget( LabelLabel, 0, 2);
112 ColLabGroupLayout->addWidget( LabelSpin, 0, 3);
114 TopLayout->addWidget( ColLabGroup );
116 // Orientation ==========================================================
117 QButtonGroup* OrientGroup = new QButtonGroup( tr( "Orientation" ), this, "OrientGroup" );
118 OrientGroup->setColumnLayout(0, Qt::Vertical );
119 OrientGroup->layout()->setSpacing( 0 );
120 OrientGroup->layout()->setMargin( 0 );
121 QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() );
122 OrientGroupLayout->setAlignment( Qt::AlignTop );
123 OrientGroupLayout->setSpacing( 6 );
124 OrientGroupLayout->setMargin( 11 );
126 RBvert = new QRadioButton( tr( "Vertical" ), OrientGroup, "RBvert" );
127 RBvert->setChecked( true );
128 RBhori = new QRadioButton( tr( "Horizontal" ), OrientGroup, "RBhori" );
129 OrientGroupLayout->addWidget( RBvert, 0, 0 );
130 OrientGroupLayout->addWidget( RBhori, 0, 1 );
132 TopLayout->addWidget( OrientGroup );
134 // Origin ===============================================================
135 QGroupBox* OriginGroup = new QGroupBox( tr( "Origin" ), this, "OriginGroup" );
136 OriginGroup->setColumnLayout(0, Qt::Vertical );
137 OriginGroup->layout()->setSpacing( 0 );
138 OriginGroup->layout()->setMargin( 0 );
139 QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() );
140 OriginGroupLayout->setAlignment( Qt::AlignTop );
141 OriginGroupLayout->setSpacing( 6 );
142 OriginGroupLayout->setMargin( 11 );
144 QLabel* XLabel = new QLabel( tr( "X:" ), OriginGroup, "XLabel" );
145 XSpin = new QAD_SpinBoxDbl( OriginGroup, 0.0, 1.0, 0.1 );
146 XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
147 XSpin->setMinimumWidth( 70 );
148 XSpin->setValue( 0.01 );
150 QLabel* YLabel = new QLabel( tr( "Y:" ), OriginGroup, "YLabel" );
151 YSpin = new QAD_SpinBoxDbl( OriginGroup, 0.0, 1.0, 0.1 );
152 YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
153 YSpin->setMinimumWidth( 70 );
154 YSpin->setValue( 0.01 );
156 OriginGroupLayout->addWidget( XLabel, 0, 0);
157 OriginGroupLayout->addWidget( XSpin, 0, 1);
158 OriginGroupLayout->addWidget( YLabel, 0, 2);
159 OriginGroupLayout->addWidget( YSpin, 0, 3);
161 TopLayout->addWidget( OriginGroup );
163 // Dimensions =========================================================
164 QGroupBox* DimGroup = new QGroupBox( tr( "Dimensions" ), this, "DimGroup" );
165 DimGroup->setColumnLayout(0, Qt::Vertical );
166 DimGroup->layout()->setSpacing( 0 );
167 DimGroup->layout()->setMargin( 0 );
168 QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() );
169 DimGroupLayout->setAlignment( Qt::AlignTop );
170 DimGroupLayout->setSpacing( 6 );
171 DimGroupLayout->setMargin( 11 );
173 QLabel* WidthLabel = new QLabel( tr( "Width:" ), DimGroup, "WidthLabel" );
174 WidthSpin = new QAD_SpinBoxDbl( DimGroup, 0.0, 1.0, 0.1 );
175 WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
176 WidthSpin->setMinimumWidth( 70 );
177 WidthSpin->setValue( 0.1 );
179 QLabel* HeightLabel = new QLabel( tr( "Height:" ), DimGroup, "HeightLabel" );
180 HeightSpin = new QAD_SpinBoxDbl( DimGroup, 0.0, 1.0, 0.1 );
181 HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
182 HeightSpin->setMinimumWidth( 70 );
183 HeightSpin->setValue( 0.8 );
185 DimGroupLayout->addWidget( WidthLabel, 0, 0);
186 DimGroupLayout->addWidget( WidthSpin, 0, 1);
187 DimGroupLayout->addWidget( HeightLabel, 0, 2);
188 DimGroupLayout->addWidget( HeightSpin, 0, 3);
190 TopLayout->addWidget( DimGroup );
192 // Save check box ===========================================================
194 CBSave = new QCheckBox( tr( "Save as default values" ), this, "CBSave" );
195 TopLayout->addWidget( CBSave );
201 // Common buttons ===========================================================
202 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
203 GroupButtons->setColumnLayout(0, Qt::Vertical );
204 GroupButtons->layout()->setSpacing( 0 );
205 GroupButtons->layout()->setMargin( 0 );
206 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
207 GroupButtonsLayout->setAlignment( Qt::AlignTop );
208 GroupButtonsLayout->setSpacing( 6 );
209 GroupButtonsLayout->setMargin( 11 );
211 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
212 buttonOk->setAutoDefault( TRUE );
213 buttonOk->setDefault( TRUE );
214 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
215 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
217 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
218 buttonCancel->setAutoDefault( TRUE );
219 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
221 TopLayout->addWidget( GroupButtons );
223 // signals and slots connections ===========================================
224 connect( RangeGroup, SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) );
225 connect( OrientGroup, SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) );
226 connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
227 connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
228 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
229 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
238 VisuGUI_ScalarBarDlg::~VisuGUI_ScalarBarDlg()
244 * Initializes dialog box values from resources
246 void VisuGUI_ScalarBarDlg::initFromResources() {
247 int sbCol=64,sbLab=5,orient=1;
248 float sbX1=0.01,sbY1=0.1,sbW=0.1,sbH=0.8;
249 float sbVmin=0., sbVmax=0.;
252 QString Orientation = QAD_CONFIG->getSetting("Visu:SBOrientation");
253 if ( !Orientation.isEmpty() ) {
254 orient = Orientation.toInt();
264 QString SBXorigin = QAD_CONFIG->getSetting("Visu:SBXorigin");
265 if ( !SBXorigin.isEmpty() )
266 sbX1 = SBXorigin.toFloat();
268 QString SBYorigin = QAD_CONFIG->getSetting("Visu:SBYorigin");
269 if ( !SBYorigin.isEmpty() )
270 sbY1 = SBYorigin.toFloat();
272 QString SBWidth = QAD_CONFIG->getSetting("Visu:SBWidth");
273 if ( !SBWidth.isEmpty() )
274 sbW = SBWidth.toFloat();
276 QString SBHeight = QAD_CONFIG->getSetting("Visu:SBHeight");
277 if ( !SBHeight.isEmpty() )
278 sbH = SBHeight.toFloat();
280 QString SBColors = QAD_CONFIG->getSetting("Visu:SBNumberOfColors");
281 if ( !SBColors.isEmpty() )
282 sbCol = SBColors.toInt();
284 QString SBLabels = QAD_CONFIG->getSetting("Visu:SBNumberOfLabels");
285 if ( !SBLabels.isEmpty() )
286 sbLab = SBLabels.toInt();
288 QString ImpRange = QAD_CONFIG->getSetting("Visu:SBImposeRange");
289 if ( ImpRange.compare("true") == 0 )
292 QString SBVmin = QAD_CONFIG->getSetting("Visu:SBMinimumValue");
293 if ( !SBVmin.isEmpty() )
294 sbVmin = SBVmin.toFloat();
296 QString SBVmax = QAD_CONFIG->getSetting("Visu:SBMaximumValue");
297 if ( !SBVmax.isEmpty() )
298 sbVmax = SBVmax.toFloat();
300 QString aScaling = QAD_CONFIG->getSetting("Visu:SBScaling");
301 if(aScaling.compare("LOGARITHMIC") == 0)
302 setLogarithmic(true);
304 setLogarithmic(false);
306 if((sbX1 < 0.) || (sbY1 < 0.) ||
307 ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
320 if(sbCol < 2) sbCol=2;
321 if(sbCol > 64) sbCol=64;
322 if(sbLab < 2) sbLab=2;
323 if(sbLab > 65) sbLab=65;
325 if(sbVmin > sbVmax) {
330 setRange( sbVmin, sbVmax, 0.0, 0.0, sbRange );
331 setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 1);
332 setScalarBarData( sbCol, sbLab );
338 * Stores dialog values to resources
340 void VisuGUI_ScalarBarDlg::storeToResources() {
341 int orient = (RBvert->isChecked())? 1 : 0;
342 float sbX1 = XSpin->value();
343 float sbY1 = YSpin->value();
344 float sbW = WidthSpin->value();
345 float sbH = HeightSpin->value();
346 int sbCol = ColorSpin->value();
347 int sbLab = LabelSpin->value();
349 if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
363 bool sbRange = RBIrange->isChecked();
364 float sbVmin = MinSpin->value();
365 float sbVmax = MaxSpin->value();
367 if(sbVmin > sbVmax) {
372 QAD_CONFIG->addSetting("Visu:SBOrientation",orient);
373 QAD_CONFIG->addSetting("Visu:SBXorigin",sbX1);
374 QAD_CONFIG->addSetting("Visu:SBYorigin",sbY1);
375 QAD_CONFIG->addSetting("Visu:SBWidth",sbW);
376 QAD_CONFIG->addSetting("Visu:SBHeight",sbH);
377 QAD_CONFIG->addSetting("Visu:SBNumberOfColors",sbCol);
378 QAD_CONFIG->addSetting("Visu:SBNumberOfLabels",sbLab);
380 QAD_CONFIG->addSetting("Visu:SBImposeRange", "true");
382 QAD_CONFIG->addSetting("Visu:SBImposeRange", "false");
383 QAD_CONFIG->addSetting("Visu:SBMinimumValue",sbVmin);
384 QAD_CONFIG->addSetting("Visu:SBMaximumValue",sbVmax);
386 QAD_CONFIG->addSetting("Visu:SBScaling", "LOGARITHMIC");
388 QAD_CONFIG->addSetting("Visu:SBScaling", "LINEAR");
393 * Initialise dialog box from presentation object
395 void VisuGUI_ScalarBarDlg::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
396 myModeCombo->setCurrentItem(thePrs->GetScalarMode());
397 setPosAndSize( thePrs->GetPosX(),
401 thePrs->GetOrientation());
402 switch(thePrs->GetScaling()){
403 case VISU::LOGARITHMIC :
404 setLogarithmic(true);
407 setLogarithmic(false);
409 setRange( thePrs->GetMin(), thePrs->GetMax(),
410 0.0, 0.0, thePrs->isRangeFixed() );
411 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
412 bool isScalarMode = (thePrs->GetField()->myNbComp > 1);
413 myModeLbl->setEnabled(isScalarMode);
414 myModeCombo->setEnabled(isScalarMode);
419 * Store values to presentation object
421 void VisuGUI_ScalarBarDlg::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
422 thePrs->SetScalarMode(myModeCombo->currentItem());
423 thePrs->SetPosition(XSpin->value(), YSpin->value());
424 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
425 thePrs->SetOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
427 thePrs->SetScaling(VISU::LOGARITHMIC);
429 thePrs->SetScaling(VISU::LINEAR);
430 if (RBFrange->isChecked()) {
431 thePrs->CalculateRange();
433 thePrs->SetRange(MinSpin->value(), MaxSpin->value());
435 thePrs->SetNbColors(ColorSpin->value());
436 thePrs->SetLabels(LabelSpin->value());
439 if (isToSave()) storeToResources();
445 Called when orientation is changed
447 void VisuGUI_ScalarBarDlg::changeDefaults( int )
449 if ( RBvert->isChecked() ) {
450 XSpin->setValue( myVerX );
451 YSpin->setValue( myVerY );
452 WidthSpin->setValue( myVerW );
453 HeightSpin->setValue( myVerH );
456 XSpin->setValue( myHorX );
457 YSpin->setValue( myHorY );
458 WidthSpin->setValue( myHorW );
459 HeightSpin->setValue( myHorH );
464 Called when Range mode is changed
466 void VisuGUI_ScalarBarDlg::changeRange( int )
468 //MinSpin->setMaxValue( Fmin );
469 //MaxSpin->setMinValue( Fmax );
470 if ( RBFrange->isChecked() ) {
471 //MinLabel->setEnabled( false );
472 MinSpin->setEnabled( false );
473 //MaxLabel->setEnabled( false );
474 MaxSpin->setEnabled( false );
475 MinSpin->setValue( Fmin );
476 MaxSpin->setValue( Fmax );
479 //MinLabel->setEnabled( true );
480 MinSpin->setEnabled( true );
481 //MaxLabel->setEnabled( true );
482 MaxSpin->setEnabled( true );
483 MinSpin->setValue( Imin );
484 MaxSpin->setValue( Imax );
489 Called when X,Y position is changed
491 void VisuGUI_ScalarBarDlg::XYChanged( double )
493 QAD_SpinBoxDbl* snd = (QAD_SpinBoxDbl*)sender();
494 if ( snd == XSpin ) {
495 WidthSpin->setMaxValue( 1.0 - XSpin->value() );
497 if ( snd == YSpin ) {
498 HeightSpin->setMaxValue( 1.0 - YSpin->value() );
503 Sets default values and range mode
505 void VisuGUI_ScalarBarDlg::setRange( double imin, double imax, double fmin, double fmax, bool sbRange )
507 Imin = imin; Imax = imax; Fmin = fmin; Fmax = fmax;
509 RBIrange->setChecked( true );
511 RBFrange->setChecked( true );
516 Sets size and position
518 void VisuGUI_ScalarBarDlg::setPosAndSize( double x, double y, double w, double h, bool vert )
525 RBvert->setChecked( true );
532 RBhori->setChecked( true );
538 Sets colors and labels number
540 void VisuGUI_ScalarBarDlg::setScalarBarData( int colors, int labels )
542 ColorSpin->setValue( colors );
543 LabelSpin->setValue( labels );
549 int VisuGUI_ScalarBarDlg::getOrientation()
551 if (RBvert->isChecked() )
558 Gets Scalar Bar's x position
560 double VisuGUI_ScalarBarDlg::getX()
562 return XSpin->value();
566 Gets Scalar Bar's y position
568 double VisuGUI_ScalarBarDlg::getY()
570 return YSpin->value();
574 Gets Scalar Bar's width
576 double VisuGUI_ScalarBarDlg::getWidth()
578 return WidthSpin->value();
582 Gets Scalar Bar's height
584 double VisuGUI_ScalarBarDlg::getHeight()
586 return HeightSpin->value();
590 Gets Scalar Bar's number of colors
592 int VisuGUI_ScalarBarDlg::getNbColors()
594 return ColorSpin->value();
598 Gets Scalar Bar's number of labels
600 int VisuGUI_ScalarBarDlg::getNbLabels()
602 return LabelSpin->value();
606 Returns true if imposed range is used
608 bool VisuGUI_ScalarBarDlg::isIRange()
610 return RBIrange->isChecked();
616 double VisuGUI_ScalarBarDlg::getMin()
618 return MinSpin->value();
624 double VisuGUI_ScalarBarDlg::getMax()
626 return MaxSpin->value();
630 return true if "save pref" flag is on
632 bool VisuGUI_ScalarBarDlg::isToSave()
634 return CBSave ? CBSave->isChecked() : false;
638 Returns true if "Logarithmic scaling" check box is on
640 bool VisuGUI_ScalarBarDlg::isLogarithmic()
642 return CBLog->isChecked();
646 Sets "Logarithmic scaling" check box on/off
648 void VisuGUI_ScalarBarDlg::setLogarithmic( bool on )
650 CBLog->setChecked( on );