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