Salome HOME
Redesign SALOME documentation
[modules/gui.git] / src / Plot2d / Plot2d_AnalyticalCurveDlg.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : Plot2d_AnalyticalCurveDlg.cxx
24 // Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
25
26
27
28 // TODO : check what happens if invalid formula is given, e.g. x/0
29 // 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)
30
31 //Local includes
32 #include "Plot2d_AnalyticalCurveDlg.h"
33 #include "Plot2d_AnalyticalCurve.h"
34 #include "Plot2d_ViewFrame.h"
35
36 //Qtx includes
37 #include <QtxIntSpinBox.h>
38 #include <QtxColorButton.h>
39
40 //SUIT includes
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_Application.h>
44
45 //Qt includes
46 #include <QListWidget>
47 #include <QGroupBox>
48 #include <QFrame>
49 #include <QHBoxLayout>
50 #include <QLabel>
51 #include <QLineEdit>
52 #include <QCheckBox>
53 #include <QComboBox>
54 #include <QPushButton>
55
56 //qwt includes
57 #include <qwt_plot.h>
58
59 // Controls
60 const int MIN_NB_INTERVALS =     1;
61 const int MAX_NB_INTERVALS = 10000;
62 const int STEP             =     1;
63 const int MIN_LINE_WIDTH   =     0;
64 const int MAX_LINE_WIDTH   =    10;
65
66 const char* PROP_TITLE       = "title";
67 const char* PROP_VISIBLE     = "visible";
68 const char* PROP_STATUS      = "status";
69 const char* PROP_FORMULA     = "formula";
70 const char* PROP_NBINTERVALS = "nb_intervals";
71 const char* PROP_AUTOASSIGN  = "auto_assign";
72 const char* PROP_MARKERTYPE  = "marker_type";
73 const char* PROP_LINETYPE    = "line_type";
74 const char* PROP_LINEWIDTH   = "line_width";
75 const char* PROP_COLOR       = "color";
76
77 /*
78   \class Plot2d_AnalyticalCurveDlg::UpdateLocker
79   \brief Update locker class
80   \internal
81 */
82 class Plot2d_AnalyticalCurveDlg::UpdateLocker
83 {
84 public:
85   UpdateLocker( QObject* );
86   ~UpdateLocker();
87 private:
88   QObject* myObject;
89   bool     myLocked;
90 };
91
92 Plot2d_AnalyticalCurveDlg::UpdateLocker::UpdateLocker( QObject* object ) : myObject( object )
93 {
94   myLocked = myObject->blockSignals( true );
95 }
96
97 Plot2d_AnalyticalCurveDlg::UpdateLocker::~UpdateLocker()
98 {
99   myObject->blockSignals( myLocked );
100 }
101
102 /*
103   \class Plot2d_AnalyticalCurveDlg::Updater
104   \brief Auxiliary class used for handle update requests from sub-widgets
105   \internal
106 */
107
108 Plot2d_AnalyticalCurveDlg::Updater::Updater( QWidget* parent ) : QObject( parent )
109 {/*nothing to do*/}
110
111 Plot2d_AnalyticalCurveDlg::Updater::~Updater()
112 {/*nothing to do*/}
113
114 /*!
115   Constructor 
116 */
117 Plot2d_AnalyticalCurveDlg::Plot2d_AnalyticalCurveDlg( Plot2d_CurveContainer* container, QWidget* parent )
118   : QDialog( parent ), myContainer( container )
119 {
120   setModal( true );
121   setWindowTitle( tr( "ANALYTICAL_CURVE_TLT" ) );
122   setSizeGripEnabled( true );
123
124   // Curves list widget
125   myCurvesList = new QListWidget( this );
126   myCurvesList->setSelectionMode( QAbstractItemView::SingleSelection );
127
128   // Curve parameters group box
129   myCurveParams =  new QGroupBox( tr( "AC_CURVE_PARAMS" ), this );
130
131   QLabel* formulaLabel     = new QLabel( tr( "AC_FORMULA" ), myCurveParams );
132   myFormula                = new QLineEdit( myCurveParams );
133   QLabel* nbIntervalsLabel = new QLabel( tr( "AC_NB_INTERVALS" ), myCurveParams );
134   myNbIntervals            = new QtxIntSpinBox( MIN_NB_INTERVALS, MAX_NB_INTERVALS, STEP, myCurveParams );
135
136   QGridLayout* paramsLayout = new QGridLayout( myCurveParams );
137   paramsLayout->addWidget( formulaLabel,     0, 0 );
138   paramsLayout->addWidget( myFormula,        0, 1 );
139   paramsLayout->addWidget( nbIntervalsLabel, 1, 0 );
140   paramsLayout->addWidget( myNbIntervals,    1, 1 );
141
142   // Curve properties group box
143   myCurveProps = new QGroupBox( tr( "AC_CURVE_PROPS" ), this );
144
145   myAutoAssign           = new QCheckBox( tr( "AC_AUTO_ASSIGN" ), myCurveProps );
146   myPropsGrp             = new QWidget( myCurveProps );
147   QLabel* markerLabel    = new QLabel( tr( "AC_MARKER_TYPE" ), myPropsGrp );  
148   myMarkerType           = new QComboBox( myPropsGrp );
149   QLabel* lineTypeLabel  = new QLabel( tr( "AC_LINE_TYPE" ), myPropsGrp );  
150   myLineType             = new QComboBox( myPropsGrp );
151   QLabel* lineWidthLabel = new QLabel( tr( "AC_LINE_WIDTH" ), myPropsGrp );  
152   myLineWidth            = new QtxIntSpinBox( MIN_LINE_WIDTH, MAX_LINE_WIDTH, STEP, myPropsGrp );
153   QLabel* colorLabel     = new QLabel( tr("AC_CURVE_COLOR"), myPropsGrp );
154   myColor                = new QtxColorButton( myPropsGrp );
155
156   QGridLayout* propsGrpLayout = new QGridLayout( myPropsGrp );
157   propsGrpLayout->addWidget( markerLabel,    0, 0 );
158   propsGrpLayout->addWidget( myMarkerType,   0, 1 );
159   propsGrpLayout->addWidget( lineTypeLabel,  1, 0 );
160   propsGrpLayout->addWidget( myLineType,     1, 1 );
161   propsGrpLayout->addWidget( lineWidthLabel, 2, 0 );
162   propsGrpLayout->addWidget( myLineWidth,    2, 1 );
163   propsGrpLayout->addWidget( colorLabel,     3, 0 );
164   propsGrpLayout->addWidget( myColor,        3, 1 );
165
166   QVBoxLayout* propsLayout = new QVBoxLayout( myCurveProps );
167   propsLayout->addWidget( myAutoAssign );
168   propsLayout->addWidget( myPropsGrp );
169
170   // Add && Remove buttons
171   myAddButton    = new QPushButton( tr("AC_ADD_BTN"), this );
172   myAddButton->setAutoDefault( true );
173   myRemoveButton = new QPushButton( tr("AC_REM_BTN"), this );
174   myRemoveButton->setAutoDefault( true );
175
176   // OK, Apply, Close, Help buttons
177   QPushButton* okButton     = new QPushButton( tr( "AC_OK_BTN" ),     this );
178   okButton->setDefault( true );
179   okButton->setAutoDefault( true );
180
181   QPushButton* applyButton     = new QPushButton( tr( "AC_APPLY_BTN" ),     this );
182   applyButton->setAutoDefault( true );
183
184   QPushButton* cancelButton = new QPushButton( tr( "AC_CLOSE_BTN" ), this );
185   cancelButton->setAutoDefault( true );
186   QPushButton* helpButton   = new QPushButton( tr( "AC_HELP_BTN" ),   this );
187   helpButton->setAutoDefault( true );
188   QHBoxLayout* btnLayout    = new QHBoxLayout;
189   btnLayout->addWidget( okButton );
190   btnLayout->addWidget( applyButton );
191   btnLayout->addStretch();
192   btnLayout->addWidget( cancelButton );
193   btnLayout->addWidget( helpButton );
194
195   QGridLayout* mainLayout = new QGridLayout( this );
196   mainLayout->addWidget( myCurvesList,   0, 0, 3, 1 );
197   mainLayout->addWidget( myCurveParams,  0, 1, 1, 2 );
198   mainLayout->addWidget( myCurveProps,   1, 1, 1, 2 );
199   mainLayout->addWidget( myAddButton,    2, 1 );
200   mainLayout->addWidget( myRemoveButton, 2, 2 );
201   mainLayout->addLayout( btnLayout,      3, 0, 1, 3 );
202
203   // Fill combo boxes
204   QColor cl = myMarkerType->palette().color( QPalette::Text ); // color to draw markers
205   QSize  sz = QSize( 16, 16 );                                 // size of the icons for markers
206   myMarkerType->setIconSize( sz );
207
208   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::None ),      tr( "NONE_MARKER_LBL" ) );
209   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Circle ),    tr( "CIRCLE_MARKER_LBL" ) );
210   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Rectangle ), tr( "RECTANGLE_MARKER_LBL" ) );
211   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Diamond ),   tr( "DIAMOND_MARKER_LBL" ) );
212   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::DTriangle ), tr( "DTRIANGLE_MARKER_LBL" ) );
213   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::UTriangle ), tr( "UTRIANGLE_MARKER_LBL" ) );
214   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::LTriangle ), tr( "LTRIANGLE_MARKER_LBL" ) );
215   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::RTriangle ), tr( "RTRIANGLE_MARKER_LBL" ) );
216   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Cross ),     tr( "CROSS_MARKER_LBL" ) );
217   myMarkerType->addItem( Plot2d::markerIcon( sz, cl, Plot2d::XCross ),    tr( "XCROSS_MARKER_LBL" ) );
218
219   cl = myLineType->palette().color( QPalette::Text ); // color to draw line types
220   sz = QSize( 40, 16 );                               // size of the icons for line types
221   myLineType->setIconSize( sz );
222
223   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::NoPen ),      tr( "NONE_LINE_LBL" ) );
224   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::Solid ),      tr( "SOLID_LINE_LBL" ) );
225   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::Dash ),       tr( "DASH_LINE_LBL" ) );
226   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::Dot ),        tr( "DOT_LINE_LBL" ) );
227   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::DashDot ),    tr( "DASHDOT_LINE_LBL" ) );
228   myLineType->addItem( Plot2d::lineIcon( sz, cl, Plot2d::DashDotDot ), tr( "DAHSDOTDOT_LINE_LBL" ) );
229
230   // Connections
231   myUpdater = new Updater( this );
232   connect( myUpdater,      SIGNAL( update()  ),                       this, SLOT( updateCurve() ) );
233   connect( myFormula,      SIGNAL( textChanged( QString ) ),          myUpdater, SIGNAL( update() ) );
234   connect( myNbIntervals,  SIGNAL( valueChanged( int ) ),             myUpdater, SIGNAL( update() ) );
235   connect( myAutoAssign,   SIGNAL( stateChanged( int ) ),             myUpdater, SIGNAL( update() ) );
236   connect( myMarkerType,   SIGNAL( activated( int ) ),                myUpdater, SIGNAL( update() ) );
237   connect( myLineType,     SIGNAL( activated( int ) ),                myUpdater, SIGNAL( update() ) );
238   connect( myLineWidth,    SIGNAL( valueChanged( int ) ),             myUpdater, SIGNAL( update() ) );
239   connect( myColor,        SIGNAL( changed( QColor ) ),               myUpdater, SIGNAL( update() ) );
240   connect( myCurvesList,   SIGNAL( itemChanged( QListWidgetItem* ) ), myUpdater, SIGNAL( update() ) );
241   connect( myCurvesList,   SIGNAL( itemSelectionChanged() ),          this, SLOT( selectionChanged() ) );
242   connect( myAddButton,    SIGNAL( clicked() ),                       this, SLOT( addCurve() ) );
243   connect( myRemoveButton, SIGNAL( clicked()),                        this, SLOT( removeCurve() ) );
244   connect( okButton,       SIGNAL( clicked() ),                       this, SLOT( accept() ) );
245   connect( applyButton,    SIGNAL( clicked() ),                       this, SLOT( apply() ) );
246   connect( cancelButton,   SIGNAL( clicked() ),                       this, SLOT( reject() ) );
247   connect( helpButton,     SIGNAL( clicked() ),                       this, SLOT( help() ) );
248
249   // Initialize dialog box
250   init();
251 }
252
253 /*!
254   Destructor
255 */
256 Plot2d_AnalyticalCurveDlg::~Plot2d_AnalyticalCurveDlg()
257 {
258 }
259
260 void Plot2d_AnalyticalCurveDlg::init()
261 {
262   AnalyticalCurveList curves = myContainer->getAnalyticalCurves();
263   foreach ( Plot2d_AnalyticalCurve* curve, curves ) {
264     QListWidgetItem* item = new QListWidgetItem( curve->getName() );
265     item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
266     item->setCheckState( curve->isActive() ? Qt::Checked : Qt::Unchecked );
267     initPropsFromCurve(curve);
268     QVariant var;
269     var.setValue( (void*)curve );
270     item->setData( Qt::UserRole, var );
271     myCurvesList->addItem( item );
272
273     if ( !myCurvesList->currentItem() )
274       myCurvesList->setCurrentItem( item );
275   }
276   
277   selectionChanged();
278 }
279
280 /*!
281  /brief Store curve properties in the local map.
282 */
283 void Plot2d_AnalyticalCurveDlg::initPropsFromCurve(Plot2d_AnalyticalCurve* curve) {
284   myProperties[ curve ][ PROP_TITLE ]         = curve->getName();
285   myProperties[ curve ][ PROP_VISIBLE ]       = curve->isActive();
286   myProperties[ curve ][ PROP_FORMULA ]       = curve->getExpression();
287   myProperties[ curve ][ PROP_NBINTERVALS ]   = (int)curve->getNbIntervals();
288   myProperties[ curve ][ PROP_AUTOASSIGN ]    = curve->isAutoAssign();
289   myProperties[ curve ][ PROP_MARKERTYPE ]  = curve->getMarker();
290   myProperties[ curve ][ PROP_LINETYPE ]    = curve->getLine();
291   myProperties[ curve ][ PROP_LINEWIDTH ]   = curve->getLineWidth();
292   myProperties[ curve ][ PROP_COLOR ]       = curve->getColor();
293   myProperties[ curve ][ PROP_STATUS ]        = ItemExisting;
294 }
295
296 QwtPlot* Plot2d_AnalyticalCurveDlg::getPlot() {
297   Plot2d_ViewFrame* frame = dynamic_cast<Plot2d_ViewFrame*>(myContainer);
298   if( frame )
299         return frame->getPlot();
300   return 0;
301 }
302
303 /*!
304  /brief Store local copy on the curves properties into curves.
305 */
306 bool Plot2d_AnalyticalCurveDlg::processCurves() {
307   // update curves
308
309   QwtPlot* plot = getPlot();
310   if(!plot)
311           return false;
312
313   PropMap::Iterator it;
314   for ( it = myProperties.begin(); it != myProperties.end(); ++it ) {
315     Plot2d_AnalyticalCurve* curve = it.key();
316     if ( propStatus( curve ) == ItemRemoved ) {
317       myContainer->removeAnalyticalCurve( curve );
318       continue;
319     }
320     curve->setName( propTitle( curve ) );
321     curve->setActive( propVisible( curve ) );
322     curve->setExpression( propFormula( curve ) );
323     curve->setNbIntervals( propIntervals(curve) );
324     bool prevValue = curve->isAutoAssign();
325     curve->setAutoAssign( propAutoAssign( curve ) );
326     if ( !curve->isAutoAssign() ) {
327       curve->setMarker( propMarkerType( curve ) );
328       curve->setLine( propLineType( curve ) );
329       curve->setLineWidth( propLineWidth( curve ) );
330       curve->setColor( propColor( curve ) );
331     }  else {
332       if(!prevValue){
333         curve->autoFill(plot);
334       }
335     }
336     
337     if (! curve->checkCurve(plot) ) {
338       QListWidgetItem* item = getItem(curve);
339       if(item) {
340         myCurvesList->setCurrentItem( item );
341         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "AC_CANT_CALCULATE" ) );
342       }
343       return false;     
344     }
345     
346     if ( propStatus( curve ) == ItemAdded ) {
347       myContainer->addAnalyticalCurve( curve );
348       myProperties[ curve ][ PROP_STATUS ] = ItemExisting;
349     }
350   }
351   return true;
352 }
353
354 /*!
355   \brief Private slot. Called when "Apply" button is clicked
356 */
357 void Plot2d_AnalyticalCurveDlg::apply() {
358   if(processCurves()) {
359     Plot2d_ViewFrame* f = dynamic_cast<Plot2d_ViewFrame*>(myContainer);
360     if(f)
361       f->updateAnalyticalCurves();
362     
363     AnalyticalCurveList curves = myContainer->getAnalyticalCurves();
364     foreach ( Plot2d_AnalyticalCurve* curve, curves ) {
365       initPropsFromCurve(curve);
366     }
367     selectionChanged();
368   }
369 }
370
371 /*!
372   \brief Private slot. Called when "Ok" button is clicked
373 */
374 void Plot2d_AnalyticalCurveDlg::accept()
375 {
376   if(processCurves())
377     QDialog::accept();
378 }
379
380 /*!
381   \brief Private slot. Called when "Close" button is clicked
382 */
383 void Plot2d_AnalyticalCurveDlg::reject()
384 {
385   // clean-up curves just created
386   PropMap::Iterator it;
387   for ( it = myProperties.begin(); it != myProperties.end(); ++it ) {
388     Plot2d_AnalyticalCurve* curve = it.key();
389     if ( propStatus( curve ) == ItemAdded )
390       delete curve;
391   }
392   QDialog::reject();
393 }
394
395 /*!
396   \brief Private slot. Called when "Add curve" button is clicked
397 */
398 void Plot2d_AnalyticalCurveDlg::addCurve()
399 {
400   Plot2d_AnalyticalCurve* curve = new Plot2d_AnalyticalCurve();
401   
402   if(curve->isAutoAssign()) {
403     QwtPlot* plot = getPlot();
404     if(plot)
405       curve->autoFill(plot);
406   }
407   
408   QListWidgetItem* item = new QListWidgetItem(curve->getName()); 
409   item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
410   item->setCheckState( Qt::Checked );
411   QVariant var;
412   var.setValue( (void*)curve );
413   item->setData( Qt::UserRole, var );
414   myCurvesList->addItem( item );
415   
416   myProperties[ curve ][ PROP_STATUS ] = ItemAdded;
417   
418   myCurvesList->setCurrentItem( item );
419 }
420
421 /*!
422   \brief Private slot. Called when "Remove curve" button is clicked
423 */
424 void Plot2d_AnalyticalCurveDlg::removeCurve()
425 {
426   QList<QListWidgetItem*> items = myCurvesList->selectedItems();
427   foreach( QListWidgetItem* item, items ) {
428     Plot2d_AnalyticalCurve* curve = (Plot2d_AnalyticalCurve*)( item->data( Qt::UserRole ).value<void*>() );
429     delete item;
430     if ( propStatus( curve ) == ItemAdded ) {
431       myProperties.remove( curve );
432       delete curve;
433     }
434     else {
435       myProperties[ curve ][ PROP_STATUS ] = ItemRemoved;
436     }
437   }
438 }
439
440 /*!
441   \brief Private slot. Called when any curve property is changed.
442 */
443 void Plot2d_AnalyticalCurveDlg::updateCurve()
444 {
445   UpdateLocker lock( myUpdater );
446   
447   QListWidgetItem* item = selected();
448   Plot2d_AnalyticalCurve* curve = selectedCurve();
449   if ( item && curve ) {
450     myProperties[ curve ][ PROP_TITLE ]       = item->text();
451     myProperties[ curve ][ PROP_VISIBLE ]     = item->checkState() == Qt::Checked;
452     myProperties[ curve ][ PROP_FORMULA ]     = myFormula->text();
453     myProperties[ curve ][ PROP_NBINTERVALS ] = myNbIntervals->value();
454     myProperties[ curve ][ PROP_AUTOASSIGN ]  = myAutoAssign->isChecked();
455     myProperties[ curve ][ PROP_MARKERTYPE ]  = myMarkerType->currentIndex();
456     myProperties[ curve ][ PROP_LINETYPE ]    = myLineType->currentIndex();
457     myProperties[ curve ][ PROP_LINEWIDTH ]   = myLineWidth->value();
458     myProperties[ curve ][ PROP_COLOR ]       = myColor->color();
459   }
460   
461   updateState();
462 }
463
464 /*!
465   \brief Private slot. Update widgets state.
466 */
467 void Plot2d_AnalyticalCurveDlg::updateState()
468 {
469   myPropsGrp->setEnabled( !myAutoAssign->isChecked() );
470   myCurveParams->setEnabled( selectedCurve() != 0 );
471   myCurveProps->setEnabled( selectedCurve() != 0 );
472   myRemoveButton->setEnabled( selectedCurve() != 0 );
473 }
474
475 /*!
476   \brief Private slot. Called when selection in the curve list is changed.
477 */
478 void Plot2d_AnalyticalCurveDlg::selectionChanged()
479 {  
480   UpdateLocker lock( myUpdater );
481
482   Plot2d_AnalyticalCurve* curve = selectedCurve();
483
484   myFormula->setText( propFormula( curve ) );
485   myNbIntervals->setValue( propIntervals( curve ) );
486   myMarkerType->setCurrentIndex( (int)propMarkerType( curve ) );
487   myLineType->setCurrentIndex( (int)propLineType( curve ) );
488   myLineWidth->setValue( propLineWidth( curve ) );
489   myColor->setColor( propColor( curve ) );
490   myAutoAssign->setChecked( propAutoAssign( curve ) );
491
492   updateState();
493 }
494
495 /*!
496   \brief Show help page
497 */
498 void Plot2d_AnalyticalCurveDlg::help()
499 {
500   SUIT_Application* app = SUIT_Session::session()->activeApplication();
501   if ( app )
502     app->onHelpContextModule( "GUI", "plot2d_viewer.html", "analytical-curve" );
503 }
504
505 /*!
506   \brief Get currently selected list widget item
507 */
508 QListWidgetItem* Plot2d_AnalyticalCurveDlg::selected() const
509 {
510   QList<QListWidgetItem*> items = myCurvesList->selectedItems();
511   return items.count() > 0 ? items[0] : 0;
512 }
513
514 /*!
515   \brief Get widget item by the curve
516 */
517 QListWidgetItem* Plot2d_AnalyticalCurveDlg::getItem(Plot2d_AnalyticalCurve* theCurve) const
518 {
519   int nb = myCurvesList->count();
520   QListWidgetItem* item = 0;
521   for(int i = 0; i < nb ; i++) {        
522     item = myCurvesList->item(i);
523     if(item->data( Qt::UserRole ).value<void*>() == theCurve)
524       break;
525   }
526   return item;
527 }
528
529 /*!
530   \brief Get currently selected curve
531 */
532 Plot2d_AnalyticalCurve* Plot2d_AnalyticalCurveDlg::selectedCurve() const
533 {
534   return selected() ? (Plot2d_AnalyticalCurve*)( selected()->data( Qt::UserRole ).value<void*>() ) : 0;
535 }
536
537 /*!
538   \brief Get curve property: status
539 */
540 int Plot2d_AnalyticalCurveDlg::propStatus( Plot2d_AnalyticalCurve* curve, const int def )
541 {
542   int val = def;
543   if ( curve ) {
544     if ( !myProperties.contains( curve ) )
545       myProperties[ curve ] = CurveProps();
546     if ( !myProperties[ curve ].contains( PROP_STATUS ) )
547       myProperties[ curve ][ PROP_STATUS ] = def;
548     QVariant v = myProperties[ curve ][ PROP_STATUS ];
549     if ( v.isValid() && v.type() == QVariant::Int ) val = v.toInt();
550   }
551   return val;
552 }
553
554 /*!
555   \brief Get curve property: title
556 */
557 QString Plot2d_AnalyticalCurveDlg::propTitle( Plot2d_AnalyticalCurve* curve, const QString& def )
558 {
559   QString val = def;
560   if ( curve ) {
561     if ( !myProperties.contains( curve ) )
562       myProperties[ curve ] = CurveProps();
563     if ( !myProperties[ curve ].contains( PROP_TITLE ) )
564       myProperties[ curve ][ PROP_TITLE ] = def;
565     QVariant v = myProperties[ curve ][ PROP_TITLE ];
566     if ( v.isValid() && v.type() == QVariant::String ) val = v.toString();
567   }
568   return val;
569 }
570
571 /*!
572   \brief Get curve property: visible flag
573 */
574 bool Plot2d_AnalyticalCurveDlg::propVisible( Plot2d_AnalyticalCurve* curve, bool def )
575 {
576   bool val = def;
577   if ( curve ) {
578     if ( !myProperties.contains( curve ) )
579       myProperties[ curve ] = CurveProps();
580     if ( !myProperties[ curve ].contains( PROP_VISIBLE ) )
581       myProperties[ curve ][ PROP_VISIBLE ] = def;
582     QVariant v = myProperties[ curve ][ PROP_VISIBLE ];
583     if ( v.isValid() && v.type() == QVariant::Bool ) val = v.toBool();
584   }
585   return val;
586 }
587
588 /*!
589   \brief Get curve property: formula
590 */
591 QString Plot2d_AnalyticalCurveDlg::propFormula( Plot2d_AnalyticalCurve* curve, const QString& def )
592 {
593   QString val = def;
594   if ( curve ) {
595     if ( !myProperties.contains( curve ) )
596       myProperties[ curve ] = CurveProps();
597     if ( !myProperties[ curve ].contains( PROP_FORMULA ) )
598       myProperties[ curve ][ PROP_FORMULA ] = def;
599     QVariant v = myProperties[ curve ][ PROP_FORMULA ];
600     if ( v.isValid() && v.type() == QVariant::String ) val = v.toString();
601   }
602   return val;
603 }
604
605 /*!
606   \brief Get curve property: nb intervals
607 */
608 int Plot2d_AnalyticalCurveDlg::propIntervals( Plot2d_AnalyticalCurve* curve, int def )
609 {
610   int val = def;
611   if ( curve ) {
612     if ( !myProperties.contains( curve ) )
613       myProperties[ curve ] = CurveProps();
614     if ( !myProperties[ curve ].contains( PROP_NBINTERVALS ) )
615       myProperties[ curve ][ PROP_NBINTERVALS ] = def;
616     QVariant v = myProperties[ curve ][ PROP_NBINTERVALS ];
617     if ( v.isValid() && v.type() == QVariant::Int ) val = v.toInt();
618   }
619   return val;
620 }
621
622 /*!
623   \brief Get curve property: marker type
624 */
625 Plot2d::MarkerType Plot2d_AnalyticalCurveDlg::propMarkerType( Plot2d_AnalyticalCurve* curve, Plot2d::MarkerType def )
626 {
627   Plot2d::MarkerType val = def;
628   if ( curve ) {
629     if ( !myProperties.contains( curve ) )
630       myProperties[ curve ] = CurveProps();
631     if ( !myProperties[ curve ].contains( PROP_MARKERTYPE ) )
632       myProperties[ curve ][ PROP_MARKERTYPE ] = def;
633     QVariant v = myProperties[ curve ][ PROP_MARKERTYPE ];
634     if ( v.isValid() && v.type() == QVariant::Int ) val = (Plot2d::MarkerType)( v.toInt() );
635   }
636   return val;
637 }
638
639 /*!
640   \brief Get curve property: line type
641 */
642 Plot2d::LineType Plot2d_AnalyticalCurveDlg::propLineType( Plot2d_AnalyticalCurve* curve, Plot2d::LineType def )
643 {
644   Plot2d::LineType val = def;
645   if ( curve ) {
646     if ( !myProperties.contains( curve ) )
647       myProperties[ curve ] = CurveProps();
648     if ( !myProperties[ curve ].contains( PROP_LINETYPE ) )
649       myProperties[ curve ][ PROP_LINETYPE ] = def;
650     QVariant v = myProperties[ curve ][ PROP_LINETYPE ];
651     if ( v.isValid() && v.type() == QVariant::Int ) val = (Plot2d::LineType)( v.toInt() );
652   }
653   return val;
654 }
655
656 /*!
657   \brief Get curve property: line width
658 */
659 int Plot2d_AnalyticalCurveDlg::propLineWidth( Plot2d_AnalyticalCurve* curve, int def )
660 {
661   int val = def;
662   if ( curve ) {
663     if ( !myProperties.contains( curve ) )
664       myProperties[ curve ] = CurveProps();
665     if ( !myProperties[ curve ].contains( PROP_LINEWIDTH ) )
666       myProperties[ curve ][ PROP_LINEWIDTH ] = def;
667     QVariant v = myProperties[ curve ][ PROP_LINEWIDTH ];
668     if ( v.isValid() && v.type() == QVariant::Int ) val = v.toInt();
669   }
670   return val;
671 }
672
673 /*!
674   \brief Get curve property: color
675 */
676 QColor Plot2d_AnalyticalCurveDlg::propColor( Plot2d_AnalyticalCurve* curve, const QColor& def )
677 {
678   QColor val = def;
679   if ( curve ) {
680     if ( !myProperties.contains( curve ) )
681       myProperties[ curve ] = CurveProps();
682     if ( !myProperties[ curve ].contains( PROP_COLOR ) )
683       myProperties[ curve ][ PROP_COLOR ] = def;
684     QVariant v = myProperties[ curve ][ PROP_COLOR ];
685     if ( v.isValid() && v.type() == QVariant::Color ) val = v.value<QColor>();
686   }
687   return val;
688 }
689
690 /*!
691   \brief Get curve property: auto-assign flag
692 */
693 bool Plot2d_AnalyticalCurveDlg::propAutoAssign( Plot2d_AnalyticalCurve* curve, bool def )
694 {
695   bool val = def;
696   if ( curve ) {
697     if ( !myProperties.contains( curve ) )
698       myProperties[ curve ] = CurveProps();
699     if ( !myProperties[ curve ].contains( PROP_AUTOASSIGN ) )
700       myProperties[ curve ][ PROP_AUTOASSIGN ] = def;
701     QVariant v = myProperties[ curve ][ PROP_AUTOASSIGN ];
702     if ( v.isValid() && v.type() == QVariant::Bool ) val = v.toBool();
703   }
704   return val;
705 }