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)  

SurfaceDialog.cpp
Go to the documentation of this file.
1 
11 
29 #include "SurfaceDialog.h"
30 #include "MyParser.h"
31 #include "ApplicationWindow.h"
32 
33 #include <QMessageBox>
34 #include <QLayout>
35 #include <QGroupBox>
36 #include <QPushButton>
37 #include <QLabel>
38 #include <QLineEdit>
39 #include <QComboBox>
40 
41 SurfaceDialog::SurfaceDialog( QWidget* parent, Qt::WindowFlags fl )
42  : QDialog( parent, fl )
43 {
44  setWindowTitle(tr("Define surface plot"));
45  setSizeGripEnabled( true );
46 
47  boxFunction = new QComboBox();
48  boxFunction->setEditable(true);
49 
50  QBoxLayout *bl1 = new QBoxLayout (QBoxLayout::LeftToRight);
51  bl1->addWidget(new QLabel( tr("f(x,y)=")), 1);
52  bl1->addWidget(boxFunction, 10);
53 
54  QGroupBox *gb1 = new QGroupBox(tr("X - axis"));
55 
56  boxXFrom = new QLineEdit();
57  boxXFrom->setText(tr("-1"));
58 
59  boxXTo = new QLineEdit();
60  boxXTo->setText(tr("1"));
61 
62  QGridLayout *gl1 = new QGridLayout();
63  gl1->addWidget(new QLabel( tr("From")), 0, 0);
64  gl1->addWidget(boxXFrom, 0, 1);
65  gl1->addWidget(new QLabel(tr("To")), 1, 0);
66  gl1->addWidget(boxXTo, 1, 1);
67  gl1->setRowStretch(2, 1);
68  gb1->setLayout(gl1);
69 
70  QGroupBox *gb2 = new QGroupBox(tr("Y - axis"));
71  boxYFrom = new QLineEdit();
72  boxYFrom->setText(tr("-1"));
73 
74  boxYTo = new QLineEdit();
75  boxYTo->setText(tr("1"));
76 
77  QGridLayout *gl2 = new QGridLayout();
78  gl2->addWidget(new QLabel( tr("From")), 0, 0);
79  gl2->addWidget(boxYFrom, 0, 1);
80  gl2->addWidget(new QLabel(tr("To")), 1, 0);
81  gl2->addWidget(boxYTo, 1, 1);
82  gl2->setRowStretch(2, 1);
83  gb2->setLayout(gl2);
84 
85  QGroupBox *gb3 = new QGroupBox(tr("Z - axis"));
86  boxZFrom = new QLineEdit();
87  boxZFrom->setText(tr("-1"));
88 
89  boxZTo = new QLineEdit();
90  boxZTo->setText(tr("1"));
91 
92  QGridLayout *gl3 = new QGridLayout();
93  gl3->addWidget(new QLabel( tr("From")), 0, 0);
94  gl3->addWidget(boxZFrom, 0, 1);
95  gl3->addWidget(new QLabel(tr("To")), 1, 0);
96  gl3->addWidget(boxZTo, 1, 1);
97  gl3->setRowStretch(2, 1);
98  gb3->setLayout(gl3);
99 
100  QBoxLayout *bl3 = new QBoxLayout (QBoxLayout::LeftToRight);
101  bl3->addWidget(gb1);
102  bl3->addWidget(gb2);
103  bl3->addWidget(gb3);
104 
105  buttonClear = new QPushButton(tr("Clear &list"));
106  buttonOk = new QPushButton(tr("&OK"));
107  buttonOk->setDefault(true);
108  buttonCancel = new QPushButton(tr("&Close"));
109 
110  QBoxLayout *bl2 = new QBoxLayout ( QBoxLayout::LeftToRight);
111  bl2->addStretch();
112  bl2->addWidget(buttonOk);
113  bl2->addWidget(buttonClear);
114  bl2->addWidget(buttonCancel);
115  bl2->addStretch();
116 
117  QVBoxLayout* vl = new QVBoxLayout(this);
118  vl->addLayout(bl1);
119  vl->addLayout(bl3);
120  vl->addLayout(bl2);
121 
122  resize(vl->minimumSize());
123  setFocusProxy(boxFunction);
124 
125  connect( buttonClear, SIGNAL( clicked() ), this, SLOT(clearList() ) );
126  connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
127  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
128 }
129 
131 {
132 boxFunction->clear();
133 emit clearFunctionsList();
134 }
135 
136 void SurfaceDialog::setFunction(const QString& s)
137 {
138 boxFunction->setItemText(boxFunction->currentIndex(), s);
139 }
140 
141 void SurfaceDialog::setLimits(double xs, double xe, double ys, double ye, double zs, double ze)
142 {
143  boxXFrom->setText(QString::number(xs));
144  boxXTo->setText(QString::number(xe));
145  boxYFrom->setText(QString::number(ys));
146  boxYTo->setText(QString::number(ye));
147  boxZFrom->setText(QString::number(zs));
148  boxZTo->setText(QString::number(ze));
149 }
150 
152 {
153 QString Xfrom=boxXFrom->text().toLower();
154 QString Xto=boxXTo->text().toLower();
155 QString Yfrom=boxYFrom->text().toLower();
156 QString Yto=boxYTo->text().toLower();
157 QString Zfrom=boxZFrom->text().toLower();
158 QString Zto=boxZTo->text().toLower();
159 
160 double fromX, toX, fromY,toY, fromZ,toZ;
161 try
162  {
163  MyParser parser;
164  parser.SetExpr(Xfrom);
165  fromX=parser.Eval();
166  }
167 catch(mu::ParserError &e)
168  {
169  QMessageBox::critical(0, tr("X Start limit error"), QStringFromString(e.GetMsg()));
170  boxXFrom->setFocus();
171  return;
172  }
173 try
174  {
175  MyParser parser;
176  parser.SetExpr(Xto);
177  toX=parser.Eval();
178  }
179 catch(mu::ParserError &e)
180  {
181  QMessageBox::critical(0, tr("X End limit error"), QStringFromString(e.GetMsg()));
182  boxXTo->setFocus();
183  return;
184  }
185 
186 try
187  {
188  MyParser parser;
189  parser.SetExpr(Yfrom);
190  fromY=parser.Eval();
191  }
192 catch(mu::ParserError &e)
193  {
194  QMessageBox::critical(0, tr("Y Start limit error"), QStringFromString(e.GetMsg()));
195  boxYFrom->setFocus();
196  return;
197  }
198 try
199  {
200  MyParser parser;
201  parser.SetExpr(Yto);
202  toY=parser.Eval();
203  }
204 catch(mu::ParserError &e)
205  {
206  QMessageBox::critical(0, tr("Y End limit error"), QStringFromString(e.GetMsg()));
207  boxYTo->setFocus();
208  return;
209  }
210 try
211  {
212  MyParser parser;
213  parser.SetExpr(Zfrom);
214  fromZ=parser.Eval();
215  }
216 catch(mu::ParserError &e)
217  {
218  QMessageBox::critical(0, tr("Z Start limit error"), QStringFromString(e.GetMsg()));
219  boxZFrom->setFocus();
220  return;
221  }
222 try
223  {
224  MyParser parser;
225  parser.SetExpr(Zto);
226  toZ=parser.Eval();
227  }
228 catch(mu::ParserError &e)
229  {
230  QMessageBox::critical(0, tr("Z End limit error"), QStringFromString(e.GetMsg()));
231  boxZTo->setFocus();
232  return;
233  }
234 
235 if (fromX >= toX || fromY >= toY || fromZ >= toZ)
236  {
237  QMessageBox::critical(0, tr("Input error"),
238  tr("Please enter limits that satisfy: from < end!"));
239  boxXTo->setFocus();
240  return;
241  }
242 
243 double x,y;
244 QString formula=boxFunction->currentText();
245 bool error=false;
246 try
247  {
248  MyParser parser;
249  parser.DefineVar(_T("x"), &x);
250  parser.DefineVar(_T("y"), &y);
251  parser.SetExpr(formula);
252 
253  x=fromX; y=fromY;
254  parser.Eval();
255  x=toX; y=toY;
256  parser.Eval();
257  }
258 catch(mu::ParserError &e)
259  {
260  QMessageBox::critical(0, tr("Input function error"), QStringFromString(e.GetMsg()));
261  boxFunction->setFocus();
262  error=true;
263  }
264 
265 if (!error)
266  {
267  emit options(boxFunction->currentText(),fromX, toX, fromY, toY, fromZ, toZ);
268  emit custom3DToolBar();
269 
270  ApplicationWindow *app = (ApplicationWindow *)this->parent();
271  app->updateSurfaceFuncList(boxFunction->currentText());
272  close();
273  }
274 }
275 
276 void SurfaceDialog::insertFunctionsList(const QStringList& list)
277 {
278 boxFunction->insertItems(1, list);
279 }
280 
282 {
283 }
MyParser.h
SurfaceDialog::setLimits
void setLimits(double xs, double xe, double ys, double ye, double zs, double ze)
Definition: SurfaceDialog.cpp:141
SurfaceDialog::setFunction
void setFunction(const QString &s)
Definition: SurfaceDialog.cpp:136
QStringFromString
QString QStringFromString(const std::string &x)
Definition: QStringStdString.h:15
SurfaceDialog::insertFunctionsList
void insertFunctionsList(const QStringList &list)
Definition: SurfaceDialog.cpp:276
SurfaceDialog::buttonOk
QPushButton * buttonOk
Definition: SurfaceDialog.h:61
MyParser
Mathematical parser class based on muParser.
Definition: MyParser.h:52
SurfaceDialog::boxXTo
QLineEdit * boxXTo
Definition: SurfaceDialog.h:66
MyParser::SetExpr
void SetExpr(const QString &x)
Definition: MyParser.h:56
ApplicationWindow::updateSurfaceFuncList
void updateSurfaceFuncList(const QString &s)
Definition: ApplicationWindow.cpp:1906
SurfaceDialog::buttonClear
QPushButton * buttonClear
Definition: SurfaceDialog.h:63
SurfaceDialog::~SurfaceDialog
~SurfaceDialog()
Definition: SurfaceDialog.cpp:281
SurfaceDialog::boxZFrom
QLineEdit * boxZFrom
Definition: SurfaceDialog.h:69
SurfaceDialog::options
void options(const QString &, double, double, double, double, double, double)
SurfaceDialog::boxXFrom
QLineEdit * boxXFrom
Definition: SurfaceDialog.h:65
SurfaceDialog::custom3DToolBar
void custom3DToolBar()
SurfaceDialog::boxYTo
QLineEdit * boxYTo
Definition: SurfaceDialog.h:68
ApplicationWindow
SciDAVis's main window.
Definition: ApplicationWindow.h:122
SurfaceDialog::buttonCancel
QPushButton * buttonCancel
Definition: SurfaceDialog.h:62
SurfaceDialog::boxFunction
QComboBox * boxFunction
Definition: SurfaceDialog.h:64
SurfaceDialog::clearList
void clearList()
Definition: SurfaceDialog.cpp:130
SurfaceDialog::clearFunctionsList
void clearFunctionsList()
SurfaceDialog::accept
void accept()
Definition: SurfaceDialog.cpp:151
SurfaceDialog::boxYFrom
QLineEdit * boxYFrom
Definition: SurfaceDialog.h:67
ApplicationWindow.h
SurfaceDialog::SurfaceDialog
SurfaceDialog(QWidget *parent=0, Qt::WindowFlags fl=0)
Definition: SurfaceDialog.cpp:41
SurfaceDialog::boxZTo
QLineEdit * boxZTo
Definition: SurfaceDialog.h:70
SurfaceDialog.h