Back to index

salome-gui  6.5.0
Plot2d_AnalyticalCurveDlg.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_AnalyticalCurveDlg.cxx
00024 // Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
00025 
00026 
00027 
00028 // TODO : check what happens if invalid formula is given, e.g. x/0
00029 // TODO : check what happens if curve formala is valid in general but some there are some problems with calculating (e.g. logarithmic formulas and negative x)
00030 
00031 //Local includes
00032 #include "Plot2d_AnalyticalCurveDlg.h"
00033 #include "Plot2d_AnalyticalCurve.h"
00034 #include "Plot2d_ViewFrame.h"
00035 
00036 //Qtx includes
00037 #include <QtxIntSpinBox.h>
00038 #include <QtxColorButton.h>
00039 
00040 //SUIT includes
00041 #include <SUIT_MessageBox.h>
00042 #include <SUIT_Session.h>
00043 #include <SUIT_Application.h>
00044 
00045 //Qt includes
00046 #include <QListWidget>
00047 #include <QGroupBox>
00048 #include <QFrame>
00049 #include <QHBoxLayout>
00050 #include <QLabel>
00051 #include <QLineEdit>
00052 #include <QCheckBox>
00053 #include <QComboBox>
00054 #include <QPushButton>
00055 
00056 //qwt includes
00057 #include <qwt_plot.h>
00058 
00059 // Controls
00060 const int MIN_NB_INTERVALS =     1;
00061 const int MAX_NB_INTERVALS = 10000;
00062 const int STEP             =     1;
00063 const int MIN_LINE_WIDTH   =     0;
00064 const int MAX_LINE_WIDTH   =    10;
00065 
00066 const char* PROP_TITLE       = "title";
00067 const char* PROP_VISIBLE     = "visible";
00068 const char* PROP_STATUS      = "status";
00069 const char* PROP_FORMULA     = "formula";
00070 const char* PROP_NBINTERVALS = "nb_intervals";
00071 const char* PROP_AUTOASSIGN  = "auto_assign";
00072 const char* PROP_MARKERTYPE  = "marker_type";
00073 const char* PROP_LINETYPE    = "line_type";
00074 const char* PROP_LINEWIDTH   = "line_width";
00075 const char* PROP_COLOR       = "color";
00076 
00077 /*
00078   \class Plot2d_AnalyticalCurveDlg::UpdateLocker
00079   \brief Update locker class
00080   \internal
00081 */
00082 class Plot2d_AnalyticalCurveDlg::UpdateLocker
00083 {
00084 public:
00085   UpdateLocker( QObject* );
00086   ~UpdateLocker();
00087 private:
00088   QObject* myObject;
00089   bool     myLocked;
00090 };
00091 
00092 Plot2d_AnalyticalCurveDlg::UpdateLocker::UpdateLocker( QObject* object ) : myObject( object )
00093 {
00094   myLocked = myObject->blockSignals( true );
00095 }
00096 
00097 Plot2d_AnalyticalCurveDlg::UpdateLocker::~UpdateLocker()
00098 {
00099   myObject->blockSignals( myLocked );
00100 }
00101 
00102 /*
00103   \class Plot2d_AnalyticalCurveDlg::Updater
00104   \brief Auxiliary class used for handle update requests from sub-widgets
00105   \internal
00106 */
00107 
00108 Plot2d_AnalyticalCurveDlg::Updater::Updater( QWidget* parent ) : QObject( parent )
00109 {/*nothing to do*/}
00110 
00111 Plot2d_AnalyticalCurveDlg::Updater::~Updater()
00112 {/*nothing to do*/}
00113 
00117 Plot2d_AnalyticalCurveDlg::Plot2d_AnalyticalCurveDlg( Plot2d_CurveContainer* container, QWidget* parent )
00118   : QDialog( parent ), myContainer( container )
00119 {
00120   setModal( true );
00121   setWindowTitle( tr( "ANALYTICAL_CURVE_TLT" ) );
00122   setSizeGripEnabled( true );
00123 
00124   // Curves list widget
00125   myCurvesList = new QListWidget( this );
00126   myCurvesList->setSelectionMode( QAbstractItemView::SingleSelection );
00127 
00128   // Curve parameters group box
00129   myCurveParams =  new QGroupBox( tr( "AC_CURVE_PARAMS" ), this );
00130 
00131   QLabel* formulaLabel     = new QLabel( tr( "AC_FORMULA" ), myCurveParams );
00132   myFormula                = new QLineEdit( myCurveParams );
00133   QLabel* nbIntervalsLabel = new QLabel( tr( "AC_NB_INTERVALS" ), myCurveParams );
00134   myNbIntervals            = new QtxIntSpinBox( MIN_NB_INTERVALS, MAX_NB_INTERVALS, STEP, myCurveParams );
00135 
00136   QGridLayout* paramsLayout = new QGridLayout( myCurveParams );
00137   paramsLayout->addWidget( formulaLabel,     0, 0 );
00138   paramsLayout->addWidget( myFormula,        0, 1 );
00139   paramsLayout->addWidget( nbIntervalsLabel, 1, 0 );
00140   paramsLayout->addWidget( myNbIntervals,    1, 1 );
00141 
00142   // Curve properties group box
00143   myCurveProps = new QGroupBox( tr( "AC_CURVE_PROPS" ), this );
00144 
00145   myAutoAssign           = new QCheckBox( tr( "AC_AUTO_ASSIGN" ), myCurveProps );
00146   myPropsGrp             = new QWidget( myCurveProps );
00147   QLabel* markerLabel    = new QLabel( tr( "AC_MARKER_TYPE" ), myPropsGrp );  
00148   myMarkerType           = new QComboBox( myPropsGrp );
00149   QLabel* lineTypeLabel  = new QLabel( tr( "AC_LINE_TYPE" ), myPropsGrp );  
00150   myLineType             = new QComboBox( myPropsGrp );
00151   QLabel* lineWidthLabel = new QLabel( tr( "AC_LINE_WIDTH" ), myPropsGrp );  
00152   myLineWidth            = new QtxIntSpinBox( MIN_LINE_WIDTH, MAX_LINE_WIDTH, STEP, myPropsGrp );
00153   QLabel* colorLabel     = new QLabel( tr("AC_CURVE_COLOR"), myPropsGrp );
00154   myColor                = new QtxColorButton( myPropsGrp );
00155 
00156   QGridLayout* propsGrpLayout = new QGridLayout( myPropsGrp );
00157   propsGrpLayout->addWidget( markerLabel,    0, 0 );
00158   propsGrpLayout->addWidget( myMarkerType,   0, 1 );
00159   propsGrpLayout->addWidget( lineTypeLabel,  1, 0 );
00160   propsGrpLayout->addWidget( myLineType,     1, 1 );
00161   propsGrpLayout->addWidget( lineWidthLabel, 2, 0 );
00162   propsGrpLayout->addWidget( myLineWidth,    2, 1 );
00163   propsGrpLayout->addWidget( colorLabel,     3, 0 );
00164   propsGrpLayout->addWidget( myColor,        3, 1 );
00165 
00166   QVBoxLayout* propsLayout = new QVBoxLayout( myCurveProps );
00167   propsLayout->addWidget( myAutoAssign );
00168   propsLayout->addWidget( myPropsGrp );
00169 
00170   // Add && Remove buttons
00171   myAddButton    = new QPushButton( tr("AC_ADD_BTN"), this );
00172   myAddButton->setAutoDefault( true );
00173   myRemoveButton = new QPushButton( tr("AC_REM_BTN"), this );
00174   myRemoveButton->setAutoDefault( true );
00175 
00176   // OK, Apply, Close, Help buttons
00177   QPushButton* okButton     = new QPushButton( tr( "AC_OK_BTN" ),     this );
00178   okButton->setDefault( true );
00179   okButton->setAutoDefault( true );
00180 
00181   QPushButton* applyButton     = new QPushButton( tr( "AC_APPLY_BTN" ),     this );
00182   applyButton->setAutoDefault( true );
00183 
00184   QPushButton* cancelButton = new QPushButton( tr( "AC_CLOSE_BTN" ), this );
00185   cancelButton->setAutoDefault( true );
00186   QPushButton* helpButton   = new QPushButton( tr( "AC_HELP_BTN" ),   this );
00187   helpButton->setAutoDefault( true );
00188   QHBoxLayout* btnLayout    = new QHBoxLayout;
00189   btnLayout->addWidget( okButton );
00190   btnLayout->addWidget( applyButton );
00191   btnLayout->addStretch();
00192   btnLayout->addWidget( cancelButton );
00193   btnLayout->addWidget( helpButton );
00194 
00195   QGridLayout* mainLayout = new QGridLayout( this );
00196   mainLayout->addWidget( myCurvesList,   0, 0, 3, 1 );
00197   mainLayout->addWidget( myCurveParams,  0, 1, 1, 2 );
00198   mainLayout->addWidget( myCurveProps,   1, 1, 1, 2 );
00199   mainLayout->addWidget( myAddButton,    2, 1 );
00200   mainLayout->addWidget( myRemoveButton, 2, 2 );
00201   mainLayout->addLayout( btnLayout,      3, 0, 1, 3 );
00202 
00203   // Fill combo boxes
00204   QColor cl = myMarkerType->palette().color( QPalette::Text ); // color to draw markers
00205   QSize  sz = QSize( 16, 16 );                                 // size of the icons for markers
00206   myMarkerType->setIconSize( sz );
00207 
00208   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::None ),      tr( "NONE_MARKER_LBL" ) );
00209   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Circle ),    tr( "CIRCLE_MARKER_LBL" ) );
00210   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Rectangle ), tr( "RECTANGLE_MARKER_LBL" ) );
00211   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Diamond ),   tr( "DIAMOND_MARKER_LBL" ) );
00212   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::DTriangle ), tr( "DTRIANGLE_MARKER_LBL" ) );
00213   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::UTriangle ), tr( "UTRIANGLE_MARKER_LBL" ) );
00214   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::LTriangle ), tr( "LTRIANGLE_MARKER_LBL" ) );
00215   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::RTriangle ), tr( "RTRIANGLE_MARKER_LBL" ) );
00216   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Cross ),     tr( "CROSS_MARKER_LBL" ) );
00217   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::XCross ),    tr( "XCROSS_MARKER_LBL" ) );
00218 
00219   cl = myLineType->palette().color( QPalette::Text ); // color to draw line types
00220   sz = QSize( 40, 16 );                               // size of the icons for line types
00221   myLineType->setIconSize( sz );
00222 
00223   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::NoPen ),      tr( "NONE_LINE_LBL" ) );
00224   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::Solid ),      tr( "SOLID_LINE_LBL" ) );
00225   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::Dash ),       tr( "DASH_LINE_LBL" ) );
00226   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::Dot ),        tr( "DOT_LINE_LBL" ) );
00227   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::DashDot ),    tr( "DASHDOT_LINE_LBL" ) );
00228   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::DashDotDot ), tr( "DAHSDOTDOT_LINE_LBL" ) );
00229 
00230   // Connections
00231   myUpdater = new Updater( this );
00232   connect( myUpdater,      SIGNAL( update()  ),                       this, SLOT( updateCurve() ) );
00233   connect( myFormula,      SIGNAL( textChanged( QString ) ),          myUpdater, SIGNAL( update() ) );
00234   connect( myNbIntervals,  SIGNAL( valueChanged( int ) ),             myUpdater, SIGNAL( update() ) );
00235   connect( myAutoAssign,   SIGNAL( stateChanged( int ) ),             myUpdater, SIGNAL( update() ) );
00236   connect( myMarkerType,   SIGNAL( activated( int ) ),                myUpdater, SIGNAL( update() ) );
00237   connect( myLineType,     SIGNAL( activated( int ) ),                myUpdater, SIGNAL( update() ) );
00238   connect( myLineWidth,    SIGNAL( valueChanged( int ) ),             myUpdater, SIGNAL( update() ) );
00239   connect( myColor,        SIGNAL( changed( QColor ) ),               myUpdater, SIGNAL( update() ) );
00240   connect( myCurvesList,   SIGNAL( itemChanged( QListWidgetItem* ) ), myUpdater, SIGNAL( update() ) );
00241   connect( myCurvesList,   SIGNAL( itemSelectionChanged() ),          this, SLOT( selectionChanged() ) );
00242   connect( myAddButton,    SIGNAL( clicked() ),                       this, SLOT( addCurve() ) );
00243   connect( myRemoveButton, SIGNAL( clicked()),                        this, SLOT( removeCurve() ) );
00244   connect( okButton,       SIGNAL( clicked() ),                       this, SLOT( accept() ) );
00245   connect( applyButton,    SIGNAL( clicked() ),                       this, SLOT( apply() ) );
00246   connect( cancelButton,   SIGNAL( clicked() ),                       this, SLOT( reject() ) );
00247   connect( helpButton,     SIGNAL( clicked() ),                       this, SLOT( help() ) );
00248 
00249   // Initialize dialog box
00250   init();
00251 }
00252 
00256 Plot2d_AnalyticalCurveDlg::~Plot2d_AnalyticalCurveDlg()
00257 {
00258 }
00259 
00260 void Plot2d_AnalyticalCurveDlg::init()
00261 {
00262   AnalyticalCurveList curves = myContainer->getAnalyticalCurves();
00263   foreach ( Plot2d_AnalyticalCurve* curve, curves ) {
00264     QListWidgetItem* item = new QListWidgetItem( curve->getName() );
00265     item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
00266     item->setCheckState( curve->isActive() ? Qt::Checked : Qt::Unchecked );
00267     initPropsFromCurve(curve);
00268     QVariant var;
00269     var.setValue( (void*)curve );
00270     item->setData( Qt::UserRole, var );
00271     myCurvesList->addItem( item );
00272 
00273     if ( !myCurvesList->currentItem() )
00274       myCurvesList->setCurrentItem( item );
00275   }
00276   
00277   selectionChanged();
00278 }
00279 
00283 void Plot2d_AnalyticalCurveDlg::initPropsFromCurve(Plot2d_AnalyticalCurve* curve) {
00284   myProperties[ curve ][ PROP_TITLE ]         = curve->getName();
00285   myProperties[ curve ][ PROP_VISIBLE ]       = curve->isActive();
00286   myProperties[ curve ][ PROP_FORMULA ]       = curve->getExpression();
00287   myProperties[ curve ][ PROP_NBINTERVALS ]   = (int)curve->getNbIntervals();
00288   myProperties[ curve ][ PROP_AUTOASSIGN ]    = curve->isAutoAssign();
00289   myProperties[ curve ][ PROP_MARKERTYPE ]  = curve->getMarker();
00290   myProperties[ curve ][ PROP_LINETYPE ]    = curve->getLine();
00291   myProperties[ curve ][ PROP_LINEWIDTH ]   = curve->getLineWidth();
00292   myProperties[ curve ][ PROP_COLOR ]       = curve->getColor();
00293   myProperties[ curve ][ PROP_STATUS ]        = ItemExisting;
00294 }
00295 
00296 QwtPlot* Plot2d_AnalyticalCurveDlg::getPlot() {
00297   Plot2d_ViewFrame* frame = dynamic_cast<Plot2d_ViewFrame*>(myContainer);
00298   if( frame )
00299        return frame->getPlot();
00300   return 0;
00301 }
00302 
00306 bool Plot2d_AnalyticalCurveDlg::processCurves() {
00307   // update curves
00308 
00309   QwtPlot* plot = getPlot();
00310   if(!plot)
00311          return false;
00312 
00313   PropMap::Iterator it;
00314   for ( it = myProperties.begin(); it != myProperties.end(); ++it ) {
00315     Plot2d_AnalyticalCurve* curve = it.key();
00316     if ( propStatus( curve ) == ItemRemoved ) {
00317       myContainer->removeAnalyticalCurve( curve );
00318       continue;
00319     }
00320     curve->setName( propTitle( curve ) );
00321     curve->setActive( propVisible( curve ) );
00322     curve->setExpression( propFormula( curve ) );
00323     curve->setNbIntervals( propIntervals(curve) );
00324     bool prevValue = curve->isAutoAssign();
00325     curve->setAutoAssign( propAutoAssign( curve ) );
00326     if ( !curve->isAutoAssign() ) {
00327       curve->setMarker( propMarkerType( curve ) );
00328       curve->setLine( propLineType( curve ) );
00329       curve->setLineWidth( propLineWidth( curve ) );
00330       curve->setColor( propColor( curve ) );
00331     }  else {
00332       if(!prevValue){
00333        curve->autoFill(plot);
00334       }
00335     }
00336     
00337     if (! curve->checkCurve(plot) ) {
00338       QListWidgetItem* item = getItem(curve);
00339       if(item) {
00340        myCurvesList->setCurrentItem( item );
00341        SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "AC_CANT_CALCULATE" ) );
00342       }
00343       return false;  
00344     }
00345     
00346     if ( propStatus( curve ) == ItemAdded ) {
00347       myContainer->addAnalyticalCurve( curve );
00348       myProperties[ curve ][ PROP_STATUS ] = ItemExisting;
00349     }
00350   }
00351   return true;
00352 }
00353 
00357 void Plot2d_AnalyticalCurveDlg::apply() {
00358   if(processCurves()) {
00359     Plot2d_ViewFrame* f = dynamic_cast<Plot2d_ViewFrame*>(myContainer);
00360     if(f)
00361       f->updateAnalyticalCurves();
00362     
00363     AnalyticalCurveList curves = myContainer->getAnalyticalCurves();
00364     foreach ( Plot2d_AnalyticalCurve* curve, curves ) {
00365       initPropsFromCurve(curve);
00366     }
00367     selectionChanged();
00368   }
00369 }
00370 
00374 void Plot2d_AnalyticalCurveDlg::accept()
00375 {
00376   if(processCurves())
00377     QDialog::accept();
00378 }
00379 
00383 void Plot2d_AnalyticalCurveDlg::reject()
00384 {
00385   // clean-up curves just created
00386   PropMap::Iterator it;
00387   for ( it = myProperties.begin(); it != myProperties.end(); ++it ) {
00388     Plot2d_AnalyticalCurve* curve = it.key();
00389     if ( propStatus( curve ) == ItemAdded )
00390       delete curve;
00391   }
00392   QDialog::reject();
00393 }
00394 
00398 void Plot2d_AnalyticalCurveDlg::addCurve()
00399 {
00400   Plot2d_AnalyticalCurve* curve = new Plot2d_AnalyticalCurve();
00401   
00402   if(curve->isAutoAssign()) {
00403     QwtPlot* plot = getPlot();
00404     if(plot)
00405       curve->autoFill(plot);
00406   }
00407   
00408   QListWidgetItem* item = new QListWidgetItem(curve->getName()); 
00409   item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
00410   item->setCheckState( Qt::Checked );
00411   QVariant var;
00412   var.setValue( (void*)curve );
00413   item->setData( Qt::UserRole, var );
00414   myCurvesList->addItem( item );
00415   
00416   myProperties[ curve ][ PROP_STATUS ] = ItemAdded;
00417   
00418   myCurvesList->setCurrentItem( item );
00419 }
00420 
00424 void Plot2d_AnalyticalCurveDlg::removeCurve()
00425 {
00426   QList<QListWidgetItem*> items = myCurvesList->selectedItems();
00427   foreach( QListWidgetItem* item, items ) {
00428     Plot2d_AnalyticalCurve* curve = (Plot2d_AnalyticalCurve*)( item->data( Qt::UserRole ).value<void*>() );
00429     delete item;
00430     if ( propStatus( curve ) == ItemAdded ) {
00431       myProperties.remove( curve );
00432       delete curve;
00433     }
00434     else {
00435       myProperties[ curve ][ PROP_STATUS ] = ItemRemoved;
00436     }
00437   }
00438 }
00439 
00443 void Plot2d_AnalyticalCurveDlg::updateCurve()
00444 {
00445   UpdateLocker lock( myUpdater );
00446   
00447   QListWidgetItem* item = selected();
00448   Plot2d_AnalyticalCurve* curve = selectedCurve();
00449   if ( item && curve ) {
00450     myProperties[ curve ][ PROP_TITLE ]       = item->text();
00451     myProperties[ curve ][ PROP_VISIBLE ]     = item->checkState() == Qt::Checked;
00452     myProperties[ curve ][ PROP_FORMULA ]     = myFormula->text();
00453     myProperties[ curve ][ PROP_NBINTERVALS ] = myNbIntervals->value();
00454     myProperties[ curve ][ PROP_AUTOASSIGN ]  = myAutoAssign->isChecked();
00455     myProperties[ curve ][ PROP_MARKERTYPE ]  = myMarkerType->currentIndex();
00456     myProperties[ curve ][ PROP_LINETYPE ]    = myLineType->currentIndex();
00457     myProperties[ curve ][ PROP_LINEWIDTH ]   = myLineWidth->value();
00458     myProperties[ curve ][ PROP_COLOR ]       = myColor->color();
00459   }
00460   
00461   updateState();
00462 }
00463 
00467 void Plot2d_AnalyticalCurveDlg::updateState()
00468 {
00469   myPropsGrp->setEnabled( !myAutoAssign->isChecked() );
00470   myCurveParams->setEnabled( selectedCurve() != 0 );
00471   myCurveProps->setEnabled( selectedCurve() != 0 );
00472   myRemoveButton->setEnabled( selectedCurve() != 0 );
00473 }
00474 
00478 void Plot2d_AnalyticalCurveDlg::selectionChanged()
00479 {  
00480   UpdateLocker lock( myUpdater );
00481 
00482   Plot2d_AnalyticalCurve* curve = selectedCurve();
00483 
00484   myFormula->setText( propFormula( curve ) );
00485   myNbIntervals->setValue( propIntervals( curve ) );
00486   myMarkerType->setCurrentIndex( (int)propMarkerType( curve ) );
00487   myLineType->setCurrentIndex( (int)propLineType( curve ) );
00488   myLineWidth->setValue( propLineWidth( curve ) );
00489   myColor->setColor( propColor( curve ) );
00490   myAutoAssign->setChecked( propAutoAssign( curve ) );
00491 
00492   updateState();
00493 }
00494 
00498 void Plot2d_AnalyticalCurveDlg::help()
00499 {
00500   SUIT_Application* app = SUIT_Session::session()->activeApplication();
00501   if ( app )
00502     app->onHelpContextModule( "GUI", "plot2d_viewer_page.html", "analytical_curve" );
00503 }
00504 
00508 QListWidgetItem* Plot2d_AnalyticalCurveDlg::selected() const
00509 {
00510   QList<QListWidgetItem*> items = myCurvesList->selectedItems();
00511   return items.count() > 0 ? items[0] : 0;
00512 }
00513 
00517 QListWidgetItem* Plot2d_AnalyticalCurveDlg::getItem(Plot2d_AnalyticalCurve* theCurve) const
00518 {
00519   int nb = myCurvesList->count();
00520   QListWidgetItem* item = 0;
00521   for(int i = 0; i < nb ; i++) {   
00522     item = myCurvesList->item(i);
00523     if(item->data( Qt::UserRole ).value<void*>() == theCurve)
00524       break;
00525   }
00526   return item;
00527 }
00528 
00532 Plot2d_AnalyticalCurve* Plot2d_AnalyticalCurveDlg::selectedCurve() const
00533 {
00534   return selected() ? (Plot2d_AnalyticalCurve*)( selected()->data( Qt::UserRole ).value<void*>() ) : 0;
00535 }
00536 
00540 int Plot2d_AnalyticalCurveDlg::propStatus( Plot2d_AnalyticalCurve* curve, const int def )
00541 {
00542   int val = def;
00543   if ( curve ) {
00544     if ( !myProperties.contains( curve ) )
00545       myProperties[ curve ] = CurveProps();
00546     if ( !myProperties[ curve ].contains( PROP_STATUS ) )
00547       myProperties[ curve ][ PROP_STATUS ] = def;
00548     QVariant v = myProperties[ curve ][ PROP_STATUS ];
00549     if ( v.isValid() && v.type() == QVariant::Int ) val = v.toInt();
00550   }
00551   return val;
00552 }
00553 
00557 QString Plot2d_AnalyticalCurveDlg::propTitle( Plot2d_AnalyticalCurve* curve, const QString& def )
00558 {
00559   QString val = def;
00560   if ( curve ) {
00561     if ( !myProperties.contains( curve ) )
00562       myProperties[ curve ] = CurveProps();
00563     if ( !myProperties[ curve ].contains( PROP_TITLE ) )
00564       myProperties[ curve ][ PROP_TITLE ] = def;
00565     QVariant v = myProperties[ curve ][ PROP_TITLE ];
00566     if ( v.isValid() && v.type() == QVariant::String ) val = v.toString();
00567   }
00568   return val;
00569 }
00570 
00574 bool Plot2d_AnalyticalCurveDlg::propVisible( Plot2d_AnalyticalCurve* curve, bool def )
00575 {
00576   bool val = def;
00577   if ( curve ) {
00578     if ( !myProperties.contains( curve ) )
00579       myProperties[ curve ] = CurveProps();
00580     if ( !myProperties[ curve ].contains( PROP_VISIBLE ) )
00581       myProperties[ curve ][ PROP_VISIBLE ] = def;
00582     QVariant v = myProperties[ curve ][ PROP_VISIBLE ];
00583     if ( v.isValid() && v.type() == QVariant::Bool ) val = v.toBool();
00584   }
00585   return val;
00586 }
00587 
00591 QString Plot2d_AnalyticalCurveDlg::propFormula( Plot2d_AnalyticalCurve* curve, const QString& def )
00592 {
00593   QString val = def;
00594   if ( curve ) {
00595     if ( !myProperties.contains( curve ) )
00596       myProperties[ curve ] = CurveProps();
00597     if ( !myProperties[ curve ].contains( PROP_FORMULA ) )
00598       myProperties[ curve ][ PROP_FORMULA ] = def;
00599     QVariant v = myProperties[ curve ][ PROP_FORMULA ];
00600     if ( v.isValid() && v.type() == QVariant::String ) val = v.toString();
00601   }
00602   return val;
00603 }
00604 
00608 int Plot2d_AnalyticalCurveDlg::propIntervals( Plot2d_AnalyticalCurve* curve, int def )
00609 {
00610   int val = def;
00611   if ( curve ) {
00612     if ( !myProperties.contains( curve ) )
00613       myProperties[ curve ] = CurveProps();
00614     if ( !myProperties[ curve ].contains( PROP_NBINTERVALS ) )
00615       myProperties[ curve ][ PROP_NBINTERVALS ] = def;
00616     QVariant v = myProperties[ curve ][ PROP_NBINTERVALS ];
00617     if ( v.isValid() && v.type() == QVariant::Int ) val = v.toInt();
00618   }
00619   return val;
00620 }
00621 
00625 Plot2d::MarkerType Plot2d_AnalyticalCurveDlg::propMarkerType( Plot2d_AnalyticalCurve* curve, Plot2d::MarkerType def )
00626 {
00627   Plot2d::MarkerType val = def;
00628   if ( curve ) {
00629     if ( !myProperties.contains( curve ) )
00630       myProperties[ curve ] = CurveProps();
00631     if ( !myProperties[ curve ].contains( PROP_MARKERTYPE ) )
00632       myProperties[ curve ][ PROP_MARKERTYPE ] = def;
00633     QVariant v = myProperties[ curve ][ PROP_MARKERTYPE ];
00634     if ( v.isValid() && v.type() == QVariant::Int ) val = (Plot2d::MarkerType)( v.toInt() );
00635   }
00636   return val;
00637 }
00638 
00642 Plot2d::LineType Plot2d_AnalyticalCurveDlg::propLineType( Plot2d_AnalyticalCurve* curve, Plot2d::LineType def )
00643 {
00644   Plot2d::LineType val = def;
00645   if ( curve ) {
00646     if ( !myProperties.contains( curve ) )
00647       myProperties[ curve ] = CurveProps();
00648     if ( !myProperties[ curve ].contains( PROP_LINETYPE ) )
00649       myProperties[ curve ][ PROP_LINETYPE ] = def;
00650     QVariant v = myProperties[ curve ][ PROP_LINETYPE ];
00651     if ( v.isValid() && v.type() == QVariant::Int ) val = (Plot2d::LineType)( v.toInt() );
00652   }
00653   return val;
00654 }
00655 
00659 int Plot2d_AnalyticalCurveDlg::propLineWidth( Plot2d_AnalyticalCurve* curve, int def )
00660 {
00661   int val = def;
00662   if ( curve ) {
00663     if ( !myProperties.contains( curve ) )
00664       myProperties[ curve ] = CurveProps();
00665     if ( !myProperties[ curve ].contains( PROP_LINEWIDTH ) )
00666       myProperties[ curve ][ PROP_LINEWIDTH ] = def;
00667     QVariant v = myProperties[ curve ][ PROP_LINEWIDTH ];
00668     if ( v.isValid() && v.type() == QVariant::Int ) val = v.toInt();
00669   }
00670   return val;
00671 }
00672 
00676 QColor Plot2d_AnalyticalCurveDlg::propColor( Plot2d_AnalyticalCurve* curve, const QColor& def )
00677 {
00678   QColor val = def;
00679   if ( curve ) {
00680     if ( !myProperties.contains( curve ) )
00681       myProperties[ curve ] = CurveProps();
00682     if ( !myProperties[ curve ].contains( PROP_COLOR ) )
00683       myProperties[ curve ][ PROP_COLOR ] = def;
00684     QVariant v = myProperties[ curve ][ PROP_COLOR ];
00685     if ( v.isValid() && v.type() == QVariant::Color ) val = v.value<QColor>();
00686   }
00687   return val;
00688 }
00689 
00693 bool Plot2d_AnalyticalCurveDlg::propAutoAssign( Plot2d_AnalyticalCurve* curve, bool def )
00694 {
00695   bool val = def;
00696   if ( curve ) {
00697     if ( !myProperties.contains( curve ) )
00698       myProperties[ curve ] = CurveProps();
00699     if ( !myProperties[ curve ].contains( PROP_AUTOASSIGN ) )
00700       myProperties[ curve ][ PROP_AUTOASSIGN ] = def;
00701     QVariant v = myProperties[ curve ][ PROP_AUTOASSIGN ];
00702     if ( v.isValid() && v.type() == QVariant::Bool ) val = v.toBool();
00703   }
00704   return val;
00705 }