1 #include "fcvsfo.h"
2 #include "deprecation.h"
3
FcVsFo(QString filename,double a,double b,double c,double al,double be,double ga,double lambda)4 FcVsFo::FcVsFo(QString filename,double a,double b, double c, double al, double be, double ga, double lambda){
5 const double g2r=180.0/M_PI;
6 cell.wave=lambda;
7 cell.a=a;
8 cell.b=b;
9 cell.c=c;
10 cell.al=al;
11 cell.be=be;
12 cell.ga=ga;
13 cell.cosal = (cos(cell.be / g2r)*cos(cell.ga / g2r)-cos(cell.al / g2r))/(sin(cell.be / g2r)*sin(cell.ga / g2r));
14 cell.cosbe = (cos(cell.al / g2r)*cos(cell.ga / g2r)-cos(cell.be / g2r))/(sin(cell.al / g2r)*sin(cell.ga / g2r));
15 cell.cosga = (cos(cell.al / g2r)*cos(cell.be / g2r)-cos(cell.ga / g2r))/(sin(cell.be / g2r)*sin(cell.be / g2r));
16 cell.singa = sin(cell.ga / g2r);
17 cell.tanga = tan(cell.ga / g2r);
18 cell.phi = sqrt(1-(cell.cosal * cell.cosal)-
19 (cell.cosbe * cell.cosbe)-(cell.cosga * cell.cosga)
20 +2*cell.cosal * cell.cosbe * cell.cosga);
21 cell.tau = cell.c *((cell.cosal- cell.cosbe * cell.cosga) / cell.singa);
22 cell.V = cell.a * cell.b * cell.c*cell.phi;
23 cell.as = cell.c * cell.b * sin(cell.al / g2r) / cell.V;
24 cell.bs = cell.c * cell.a * sin(cell.be / g2r) / cell.V;
25 cell.cs = cell.a * cell.b * cell.singa / cell.V;
26 if (filename.endsWith(".fcf", Qt::CaseInsensitive)){
27 fileName=filename;
28 }else{
29 fileName=filename;
30 fileName.chop(3);
31 fileName.append("fcf");
32 }
33 foMax=foMin=fcMax=fcMin=0;
34 readFCF();
35 timer = new QTimer(this);
36 timer->setSingleShot(true);
37 connect(timer, SIGNAL(timeout()), this, SLOT(selektiert()));
38 QHBoxLayout *lh = new QHBoxLayout(this);
39 QVBoxLayout *lt = new QVBoxLayout();
40 QVBoxLayout *lr = new QVBoxLayout();
41 brw = new QTextBrowser(this);
42 brw->setLineWrapMode(QTextEdit::NoWrap);
43 brw->setHtml("<h1>Selected Reflections</h1>");
44
45 scene= new GraphSceene(-30,-10,550,530);
46 scene->setBackgroundBrush(QBrush(QColor("#e9f7d6")));
47 scene->clear ();
48
49 // qDebug()<<"Fo"<<foMin<< foMax<<"Fc "<<fcMin <<fcMax ;
50 QGraphicsItem *itm;
51 for (int i=0; i<51;i++){
52 itm=scene->addLine(i*10,0,i*10,500,QPen(QColor("#cbdbbb"),0));
53 itm->setData(0,-1);
54 itm=scene->addLine(0,i*10,500,i*10,QPen(QColor("#cbdbbb"),0));
55 itm->setData(0,-1);
56 }
57 // scene->addEllipse(50,450,2,2,QPen(Qt::NoPen),QBrush(QColor("#e90706")));
58 //double maxx2=-1000,minn2=10000;
59 //minn2=qMin(foMin*foMin,fcMin*fcMin);
60 //maxx2=qMax(foMax*foMax,fcMax*fcMax);
61 double maxx=-1000,minn=10000;
62 minn=qMin(foMin,fcMin);
63 maxx=qMax(foMax,fcMax);
64 //qDebug()<<minn<<maxx<< minn2<<maxx2;
65 for (int i=0; i<Fo.size(); i++){
66 // printf("%g %g\n",(Fo.at(i).F-foMin)/(foMax-foMin)*500,500-(Fc.at(i).F-fcMin)/(fcMax-fcMin)*500);
67
68 //itm=scene->addEllipse(((Fo.at(i).F*Fo.at(i).F)-minn2)/(maxx2-minn2)*500,500-((Fc.at(i).F*Fc.at(i).F)-minn2)/(maxx2-minn2)*500,2,2,QPen(Qt::NoPen),QBrush(QColor("#e90706")));
69 //itm->setData(0,i);
70 itm=scene->addEllipse((Fo.at(i).F-minn)/(maxx-minn)*500,500-(Fc.at(i).F-minn)/(maxx-minn)*500,1.5,1.5,QPen(Qt::NoPen),QBrush(QColor("#0907e6")));
71 itm->setData(0,i);
72 }
73 diagonale=scene->addLine(0,500,500,0,QColor("#d99999"));
74 itm->setData(0,-2);
75 itm=scene->addLine(0,0,3,5,QColor("#000000"));
76 itm->setData(0,-1);
77 itm=scene->addLine(0,0,-3,5,QColor("#000000"));
78 itm->setData(0,-1);
79 itm=scene->addLine(0,0,0,500,QPen(QColor("#000000"),1.1));
80 itm->setData(0,-1);
81 itm=scene->addLine(500,500,495,503,QColor("#000000"));
82 itm->setData(0,-1);
83 itm=scene->addLine(500,500,495,497,QColor("#000000"));
84 itm->setData(0,-1);
85 itm=scene->addLine(0,500,500,500,QPen(QColor("#000000"),1.0));
86 itm->setData(0,-1);
87 txt = scene->addText("Fc");
88 txt->moveBy(-20,10);
89 txt->setData(0,-1);
90 txt2 = scene->addText("Fo");
91 txt2->moveBy(480,503);
92 txt2->setData(0,-1);
93 QToolBar *tb=new QToolBar(this);
94 tb-> addAction(QIcon(":/xle-icons/zoom-in.png"),"Zoom +",this,SLOT(zoomin()));
95 tb-> addAction(QIcon(":/xle-icons/zoom-out.png"),"Zoom -",this,SLOT(zoomout()));
96 tb-> addAction(QIcon(":/xle-icons/zoom-fit.png"),"Zoom selected",this,SLOT(zoomfit()));
97 tb-> addAction(QIcon(":/xle-icons/zoom-off.png"),"Zoom out",this,SLOT(zoomoff()));
98 QComboBox *cbx=new QComboBox(this);
99 cbx->addItem("Fo vs. Fc",1);
100 cbx->addItem("Delta( F^2)/sigma vs. sin(theta/lambda)");
101 cbx->addItem("Fo / Fc vs. sin(theta/lambda)");
102 connect(cbx,SIGNAL(currentIndexChanged(int)),this,SLOT(graphChange(int)));
103 tb->addWidget(cbx);
104 view = new QGraphicsView(scene,this);
105 state = new QLabel("", this);
106 connect(scene,
107 SIGNAL(meinstatus(int)),
108 this,
109 SLOT(st(int)));
110 connect(scene,
111 SIGNAL(listen()),
112 this,
113 SLOT(delayMe()));
114 QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Close);
115 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
116 setMouseTracking(true);
117 //view.show();
118 scene->selEckt=scene->addRect(0,0,0,0,Qt::DashLine,QBrush(QColor("#d9e7e6")));
119 scene->selEckt-> setOpacity(0.5);
120 lt->addWidget(view);
121 lt->addWidget(tb);
122 lt->addWidget(state);
123 lt->addWidget(buttonBox);
124 QPushButton *omit =new QPushButton("Omit reflections",this);
125 connect(omit, SIGNAL(clicked()), this, SLOT(omitref()));
126 lr->addWidget(brw);
127 lr->addWidget(omit);
128 lh->addLayout(lt);
129 lh->addLayout(lr);
130 //setLayout(lh);
131 // int da= scene->itemAt(50, 50)->data(0).toInt();
132 // qDebug()<<Fo.at(da).h<<Fo.at(da).k<<Fo.at(da).l<<Fo.at(da).F<<Fc.at(da).F;
133 }
134
~FcVsFo()135 FcVsFo::~FcVsFo(){
136 // qDebug()<<"a";
137 Fo.clear();
138 // qDebug()<<"b";
139 Fc.clear();
140 // qDebug()<<"c";
141 // qDebug()<<"d";
142 scene->selected.clear();
143 // qDebug()<<"e";
144 scene->clear();
145 // qDebug()<<"f";
146 }
147
delayMe()148 void FcVsFo::delayMe(){
149 if (!timer->isActive()) timer->start(80);
150 }
151
zoomin()152 void FcVsFo::zoomin(){
153 view->scale(1.05,1.05);
154 }
155
zoomout()156 void FcVsFo::zoomout(){
157 view->scale(0.95,0.95);
158
159 }
160
zoomfit()161 void FcVsFo::zoomfit(){
162 view->fitInView(QRectF(scene->selStart,scene->selEnd),Qt::KeepAspectRatio);//Qt::KeepAspectRatio);
163 }
164
zoomoff()165 void FcVsFo::zoomoff(){
166 view->fitInView(QRectF(-30,-10,550,530),Qt::KeepAspectRatio);
167 }
168
readFCF()169 void FcVsFo::readFCF(){
170 QFile f(fileName);
171 listType=0;
172 f.open(QIODevice::ReadOnly|QIODevice::Text);
173 // figure out what list type it is...
174 QString test=QString(f.readLine(120));
175 QStringList lines;
176 if (test.contains("index")) listType=1;
177 //qDebug()<<test<<test.contains(QRegExp("\\s*\\d+\\s*\\d+\\s*\\d+\\s*\\d+\\.\\d+\\s*\\d+\\.\\d+\\s*\\d+"));
178 if (test.contains(QRegExp("\\s*\\d+\\s*\\d+\\s*\\d+\\s*\\d+\\.\\d+\\s*\\d+\\.\\d+\\s*\\d+"))) listType=2;
179 if (test.contains(QRegExp("\\s*\\d+\\s*\\d+\\s*\\d+\\s*\\d+\\.\\d+\\s*\\d+\\.\\d+\\s*\\d+\\.\\d+"))) listType=5;
180 if ((test.startsWith("#"))||(test.startsWith("data"))){
181 while (!test.isEmpty()){
182 test=QString(f.readLine(120));
183 if (test.startsWith("_shelx_refln_list_code")){
184 test.remove(0,22);
185 test=test.trimmed();
186 listType=test.toInt();
187 break;
188 }
189 }
190 }
191 //printf("list type %d \n",listType);
192 QStringList tok;
193 Refls obs,cal;
194 double a,b;
195 cal.sigma=obs.sigma=0;
196 switch (listType){
197 case 0:
198 ;
199 break;
200 case 1:
201 f.reset();
202 lines=QString(f.readAll()).split(QRegExp("[\\r\\n]"),skipEmptyParts);
203 for (int i=0; i<lines.size(); i++){
204 tok=lines.at(i).split(' ',skipEmptyParts);
205 if (!tok.isEmpty()){
206 obs.h=cal.h=tok.at(1).toInt();
207 obs.k=cal.k=tok.at(2).toInt();
208 obs.l=cal.l=tok.at(3).toInt();
209 obs.F=tok.at(5).toDouble();
210 cal.F=tok.at(7).toDouble();
211 obs.stl=cal.stl=
212 sqrt(
213 obs.h*obs.h*cell.as*cell.as+
214 obs.k*obs.k*cell.bs*cell.bs+
215 obs.l*obs.l*cell.cs*cell.cs+
216 2*obs.h*obs.l*cell.as*cell.cs*cell.cosbe+
217 2*obs.k*obs.l*cell.bs*cell.cs*cell.cosal+
218 2*obs.h*obs.k*cell.as*cell.bs*cell.cosga)/2.0;
219
220
221
222 obs.phase=cal.phase=tok.at(8).toDouble();
223 Fc.append(cal);
224 Fo.append(obs);
225 }
226 }
227 break;
228 case 3:{
229 f.reset();
230 lines=QString(f.readAll()).split(QRegExp("[\\r\\n]"),skipEmptyParts);
231
232 int i= 0;
233 for (int j=0; !j; i++){
234 if (lines.at(i).contains("_refln_B_calc")) j++;
235 }
236 for (; i<lines.size(); i++){
237 tok=lines.at(i).split(' ',skipEmptyParts);
238 if (!tok.isEmpty()&&(tok.size()==7)){
239 obs.h= cal.h=tok.at(0).toInt();
240 obs.k= cal.k=tok.at(1).toInt();
241 obs.l= cal.l=tok.at(2).toInt();
242 obs.F= tok.at(3).toDouble();
243 obs.sigma= tok.at(4).toDouble();
244 a= tok.at(5).toDouble();
245 b= tok.at(6).toDouble();
246 cal.F= sqrt(a*a+b*b);
247 double FF= (b<0)?-1:1;
248 obs.phase= cal.phase= (cal.F!=0)?FF*acosf(a/cal.F):0;
249 obs.phase= cal.phase=fmod(4*M_PI+cal.phase,2*M_PI);
250 obs.stl=cal.stl=
251 sqrt(
252 obs.h*obs.h*cell.as*cell.as+
253 obs.k*obs.k*cell.bs*cell.bs+
254 obs.l*obs.l*cell.cs*cell.cs+
255 2*obs.h*obs.l*cell.as*cell.cs*cell.cosbe+
256 2*obs.k*obs.l*cell.bs*cell.cs*cell.cosal+
257 2*obs.h*obs.k*cell.as*cell.bs*cell.cosga)/2.0;
258 Fc.append(cal);
259 Fo.append(obs);
260 }
261 }
262 }
263 break;
264 case 4:{
265 f.reset();
266 lines=QString(f.readAll()).split(QRegExp("[\\r\\n]"),skipEmptyParts);
267
268 int i= 0;
269 for (int j=0; !j; i++){
270 if (lines.at(i).contains("_refln_observed_status")) j++;
271 }
272 for (; i<lines.size(); i++){
273 tok=lines.at(i).split(' ',skipEmptyParts);
274 if (!tok.isEmpty()&&(tok.size()==7)){
275 obs.h= cal.h=tok.at(0).toInt();
276 obs.k= cal.k=tok.at(1).toInt();
277 obs.l= cal.l=tok.at(2).toInt();
278 obs.F= sqrt(fabs(tok.at(4).toDouble()));
279 if (tok.at(4).toDouble()<0) obs.F*=-1;
280 cal.F= sqrt(fabs(tok.at(3).toDouble()));
281 if (tok.at(3).toDouble()<0) cal.F*=-1;
282 cal.sigma=obs.sigma=tok.at(5).toDouble();
283 obs.stl=cal.stl=
284 sqrt(
285 obs.h*obs.h*cell.as*cell.as+
286 obs.k*obs.k*cell.bs*cell.bs+
287 obs.l*obs.l*cell.cs*cell.cs+
288 2*obs.h*obs.l*cell.as*cell.cs*cell.cosbe+
289 2*obs.k*obs.l*cell.bs*cell.cs*cell.cosal+
290 2*obs.h*obs.k*cell.as*cell.bs*cell.cosga)/2.0;
291 Fc.append(cal);
292 Fo.append(obs);
293 }
294 }
295
296 }
297 // qDebug()<<"List4 OK";
298 break;
299 case 5:f.reset();
300 lines=QString(f.readAll()).split(QRegExp("[\\r\\n]"),skipEmptyParts);
301 for (int i=0; i<lines.size(); i++){
302 tok=lines.at(i).split(' ',skipEmptyParts);
303 if (!tok.isEmpty()&&(tok.size()>5)){
304 obs.h=cal.h=tok.at(0).toInt();
305 obs.k=cal.k=tok.at(1).toInt();
306 obs.l=cal.l=tok.at(2).toInt();
307 obs.F=tok.at(3).toDouble();
308 cal.F=tok.at(4).toDouble();
309 obs.phase=cal.phase=tok.at(5).toDouble();
310 obs.stl=cal.stl=
311 sqrt(
312 obs.h*obs.h*cell.as*cell.as+
313 obs.k*obs.k*cell.bs*cell.bs+
314 obs.l*obs.l*cell.cs*cell.cs+
315 2*obs.h*obs.l*cell.as*cell.cs*cell.cosbe+
316 2*obs.k*obs.l*cell.bs*cell.cs*cell.cosal+
317 2*obs.h*obs.k*cell.as*cell.bs*cell.cosga)/2.0;
318 Fc.append(cal);
319 Fo.append(obs);
320 }
321 }
322
323 break;
324 case 6:{
325 f.reset();
326 lines=QString(f.readAll()).split(QRegExp("[\\r\\n]"),skipEmptyParts);
327
328 int i= 0;
329 for (int j=0; (!j)&&(i<lines.size()); i++){
330 if (lines.at(i).contains("_refln_phase_calc")) j++;
331 }
332 // qDebug()<<i<<lines.at(i);
333 for (; i<lines.size(); i++){
334 tok=lines.at(i).split(' ',skipEmptyParts);
335 if (!tok.isEmpty()&&(tok.size()==7)){
336 obs.h= cal.h=tok.at(0).toInt();
337 obs.k= cal.k=tok.at(1).toInt();
338 obs.l= cal.l=tok.at(2).toInt();
339 obs.F= sqrt(fabs(tok.at(3).toDouble()));
340 cal.sigma=obs.sigma=tok.at(4).toDouble();
341 cal.F= tok.at(5).toDouble();
342 obs.phase=cal.phase=tok.at(6).toDouble();
343 obs.stl=cal.stl=
344 sqrt(
345 obs.h*obs.h*cell.as*cell.as+
346 obs.k*obs.k*cell.bs*cell.bs+
347 obs.l*obs.l*cell.cs*cell.cs+
348 2*obs.h*obs.l*cell.as*cell.cs*cell.cosbe+
349 2*obs.k*obs.l*cell.bs*cell.cs*cell.cosal+
350 2*obs.h*obs.k*cell.as*cell.bs*cell.cosga)/2.0;
351 Fc.append(cal);
352 Fo.append(obs);
353 // printf("%d %d %d %f %f\n",obs.h,obs.k,obs.l,obs.F,cal.F);
354 }
355 }
356
357 }
358 // qDebug()<<"List6 OK";
359
360 break;
361 case 7:{
362
363 }
364 break;
365 case 8:{
366
367 f.reset();
368 lines=QString(f.readAll()).split(QRegExp("[\\r\\n]"),skipEmptyParts);
369
370 int i= 0;
371 for (int j=0; (!j)&&(i<lines.size()); i++){
372 if (lines.at(i).contains("_shelx_refinement_sigma")) j++;
373 }
374 // qDebug()<<i<<lines.at(i-1);
375 for (; i<lines.size(); i++){
376 tok=lines.at(i).split(' ',skipEmptyParts);
377 if (!tok.isEmpty()&&(tok.size()==9)){
378 obs.h= cal.h=tok.at(0).toInt();
379 obs.k= cal.k=tok.at(1).toInt();
380 obs.l= cal.l=tok.at(2).toInt();
381 obs.F= sqrt(fabs(tok.at(3).toDouble()));
382 cal.sigma=obs.sigma=tok.at(4).toDouble();
383 cal.F= sqrt(fabs(tok.at(5).toDouble()));
384 obs.phase=cal.phase=tok.at(6).toDouble();
385 obs.stl=cal.stl=1.0/(2.0*tok.at(7).toDouble());
386 obs.w=tok.at(8).toDouble();
387 Fc.append(cal);
388 Fo.append(obs);
389 }
390 }
391 }
392 break;
393 default:
394 break;
395
396 }
397 // qDebug() << Fo.size() << Fc.size() << Fo.last().F<<Fc.last().F;
398 f.close();
399 foMin=fcMin=1000000;
400 for (int i=0; i<Fo.size(); i++){
401 foMax=qMax(foMax,Fo.at(i).F);
402 foMin=qMin(foMin,Fo.at(i).F);
403 fcMax=qMax(fcMax,Fc.at(i).F);
404 fcMin=qMin(fcMin,Fc.at(i).F);
405 }
406 // Fo.clear();
407 // Fc.clear();
408 // qDebug()<<"Fo"<<foMin<< foMax<<"Fc "<<fcMin <<fcMax ;
409 lines.clear();
410 // qDebug()<<"Fo"<<foMin<< foMax<<"Fc "<<fcMin <<fcMax ;
411 }
412
omitref()413 void FcVsFo::omitref(){
414 QString omitstr;
415 for (int i=0; i<scene->selected.size(); i++){
416 omitstr.append(QString("OMIT %1 %2 %3\n")
417 .arg(Fo.at(scene->selected.at(i)).h)
418 .arg(Fo.at(scene->selected.at(i)).k)
419 .arg(Fo.at(scene->selected.at(i)).l));
420 }
421 emit weg(omitstr);
422 }
423
selektiert()424 void FcVsFo::selektiert(){
425
426 QString s="<h1>Selected Reflections</h1> <table><tr><th width=\"30\">h</th><th width=\"30\">k</th><th width=\"30\">l</th><th width=\"50\">Fo<sup>2</sup></th><th width=\"50\">Fc<sup>2</sup></th><th width=\"50\">Δ(F<sup>2</sup>)/sigma</th><th width=\"50\">sigma</th><th width=\"50\">sin(theta)/lambda</th></tr>\n";
427 //double wghta=0,wghtb=0;
428 for (int i=0; i<scene->selected.size(); i++){
429 int sel=scene->selected.at(i);
430
431 // Weight = 1 / [ sigma^2(Fo^2) + ( 0.0693 * P )^2 + 0.00 * P ] where P = ( Max ( Fo^2, 0 ) + 2 * Fc^2 ) / 3
432 // double P= (qMax(0.0,Fo.at(sel).F*Fo.at(sel).F) + 2.0 * Fc.at(sel).F * Fc.at(sel).F )/3.0;
433 // double wght=1.0/(Fo.at(sel).sigma + ( wghta * P)*( wghta * P) +wghtb*P);
434 s.append(QString(
435 "<tr>"
436 "<th style=\"text-align: right;\" >%1</th>"
437 "<th style=\"text-align: right;\" >%2</th>"
438 "<th style=\"text-align: right;\" >%3</th>"
439 "<th style=\"text-align: right;\" >%4</th>"
440 "<th style=\"text-align: right;\" >%5</th>"
441 "<th style=\"text-align: right;\" >%6</th>"
442 "<th style=\"text-align: right;\" >%7</th>"
443 "<th style=\"text-align: right;\" >%8</th></tr>\n")
444 .arg(Fo.at(sel).h)
445 .arg(Fo.at(sel).k)
446 .arg(Fo.at(sel).l)
447 .arg(Fo.at(sel).F*
448 Fo.at(sel).F)
449 .arg(Fc.at(sel).F*
450 Fc.at(sel).F)
451 .arg(fabs(Fo.at(sel).F*Fo.at(sel).F-
452 Fc.at(sel).F*Fc.at(sel).F)/ (Fc.at(sel).sigma))
453 .arg(Fc.at(sel).sigma)
454 .arg(Fc.at(sel).stl));
455 //Delta(F^2)/esd Fc/Fc(max) Resolution(A)
456 //
457 // qDebug()<<Fo.at(scene->selected.at(i)).h<<Fo.at(scene->selected.at(i)).k<<Fo.at(scene->selected.at(i)).l<<Fo.at(scene->selected.at(i)).F<<Fc.at(scene->selected.at(i)).F;
458 }
459 s.append("</table>\n");
460 // qDebug()<<s;
461 brw->setHtml(s);
462 }
463
graphChange(int type)464 void FcVsFo::graphChange(int type){
465 QList<QGraphicsItem *> drin= scene->items (QRectF(-30,-10,550,530),Qt::ContainsItemShape);
466 view->hide();
467 double maxx=-1000,minn=10000;
468 minn=qMin(foMin,fcMin);
469 maxx=qMax(foMax,fcMax);
470 double maxsintl=0;
471 switch (type){
472 case 1:
473 {
474 if (txt2->toPlainText()!="sin(theta)/lambda"){
475 txt2->setPlainText("sin(theta)/lambda");
476 txt2->moveBy(-100,0);
477 }
478 txt->setPlainText("Delta( F^2)/sigma(F^2)");
479 maxx=-1000;
480 minn=10000;
481 for (int i=0; i<Fo.size(); i++){
482 double xx=fabs(Fo.at(i).F*Fo.at(i).F-Fc.at(i).F*Fc.at(i).F)/Fo.at(i).sigma;
483 minn=qMin(minn,xx);
484 maxx=qMax(maxx,xx);
485 // qDebug()<<Fo.at(i).stl<<maxsintl;
486 maxsintl=qMax(maxsintl,Fo.at(i).stl);
487 }
488 }
489 break;
490 case 0:
491 {
492 txt->setPlainText("Fc");
493 txt2->setPlainText("Fo");
494 txt2->moveBy(100,0);
495 }
496 break;
497 case 2:
498 {
499 if (txt2->toPlainText()!="sin(theta) / lambda"){
500 txt2->setPlainText("sin(theta) / lambda");
501 txt2->moveBy(-100,0);
502 }
503 txt->setPlainText("Fo / Fc");
504 maxx=-1000;
505 minn=10000;
506 for (int i=0; i<Fo.size(); i++){
507 double xx=Fo.at(i).F/Fc.at(i).F;
508 if ((std_isnormal(xx))&&(xx>0.001)){
509 minn=qMin(minn,xx);
510 maxx=qMax(maxx,xx);
511 // qDebug()<<Fo.at(i).stl<<maxsintl<<xx;
512 maxsintl=qMax(maxsintl,Fo.at(i).stl);
513 }
514 }
515
516 }
517 break;
518 }
519 QRectF ect;
520 if (type!=0) diagonale->hide();
521 else diagonale->show();
522 for (int i=0; i<drin.size();i++){
523 bool ok=false;
524 int ix;
525 ix=drin.at(i)->data(0).toInt(&ok);
526 ect=drin.at(i)->sceneBoundingRect();
527 if ((ix>-1)&&(ok)&&(ix<Fo.size())&&(ix<Fc.size())) {
528 drin[i]->moveBy(-ect.x(),-ect.y());
529 switch (type){
530 case 0:
531 drin[i]->moveBy((Fo.at(ix).F-minn)/(maxx-minn)*500,500-(Fc.at(ix).F-minn)/(maxx-minn)*500);
532 break;
533 case 1:{
534 double xx=fabs(Fo.at(ix).F*Fo.at(ix).F-Fc.at(ix).F*Fc.at(ix).F)/Fo.at(ix).sigma;
535 if ((std_isnormal(Fc.at(ix).stl))&&(std_isnormal(xx))){
536 // printf("%g %g\n",Fc.at(ix).stl/maxsintl*500,500-(xx-minn)/(maxx-minn)*500);
537 drin[i]->moveBy(Fc.at(ix).stl/maxsintl*500,500-(xx-minn)/(maxx-minn)*500);
538 }
539 else drin[i]->moveBy(0,500);
540 }
541 break;
542 case 2:{
543 double xx=Fo.at(ix).F / Fc.at(ix).F;
544 if ((std_isnormal(Fc.at(ix).stl))&&(std_isnormal(xx))){
545 drin[i]->moveBy(Fc.at(ix).stl/maxsintl*500,500-(xx-minn)/(maxx-minn)*500);
546 }
547 else drin[i]->moveBy(0,500);
548 }
549 break;
550
551 }
552
553 }
554 }
555 view->show();
556 }
557
558
GraphSceene(qreal x,qreal y,qreal width,qreal height,QObject * parent)559 GraphSceene::GraphSceene( qreal x, qreal y, qreal width, qreal height, QObject * parent ) :QGraphicsScene ( x, y, width, height, parent){
560 //constructor
561 }
562
mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)563 void GraphSceene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ){
564 qreal x= mouseEvent->scenePos().x(),
565 y= mouseEvent->scenePos().y();
566 // qDebug()<<mouseEvent->buttons()<< mouseEvent->buttonDownScreenPos (Qt::LeftButton);
567 if (mouseEvent->buttons()&Qt::LeftButton){
568 QPointF oli,ure;//oben links , unten rechts
569 oli.setX(qMin(selStart.x(),selEnd.x()));
570 oli.setY(qMin(selStart.y(),selEnd.y()));
571 ure.setX(qMax(selStart.x(),selEnd.x()));
572 ure.setY(qMax(selStart.y(),selEnd.y()));
573 QList<QGraphicsItem *> drin= items ( QRectF(oli,ure),Qt::ContainsItemShape);
574 // qDebug()<<drin.size();
575 selected.clear();
576 if (drin.size()){
577 for (int i=0; i<drin.size();i++){
578 bool ok=false;
579 int ix;
580 ix=drin.at(i)->data(0).toInt(&ok);
581 if ((ix>-1)&&(selected.size()<100)&&(ok)) selected.append(ix);
582 }
583 emit listen();
584 }
585 selStart = mouseEvent->buttonDownScenePos (Qt::LeftButton);
586 selEnd = mouseEvent->scenePos();
587 //if (selStart!=QPointF(0,0)) selEckt->setRect(QRectF(selStart,selEnd));
588 if (selStart!=QPointF(0,0)) selEckt->setRect(QRectF(oli,ure));
589 drin.clear();
590 // qDebug()<<"End"<<selEnd;
591 }else{
592 // qDebug()<<x<<y;
593 if (!itemAt(x,y,QTransform())) emit meinstatus(-1);
594 else{
595 int da = itemAt(x,y,QTransform())->data(0).toInt();
596 emit meinstatus(da);
597 }
598 }
599 }
600
mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)601 void GraphSceene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ){
602 if (mouseEvent->button()==Qt::LeftButton){
603 selEckt->setRect(0,0,0,0);
604 selected.clear();
605 emit listen();
606 // qDebug()<<"start"<<selStart;
607 }
608 }
609
610
611
st(int da)612 void FcVsFo::st(int da){
613 if (da<0) state->setText("");
614 else{
615 QString s;
616 s=QString("%1 %2 %3 Fo=%4 Fc%5 delta(F^2)/sigma(F^2)= %6")
617 .arg(Fo.at(da).h).arg(Fo.at(da).k).arg(Fo.at(da).l).arg(Fo.at(da).F).arg(Fc.at(da).F)
618 .arg(fabs(Fo.at(da).F*Fo.at(da).F-Fc.at(da).F*Fc.at(da).F)/Fo.at(da).sigma)
619 ;
620 state->setText(s);
621 }
622 }
623