scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

IntDialog.cpp
Go to the documentation of this file.
1 
11 
29 #include "IntDialog.h"
30 #include "MyParser.h"
31 #include "Graph.h"
32 #include "ApplicationWindow.h"
33 #include "Integration.h"
34 #include "FunctionCurve.h"
35 #include "Differentiation.h"
36 
37 #include <QGroupBox>
38 #include <QSpinBox>
39 #include <QMessageBox>
40 #include <QPushButton>
41 #include <QLabel>
42 #include <QLineEdit>
43 #include <QComboBox>
44 #include <QLayout>
45 
46 IntDialog::IntDialog( QWidget* parent, Qt::WindowFlags fl )
47  : QDialog( parent, fl )
48 {
49  setWindowTitle(tr("Integration Options"));
50  setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
51 
52  QGroupBox *gb1 = new QGroupBox();
53  QGridLayout *gl1 = new QGridLayout(gb1);
54  gl1->addWidget(new QLabel(tr("Integration of")), 0, 0);
55  boxName = new QComboBox();
56  gl1->addWidget(boxName, 0, 1);
57 
58  gl1->addWidget(new QLabel(tr("Interpolation")), 1, 0);
59  boxMethod = new QComboBox();
60  boxMethod->addItem(tr("Linear"));
61  boxMethod->addItem(tr("Cubic"));
62  boxMethod->addItem(tr("Non-rounded Akima"));
63  gl1->addWidget(boxMethod, 1, 1);
64 
65  gl1->addWidget(new QLabel(tr("Lower limit")), 4, 0);
66  boxStart = new QLineEdit();
67  gl1->addWidget(boxStart, 4, 1);
68 
69  gl1->addWidget(new QLabel(tr("Upper limit")), 5, 0);
70  boxEnd = new QLineEdit();
71  gl1->addWidget(boxEnd, 5, 1);
72  gl1->setRowStretch(6, 1);
73 
74  buttonOk = new QPushButton(tr( "&Integrate" ));
75  buttonOk->setDefault( true );
76  buttonHelp = new QPushButton(tr("&Help"));
77  buttonCancel = new QPushButton(tr("&Close" ));
78 
79  QVBoxLayout *vl = new QVBoxLayout();
80  vl->addWidget(buttonOk);
81  vl->addWidget(buttonHelp);
82  vl->addWidget(buttonCancel);
83  vl->addStretch();
84 
85  QHBoxLayout *hb = new QHBoxLayout(this);
86  hb->addWidget(gb1);
87  hb->addLayout(vl);
88 
89  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
90  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
91  connect( buttonHelp, SIGNAL(clicked()),this, SLOT(help()));
92  connect( boxName, SIGNAL( activated(const QString&) ), this, SLOT(activateCurve(const QString&)));
93 }
94 
96 {
97 QString curveName = boxName->currentText();
98 QwtPlotCurve *c = graph->curve(curveName);
99 QStringList curvesList = graph->analysableCurvesList();
100 if (!c || !curvesList.contains(curveName))
101  {
102  QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") +" - "+ tr("Warning"),
103  tr("The curve <b> %1 </b> doesn't exist anymore! Operation aborted!").arg(curveName));
104  boxName->clear();
105  boxName->addItems(curvesList);
106  return;
107  }
108 
109 double start = 0, stop = 0;
110 double minx = c->minXValue();
111 double maxx = c->maxXValue();
112 
113 // Check the Xmin
114 QString from = boxStart->text().toLower();
115 if(from=="min")
116  {
117  boxStart->setText(QString::number(minx));
118  return;
119  }
120 else if(from=="max")
121  {
122  boxStart->setText(QString::number(maxx));
123  return;
124  }
125 else
126  {
127  try
128  {
129  MyParser parser;
130  parser.SetExpr((boxStart->text()).toUtf8().constData());
131  start=parser.Eval();
132 
133  if(start<minx)
134  {
135  QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
136  tr("Please give a number larger or equal to the minimum value of X, for the lower limit.\n If you do not know that value, type min in the box."));
137  boxStart->clear();
138  boxStart->setFocus();
139  return;
140  }
141  if(start > maxx)
142  {
143  QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
144  tr("Please give a number smaller or equal to the maximum value of X, for the lower limit.\n If you do not know that value, type max in the box."));
145  boxStart->clear();
146  boxStart->setFocus();
147  return;
148  }
149  }
150  catch(mu::ParserError &e)
151  {
152  QMessageBox::critical((ApplicationWindow *)parent(),tr("Start limit error"),QStringFromString(e.GetMsg()));
153  boxStart->clear();
154  boxStart->setFocus();
155  return;
156  }
157  }
158 
159 // Check Xmax
160 QString end=boxEnd->text().toLower();
161 if(end=="min")
162  {
163  boxEnd->setText(QString::number(minx));
164  return;
165  }
166 else if(end=="max")
167  {
168  boxEnd->setText(QString::number(maxx));
169  return;
170  }
171 else
172  {
173  try
174  {
175  MyParser parser;
176  parser.SetExpr(boxEnd->text());
177  stop = parser.Eval();
178  if(stop > maxx)
179  {
180  //FIXME: I don't understand why this doesn't work for FunctionCurves!!(Ion)
181  /*QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
182  tr("Please give a number smaller or equal to the maximum value of X, for the upper limit.\n If you do not know that value, type max in the box."));
183  boxEnd->clear();
184  boxEnd->setFocus();
185  return;
186  */
187  boxEnd->setText(QString::number(maxx));
188  }
189  if(stop < minx)
190  {
191  QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
192  tr("Please give a number larger or equal to the minimum value of X, for the upper limit.\n If you do not know that value, type min in the box."));
193  boxEnd->clear();
194  boxEnd->setFocus();
195  return;
196  }
197  }
198  catch(mu::ParserError &e)
199  {
200  QMessageBox::critical((ApplicationWindow *)parent(), tr("End limit error"),QStringFromString(e.GetMsg()));
201  boxEnd->clear();
202  boxEnd->setFocus();
203  return;
204  }
205  }
206 
207 Integration *i = new Integration((ApplicationWindow *)this->parent(), graph, curveName,
208  boxStart->text().toDouble(), boxEnd->text().toDouble());
210 i->run();
211 delete i;
212 }
213 
215 {
216  graph = g;
217  boxName->addItems(g->analysableCurvesList());
218 
219  QString selectedCurve = g->selectedCurveTitle();
220  if(!selectedCurve.isEmpty())
221  {
222  int index = boxName->findText(selectedCurve);
223  boxName->setCurrentIndex(index);
224  }
225  activateCurve(boxName->currentText());
226 
227  connect (graph, SIGNAL(closedGraph()), this, SLOT(close()));
228  connect (graph, SIGNAL(dataRangeChanged()), this, SLOT(changeDataRange()));
229 }
230 
231 void IntDialog::activateCurve(const QString& curveName)
232 {
233  ApplicationWindow *app = (ApplicationWindow *)parent();
234  if(!app)
235  return;
236 
237  QwtPlotCurve *c = graph->curve(curveName);
238  if (!c)
239  return;
240 
241  double start, end;
242  graph->range(graph->curveIndex(curveName), &start, &end);
243  boxStart->setText(QString::number(qMin(start, end), 'g', app->d_decimal_digits));
244  boxEnd->setText(QString::number(qMax(start, end), 'g', app->d_decimal_digits));
245 };
246 
248 {
249 ApplicationWindow *app = (ApplicationWindow *)parent();
250 if(!app)
251  return;
252 
253 double start = graph->selectedXStartValue();
254 double end = graph->selectedXEndValue();
255 boxStart->setText(QString::number(qMin(start, end), 'g', app->d_decimal_digits));
256 boxEnd->setText(QString::number(qMax(start, end), 'g', app->d_decimal_digits));
257 }
258 
260 {
261 QMessageBox::about(this, tr("Help for Integration"),
262  tr("The integration of a curve consists of the following five steps:\n 1) Choose which curve you want to integrate\n 2) Set the order of the integration. The higher it is the more accurate the calculation is\n 3) Choose the number of iterations \n 4) Choose the tolerance \n 5) Choose the lower and the upper limit.\n The code integrates the curve with an iterative algorithm. The tolerance determines the termination criteria for the solver.\n Because, sometimes we ask for too much accuracy, the number of iterations makes sure that the solver will not work for ever.\n IMPORTANT \nThe limits must be within the range of x; If you do not know the maximum (minimum) value of x, type max (min) in the boxes."));
263 }
MyParser.h
FunctionCurve.h
QStringFromString
QString QStringFromString(const std::string &x)
Definition: QStringStdString.h:15
Differentiation.h
IntDialog::help
void help()
Definition: IntDialog.cpp:259
IntDialog::buttonCancel
QPushButton * buttonCancel
Definition: IntDialog.h:51
Graph::analysableCurvesList
QStringList analysableCurvesList()
Returns the names of all the curves suitable for data analysis, as a string list. The list excludes e...
Definition: Graph.cpp:1311
IntDialog.h
IntDialog::buttonOk
QPushButton * buttonOk
Definition: IntDialog.h:48
IntDialog::graph
Graph * graph
Definition: IntDialog.h:70
IntDialog::setGraph
void setGraph(Graph *g)
Definition: IntDialog.cpp:214
MyParser
Mathematical parser class based on muParser.
Definition: MyParser.h:52
MyParser::SetExpr
void SetExpr(const QString &x)
Definition: MyParser.h:56
IntDialog::boxMethod
QComboBox * boxMethod
Definition: IntDialog.h:55
Graph::selectedXStartValue
double selectedXStartValue()
Definition: Graph.cpp:2787
Integration::InterpolationMethod
InterpolationMethod
Definition: Integration.h:39
Graph::selectedXEndValue
double selectedXEndValue()
Definition: Graph.cpp:2795
Integration::setMethod
void setMethod(InterpolationMethod method)
Definition: Integration.h:46
Integration.h
IntDialog::boxName
QComboBox * boxName
Definition: IntDialog.h:54
IntDialog::buttonHelp
QPushButton * buttonHelp
Definition: IntDialog.h:52
Graph::selectedCurveTitle
QString selectedCurveTitle()
Definition: Graph.cpp:1535
IntDialog::boxEnd
QLineEdit * boxEnd
Definition: IntDialog.h:57
ApplicationWindow
SciDAVis's main window.
Definition: ApplicationWindow.h:122
IntDialog::accept
void accept()
Definition: IntDialog.cpp:95
Graph.h
IntDialog::IntDialog
IntDialog(QWidget *parent=0, Qt::WindowFlags fl=0)
Definition: IntDialog.cpp:46
IntDialog::activateCurve
void activateCurve(const QString &curveName)
Definition: IntDialog.cpp:231
Filter::run
virtual bool run()
Actually does the job. Should be reimplemented in derived classes.
Definition: Filter.cpp:208
Graph
A 2D-plotting widget.
Definition: Graph.h:119
Integration
Definition: Integration.h:35
IntDialog::boxStart
QLineEdit * boxStart
Definition: IntDialog.h:56
ApplicationWindow.h
IntDialog::changeDataRange
void changeDataRange()
Definition: IntDialog.cpp:247
ApplicationWindow::d_decimal_digits
int d_decimal_digits
default precision to be used for all other operations than fitting
Definition: ApplicationWindow.h:956
Graph::curve
QwtPlotCurve * curve(int index) const
get curve by index
Definition: Graph.cpp:2821
Graph::curveIndex
int curveIndex(long key) const
Definition: Graph.h:199
Graph::range
int range(int index, double *start, double *end)
Definition: Graph.cpp:2834