Fixed text file permissions
[snark14.git] / tools / Input / super.cpp
1 #include "super.h"
2 #include "variables.h"
3 #include "misc.h"
4 #include <stdio.h>
5
6 #include <qbuttongroup.h>
7 #include <qframe.h>
8 #include <qlabel.h>
9 #include <qcombobox.h>
10 #include <qlineedit.h>
11 #include <qpushbutton.h>
12 #include <qradiobutton.h>
13 #include <qlayout.h>
14 #include <qvariant.h>
15 #include <qtooltip.h>
16 #include <qwhatsthis.h>
17 #include <qmessagebox.h>
18
19 superwindow::superwindow(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl)
20 {
21         if (!name) setName("superwindow");
22         resize(600, 340);
23         setSizePolicy( QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0, sizePolicy().hasHeightForWidth()));
24         setMinimumSize(QSize(600, 280));
25         setMaximumSize(QSize(600, 280));
26         setCaption(tr("Superiorize Window"));
27
28         superlabel = new QLabel(this, "superlabel");
29         superlabel->setGeometry(QRect(10, 10, 150, 30));
30         superlabel->setSizePolicy(QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0, superlabel->sizePolicy().hasHeightForWidth()));
31         superlabel->setMinimumSize(QSize(150, 30));
32         superlabel->setMaximumSize(QSize(150, 30));
33         superlabel->setText(tr("SUPERIORIZE"));
34
35         superbuttongroup = new QButtonGroup(this, "superbuttongroup");
36         superbuttongroup->setGeometry(QRect(15, 45, 575, 155));
37         superbuttongroup->setTitle(tr("options"));
38         superbuttongroup->setAlignment(int(QButtonGroup::AlignHCenter));
39
40         N = new QLineEdit(superbuttongroup, "N");
41         N->setGeometry(QRect(10, 45, 80, 24));
42         N->setSizePolicy(QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,N->sizePolicy().hasHeightForWidth()));
43         N->setEnabled(true);
44
45         Nlabel = new QLabel(superbuttongroup, "Nlabel");
46         Nlabel->setGeometry(QRect(45, 20, 40, 20));
47         Nlabel->setText(tr("N"));
48         Nlabel->setEnabled(true);
49
50         a = new QLineEdit(superbuttongroup, "a");
51         a->setGeometry(QRect(100, 45, 80, 24));
52         a->setSizePolicy(QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,a->sizePolicy().hasHeightForWidth()));
53         a->setEnabled(true);
54
55         alabel = new QLabel(superbuttongroup, "alabel");
56         alabel->setGeometry(QRect(135, 20, 40, 20));
57         alabel->setText(tr("a"));
58         alabel->setEnabled(true);
59
60         b = new QLineEdit(superbuttongroup, "b");
61         b->setGeometry(QRect(190, 45, 80, 24));
62         b->setSizePolicy(QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,b->sizePolicy().hasHeightForWidth()));
63         b->setEnabled(true);
64
65         blabel = new QLabel(superbuttongroup, "blabel");
66         blabel->setGeometry(QRect(225, 20, 40, 20));
67         blabel->setText(tr("b"));
68         blabel->setEnabled(true);
69
70         sec_cri = new QComboBox(superbuttongroup, "sec_cri");
71         sec_cri->setGeometry(QRect(15, 100, 130, 30));
72         sec_cri->setSizePolicy(QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,sec_cri->sizePolicy().hasHeightForWidth()));
73         sec_cri->insertItem("TVAR", -1);
74         sec_cri->insertItem("SMOO", -1);
75         sec_cri->insertItem("SCR3", -1);
76         sec_cri->insertItem("SCR4", -1);
77         sec_cri->insertItem("SCR5", -1);
78         sec_cri->setEnabled(true);
79         //QObject::connect(sec_cri,SIGNAL(activated(int)),this,SLOT(setEpsilon()));
80
81         sec_crilabel = new QLabel(superbuttongroup, "sec_crilabel");
82         sec_crilabel->setGeometry(QRect(10, 80, 145, 20));
83         sec_crilabel->setText(tr("secondary criterion"));
84         sec_crilabel->setEnabled(true);
85
86         altl = new QComboBox(superbuttongroup, "altl");
87         altl->setGeometry(QRect(195, 100, 130, 30));
88         altl->setSizePolicy(QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,altl->sizePolicy().hasHeightForWidth()));
89         altl->insertItem("NONE", -1);
90         altl->insertItem("ATL1", -1);
91         altl->insertItem("ATL2", -1);
92         altl->setEnabled(true);
93         //QObject::connect(sec_cri,SIGNAL(activated(int)),this,SLOT(setEpsilon()));
94
95         altllabel = new QLabel(superbuttongroup, "altllabel");
96         altllabel->setGeometry(QRect(215, 80, 100, 20));
97         altllabel->setText(tr("alternative l"));
98         altllabel->setEnabled(true);
99
100         rprtcb = new QCheckBox( this, "rprtcb" );
101         rprtcb->setGeometry(QRect(380, 145, 80, 30));
102         rprtcb->setText( "RPRT" );
103         rprtcb->setChecked(false);
104         rprtcb->setEnabled(true);
105         QObject::connect(rprtcb,SIGNAL(clicked()),this,SLOT(setSkips()));
106
107         skips = new QLineEdit(superbuttongroup, "skips");
108         skips->setGeometry(QRect(450, 100, 80, 30));
109         skips->setSizePolicy(QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,skips->sizePolicy().hasHeightForWidth()));
110         skips->setEnabled(false);
111
112         skipslabel = new QLabel(superbuttongroup, "skipslabel");
113         skipslabel->setGeometry(QRect(465, 80, 60, 20));
114         skipslabel->setText(tr("skips"));
115         skipslabel->setEnabled(false);
116
117         okbutton = new QPushButton(this, "okbutton");
118         okbutton->setGeometry(QRect(50, 230, 100, 40));
119         okbutton->setText(tr("OK"));
120         QObject::connect(okbutton, SIGNAL(clicked()), this, SLOT(checkValues()));
121
122         cancelbutton = new QPushButton(this, "cancelbutton");
123         cancelbutton->setGeometry(QRect(280, 230, 100, 40));
124         cancelbutton->setText(tr("Cancel"));
125         QObject::connect(cancelbutton, SIGNAL(clicked()), this, SLOT(reject()));
126 }
127
128 /**  
129  *  Destroys the object and frees any allocated resources
130  */
131 superwindow::~superwindow()
132 {
133         // no need to delete child widgets, Qt does it all for us
134 }
135
136 void superwindow::setSkips()
137 {
138         if (rprtcb->isChecked())
139         {
140                 skips->setEnabled(TRUE);
141                 skipslabel->setEnabled(TRUE);
142         }
143         else
144         {
145                 skips->setEnabled(FALSE);
146                 skipslabel->setEnabled(FALSE);
147         }
148 }
149
150 QString superwindow::getOutput()
151 {
152         QString output;
153
154         output.sprintf("SUPERIORIZE ");
155
156         output += N->text();
157         output.append(" ");
158         output += a->text();
159         output.append(" ");
160         output += b->text();
161         output.append(" ");
162
163         switch (sec_cri->currentItem())
164         {
165         case 0:
166                 output.append("TVAR");
167                 break;
168         case 1:
169                 output.append("SMOO");
170                 break;
171         case 2:
172                 output.append("SCR3");
173                 break;
174         case 3:
175                 output.append("SCR4");
176                 break;
177         case 4:
178                 output.append("SCR5");
179                 break;
180         }
181
182         switch (altl->currentItem())
183         {
184         case 0:
185                 // "none" is selected
186                 break;
187         case 1:
188                 output.append(" ATL1");
189                 break;
190         case 2:
191                 output.append(" ATL2");
192                 break;
193         }
194
195         if (rprtcb->isChecked())
196         {
197                 output.append(" RPRT");
198
199                 float s = strtof((const char *) skips->text());
200                 if (s>1)
201                 {
202                         output.append(" ");
203                         output += skips->text();
204                 }
205         }
206
207         return output;
208 }
209
210 void superwindow::checkValues()
211 {
212         int f = 0;
213         int iN = 0;
214         float fa = 0;
215         float fb = 0;
216         int is = 0;
217
218         iN = strtoi((const char *) N->text());
219         if (errnum) f = 1;
220         if (iN < 1) f = 2;
221
222         fa = strtof((const char *) a->text());
223         if (errnum) f = 3;
224         if ( fa <= 0 || fa>=1 ) f = 4;
225
226         fb = strtof((const char *) b->text());
227         if (errnum) f = 5;
228         if ( fb <= 0 || fb>1 ) f = 6;
229
230         switch (f)
231         {
232         case 0:
233                 accept();
234                 break;
235         case 1:
236                 QMessageBox::information(this, "SnarkInput", "Error!\n" "Invalid N format.");
237                 N->setFocus();
238                 break;
239         case 2:
240                 QMessageBox::information(this, "SnarkInput", "Error!\n" "N must be >0.");
241                 N->setFocus();
242                 break;
243         case 3:
244                 QMessageBox::information(this, "SnarkInput", "Error!\n" "Invalid a format.");
245                 a->setFocus();
246                 break;
247         case 4:
248                 QMessageBox::information(this, "SnarkInput", "Error!\n" "a must be >0 and <1.");
249                 a->setFocus();
250                 break;
251         case 5:
252                 QMessageBox::information(this, "SnarkInput", "Error!\n" "Invalid b format.");
253                 b->setFocus();
254                 break;
255         case 6:
256                 QMessageBox::information(this, "SnarkInput", "Error!\n" "b must be >0 and <=1.");
257                 b->setFocus();
258                 break;
259         }
260 }