Back to index

salome-gui  6.5.0
Plot2d_FitDataDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : Plot2d_FitDataDlg.cxx
00024 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00025 //
00026 #include "Plot2d_FitDataDlg.h"
00027 #include <QLabel>
00028 #include <QLayout>
00029 #include <QValidator>
00030 #include <QPushButton>
00031 #include <QRadioButton>
00032 #include <QGroupBox>
00033 #include <QLineEdit>
00034 
00035 #define SPACING_SIZE      6
00036 #define MARGIN_SIZE       11
00037 #define MIN_EDIT_SIZE     100
00038 
00042 Plot2d_FitDataDlg::Plot2d_FitDataDlg( QWidget* parent, bool secondAxisY )
00043      : QDialog( parent ? parent : 0,
00044          Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
00045        myY2MinEdit( 0 ), myY2MaxEdit( 0 ), mySecondAxisY( secondAxisY )
00046 
00047 {
00048   setObjectName( "Plot2d_FitDataDlg" );
00049   setModal( true );
00050   setWindowTitle( tr( "FIT_DATA_TLT" ) );
00051   setSizeGripEnabled( TRUE );
00052   QGridLayout* topLayout = new QGridLayout( this ); 
00053   topLayout->setSpacing( SPACING_SIZE );
00054   topLayout->setMargin( MARGIN_SIZE );
00055 
00056   // 'Range' group
00057   myRangeGrp = new QGroupBox( this );
00058   QGridLayout* aGridLayout = new QGridLayout( myRangeGrp );
00059   myRangeGrp->setLayout( aGridLayout );
00060   aGridLayout->setAlignment( Qt::AlignTop );
00061   aGridLayout->setMargin( MARGIN_SIZE );
00062   aGridLayout->setSpacing( SPACING_SIZE );
00063 
00064   myModeAllRB  = new QRadioButton( tr( "FIT_ALL" ),        myRangeGrp );
00065   myModeHorRB  = new QRadioButton( tr( "FIT_HORIZONTAL" ), myRangeGrp );
00066   myModeVerRB  = new QRadioButton( tr( "FIT_VERTICAL" ),   myRangeGrp );
00067 
00068   QDoubleValidator* aValidator = new QDoubleValidator( this );
00069   myXMinEdit = new QLineEdit( myRangeGrp );
00070   myXMinEdit->setValidator( aValidator );
00071   myXMinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00072   myXMinEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
00073   myXMinEdit->setText( "0.0" );
00074 
00075   myYMinEdit = new QLineEdit( myRangeGrp );
00076   myYMinEdit->setValidator( aValidator );
00077   myYMinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00078   myYMinEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
00079   myYMinEdit->setText( "0.0" );
00080 
00081   myXMaxEdit = new QLineEdit( myRangeGrp );
00082   myXMaxEdit->setValidator( aValidator );
00083   myXMaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00084   myXMaxEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
00085   myXMaxEdit->setText( "0.0" );
00086 
00087   myYMaxEdit = new QLineEdit( myRangeGrp );
00088   myYMaxEdit->setValidator( aValidator );
00089   myYMaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00090   myYMaxEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
00091   myYMaxEdit->setText( "0.0" );
00092 
00093   if (mySecondAxisY) {
00094     myY2MinEdit = new QLineEdit( myRangeGrp );
00095     myY2MinEdit->setValidator( aValidator );
00096     myY2MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00097     myY2MinEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
00098     myY2MinEdit->setText( "0.0" );
00099 
00100     myY2MaxEdit = new QLineEdit( myRangeGrp );
00101     myY2MaxEdit->setValidator( aValidator );
00102     myY2MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00103     myY2MaxEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
00104     myY2MaxEdit->setText( "0.0" );
00105   }
00106 
00107   QFrame* aHLine = new QFrame( myRangeGrp );
00108   aHLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
00109 
00110   QHBoxLayout* aModeLayout = new QHBoxLayout;
00111   aModeLayout->setMargin( 0 );
00112   aModeLayout->setSpacing( SPACING_SIZE );
00113   aModeLayout->addWidget( myModeAllRB );
00114   aModeLayout->addWidget( myModeHorRB );
00115   aModeLayout->addWidget( myModeVerRB );
00116 
00117   QLabel* horLab = new QLabel( tr( "HORIZONTAL_AXIS" ), myRangeGrp );
00118   QLabel* verLab = new QLabel( tr( "VERTICAL_AXIS" ), myRangeGrp );
00119   if (mySecondAxisY)
00120     verLab->setText( tr( "VERTICAL_LEFT_AXIS" ) );
00121 
00122   QFont font = horLab->font(); font.setBold( true );
00123   horLab->setFont( font ); verLab->setFont( font );
00124 
00125   aGridLayout->addLayout( aModeLayout,    0, 0, 1, 5 );
00126   aGridLayout->addWidget( aHLine,         1, 0, 1, 5 );
00127   aGridLayout->addWidget( horLab,         2,    0 );
00128   aGridLayout->addWidget( new QLabel( tr( "MIN_VALUE_LAB" ), myRangeGrp ), 
00129                                           2,    1 );
00130   aGridLayout->addWidget( myXMinEdit,     2,    2 );
00131   aGridLayout->addWidget( new QLabel( tr( "MAX_VALUE_LAB" ), myRangeGrp ), 
00132                                           2,    3 );
00133   aGridLayout->addWidget( myXMaxEdit,     2,    4 );
00134   aGridLayout->addWidget( verLab,         3,    0 );
00135   aGridLayout->addWidget( new QLabel( tr( "MIN_VALUE_LAB" ), myRangeGrp ), 
00136                                           3,    1 );
00137   aGridLayout->addWidget( myYMinEdit,     3,    2 );
00138   aGridLayout->addWidget( new QLabel( tr( "MAX_VALUE_LAB" ), myRangeGrp ), 
00139                                           3,    3 );
00140   aGridLayout->addWidget( myYMaxEdit,     3,    4 );
00141 
00142   if (mySecondAxisY) {
00143     QLabel* ver2Lab = new QLabel(tr( "VERTICAL_RIGHT_AXIS" ), myRangeGrp );
00144     ver2Lab->setFont( font );
00145     aGridLayout->addWidget( ver2Lab,        4,    0 );
00146     aGridLayout->addWidget( new QLabel( tr( "MIN_VALUE_LAB" ), myRangeGrp ), 
00147                                             4,    1 );
00148     aGridLayout->addWidget( myY2MinEdit,    4,    2 );
00149     aGridLayout->addWidget( new QLabel( tr( "MAX_VALUE_LAB" ), myRangeGrp ), 
00150                                             4,    3 );
00151     aGridLayout->addWidget( myY2MaxEdit,    4,    4 );
00152   }
00153 
00154   // OK/Cancel buttons
00155   myOkBtn = new QPushButton( tr( "BUT_OK" ), this );
00156   myOkBtn->setObjectName( "buttonOk" );
00157   myOkBtn->setAutoDefault( TRUE );
00158   myOkBtn->setDefault( TRUE );
00159   myCancelBtn = new QPushButton(  tr( "BUT_CANCEL" ), this );
00160   myCancelBtn->setObjectName( "buttonCancel" );
00161   myCancelBtn->setAutoDefault( TRUE );
00162 
00163   topLayout->addWidget( myRangeGrp, 0, 0, 1, 3 );
00164   topLayout->addWidget( myOkBtn, 1, 0 );
00165   topLayout->setColumnStretch( 1, 5 );
00166   topLayout->addWidget( myCancelBtn, 1, 2 );
00167 
00168   // connect signals
00169   connect( myOkBtn,      SIGNAL( clicked() ),      this, SLOT( accept() ) );
00170   connect( myCancelBtn,  SIGNAL( clicked() ),      this, SLOT( reject() ) );
00171   connect( myRangeGrp,   SIGNAL( clicked( int ) ), this, SLOT( onModeChanged( int ) ) );
00172 
00173   // initial state
00174   myModeAllRB->setChecked( true );
00175   onModeChanged( 0 );
00176 }
00177 
00181 void Plot2d_FitDataDlg::setRange( const double xMin, 
00182                                   const double xMax,
00183                                   const double yMin,
00184                                   const double yMax,
00185                                   const double y2Min,
00186                                   const double y2Max) 
00187 {
00188   myXMinEdit->setText( QString::number( xMin ) );
00189   myXMaxEdit->setText( QString::number( xMax ) );
00190   myYMinEdit->setText( QString::number( yMin ) );
00191   myYMaxEdit->setText( QString::number( yMax ) );
00192   if (mySecondAxisY) {
00193     myY2MinEdit->setText( QString::number( y2Min ) );
00194     myY2MaxEdit->setText( QString::number( y2Max ) );
00195   }
00196 }
00197 
00201 int Plot2d_FitDataDlg::getRange( double& xMin, 
00202                                  double& xMax,
00203                                  double& yMin,
00204                                  double& yMax,
00205                                  double& y2Min,
00206                                  double& y2Max) 
00207 {
00208   xMin = myXMinEdit->text().toDouble();
00209   xMax = myXMaxEdit->text().toDouble();
00210   yMin = myYMinEdit->text().toDouble();
00211   yMax = myYMaxEdit->text().toDouble();
00212   if (mySecondAxisY) {
00213     y2Min = myY2MinEdit->text().toDouble();
00214     y2Max = myY2MaxEdit->text().toDouble();
00215   }
00216   else {
00217     y2Min = 0;
00218     y2Max = 0;
00219   }
00220   int myMode = 0;
00221   if ( myModeAllRB->isChecked() )
00222     myMode = 0;
00223   if ( myModeHorRB->isChecked() )
00224     myMode = 1;
00225   if ( myModeVerRB->isChecked() )
00226     myMode = 2;
00227   return myMode;
00228 }
00229 
00233 int Plot2d_FitDataDlg::getMode() 
00234 {
00235   int myMode = 0;
00236   if ( myModeAllRB->isChecked() )
00237     myMode = 0;
00238   if ( myModeHorRB->isChecked() )
00239     myMode = 1;
00240   if ( myModeVerRB->isChecked() )
00241     myMode = 2;
00242   return myMode;
00243 }
00244 
00248 void Plot2d_FitDataDlg::onModeChanged(int mode) 
00249 {
00250   bool badFocus;
00251   switch( mode ) {
00252   case 0: // fit all mode
00253     myXMinEdit->setEnabled(true);
00254     myXMaxEdit->setEnabled(true);
00255     myYMinEdit->setEnabled(true);
00256     myYMaxEdit->setEnabled(true);
00257     if (mySecondAxisY) {
00258       myY2MinEdit->setEnabled(true);
00259       myY2MaxEdit->setEnabled(true);
00260     }
00261     break;
00262   case 1: // fit horizontal mode
00263     badFocus = myYMinEdit->hasFocus() || myYMaxEdit->hasFocus();
00264     myXMinEdit->setEnabled(true);
00265     myXMaxEdit->setEnabled(true);
00266     myYMinEdit->setEnabled(false);
00267     myYMaxEdit->setEnabled(false);
00268     if (mySecondAxisY) {
00269       myY2MinEdit->setEnabled(false);
00270       myY2MaxEdit->setEnabled(false);
00271     }
00272     if (badFocus)
00273       myXMinEdit->setFocus();
00274     break;
00275   case 2: // fit vertical mode
00276     badFocus = myXMinEdit->hasFocus() || myXMaxEdit->hasFocus();
00277     myXMinEdit->setEnabled(false);
00278     myXMaxEdit->setEnabled(false);
00279     myYMinEdit->setEnabled(true);
00280     myYMaxEdit->setEnabled(true);
00281     if (mySecondAxisY) {
00282       myY2MinEdit->setEnabled(true);
00283       myY2MaxEdit->setEnabled(true);
00284     }
00285     if (badFocus)
00286       myYMinEdit->setFocus();
00287     break;
00288   }
00289 }
00290