~showard314/ubuntu/natty/qtiplot/Python2.7_fix

« back to all changes in this revision

Viewing changes to qtiplot/src/SurfaceDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gudjon I. Gudjonsson
  • Date: 2007-03-25 12:06:27 UTC
  • Revision ID: james.westby@ubuntu.com-20070325120627-5pvdufddr7i0r74x
Tags: upstream-0.9~rc2
ImportĀ upstreamĀ versionĀ 0.9~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : SurfaceDialog.cpp
 
3
    Project              : QtiPlot
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2006 by Ion Vasilief
 
6
    Email (use @ for *)  : ion_vasilief*yahoo.fr
 
7
    Description          : Define surface plot dialog
 
8
 
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
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.                                    *
 
17
 *                                                                         *
 
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.                           *
 
22
 *                                                                         *
 
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                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
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, const char* name, bool modal, Qt::WFlags fl )
 
42
    : QDialog( parent, name, modal, fl )
 
43
{
 
44
    if ( !name )
 
45
        setName( "SurfaceDialog" );
 
46
        setWindowTitle(tr("QtiPlot - Define surface plot"));
 
47
    setSizeGripEnabled( true );
 
48
 
 
49
        boxFunction = new QComboBox();
 
50
        boxFunction->setEditable(true);
 
51
 
 
52
        QBoxLayout *bl1 = new QBoxLayout (QBoxLayout::LeftToRight);
 
53
        bl1->addWidget(new QLabel( tr("f(x,y)=")), 1);
 
54
        bl1->addWidget(boxFunction, 10);
 
55
 
 
56
    QGroupBox *gb1 = new QGroupBox(tr("X - axis"));
 
57
 
 
58
        boxXFrom = new QLineEdit();
 
59
        boxXFrom->setText(tr("-1"));
 
60
 
 
61
        boxXTo = new QLineEdit();
 
62
        boxXTo->setText(tr("1"));
 
63
 
 
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);
 
70
    gb1->setLayout(gl1);
 
71
 
 
72
    QGroupBox *gb2 = new QGroupBox(tr("Y - axis"));
 
73
        boxYFrom = new QLineEdit();
 
74
        boxYFrom->setText(tr("-1"));
 
75
 
 
76
        boxYTo = new QLineEdit();
 
77
        boxYTo->setText(tr("1"));
 
78
 
 
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);
 
85
    gb2->setLayout(gl2);
 
86
 
 
87
    QGroupBox *gb3 = new QGroupBox(tr("Z - axis"));
 
88
        boxZFrom = new QLineEdit();
 
89
        boxZFrom->setText(tr("-1"));
 
90
 
 
91
        boxZTo = new QLineEdit();
 
92
        boxZTo->setText(tr("1"));
 
93
 
 
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);
 
100
    gb3->setLayout(gl3);
 
101
 
 
102
    QBoxLayout *bl3 = new QBoxLayout (QBoxLayout::LeftToRight);
 
103
        bl3->addWidget(gb1);
 
104
        bl3->addWidget(gb2);
 
105
        bl3->addWidget(gb3);
 
106
 
 
107
        buttonClear = new QPushButton(tr("Clear &list"));
 
108
        buttonOk = new QPushButton(tr("&OK"));
 
109
    buttonOk->setDefault(true);
 
110
    buttonCancel = new QPushButton(tr("&Close"));
 
111
 
 
112
    QBoxLayout *bl2 = new QBoxLayout ( QBoxLayout::LeftToRight);
 
113
    bl2->addStretch();
 
114
        bl2->addWidget(buttonOk);
 
115
    bl2->addWidget(buttonClear);
 
116
        bl2->addWidget(buttonCancel);
 
117
    bl2->addStretch();
 
118
 
 
119
        QVBoxLayout* vl = new QVBoxLayout(this);
 
120
    vl->addLayout(bl1);
 
121
        vl->addLayout(bl3);
 
122
        vl->addLayout(bl2);
 
123
 
 
124
    resize(minimumSize());
 
125
    setFocusProxy(boxFunction);
 
126
 
 
127
        connect( buttonClear, SIGNAL( clicked() ), this, SLOT(clearList() ) );
 
128
    connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
 
129
    connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
 
130
}
 
131
 
 
132
void SurfaceDialog::clearList()
 
133
{
 
134
boxFunction->clear();
 
135
emit clearFunctionsList();
 
136
}
 
137
 
 
138
void SurfaceDialog::setFunction(const QString& s)
 
139
{
 
140
boxFunction->setCurrentText(s);
 
141
}
 
142
 
 
143
void SurfaceDialog::setLimits(double xs, double xe, double ys, double ye, double zs, double ze)
 
144
{
 
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));
 
151
}
 
152
 
 
153
void SurfaceDialog::accept()
 
154
{
 
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();
 
161
 
 
162
double fromX, toX, fromY,toY, fromZ,toZ;
 
163
try
 
164
        {
 
165
        MyParser parser;
 
166
        parser.SetExpr(Xfrom.ascii());
 
167
        fromX=parser.Eval();
 
168
        }
 
169
catch(mu::ParserError &e)
 
170
        {
 
171
        QMessageBox::critical(0, tr("QtiPlot - X Start limit error"), QString::fromStdString(e.GetMsg()));
 
172
        boxXFrom->setFocus();
 
173
        return;
 
174
        }
 
175
try
 
176
        {
 
177
        MyParser parser;
 
178
        parser.SetExpr(Xto.ascii());
 
179
        toX=parser.Eval();
 
180
        }
 
181
catch(mu::ParserError &e)
 
182
        {
 
183
        QMessageBox::critical(0, tr("QtiPlot - X End limit error"), QString::fromStdString(e.GetMsg()));
 
184
        boxXTo->setFocus();
 
185
        return;
 
186
        }
 
187
 
 
188
try
 
189
        {
 
190
        MyParser parser;
 
191
        parser.SetExpr(Yfrom.ascii());
 
192
        fromY=parser.Eval();
 
193
        }
 
194
catch(mu::ParserError &e)
 
195
        {
 
196
        QMessageBox::critical(0, tr("QtiPlot - Y Start limit error"), QString::fromStdString(e.GetMsg()));
 
197
        boxYFrom->setFocus();
 
198
        return;
 
199
        }
 
200
try
 
201
        {
 
202
        MyParser parser;
 
203
        parser.SetExpr(Yto.ascii());
 
204
        toY=parser.Eval();
 
205
        }
 
206
catch(mu::ParserError &e)
 
207
        {
 
208
        QMessageBox::critical(0, tr("QtiPlot - Y End limit error"), QString::fromStdString(e.GetMsg()));
 
209
        boxYTo->setFocus();
 
210
        return;
 
211
        }
 
212
try
 
213
        {
 
214
        MyParser parser;
 
215
        parser.SetExpr(Zfrom.ascii());
 
216
        fromZ=parser.Eval();
 
217
        }
 
218
catch(mu::ParserError &e)
 
219
        {
 
220
        QMessageBox::critical(0, tr("QtiPlot - Z Start limit error"), QString::fromStdString(e.GetMsg()));
 
221
        boxZFrom->setFocus();
 
222
        return;
 
223
        }
 
224
try
 
225
        {
 
226
        MyParser parser;
 
227
        parser.SetExpr(Zto.ascii());
 
228
        toZ=parser.Eval();
 
229
        }
 
230
catch(mu::ParserError &e)
 
231
        {
 
232
        QMessageBox::critical(0, tr("QtiPlot - Z End limit error"), QString::fromStdString(e.GetMsg()));
 
233
        boxZTo->setFocus();
 
234
        return;
 
235
        }
 
236
 
 
237
if (fromX >= toX || fromY >= toY || fromZ >= toZ)
 
238
        {
 
239
        QMessageBox::critical(0, tr("QtiPlot - Input error"),
 
240
                                tr("Please enter limits that satisfy: from < end!"));
 
241
        boxXTo->setFocus();
 
242
        return;
 
243
        }
 
244
 
 
245
double x,y;
 
246
QString formula=boxFunction->currentText();
 
247
bool error=false;
 
248
try
 
249
        {
 
250
        MyParser parser;
 
251
        parser.DefineVar("x", &x);
 
252
        parser.DefineVar("y", &y);
 
253
        parser.SetExpr(formula.ascii());
 
254
 
 
255
        x=fromX; y=fromY;
 
256
        parser.Eval();
 
257
        x=toX; y=toY;
 
258
        parser.Eval();
 
259
        }
 
260
catch(mu::ParserError &e)
 
261
        {
 
262
        QMessageBox::critical(0, tr("QtiPlot - Input function error"), QString::fromStdString(e.GetMsg()));
 
263
        boxFunction->setFocus();
 
264
        error=true;
 
265
        }
 
266
 
 
267
if (!error)
 
268
        {
 
269
        emit options(boxFunction->currentText(),fromX, toX, fromY, toY, fromZ, toZ);
 
270
        emit custom3DToolBar();
 
271
 
 
272
        ApplicationWindow *app = (ApplicationWindow *)this->parent();
 
273
        app->updateSurfaceFuncList(boxFunction->currentText());
 
274
        close();
 
275
        }
 
276
}
 
277
 
 
278
void SurfaceDialog::insertFunctionsList(const QStringList& list)
 
279
{
 
280
boxFunction->insertStringList (list, 1);
 
281
}
 
282
 
 
283
SurfaceDialog::~SurfaceDialog()
 
284
{
 
285
}