1
/***************************************************************************
2
File : SurfaceDialog.cpp
4
--------------------------------------------------------------------
5
Copyright : (C) 2006 by Ion Vasilief
6
Email (use @ for *) : ion_vasilief*yahoo.fr
7
Description : Define surface plot dialog
9
***************************************************************************/
11
/***************************************************************************
13
* This program is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
18
* This program is distributed in the hope that it will be useful, *
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21
* GNU General Public License for more details. *
23
* You should have received a copy of the GNU General Public License *
24
* along with this program; if not, write to the Free Software *
25
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26
* Boston, MA 02110-1301 USA *
28
***************************************************************************/
29
#include "SurfaceDialog.h"
31
#include "ApplicationWindow.h"
33
#include <QMessageBox>
36
#include <QPushButton>
41
SurfaceDialog::SurfaceDialog( QWidget* parent, const char* name, bool modal, Qt::WFlags fl )
42
: QDialog( parent, name, modal, fl )
45
setName( "SurfaceDialog" );
46
setWindowTitle(tr("QtiPlot - Define surface plot"));
47
setSizeGripEnabled( true );
49
boxFunction = new QComboBox();
50
boxFunction->setEditable(true);
52
QBoxLayout *bl1 = new QBoxLayout (QBoxLayout::LeftToRight);
53
bl1->addWidget(new QLabel( tr("f(x,y)=")), 1);
54
bl1->addWidget(boxFunction, 10);
56
QGroupBox *gb1 = new QGroupBox(tr("X - axis"));
58
boxXFrom = new QLineEdit();
59
boxXFrom->setText(tr("-1"));
61
boxXTo = new QLineEdit();
62
boxXTo->setText(tr("1"));
64
QGridLayout *gl1 = new QGridLayout();
65
gl1->addWidget(new QLabel( tr("From")), 0, 0);
66
gl1->addWidget(boxXFrom, 0, 1);
67
gl1->addWidget(new QLabel(tr("To")), 1, 0);
68
gl1->addWidget(boxXTo, 1, 1);
69
gl1->setRowStretch(2, 1);
72
QGroupBox *gb2 = new QGroupBox(tr("Y - axis"));
73
boxYFrom = new QLineEdit();
74
boxYFrom->setText(tr("-1"));
76
boxYTo = new QLineEdit();
77
boxYTo->setText(tr("1"));
79
QGridLayout *gl2 = new QGridLayout();
80
gl2->addWidget(new QLabel( tr("From")), 0, 0);
81
gl2->addWidget(boxYFrom, 0, 1);
82
gl2->addWidget(new QLabel(tr("To")), 1, 0);
83
gl2->addWidget(boxYTo, 1, 1);
84
gl2->setRowStretch(2, 1);
87
QGroupBox *gb3 = new QGroupBox(tr("Z - axis"));
88
boxZFrom = new QLineEdit();
89
boxZFrom->setText(tr("-1"));
91
boxZTo = new QLineEdit();
92
boxZTo->setText(tr("1"));
94
QGridLayout *gl3 = new QGridLayout();
95
gl3->addWidget(new QLabel( tr("From")), 0, 0);
96
gl3->addWidget(boxZFrom, 0, 1);
97
gl3->addWidget(new QLabel(tr("To")), 1, 0);
98
gl3->addWidget(boxZTo, 1, 1);
99
gl3->setRowStretch(2, 1);
102
QBoxLayout *bl3 = new QBoxLayout (QBoxLayout::LeftToRight);
107
buttonClear = new QPushButton(tr("Clear &list"));
108
buttonOk = new QPushButton(tr("&OK"));
109
buttonOk->setDefault(true);
110
buttonCancel = new QPushButton(tr("&Close"));
112
QBoxLayout *bl2 = new QBoxLayout ( QBoxLayout::LeftToRight);
114
bl2->addWidget(buttonOk);
115
bl2->addWidget(buttonClear);
116
bl2->addWidget(buttonCancel);
119
QVBoxLayout* vl = new QVBoxLayout(this);
124
resize(minimumSize());
125
setFocusProxy(boxFunction);
127
connect( buttonClear, SIGNAL( clicked() ), this, SLOT(clearList() ) );
128
connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
129
connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
132
void SurfaceDialog::clearList()
134
boxFunction->clear();
135
emit clearFunctionsList();
138
void SurfaceDialog::setFunction(const QString& s)
140
boxFunction->setCurrentText(s);
143
void SurfaceDialog::setLimits(double xs, double xe, double ys, double ye, double zs, double ze)
145
boxXFrom->setText(QString::number(xs));
146
boxXTo->setText(QString::number(xe));
147
boxYFrom->setText(QString::number(ys));
148
boxYTo->setText(QString::number(ye));
149
boxZFrom->setText(QString::number(zs));
150
boxZTo->setText(QString::number(ze));
153
void SurfaceDialog::accept()
155
QString Xfrom=boxXFrom->text().lower();
156
QString Xto=boxXTo->text().lower();
157
QString Yfrom=boxYFrom->text().lower();
158
QString Yto=boxYTo->text().lower();
159
QString Zfrom=boxZFrom->text().lower();
160
QString Zto=boxZTo->text().lower();
162
double fromX, toX, fromY,toY, fromZ,toZ;
166
parser.SetExpr(Xfrom.ascii());
169
catch(mu::ParserError &e)
171
QMessageBox::critical(0, tr("QtiPlot - X Start limit error"), QString::fromStdString(e.GetMsg()));
172
boxXFrom->setFocus();
178
parser.SetExpr(Xto.ascii());
181
catch(mu::ParserError &e)
183
QMessageBox::critical(0, tr("QtiPlot - X End limit error"), QString::fromStdString(e.GetMsg()));
191
parser.SetExpr(Yfrom.ascii());
194
catch(mu::ParserError &e)
196
QMessageBox::critical(0, tr("QtiPlot - Y Start limit error"), QString::fromStdString(e.GetMsg()));
197
boxYFrom->setFocus();
203
parser.SetExpr(Yto.ascii());
206
catch(mu::ParserError &e)
208
QMessageBox::critical(0, tr("QtiPlot - Y End limit error"), QString::fromStdString(e.GetMsg()));
215
parser.SetExpr(Zfrom.ascii());
218
catch(mu::ParserError &e)
220
QMessageBox::critical(0, tr("QtiPlot - Z Start limit error"), QString::fromStdString(e.GetMsg()));
221
boxZFrom->setFocus();
227
parser.SetExpr(Zto.ascii());
230
catch(mu::ParserError &e)
232
QMessageBox::critical(0, tr("QtiPlot - Z End limit error"), QString::fromStdString(e.GetMsg()));
237
if (fromX >= toX || fromY >= toY || fromZ >= toZ)
239
QMessageBox::critical(0, tr("QtiPlot - Input error"),
240
tr("Please enter limits that satisfy: from < end!"));
246
QString formula=boxFunction->currentText();
251
parser.DefineVar("x", &x);
252
parser.DefineVar("y", &y);
253
parser.SetExpr(formula.ascii());
260
catch(mu::ParserError &e)
262
QMessageBox::critical(0, tr("QtiPlot - Input function error"), QString::fromStdString(e.GetMsg()));
263
boxFunction->setFocus();
269
emit options(boxFunction->currentText(),fromX, toX, fromY, toY, fromZ, toZ);
270
emit custom3DToolBar();
272
ApplicationWindow *app = (ApplicationWindow *)this->parent();
273
app->updateSurfaceFuncList(boxFunction->currentText());
278
void SurfaceDialog::insertFunctionsList(const QStringList& list)
280
boxFunction->insertStringList (list, 1);
283
SurfaceDialog::~SurfaceDialog()