Debian Codegraph @

calculator.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 Pavlo V. Solntsev
4 ** All rights reserved.
5 ** Contact: [email protected]
6 **
7 ** This file is part of the ShelXle
8 **
9 ** This file may be used under the terms of the GNU Lesser
10 ** General Public License version 2.1 as published by the Free Software
11 ** Foundation and appearing in the file COPYING included in the
12 ** packaging of this file. Please review the following information to
13 ** ensure the GNU Lesser General Public License version 2.1 requirements
14 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
15 **
16 **
17 ****************************************************************************/
18 #include "calculator.h"
19 #include "deprecation.h"
20 #include "itsme.h"
21
22 Calculator::Calculator(QString cellLine, QWidget *parent):
23 QWidget(parent){
24 setWindowFlags(Qt::Window);
25 setWindowTitle(tr("Calculator"));
26 // Set up wavelength box
27 // double lambda;
28 // QList<QPair<QString,double> > wavelist;
29 setLocale(QLocale::C);
30 wavelist = new QList<XraySource>();
31 wllist = new QStringList();
32 xraytype = new QStringList();
33 waveline = new QLineEdit();
34
35 wavelist->push_back(XraySource(XraySource::INPUT));// Should be first in this array !
36 wavelist->push_back(XraySource(XraySource::Cr));
37 wavelist->push_back(XraySource(XraySource::Mn));
38 wavelist->push_back(XraySource(XraySource::Fe));
39 wavelist->push_back(XraySource(XraySource::Co));
40 wavelist->push_back(XraySource(XraySource::Ni));
41 wavelist->push_back(XraySource(XraySource::Cu));
42 wavelist->push_back(XraySource(XraySource::Ga));
43 wavelist->push_back(XraySource(XraySource::Zr));
44 wavelist->push_back(XraySource(XraySource::Mo));
45 wavelist->push_back(XraySource(XraySource::Ag));
46 wavelist->push_back(XraySource(XraySource::In));
47 wavelist->push_back(XraySource(XraySource::CUSTOM)); // Should be last in this array !
48
49 for(QList<XraySource>::iterator it = wavelist->begin();it!=wavelist->end();it++ ){
50 if(it->name() == "INPUT")
51 wllist->push_back("From file");
52 else
53 wllist->push_back(it->name());
54 }
55 // QStringList listfordialog;
56 wavebox = new QComboBox(this);
57 wavebox->addItems(*wllist);
58 wavebox->setCurrentIndex(0);
59
60 xraytype->push_back(QString("<K%1 1&2>").arg(QChar(0xB1,0x03))); // Kalpha AVERAGE
61 xraytype->push_back(QString("K%1 1").arg(QChar(0xB1,0x03))); // Kalpha1
62 xraytype->push_back(QString("K%1 2").arg(QChar(0xB1,0x03))); // Kalpha2
63 xraytype->push_back(QString("K%1 1").arg(QChar(0xB2,0x03))); // Kbeta1
64 xraytype->push_back(QString("K%1 3").arg(QChar(0xB2,0x03))); // Kbeta3
65
66 xraytypebox = new QComboBox(this);
67 xraytypebox->addItems(*xraytype);
68 xraytypebox->setCurrentIndex(0);
69
70 mainvlayout = new QVBoxLayout(this);
71 setLayout(mainvlayout);
72 // Create dialog bottom layout
73 CloseButton = new QPushButton(tr("&Close"),this);
74 // buttonBox->addButton(QDialogButtonBox::Close);
75 tabwidget = new QTabWidget(this);
76 // Put tab widget and bottons into the dialog
77 mainvlayout->addWidget(tabwidget);
78 mainvlayout->addWidget(CloseButton,0,Qt::AlignRight);
79
80 // hkl resolution tab widget
81 QWidget *hklResolutionWidget = new QWidget(this);
82 QGridLayout *hklgrid = new QGridLayout(hklResolutionWidget);
83 lambdaSpin = new QDoubleSpinBox(this);
84 lambdaSpin->setRange(0.01,10.0);
85 lambdaSpin->setDecimals(5);
86 lambdaSpin->setSingleStep(0.0001);
87 aSpin = new QDoubleSpinBox(this);
88 aSpin->setRange(1.00,500.0);
89 aSpin->setDecimals(5);
90 aSpin->setSingleStep(0.01);
91 bSpin = new QDoubleSpinBox(this);
92 bSpin->setRange(1.0,500.0);
93 bSpin->setDecimals(5);
94 bSpin->setSingleStep(0.01);
95 cSpin = new QDoubleSpinBox(this);
96 cSpin->setRange(1.0,500.0);
97 cSpin->setDecimals(5);
98 cSpin->setSingleStep(0.01);
99 alSpin = new QDoubleSpinBox(this);
100 alSpin->setRange(1.0,180.0);
101 alSpin->setDecimals(4);
102 alSpin->setSingleStep(0.1);
103 beSpin = new QDoubleSpinBox(this);
104 beSpin->setRange(1.0,180.0);
105 beSpin->setDecimals(4);
106 beSpin->setSingleStep(0.1);
107 gaSpin = new QDoubleSpinBox(this);
108 gaSpin->setRange(1.0,180.0);
109 gaSpin->setDecimals(4);
110 gaSpin->setSingleStep(0.1);
111 hSpin = new QSpinBox(this);
112 hSpin->setRange(-2000,2000);
113 hSpin->setValue(1);
114
115 kSpin = new QSpinBox(this);
116 kSpin->setRange(-2000,2000);
117 kSpin->setValue(1);
118
119 lSpin = new QSpinBox(this);
120 lSpin->setRange(-2000,2000);
121 lSpin->setValue(1);
122
123 int j(0);
124 LCell = new QLineEdit((cellLine.isEmpty())?"CELL 0.5 10.0 10.0 10.0 90.0 90.0 90.0":cellLine.simplified(),this);
125 hklgrid->addWidget(LCell,j,0,1,3);
126 QPushButton *getCurentCell = new QPushButton("get current cell",this);
127 connect(getCurentCell,SIGNAL(pressed()),this,SIGNAL(currentCellrequest()));
128 hklgrid->addWidget(getCurentCell,j,3);
129 HKLedit = new QLineEdit("HKL 1 1 1",this);
130 hklgrid->addWidget(new QLabel("wavelength",this),++j,0,Qt::AlignRight);
131 hklgrid->addWidget(lambdaSpin,j,1);
132 hklgrid->addWidget(HKLedit,j,2,1,2);
133 hklgrid->addWidget(new QLabel("a",this),++j,0,Qt::AlignRight);
134 hklgrid->addWidget(aSpin,j,1);
135 hklgrid->addWidget(new QLabel("h",this),j,2,Qt::AlignRight);
136 hklgrid->addWidget(hSpin,j,3);
137 hklgrid->addWidget(new QLabel("b",this),++j,0,Qt::AlignRight);
138 hklgrid->addWidget(bSpin,j,1);
139 hklgrid->addWidget(new QLabel("k",this),j,2,Qt::AlignRight);
140 hklgrid->addWidget(kSpin,j,3);
141 hklgrid->addWidget(new QLabel("c",this),++j,0,Qt::AlignRight);
142 hklgrid->addWidget(cSpin,j,1);
143 hklgrid->addWidget(new QLabel("l",this),j,2,Qt::AlignRight);
144 hklgrid->addWidget(lSpin,j,3);
145 hklgrid->addWidget(new QLabel("alpha",this),++j,0,Qt::AlignRight);
146 hklgrid->addWidget(alSpin,j,1);
147 hklgrid->addWidget(new QLabel("beta",this),++j,0,Qt::AlignRight);
148 hklgrid->addWidget(beSpin,j,1);
149 hklgrid->addWidget(new QLabel("gamma",this),++j,0,Qt::AlignRight);
150 hklgrid->addWidget(gaSpin,j,1);
151 resolutionL=new QLabel("",this);
152 hklgrid->addWidget(resolutionL,++j,0,1,4,Qt::AlignRight);
153 wlcellChanged();
154 hkl2stl2();
155
156 connect(LCell,SIGNAL(textEdited(QString)),this,SLOT(wlcellChanged()));
157 connect(lambdaSpin,SIGNAL(valueChanged(double)),this,SLOT(changeWlCell()));
158 connect(aSpin,SIGNAL(valueChanged(double)),this,SLOT(changeWlCell()));
159 connect(bSpin,SIGNAL(valueChanged(double)),this,SLOT(changeWlCell()));
160 connect(cSpin,SIGNAL(valueChanged(double)),this,SLOT(changeWlCell()));
161 connect(alSpin,SIGNAL(valueChanged(double)),this,SLOT(changeWlCell()));
162 connect(beSpin,SIGNAL(valueChanged(double)),this,SLOT(changeWlCell()));
163 connect(gaSpin,SIGNAL(valueChanged(double)),this,SLOT(changeWlCell()));
164 connect(hSpin,SIGNAL(valueChanged(int)),this,SLOT(hkl2stl2()));
165 connect(kSpin,SIGNAL(valueChanged(int)),this,SLOT(hkl2stl2()));
166 connect(lSpin,SIGNAL(valueChanged(int)),this,SLOT(hkl2stl2()));
167 connect(HKLedit,SIGNAL(textEdited(QString)),this,SLOT(hKLChanged()));
168 connect(hSpin,SIGNAL(valueChanged(int)),this,SLOT(changeHKLEdit()));
169 connect(kSpin,SIGNAL(valueChanged(int)),this,SLOT(changeHKLEdit()));
170 connect(lSpin,SIGNAL(valueChanged(int)),this,SLOT(changeHKLEdit()));
171 // Add resolution page to the tab widget
172 QWidget *reswidget = new QWidget();
173 resgrid = new QGridLayout(); // a grid for resolution
174 reswidget->setLayout(resgrid);
175 // Add page for 1,3 distances
176 QWidget *dangwidget = new QWidget();
177 danglayout = new QVBoxLayout(); // a grid for 1-3 distances
178 dangwidget->setLayout(danglayout);
179 danggrid = new QGridLayout();
180 // Prepare resolution dialog
181 sourcelabel = new QLabel(QString("Wavelength, %1").arg(QChar(0xC5,0x00)),this);
182 dres = new QLabel(QString("d, %1").arg(QChar(0xC5,0x00)), this); // d obtained from Bregs law: 2dsin(Theta) = 1 labda
183 sinthoverlm = new QLabel(QString("sin(%1)/%2, %3<sup>-1</sup>").arg(QChar(0xB8,0x03)).arg(QChar(0xBB,0x03)).arg(QChar(0xC5,0x00)), this); // Sin(Theta)/lambda is the same as 1/(2d) obtained from Bregs law: 2dsin(Theta) = 1 labda
184 theta = new QLabel(QString("%1,%2").arg(QChar(0xB8,0x03)).arg(QChar(0xB0,0x00)),this); // Theta angle
185 twotheta = new QLabel(QString("2%1,%2").arg(QChar(0xB8,0x03)).arg(QChar(0xB0,0x00)),this); // 2Theta
186 twotheta->setTextFormat(Qt::RichText);
187
188 dresline = new QLineEdit(this);
189 sinthoverlmline = new QLineEdit(this);
190 thetaline = new QLineEdit(this);
191 twothetaline = new QLineEdit(this);
192
193 // Put all widgets to the resolution grid
194 int i(0);
195 resgrid->addWidget(sourcelabel,i,0);
196 resgrid->addWidget(wavebox,i++,1);
197 resgrid->addWidget(xraytypebox,i,0);
198 resgrid->addWidget(waveline,i++,1);
199
200 resgrid->addWidget(dres,i,0);
201 resgrid->addWidget(dresline,i++,1);
202 resgrid->addWidget(sinthoverlm,i,0);
203 resgrid->addWidget(sinthoverlmline,i++,1);
204 resgrid->addWidget(theta,i,0);
205 resgrid->addWidget(thetaline,i++,1);
206 resgrid->addWidget(twotheta,i,0);
207 resgrid->addWidget(twothetaline,i++,1);
208 // put resolution and 1-3 distance widgets to the tab
209 tabwidget->insertTab(0,reswidget,tr("Resolution"));
210 tabwidget->insertTab(1,dangwidget,tr("1-3 Distances"));
211 tabwidget->insertTab(2,hklResolutionWidget,QString("Resolution of reflection HKL"));
212
213 danglayout->insertLayout(0,danggrid);
214 dangpicturelabel = new QLabel(this);
215 QString theIconPath;
216 if (!QString(PROGRAM_NAME).compare("shelXle")){
217 theIconPath=QString(":/xle-icons/");
218 }else{
219 theIconPath=QString(":/bicons/");
220 }
221 dangpicturelabel->setPixmap(QPixmap(theIconPath+"dang.png"));
222 dangpicturelabel->show();
223 danglayout->insertWidget(1,dangpicturelabel);
224 // Initiate all widgets for 1-3 distances tab
225 d1label = new QLabel();
226 d2label = new QLabel();
227 angle = new QLabel();
228 dlabel = new QLabel();
229
230 d1line = new QLineEdit();
231 d2line = new QLineEdit();
232 angleline = new QLineEdit();
233 dline = new QLineEdit();
234
235 // Set values for all labels for 1-3 tab widget
236 d1label->setText(QString("d1, %1").arg(QChar(0xC5,0x00)));
237 d2label->setText(QString("d2, %1").arg(QChar(0xC5,0x00)));
238 angle->setText(QString("%1, %2").arg(QChar(0xB1,0x03)).arg(QChar(0xB0,0x00)) );
239 dlabel->setText(QString("d, %1").arg(QChar(0xC5,0x00)) );
240
241 i=0;
242 danggrid->addWidget(d1label,i,0);
243 danggrid->addWidget(d1line,i++,1);
244 danggrid->addWidget(d2label,i,0);
245 danggrid->addWidget(d2line,i++,1);
246 danggrid->addWidget(angle,i,0);
247 danggrid->addWidget(angleline,i++,1);
248 danggrid->addWidget(dlabel,i,0);
249 danggrid->addWidget(dline,i++,1);
250
251
252 // Set defult values for resolution dialog
253 /*
254 2dsinA = L => sinA/L = 1/(2d)
255 Default sinA/L = 0.6
256 */
257 _sintl = 0.6;
258 QString s = LCell->text();
259 QRegularExpression sep=QRegularExpression("\\s+");
260 _shelxlambda = lambda = (s.isEmpty())?0.71073:s.section(sep,1,1).toDouble();
261 sinthoverlmline->setText(QString::number(_sintl));
262 sinthoverlmline_changed();
263 waveline->setText(QString::number(lambda,10,5));
264
265 if(_shelxlambda < 0.001) {
266 xraytypebox->setEnabled(false);
267 waveline->setEnabled(false);
268 }
269
270 xraytypebox->setEnabled(false);
271
272 // Show all widgets
273 tabwidget->show();
274 // connect signals for resolution tab
275 connect(dresline,SIGNAL(editingFinished()),this,SLOT(dresline_changed()));
276 connect(sinthoverlmline,SIGNAL(editingFinished()),this,SLOT(sinthoverlmline_changed()));
277 connect(thetaline,SIGNAL(editingFinished()),this,SLOT(thetaline_changed()));
278 connect(twothetaline,SIGNAL(editingFinished()),this,SLOT(twothetaline_changed()));
279 connect(wavebox,SIGNAL(currentIndexChanged(int)),this,SLOT(wl_changed(int)));
280 connect(xraytypebox,SIGNAL(currentIndexChanged(int)),this,SLOT(wl_type_changed(int)));
281
282
283 // connect signals for dang tab
284 connect(d1line,SIGNAL(editingFinished()),this,SLOT(d1line_changed()));
285 connect(d2line,SIGNAL(editingFinished()),this,SLOT(d2line_changed()));
286 connect(angleline,SIGNAL(editingFinished()),this,SLOT(angleline_changed()));
287 connect(dline,SIGNAL(editingFinished()),this,SLOT(dline_changed()));
288
289 connect(CloseButton, SIGNAL(clicked()), this, SLOT(close()));
290 // connect(CancelButton, SIGNAL(clicked()), this, SLOT(close()));
291 QSize _size=sizeHint();
292 _size.setWidth(static_cast<int>(_size.width()*1.2));
293 setFixedSize(_size);
294 show();
295
296
297 }
298
299 Calculator::~Calculator(){
300 delete CloseButton;
301 delete wllist;
302 delete wavelist;
303 delete dangpicturelabel;
304 delete xraytype;
305 delete waveline;
306 delete d1label;
307 delete d2label;
308 delete angle;
309 delete d1line;
310 delete d2line;
311 delete angleline;
312 delete dline;
313 printf("~Calculator()\n");
314 }
315 /*! \brief Recalculate all values in the line using dresline as a reference
316 */
317 void Calculator::dresline_changed(){
318 /* 2dsinA = L
319 sinA/L = 1/(2d)
320 (sinA/L)^2 = 1/(2d)^2
321 theta = arcsin(L/2d)
322 2theta = 2arcsin(L/2d)
323 */
324 _dres = dresline->text().toDouble();
325 _sintl = 1/(2*_dres);
326 _theta = RAD2DEG(asin(lambda/(2*_dres)));
327 _twotheta = 2*_theta;
328
329 sinthoverlmline->setText(QString::number(_sintl,10,3));
330 thetaline->setText(QString::number(_theta,10,2));
331 twothetaline->setText(QString::number(_twotheta,10,2));
332 }
333
334 void Calculator::sinthoverlmline_changed(){
335 /* sinA/L = 1/(2d) = s
336 d = 1/(2s)
337 (sinA/L)^2 = s^2
338 theta = arcsin(s*L)
339 2theta = 2*theta
340 */
341 _sintl = sinthoverlmline->text().toDouble();
342 _dres = 1/(2*_sintl);
343 _theta = RAD2DEG(asin(lambda/(2*_dres)));
344 _twotheta = 2*_theta;
345
346 dresline->setText(QString::number(_dres,10,3));
347 thetaline->setText(QString::number(_theta,10,2));
348 twothetaline->setText(QString::number(_twotheta,10,2));
349 }
350
351 void Calculator::changeWlCell(){
352 QString s=QString("CELL %1 %2 %3 %4 %5 %6 %7")
353 .arg(lambdaSpin->value(),0,'f',5)
354 .arg(aSpin->value() ,0,'g',5)
355 .arg(bSpin->value() ,0,'g',5)
356 .arg(cSpin->value() ,0,'g',5)
357 .arg(alSpin->value() ,0,'g',4)
358 .arg(beSpin->value() ,0,'g',4)
359 .arg(gaSpin->value() ,0,'g',4);
360 if (!LCell->hasFocus()) {
361 LCell->setText(s);
362
363 mole.cell.wave = lambdaSpin->value();
364 mole.cell.a = aSpin->value() ;
365 mole.cell.b = bSpin->value() ;
366 mole.cell.c = cSpin->value() ;
367 mole.cell.al = alSpin->value() ;
368 mole.cell.be = beSpin->value() ;
369 mole.cell.ga = gaSpin->value() ;
370 mole.cellSetup();
371 QSize _size=size();
372 #if (QT_VERSION>=0x050000)
373 int w=75+
374 fontMetrics().horizontalAdvance(s);
375
376 #else
377 int w=75+
378 fontMetrics().width(s);
379 #endif
380 _size.setWidth(static_cast<int>(qMax(w,width())));
381 setFixedSize(_size);
382 printf("changeWlCell w%d\n",qMax(w,width()));
383 }
384 hkl2stl2();
385 }
386
387 void Calculator::setHKLEdit(QString text){
388 LCell->setFocus();
389 LCell->setText(text.simplified());
390 wlcellChanged();
391 }
392
393 void Calculator::wlcellChanged(){
394 QString s=LCell->text();
395 if (s.isEmpty())return;
396 QRegularExpression sep=QRegularExpression("\\s+");
397 QStringList tok = s.split(sep,skipEmptyParts);
398 if (tok.size()<8)return;
399 mole.cell.wave = tok.at(1).toDouble();
400 mole.cell.a = tok.at(2).toDouble();
401 mole.cell.b = tok.at(3).toDouble();
402 mole.cell.c = tok.at(4).toDouble();
403 mole.cell.al = tok.at(5).toDouble();
404 mole.cell.be = tok.at(6).toDouble();
405 mole.cell.ga = tok.at(7).toDouble();
406 mole.cellSetup();
407 lambdaSpin->setValue(mole.cell.wave);
408 aSpin->setValue(mole.cell.a);
409 bSpin->setValue(mole.cell.b);
410 cSpin->setValue(mole.cell.c);
411 alSpin->setValue(mole.cell.al);
412 beSpin->setValue(mole.cell.be);
413 gaSpin->setValue(mole.cell.ga);
414 //printf("\n!!%f %f %f %f %f %f %f %d\n",mole.cell.wave,mole.cell.a,mole.cell.b,mole.cell.c,mole.cell.al,mole.cell.be,mole.cell.ga,tok.size());
415 QSize _size=size();
416 #if (QT_VERSION>=0x050000)
417 int w=75+
418 fontMetrics().horizontalAdvance(s);
419
420 #else
421 int w=75+
422 fontMetrics().width(s);
423 #endif
424 _size.setWidth(static_cast<int>(qMax(w,width())));
425 setFixedSize(_size);
426 //hkl2stl2();
427 }
428
429 void Calculator::hKLChanged(){
430 QString s=HKLedit->text();
431 printf("hKLChanged() %d\n",s.isEmpty());
432 if (s.isEmpty())return;
433 QRegularExpression sep=QRegularExpression("\\s+");
434 QStringList tok = s.split(sep, skipEmptyParts);
435 if ((tok.size()==3)&&(!tok.at(0).contains("HKL",Qt::CaseInsensitive))){
436 hSpin->setValue(tok.at(0).toInt());
437 kSpin->setValue(tok.at(1).toInt());
438 lSpin->setValue(tok.at(2).toInt());
439 QString s=QString("HKL %1 %2 %3")
440 .arg(hSpin->value() )
441 .arg(kSpin->value() )
442 .arg(lSpin->value() );
443 HKLedit->setText(s);
444 hkl2stl2();
445 return;
446 }
447 if (tok.size()<4)return;
448 hSpin->setValue(tok.at(1).toInt());
449 kSpin->setValue(tok.at(2).toInt());
450 lSpin->setValue(tok.at(3).toInt());
451 hkl2stl2();
452 }
453
454 void Calculator::changeHKLEdit(){
455 QString s=QString("HKL %1 %2 %3")
456 .arg(hSpin->value() )
457 .arg(kSpin->value() )
458 .arg(lSpin->value() );
459 if (!HKLedit->hasFocus()) {
460 HKLedit->setText(s);
461 hkl2stl2();
462 }
463 }
464
465 void Calculator::hkl2stl2(){
466 int h = hSpin->value();
467 int k = kSpin->value();
468 int l = lSpin->value();
469 V3 H=V3(h,k,l);
470 double stl=sqrt(H*mole.cell.Gi*H)/2.0;
471 // printf("%f d=%f 2theta=%f\n",stl,0.5/stl,2.0*RAD2DEG(asin(stl*mole.cell.wave)));
472 resolutionL->setText(QString("<h2>d = %1 &Aring;; sin(&theta;/&lambda;) = %2 &Aring;<sup>-1</sup>; 2&theta; = %3 &#176; </h2>")
473 .arg(0.5/stl,0,'g',5)
474 .arg(stl,0,'g',5)
475 .arg(2.0*RAD2DEG(asin(stl*mole.cell.wave)),0,'f',2));
476 }
477
478 void Calculator::thetaline_changed(){
479 /* theta = s
480 d = L/(2sin(s))
481 sin(s)/L
482 (sin(s)/L)^2
483 2theta = 2*s
484 */
485 _theta = thetaline->text().toDouble();
486 _dres = lambda/(2*sin(DEG2RAD(_theta)));
487 _sintl = (sin(DEG2RAD(_theta)))/lambda;
488 _twotheta = 2*_theta;
489
490 dresline->setText(QString::number(_dres,10,3));
491 sinthoverlmline->setText(QString::number(_sintl,10,3));
492 twothetaline->setText(QString::number(_twotheta,10,2));
493 }
494
495 void Calculator::twothetaline_changed(){
496 /* 2theta = s
497 d = L/(2 sin(s/2))
498 sin(s)/L
499 (sin(s)/L)^2
500 theta = sqrt(s)
501 */
502 _twotheta = twothetaline->text().toDouble();
503 _theta = _twotheta/2;
504 _dres = lambda/(2*sin(DEG2RAD(_theta)));
505 _sintl = (sin(DEG2RAD(_theta)))/lambda;
506
507 dresline->setText(QString::number(_dres,10,3));
508 sinthoverlmline->setText(QString::number(_sintl,10,3));
509 thetaline->setText(QString::number(_theta,10,2));
510 }
511
512 void Calculator::wl_changed(int a){
513 /*
514 2dsinA = L
515 sinA/L = 1/(2d) = s
516 d = L/(2sinA)
517 sinA = L/(2d) => A = arcsin(L/(2d))
518
519 */
520
521 if(a==0)
522 {
523 xraytypebox->setEnabled(false);
524 if(_shelxlambda < 0.001)
525 waveline->setEnabled(false);
526
527 lambda = _shelxlambda;
528 // lambda = wavelist->at(a).wavelength(static_cast<XraySource::XrayType>(xraytypebox->currentIndex()));
529 waveline->setText(QString::number(lambda,10,5));
530 }
531 else
532 {
533 if(a == (wavelist->size()-1))
534 {
535 if (xraytypebox->isEnabled())
536 xraytypebox->setEnabled(false);
537 if(!waveline->isEnabled())
538 waveline->setEnabled(true);
539
540 connect(waveline,SIGNAL(editingFinished()),this,SLOT(wl_custom_changed()));
541 }
542 else
543 {
544 if(!xraytypebox->isEnabled())
545 xraytypebox->setEnabled(true);
546 if(!waveline->isEnabled())
547 waveline->setEnabled(true);
548
549 lambda = wavelist->at(a).wavelength(static_cast<XraySource::XrayType>(xraytypebox->currentIndex()));
550 waveline->setText(QString::number(lambda,10,5));
551 }
552 }
553
554 _theta = RAD2DEG(asin(lambda/(2*_dres)));
555 _twotheta = 2*_theta;
556 thetaline->setText(QString::number(_theta,10,2));
557 twothetaline->setText(QString::number(_twotheta,10,2));
558 }
559
560 void Calculator::wl_type_changed(int a){
561 lambda = wavelist->at(wavebox->currentIndex()).wavelength(static_cast<XraySource::XrayType>(a));
562 waveline->setText(QString::number(lambda,10,5));
563
564 _theta = RAD2DEG(asin(lambda/(2*_dres)));
565 _twotheta = 2*_theta;
566 thetaline->setText(QString::number(_theta,10,2));
567 twothetaline->setText(QString::number(_twotheta,10,2));
568 }
569
570 void Calculator::wl_custom_changed(){
571 lambda = waveline->text().toDouble();
572 _theta = RAD2DEG(asin(lambda/(2*_dres)));
573 _twotheta = 2*_theta;
574 thetaline->setText(QString::number(_theta,10,2));
575 twothetaline->setText(QString::number(_twotheta,10,2));
576 }
577
578 void Calculator::d1line_changed(){
579 _d1 = d1line->text().toDouble();
580 // _d2 = d2line->text().toDouble();
581 // _angle = angleline->text().toDouble();
582 _d =sqrt(_d1*_d1+_d2*_d2-2*_d1*_d2*cos(DEG2RAD(_angle)));
583 dline->setText(QString::number(_d,10,3));
584 }
585
586 void Calculator::d2line_changed(){
587 // _d1 = d1line->text().toDouble();
588 _d2 = d2line->text().toDouble();
589 // _angle = angleline->text().toDouble();
590 _d =sqrt(_d1*_d1+_d2*_d2-2*_d1*_d2*cos(DEG2RAD(_angle)));
591 dline->setText(QString::number(_d,10,3));
592
593 }
594
595 void Calculator::angleline_changed(){
596 // _d1 = d1line->text().toDouble();
597 // _d2 = d2line->text().toDouble();
598 _angle = angleline->text().toDouble();
599 _d =sqrt(_d1*_d1+_d2*_d2-2*_d1*_d2*cos(DEG2RAD(_angle)));
600 dline->setText(QString::number(_d,10,3));
601 }
602
603 void Calculator::dline_changed(){
604 // _d1 = d1line->text().toDouble();
605 // _d2 = d2line->text().toDouble();
606 _d = dline->text().toDouble();
607 _angle = RAD2DEG(acos(((_d*_d)-(_d1*_d1)-(_d2*_d2))/(-2*_d1*_d2)));
608 angleline->setText(QString::number(_angle,10,3));
609 }
610
611
612 XraySource::XraySource(XraySource::Sources source){
613 /*
614 All wavelengths were takedn from
615 Internationl Union of Crystallography Vol. C (2004)
616 Table 4.2.2.1
617 */
618 switch(source) {
619 case XraySource::INPUT:
620 _name = "INPUT";
621 // _wavelength = 0;
622 _Kalpha1 = 0;
623 _Kalpha2 = 0;
624 _Kbeta1 = 0;
625 _Kbeta3 = 0;
626 break;
627 case XraySource::Mg:
628 _name = "Mg";
629 // _wavelength = 0.7107;
630 _Kalpha1 = 9.889555;
631 _Kalpha2 = 9.89153;
632 _Kbeta1 = 0;
633 _Kbeta3 = 0;
634 break;
635 case XraySource::Al:
636 _name = "Al";
637 _Kalpha1 = 8.339515;
638 _Kalpha2 = 8.341832;
639 _Kbeta1 = 0;
640 _Kbeta3 = 0;
641 break;
642 case XraySource::Si:
643 _name = "Si";
644 _Kalpha1 = 7.125589;
645 _Kalpha2 = 7.12801;
646 _Kbeta1 = 0;
647 _Kbeta3 = 0;
648 break;
649 case XraySource::Cr:
650 _name = "Cr";
651 _Kalpha1 = 2.2897260;
652 _Kalpha2 = 2.2936510;
653 _Kbeta1 = 2.0848810;
654 _Kbeta3 = 2.0848810 ;
655 break;
656 case XraySource::Mn:
657 _name = "Mn";
658 _Kalpha1 = 2.1018540;
659 _Kalpha2 = 2.1058220;
660 _Kbeta1 = 1.9102160;
661 _Kbeta3 = 1.9102160 ;
662 break;
663 case XraySource::Fe:
664 _name = "Fe";
665 _Kalpha1 = 1.9360410;
666 _Kalpha2 = 1.9399730;
667 _Kbeta1 = 1.7566040;
668 _Kbeta3 = 1.7566040;
669 break;
670 case XraySource::Co:
671 _name = "Co";
672 _Kalpha1 = 1.7889960;
673 _Kalpha2 = 1.7928350;
674 _Kbeta1 = 1.6208260;
675 _Kbeta3 = 1.6208260 ;
676 break;
677 case XraySource::Ni:
678 _name = "Ni";
679 _Kalpha1 = 1.6579300;
680 _Kalpha2 = 1.6617560;
681 _Kbeta1 = 1.5001520;
682 _Kbeta3 = 1.5001520 ;
683 break;
684 case XraySource::Cu:
685 _name = "Cu";
686 _Kalpha1 = 1.5405930;
687 _Kalpha2 = 1.5444275;
688 _Kbeta1 = 1.392235;
689 _Kbeta3 = 1.392235 ;
690 break;
691 case XraySource::Ga:
692 _name = "Ga";
693 _Kalpha1 = 1.3401270;
694 _Kalpha2 = 1.3440260;
695 _Kbeta1 = 1.207930;
696 _Kbeta3 = 1.208390;
697 break;
698 case XraySource::Zr:
699 _name = "Zr";
700 _Kalpha1 = 0.785958;
701 _Kalpha2 = 0.790179;
702 _Kbeta1 = 0.701801;
703 _Kbeta3 = 0.702355 ;
704 break;
705 case XraySource::Mo:
706 _name = "Mo";
707 _Kalpha1 = 0.7093172;
708 _Kalpha2 = 0.71361;
709 _Kbeta1 = 0.632303;
710 _Kbeta3 = 0.632887;
711 break;
712 case XraySource::Ag:
713 _name = "Ag";
714 _Kalpha1 = 0.5594218;
715 _Kalpha2 = 0.563813;
716 _Kbeta1 = 0.497082;
717 _Kbeta3 = 0.497697;
718 break;
719 case XraySource::In:
720 _name = "In";
721 _Kalpha1 = 0.512126;
722 _Kalpha2 = 0.516558;
723 _Kbeta1 = 0.454562;
724 _Kbeta3 = 0.455197;
725 break;
726 case XraySource::CUSTOM:
727 _name = "Custom";
728 _Kalpha1 = 0;
729 _Kalpha2 = 0;
730 _Kbeta1 = 0;
731 _Kbeta3 = 0;
732 break;
733 default:
734 break;
735 }
736 }
737
738 double XraySource::wavelength(XraySource::XrayType type) const{
739 double res(0);
740
741 switch (type) {
742 case XraySource::WAVELENGTH:
743 res = (_Kalpha1*2+_Kalpha2)/3;
744 break;
745 case XraySource::KALPHA1:
746 res = _Kalpha1;
747 break;
748 case XraySource::KALPHA2:
749 res = _Kalpha2;
750 break;
751 case XraySource::KBETA1:
752 res = _Kbeta1;
753 break;
754 case XraySource::KBETA3:
755 res = _Kbeta3;
756 break;
757 default:
758 res = (_Kalpha1*2+_Kalpha2)/3;
759 break;
760 }
761 return res;
762 }