1 /***************************************************************************
2 * Copyright (C) 2008 by Alexey Balakin *
3 * mathgl.abalakin@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #include <QPushButton>
21 #include <QComboBox>
22 #include <QSpinBox>
23 #include <QLayout>
24 #include <QLabel>
25 #include <QLineEdit>
26 //-----------------------------------------------------------------------------
27 #include <mgl2/mgl.h>
28 extern mglParse parser;
29 #include "data_dlg.h"
30 //-----------------------------------------------------------------------------
DataDialog(QWidget * parent)31 DataDialog::DataDialog(QWidget* parent): QDialog(parent)
32 {
33 setWindowTitle(_("UDAV - Insert style/scheme"));
34 QHBoxLayout *h;
35 QVBoxLayout *v;
36 QGridLayout *g;
37 QLabel *l;
38 QPushButton *b;
39
40 v = new QVBoxLayout(this);
41 h = new QHBoxLayout(); v->addLayout(h);
42 l = new QLabel(_("Data name"), this); h->addWidget(l);
43 name = new QComboBox(this); h->addWidget(name);
44
45 g = new QGridLayout(); v->addLayout(g);
46
47 l = new QLabel("x1", this); g->addWidget(l, 0, 0);
48 x1 = new QSpinBox(this); x1->setMinimum(-1); g->addWidget(x1, 0, 1);
49 l = new QLabel("x2", this); g->addWidget(l, 0, 2);
50 x2 = new QSpinBox(this); x2->setMinimum(-1); g->addWidget(x2, 0, 3);
51
52 l = new QLabel("y1", this); g->addWidget(l, 1, 0);
53 y1 = new QSpinBox(this); y1->setMinimum(-1); g->addWidget(y1, 1, 1);
54 l = new QLabel("y2", this); g->addWidget(l, 1, 2);
55 y2 = new QSpinBox(this); y2->setMinimum(-1); g->addWidget(y2, 1, 3);
56
57 l = new QLabel("z1", this); g->addWidget(l, 2, 0);
58 z1 = new QSpinBox(this); z1->setMinimum(-1); g->addWidget(z1, 2, 1);
59 l = new QLabel("z2", this); g->addWidget(l, 2, 2);
60 z2 = new QSpinBox(this); z2->setMinimum(-1); g->addWidget(z2, 2, 3);
61
62 x1->setValue(-1); y1->setValue(-1); z1->setValue(-1);
63 x2->setValue(-1); y2->setValue(-1); z2->setValue(-1);
64
65 l = new QLabel(_("Operation")); g->addWidget(l, 3, 0);
66 oper = new QComboBox(this); g->addWidget(oper, 3, 1);
67 oper->addItem(_("none")); oper->addItem(_("sum"));
68 oper->addItem(_("min")); oper->addItem(_("max"));
69 l = new QLabel("along", this); g->addWidget(l, 3, 2);
70 dirs = new QComboBox(this); g->addWidget(dirs, 3, 3);
71 dirs->addItem("xyz");
72 dirs->addItem("x"); dirs->addItem("y"); dirs->addItem("z");
73 dirs->addItem("xy"); dirs->addItem("xz"); dirs->addItem("yz");
74
75 connect(name, SIGNAL(currentIndexChanged(int)), this, SLOT(nameChanged()));
76 connect(x1, SIGNAL(valueChanged(int)), this, SLOT(updateRes()));
77 connect(x2, SIGNAL(valueChanged(int)), this, SLOT(updateRes()));
78 connect(y1, SIGNAL(valueChanged(int)), this, SLOT(updateRes()));
79 connect(y2, SIGNAL(valueChanged(int)), this, SLOT(updateRes()));
80 connect(z1, SIGNAL(valueChanged(int)), this, SLOT(updateRes()));
81 connect(z2, SIGNAL(valueChanged(int)), this, SLOT(updateRes()));
82 connect(oper, SIGNAL(currentIndexChanged(int)), this, SLOT(updateRes()));
83 connect(dirs, SIGNAL(currentIndexChanged(int)), this, SLOT(updateRes()));
84
85 sizes = new QLabel(_("Result")); v->addWidget(sizes);
86 res = new QLineEdit(this); v->addWidget(res);
87 connect(res, SIGNAL(textChanged(QString)), this, SLOT(userRes()));
88
89 h = new QHBoxLayout(); v->addLayout(h); h->addStretch(1);
90 b = new QPushButton(_("Cancel"), this); h->addWidget(b);
91 connect(b, SIGNAL(clicked()),this, SLOT(reject()));
92 b = new QPushButton(_("OK"), this); h->addWidget(b);
93 connect(b, SIGNAL(clicked()),this, SLOT(accept()));
94 b->setDefault(true);
95 }
96 //-----------------------------------------------------------------------------
nameChanged()97 void DataDialog::nameChanged()
98 {
99 QString var = name->currentText();
100 wchar_t *txt=new wchar_t[var.length()+1];
101 var.toWCharArray(txt); txt[var.length()]=0;
102 mglData dat=parser.Calc(txt); delete []txt;
103 x1->setMaximum(dat.nx-1); x1->setValue(-1);
104 x2->setMaximum(dat.nx-1); x2->setValue(-1);
105 y1->setMaximum(dat.ny-1); y1->setValue(-1);
106 y2->setMaximum(dat.ny-1); y2->setValue(-1);
107 z1->setMaximum(dat.nz-1); z1->setValue(-1);
108 z2->setMaximum(dat.nz-1); z2->setValue(-1);
109 }
110 //-----------------------------------------------------------------------------
updateRes()111 void DataDialog::updateRes()
112 {
113 result = name->currentText();
114 int nx1 = x1->value(), nx2 = x2->value(), ny1 = y1->value(), ny2 = y2->value(), nz1 = z1->value(), nz2 = z2->value();
115 if(nx1>=0 || ny1>=0 || nz1>=0 || nx2>=0 || ny2>=0 || nz2>=0)
116 result += "(" + (nx1<0?"":QString::number(nx1)) + ":" + (nx2<0?"":QString::number(nx2)) + "," +
117 (ny1<0?"":QString::number(ny1)) + ":" + (ny2<0?"":QString::number(ny2)) + "," +
118 (nz1<0?"":QString::number(nz1)) + ":" + (nz2<0?"":QString::number(nz2)) + ")";
119 if(oper->currentIndex()>0)
120 result = "{" + oper->currentText() + " " + result + " '" + dirs->currentText() + "'}";
121 wchar_t *txt=new wchar_t[result.length()+1];
122 result.toWCharArray(txt); txt[result.length()]=0;
123 mglData dat=parser.Calc(txt); delete []txt;
124 sizes->setText(_("Result (will have sizes ") + QString::number(dat.nx)+"*"+QString::number(dat.ny)+"*"+QString::number(dat.nz)+")" );
125 res->setText(result);
126 }
127 //-----------------------------------------------------------------------------
updateNames()128 void DataDialog::updateNames()
129 {
130 name->clear();
131 long i, n = parser.GetNumVar();
132 for(i=0;i<n;i++)
133 {
134 const mglDataA *v = parser.GetVar(i);
135 if(v) name->addItem(QString::fromWCharArray(v->Name()));
136 }
137 }
138 //-----------------------------------------------------------------------------
userRes()139 void DataDialog::userRes()
140 {
141 QString txt = res->text();
142 if(txt != result)
143 { result = txt; sizes->setText(_("Result")); }
144 }
145 //-----------------------------------------------------------------------------
146