Salome HOME
sources v1.2
[modules/visu.git] / src / VISUGUI / VisuGUI_ScalarBarDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VisuGUI_ScalarBarDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND 
26 //  Module : VISU
27 //  $Header$
28
29 using namespace std;
30 #include "VisuGUI_ScalarBarDlg.h"
31 #include <limits.h>
32 #include <qlayout.h>
33 #include <qvalidator.h>
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "QAD_Config.h"
37 #include "QAD_MessageBox.h"
38 #include "VISU_Convertor.hxx"
39
40 /*!
41   Constructor
42 */
43 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg(bool SetPref)
44     : QDialog( QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
45 {
46   setName( "VisuGUI_ScalarBarDlg" );
47   setCaption( SetPref ? tr( "Scalar Bar Preferences" ) : tr( "Scalar Bar Properties" ) );
48   setSizeGripEnabled( TRUE );
49   
50   myVerX = 0.01;  myVerY = 0.10;  myVerW = 0.10;  myVerH = 0.80;
51   myHorX = 0.20;  myHorY = 0.01;  myHorW = 0.60;  myHorH = 0.12;
52   Imin = 0.0; Imax = 0.0; Fmin = 0.0; Fmax = 0.0; Rmin = 0.0; Rmax = 0.0;
53   myRangeMode = -1;
54   
55   QVBoxLayout* TopLayout = new QVBoxLayout( this ); 
56   TopLayout->setSpacing( 6 );
57   TopLayout->setMargin( 11 );
58
59   // Range ============================================================
60   RangeGroup = new QButtonGroup( tr( "Scalar range" ), this, "RangeGroup" );
61   RangeGroup->setColumnLayout(0, Qt::Vertical );
62   RangeGroup->layout()->setSpacing( 0 );
63   RangeGroup->layout()->setMargin( 0 );
64   QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() );
65   RangeGroupLayout->setAlignment( Qt::AlignTop );
66   RangeGroupLayout->setSpacing( 6 );
67   RangeGroupLayout->setMargin( 11 );
68   
69   myModeLbl = new QLabel("Scalar Mode", RangeGroup);
70   
71   myModeCombo = new QComboBox(RangeGroup);
72   myModeCombo->insertItem("Modulus");
73   myModeCombo->insertItem("Component 1");
74   myModeCombo->insertItem("Component 2");
75   myModeCombo->insertItem("Component 3");
76
77   CBLog = new QCheckBox( tr( "Logarithmic scaling" ), RangeGroup );
78   CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
79   
80   RBFrange = new QRadioButton( tr( "Use field range" ), RangeGroup, "RBFrange" );
81   RBIrange = new QRadioButton( tr( "Use imposed range" ), RangeGroup, "RBIrange" );
82   RBFrange->setChecked( true );
83
84   MinEdit = new QLineEdit( RangeGroup, "MinEdit" );
85   MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
86   MinEdit->setMinimumWidth( 70 );
87   MinEdit->setValidator( new QDoubleValidator(this) );
88   MinEdit->setText( "0.0" );
89   QLabel* MinLabel = new QLabel( tr( "Min:" ), RangeGroup, "MinLabel" );
90   MinLabel->setBuddy(MinEdit);
91
92   MaxEdit = new QLineEdit( RangeGroup, "MaxEdit" );
93   MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94   MaxEdit->setMinimumWidth( 70 );
95   MaxEdit->setValidator( new QDoubleValidator(this) );
96   MaxEdit->setText( "0.0" );
97   QLabel* MaxLabel = new QLabel( tr( "Max:" ), RangeGroup, "MaxLabel" );
98   MaxLabel->setBuddy(MaxEdit);
99
100   RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
101   RangeGroupLayout->addMultiCellWidget( myModeCombo, 0, 0, 1, 3);
102   RangeGroupLayout->addMultiCellWidget( CBLog, 1, 1, 0, 3);
103   RangeGroupLayout->addMultiCellWidget( RBFrange, 2, 2, 0, 1);
104   RangeGroupLayout->addMultiCellWidget( RBIrange, 2, 2, 2, 3);
105   RangeGroupLayout->addWidget( MinLabel, 3, 0 );
106   RangeGroupLayout->addWidget( MinEdit,  3, 1 );
107   RangeGroupLayout->addWidget( MaxLabel, 3, 2 );
108   RangeGroupLayout->addWidget( MaxEdit,  3, 3 );
109
110   TopLayout->addWidget( RangeGroup );
111
112   // Colors and Labels ========================================================
113   QGroupBox* ColLabGroup = new QGroupBox( tr( "Colors and labels" ), this, "ColLabGroup" );
114   ColLabGroup->setColumnLayout(0, Qt::Vertical );
115   ColLabGroup->layout()->setSpacing( 0 );
116   ColLabGroup->layout()->setMargin( 0 );
117   QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() );
118   ColLabGroupLayout->setAlignment( Qt::AlignTop );
119   ColLabGroupLayout->setSpacing( 6 );
120   ColLabGroupLayout->setMargin( 11 );
121
122   QLabel* ColorLabel = new QLabel( tr( "Nb. of colors:" ), ColLabGroup, "ColorLabel" );
123   ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup );
124   ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
125   ColorSpin->setMinimumWidth( 70 );
126   ColorSpin->setValue( 64 );
127
128   QLabel* LabelLabel = new QLabel( tr( "Nb. of labels:" ), ColLabGroup, "LabelLabel" );
129   LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup );
130   LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
131   LabelSpin->setMinimumWidth( 70 );
132   LabelSpin->setValue( 5 );
133   
134   ColLabGroupLayout->addWidget( ColorLabel, 0, 0);
135   ColLabGroupLayout->addWidget( ColorSpin,  0, 1);
136   ColLabGroupLayout->addWidget( LabelLabel, 0, 2);
137   ColLabGroupLayout->addWidget( LabelSpin,  0, 3);
138
139   TopLayout->addWidget( ColLabGroup );
140
141   // Orientation ==========================================================
142   QButtonGroup* OrientGroup = new QButtonGroup( tr( "Orientation" ), this, "OrientGroup" );
143   OrientGroup->setColumnLayout(0, Qt::Vertical );
144   OrientGroup->layout()->setSpacing( 0 );
145   OrientGroup->layout()->setMargin( 0 );
146   QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() );
147   OrientGroupLayout->setAlignment( Qt::AlignTop );
148   OrientGroupLayout->setSpacing( 6 );
149   OrientGroupLayout->setMargin( 11 );
150
151   RBvert = new QRadioButton( tr( "Vertical" ), OrientGroup, "RBvert" );
152   RBvert->setChecked( true );
153   RBhori = new QRadioButton( tr( "Horizontal" ), OrientGroup, "RBhori" );
154   OrientGroupLayout->addWidget( RBvert, 0, 0 );
155   OrientGroupLayout->addWidget( RBhori, 0, 1 );
156   
157   TopLayout->addWidget( OrientGroup );
158
159   // Origin ===============================================================
160   QGroupBox* OriginGroup = new QGroupBox( tr( "Origin" ), this, "OriginGroup" );
161   OriginGroup->setColumnLayout(0, Qt::Vertical );
162   OriginGroup->layout()->setSpacing( 0 );
163   OriginGroup->layout()->setMargin( 0 );
164   QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() );
165   OriginGroupLayout->setAlignment( Qt::AlignTop );
166   OriginGroupLayout->setSpacing( 6 );
167   OriginGroupLayout->setMargin( 11 );
168
169   QLabel* XLabel = new QLabel( tr( "X:" ), OriginGroup, "XLabel" );
170   XSpin = new QAD_SpinBoxDbl( OriginGroup, 0.0, 1.0, 0.1 );
171   XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
172   XSpin->setMinimumWidth( 70 );
173   XSpin->setValue( 0.01 );
174
175   QLabel* YLabel = new QLabel( tr( "Y:" ), OriginGroup, "YLabel" );
176   YSpin = new QAD_SpinBoxDbl( OriginGroup, 0.0, 1.0, 0.1 );
177   YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
178   YSpin->setMinimumWidth( 70 );
179   YSpin->setValue( 0.01 );
180   
181   OriginGroupLayout->addWidget( XLabel, 0, 0);
182   OriginGroupLayout->addWidget( XSpin,  0, 1);
183   OriginGroupLayout->addWidget( YLabel, 0, 2);
184   OriginGroupLayout->addWidget( YSpin,  0, 3);
185
186   TopLayout->addWidget( OriginGroup );
187
188   // Dimensions =========================================================
189   QGroupBox* DimGroup = new QGroupBox( tr( "Dimensions" ), this, "DimGroup" );
190   DimGroup->setColumnLayout(0, Qt::Vertical );
191   DimGroup->layout()->setSpacing( 0 );
192   DimGroup->layout()->setMargin( 0 );
193   QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() );
194   DimGroupLayout->setAlignment( Qt::AlignTop );
195   DimGroupLayout->setSpacing( 6 );
196   DimGroupLayout->setMargin( 11 );
197
198   QLabel* WidthLabel = new QLabel( tr( "Width:" ), DimGroup, "WidthLabel" );
199   WidthSpin = new QAD_SpinBoxDbl( DimGroup, 0.0, 1.0, 0.1 );
200   WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
201   WidthSpin->setMinimumWidth( 70 );
202   WidthSpin->setValue( 0.1 );
203
204   QLabel* HeightLabel = new QLabel( tr( "Height:" ), DimGroup, "HeightLabel" );
205   HeightSpin = new QAD_SpinBoxDbl( DimGroup, 0.0, 1.0, 0.1 );
206   HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
207   HeightSpin->setMinimumWidth( 70 );
208   HeightSpin->setValue( 0.8 );
209   
210   DimGroupLayout->addWidget( WidthLabel, 0, 0);
211   DimGroupLayout->addWidget( WidthSpin,  0, 1);
212   DimGroupLayout->addWidget( HeightLabel, 0, 2);
213   DimGroupLayout->addWidget( HeightSpin,  0, 3);
214
215   TopLayout->addWidget( DimGroup );
216
217   // Save check box ===========================================================
218   if ( !SetPref ) {
219     CBSave = new QCheckBox( tr( "Save as default values" ), this, "CBSave" );
220     TopLayout->addWidget( CBSave );
221   }
222   else {
223     CBSave = 0;
224   }
225
226   // Common buttons ===========================================================
227   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
228   GroupButtons->setColumnLayout(0, Qt::Vertical );
229   GroupButtons->layout()->setSpacing( 0 );
230   GroupButtons->layout()->setMargin( 0 );
231   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
232   GroupButtonsLayout->setAlignment( Qt::AlignTop );
233   GroupButtonsLayout->setSpacing( 6 );
234   GroupButtonsLayout->setMargin( 11 );
235
236   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
237   buttonOk->setAutoDefault( TRUE );
238   buttonOk->setDefault( TRUE );
239   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
240   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
241
242   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
243   buttonCancel->setAutoDefault( TRUE );
244   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
245
246   TopLayout->addWidget( GroupButtons );
247
248   // signals and slots connections ===========================================
249   connect( RangeGroup,   SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) );
250   connect( OrientGroup,  SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) );
251   connect( XSpin,        SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
252   connect( YSpin,        SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
253   connect( buttonOk,     SIGNAL( clicked() ),      this, SLOT( accept() ) );
254   connect( buttonCancel, SIGNAL( clicked() ),      this, SLOT( reject() ) );
255
256   changeRange( 0 );
257   changeDefaults( 0 );
258 }
259
260 /*!
261   Destructor
262 */
263 VisuGUI_ScalarBarDlg::~VisuGUI_ScalarBarDlg()
264 {
265 }
266
267
268 /**
269  * Initializes dialog box values from resources
270  */
271 void VisuGUI_ScalarBarDlg::initFromResources() {
272   int sbCol=64,sbLab=5,orient=1;
273   float sbX1=0.01,sbY1=0.1,sbW=0.1,sbH=0.8;
274   float sbVmin=0., sbVmax=0.;
275   bool sbRange=false;
276   
277   QString Orientation = QAD_CONFIG->getSetting("Visu:SBOrientation");
278   if ( !Orientation.isEmpty() ) {
279     orient = Orientation.toInt();
280     if(orient != 1) {
281       orient=0;
282       sbX1=0.2;
283       sbY1=0.01;
284       sbW=0.6;
285       sbH=0.12;
286     }
287   }
288
289   QString SBXorigin = QAD_CONFIG->getSetting("Visu:SBXorigin");
290   if ( !SBXorigin.isEmpty() )
291     sbX1 = SBXorigin.toFloat();
292   
293   QString SBYorigin = QAD_CONFIG->getSetting("Visu:SBYorigin");
294   if ( !SBYorigin.isEmpty() )
295     sbY1 = SBYorigin.toFloat();
296   
297   QString SBWidth = QAD_CONFIG->getSetting("Visu:SBWidth");
298   if ( !SBWidth.isEmpty() )
299     sbW = SBWidth.toFloat();
300   
301   QString SBHeight = QAD_CONFIG->getSetting("Visu:SBHeight");
302   if ( !SBHeight.isEmpty() )
303     sbH = SBHeight.toFloat();
304   
305   QString SBColors = QAD_CONFIG->getSetting("Visu:SBNumberOfColors");
306   if ( !SBColors.isEmpty() )
307     sbCol = SBColors.toInt();
308   
309   QString SBLabels = QAD_CONFIG->getSetting("Visu:SBNumberOfLabels");
310   if ( !SBLabels.isEmpty() )
311     sbLab = SBLabels.toInt();
312   
313   QString ImpRange = QAD_CONFIG->getSetting("Visu:SBImposeRange");
314   if ( ImpRange.compare("true") == 0 )
315     sbRange=true;
316   
317   QString SBVmin = QAD_CONFIG->getSetting("Visu:SBMinimumValue");
318   if ( !SBVmin.isEmpty() )
319     sbVmin = SBVmin.toFloat();
320   
321   QString SBVmax = QAD_CONFIG->getSetting("Visu:SBMaximumValue");
322   if ( !SBVmax.isEmpty() )
323     sbVmax = SBVmax.toFloat();
324   
325   QString aScaling = QAD_CONFIG->getSetting("Visu:SBScaling");
326   if(aScaling.compare("LOGARITHMIC") == 0) 
327     setLogarithmic(true);
328   else 
329     setLogarithmic(false);
330
331   if((sbX1 < 0.) || (sbY1 < 0.) || 
332      ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
333     if(orient == 1) {
334       sbX1=0.01;
335       sbY1=0.1;
336       sbW=0.1;
337       sbH=0.8;
338     } else {
339       sbX1=0.2;
340       sbY1=0.01;
341       sbW=0.6;
342       sbH=0.12;
343     }
344   }
345   if(sbCol < 2) sbCol=2;
346   if(sbCol > 64) sbCol=64;
347   if(sbLab < 2) sbLab=2;
348   if(sbLab > 65) sbLab=65;
349
350   if(sbVmin > sbVmax) {
351     sbVmin=0.;
352     sbVmax=0.;
353   }
354   
355   setRange( sbVmin, sbVmax, 0.0, 0.0, sbRange );
356   setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 1);
357   setScalarBarData( sbCol, sbLab );
358 }
359
360
361
362 /**
363  * Stores dialog values to resources
364  */
365 void VisuGUI_ScalarBarDlg::storeToResources() {
366   int orient = (RBvert->isChecked())? 1 : 0;
367   float sbX1   = XSpin->value();
368   float sbY1   = YSpin->value();
369   float sbW    = WidthSpin->value();
370   float sbH    = HeightSpin->value();
371   int sbCol  = ColorSpin->value();
372   int sbLab  = LabelSpin->value();
373   
374   if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
375     if(orient == 1) {
376       sbX1=0.01;
377       sbY1=0.1;
378       sbW=0.17;
379       sbH=0.8;
380     } else {
381       sbX1=0.2;
382       sbY1=0.01;
383       sbW=0.6;
384       sbH=0.12;
385     }
386   }
387   
388   bool sbRange = RBIrange->isChecked();
389   float sbVmin = (float)(MinEdit->text().toDouble());
390   float sbVmax = (float)(MaxEdit->text().toDouble());
391   
392   if(sbVmin > sbVmax) {
393     sbVmin=0.;
394     sbVmax=0.;
395   }
396   
397   QAD_CONFIG->addSetting("Visu:SBOrientation",orient);
398   QAD_CONFIG->addSetting("Visu:SBXorigin",sbX1);
399   QAD_CONFIG->addSetting("Visu:SBYorigin",sbY1);
400   QAD_CONFIG->addSetting("Visu:SBWidth",sbW);
401   QAD_CONFIG->addSetting("Visu:SBHeight",sbH);
402   QAD_CONFIG->addSetting("Visu:SBNumberOfColors",sbCol);
403   QAD_CONFIG->addSetting("Visu:SBNumberOfLabels",sbLab);
404   if(sbRange)
405     QAD_CONFIG->addSetting("Visu:SBImposeRange", "true");
406   else
407     QAD_CONFIG->addSetting("Visu:SBImposeRange", "false");
408   QAD_CONFIG->addSetting("Visu:SBMinimumValue",sbVmin);
409   QAD_CONFIG->addSetting("Visu:SBMaximumValue",sbVmax);
410   if(isLogarithmic())
411     QAD_CONFIG->addSetting("Visu:SBScaling", "LOGARITHMIC");
412   else
413     QAD_CONFIG->addSetting("Visu:SBScaling", "LINEAR");
414 }
415
416
417 /**
418  * Initialise dialog box from presentation object
419  */
420 void VisuGUI_ScalarBarDlg::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
421   myModeCombo->setCurrentItem(thePrs->GetScalarMode());
422   setPosAndSize( thePrs->GetPosX(), 
423                  thePrs->GetPosY(), 
424                  thePrs->GetWidth(), 
425                  thePrs->GetHeight(), 
426                  thePrs->GetOrientation());
427   switch(thePrs->GetScaling()){
428   case VISU::LOGARITHMIC : 
429     setLogarithmic(true);
430     break;
431   default:  
432     setLogarithmic(false);
433   }
434   float aRange[2];
435   thePrs->GetFieldRange(aRange);
436   Rmin = aRange[0]; Rmax = aRange[1];
437   setRange( thePrs->GetMin(), thePrs->GetMax(), 
438             0.0, 0.0, thePrs->isRangeFixed() );
439   setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
440   bool isScalarMode = (thePrs->GetField()->myNbComp > 1);
441   myModeLbl->setEnabled(isScalarMode);
442   myModeCombo->setEnabled(isScalarMode);
443 }
444
445
446 /**
447  * Store values to presentation object
448  */
449 void VisuGUI_ScalarBarDlg::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
450   thePrs->SetScalarMode(myModeCombo->currentItem());
451   thePrs->SetPosition(XSpin->value(), YSpin->value());
452   thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
453   thePrs->SetOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
454   if (RBFrange->isChecked()) {
455     thePrs->CalculateRange();
456   } else {
457     thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
458   }    
459   if(isLogarithmic()) 
460     thePrs->SetScaling(VISU::LOGARITHMIC); 
461   else
462     thePrs->SetScaling(VISU::LINEAR);
463   thePrs->SetNbColors(ColorSpin->value());
464   thePrs->SetLabels(LabelSpin->value());
465   thePrs->Update();
466
467   if (isToSave()) storeToResources();
468 }
469
470
471
472 /*!
473   Called when orientation is changed
474 */
475 void VisuGUI_ScalarBarDlg::changeDefaults( int )
476 {
477   if ( RBvert->isChecked() ) {
478     XSpin->setValue( myVerX );
479     YSpin->setValue( myVerY );
480     WidthSpin->setValue( myVerW );
481     HeightSpin->setValue( myVerH );
482   }
483   else {
484     XSpin->setValue( myHorX );
485     YSpin->setValue( myHorY );
486     WidthSpin->setValue( myHorW );
487     HeightSpin->setValue( myHorH );
488   }
489 }
490
491 /*!
492   Called when Range mode is changed
493 */
494 void VisuGUI_ScalarBarDlg::changeRange( int )
495 {
496   int mode = -1;
497   if ( RBFrange->isChecked() )
498     mode = 0;
499   if ( RBIrange->isChecked() )
500     mode = 1;
501   if ( myRangeMode == mode ) 
502     return;
503   //MinSpin->setMaxValue( Fmin );
504   //MaxSpin->setMinValue( Fmax );
505   if ( RBFrange->isChecked() ) { 
506     //MinLabel->setEnabled( false );
507     MinEdit->setEnabled( false );
508     //MaxLabel->setEnabled( false );
509     MaxEdit->setEnabled( false );
510     if ( mode != -1 ) {
511       Imin = MinEdit->text().toDouble();
512       Imax = MaxEdit->text().toDouble();
513     }
514     MinEdit->setText( QString::number( Rmin ) );
515     MaxEdit->setText( QString::number( Rmax ) );
516   }
517   else {
518     //MinLabel->setEnabled( true );
519     MinEdit->setEnabled( true );
520     //MaxLabel->setEnabled( true );
521     MaxEdit->setEnabled( true );
522     MinEdit->setText( QString::number( Imin ) );
523     MaxEdit->setText( QString::number( Imax ) );
524   }
525   myRangeMode = mode;
526 }
527
528 /*!
529   Called when X,Y position is changed
530 */
531 void VisuGUI_ScalarBarDlg::XYChanged( double )
532 {
533   QAD_SpinBoxDbl* snd = (QAD_SpinBoxDbl*)sender();
534   if ( snd == XSpin ) {
535     WidthSpin->setMaxValue( 1.0 - XSpin->value() );
536   }
537   if ( snd == YSpin ) {
538     HeightSpin->setMaxValue( 1.0 - YSpin->value() );
539   }
540 }
541
542 /*!
543   Sets default values and range mode
544 */
545 void VisuGUI_ScalarBarDlg::setRange( double imin, double imax, double fmin, double fmax, bool sbRange )
546 {
547   Imin = imin; Imax = imax; Fmin = fmin; Fmax = fmax;
548   if ( RBIrange->isChecked() ) {
549     MinEdit->setText( QString::number( Imin ) );
550     MaxEdit->setText( QString::number( Imax ) );
551   }
552   else {
553     MinEdit->setText( QString::number( Rmin ) );
554     MaxEdit->setText( QString::number( Rmax ) );
555   }
556   myRangeMode = -1;
557   if( sbRange )
558     RBIrange->setChecked( true );
559   else
560     RBFrange->setChecked( true );
561   changeRange( 0 );
562 }
563
564 /*!
565   Sets size and position
566 */
567 void VisuGUI_ScalarBarDlg::setPosAndSize( double x, double y, double w, double h, bool vert )
568 {
569   if ( vert ) {
570     myVerX = x;
571     myVerY = y;
572     myVerW = w;
573     myVerH = h;
574     RBvert->setChecked( true );
575   }
576   else {
577     myHorX = x;
578     myHorY = y;
579     myHorW = w;
580     myHorH = h;
581     RBhori->setChecked( true );
582   }
583   changeDefaults( 0 );
584 }
585
586 /*!
587   Sets colors and labels number
588 */
589 void VisuGUI_ScalarBarDlg::setScalarBarData( int colors, int labels ) 
590 {
591   ColorSpin->setValue( colors );
592   LabelSpin->setValue( labels );
593 }
594
595 /*!
596   Gets orientation
597 */
598 int  VisuGUI_ScalarBarDlg::getOrientation() 
599 {
600   if (RBvert->isChecked() )
601     return  1;
602   else
603     return 0;
604 }
605
606 /*!
607   Gets Scalar Bar's x position
608 */
609 double VisuGUI_ScalarBarDlg::getX()
610 {
611   return XSpin->value();
612 }
613
614 /*!
615   Gets Scalar Bar's y position
616 */
617 double VisuGUI_ScalarBarDlg::getY()
618 {
619   return YSpin->value();
620 }
621
622 /*!
623   Gets Scalar Bar's width
624 */
625 double VisuGUI_ScalarBarDlg::getWidth()
626 {
627   return WidthSpin->value();
628 }
629
630 /*!
631   Gets Scalar Bar's height
632 */
633 double VisuGUI_ScalarBarDlg::getHeight()
634 {
635   return HeightSpin->value();
636 }
637
638 /*!
639   Gets Scalar Bar's number of colors
640 */
641 int VisuGUI_ScalarBarDlg::getNbColors()
642 {
643   return ColorSpin->value();
644 }
645
646 /*!
647   Gets Scalar Bar's number of labels
648 */
649 int VisuGUI_ScalarBarDlg::getNbLabels()
650 {
651   return LabelSpin->value();
652 }
653
654 /*!
655   Returns true if imposed range is used
656 */
657 bool VisuGUI_ScalarBarDlg::isIRange()
658 {
659   return RBIrange->isChecked();
660 }
661
662 /*!
663   Gets Min value
664 */
665 double VisuGUI_ScalarBarDlg::getMin()
666 {
667   return MinEdit->text().toDouble();
668 }
669
670 /*!
671   Gets Max value
672 */
673 double VisuGUI_ScalarBarDlg::getMax()
674 {
675   return MaxEdit->text().toDouble();
676 }
677
678 /*!
679   return true if "save pref" flag is on
680 */
681 bool VisuGUI_ScalarBarDlg::isToSave()
682 {
683   return CBSave ? CBSave->isChecked() : false;
684 }
685
686 /*!
687   Returns true if "Logarithmic scaling" check box is on
688 */
689 bool VisuGUI_ScalarBarDlg::isLogarithmic()
690 {
691   return CBLog->isChecked();
692 }
693
694 /*!
695   Sets "Logarithmic scaling" check box on/off
696 */
697 void VisuGUI_ScalarBarDlg::setLogarithmic( bool on )
698 {
699   CBLog->setChecked( on );
700 }
701
702 /*!
703   Called when <OK> button is clicked, validates data and closes dialog
704 */
705 void VisuGUI_ScalarBarDlg::accept()
706 {
707   double minVal = MinEdit->text().toDouble();
708   double maxVal = MaxEdit->text().toDouble();
709   if ( RBIrange->isChecked() ) {
710     if (minVal >= maxVal) {
711       QAD_MessageBox::warn1( this,tr("VISU_WARNING"),
712                              tr("MSG_MINMAX_VALUES"),
713                              tr("VISU_BUT_OK"));
714       return;
715     }
716   }
717   // check if logarithmic mode is on and check imposed range to not contain negative values
718   if ( CBLog->isChecked() ) {
719     if ( RBIrange->isChecked() ) {
720       if ( (minVal > 0) && (maxVal > 0) ) {
721         // nothing to do
722       }
723       else {
724         QAD_MessageBox::warn1( this,
725                                 tr("VISU_WARNING"),
726                                 tr("WRN_LOGARITHMIC_RANGE"),
727                                 tr("VISU_BUT_OK"));
728         return;
729       }
730     }
731     else {
732       if ( Rmin > 0 && Rmax > 0 ) {
733         // nothing to do
734       }
735       else {
736         QAD_MessageBox::warn1( this,
737                                 tr("VISU_WARNING"),
738                                 tr("WRN_LOGARITHMIC_FIELD_RANGE"),
739                                 tr("VISU_BUT_OK"));
740         RBIrange->setChecked(1);
741         changeRange(1);
742         //MinEdit->setText( QString::number( Rmin ) );
743         //MaxEdit->setText( QString::number( Rmax ) );
744         return;
745       }
746     }
747   }
748   QDialog::accept();
749 }