Debian Codegraph @

chgl.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Christian B. Huebschle & George M. Sheldrick
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 //äöüß needed to keep this file UTF8 QString::fromUtf8("»")
19 #include "chgl.h"
20 #include "deprecation.h"
21 //#if defined (Q_WS_MAC) || defined (Q_OS_MAC)
22 //#include <OpenGL/glu.h>
23 //#include <glu.h>
24 //#else
25 //#include <GL/glu.h>
26 //#endif
27 #include <QtGui>
28 #include <QtOpenGL>
29 #include <QDialog>
30 #include <QFileDialog>
31 #include <QInputDialog>
32 #include <QMenu>
33 #include <QColorDialog>
34 #include <QDialogButtonBox>
35 #include <QPushButton>
36 #include "glureplace.h"
37 #ifndef GL_MULTISAMPLE
38 #define ICH_KANNTE_NICHT_MS 42
39 #define GL_MULTISAMPLE 0x809D
40 #endif
41 //
42 //#define HIDE_REASON_SELECT 1
43 //#define HIDE_REASON_THIS_FRAGMENT 2
44 //#define HIDE_REASON_OTHER_FRAGMENT 4
45 //#define HIDE_REASON_HYDROGEN 8
46 //#define HIDE_REASON_QPEAK 16
47 //
48
49
50 inline void ChGL::__RotateCS( double c, double s, double& X, double& Y ) {
51 double T = X;
52 X = c*X - s*Y;
53 Y = s*T + c*Y;
54 }
55
56 void ChGL::glTranslateL( const double dx, const double dy, const double dz ) {
57 double mat[4][4];
58 makeCurrent();
59 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mat );
60 mat[3][0] += dx; mat[3][1] += dy; mat[3][2] += dz;
61 glLoadMatrixd((double*)mat);
62 }
63 void ChGL::glRotateL( const double dang, const double x, const double y, const double z ) {
64 makeCurrent();
65 double mat[4][4];
66 #ifndef M_PI
67 #define M_PI 3.14159265358979323846 /* pi */
68 #endif
69 double s = z;
70 s = sin(dang*M_PI/180);
71 const double c = cos(dang*M_PI/180);
72 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mat );
73 // glGetDoublev( GL_PROJECTION_MATRIX, (double*)mat );
74 if( x!=0.0 ){
75 __RotateCS( c, s, mat[0][1], mat[0][2] );
76 __RotateCS( c, s, mat[1][1], mat[1][2] );
77 __RotateCS( c, s, mat[2][1], mat[2][2] );
78 // printf("x\n");
79 }else if( y!=0.0 ){
80 __RotateCS( c, s, mat[0][2], mat[0][0] );
81 __RotateCS( c, s, mat[1][2], mat[1][0] );
82 __RotateCS( c, s, mat[2][2], mat[2][0] );
83 // printf("y\n");
84 }else{
85 __RotateCS( c, s, mat[0][0], mat[0][1] );
86 __RotateCS( c, s, mat[1][0], mat[1][1] );
87 __RotateCS( c, s, mat[2][0], mat[2][1] );
88 // printf("z\n");
89 }
90 glLoadMatrixd((double*)mat);
91 }
92
93 void ChGL::glRotateMat( Matrix &mat, const double dang, const double x, const double y, const double z ) {
94 #ifndef M_PI
95 #define M_PI 3.14159265358979323846 /* pi */
96 #endif
97 double s = z;
98 s = sin(dang*M_PI/180);
99 const double c = cos(dang*M_PI/180);
100 if( x!=0.0 ){
101 __RotateCS( c, s, mat.m21, mat.m31 );
102 __RotateCS( c, s, mat.m22, mat.m32 );
103 __RotateCS( c, s, mat.m23, mat.m33 );
104 // printf("x\n");
105 }else if( y!=0.0 ){
106 __RotateCS( c, s, mat.m31, mat.m11 );
107 __RotateCS( c, s, mat.m32, mat.m12 );
108 __RotateCS( c, s, mat.m33, mat.m13 );
109 // printf("y\n");
110 }else{
111 __RotateCS( c, s, mat.m11, mat.m21 );
112 __RotateCS( c, s, mat.m12, mat.m22 );
113 __RotateCS( c, s, mat.m13, mat.m23 );
114 // printf("z\n");
115 }
116 }
117
118
119
120 void ChGL::saveOrientation(){
121 QString fn=QFileDialog::getSaveFileName(this, tr("Save Orientation into file "), "orientation.ini",
122 "orientation.ini (*.ini);;");
123
124 if (fn.isEmpty()) return;
125 QFile mconf(fn);
126 mconf.open(QIODevice::WriteOnly|QIODevice::Text);
127 GLdouble mm[16];
128 makeCurrent();
129 glGetDoublev(GL_MODELVIEW_MATRIX,mm);
130 mconf.write(QString("%1/%2/%3/%4/%5/%6/%7/%8/%9/%10/%11/%12/%13/%14/%15/%16\n")
131 .arg(mm[0]).arg(mm[1]).arg(mm[2]).arg(mm[3]).arg( mm[4]).arg(mm[5])
132 .arg(mm[6]).arg(mm[7]).arg( mm[8]).arg(mm[9]).arg(mm[10]).arg(mm[11])
133 .arg( mm[12]).arg(mm[13]).arg(mm[14]).arg(mm[15]).toLatin1());
134 mconf.close();
135 }
136
137 void ChGL::saveOrientation(QString fn){
138 if (fn.isEmpty()) return;
139 QFile mconf(fn);
140 mconf.open(QIODevice::WriteOnly|QIODevice::Text);
141 GLdouble mm[16];
142 glGetDoublev(GL_MODELVIEW_MATRIX,mm);
143 mconf.write(QString("%1/%2/%3/%4/%5/%6/%7/%8/%9/%10/%11/%12/%13/%14/%15/%16\n")
144 .arg(mm[0]).arg(mm[1]).arg(mm[2]).arg(mm[3]).arg( mm[4]).arg(mm[5])
145 .arg(mm[6]).arg(mm[7]).arg( mm[8]).arg(mm[9]).arg(mm[10]).arg(mm[11])
146 .arg( mm[12]).arg(mm[13]).arg(mm[14]).arg(mm[15]).toLatin1());
147 mconf.close();
148 }
149
150 void ChGL::rotateIdle(){
151 if (idl!=NULL){
152 glRotateL(0.5,0.0,1.0,0.0);
153 update();
154 }
155 }
156
157 void ChGL::loadOrientation(QString fn){
158 if (fn.isEmpty()) return;
159 QFile miconf(fn);
160 miconf.open(QIODevice::ReadOnly|QIODevice::Text);
161 QString all=miconf.readAll();
162 miconf.close();
163
164 MM[0] = all.section('/',0,0).toDouble();
165 MM[1] = all.section('/',1,1).toDouble();
166 MM[2] = all.section('/',2,2).toDouble();
167 MM[3] = all.section('/',3,3).toDouble();
168 MM[4] = all.section('/',4,4).toDouble();
169 MM[5] = all.section('/',5,5).toDouble();
170 MM[6] = all.section('/',6,6).toDouble();
171 MM[7] = all.section('/',7,7).toDouble();
172 MM[8] = all.section('/',8,8).toDouble();
173 MM[9] = all.section('/',9,9).toDouble();
174 MM[10]= all.section('/',10,10).toDouble();
175 MM[11]= all.section('/',11,11).toDouble();
176 MM[12]= all.section('/',12,12).toDouble();
177 MM[13]= all.section('/',13,13).toDouble();
178 MM[14]= all.section('/',14,14).toDouble();
179 MM[15]= all.section('/',15,15).toDouble();
180 printf("matrix:\n%12g %12g %12g %12g\n%12g %12g %12g %12g\n%12g %12g %12g %12g\n%12g %12g %12g %12g\n",
181 MM[0],
182 MM[1] ,
183 MM[2] ,
184 MM[3] ,
185 MM[4] ,
186 MM[5] ,
187 MM[6] ,
188 MM[7] ,
189 MM[8] ,
190 MM[9] ,
191 MM[10],
192 MM[11],
193 MM[12],
194 MM[13],
195 MM[14],
196 MM[15]);
197 setMatrix();
198 // emit mconf();
199 update();
200 }
201
202 void ChGL::loadOrientation(){
203 QString fn=QFileDialog::getOpenFileName(this, tr("Open MoleCoolQt MolIso Settings file "), "MoleCoolQt.moliso.ini",
204 "MoleCoolQt.moliso.ini (*.ini);;" );
205
206 if (fn.isEmpty()) return;
207 QFile miconf(fn);
208 miconf.open(QIODevice::ReadOnly|QIODevice::Text);
209 QString all=miconf.readAll();
210 miconf.close();
211
212 MM[0] = all.section('/',0,0).toDouble();
213 MM[1] = all.section('/',1,1).toDouble();
214 MM[2] = all.section('/',2,2).toDouble();
215 MM[3] = all.section('/',3,3).toDouble();
216 MM[4] = all.section('/',4,4).toDouble();
217 MM[5] = all.section('/',5,5).toDouble();
218 MM[6] = all.section('/',6,6).toDouble();
219 MM[7] = all.section('/',7,7).toDouble();
220 MM[8] = all.section('/',8,8).toDouble();
221 MM[9] = all.section('/',9,9).toDouble();
222 MM[10]= all.section('/',10,10).toDouble();
223 MM[11]= all.section('/',11,11).toDouble();
224 MM[12]= all.section('/',12,12).toDouble();
225 MM[13]= all.section('/',13,13).toDouble();
226 MM[14]= all.section('/',14,14).toDouble();
227 MM[15]= all.section('/',15,15).toDouble();
228 printf("matrix:\n%12g %12g %12g %12g\n%12g %12g %12g %12g\n%12g %12g %12g %12g\n%12g %12g %12g %12g\n",
229 MM[0],
230 MM[1] ,
231 MM[2] ,
232 MM[3] ,
233 MM[4] ,
234 MM[5] ,
235 MM[6] ,
236 MM[7] ,
237 MM[8] ,
238 MM[9] ,
239 MM[10],
240 MM[11],
241 MM[12],
242 MM[13],
243 MM[14],
244 MM[15]);
245 setMatrix();
246 // emit mconf();
247 update();
248 }
249
250 void ChGL::setMatrix(){
251 glMatrixMode(GL_MODELVIEW);
252 /*GLdouble det=
253 MM[0]*MM[5]*MM[10] - MM[8]*MM[5]*MM[2]+
254 MM[1]*MM[6]*MM[8] - MM[9]*MM[6]*MM[0]+
255 MM[2]*MM[4]*MM[9] - MM[10]*MM[4]*MM[1];*/
256 //printf("Determinant is %g\n",det);
257 //if ((det>0.1)&&(det<9.0))
258 glLoadMatrixd(MM);
259 /*else {
260 MM[0]=1;
261 MM[1]=0;
262 MM[2]=0;
263 MM[3]=0;
264 MM[4]=0;
265 MM[5]=1;
266 MM[6]=0;
267 MM[7]=0;
268 MM[8]=0;
269 MM[9]=0;
270 MM[10]=1;
271 MM[11]=0;
272 MM[12]=0;
273 MM[13]=0;
274 MM[14]=-200;
275 MM[15]=1;
276 glLoadIdentity();
277 glLoadMatrixd(MM);
278 }*/
279 update();
280 }
281
282
283 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
284 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
285 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
286 //ChGL::ChGL(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers),parent){ ///////////////
287 ChGL::ChGL(QWidget *parent) :QOpenGLWidget(parent) {
288 //printf("ChGL::ChGL\n");|QGL::DoubleBuffer|QGL::DepthBuffer|QGL::DirectRendering|QGL::StereoBuffers
289 QSurfaceFormat glf=format();
290 printf(" stereo=%d samples=%d sync?%d\n"
291 ,glf.stereo(),glf.samples(),glf.swapInterval());
292 #ifdef ICH_KANNTE_NICHT_MS
293 printf("msaa ndef %d\n",ICH_KANNTE_NICHT_MS);
294 #endif
295 inRenameMode=false;
296 fVertexes.resize(28);
297 fNormals.resize(28);
298 pause=true;
299 altpivot=false;
300 whyNotSplit=NULL;
301 axx=NULL;
302 axy=NULL;
303 axz=NULL;
304 depthcueing=false;
305 retinafktr=1;
306 on=false;
307 idl=NULL;
308 manualAx=NULL;
309 //orthoView=false;
310 withsymm=0;
311 labScal=0.3;
312 exporting=false;
313 dratpause=80;
314 murx=0;
315 chparent=parent;
316 envirange=3.2;
317 apair.clear();
318 enviNoQ= new QAction("Exclude Q-peaks from environment listing", this);
319 enviCova = new QAction("List only covalent bonds.",this);
320 enviButt= new QToolButton(this);
321 enviButt->setText("clear ENVI");
322 connect(enviButt,SIGNAL(clicked()),this,SLOT(clearEnvi()));
323 enviSelect= new QToolButton(this);
324 enviSelect->setText("Select ENVI");
325 connect(enviSelect,SIGNAL(clicked()),this,SLOT(selectEnvi()));
326 wireButt= new QAction("Wiremodel while rotate",this);
327 wireButt->setCheckable(true);
328 wireButt->setChecked(false);//defaut changed 13.12.2019
329 rainbowPlot= new QAction("Contour plot in rainbow colors",this);
330 rainbowPlot->setCheckable(true);
331 rainbowPlot->setChecked(false);
332 rainbowPlot->setVisible(false);
333 enviButt->setVisible(false);
334 enviSelect->setVisible(false);
335 enviNoQ->setCheckable(true);
336 enviNoQ->setChecked(false);
337 enviCova->setCheckable(true);
338 enviCova->setChecked(false);
339 mol=new Molecule();
340 if (mol->mynewnameis=="shelXle"){
341 theIconPath=QString(":/xle-icons/");
342 }else{
343 theIconPath=QString(":/bicons/");
344 }
345 warLabel=noWaitLabel=false;
346 viewAngle=29.0;
347 imFokus=afok=-1;
348 pickradius=256.0;
349 //printf("__ChGL::ChGL\n");
350 moving = new QTimer(this);
351 moving->setSingleShot(true);
352 connect(moving,SIGNAL(timeout()),this,SLOT(update()));
353 p=pp=ppp=0;
354 bggradient=true;
355 altemitte=V3(0,0,0);
356 hiddenThings=false;
357 hideReason=0;
358 qcutoff=-9;
359 setMinimumSize(200,200);
360 myFont=QFont("Arial",16);
361 centerSelection = new QAction(this);//for a dirty fix
362 rotze=-1; ///////////////
363 stereo_mode=0; ///////////////a
364 atomsClickable=true; ///////////////
365 mouseOverInteraction=true; ///////////////
366 // warfaul=
367 drawUc=false;
368
369 // 0 1 2 3
370 // 4 5 6 7
371 // 8 9 10 11
372 //12 13 14 15
373 MM[0]=-1;
374 MM[1]=MM[2]=MM[3]=MM[4]=MM[7]=MM[8]=MM[11]=MM[12]=MM[13]=0;
375 MM[5]=-0.242536;
376 MM[6]=0.970142;
377 MM[9]=0.970142;
378 MM[10]=0.242536;
379 MM[15]=1.0;
380 //MM[1]=MM[2]=MM[3]=MM[4]=MM[6]=MM[7]=MM[8]=MM[9]=MM[11]=MM[12]=MM[13]=0.0;
381 MM[14]=-200.0;
382 drawDF=drawFO= drawAx=drawAt=drawADP=drawBo=drawLa=drawHb=true;
383 //glEnable(GL_MULTISAMPLE);
384 ///////////////
385 /*
386 #if (QT_VERSION >= 0x040600) && defined (Q_WS_MAC)
387 grabGesture(Qt::PinchGesture);
388 grabGesture(Qt::SwipeGesture);
389 #endif
390 */
391 /*
392 QGLFormat fmt=QGLFormat::defaultFormat() ;
393 //fmt.setOption(QGL::StereoBuffers);
394 fmt.setOption(QGL::DirectRendering|QGL::StereoBuffers);
395 //fmt.setOption(QGL::);
396 setFormat(fmt);
397 */
398 // ///////////////
399 } ///////////////
400
401 ChGL::~ChGL(){
402 //printf("close chgl?\n");
403 if (mol->g_Program!=NULL) mol->g_Program->deleteLater();
404 labelTextures.clear();
405 //printf("Destructor of chGL %d %d\n",fVertexes.size(),fNormals.size());
406 int sumsize=0;
407 for (int i=0; i<fVertexes.size(); i++) {sumsize+=fVertexes[i].size(); fVertexes[i].clear();}
408 for (int i=0; i<fNormals.size(); i++) {sumsize+=fNormals[i].size(); fNormals[i].clear();}
409 fVertexes.clear();
410 fNormals.clear();
411 //printf("Destructor of chGL freed %d normals and vertices.\n",sumsize);
412 //printf("close chgl!\n");
413 }
414 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
415 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
416 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
417 /*
418 #if (QT_VERSION >= 0x040600) && (defined (Q_WS_MAC) || defined(Q_OS_MAC))
419 bool ChGL::event(QEvent *event){
420 if (event->type() == QEvent::Gesture)
421 return gestureEvent(static_cast<QGestureEvent*>(event));
422 return QWidget::event(event);
423 }
424
425 bool ChGL::gestureEvent(QGestureEvent *event){
426 if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
427 swipeTriggered(static_cast<QSwipeGesture *>(swipe));
428 else
429 if (QGesture *pinch = event->gesture(Qt::PinchGesture))
430 pinchTriggered(static_cast<QPinchGesture *>(pinch));
431 return true;
432 }
433
434 void ChGL::pinchTriggered(QPinchGesture *gesture){
435 QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags();
436 if (changeFlags & QPinchGesture::RotationAngleChanged) {
437 qreal value = gesture->property("rotationAngle").toReal();
438 rotZ(value/-36.0);
439 }
440 if (changeFlags & QPinchGesture::ScaleFactorChanged) {
441 qreal value = gesture->property("scaleFactor").toReal();
442 gZoom(value-1.0);
443 }
444 update();
445 }
446
447 void ChGL::swipeTriggered(QSwipeGesture *gesture) {
448 if (gesture->horizontalDirection() == QSwipeGesture::Left) glRotateL(-5.0,0.0f,1.0f,0.0f);
449 if (gesture->horizontalDirection() == QSwipeGesture::Right) glRotateL(5.0,0.0f,1.0f,0.0f);
450 if (gesture->verticalDirection() == QSwipeGesture::Up) glRotateL(-5.0,1.0f,0.0f,0.0f);
451 if (gesture->verticalDirection() == QSwipeGesture::Down) glRotateL(5.0,1.0f,0.0f,0.0f);
452 update();
453 }
454 #endif
455 */
456
457
458 static inline void transform_point(GLdouble out[4], const GLdouble m[16], const GLdouble in[4]) {
459 #define M(row,col) m[col*4+row]
460 out[0] =
461 M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3];
462 out[1] =
463 M(1, 0) * in[0] + M(1, 1) * in[1] + M(1, 2) * in[2] + M(1, 3) * in[3];
464 out[2] =
465 M(2, 0) * in[0] + M(2, 1) * in[1] + M(2, 2) * in[2] + M(2, 3) * in[3];
466 out[3] =
467 M(3, 0) * in[0] + M(3, 1) * in[1] + M(3, 2) * in[2] + M(3, 3) * in[3];
468 #undef M
469 }
470 int scrx=0,scry=0;
471 int scrx0=0,scry0=0;
472 bool rectangle=false;
473 static inline bool posTo2D(V3 obj,
474 const GLdouble model[16], const GLdouble proj[16],
475 const GLint viewport[4],
476 GLdouble * winx, GLdouble * winy,double retinafktr) {
477 GLdouble in[4], out[4];
478
479 in[0] = obj.x;
480 in[1] = obj.y;
481 in[2] = obj.z;
482 in[3] = 1.0;
483 transform_point(out, model, in);
484 transform_point(in, proj, out);
485
486 if (in[3] == 0.0) return false;
487
488 in[0] /= in[3];
489 in[1] /= in[3];
490 in[2] /= in[3];
491
492 *winx = viewport[0] + (1 + in[0]) * viewport[2] / 2;
493 *winy = viewport[1] + (1 - in[1]) * viewport[3] / 2;
494 *winx/=retinafktr;
495 *winy/=retinafktr;
496 return true;
497
498 }
499
500
501 void ChGL::changeEnviRange(){//! a dialog for a new ChGL.envirange.
502 bool ok;
503 double r=QInputDialog::getDouble ( this,"Envi-Range", "change environment range", envirange,0.7,8.0,2,&ok);
504 if (ok) envirange=r;
505 }
506
507 void ChGL::mousePressEvent(QMouseEvent *event) {
508 //printf("press\n");
509 altpivot=false;
510 if (rectangle){
511 rectangle=false;
512 update();
513 }
514 lastPos = event->pos();
515 p = qMin(p,mol->showatoms.size()-1);
516 pp = qMin(pp,mol->showatoms.size()-1);
517 ppp = qMin(ppp,mol->showatoms.size()-1);
518
519 p = qMax(p,0);
520 pp = qMax(pp,0);
521 ppp = qMax(ppp,0);
522 double nahda=pickradius,da=0;
523 int nahdai=-1;
524 for (int j=0; j<mol->showatoms.size();j++){
525 if (mol->showatoms.at(j).hidden) continue;
526 da=(((mol->showatoms.at(j).screenX-event->x())*( mol->showatoms.at(j).screenX-event->x()))+
527 ((mol->showatoms.at(j).screenY-event->y())*( mol->showatoms.at(j).screenY-event->y())));
528 nahdai=(da<nahda)?j:nahdai;
529 nahda=qMin(nahda,da);
530 }
531 // printf("press =>%d RNM%d %d\n",nahdai,inRenameMode,mol->selectedatoms.size());
532 //if (nahdai!=-1)printf("MousePressEvent %d %d %f\n",nahdai,mol->showatoms.size(),nahda);
533 // fprintf(stderr,"pressed %d %d %d %d\n",p,pp,ppp,mol->showatoms.size());
534 if (event->buttons() & Qt::MiddleButton){
535
536 if (nahdai < 0) {
537 }else
538 if (nahdai<mol->showatoms.size()) {
539 int index=nahdai;
540 if (index==(-1))return;
541 rotze=((int)index<mol->showatoms.size())?index:-1;
542 if (rotze>-1){ rCenter->show();
543
544 glGetDoublev(GL_MODELVIEW_MATRIX,MM);
545 MM[12]=MM[13]=0;
546 glLoadMatrixd(MM);
547 }
548 update();
549
550 }
551 }
552 //*/
553 // if((reSe | moveLab| invEditAble | atomsClickable| xdSetupMode) &&
554 if (event->buttons() & Qt::LeftButton){
555 scrx0=lastPos.x();
556 scry0=lastPos.y();
557 if (nahdai < 0) {
558 }else
559 if (nahdai<mol->showatoms.size()) {
560 int index=nahdai;
561 if (index==(-1))return;
562 double w=0,dw=0;
563 if ((pp!=p)&&(pp!=index)&&(p!=index)) {
564 V3 aa1=mol->showatoms.at(p).pos-mol->showatoms.at(pp).pos;
565 V3 aa2=mol->showatoms.at(p).pos-mol->showatoms.at(index).pos;
566 w=mol->winkel(aa1,aa2);
567 if ((ppp!=p)&&(ppp!=pp)&&(ppp!=index))
568 dw=mol->dieder(mol->showatoms.at(pp).pos-mol->showatoms.at(ppp).pos,
569 mol->showatoms.at(pp).pos-mol->showatoms.at(p).pos,
570 mol->showatoms.at(p).pos-mol->showatoms.at(index).pos);
571 }
572 if (atomsClickable){
573 emit jumpit(index);
574 /* printf("%s %d %d\n",
575 mol->showatoms.at(index).Label.toStdString().c_str(),
576 mol->showatoms.at(index).scod,
577 mol->showatoms.at(index).an);*/
578 if (inRenameMode) return;
579 if (!inRenameMode){
580 apair.clear();
581 if (event->modifiers()==Qt::NoModifier) {
582 int isschon=-1;
583 for (int i=0; i< mol->selectedatoms.size();i++){
584 isschon=(mol->selectedatoms.at(i).style==index)?index:isschon;
585 }
586 mol->selectedatoms.clear();
587 if (isschon==-1){
588 mol->selectedatoms.append(mol->showatoms[index]);
589 mol->selectedatoms.last().style=index;
590 }
591 }
592 if ((manualAx!=nullptr)&&(!manualAx->isChecked())&&(event->modifiers()==Qt::AltModifier)) {
593 int pv1=pivot1cb->findText(mol->showatoms.at(p).Label);
594 int pv2=pivot2cb->findText(mol->showatoms.at(index).Label);
595 if ((pv1>-1)&&(pv2)){
596 emit pivot1Changed(pv1);
597 emit pivot2Changed(pv2);
598 altpivot=true;
599 //printf("new axe %d %d\n",pv1,pv2);
600 }
601
602 }
603 if (event->modifiers()==Qt::ShiftModifier) {
604 int min=mol->showatoms.size(), max=-1;
605 for (int i=0; i< mol->selectedatoms.size();i++){
606 min=qMin(mol->selectedatoms.at(i).style,min);
607 max=qMax(mol->selectedatoms.at(i).style,max);
608 }
609 min=qMin((int)index,min);
610 max=qMax((int)index,max);
611 mol->selectedatoms.clear();
612 for (int i=min; i<=max; i++){
613 mol->selectedatoms.append(mol->showatoms[i]);
614 mol->selectedatoms.last().style=i;
615 }
616 }
617 if (event->modifiers()==Qt::ControlModifier) {
618 if (mol->selectedatoms.contains(mol->showatoms[index])){
619 mol->selectedatoms.removeOne(mol->showatoms[index]);
620 } else {
621 mol->selectedatoms.append(mol->showatoms[index]);
622 mol->selectedatoms.last().style=index;
623 // for (int oo=0; oo<mol->selectedatoms.size(); oo++) qDebug()<<mol->selectedatoms.at(oo).Label<<mol->selectedatoms.at(oo).symmGroup<< mol->selectedatoms.at(oo).style<<mol->selectedatoms.size();
624 }
625 }
626 // std::cout<<mol->selectedatoms.size()<<mol->selectedatoms.last().Label.toStdString()<<std::endl;
627 emit selectionChanged();
628 updateBondActions();
629 update();
630 }
631 //
632
633 V3 hin;
634 double dmsda=0;
635 hin = Normalize(mol->showatoms.at(index).pos-mol->showatoms.at(p).pos);
636 if ((mol->showatoms.at(index).an>-1) && (mol->showatoms.at(p).an))
637 dmsda = fabs(((hin*mol->showatoms.at(index).uc)*hin)- ((hin*mol->showatoms.at(p).uc)*hin));
638 //
639 bool syok;
640 QString symml;
641 int syid=mol->showatoms.at(index).Label.section(QString::fromUtf8("»"),1).toInt(&syok);
642 if (mol->usedSymmetry.size()&&syok) symml=mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid);
643 syid=mol->showatoms.at(p).Label.section(QString::fromUtf8("»"),1).toInt(&syok);
644 if ((mol->usedSymmetry.size())&&(syok)&&(!symml.contains(mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid))))
645 symml+=mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid);
646
647 syid=mol->showatoms.at(pp).Label.section(QString::fromUtf8("»"),1).toInt(&syok);
648 if ((mol->usedSymmetry.size())&&(syok)&&(!symml.contains(mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid))))
649 symml+=mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid);
650
651 syid=mol->showatoms.at(ppp).Label.section(QString::fromUtf8("»"),1).toInt(&syok);
652 if ((mol->usedSymmetry.size())&&(syok)&&(!symml.contains(mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid))))
653 symml+=mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid);
654 /*printf("%s org=%s iso=%d\n a%9.6f b%9.6f c%9.6f %9.6f %9.6f %9.6f\n d%9.6f e%9.6f f%9.6f %9.6f %9.6f %9.6f\n g%9.6f h%9.6f i%9.6f %9.6f %9.6f %9.6f\n\n",
655 mol->showatoms.at(index).Label.toStdString().c_str(),
656 mol->showatoms.at(index).ufiso_org.toStdString().c_str(),
657 mol->showatoms.at(index).isIso,
658 mol->showatoms.at(index).uf.m11,mol->showatoms.at(index).uf.m12,mol->showatoms.at(index).uf.m13, mol->showatoms.at(index).uc.m11,mol->showatoms.at(index).uc.m12,mol->showatoms.at(index).uc.m13,
659 mol->showatoms.at(index).uf.m21,mol->showatoms.at(index).uf.m22,mol->showatoms.at(index).uf.m23, mol->showatoms.at(index).uc.m21,mol->showatoms.at(index).uc.m22,mol->showatoms.at(index).uc.m23,
660 mol->showatoms.at(index).uf.m31,mol->showatoms.at(index).uf.m32,mol->showatoms.at(index).uf.m33, mol->showatoms.at(index).uc.m31,mol->showatoms.at(index).uc.m32,mol->showatoms.at(index).uc.m33
661 );// */
662
663 if ((index!=p)&&(index!=pp)&&(mol->showatoms.at(index).Label[0]=='Q')){
664 /*printf("scod %d %f %f %f \n",mol->showatoms.at(index).scod,
665 mol->showatoms.at(index).frac.x,
666 mol->showatoms.at(index).frac.y,
667 mol->showatoms.at(index).frac.z);// **/
668 emit bigmessage(QString("<hr><table><tr><td><b>%1</b></td><td align=\"right\"></td></tr><tr><td><b>%1--%2</b>"
669 "</td><td align=\"right\">%5 &Aring;</td></tr><tr><td><b>%1--%2--%3</b></td><td "
670 "align=\"right\">%6&deg;</td></tr><tr><td><b>%1--%2--%3--%4 </b></td><td "
671 "align=\"right\">%7&deg;</td></tr><tr><td><b>%1</b> Peak Height: </td><td "
672 "align=\"right\">%8 e&Aring;<sup>-3</sup></td><td>[%9&hellip;%10]"
673 "</td></tr></table>%11")
674 .arg((mol->showatoms.at(index).Label)) //1
675 .arg((mol->showatoms.at(p).Label)) //3
676 .arg((mol->showatoms.at(pp).Label)) //5 //8
677 .arg((mol->showatoms.at(ppp).Label)) //9
678 .arg(sqrt(Distance(mol->showatoms.at(index).pos,mol->showatoms.at(p).pos)),8,'f',3) //4
679 .arg(w,8,'f',2)
680 .arg(dw,8,'f',2)
681 .arg(mol->showatoms.at(index).peakHeight,8,'f',2)
682 .arg(mol->pmin,3,'f',2)
683 .arg(mol->pmax,3,'f',2)
684 .arg(symml)
685
686 );
687 }
688 else if ((index!=p)&&(index!=pp)&&(mol->showatoms.at(index).Label[0]=='L')&&(mol->showatoms.at(index).an==-42)){
689 emit bigmessage(QString("<hr><table><tr><td><b>%1</b></td><td align=\"right\"></td></tr><tr><td><b>%1--%2</b>"
690 "</td><td align=\"right\">%5 &Aring;</td></tr><tr><td><b>%1--%2--%3</b></td><td "
691 "align=\"right\">%6&deg;</td></tr><tr><td><b>%1--%2--%3--%4 </b></td><td "
692 "align=\"right\">%7&deg;</td></tr><tr><td><b>%1</b> a exp(-b x<sup>2</sup>)</td><td "
693 "align=\"right\">a = %8 </td><td> b = %9 "
694 "</td></tr></table>%11")
695 .arg((mol->showatoms.at(index).Label)) //1
696 .arg((mol->showatoms.at(p).Label)) //3
697 .arg((mol->showatoms.at(pp).Label)) //5 //8
698 .arg((mol->showatoms.at(ppp).Label)) //9
699 .arg(sqrt(Distance(mol->showatoms.at(index).pos,mol->showatoms.at(p).pos)),8,'f',3) //4
700 .arg(w,8,'f',2)
701 .arg(dw,8,'f',2)
702 .arg(mol->showatoms.at(index).sof,8,'f',2)
703 .arg(mol->showatoms.at(index).peakHeight,8,'f',2)
704 .arg(symml)
705
706 );
707 }
708 else if ((index!=p)&&(index!=pp)){
709 emit bigmessage(QString("<br><hr><table><tr><td><b>%1</b> part: %8 residue: %9 %10 (fragment: %12)</td><td align=\"right\">"
710 "</td></tr><tr><td><b>%1--%2</b></td><td align=\"right\">%5 &Aring;</td><td>&nbsp;&nbsp;&nbsp;DMSDA: %13 &Aring;<sup>2</sup></td></tr>"
711 "<tr><td><b>%1--%2--%3</b></td><td align=\"right\">%6&deg;</td><td>&nbsp;&nbsp;&nbsp;1,3 Distance( DANG) %14 &Aring;</td></tr><tr><td>"
712 "<b>%1--%2--%3--%4 </b></td><td align=\"right\">%7&deg;</td></tr></table>%11")
713 .arg((mol->showatoms.at(index).Label)) //1
714 .arg((mol->showatoms.at(p).Label)) //2
715 .arg((mol->showatoms.at(pp).Label)) //3
716 .arg((mol->showatoms.at(ppp).Label)) //4
717 .arg(sqrt(Distance(mol->showatoms.at(index).pos,mol->showatoms.at(p).pos)),8,'f',3) //5
718 .arg(w,8,'f',2) //6
719 .arg(dw,8,'f',2) //7
720 .arg(mol->showatoms.at(index).part)
721 .arg(mol->showatoms.at(index).resiNr)
722 .arg(mol->showatoms.at(index).ResiClass)
723 .arg(symml)
724 .arg(mol->showatoms.at(index).molindex)
725 .arg(dmsda,5,'e',2)
726 .arg(sqrt(Distance(mol->showatoms.at(index).pos,mol->showatoms.at(pp).pos)),8,'f',3)
727 );
728 }
729 // ,QMessageBox::Ok);
730 ppp = pp;
731 pp = p;
732 p = index;
733 }
734
735 //888
736 }
737 }
738 }
739
740 void ChGL::mouseMoveEvent(QMouseEvent *event) {
741 double nahda=pickradius,da=0;
742
743 makeCurrent();
744 rectangle=false;
745 int nahdai=-1;
746 bool changed=false;
747 scrx=event->x();
748 scry=event->y();
749 for (int j=0; j<mol->showatoms.size();j++){
750 if (mol->showatoms.at(j).hidden) continue;
751 da=(((mol->showatoms.at(j).screenX-event->x())*( mol->showatoms.at(j).screenX-event->x()))+
752 ((mol->showatoms.at(j).screenY-event->y())*( mol->showatoms.at(j).screenY-event->y())));
753 nahdai=(da<nahda)?j:nahdai;
754 nahda=qMin(nahda,da);
755 }
756 //if (nahdai!=-1)printf("MouseMoveEvent %d %d %f\n",nahdai,mol->showatoms.size(),nahda);
757 // printf("move =>%d\n",nahdai);
758 if ((mouseOverInteraction)&&(!event->buttons())) {
759 if (imFokus!=nahdai) changed=true;
760 imFokus=nahdai;
761 if (imFokus==-1) {
762 emit qpfoci(-1.0);
763 emit message("");
764 }
765 else {
766 emit message(mol->showatoms.at(imFokus).Label);
767 if ((mol->showatoms.at(imFokus).an<0)) emit qpfoci(mol->showatoms.at(imFokus).peakHeight);
768 else qpfoci(-1.0);
769 }
770
771 if (changed) {
772 // printf("MouseMoveEvent changed %d %d %d\n",nahdai,mol->showatoms.size(),imFokus);fflush(stdout);
773 update();
774 }
775 return;
776 }
777 GLfloat dx = GLfloat( event->x() - lastPos.x()) / ww;
778 GLfloat dy = GLfloat( event->y() - lastPos.y()) / wh;
779
780 if (event->buttons() & Qt::MiddleButton){
781 if ((freeRot!=nullptr)&&(freeRot->isChecked())&&(event->modifiers()==(Qt::AltModifier|Qt::ControlModifier))){
782 V3 mv(dx, -dy, 0);
783 makeCurrent();
784 GLdouble mm[16];
785 glGetDoublev(GL_MODELVIEW_MATRIX,mm);
786 double det=
787 mm[0]*mm[5]*mm[10] - mm[8]*mm[5]*mm[2]+
788 mm[1]*mm[6]*mm[8] - mm[9]*mm[6]*mm[0]+
789 mm[2]*mm[4]*mm[9] - mm[10]*mm[4]*mm[1];
790 Matrix mat=Matrix(mm[0],mm[1],mm[2],mm[4],mm[5],mm[6],mm[8],mm[9],mm[10]);
791 //printf("A%g %g\n",determinant(mat),det);
792 mat=mat*pow(det,-1.0/3.0);
793 mv=mat*mv;
794 V3 o(orgx->value(), orgy->value(), orgz->value());
795 o+=mv;
796 orgx->setValue(o.x);
797 orgy->setValue(o.y);
798 orgz->setValue(o.z);
799 //printf("%f%f %f\n",mv.x,mv.x,mv.z);
800 splitRotate();
801 }else{
802 moving->start(dratpause);
803 glTranslateL(dx*viewAngle*3,-dy*viewAngle*3,0);
804 update();
805 }
806 }
807
808 if ((event->buttons() & Qt::LeftButton && (event->modifiers()==(Qt::ShiftModifier|Qt::ControlModifier)))) {
809 rectangle=true;
810 int minxp=ww,minyp=wh,maxxp=0,maxyp=0;
811 minxp=qMin(scrx0,scrx);
812 minyp=qMin(scry0,scry);
813 maxxp=qMax(scrx0,scrx);
814 maxyp=qMax(scry0,scry);
815 mol->selectedatoms.clear();
816 for (int j=0; j<mol->showatoms.size();j++){
817 if (mol->showatoms.at(j).hidden) continue;
818 if ((mol->showatoms.at(j).screenX>minxp)&&
819 (mol->showatoms.at(j).screenX<maxxp)&&
820 (mol->showatoms.at(j).screenY>minyp)&&
821 (mol->showatoms.at(j).screenY<maxyp)){
822
823 mol->selectedatoms.append(mol->showatoms[j]);
824 mol->selectedatoms.last().style=j;
825 }
826 }
827 updateBondActions();
828 update();
829 }else
830 if ((event->buttons() & Qt::LeftButton)) {
831 if (event->modifiers()==Qt::ShiftModifier) {
832 moving->start(dratpause);
833 glTranslateL(dx*viewAngle*3,-dy*viewAngle*3,0);
834 update();}
835 else
836 {
837 //printf("%d %d drag \n",(manualAx!=nullptr),(freeRot!=nullptr));
838 moving->start(dratpause);
839 double slow=1.0;
840 if (event->modifiers()==Qt::ShiftModifier) slow=0.25;
841 if (event->modifiers()==Qt::ControlModifier) slow=0.06;
842 emit movedByUser();
843 //if ((idl!=NULL)&&(idl->isActive())) idl->stop();
844 if ((manualAx!=nullptr)&&(manualAx->isChecked())&&(event->modifiers()==Qt::AltModifier)){
845 //printf("X\n");
846 makeCurrent();
847 GLdouble mm[16];
848 glGetDoublev(GL_MODELVIEW_MATRIX,mm);
849 double det=
850 mm[0]*mm[5]*mm[10] - mm[8]*mm[5]*mm[2]+
851 mm[1]*mm[6]*mm[8] - mm[9]*mm[6]*mm[0]+
852 mm[2]*mm[4]*mm[9] - mm[10]*mm[4]*mm[1];
853 Matrix mat=Matrix(mm[0],mm[1],mm[2],mm[4],mm[5],mm[6],mm[8],mm[9],mm[10]);
854 //printf("A%g %g\n",determinant(mat),det);
855 mat=mat*pow(det,-1.0/3.0);
856 //printf("B%g %g\n",determinant(mat),det);
857
858 V3 axe=Normalize(V3(axx->value(),axy->value(),axz->value()));
859 axe=transponse(mat)*axe;
860 double arr[4];
861 arr[0]=dx*360.0;
862 arr[1]=0.0;
863 arr[2]=1.0;
864 arr[3]=0.0;
865 axe=mol->rotarb(arr)*axe;
866 V3 XX = mol->rotarb(arr)*V3(1, 0, 0);
867 arr[0]=dy*360.0;
868 arr[1]=XX.x;
869 arr[2]=XX.y;
870 arr[3]=XX.z;
871 axe=mol->rotarb(arr)*axe;
872 axe=mat*axe;
873 axx->setValue(axe.x);
874 axy->setValue(axe.y);
875 axz->setValue(axe.z);
876 splitRotate();
877 }else if ((freeRot!=nullptr)&&(freeRot->isChecked())&&(event->modifiers()==(Qt::AltModifier|Qt::ControlModifier))){
878 //printf("Y\n");
879 GLdouble mm[16];
880 makeCurrent();
881 glGetDoublev(GL_MODELVIEW_MATRIX,mm);
882 double det=
883 mm[0]*mm[5]*mm[10] - mm[8]*mm[5]*mm[2]+
884 mm[1]*mm[6]*mm[8] - mm[9]*mm[6]*mm[0]+
885 mm[2]*mm[4]*mm[9] - mm[10]*mm[4]*mm[1];
886 Matrix mat=Matrix(mm[0],mm[1],mm[2],mm[4],mm[5],mm[6],mm[8],mm[9],mm[10]);
887 //printf("A%g %g\n",determinant(mat),det);
888 mat=mat*pow(det,-1.0/3.0);
889 //printf("B%g %g\n",determinant(mat),det);
890
891 //V3 axe=Normalize(V3(axx->value(),axy->value(),axz->value()));
892 //axe=transponse(mat)*axe;
893 double arr[4];
894 arr[0]=angle1->value();
895 V3 ax = transponse(mat)*Normalize(V3(axx->value(),axy->value(),axz->value()));
896 arr[1]=ax.x;
897 arr[2]=ax.y;
898 arr[3]=ax.z;
899 Matrix R=mol->rotarb(arr);
900
901 V3 V1(1, 0, 0);
902 V3 V2(0, 1, 0);
903 //V1 = mat * V1;
904 //V2 = mat * V2;
905 V3 dirxy(dy,dx,0);
906 double deg = sqrt(Norm(dirxy));
907 dirxy = Normalize(dirxy);
908 double dd[4]={deg * 360.0, dirxy.x, dirxy.y, dirxy.z};
909 R = mol->rotarb(dd)*R;
910 //glRotateMat(R, dy*360.0, V1.x, V1.y, V1.z);
911 //glRotateMat(R, dx*360.0, V2.x, V2.y, V2.z);
912 //R=transponse(mat)*R;
913 //double
914 //det =determinant(R);
915 //printf("!!die Determinante der Drehmatrix ist: %g\n",det);
916 V3 axe = V3((R.m23 - R.m32) , (R.m31 - R.m13) , (R.m12 - R.m21)) ;
917 double _si = sqrt(Norm(axe)) / 2.0;
918 double _co = ((R.m11 + R.m22 + R.m33) - 1.0)/ 2.0;
919 //double ws = asin(_si) / M_PI * 180.0;
920 //double ll=sqrt(Norm(axe));
921 axe=Normalize(axe);
922 //double wc = acos(((R.m11+R.m22+R.m33)-1.0)/2.0) / M_PI * 180.0;
923 double wt = atan2(_si,_co) / M_PI * 180.0;
924 //printf("Winke %f %f %f\n", ws, wc, wt);
925 //printf("!!%fdeg %f %f %f\n", wt, axe.x, axe.y, axe.z);
926 //printf("->%f %f %f %f %f %f %f %f %f \n",R.m11,R.m12,R.m13,R.m21,R.m22,R.m23,R.m31,R.m32,R.m33);
927 angle1->setValue(static_cast<int>(wt));
928 axe=mat*axe;
929 axx->setValue(axe.x);
930 axy->setValue(axe.y);
931 axz->setValue(axe.z);
932 splitRotate();
933 }else{
934 glRotateL(dy*360.0*slow,1.0,0.0,0.0);
935 glRotateL(dx*360.0*slow,0.0,1.0,0.0);
936 }
937 }
938 update();
939 }
940 else if((event->buttons() & Qt::RightButton)){
941 if (!invertMouseZoom->isChecked()){
942
943 moving->start(dratpause);
944 glScaled(1.0-dy,1.0-dy,1.0-dy);
945 // mlsc/=1.0-dy;
946 }else {
947
948 moving->start(dratpause);
949 glScaled(1.0+dy,1.0+dy,1.0+dy);
950 // mlsc/=1.0+dy;
951 }
952 update();
953 }
954 lastPos = event->pos();
955 }
956
957 QList<int> ChGL::lastClicked(){
958 QList<int> pppp;
959 //if ((ppp>=0)&&(ppp<mol->showatoms.size())&&(ppp!=pp)&&(ppp!=p)) pppp.append(ppp);
960 if (( p>=0)&&( p<mol->showatoms.size())) pppp.append(p);
961 if (( pp>=0)&&( pp<mol->showatoms.size())&&(pp!=p)) pppp.append(pp);
962 return pppp;
963 }
964
965 void ChGL::wheelEvent(QWheelEvent *event){
966 /*
967 modifiers:
968 Qt::NoModifier 0x00000000 No modifier key is pressed.
969 Qt::ShiftModifier 0x02000000 A Shift key on the keyboard is pressed.
970 Qt::ControlModifier 0x04000000 A Ctrl key on the keyboard is pressed.
971 Qt::AltModifier 0x08000000 An Alt key on the keyboard is pressed.
972 Qt::MetaModifier 0x10000000 A Meta key on the keyboard is pressed.
973 Qt::KeypadModifier 0x20000000 A keypad button is pressed.
974 Qt::GroupSwitchModifier 0x40000000 X11 only. A Mode_switch key on the keyboard is pressed.
975 */
976 #if (QT_VERSION>0x050000)
977 int numDegrees = event->angleDelta().y() / 8;
978 #else
979 int numDegrees = event->delta() / 8;
980 #endif
981
982 int numSteps = numDegrees / 15;
983 if (event->modifiers()==Qt::NoModifier){
984 int d = myFont.pointSize();
985 d=(d+numSteps>4)?d+numSteps:d;
986 labScal+=0.01*numSteps;
987 labScal=(labScal<0.1)?0.1:labScal;
988 d=qMax(d,7);
989
990 update();
991 }
992 if (event->modifiers()==Qt::ControlModifier){
993 emit diffscroll(numSteps,1);
994 }
995 if (event->modifiers()==Qt::ShiftModifier){
996 emit diffscroll(numSteps,0);
997 }
998 if (event->modifiers()==(Qt::AltModifier|Qt::ShiftModifier)){
999 double va=viewAngle+0.1*numSteps;
1000 setViewAngle(va);
1001 }
1002 if (event->modifiers()==Qt::AltModifier){
1003 int afr=mol->fogrange;
1004 mol->fogrange+=numSteps*5;
1005 mol->fogrange=qMax(mol->fogrange,1);
1006 mol->fogrange=qMin(mol->fogrange,204);
1007 //printf("fogrange = %d\n", mol->fogrange);
1008 if (afr!=mol->fogrange){
1009 glFogi(GL_FOG_MODE,GL_LINEAR);
1010 glFogi(GL_FOG_START,205-mol->fogrange);
1011 glFogi(GL_FOG_END,205+mol->fogrange);
1012 GLfloat fgc[4]={(GLfloat)backGroundColor.redF(),(GLfloat)backGroundColor.greenF(),(GLfloat)backGroundColor.blueF(),1.0};
1013 glFogfv(GL_FOG_COLOR,fgc);
1014 update();}
1015 }
1016
1017 event->accept();
1018 }
1019
1020 void ChGL::contextMenuEvent(QContextMenuEvent *event){
1021 double nahda=pickradius,da=0;
1022 int nahdai=-1;
1023 for (int j=0; j<mol->showatoms.size();j++){
1024 if (mol->showatoms.at(j).hidden) continue;
1025 da=(((mol->showatoms.at(j).screenX-event->x())*( mol->showatoms.at(j).screenX-event->x()))+
1026 ((mol->showatoms.at(j).screenY-event->y())*( mol->showatoms.at(j).screenY-event->y())));
1027 nahdai=(da<nahda)?j:nahdai;
1028 nahda=qMin(nahda,da);
1029 }
1030
1031 // printf("contextEvent %d %d %f\n",nahdai,mol->showatoms.size(),nahda);
1032 if ((nahdai < 0)||(mol->showatoms.size()<nahdai)) {
1033 return;
1034 }
1035 else {
1036 int idx=nahdai;
1037 ImeanThisAtom=idx;
1038 if (idx>mol->showatoms.size()) return;
1039 QList<QAction *> sfas = sfacMenu->actions();
1040 for (int k=0;k<sfas.size();k++){
1041 sfas[k]->setEnabled(sfas[k]->text()!=mol->pse(mol->showatoms.at(idx).an));
1042 }
1043 QMenu *menu = new QMenu(mol->showatoms.at(idx).Label);
1044 if (mol->showatoms.at(idx).symmGroup==0) menu->addMenu(sfacMenu);
1045 QAction *a;
1046 if ((mol->selectedatoms.isEmpty())&&(mol->showatoms.at(idx).symmGroup==0)) {
1047 a=menu->addAction(QIcon(theIconPath+"killselected.svg"),QString("Delete %1 ").arg(mol->showatoms.at(idx).Label),
1048 chparent,SLOT(deleteSelectedAtoms()));
1049 a->setData(idx);
1050 }else if (mol->showatoms.at(idx).symmGroup==0){
1051 a=menu->addAction(QIcon(theIconPath+"killselected.svg"),QString("Delete selected atoms"),
1052 chparent,SLOT(deleteSelectedAtoms()));
1053 a->setData(-1);
1054 }
1055 if (!mol->selectedatoms.isEmpty()) a=menu->addAction("Change RESI or PART of selected atoms",chparent,SLOT(changeResiPart()));
1056 menu->addSeparator();
1057 a=menu->addAction(QString("Set rotation center to %1").arg(mol->showatoms.at(idx).Label),this,SLOT(setRotationCenter()));
1058 a->setData(idx);
1059 a=menu->addAction(QString("Expand contacts around %1").arg(mol->showatoms.at(idx).Label),this,SLOT(expand()));
1060 a->setData(idx);
1061 a=menu->addAction(QString("Hide this fragment"),this,SLOT(hideThisFragment()));
1062 a->setData(idx);
1063 a=menu->addAction(QString("Select this fragment"),this,SLOT(selectThisFragment()));
1064 a->setData(idx);
1065 a=menu->addAction(QString("Hide other fragments"),this,SLOT(hideOtherFragments()));
1066 a->setData(idx);
1067 a=menu->addAction(QString("Fragment includes symmetry generated"), this ,SLOT(toogleWithSymmetry(bool)));
1068 a->setCheckable(true);
1069 a->setChecked(!(withsymm));
1070 if (!mol->selectedatoms.isEmpty()) a=menu->addAction("Hide selected Atoms",this,SLOT(hideSelected()));
1071 bool hasSameBonds=false;//for sadi two neighbor) atoms need to be same atomic number and no hydrogen
1072 //it warks if they are not the same but gives a warning and does not make much sense
1073 if (idx<mol->asymm.size()) for (int nb=1; nb<mol->knoepfe.at(idx).neighbors.size(); nb++){
1074 if ((mol->knoepfe.at(idx).neighbors.at(nb-1)>=mol->asymm.size())||(mol->knoepfe.at(idx).neighbors.at(nb)>=mol->asymm.size())) continue;
1075 if ((mol->asymm.at(mol->knoepfe.at(idx).neighbors.at(nb-1)).an>0)&&
1076 (mol->asymm.at(mol->knoepfe.at(idx).neighbors.at(nb-1)).an==mol->asymm.at(mol->knoepfe.at(idx).neighbors.at(nb)).an))hasSameBonds=true;
1077 }
1078 // qDebug()<<hasSameBonds;
1079 if(!mol->selectedatoms.isEmpty()){
1080 QMenu *RestrMenu = new QMenu("Add restraints");
1081 QMenu *ConstrMenu = new QMenu("Add constraints");
1082 RestrMenu->addAction("ISOR", this, SLOT(addISOR()));
1083 if (hasSameBonds){
1084 QAction *restr;
1085 restr=RestrMenu->addAction("SADI", this, SLOT(addSADI()));
1086 restr->setData(idx);
1087 }
1088 if(mol->selectedatoms.size() == 2){
1089 RestrMenu->addAction("DFIX", this, SLOT(addDFIX()));
1090 RestrMenu->addAction("DANG", this, SLOT(addDANG()));
1091 }
1092 if(mol->selectedatoms.size() >= 4){
1093 RestrMenu->addAction("FLAT", this, SLOT(addFLAT()));
1094 }
1095 if(mol->selectedatoms.size() > 1){
1096 ConstrMenu->addAction("EXYZ", this, SLOT(addEXYZ()));
1097 ConstrMenu->addAction("EADP", this, SLOT(addEADP()));
1098 RestrMenu->addAction("RIGU", this, SLOT(addRIGU()));
1099 RestrMenu->addAction("DELU", this, SLOT(addDELU()));
1100 RestrMenu->addAction("SIMU", this, SLOT(addSIMU()));
1101 RestrMenu->addAction("CHIV", this, SLOT(addCHIV()));
1102 }
1103 menu->addMenu(RestrMenu);
1104 menu->addMenu(ConstrMenu);
1105 }else if (hasSameBonds) {
1106 QMenu *RestrMenu = new QMenu("Add restraints");
1107 QAction *restr;
1108 restr=RestrMenu->addAction("SADI", this, SLOT(addSADI()));
1109 restr->setData(idx);
1110 menu->addMenu(RestrMenu);
1111 }
1112 menu->addSeparator();
1113 QMenu *enviMenu = new QMenu("ENVI-Settings");
1114 enviMenu->addAction("Change envi range", this, SLOT(changeEnviRange()));
1115 enviMenu->addAction(enviNoQ);
1116 enviMenu->addAction(enviCova);
1117 menu->addMenu(enviMenu);
1118 if ((int) idx < mol->asymm.size()){
1119 a=menu->addAction(QString("List ENVIronment of %1").arg(mol->showatoms.at(idx).Label),this,SLOT(envi()));
1120 a->setData(idx);
1121 }
1122 menu->addSeparator();
1123 int ssgr=0;
1124 int adpat=0;
1125 for (int seli=0; seli<mol->selectedatoms.size(); seli++){
1126 if ((mol->showatoms.at(seli).symmGroup==0)&&(!mol->selectedatoms.at(seli).isIso))adpat++;
1127 }
1128 for (int seli=0; seli<mol->selectedatoms.size(); seli++){
1129 if (mol->selectedatoms.at(seli).symmGroup>0) ssgr+=mol->selectedatoms.at(seli).symmGroup;
1130 else {
1131 ssgr=0;
1132 break;
1133 }
1134 }
1135 if (ssgr) adpat=0;
1136 if (ssgr){
1137 a=menu->addAction(QString("Move selected atoms to selected sites"),
1138 chparent,SLOT(moveSymmMateSel()));
1139 //////// 28.03.12
1140 if (mol->showatoms.at(idx).part<0){
1141 a=menu->addAction(QString("Copy %1 here").arg(mol->showatoms.at(idx).Label.section("_",0,0)),
1142 chparent,SLOT(copySymmMate()));
1143 a->setData(idx);
1144 }
1145 //////// -
1146 }else{
1147 if (mol->showatoms.at(idx).symmGroup>0){
1148 a=menu->addAction(QString("Move %1 here").arg(mol->showatoms.at(idx).Label.section("_",0,0)),
1149 chparent,SLOT(moveSymmMate()));
1150 a->setData(idx);
1151 if (mol->showatoms.at(idx).part<0){
1152 a=menu->addAction(QString("Copy %1 here").arg(mol->showatoms.at(idx).Label.section("_",0,0)),
1153 chparent,SLOT(copySymmMate()));
1154 a->setData(idx);
1155 }
1156
1157 }
1158 }
1159 menu->addSeparator();
1160 if ((nahdai<mol->asymm.size())&&(mol->knoepfe.at(idx).neighbors.size()==1)&&((mol->showatoms.at(idx).an==6)||(mol->showatoms.at(idx).an==5))) {
1161
1162 // printf("%s hat %d Nachbarn\n",mol->showatoms.at(idx).Label.toStdString().c_str(),mol->knoepfe.at(idx).neighbors.size());
1163 a=menu->addAction(QString("Add dissordered %1 Hydrogen atoms").arg(((mol->showatoms.at(idx).an==5))?"methyl":"-NH3"),chparent,SLOT(addDissorderedMethyl()));
1164 a->setData(idx);
1165 a=menu->addAction(QString("Add ordered %1 Hydrogen atoms").arg(((mol->showatoms.at(idx).an==5))?"methyl":"-NH3+"),chparent,SLOT(addMethyl()));
1166 a->setData(idx);
1167 a=menu->addAction(QString("Add terminal %1 Hydrogen atoms").arg(((mol->showatoms.at(idx).an==5))?"=CH2 ":"=NH2+"),chparent,SLOT(addH93()));
1168 a->setData(idx);
1169 if (mol->showatoms.at(idx).an==5){
1170 a=menu->addAction(QString("Add acetylenic C-H Hydrogen atom"),chparent,SLOT(addH163()));
1171 a->setData(idx);
1172 }
1173 if (mol->showatoms.at(idx).an==6){
1174 a=menu->addAction(QString("Add %1 Hydrogen atoms").arg("-NH2 (non planar)"),chparent,SLOT(addHnonplanarAminR1()));
1175 a->setData(idx);
1176 }
1177 }
1178 if ((nahdai<mol->asymm.size())&&(mol->knoepfe.at(idx).neighbors.size()==1)&&(mol->showatoms.at(idx).an==7)){
1179 a->setData(idx);
1180 a=menu->addAction(QString("Add hydroxyl Hydrogen atom to %1").arg(mol->showatoms.at(idx).Label.section("_",0,0)),chparent,SLOT(addHydroxyl()));
1181 a->setData(idx);
1182 }
1183 if ((nahdai<mol->asymm.size())&&(mol->knoepfe.at(idx).neighbors.size()==2)&&((mol->showatoms.at(idx).an==6)||(mol->showatoms.at(idx).an==5))) {
1184 a=menu->addAction(QString("Add %1 Hydrogen atoms").arg(((mol->showatoms.at(idx).an==5))?">CH2":">NH2+"),chparent,SLOT(addH23()));
1185 a->setData(idx);
1186 a=menu->addAction(QString("Add %1 Hydrogen atom").arg(((mol->showatoms.at(idx).an==5))?">CH":">NH (planar)"),chparent,SLOT(addH43()));
1187 a->setData(idx);
1188 //addHnonplanarAminR2();
1189 if (mol->showatoms.at(idx).an==6){
1190 a=menu->addAction(QString("Add %1 Hydrogen atom").arg(">NH (non planar)"),chparent,SLOT(addHnonplanarAminR2()));
1191 a->setData(idx);
1192 }
1193 }
1194 if ((idx < mol->asymm.size()) && (mol->asymm.at(idx).an>-1)) {
1195 a=menu->addAction(QString("Use %1 as new label for rename mode").arg(mol->showatoms.at(idx).Label.section("_",0,0)),chparent,SLOT(renameThisAtom()));
1196 a->setData(idx);
1197 }
1198
1199 if(!mol->selectedatoms.isEmpty()){
1200 menu->addAction(QString("Make selected atoms ANIS"),this,SLOT(addANIS()));
1201 }
1202 if (adpat) {
1203 if (mol->selectedatoms.isEmpty()){
1204 a=menu->addAction(QIcon(theIconPath+"sina.svg"),QString("make %1 isotropic (ISOT)")
1205 .arg(mol->showatoms.at(idx).Label),chparent,SLOT(sina()));
1206 a->setData(idx);
1207 }else{
1208 a=menu->addAction(QIcon(theIconPath+"sina.svg"),QString("make selected atoms isotropic (ISOT)"),chparent,SLOT(sina()));
1209 a->setData(-1);
1210 }
1211 }
1212 if ((idx<mol->asymm.size())&&(mol->asymm.at(idx).an>-1)){
1213 QAction *a = menu->addAction("Draw voronoi polyeder of this atom",chparent,SLOT(makeVoro()));
1214 a->setData(idx);
1215 }
1216
1217 if (mol->showatoms.at(p).molindex!=mol->showatoms.at(idx).molindex){
1218 menu->addSeparator();
1219 a=menu->addAction(QString("Inherit Labels from molecule around %1 to atoms around %2")
1220 .arg(mol->showatoms.at(p).Label)
1221 .arg(mol->showatoms.at(idx).Label)
1222 ,chparent,SLOT(inheritLabels()));
1223 ppp = pp;
1224 pp = p;
1225 p = idx;
1226
1227 }
1228
1229 menu->exec(event->globalPos());
1230 delete enviMenu;
1231 delete menu;
1232 }
1233 }
1234
1235 void ChGL::Listen(){//! forces the lists to be rerendered.
1236 murx=-__LINE__;
1237 }
1238
1239 void ChGL::disSelection(){//! Un select everything.
1240 //rotCenter();
1241 //QTime rzeit;
1242 //rzeit.start();
1243 mol->selectedatoms.clear();
1244 apair.clear();
1245 updateBondActions();
1246 update();
1247 }
1248
1249 void ChGL::selectPair(const QString &s){
1250 apair.clear();
1251 //! Selelects two atoms from the spaces separated string s. @param space separated pair of atom labels.
1252 mol->selectedatoms.clear();
1253 if (s.isEmpty()) {
1254 update();
1255 return;
1256 }
1257 QStringList index=s.split(' ',skipEmptyParts);
1258 if (index.size()<2) {
1259 update();
1260 return;
1261 }
1262 /*
1263 *
1264 length=b.length;
1265 ato1=b.ato1;
1266 ato2=b.ato2;
1267 a1=b.a1;
1268 a2=b.a2;
1269 */
1270 MyBond pair;
1271 pair.length=1.0;
1272 for (int i=0; i<index.size();i++){
1273 mol->selectedatoms.append(mol->showatoms[index.at(i).toInt()]);
1274 mol->selectedatoms.last().style=index.at(i).toInt();
1275 if (i==0){
1276 pair.ato1=&mol->selectedatoms.last();
1277 pair.a1=index.at(i).toInt();
1278 }else{
1279 pair.ato2=&mol->selectedatoms.last();
1280 pair.a2=index.at(i).toInt();
1281 }
1282 }
1283 //printf("a pair is made %d %d\n",pair.a1,pair.a2);
1284 apair.append(pair);
1285 //updateBondActions();
1286 update();
1287 }
1288
1289 void ChGL::pairing(QList<int> ima, QList<int> imb){
1290 MyBond pair;
1291 pair.length=1.0;
1292 for (int i=0; i<ima.size(); i++){
1293 pair.ato1=&mol->showatoms[ima.at(i)];
1294 pair.ato2=&mol->showatoms[imb.at(i)];
1295 pair.a1=ima.at(i);
1296 pair.a2=ima.at(i);
1297 apair.append(pair);
1298 }
1299 update();
1300 }
1301
1302 void ChGL::selectResiByNr(int nr){//! Selects atoms in residues with the same residue number. @param nr residue number.
1303 mol->selectedatoms.clear();
1304 apair.clear();
1305 for (int i=0; i<mol->showatoms.size();i++){
1306 if (mol->showatoms.at(i).resiNr==nr) {
1307 mol->selectedatoms.append(mol->showatoms[i]);
1308 mol->selectedatoms.last().style=i;
1309 }
1310 }
1311 draw();
1312 if (hiddenThings) hideNonSelected();
1313 updateBondActions();
1314 update();
1315 }
1316
1317 void ChGL::invertSelection(){//!Inverts stelection, means selected atoms get disselected and vice versa.
1318 CEnvironment tempa=mol->selectedatoms;
1319 // printf("invert %d %d\n",tempa.size(),mol->selectedatoms.size());
1320 mol->selectedatoms.clear();
1321
1322 for (int i=0; i<mol->showatoms.size();i++){
1323 if (!tempa.contains(mol->showatoms.at(i))) {
1324 mol->selectedatoms.append(mol->showatoms[i]);
1325 mol->selectedatoms.last().style=i;
1326 }
1327 }
1328 draw();
1329 rehide();
1330 updateBondActions();
1331 update();
1332 }
1333
1334 void ChGL::findPivot(){
1335 //printf("findpv %p\n",whyNotSplit);
1336 if ((altpivot)||(whyNotSplit==NULL)) return;
1337 // for(int i=0; i<mol->showatoms.size(); i++) mol->showatoms[i].hidden=0;
1338 if (mol->selectedatoms.size()<3) {
1339 whyNotSplit->setText("<h2>Select at least 3 atoms first.</h2>");
1340 emit splitable(canSplitRotate());
1341 return;
1342 }
1343 //printf("findPivot: ");
1344 pivot=-1;pivot2=-1;
1345 emit pivot2Changed(pivot2);
1346 emit pivot1Changed(pivot);
1347 int molidx=-1,mi;
1348 seat.clear();
1349 for (int i=0; i<mol->selectedatoms.size();i++){//all selectet atoms have to be in the same molecule
1350 int ii=mol->selectedatoms.at(i).style;
1351 if ((ii<0)||(ii>=mol->asymm.size()))continue;
1352 mi=mol->asymm.at(ii).molindex;
1353 if ((molidx!=-1)&&(molidx!=mi)) {
1354 whyNotSplit->setText("<h2>Selected atoms have to be in the same molecule.</h2>");
1355 emit splitable(canSplitRotate());
1356 return;
1357 }
1358 molidx=mi;
1359 seat.append(ii);
1360 }
1361 int atinmol=0;
1362 for (int i=0; i<mol->asymm.size();i++){
1363 if (mol->asymm.at(i).molindex==molidx) atinmol++;
1364 }
1365 //printf("==%d\n",__LINE__);
1366 if (mol->selectedatoms.size()>atinmol) {
1367 whyNotSplit->setText("<h2>Only a part of a molecule may be selected.<br>Or you have to specify atoms definig the rotation axis yourself.</h2>");
1368 emit splitable(canSplitRotate());
1369 return;
1370 } //only a part of the molecule may be selected
1371 // */
1372 for (int i=0;i<seat.size();i++){
1373 //printf("**%d %d\n",mol->knoepfe.size(),seat.at(i));
1374 int isin=0,ks=mol->knoepfe.at(seat.at(i)).neighbors.size();
1375 for (int j=0;j<ks; j++){
1376 int nb=mol->knoepfe.at(seat.at(i)).neighbors.at(j);
1377 if (seat.contains(nb))isin++;
1378 }
1379 if ((pivot==-1)&&(isin<ks)) {pivot=seat.at(i);emit pivot1Changed(pivot);}
1380 else if (isin<ks) {
1381 whyNotSplit->setText("<h2>Only one atom is allowed to have bonds to none selected atoms.</h2>");
1382 emit splitable(canSplitRotate());
1383 return;
1384 }
1385 }
1386 //printf("==%d\n",__LINE__);
1387 if (pivot<0) {
1388 emit splitable(canSplitRotate());
1389 return;
1390 }
1391 int isin=0,ks=mol->knoepfe.at(pivot).neighbors.size();
1392 for (int j=0;j<ks; j++){
1393 int nb=mol->knoepfe.at(pivot).neighbors.at(j);
1394 if (seat.contains(nb)){pivot2=nb;emit pivot2Changed(pivot2);isin++;}
1395 }
1396 if (isin>1) {
1397 whyNotSplit->setText("<h2>pivot atom may be bonded to only one selected atoms.</h2>");
1398 emit splitable(canSplitRotate());
1399 return;
1400 }
1401 whyNotSplit->setText(QString("<h2>You can rotate around %1=%2</h2>").arg(mol->asymm.at(pivot).Label).arg(mol->asymm.at(pivot2).Label));
1402 emit splitable(canSplitRotate());
1403 }
1404
1405 void ChGL::splitRotate(){
1406 mol->splitRbonds.clear();
1407 mol->splitLbonds.clear();
1408 mol->splitLeftAtoms.clear();
1409 mol->splitRightAtoms.clear();
1410 if (freeRot->isChecked()){
1411 }
1412 //printf("?splitRotate\n");
1413 if (!canSplitRotate())return;
1414 //printf("splitRotate!\n");
1415 if (!freeRot->isChecked()&&((pivot<0)||(pivot2<0)))return;
1416 for (int i=0; i<seat.size();i++){
1417 mol->splitLeftAtoms.append(mol->asymm[seat.at(i)]);
1418 mol->splitRightAtoms.append(mol->asymm[seat.at(i)]);
1419 // if (seat.at(i)!=pivot) mol->showatoms[seat.at(i)].hidden=1;
1420 }
1421 /*printf("?splitRotate %d %d %d\n",
1422 mol->splitLeftAtoms.size(),
1423 mol->splitRightAtoms.size(),
1424 seat.size());*/
1425 //mol->selectedatoms.clear();
1426 //printf("%p %p\n", angle1, angle2);
1427 double arr[4];
1428 arr[0]=angle1->value();
1429 V3 ax=((manualAx->isChecked())||(freeRot->isChecked()))?
1430 Normalize(V3(axx->value(),axy->value(),axz->value())):
1431 Normalize(mol->asymm.at(pivot).pos-mol->asymm.at(pivot2).pos);
1432 arr[1]=ax.x;
1433 arr[2]=ax.y;
1434 arr[3]=ax.z;
1435 if ((!manualAx->isChecked())&&(!freeRot->isChecked())){
1436 axx->setValue(ax.x);
1437 axy->setValue(ax.y);
1438 axz->setValue(ax.z);
1439 }
1440 if ((freeRot->isChecked())&&(pivot1cb->isEnabled())){
1441 V3 o(0,0,0);
1442 for (int i=0; i<mol->selectedatoms.size(); i++){
1443 o+=mol->selectedatoms.at(i).pos;
1444 }
1445 o*=1.0/mol->selectedatoms.size();
1446 orgx->setValue(o.x);
1447 orgy->setValue(o.y);
1448 orgz->setValue(o.z);
1449 }
1450 if (freeRot->isChecked()){
1451 V3 o(0,0,0);
1452 for (int i=0; i<mol->splitLeftAtoms.size(); i++){
1453 o+=mol->splitLeftAtoms.at(i).pos;
1454 }
1455 o*=1.0/mol->splitLeftAtoms.size();
1456 V3 no(orgx->value(), orgy->value(), orgz->value());
1457 for (int i=0; i<mol->splitLeftAtoms.size(); i++){
1458 mol->splitLeftAtoms[i].pos+=no-o;
1459 }
1460 }
1461 pivot1cb->setEnabled(!freeRot->isChecked());
1462 pivot2cb->setEnabled(!freeRot->isChecked());
1463
1464 /*makeCurrent();
1465 glGetDoublev(GL_MODELVIEW_MATRIX,MM);
1466 printf("The MMATRIX is:\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n",
1467 MM[0],MM[1],MM[2],MM[3],
1468 MM[4],MM[5],MM[6],MM[7],
1469 MM[8],MM[9],MM[10],MM[11],
1470 MM[12],MM[13],MM[14],MM[15]);
1471 Matrix R=Matrix(
1472 MM[0],MM[1],MM[2],
1473 MM[4],MM[5],MM[6],
1474 MM[8],MM[9],MM[10]);//mol->rotarb(arr);
1475 GLdouble det=
1476 MM[0]*MM[5]*MM[10] - MM[8]*MM[5]*MM[2]+
1477 MM[1]*MM[6]*MM[8] - MM[9]*MM[6]*MM[0]+
1478 MM[2]*MM[4]*MM[9] - MM[10]*MM[4]*MM[1];
1479 printf("det %g %g\n",det,determinant(R));
1480 R = transponse(R * pow(det,-1.0/3.0));
1481 printf("__%f %f %f %f %f %f %f %f %f %d 1==%f\n",R.m11,R.m12,R.m13,R.m21,R.m22,R.m23,R.m31,R.m32,R.m33,angle1->value(),determinant(R));
1482 */
1483 /*
1484 double det =determinant(R);
1485 printf("die Determinante der Drehmatrix ist: %g\n",det);
1486 double w = asin(sqrt(Norm(axe)) / 2.0) / M_PI * 180.0;
1487 axe=Normalize(axe);
1488 printf("??%fdeg %f %f %f\n", w, axe.x, axe.y, axe.z);
1489 printf("=>%ddeg %f %f %f\n",angle1->value(), ax.x, ax.y, ax.z);
1490 */
1491 Matrix R = mol->rotarb(arr);
1492 V3 axe = V3((R.m23 - R.m32), (R.m31 - R.m13), (R.m12 - R.m21));
1493 //double _si = sqrt(Norm(axe)) / 2.0;
1494 //double _co = ((R.m11 + R.m22 + R.m33) - 1.0)/ 2.0;
1495 axe=Normalize(axe);
1496 //double wt = atan2(_si, _co) / M_PI * 180.0;
1497 //printf("%f grad %f %f %f\n", wt, axe.x, axe.y, axe.z);
1498 arr[0]=-angle2->value();
1499 Matrix Rbar=mol->rotarb(arr);
1500 V3 org=V3(orgx->value(), orgy->value(), orgz->value());
1501 if (!freeRot->isChecked()){
1502 org=mol->asymm.at(pivot).pos;
1503 orgx->setValue(org.x);
1504 orgy->setValue(org.y);
1505 orgz->setValue(org.z);
1506 }
1507 for (int i=0; i<seat.size();i++){
1508 mol->splitLeftAtoms[i].pos=R*(mol->splitLeftAtoms.at(i).pos-org)+org;
1509 mol->splitRightAtoms[i].pos=Rbar*(mol->splitRightAtoms.at(i).pos-org)+org;
1510 }
1511 mol->splitRbonds=mol->connecting(mol->splitRightAtoms,true);
1512 mol->splitLbonds=mol->connecting(mol->splitLeftAtoms,true);
1513 //rotze=pivot;
1514 update();
1515 }
1516
1517 bool ChGL::canSplitRotate(){
1518 printf("canSplitRotate? %d \n",(freeRot!=nullptr)&&(freeRot->isChecked())&&(mol->selectedatoms.size()>2));
1519 if (freeRot==nullptr) return false;//!!!
1520 if ((freeRot!=nullptr)&&(freeRot->isChecked())&&(mol->selectedatoms.size()>2)) return true;
1521 if ((pivot>-1)&&(pivot2>-1)&&(pivot<mol->asymm.size())&&(pivot2<mol->asymm.size())&&(mol->selectedatoms.size()>2)) return true;
1522 return false;
1523 }
1524
1525 void ChGL::updateBondActions(){//!<changes the visibility state of QActions in the 'Selection Toolbar'.
1526 bool p=pause;
1527 pause=true;
1528 clearSelection->setVisible(!mol->selectedatoms.isEmpty());
1529 invSelection->setVisible(!mol->selectedatoms.isEmpty());
1530 centroid->setVisible(mol->selectedatoms.size()>1);
1531 centerSelection->setVisible((!mol->selectedatoms.isEmpty())||(centerSelection->isChecked()));
1532 delSelAt->setVisible(!mol->selectedatoms.isEmpty());
1533 delSelAt->setEnabled(!mol->selectedatoms.isEmpty());
1534 hideNotSelection->setVisible(!mol->selectedatoms.isEmpty());
1535 cntrPlot->setVisible(((!fVertexes[0].isEmpty()||!fVertexes[1].isEmpty())&&(mol->selectedatoms.size()==3)));
1536 unhide->setVisible(hiddenThings);
1537 invhide->setVisible(hiddenThings);
1538 if (mol->selectedatoms.size()!=2){
1539 addBond->setVisible(false);
1540 killBond->setVisible(false);
1541 }
1542 else{
1543 int da=0;
1544 for (int i=0; i<mol->showbonds.size();i++){
1545 if (((mol->selectedatoms.at(0).style==mol->showbonds.at(i).a1)||
1546 (mol->selectedatoms.at(0).style==mol->showbonds.at(i).a2))&&
1547 ((mol->selectedatoms.at(1).style==mol->showbonds.at(i).a1)||
1548 (mol->selectedatoms.at(1).style==mol->showbonds.at(i).a2))) da=i;
1549 }
1550 if (da){
1551 addBond->setVisible(false);
1552 killBond->setVisible(true);
1553 killBond->setData(da);
1554 }
1555 else{
1556 addBond->setVisible(true);
1557 killBond->setVisible(false);
1558 }
1559 }
1560 findPivot();
1561 pause=p;
1562 }
1563
1564 void ChGL::connectSelection(){//!creates a bond betwen two selected atoms.
1565 if (mol->selectedatoms.size()!=2) return;
1566 MyBond b;
1567 b.a1=mol->selectedatoms.at(0).style;
1568 b.a2=mol->selectedatoms.at(1).style;
1569 b.ato1=&mol->showatoms[mol->selectedatoms.at(0).style];
1570 b.ato2=&mol->showatoms[mol->selectedatoms.at(1).style];
1571 b.length=sqrt(Distance(b.ato1->pos,b.ato2->pos));
1572 mol->showbonds.append(b);
1573 mol->selectedatoms.clear();
1574 updateBondActions();
1575 update();
1576 }
1577
1578 void ChGL::disConnectSelection(int index){//! destroyes the bond between two selected atoms.
1579 mol->showbonds.removeAt(index);
1580 mol->selectedatoms.clear();
1581 updateBondActions();
1582 update();
1583 }
1584
1585 void ChGL::setAtom(bool b){//!toggles atoms
1586 drawAt=b;
1587 update();
1588 }
1589
1590 void ChGL::setBond(bool b){//!toggles bonds
1591 drawBo=b;
1592 update();
1593 }
1594
1595 void ChGL::setLabel(bool b){//!toggles lables
1596 drawLa=b;
1597 update();
1598 }
1599
1600 void ChGL::setHBond(bool b){//!toggles H-bonds
1601 drawHb=b;
1602 update();
1603 }
1604
1605 void ChGL::setBGGradient(bool b){//!toggles back gound gradient
1606 bggradient=b;
1607 update();
1608 }
1609
1610 void ChGL::setADP(bool b){//!toggles ellipsoids
1611 drawADP=b;
1612 update();
1613 }
1614
1615 void ChGL::setMSAA(bool b){
1616 if (b) {
1617 glEnable(GL_MULTISAMPLE);
1618 }
1619 else {
1620 glDisable(GL_MULTISAMPLE);
1621 }
1622 update();
1623 }
1624
1625 void ChGL::setUnit(bool b){//!toggles unit cell box
1626 drawUc=b;
1627 update();
1628 }
1629
1630 void ChGL::changeBColor(){//! a color dialog for chosing a new back ground color
1631 QColor bc= QColorDialog::getColor(backGroundColor, this);
1632 if(bc.isValid()) backGroundColor=bc;
1633 update();
1634 }
1635
1636 void ChGL::changeTColor(){//! a color dialog for chosing a label color
1637 QColor lc= QColorDialog::getColor(labelColor, this);
1638 if (lc.isValid()) labelColor=lc;
1639 update();
1640 }
1641
1642 void ChGL::setMolecule(Molecule *m){//! sets the pointer to the Molecule object deletes the old one if it is exists and is differen from the new one
1643 //printf("setMolecule\n");
1644 if (mol!=m) {
1645 if (mol) delete mol;
1646 mol=m;
1647 }
1648 double dim=mol->dimension();
1649 L=100.0/dim;
1650 }
1651
1652 void ChGL::showMatrix(){
1653 // stereo_mode++;
1654 // stereo_mode%=4;
1655
1656 makeCurrent();
1657 update();
1658 printf("The MMATRIX is:\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n",
1659 MM[0],MM[1],MM[2],MM[3],
1660 MM[4],MM[5],MM[6],MM[7],
1661 MM[8],MM[9],MM[10],MM[11],
1662 MM[12],MM[13],MM[14],MM[15]);
1663 GLdouble mm[16];
1664 /*
1665 int maxstack=0;
1666 glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &maxstack);
1667 for (int i=1; i<maxstack; i++){
1668 glPushMatrix();
1669 */
1670 glGetDoublev(GL_MODELVIEW_MATRIX,mm);
1671 printf("The Mmatrix is:\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n",
1672 mm[0],mm[1],mm[2],mm[3],
1673 mm[4],mm[5],mm[6],mm[7],
1674 mm[8],mm[9],mm[10],mm[11],
1675 mm[12],mm[13],mm[14],mm[15]);
1676 /*}
1677 for (int i=1; i<maxstack; i++){
1678 glPopMatrix();
1679 }
1680
1681 */
1682 GLdouble det=
1683 mm[0]*mm[5]*mm[10] - mm[8]*mm[5]*mm[2]+
1684 mm[1]*mm[6]*mm[8] - mm[9]*mm[6]*mm[0]+
1685 mm[2]*mm[4]*mm[9] - mm[10]*mm[4]*mm[1];
1686 printf("die Determinante der Drehmatrix ist: %g\n",det);
1687 V3 axe = V3((mm[9]-mm[6])/det,(mm[2]-mm[8])/det,(mm[4]-mm[1])/det);
1688 double w = asin(sqrt(Norm(axe))/2.0)/M_PI*180.0;
1689 axe=Normalize(axe);
1690 printf("%fdeg %f %f %f\n",w,axe.x,axe.y,axe.z);
1691 glGetDoublev(GL_PROJECTION_MATRIX,mm);
1692 printf("Die Pmatrix ist:\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n",
1693 mm[0],mm[1],mm[2],mm[3],
1694 mm[4],mm[5],mm[6],mm[7],
1695 mm[8],mm[9],mm[10],mm[11],
1696 mm[12],mm[13],mm[14],mm[15]);
1697 det=
1698 mm[0]*mm[5]*mm[10] - mm[8]*mm[5]*mm[2]+
1699 mm[1]*mm[6]*mm[8] - mm[9]*mm[6]*mm[0]+
1700 mm[2]*mm[4]*mm[9] - mm[10]*mm[4]*mm[1];
1701 printf("die Determinante der Drehmatrix ist: %g\n",det);
1702
1703 }
1704
1705 void ChGL::along001(){
1706 makeCurrent();
1707 double va=viewAngle;
1708 setViewAngle(29.0);
1709 MM[0]=1.0;
1710 MM[1]=0.0;
1711 MM[2]=0.0;
1712 MM[4]=0.0;
1713 MM[5]=-1.0;
1714 MM[6]=0.0;
1715 MM[8]=0.0;
1716 MM[9]=0.0;
1717 MM[10]=-1.0;
1718 glMatrixMode(GL_MODELVIEW);
1719 glLoadMatrixd(MM);
1720 setViewAngle(va);
1721 }
1722
1723 void ChGL::zoomOut(){
1724
1725 makeCurrent();
1726 double va=viewAngle;
1727 setViewAngle(29.0);
1728 glMatrixMode(GL_MODELVIEW);
1729 glGetDoublev(GL_MODELVIEW_MATRIX,MM);
1730 GLdouble det=
1731 MM[0]*MM[5]*MM[10] - MM[8]*MM[5]*MM[2]+
1732 MM[1]*MM[6]*MM[8] - MM[9]*MM[6]*MM[0]+
1733 MM[2]*MM[4]*MM[9] - MM[10]*MM[4]*MM[1];
1734 /*printf("Die Mmatrix ist:\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n",
1735 MM[0] ,MM[1] ,MM[2] ,MM[3],
1736 MM[4] ,MM[5] ,MM[6] ,MM[7],
1737 MM[8] ,MM[9] ,MM[10],MM[11],
1738 MM[12],MM[13],MM[14],MM[15]);
1739 printf("die Determinante der Matrix ist: %g\n",det);*/
1740 if (det !=0.0){
1741 det=pow(det,1.0/3.0);
1742 MM[ 0]/=det;
1743 MM[ 1]/=det;
1744 MM[ 2]/=det;
1745 MM[ 4]/=det;
1746 MM[ 5]/=det;
1747 MM[ 6]/=det;
1748 MM[ 8]/=det;
1749 MM[ 9]/=det;
1750 MM[10]/=det;
1751 det=
1752 MM[0]*MM[5]*MM[10] - MM[8]*MM[5]*MM[2]+
1753 MM[1]*MM[6]*MM[8] - MM[9]*MM[6]*MM[0]+
1754 MM[2]*MM[4]*MM[9] - MM[10]*MM[4]*MM[1];
1755 /*printf("##Die Mmatrix ist:\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n%9.6f %9.6f %9.6f %9.6f\n",
1756 MM[0] ,MM[1] ,MM[2] ,MM[3],
1757 MM[4] ,MM[5] ,MM[6] ,MM[7],
1758 MM[8] ,MM[9] ,MM[10],MM[11],
1759 MM[12],MM[13],MM[14],MM[15]);
1760 printf("##die Determinante der Matrix ist: %g\n",det);*/
1761
1762 }
1763 glLoadMatrixd(MM);
1764 setViewAngle(va);
1765 }
1766
1767
1768 void ChGL::initializeGL(){
1769 printf("initGL\n");
1770 glEnable(GL_LINE_SMOOTH);
1771 glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
1772 const GLfloat position[] = {100.0f, 100.0f,100.0f,0.0f};
1773 const GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
1774 const GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
1775 const GLfloat ambient[] = { 0.5, 0.5, 0.5, 1.0 };
1776
1777 glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, 1 );
1778
1779 glLightfv( GL_LIGHT0, GL_POSITION, position );
1780 glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
1781 glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
1782 glLightfv( GL_LIGHT0, GL_SPECULAR, specular );
1783
1784 glLightfv( GL_LIGHT1, GL_POSITION, position );
1785 glLightfv( GL_LIGHT1, GL_DIFFUSE, diffuse );
1786 glLightfv( GL_LIGHT1, GL_AMBIENT, ambient );
1787 glLightfv( GL_LIGHT2, GL_DIFFUSE, diffuse );
1788
1789
1790 glEnable( GL_LIGHTING );
1791 glEnable( GL_LIGHT0 );
1792
1793 glEnable( GL_LIGHT1 );
1794 glEnable( GL_BLEND);
1795 mol->fogrange=60;
1796 glDisable(GL_FOG);
1797 glFogi(GL_FOG_MODE,GL_LINEAR);
1798 glFogi(GL_FOG_START,205-mol->fogrange);
1799 glFogi(GL_FOG_END,205+mol->fogrange);
1800 GLfloat fgc[4]={(GLfloat)backGroundColor.redF(),(GLfloat)backGroundColor.greenF(),(GLfloat)backGroundColor.blueF(),1.0f};
1801 //printf("FOG %f %f %f %f\n",fgc[0],fgc[1],fgc[2],fgc[3]);
1802 glFogfv(GL_FOG_COLOR,fgc);
1803
1804 glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
1805 glAlphaFunc ( GL_GREATER, 0.01f ) ;
1806 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
1807 const GLfloat OBJ_SPE[] = { 0.8f, 0.8f, 0.8f, 1.0f };
1808 const GLfloat OBJ_SHIN = 32.0;
1809 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, OBJ_SPE );
1810 glEnable ( GL_COLOR_MATERIAL ) ;
1811 glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
1812 glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, OBJ_SHIN );
1813 glShadeModel( GL_SMOOTH );
1814 //glShadeModel(GL_FLAT);
1815 glEnable(GL_NORMALIZE);
1816
1817 qglClearColor(backGroundColor);
1818
1819 glEnable(GL_DEPTH_TEST );
1820 glDepthFunc(GL_LEQUAL);
1821 gluLookAt_(0.0, 200, 50 , 0.0, 0.0, 0.0, 0.0, -100, 400 );
1822 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
1823 setMouseTracking(true);
1824 //Listen inititialisieren ist hier!
1825 int ect=0;
1826 #ifndef GL_MAX_ELEMENTS_INDICES
1827 #define GL_MAX_ELEMENTS_INDICES 0x80E9
1828 #endif /* GL_MAX_ELEMENTS_INDICES */
1829 int midx;
1830 glGetIntegerv(GL_MAX_ELEMENTS_INDICES,&midx);
1831 //printf("GL_MAX_ELEMENTS_INDICES = %d\n",midx);
1832 if (midx<3840)mol->LOD=qMin(mol->LOD,3);
1833 if (midx<940)mol->LOD=qMin(mol->LOD,2);
1834 GLenum err = GL_NO_ERROR;
1835 while((err = glGetError()) != GL_NO_ERROR)
1836 {
1837 printf("ganz davor %d %d [%d]\n",err==GL_INVALID_VALUE ,err == GL_INVALID_OPERATION,++ect);
1838 // printf("%s\n",(char*)gluErrorString(err));
1839 }
1840 //printf("before makeCurrent()\n");
1841 makeCurrent();
1842
1843 //printf("after makeCurrent()\n");
1844 //QOpenGLBuffer m_vertexBuffer;
1845 // we need a VAO in core!
1846 //GLuint VAO;
1847 //PglGenVertexArrays glGenVertexArrays = (PglGenVertexArrays) context->getProcAddress("glGenVertexArrays");
1848 //PglBindVertexArray glBindVertexArray = (PglBindVertexArray) context->getProcAddress("glBindVertexArray");
1849 //glGenVertexArrays(1, &VAO);
1850 //glBindVertexArray(VAO);
1851
1852 /*
1853 float points[] = { -0.5f, -0.5f, 0.5f, 1.0f,
1854 -0.5f, 0.5f, 0.5f, 1.0f,
1855 0.01f, 0.01f, 0.01f, 1.0f,
1856 1.0f, 0.0f, 0.5f, 1.0f,
1857 -1.0f, 0.0f, 0.0f, 1.0f,
1858 0.0f, -1.0f, 0.0f, 1.0f,
1859 0.0f, 1.0f, -0.5f, 1.0f,
1860 0.5f, -0.5f, -0.5f, 1.0f,
1861 0.5f, 0.5f, -0.5f, 1.0f };
1862
1863 if ( !prepareShaderProgram( ":/std.vert", ":/std.geom",":/std.frag" ) ) return;
1864 if ( !m_shader.bind() )
1865 {
1866 qWarning() << "Could not bind shader program to context";
1867 return;
1868 }
1869
1870 // Enable the "vertex" attribute to bind it to our currently bound
1871 // vertex buffer.
1872 m_shader.setAttributeBuffer( "vertex", GL_FLOAT, 0, 4 );
1873 angleH = m_shader.uniformLocation( "angle");
1874 m_shader.setUniformValue(angleH, ang);
1875 colorH = m_shader.uniformLocation( "Color");
1876 m_shader.setUniformValue(colorH, QColor("teal"));
1877 m_shader.enableAttributeArray( "vertex" );
1878 m_shader.release();
1879 */
1880 const QOpenGLContext *contxt = this->context();
1881 //printf("%p %p\n",mol->g_Program,contxt);
1882 if (mol->g_Program==NULL){
1883 mol->g_Program = new QOpenGLShaderProgram(this);
1884 //printf("%p %p\n",mol->g_Program,contxt);
1885 mol->g_program = mol->installShader();//note the CaSe
1886 //printf("mol->g_program %d\n",mol->g_program);
1887 }
1888 printf("shaderprog %d context is valid = %d \n",mol->g_program,contxt->isValid());
1889 if (!mol->g_program) printf("%s\n",mol->g_Program->log().toStdString().c_str());
1890 while((err = glGetError()) != GL_NO_ERROR)
1891 {
1892 printf("kurz davor GL_INVALID_VALUE%d GL_INVALID_OPERATION%d [%d] err=%x\n",err==GL_INVALID_VALUE ,err == GL_INVALID_OPERATION,++ect,err);
1893 }
1894 on=true;
1895 setupTexture();
1896 //printf("--initGL\n");
1897 emit initialized();
1898 /*
1899 QTimer *tmr = new QTimer();
1900 connect(tmr, &QTimer::timeout, this, &ChGL::printFPS);
1901 tmr->start(2000);
1902 */
1903 }
1904
1905 void ChGL::printFPS(){
1906 printf("FPS: %.1f %d\n", frames_counter / 2.0, format().swapInterval());
1907 frames_counter = 0;
1908 }
1909
1910 void ChGL::setRotationCenter(){
1911 //! Sets the rotation center to the spezified atom
1912 QAction *action = qobject_cast<QAction *>(sender());
1913 int index=0;
1914 if (action)
1915 index=action->data().toInt();
1916 else return;
1917 if (index==(int)((GLuint)-1))return;
1918 rotze=((int)index<mol->showatoms.size())?index:-1;
1919 if (rotze>-1){
1920 rCenter->show();
1921 glGetDoublev(GL_MODELVIEW_MATRIX,MM);
1922 MM[12]=MM[13]=0;
1923 glLoadMatrixd(MM);
1924 }
1925 update();
1926 }
1927
1928 void ChGL::setRotationCenter(V3 center){
1929 // printf("%f %f %f \n%f %f %f\n", altemitte.x, altemitte.y, altemitte.z, center.x, center.y, center.z);
1930 altcenter=center;
1931 rotze=-76185;//zip code
1932 rCenter->show();
1933 update();
1934 }
1935
1936
1937 void ChGL::setRotationCenter(int rz){
1938 /*! Sets the rotation center to the spezified atom
1939 * @param index of the spezified atom.
1940 */
1941 rotze=((int)rz<mol->showatoms.size())?rz:-1;
1942 if (rotze>-1){
1943 rCenter->show();
1944 glGetDoublev(GL_MODELVIEW_MATRIX,MM);
1945 MM[12]=MM[13]=0;
1946 glLoadMatrixd(MM);
1947 }
1948 update();
1949 }
1950
1951 void ChGL::expand(){//! Lets Molecule.expandAt(int index) serach for neighboring molecules around the specified atom.
1952 QAction *action = qobject_cast<QAction *>(sender());
1953 int index=0;
1954 if (action)
1955 index=action->data().toInt();
1956 else return;
1957 if (index==(int)((GLuint)-1))return;
1958 mol->expandAt(index);
1959 fuse->setVisible(true);
1960 grow->setVisible(false);
1961 emit bigmessage(mol->HumanSymmetry);
1962 murx=-__LINE__;
1963 update();
1964 }
1965
1966
1967
1968 void ChGL::updateLabelTextures(){
1969 if (pause) return;
1970 bool worknow = false;
1971 int nchanged=0;
1972 int changethis=0;
1973 if (shortLabels->isChecked()!=was_short_labels){
1974 worknow = true;
1975 was_short_labels=shortLabels->isChecked();
1976 }
1977 if (mol->showatoms.size()!=labelTexts.size())worknow = true;
1978 if (!worknow){
1979 for (int li=0; li<mol->showatoms.size(); li++){
1980 QString label=mol->showatoms.at(li).Label;
1981 if (shortLabels->isChecked()) {
1982 label=label.section("_",0,0);
1983 label=label.section(QString::fromUtf8("»"),0,0);
1984 }
1985 if (labelTexts.at(li)!=label){
1986 worknow = true;
1987 changethis = li;
1988 nchanged++;
1989 //break; // cause of 24065
1990 }
1991 }
1992 }
1993 makeCurrent();
1994 //printf("updateLabelTextures() %p need to update %d number of changed atoms %d\n",context(),worknow,nchanged);
1995 //if (!worknow) return;
1996 if (!context()) return;
1997 if (worknow){
1998 if (nchanged==1){//only one change to perform
1999 QFont fnt=myFont;
2000 fnt.setPointSize((mol->showatoms.at(changethis).an>=0)?48:24);// prabably smaller values than 144:96 render faster
2001 QFontMetrics mtr(fnt);
2002 QString label=mol->showatoms.at(changethis).Label;
2003 if (shortLabels->isChecked()) {
2004 label=label.section("_",0,0);
2005 label=label.section(QString::fromUtf8("»"),0,0);
2006 }
2007 labelTexts[changethis]=label;
2008 QRect rc=mtr.boundingRect(label);
2009 #if (QT_VERSION>=0x050000)
2010 QImage image(rc.width()+mtr.horizontalAdvance("Li"), rc.height()+2,QImage::Format_ARGB32_Premultiplied);
2011 #else
2012 QImage image(rc.width()+mtr.width("Li"), rc.height()+2,QImage::Format_ARGB32_Premultiplied);
2013 #endif
2014 //printf("texture %d %d x %d Pts = %d\n",li,image.width(),image.height(),fnt.pointSize());
2015
2016 image.fill(0);
2017 QPainter p;
2018 p.begin(&image);
2019 p.setPen(QPen(Qt::white));
2020 p.setBackground(Qt::NoBrush);
2021 p.setFont(fnt);
2022 p.drawText(image.rect(), Qt::AlignRight, label);
2023 p.end();
2024 image=image.convertToFormat(QImage::Format_Indexed8);
2025 labelTextures[changethis] = new QOpenGLTexture(image.mirrored());
2026 }
2027 else {
2028 //printf("work %d %d %d %p\n",worknow,mol->showatoms.size(),labelTexts.size(),context());
2029 labelTextures.clear();
2030 labelTexts.clear();
2031 for (int li=0; li<mol->showatoms.size(); li++){
2032 QFont fnt=myFont;
2033 fnt.setPointSize((mol->showatoms.at(li).an>=0)?48:24);// prabably smaller values than 144:96 render faster
2034 QFontMetrics mtr(fnt);
2035 QString label=mol->showatoms.at(li).Label;
2036 if (shortLabels->isChecked()) {
2037 label=label.section("_",0,0);
2038 label=label.section(QString::fromUtf8("»"),0,0);
2039 }
2040 labelTexts.append(label);
2041 QRect rc=mtr.boundingRect(label);
2042 #if (QT_VERSION>=0x050000)
2043 QImage image(rc.width()+mtr.horizontalAdvance("Li"), rc.height()+2,QImage::Format_ARGB32_Premultiplied);
2044 #else
2045 QImage image(rc.width()+mtr.width("Li"), rc.height()+2,QImage::Format_ARGB32_Premultiplied);
2046 #endif
2047 //printf("texture %d %d x %d Pts = %d\n",li,image.width(),image.height(),fnt.pointSize());
2048
2049 image.fill(0);
2050 QPainter p;
2051 p.begin(&image);
2052 p.setPen(QPen(Qt::white));
2053 p.setBackground(Qt::NoBrush);
2054 p.setFont(fnt);
2055 p.drawText(image.rect(), Qt::AlignRight, label);
2056 p.end();
2057 image=image.convertToFormat(QImage::Format_Indexed8);
2058 labelTextures.append(new QOpenGLTexture(image.mirrored()));
2059 }
2060 }
2061 }// work now you lazy!
2062 extraTextures.clear();
2063 QStringList lala;
2064 lala<<"0"<<"a"<<"b"<<"c";
2065 for (int i=0; i<mol->legendAtoms.size(); i++){
2066 lala.append(mol->legendAtoms.at(i).Label);
2067 }
2068 for (int i=0; i<lala.size();i++){
2069 QFont fnt=myFont;
2070 fnt.setPointSize(96);
2071 QFontMetrics mtr(myFont);
2072 QRect rc=mtr.boundingRect(lala.at(i));
2073 #if (QT_VERSION>=0x050000)
2074 QImage image(rc.width()+mtr.horizontalAdvance("Li"),rc.height(),QImage::Format_ARGB32_Premultiplied);
2075 #else
2076 QImage image(rc.width()+mtr.width("Li"),rc.height(),QImage::Format_ARGB32_Premultiplied);
2077 #endif
2078 image.fill(0);
2079 QPainter p;
2080 p.begin(&image);
2081 p.setPen(QPen(Qt::white));
2082 p.setBackground(Qt::NoBrush);
2083 p.setFont(myFont);
2084 p.drawText(image.rect(), Qt::AlignRight, lala.at(i));
2085 p.end();
2086 image=image.convertToFormat(QImage::Format_Indexed8);
2087 extraTextures.append(new QOpenGLTexture(image.mirrored()));
2088 }
2089 update();
2090 }
2091
2092 //#include <iostream>
2093 void ChGL::setReNaMo(bool b){//!enter rename mode
2094 inRenameMode=b;
2095 //printf("ChGL Re Na Mo\n");
2096 }
2097
2098 void ChGL::rotCenter(){//! reset the rotation center to the center of gravity.
2099 rotze=-1;
2100 update();
2101 rCenter->hide();
2102 }
2103
2104 void ChGL::resizeGL(int width, int height) {
2105 if (pause) {ww=width; wh=height; return;}
2106 //GLint v[2];
2107 //glGetIntegerv(GL_MAX_VIEWPORT_DIMS,v);
2108 //printf("MAXVP %d %d \n",v[0],v[1]);
2109 retinafktr=devicePixelRatio();// it qt5 this is in in qt6 its qreal!!
2110 glViewport(0, 0, ww=width*retinafktr, wh=height*retinafktr);
2111 glGetIntegerv(GL_VIEWPORT, vp);
2112
2113 //printf("VP %d %d %d %d w = %d h = %d width = %d height = %d retina factor = %f devicePixelRatio() = %f\n",vp[0],vp[1],vp[2],vp[3],ww,wh,
2114 // this->width(),this->height(),retinafktr,devicePixelRatio());
2115 glMatrixMode(GL_PROJECTION);
2116 glLoadIdentity();
2117 gluPerspective_( viewAngle, (double)width/height, 5.0, 8000.0 );
2118 }
2119
2120 void ChGL::zoom(double speed){//!scale about speed @param speed scale factor
2121 moving->start(dratpause);
2122 makeCurrent();
2123 // printf("%d\n",dratpause);
2124 glScaled(1.0+speed*0.1,1.0+speed*0.1,1.0+speed*0.1);
2125 update();
2126 }
2127
2128 void ChGL::rotY(double speed){//!rotate around Y axis @param speed in degrees
2129 moving->start(dratpause);
2130
2131 makeCurrent();
2132 glRotateL(-20.0*speed,0.0f,1.0f,0.0f);
2133 update();
2134 }
2135
2136 void ChGL::gZoom(double speed){//!scale about speed @param speed scale factor
2137 moving->start(dratpause);
2138 makeCurrent();
2139 glScaled(1.0+speed*0.02,1.0+speed*0.02,1.0+speed*0.02);
2140 update();
2141 }
2142
2143 void ChGL::rotZ(double speed){//!rotate around Z axis @param speed in degrees
2144 moving->start(dratpause);
2145 makeCurrent();
2146 glRotateL(speed,0.0f,0.0f,1.0f);
2147 update();
2148 }
2149
2150 void ChGL::moveY(double speed){//!translate the molecule in Y direction
2151 moving->start(dratpause);
2152 makeCurrent();
2153 glTranslateL(0.0,speed,0.0);
2154 update();
2155 }
2156
2157 void ChGL::moveX(double speed){//!translate the molecule in X direction
2158 moving->start(dratpause);
2159 makeCurrent();
2160 glTranslateL(speed,0.0,0.0);
2161 // QMessageBox::information(this,"Px move","xmoved",QMessageBox::Ok);
2162 update();
2163 }
2164
2165 void ChGL::rotX(double speed){//!rotate around X axis @param speed in degrees
2166 moving->start(dratpause);
2167 makeCurrent();
2168 glRotateL(-20.0*speed,1.0f,0.0f,0.0f);
2169 update();
2170 }
2171
2172
2173 void ChGL::zalman(){//!sets the stereo mode for Zalman monitors.
2174 stereo_mode=1;
2175 minus= 1;
2176 update();
2177 }
2178
2179 QStringList ChGL::resis(){
2180 QStringList l;
2181 for (int i=0; i<mol->asymm.size(); i++){
2182 if (mol->asymm.at(i).an<0)continue;
2183 if (mol->asymm.at(i).resiNr>0){
2184 if (!l.contains(QString::number(mol->asymm.at(i).resiNr),Qt::CaseInsensitive))
2185 l.append(QString::number(mol->asymm.at(i).resiNr));
2186 if (!l.contains(mol->asymm.at(i).ResiClass))
2187 l.append(mol->asymm.at(i).ResiClass);
2188 }
2189 }
2190 if (!l.isEmpty()) l.insert(0,"*");
2191 return l;
2192 }
2193
2194 void ChGL::singleBondDistance(){
2195 if (mol->selectedatoms.size()!=2)return;
2196 QWidgetList wl = QApplication::allWidgets();
2197 for (int i=0; i<wl.size(); i++){
2198 if (wl.at(i)->objectName()=="DFIX_DIST"){
2199 QLineEdit *valueline = qobject_cast<QLineEdit *>(wl[i]);
2200 valueline->setText(QString::number(0.01*(mol->Kovalenz_Radien[mol->selectedatoms.at(0).an]+mol->Kovalenz_Radien[mol->selectedatoms.at(1).an]),10,3));
2201 }
2202 }
2203 }
2204
2205 void ChGL::addDFIX(){
2206 if (mol->selectedatoms.size()!=2)return;
2207 QDialog *dia = new QDialog();
2208 dia->setWindowTitle("DFIX: Geometrical restraint");
2209 dia->setModal(false);
2210
2211 QGridLayout *grid = new QGridLayout(dia);
2212 QLineEdit *valueline = new QLineEdit(dia);
2213 valueline->setObjectName("DFIX_DIST");
2214 QLineEdit *esdline = new QLineEdit(dia);
2215 QLabel *value = new QLabel("Value:", dia);
2216 QLabel *esd = new QLabel("ESD:", dia);
2217 QLabel *atoms = new QLabel(QString("%1==%2 : %3 A")
2218 .arg(mol->selectedatoms.at(0).Label)
2219 .arg(mol->selectedatoms.at(1).Label)
2220 .arg( sqrt(Distance(mol->selectedatoms.at(0).pos,mol->selectedatoms.at(1).pos)),10,'f',3));
2221 QCheckBox *bindit = new QCheckBox("Insert BIND instruction",dia);
2222 QStringList rl = resis();
2223 QComboBox *resiCom = NULL;
2224 if (!rl.isEmpty()){
2225 QLabel *resi = new QLabel("Residue specific",dia);
2226 resiCom = new QComboBox(dia);
2227 // Usually you want to define residue restraints with numbers at the atom:
2228 resiCom->addItem("");
2229 resiCom->addItems(rl);
2230 grid->addWidget(resi,3,0);
2231 grid->addWidget(resiCom,3,1);
2232 }
2233 // Set default value for distance and esd
2234 // Get value for DFIX. Current bond distance and default esd - 0.02
2235 valueline->setText(QString::number(sqrt(Distance(mol->selectedatoms.at(0).pos,mol->selectedatoms.at(1).pos)),10,3));
2236 esdline->setText("0.02");
2237 grid->addWidget(atoms,0,0,1,2);
2238 grid->addWidget(value,1,0);
2239 grid->addWidget(valueline,1,1);
2240 grid->addWidget(esd,2,0);
2241 grid->addWidget(esdline,2,1);
2242 grid->addWidget(bindit,4,0);
2243 QDialogButtonBox *buttonBox = new QDialogButtonBox();
2244
2245 QPushButton *OkButton;
2246 QPushButton *CancelButton;
2247 QPushButton *singleBondButton = new QPushButton(QString("%1 A").arg(0.01*(mol->Kovalenz_Radien[mol->selectedatoms.at(0).an]+mol->Kovalenz_Radien[mol->selectedatoms.at(1).an])));
2248
2249 OkButton = buttonBox->addButton(QDialogButtonBox::Ok);
2250 CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
2251 buttonBox->addButton(singleBondButton,QDialogButtonBox::ActionRole);
2252
2253
2254 buttonBox->setOrientation(Qt::Horizontal);
2255
2256 grid->addWidget(buttonBox,10,0);
2257
2258 dia->setLayout(grid);
2259 connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept()));
2260 connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject()));
2261 connect(singleBondButton, SIGNAL(clicked()), this, SLOT(singleBondDistance()));
2262
2263 dia->show();
2264 int a = dia->exec();
2265
2266 if(a == QDialog::Accepted)
2267 {
2268 // read value from value line
2269 QString s=(rl.isEmpty())?"":resiCom->currentText();
2270 emit insertDFIX(valueline->text().toDouble(),esdline->text().toDouble(),mol->selectedatoms,s);
2271 if (bindit->isChecked()) emit bindthem();
2272 mol->selectedatoms.clear();
2273 }
2274 else
2275 {
2276 if(a == QDialog::Rejected)
2277 dia->close();
2278
2279 }
2280
2281
2282 // updateBondActions();
2283 }
2284
2285 void ChGL::addDANG(){
2286 QDialog *dia = new QDialog(this);
2287 dia->setWindowTitle(tr("DANG: Geometrical restraint"));
2288 dia->setModal(false);
2289
2290 QGridLayout *grid = new QGridLayout(dia);
2291 QLineEdit *valueline = new QLineEdit(dia);
2292 QLineEdit *esdline = new QLineEdit(dia);
2293 QLabel *value = new QLabel("Value:", dia);
2294 QLabel *esd = new QLabel("ESD:", dia);
2295 QStringList rl = resis();
2296 QComboBox *resiCom = NULL;
2297 if (!rl.isEmpty()){
2298 QLabel *resi = new QLabel("Residue specific",dia);
2299 resiCom = new QComboBox(dia);
2300 resiCom->addItem("");
2301 resiCom->addItems(rl);
2302 grid->addWidget(resi,2,0);
2303 grid->addWidget(resiCom,2,1);
2304 }
2305 // Set default value for distance and esd
2306 // Get value for DANG. Current bond distance and default esd - 0.04
2307 valueline->setText(QString::number(sqrt(Distance(mol->selectedatoms.at(0).pos,mol->selectedatoms.at(1).pos)),10,3));
2308 esdline->setText("0.04");
2309
2310 grid->addWidget(value,0,0);
2311 grid->addWidget(valueline,0,1);
2312 grid->addWidget(esd,1,0);
2313 grid->addWidget(esdline,1,1);
2314
2315 QDialogButtonBox *buttonBox = new QDialogButtonBox();
2316
2317 QPushButton *OkButton;
2318 QPushButton *CancelButton;
2319
2320 OkButton = buttonBox->addButton(QDialogButtonBox::Ok);
2321 CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
2322
2323 buttonBox->setOrientation(Qt::Horizontal);
2324
2325 grid->addWidget(buttonBox,4,0);
2326
2327 dia->setLayout(grid);
2328 connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept()));
2329 connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject()));
2330
2331 dia->show();
2332 int a = dia->exec();
2333
2334 if(a == QDialog::Accepted)
2335 {
2336 // read value from value line
2337 QString s=(rl.isEmpty())?"":resiCom->currentText();
2338 emit insertDANG(valueline->text().toDouble(),esdline->text().toDouble(),mol->selectedatoms,s);
2339 mol->selectedatoms.clear();
2340 }
2341 else
2342 {
2343 if(a == QDialog::Rejected)
2344 dia->close();
2345 }
2346
2347 }
2348
2349 void ChGL::addFLAT(){
2350 QDialog *dia = new QDialog(this);
2351 dia->setWindowTitle(tr("FLAT: Geometrical restraint"));
2352 dia->setModal(false);
2353
2354 QGridLayout *grid = new QGridLayout(dia);
2355 QLineEdit *esdline = new QLineEdit(dia);
2356 QLabel *esd = new QLabel("ESD:", dia);
2357 QStringList rl = resis();
2358 QComboBox *resiCom = NULL;
2359 if (!rl.isEmpty()){
2360 QLabel *resi = new QLabel("Residue specific",dia);
2361 resiCom = new QComboBox(dia);
2362 resiCom->addItem("");
2363 resiCom->addItems(rl);
2364 grid->addWidget(resi,2,0);
2365 grid->addWidget(resiCom,2,1);
2366 }
2367 // Set default value for esd
2368 esdline->setText("0.1");
2369
2370 grid->addWidget(esd,0,0);
2371 grid->addWidget(esdline,0,1);
2372
2373 QDialogButtonBox *buttonBox = new QDialogButtonBox();
2374
2375 QPushButton *OkButton;
2376 QPushButton *CancelButton;
2377
2378 OkButton = buttonBox->addButton(QDialogButtonBox::Ok);
2379 CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
2380
2381 buttonBox->setOrientation(Qt::Horizontal);
2382
2383 grid->addWidget(buttonBox,1,0);
2384
2385 dia->setLayout(grid);
2386 connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept()));
2387 connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject()));
2388
2389 dia->show();
2390 int a = dia->exec();
2391
2392 if(a == QDialog::Accepted)
2393 {
2394 // read value from value line
2395 QString s=(rl.isEmpty())?"":resiCom->currentText();
2396 emit insertFLAT(esdline->text().toDouble(),mol->selectedatoms,s);
2397 mol->selectedatoms.clear();
2398 }
2399 else
2400 {
2401 if(a == QDialog::Rejected)
2402 dia->close();
2403 }
2404
2405 }
2406
2407 void ChGL::addEXYZ(){
2408 emit insertEXYZ(mol->selectedatoms);
2409 mol->selectedatoms.clear();
2410 }
2411
2412 void ChGL::addEADP(){
2413 emit insertEADP(mol->selectedatoms);
2414 mol->selectedatoms.clear();
2415 }
2416
2417 void ChGL::addDELU(){
2418 QDialog *dia = new QDialog(this);
2419 dia->setWindowTitle(tr("DELU: ADP restraint"));
2420 dia->setModal(false);
2421
2422 QGridLayout *grid = new QGridLayout(dia);
2423 QLineEdit *esd1line = new QLineEdit(dia);
2424 QLineEdit *esd2line = new QLineEdit(dia);
2425 QLabel *esd1 = new QLabel("ESD1:", dia);
2426 QLabel *esd2 = new QLabel("ESD2:", dia);
2427 // Set default value for distance and esd
2428 esd1line->setText("0.01");
2429 esd2line->setText("0.01");
2430
2431 grid->addWidget(esd1,0,0);
2432 grid->addWidget(esd1line,0,1);
2433 grid->addWidget(esd2,1,0);
2434 grid->addWidget(esd2line,1,1);
2435 QStringList rl = resis();
2436 QComboBox *resiCom = NULL;
2437 if (!rl.isEmpty()){
2438 QLabel *resi = new QLabel("Residue specific",dia);
2439 resiCom = new QComboBox(dia);
2440 resiCom->addItem("");
2441 resiCom->addItems(rl);
2442 grid->addWidget(resi,3,0);
2443 grid->addWidget(resiCom,3,1);
2444 }
2445
2446 QDialogButtonBox *buttonBox = new QDialogButtonBox();
2447
2448 QPushButton *OkButton;
2449 QPushButton *CancelButton;
2450
2451 OkButton = buttonBox->addButton(QDialogButtonBox::Ok);
2452 CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
2453
2454 buttonBox->setOrientation(Qt::Horizontal);
2455
2456 grid->addWidget(buttonBox,4,0);
2457
2458 dia->setLayout(grid);
2459 connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept()));
2460 connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject()));
2461
2462 dia->show();
2463 int a = dia->exec();
2464
2465 if(a == QDialog::Accepted)
2466 {
2467 // read value from value line
2468 QString s=(rl.isEmpty())?"":resiCom->currentText();
2469 emit insertDELU(esd1line->text().toDouble(),esd2line->text().toDouble(),mol->selectedatoms,s);
2470 mol->selectedatoms.clear();
2471 }
2472 else
2473 {
2474 if(a == QDialog::Rejected)
2475 dia->close();
2476 }
2477 }
2478
2479 void ChGL::addSIMU(){
2480 QDialog *dia = new QDialog(this);
2481 dia->setWindowTitle(tr("SIMU: ADP restraint"));
2482 dia->setModal(false);
2483
2484 QGridLayout *grid = new QGridLayout(dia);
2485 QLineEdit *esd1line = new QLineEdit(dia);
2486 QLineEdit *esd2line = new QLineEdit(dia);
2487 QLineEdit *dmaxline = new QLineEdit(dia);
2488 QLabel *esd1 = new QLabel("ESD1:", dia);
2489 QLabel *esd2 = new QLabel("ESD2:", dia);
2490 QLabel *dmax = new QLabel("dmax:", dia);
2491 // Set default value for distance and esd
2492 esd1line->setText("0.04");
2493 esd2line->setText("0.08");
2494 dmaxline->setText("2.00");
2495
2496 grid->addWidget(esd1,0,0);
2497 grid->addWidget(esd1line,0,1);
2498 grid->addWidget(esd2,1,0);
2499 grid->addWidget(esd2line,1,1);
2500 grid->addWidget(dmax,2,0);
2501 grid->addWidget(dmaxline,2,1);
2502 QStringList rl = resis();
2503 QComboBox *resiCom = NULL;
2504 if (!rl.isEmpty()){
2505 QLabel *resi = new QLabel("Residue specific", dia);
2506 resiCom = new QComboBox(dia);
2507 // Usually you want to define residue restraints with numbers at the atom:
2508 resiCom->addItem("");
2509 resiCom->addItems(rl);
2510 grid->addWidget(resi,3,0);
2511 grid->addWidget(resiCom,3,1);
2512 }
2513
2514 QDialogButtonBox *buttonBox = new QDialogButtonBox();
2515
2516 QPushButton *OkButton;
2517 QPushButton *CancelButton;
2518
2519 OkButton = buttonBox->addButton(QDialogButtonBox::Ok);
2520 CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
2521
2522 buttonBox->setOrientation(Qt::Horizontal);
2523
2524 grid->addWidget(buttonBox,4,0);
2525
2526 dia->setLayout(grid);
2527 connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept()));
2528 connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject()));
2529
2530 dia->show();
2531 int a = dia->exec();
2532
2533 if(a == QDialog::Accepted)
2534 {
2535 // read value from value line
2536 QString s=(rl.isEmpty())?"":resiCom->currentText();
2537 emit insertSIMU(esd1line->text().toDouble(),esd2line->text().toDouble(),dmaxline->text().toDouble(),mol->selectedatoms,s);
2538 mol->selectedatoms.clear();
2539 }
2540 else
2541 {
2542 if(a == QDialog::Rejected)
2543 dia->close();
2544 }
2545
2546 }
2547
2548 void ChGL::addSADI() {
2549 //! Adds SADI restraints between the selected atom and all bonded atoms.
2550 QAction *action = qobject_cast<QAction *>(sender());
2551 int index=-1;
2552 if (action)
2553 index=action->data().toInt();
2554 else index=-1;
2555 if (index>mol->asymm.size()) index=-1;
2556 if (index!=-1) {
2557 emit insertSADI(index);
2558 }
2559 }
2560
2561 void ChGL::addISOR(){
2562 QDialog *dia = new QDialog(this);
2563 dia->setWindowTitle(tr("ISOR: ADP restraint"));
2564 dia->setModal(false);
2565
2566 QGridLayout *grid = new QGridLayout(dia);
2567 QLineEdit *esd1line = new QLineEdit(dia);
2568 QLineEdit *esd2line = new QLineEdit(dia);
2569 QLabel *esd1 = new QLabel("ESD1:", dia);
2570 QLabel *esd2 = new QLabel("ESD2:", dia);
2571 QStringList rl = resis();
2572 QComboBox *resiCom = NULL;
2573 if (!rl.isEmpty()){
2574 QLabel *resi = new QLabel("Residue specific",dia);
2575 resiCom = new QComboBox(dia);
2576 resiCom->addItem("");
2577 resiCom->addItems(rl);
2578 grid->addWidget(resi,3,0);
2579 grid->addWidget(resiCom,3,1);
2580 }
2581 // Set default values for s and st
2582 esd1line->setText("0.1");
2583 esd2line->setText("0.2");
2584
2585 grid->addWidget(esd1,0,0);
2586 grid->addWidget(esd1line,0,1);
2587 grid->addWidget(esd2,1,0);
2588 grid->addWidget(esd2line,1,1);
2589
2590 QDialogButtonBox *buttonBox = new QDialogButtonBox();
2591
2592 QPushButton *OkButton;
2593 QPushButton *CancelButton;
2594
2595 OkButton = buttonBox->addButton(QDialogButtonBox::Ok);
2596 CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
2597
2598 buttonBox->setOrientation(Qt::Horizontal);
2599
2600 grid->addWidget(buttonBox,4,0);
2601
2602 dia->setLayout(grid);
2603 connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept()));
2604 connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject()));
2605
2606 dia->show();
2607 int a = dia->exec();
2608
2609 if(a == QDialog::Accepted)
2610 {
2611 // read value from value line
2612 QString s=(rl.isEmpty())?"":resiCom->currentText();
2613 emit insertISOR(esd1line->text().toDouble(),esd2line->text().toDouble(),mol->selectedatoms,s);
2614 mol->selectedatoms.clear();
2615 }
2616 else
2617 {
2618 if(a == QDialog::Rejected)
2619 dia->close();
2620 }
2621 }
2622
2623 void ChGL::addRIGU(){
2624 QDialog *dia = new QDialog(this);
2625 dia->setWindowTitle(tr("RIGU: ADP restraint"));
2626 dia->setModal(false);
2627
2628 QGridLayout *grid = new QGridLayout(dia);
2629 QLineEdit *esd1line = new QLineEdit(dia);
2630 QLineEdit *esd2line = new QLineEdit(dia);
2631 QLabel *esd1 = new QLabel("ESD1:", dia);
2632 QLabel *esd2 = new QLabel("ESD2:", dia);
2633 // Set default value for distance and esd
2634 esd1line->setText("0.004");
2635 esd2line->setText("0.004");
2636 int i(0); // index for position of widgets in the container
2637 grid->addWidget(esd1,i,0);
2638 grid->addWidget(esd1line,i++,1);
2639 grid->addWidget(esd2,i,0);
2640 grid->addWidget(esd2line,i++,1);
2641 QStringList rl = resis();
2642 QComboBox *resiCom = NULL;
2643 if (!rl.isEmpty()){
2644 QLabel *resi = new QLabel("Residue specific",dia);
2645 resiCom = new QComboBox(dia);
2646 resiCom->addItem("");
2647 resiCom->addItems(rl);
2648 grid->addWidget(resi,i,0);
2649 grid->addWidget(resiCom,i++,1);
2650 }
2651
2652 QDialogButtonBox *buttonBox = new QDialogButtonBox();
2653
2654 QPushButton *OkButton;
2655 QPushButton *CancelButton;
2656
2657 OkButton = buttonBox->addButton(QDialogButtonBox::Ok);
2658 CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
2659
2660 buttonBox->setOrientation(Qt::Horizontal);
2661
2662 grid->addWidget(buttonBox,i,0);
2663
2664 dia->setLayout(grid);
2665 connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept()));
2666 connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject()));
2667
2668 dia->show();
2669 int a = dia->exec();
2670
2671 if(a == QDialog::Accepted)
2672 {
2673 // read value from value line
2674 QString s=(rl.isEmpty())?"":resiCom->currentText();
2675 emit insertRIGU(esd1line->text().toDouble(),esd2line->text().toDouble(),mol->selectedatoms,s);
2676 mol->selectedatoms.clear();
2677 }
2678 else
2679 {
2680 if(a == QDialog::Rejected)
2681 dia->close();
2682 }
2683 }
2684
2685 void ChGL::addCHIV(){
2686 QDialog *dia = new QDialog(this);
2687 dia->setWindowTitle(tr("CHIV: Geometrical restraint"));
2688 dia->setModal(false);
2689
2690 QGridLayout *grid = new QGridLayout(dia);
2691 QLineEdit *volline = new QLineEdit(dia);
2692 QLineEdit *esd1line = new QLineEdit(dia);
2693 QLabel *vol = new QLabel("Volume:", dia);
2694 QLabel *esd1 = new QLabel("ESD:", dia);
2695 // Set default value for distance and esd
2696 volline->setText("0.0");
2697 esd1line->setText("0.1");
2698 int i(0); // index for position of widgets in the container
2699 grid->addWidget(vol,i,0);
2700 grid->addWidget(volline,i++,1);
2701 grid->addWidget(esd1,i,0);
2702 grid->addWidget(esd1line,i++,1);
2703 QStringList rl = resis();
2704 QComboBox *resiCom = NULL;
2705 if (!rl.isEmpty()){
2706 QLabel *resi = new QLabel("Residue specific",dia);
2707 resiCom = new QComboBox(dia);
2708 resiCom->addItem("");
2709 resiCom->addItems(rl);
2710 grid->addWidget(resi,i,0);
2711 grid->addWidget(resiCom,i++,1);
2712 }
2713
2714 QDialogButtonBox *buttonBox = new QDialogButtonBox();
2715
2716 QPushButton *OkButton;
2717 QPushButton *CancelButton;
2718
2719 OkButton = buttonBox->addButton(QDialogButtonBox::Ok);
2720 CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
2721
2722 buttonBox->setOrientation(Qt::Horizontal);
2723
2724 grid->addWidget(buttonBox,i,0);
2725
2726 dia->setLayout(grid);
2727 connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept()));
2728 connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject()));
2729
2730 dia->show();
2731 int a = dia->exec();
2732
2733 if(a == QDialog::Accepted)
2734 {
2735 // read value from value line
2736 QString s=(rl.isEmpty())?"":resiCom->currentText();
2737 emit insertCHIV(volline->text().toDouble(),esd1line->text().toDouble(),mol->selectedatoms,s);
2738 mol->selectedatoms.clear();
2739 }
2740 else
2741 {
2742 if(a == QDialog::Rejected)
2743 dia->close();
2744 }
2745 }
2746
2747 void ChGL::addANIS()
2748 {
2749 emit insertANIS(mol->selectedatoms);
2750 mol->selectedatoms.clear();
2751 }
2752
2753
2754 void ChGL::parallel(){//!sets the stereo mode for parallel eye side by side stereo
2755 stereo_mode=2;
2756 minus=1;
2757 update();
2758 }
2759
2760 void ChGL::crosseye(){//!sets the stereo mode for crossed eye side by side stereo
2761 stereo_mode=3;
2762 minus=-1;
2763 update();
2764 }
2765
2766 void ChGL::anaglyphRedCyan(){//!sets the stereo mode for analglyph stereo Red and Cyan glasses.
2767 stereo_mode=4;
2768 minus=1;
2769 update();
2770 }
2771
2772 void ChGL::hardwareStereo(){//!sets the stereo mode for hardware or driver supported stereo mode
2773 if (format().stereo()){
2774 stereo_mode=5;
2775 minus=-1;
2776 update();
2777 }
2778 else {
2779 qDebug()<<"no stereo sorry!";
2780 emit no_hw_st();
2781 }
2782 }
2783
2784 void ChGL::nostereo(){//!turns the stereo mode off
2785 stereo_mode=0;
2786 update();
2787 }
2788
2789 void ChGL::clearEnvi(){
2790 /*! Clears ChGL.enviPositions, ChGL.enviKat. and ChGL.labs */
2791 enviPositions.clear();
2792 labs.clear();
2793 enviKat.clear();
2794 enviButt->setVisible(false);
2795 enviSelect->setVisible(false);
2796 rotCenter();
2797 }
2798
2799 void ChGL::selectEnvi(){
2800 mol->selectedatoms.clear();
2801 if (rotze>=0) {
2802 mol->selectedatoms.append(mol->showatoms[rotze]);
2803 mol->selectedatoms.last().style=rotze;
2804 }
2805 for (int i=0; i<mol->showatoms.size(); i++){
2806 for (int j=0; j< enviPositions.size(); j++){
2807 if (mol->showatoms.at(i).pos==enviPositions.at(j)) {
2808 mol->selectedatoms.append(mol->showatoms[i]);
2809 mol->selectedatoms.last().style=i;
2810 }
2811 }
2812 }
2813 updateBondActions();
2814 update();
2815
2816 }
2817
2818
2819 void ChGL::envi(){
2820 /*! Finds neighboring atoms around a ChGL.envirange the spezified atom and passes a html table via ChGL.bigmessage
2821 * Feeds ChGL.enviPositions, ChGL.labs and ChGL.enviKat.
2822 * sets the rotation center to the spezified atom.
2823 * */
2824 // printf("->-ENVI-<-\n");
2825 QAction *action = qobject_cast<QAction *>(sender());
2826 int index=0;
2827 if (action)
2828 index=action->data().toInt();
2829 else index=rotze;//return;
2830 if (index<0) return;
2831 if (index>=mol->asymm.size())return;
2832 mol->enviSDM(envirange);
2833 enviPositions.clear();
2834 enviKat.clear();
2835 labs.clear();
2836 QList<bool> covs;
2837 pause=true;
2838
2839 V3 ppc,ppf,p0;
2840 // int ssy=0;
2841 QString systr;
2842 QStringList bs;
2843 QString info;
2844 enviP0=mol->asymm.at(index).pos;
2845 info.append(QString("<hr><b>Environment of %1 </b><table border=\"0\" cellspacing=\"0\" cellpadding=\"5\">").arg(mol->asymm[index].Label));
2846 for (int i = 0; i < mol->envi_sdm.size(); i++){
2847 if ((mol->envi_sdm.at(i).a2==index)&&mol->envi_sdm.at(i).d<envirange) {
2848 if ((!mol->envi_sdm.at(i).covalent)&&(enviCova->isChecked())) continue;
2849 if ((mol->asymm[mol->envi_sdm.at(i).a1].an==-1)&&(enviNoQ->isChecked())) continue;
2850 ppf=mol->cell.symmops.at(mol->envi_sdm.at(i).sn) *
2851 mol->asymm[mol->envi_sdm.at(i).a1].frac +
2852 mol->cell.trans.at(mol->envi_sdm.at(i).sn) -//-
2853 mol->envi_sdm.at(i).floorD;
2854 mol->frac2kart(ppf,ppc);
2855 mol->frac2kart(mol->asymm[index].frac,p0);
2856 /*
2857 if (fabs(mol->envi_sdm.at(i).d-sqrt(Distance(p0,ppc)))>0.5){
2858 ppf=mol->cell.symmops.at(mol->envi_sdm.at(i).sn) *
2859 mol->asymm[mol->envi_sdm.at(i).a2].frac -
2860 mol->cell.trans.at(mol->envi_sdm.at(i).sn) -
2861 mol->envi_sdm.at(i).floorD;
2862 mol->frac2kart(ppf,ppc);
2863
2864 }// */
2865 enviPositions.append(ppc);
2866 covs.append(mol->envi_sdm.at(i).covalent);
2867 enviKat.append((mol->envi_sdm.at(i).covalent)?1:0);
2868 if((abs(mol->asymm[mol->envi_sdm.at(i).a1].an-7)<2)
2869 &&(abs(mol->asymm[mol->envi_sdm.at(i).a2].an-7)<2)
2870 &&(fabs(mol->envi_sdm.at(i).d-2.725)<0.275)){enviKat.last()=2;}
2871
2872 if((mol->asymm[mol->envi_sdm.at(i).a1].an==0)&&(abs(mol->asymm[mol->envi_sdm.at(i).a2].an-7)<2)&&(fabs(mol->envi_sdm.at(i).d-1.875)<0.275)){enviKat.last()=2;}
2873 if((mol->asymm[mol->envi_sdm.at(i).a2].an==0)&&(abs(mol->asymm[mol->envi_sdm.at(i).a1].an-7)<2)&&(fabs(mol->envi_sdm.at(i).d-1.875)<0.275)){enviKat.last()=2;}
2874 bool symm=((mol->envi_sdm.at(i).sn)||(!(mol->envi_sdm.at(i).floorD==V3(0,0,0))));
2875 if (symm) {
2876 QString sss=QString("%1_%2%3%4:%5,").arg(mol->envi_sdm.at(i).sn+1).arg(5-(int)mol->envi_sdm.at(i).floorD.x).arg(5-(int)mol->envi_sdm.at(i).floorD.y).arg(5-(int)mol->envi_sdm.at(i).floorD.z).arg(mol->asymm[mol->envi_sdm.at(i).a1].molindex);
2877 if (!bs.contains(sss)){
2878 bs.append(sss);
2879 }
2880
2881 systr=QString("%1%2").arg(QString::fromUtf8("»")).arg(bs.indexOf(sss)+1);
2882 labs.append(mol->asymm[ mol->envi_sdm.at(i).a1].Label+systr);
2883 }
2884 else labs.append(mol->asymm[ mol->envi_sdm.at(i).a1].Label);
2885 info.append(QString("<tr><th style=\"background:%6\" >%1%4</th><td style=\"background:%5\" >%7<font color=%3> %2&nbsp;&Aring;</font></b></td>")
2886 .arg(mol->asymm[ mol->envi_sdm.at(i).a1].Label)
2887 .arg(mol->envi_sdm.at(i).d,8,'f',3)
2888 .arg((mol->envi_sdm.at(i).covalent)?"green":"black")
2889 .arg(symm?systr:"").arg((labs.size()%2)?"#eeeeee":"white")
2890 .arg((labs.size()%2)?"#d4d4e4":"#efefff")
2891 .arg((mol->envi_sdm.at(i).covalent)?"<b>":""));
2892 for (int j=0; j<enviPositions.size()-1; j++){
2893 double w=
2894 mol->winkel(p0-enviPositions.at(j),
2895 p0-enviPositions.last());
2896 // printf("%s-%s-%s %g %g %g %g\n",labs.at(j).toStdString().c_str(),mol->asymm[index].Label.toStdString().c_str(),labs.last().toStdString().c_str(),w,enviPositions.at(j).x ,enviPositions.at(j).y,enviPositions.at(j).z);
2897 info.append(QString("<td style=\"background:%3\" align=right>%4<font color=%2> %1&deg;</font></b></td>")
2898 .arg(w,8,'f',2)
2899 .arg(((mol->envi_sdm.at(i).covalent)&&(covs.at(j)))?"green":"black")
2900 .arg(((j+1)%2)?(labs.size()%2)?"#d4d4d4":"#e4e4e4":(labs.size()%2)?"#eeeeee":"#ffffff")
2901 .arg(((mol->envi_sdm.at(i).covalent)&&(covs.at(j)))?"<b>":""));
2902
2903 }
2904 info.append("</tr>\n");
2905 }
2906 }
2907 info.append("<tr><td style=\"background:#efefff\"></td><td style=\"background:#efefff\"></td>");
2908 for (int j=0; j<enviPositions.size()-1; j++){
2909 info.append(QString("<th style=\"background:%2\">%1</th>").arg(labs.at(j)).arg(((j+1)%2)?"#d4d4e4":"#efefff"));
2910 }
2911 QString symml="";
2912 for (int j=0; j<bs.size(); j++){
2913 symml+=mol->symmcode2human(bs.at(j),j+1);
2914 }
2915 info.append(QString("</tr>\n</table>%1<hr>\n").arg(symml));
2916
2917 enviTextures.clear();
2918 QFont fnt=myFont;
2919 fnt.setPointSize(96);
2920 QFontMetrics mtr(myFont);
2921 for (int li=0; li<labs.size(); li++){
2922 QString label=labs.at(li);
2923 #if (QT_VERSION>=0x050000)
2924 int rcw=mtr.horizontalAdvance(label);
2925 QImage image(rcw+mtr.horizontalAdvance("Li"), mtr.height()+2,QImage::Format_ARGB32_Premultiplied);
2926 #else
2927 int rcw=mtr.width(label);
2928 QImage image(rcw+mtr.width("Li"), mtr.height()+2,QImage::Format_ARGB32_Premultiplied);
2929 #endif
2930 image.fill(0);
2931 QPainter p;
2932 p.begin(&image);
2933 p.setPen(QPen(Qt::white));
2934 p.setBackground(Qt::NoBrush);
2935 p.setFont(myFont);
2936 //p.drawRect( 1, 1, image.rect().width()-3, image.rect().height()-3 );
2937 p.drawText(5,image.rect().height()-3, label);
2938 p.end();//new QOpenGLTexture(image.mirrored())
2939 enviTextures.append(new QOpenGLTexture(image.convertToFormat(QImage::Format_Indexed8).mirrored()));
2940 }
2941 for (int j=0; j<enviPositions.size()-1; j++){
2942 QString label=QString::number(sqrt(Distance(enviP0,enviPositions.at(j))),'f',3);
2943 label.append("Ang");
2944 #if (QT_VERSION>=0x050000)
2945 int rcw=mtr.horizontalAdvance(label);
2946 #else
2947 int rcw=mtr.width(label);
2948 #endif
2949 QImage image(rcw+4, mtr.height()+4,QImage::Format_ARGB32_Premultiplied);
2950 image.fill(0);
2951 QPainter p;
2952 p.begin(&image);
2953 p.setPen(QPen(Qt::white));
2954 p.setBackground(Qt::NoBrush);
2955 p.setFont(myFont);
2956 p.drawText(0,image.rect().height()-10, label);
2957 //p.drawRect( 1, 1, image.rect().width()-3, image.rect().height()-3 );
2958 p.end();
2959 enviTextures.append(new QOpenGLTexture(image.convertToFormat(QImage::Format_Indexed8).mirrored()));
2960 }
2961 emit bigmessage(info);
2962
2963 enviButt->setVisible(true);
2964 enviSelect->setVisible(true);
2965 pause=false;
2966 setRotationCenter(index);
2967 // printf("--ENVI--\n");
2968 }
2969
2970 void ChGL::setDepthCueing(bool b){
2971 depthcueing=b;
2972 mol->mist=b;
2973 update();
2974
2975 }
2976
2977 void ChGL::paintGL(){
2978 //printf("%d pause%d\n",__LINE__,pause);
2979 frames_counter++;
2980 /*
2981 static QGLFunctions *glf= new QGLFunctions(context());
2982 printf ("!!! %p\n",glf);
2983 GLenum stat = glf->glCheckFramebufferStatus(GL_FRAMEBUFFER);
2984 printf("%x %x\n",stat, GL_FRAMEBUFFER_COMPLETE);
2985 if (stat!= GL_FRAMEBUFFER_COMPLETE) return;
2986 */
2987
2988 if (!moving->isActive()) mol->dratom=0;
2989 if (pause) return;
2990 GLenum err = GL_NO_ERROR;
2991 while((err = glGetError()) != GL_NO_ERROR)
2992 {
2993 printf("0paintGL %s err=%X\n",glError2String(err).toStdString().c_str(),err);
2994 //printf("%s\n",(char*)gluErrorString(err));
2995 }
2996 //if ((viewAngle>0.3)&&(orthoView)&&(mol->showatoms.size()>0)) setViewAngle((orthoView)?0.2:29.0);
2997 warLabel = drawLa;
2998 qglClearColor(backGroundColor);
2999 mol->fgc[0] = (GLfloat)backGroundColor.redF();
3000 mol->fgc[1] = (GLfloat)backGroundColor.greenF();
3001 mol->fgc[2] = (GLfloat)backGroundColor.blueF();
3002 mol->fgc[3] = 1.0f;
3003 glFogfv(GL_FOG_COLOR,mol->fgc);
3004 glViewport(0, 0, ww, wh);
3005 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3006 // printf("clear %d %d\n",ww,wh);
3007 glViewport(0, 0, ww, wh);
3008 glDisable(GL_STENCIL_TEST);
3009 glGetIntegerv(GL_VIEWPORT, vp);
3010 if (!stereo_mode){
3011 //printf("%d %d %d %d retina %d\n", vp[0], vp[1], vp[2], vp[3], retinafktr);
3012 glMatrixMode(GL_PROJECTION);
3013 glLoadIdentity();
3014 gluPerspective_( viewAngle, (double)ww/wh, 5.0, 8000.0 );
3015 glMatrixMode(GL_MODELVIEW);
3016 if (!pause) draw();
3017 }else
3018 /* if (stereo_mode==1){// stereo zalman
3019 GLint viewport[4];
3020 glGetIntegerv(GL_VIEWPORT,viewport);
3021
3022 glPushAttrib(GL_ENABLE_BIT);
3023 glMatrixMode(GL_PROJECTION);
3024 glLoadIdentity();
3025 glOrtho(0,viewport[2],0,viewport[3],-10.0,10.0);
3026 glMatrixMode(GL_MODELVIEW);
3027 glLoadIdentity();
3028 glTranslatef(0.33F,0.33F,0.0F);
3029 glDisable(GL_STENCIL_TEST);
3030 glDisable(GL_ALPHA_TEST);
3031 glDisable(GL_LIGHTING);
3032 glDisable(GL_FOG);
3033 glDisable(GL_NORMALIZE);
3034 glDisable(GL_DEPTH_TEST);
3035 glDisable(GL_COLOR_MATERIAL);
3036 glDisable(GL_LINE_SMOOTH);
3037 glDisable(GL_DITHER);
3038 glDisable(GL_BLEND);
3039 glShadeModel(GL_SMOOTH);
3040
3041 glClearStencil(0);
3042 glColorMask(false,false,false,false);
3043 glDepthMask(false);
3044 glClear(GL_STENCIL_BUFFER_BIT);
3045
3046 glEnable(GL_STENCIL_TEST);
3047 glStencilFunc(GL_ALWAYS, 1, 1);
3048 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
3049
3050 glLineWidth(1.0);
3051 glBegin(GL_LINES);
3052 int h = viewport[3], w=viewport[2];
3053 int y;
3054 for(y=0;y<h;y+=2) {
3055 glVertex2i(0,y);
3056 glVertex2i(w,y);
3057 }
3058 glEnd();
3059
3060 glColorMask(true,true,true,true);
3061 glDepthMask(true);
3062
3063 glMatrixMode(GL_MODELVIEW);
3064 glMatrixMode(GL_PROJECTION);
3065 //
3066 glPopAttrib();
3067
3068 glViewport(0, 0, ww, wh);
3069 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3070 glViewport(0, 0, ww, wh);
3071 glGetIntegerv(GL_VIEWPORT, vp);
3072 glMatrixMode(GL_PROJECTION);
3073 glLoadIdentity();
3074 gluPerspective_( viewAngle, (double)ww/wh, 5.0, 8000.0 );
3075 glMatrixMode(GL_MODELVIEW);
3076 drawLa=false;
3077 glRotateL(minus*-1.5,0,1,0);
3078 glEnable(GL_STENCIL_TEST);
3079 glStencilFunc(GL_EQUAL, 1, 1);
3080 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
3081 glEnable(GL_STENCIL_TEST);// * /
3082 if (!pause) draw();
3083
3084 drawLa= warLabel;
3085 glRotateL(minus*1.5,0,1,0);
3086 glEnable(GL_STENCIL_TEST);
3087 glStencilFunc(GL_EQUAL, 0, 1);
3088 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
3089 glEnable(GL_STENCIL_TEST);// * /
3090 if (!pause) draw();
3091 } else*/
3092 if ((stereo_mode>1)&&(stereo_mode<4)) { //stereo_side by side
3093 glViewport(0, 0, ww/2, wh);
3094 glMatrixMode(GL_PROJECTION);
3095 glLoadIdentity();
3096 gluPerspective_( viewAngle, (double)(ww/2.0)/wh, 5.0, 8000.0 );
3097 glMatrixMode(GL_MODELVIEW);
3098 glRotateL(1.5*minus,0,1,0);
3099 if (!pause) draw();
3100 glViewport( ww / 2 , 0,ww / 2,wh );
3101 glMatrixMode(GL_PROJECTION);
3102 glLoadIdentity();
3103 gluPerspective_( viewAngle, (double)(ww/2.0)/wh, 5.0, 8000.0 );
3104 glMatrixMode(GL_MODELVIEW);
3105 glRotateL(-1.5*minus,0,1,0);
3106 if (!pause) draw();
3107
3108 }
3109 else if (stereo_mode==4){//anaglyph red cyan
3110 glGetIntegerv(GL_VIEWPORT, vp);
3111 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3112 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
3113 glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
3114
3115 // set camera for blue eye, red will be filtered.
3116
3117 // draw scene
3118 glViewport(0, 0, ww, wh);
3119 glMatrixMode(GL_PROJECTION);
3120 glLoadIdentity();
3121 gluPerspective_( viewAngle, (double)ww/wh, 5.0, 8000.0 );
3122 glMatrixMode(GL_MODELVIEW);
3123 glRotateL(1.5*minus,0,1,0);
3124 if (!pause) draw();
3125
3126 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
3127 glClear(GL_DEPTH_BUFFER_BIT);
3128 glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
3129
3130 // set camera for red eye, blue will be filtered.
3131
3132 // draw scene
3133 glViewport(0, 0, ww, wh);
3134 glMatrixMode(GL_PROJECTION);
3135 glLoadIdentity();
3136 gluPerspective_( viewAngle, (double)ww/wh, 5.0, 8000.0 );
3137 glMatrixMode(GL_MODELVIEW);
3138 glRotateL(-1.5*minus,0,1,0);
3139 if (!pause) draw();
3140 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
3141
3142 }
3143 {
3144 GLenum err = GL_NO_ERROR;
3145 while((err = glGetError()) != GL_NO_ERROR){
3146 printf("paintGL %s err=%X\n",glError2String(err).toStdString().c_str(),err);
3147 }
3148 }
3149 //printf("%d pause%d\n",__LINE__,pause);
3150 //update();
3151 }
3152
3153 void ChGL::setViewAngle(double ang){
3154 /*! sets ChGL.viewAngele for the perspective view 0 is othogonal, 29 degrees is the perpective default.
3155 */
3156 if ((ang>0.001)&&(ang<160.0)){
3157 makeCurrent();
3158 //printf("View angle = %g degrees. %10.8f %f\n",ang,ang/viewAngle,viewAngle);
3159 glScaled(ang/viewAngle,ang/viewAngle,ang/viewAngle);
3160 viewAngle=ang;
3161 homeXY();
3162 }
3163 }
3164
3165 void ChGL::rehide(){//! Trys to hide previous hidden atoms.
3166 //printf("haa %d %d %g\n",hideReason,hiddenThings,qcutoff);
3167 if (!hiddenThings) return;
3168 if ((hideReason&HIDE_REASON_SELECT)&&(mol->selectedatoms.size())) {hideNonSelected(); return;}
3169 else if (hideReason&HIDE_REASON_SELECT) hideReason-=HIDE_REASON_SELECT;
3170 int gute=frid;
3171 for (int i=0;i<mol->showatoms.size();i++){
3172 if (hideReason&HIDE_REASON_QPEAK) if (mol->showatoms[i].an==-1) {if (qcutoff>0)
3173 mol->showatoms[i].hidden=((mol->showatoms[i].peakHeight>0)&&(mol->showatoms[i].peakHeight<qcutoff))?1:0;
3174 else mol->showatoms[i].hidden=((mol->showatoms[i].peakHeight<0)&&(mol->showatoms[i].peakHeight>qcutoff))?1:0;}
3175 if (hideReason&HIDE_REASON_HYDROGEN) mol->showatoms[i].hidden=
3176 (mol->showatoms.at(i).an==0)?1:mol->showatoms.at(i).hidden;
3177 if (hideReason&(HIDE_REASON_THIS_FRAGMENT|HIDE_REASON_OTHER_FRAGMENT)){
3178 if (mol->showatoms.at(i).an>=0){
3179 if (hideReason&HIDE_REASON_THIS_FRAGMENT) mol->showatoms[i].hidden=
3180 (mol->showatoms.at(i).molindex+withsymm*9999*mol->showatoms.at(i).symmGroup!=gute)?mol->showatoms.at(i).hidden:1;
3181 if (hideReason&HIDE_REASON_OTHER_FRAGMENT)mol->showatoms[i].hidden=
3182 (mol->showatoms.at(i).molindex+withsymm*9999*mol->showatoms.at(i).symmGroup!=gute)?1:mol->showatoms.at(i).hidden;
3183 }
3184 }
3185 }
3186
3187 }
3188
3189 void ChGL::hideNonSelected(){//! Hides all atoms that are not selected
3190 for (int i=0;i<mol->showatoms.size();i++) mol->showatoms[i].hidden=1;
3191 for(int i=0;i<mol->selectedatoms.size();i++){
3192 if (mol->selectedatoms.at(i).style < mol->showatoms.size())
3193 mol->showatoms[mol->selectedatoms.at(i).style].hidden=0;
3194 // std::cout<<mol->showatoms.at(mol->selectedatoms.at(i).style).Label.toStdString()<<std::endl;
3195 }
3196 hiddenThings=true;
3197 hideReason|=HIDE_REASON_SELECT;
3198 mol->selectedatoms.clear();
3199 murx=-__LINE__;
3200 updateBondActions();
3201 update();
3202 }
3203
3204 void ChGL::hideSelected(){//! Hides the selected atoms
3205 for(int i=0;i<mol->selectedatoms.size();i++){
3206 if (mol->selectedatoms.at(i).style < mol->showatoms.size())
3207 mol->showatoms[mol->selectedatoms.at(i).style].hidden=1;
3208 // std::cout<<mol->showatoms.at(mol->selectedatoms.at(i).style).Label.toStdString()<<std::endl;
3209 }
3210 hiddenThings=true;
3211 mol->selectedatoms.clear();
3212 murx=-__LINE__;
3213 updateBondActions();
3214 update();
3215 }
3216
3217 void ChGL::invertHidden(){//!< Toggle visibility of atoms etc
3218 if (!hiddenThings) return; // nothing is hidden => hide everything now? NO!
3219 for (int i=0;i<mol->legendAtoms.size();i++) mol->legendAtoms[i].hidden=1;
3220 QHash<int,bool> anExists;
3221 for (int i = 0; i < mol->showatoms.size(); i++){
3222 mol->showatoms[i].hidden = (mol->showatoms.at(i).hidden!=0)?0:1;
3223 if (!mol->showatoms.at(i).hidden) anExists[mol->showatoms.at(i).an]=true;
3224 }
3225 for (int i=0;i<mol->legendAtoms.size();i++) if (anExists.contains(mol->legendAtoms.at(i).an)) mol->legendAtoms[i].hidden=0;
3226 frid=-10;
3227 hideReason=0;
3228 mol->selectedatoms.clear();
3229 murx=__LINE__;
3230 updateBondActions();
3231 update();
3232 }
3233
3234 void ChGL::sdm(){
3235 if (mol->asymm.size()<=SDM_Limit)return;//sdm is done regularly if number is below so we do not have to do iot now.
3236 if (!(fuse->isVisible()||grow->isVisible ())){
3237 fuse->setVisible(true);
3238 grow->setVisible(false);
3239 }
3240 mol->showatoms.clear();
3241 mol->showbonds.clear();
3242 mol->showatoms.clear();
3243 mol->showbonds.clear();
3244 mol->selectedatoms.clear();
3245 for (int o=0; o<mol->asymm.size();o++)
3246 mol->showatoms.append(mol->asymm[o]);
3247 mol->packer(mol->sdmcompleter());
3248 mol->showbonds =
3249 mol->connecting(mol->showatoms);
3250 mol->selectedatoms.clear();
3251 murx=__LINE__;
3252 bool growYes=fuse->isVisible ();
3253 mol->fuse();
3254 if (growYes) mol->grow();
3255 pause=false;
3256 // printf("%d\n",__LINE__);
3257 updateBondActions();
3258 update();
3259 }
3260
3261
3262 void ChGL::hideThisFragment(){//! Hides the specified molecular fragment.
3263 sdm();
3264 QAction *action = qobject_cast<QAction *>(sender());
3265 int index=0;
3266 if (action)
3267 index=action->data().toInt();
3268 else return;
3269 if (index>mol->showatoms.size()) return;
3270 int gute=mol->showatoms.at(index).molindex+9999*mol->showatoms.at(index).symmGroup;
3271 //int gute=mol->showatoms.at(index).molindex;
3272 for (int i=0;i<mol->showatoms.size();i++)
3273 if (mol->showatoms.at(i).an>=0)
3274 mol->showatoms[i].hidden=
3275 (mol->showatoms.at(i).molindex+9999*mol->showatoms.at(i).symmGroup!=gute)?mol->showatoms.at(i).hidden:1;
3276 //(mol->showatoms.at(i).molindex!=gute)?mol->showatoms.at(i).hidden:1;
3277 //
3278 frid=gute;
3279 hiddenThings=true;
3280 hideReason|=HIDE_REASON_THIS_FRAGMENT;
3281 mol->selectedatoms.clear();
3282 murx=-__LINE__;
3283 updateBondActions();
3284 update();
3285 }
3286
3287 void ChGL::selectThisFragment(){//! Selects the specified molecular fragment
3288 sdm();
3289 QAction *action = qobject_cast<QAction *>(sender());
3290 int index=0;
3291 if (action)
3292 index=action->data().toInt();
3293 else return;
3294 if (index>mol->showatoms.size()) return;
3295 mol->selectedatoms.clear();
3296 int gute=mol->showatoms.at(index).molindex+9999*mol->showatoms.at(index).symmGroup;
3297 //int gute=mol->showatoms.at(index).molindex;
3298 for (int i=0;i<mol->showatoms.size();i++)
3299 if (mol->showatoms.at(i).an>=0)
3300 if(mol->showatoms.at(i).molindex+9999*mol->showatoms.at(i).symmGroup==gute){
3301 mol->selectedatoms.append(mol->showatoms[i]);
3302 mol->selectedatoms.last().style=i;
3303 }
3304 //(mol->showatoms.at(i).molindex!=gute)?mol->showatoms.at(i).hidden:1;
3305 //
3306 updateBondActions();
3307 update();
3308 }
3309
3310 void ChGL::hideHydrogens(){//! Hides all Hydrogran atoms
3311 for (int i=0;i<mol->showatoms.size();i++) mol->showatoms[i].hidden=
3312 (mol->showatoms.at(i).an==0)?1:mol->showatoms.at(i).hidden;
3313 for (int i=0;i<mol->legendAtoms.size();i++) mol->legendAtoms[i].hidden=
3314 (mol->legendAtoms.at(i).an==0)?1:mol->legendAtoms.at(i).hidden;
3315 hiddenThings=true;
3316 hideReason|=HIDE_REASON_HYDROGEN;
3317 hideh->setVisible(false);
3318 mol->selectedatoms.clear();
3319 murx=-__LINE__;
3320 updateBondActions();
3321 update();
3322 }
3323
3324 void ChGL::wuff(){
3325 bool beloff=hideBeLo->isChecked();
3326 for (int i=0;i<mol->showatoms.size();i++) if (mol->showatoms.at(i).an==-42) mol->showatoms[i].hidden=(beloff)?0:1;
3327 for (int i=0;i<mol->legendAtoms.size();i++) if (mol->legendAtoms.at(i).an==-42) mol->legendAtoms[i].hidden=(beloff)?0:1;
3328 hiddenThings=hiddenThings||(!hideBeLo->isChecked());
3329 hideReason|=HIDE_REASON_BELO;
3330 // hideh->setVisible(false);
3331 mol->selectedatoms.clear();
3332 murx=-__LINE__;
3333 updateBondActions();
3334 update();
3335
3336 }
3337
3338 void ChGL::farbverlauf(double wrt, double min, double max){
3339 if (min>=max) max=min+0.001;
3340 double rot,gruen,blau,alpha;
3341 int lauf=0;
3342 const float farbe[6][4]={{1.0f,0.0f,0.0f,1.0f},
3343 {1.0f,1.0f,0.0f,1.0f},
3344 {0.0f,1.0f,0.0f,1.0f},
3345 {0.0f,1.0f,1.0f,1.0f},
3346 {0.0f,0.0f,1.0f,1.0f},
3347 {1.0f,0.0f,1.0f,1.0f}};
3348 double nwrt=(wrt-min)/(max-min);
3349 nwrt=(nwrt>=1.0)?0.99999:nwrt;
3350 nwrt=(nwrt<=0.0)?0.00001:nwrt;
3351 lauf=(int (nwrt/0.2));
3352 nwrt-=(0.2*lauf);
3353 nwrt/=(0.2);
3354
3355 rot=(((1.0-nwrt)*farbe[lauf][0]+farbe[lauf+1][0]*nwrt));
3356 gruen=(((1.0-nwrt)*farbe[lauf][1]+farbe[lauf+1][1]*nwrt));
3357 blau=(((1.0-nwrt)*farbe[lauf][2]+farbe[lauf+1][2]*nwrt));
3358 alpha=1.0;
3359 glColor4d(rot,gruen,blau,alpha);
3360 }
3361
3362 QColor ChGL::farbverlaufQC(double wrt, double min, double max){
3363 if (min>=max) max=min+0.001;
3364 double rot,gruen,blau,alpha;
3365 int lauf=0;
3366 double farbe[6][4]={{1.0,0.0,0.0,1.0},
3367 {1.0,1.0,0.0,1.0},
3368 {0.0,1.0,0.0,1.0},
3369 {0.0,1.0,1.0,1.0},
3370 {0.0,0.0,1.0,1.0},
3371 {1.0,0.0,1.0,1.0}};
3372 double nwrt=(wrt-min)/(max-min);
3373 nwrt=(nwrt>=1.0)?0.99999:nwrt;
3374 nwrt=(nwrt<=0.0)?0.00001:nwrt;
3375 lauf=(int (nwrt/0.2));
3376 nwrt-=(0.2*lauf);
3377 nwrt/=(0.2);
3378
3379 rot=(((1.0-nwrt)*farbe[lauf][0]+farbe[lauf+1][0]*nwrt));
3380 gruen=(((1.0-nwrt)*farbe[lauf][1]+farbe[lauf+1][1]*nwrt));
3381 blau=(((1.0-nwrt)*farbe[lauf][2]+farbe[lauf+1][2]*nwrt));
3382 alpha=1.0;
3383 return QColor(static_cast<int>(255*rot),
3384 static_cast<int>(255*gruen),
3385 static_cast<int>(255*blau),
3386 static_cast<int>(255*alpha));
3387 }
3388
3389
3390 void ChGL::toogleWithSymmetry(bool b){
3391 withsymm=(b)?0:1;
3392 }
3393
3394 void ChGL::hideOtherFragments(){//! Hides all molecular fragments except from the specified one
3395 sdm();
3396 QAction *action = qobject_cast<QAction *>(sender());
3397 int index=0;
3398 if (action)
3399 index=action->data().toInt();
3400 else return;
3401 if (index==(int)((GLuint)-1))return;
3402 if (index>mol->showatoms.size()) return;
3403 int gute=mol->showatoms.at(index).molindex+withsymm*9999*mol->showatoms.at(index).symmGroup;
3404 //int gute=mol->showatoms.at(index).molindex;
3405 // printf("hide %d %d %d \n",withsymm,gute,mol->showatoms.at(index).molindex+9999*mol->showatoms.at(index).symmGroup);
3406 for (int i=0;i<mol->showatoms.size();i++)
3407 if (mol->showatoms.at(i).an>=0){
3408 mol->showatoms[i].hidden=
3409 // (mol->showatoms.at(i).molindex!=gute)?1:mol->showatoms.at(i).hidden;
3410 (mol->showatoms.at(i).molindex+withsymm*9999*mol->showatoms.at(i).symmGroup!=gute)?1:mol->showatoms.at(i).hidden;
3411 // printf("%d %d \n",mol->showatoms[i].hidden,mol->showatoms.at(i).molindex+withsymm*9999*mol->showatoms.at(i).symmGroup);
3412 }
3413 hiddenThings=true;
3414 frid=gute;
3415 hideReason|=HIDE_REASON_OTHER_FRAGMENT;
3416 mol->selectedatoms.clear();
3417 murx=-__LINE__;
3418 updateBondActions();
3419 update();
3420 }
3421
3422 void ChGL::highliteQPeak(double co){//! highligts the first Q-Peak with a lower or equal peak height than co. @param co cutoff value.
3423 imFokus=-1;
3424 //printf("co %f\n",co)
3425 for (int i=0;i<mol->showatoms.size();i++){
3426 if (mol->showatoms[i].an==-66) continue;
3427 if (mol->showatoms[i].an>=0) continue;
3428 if (mol->showatoms[i].hidden)continue;
3429 if (mol->showatoms[i].peakHeight<=co) {imFokus=i; break;}
3430 }
3431 update();
3432 }
3433
3434 void ChGL::hideQPeaksBelow(double cutoff){//!hides all Q-Peaks below the given cutoff value. @param cutoff The cutoff value.
3435 // qDebug()<<cutoff;
3436 int vor=0,nach=0;
3437 for (int i=0;i<mol->showatoms.size();i++){
3438 vor += mol->showatoms[i].hidden;
3439 if ((mol->showatoms[i].an == -1)&&(cutoff>0)) mol->showatoms[i].hidden = ((mol->showatoms[i].peakHeight>=0)&&(mol->showatoms[i].peakHeight<cutoff))?1:0;
3440 else if ((mol->showatoms[i].an ==-1)&&(cutoff<0)) mol->showatoms[i].hidden = ((mol->showatoms[i].peakHeight<=0)&&(mol->showatoms[i].peakHeight>cutoff))?1:0;
3441 // if (mol->showatoms[i].an < 0) printf("#%d %g %d\n",mol->showatoms[i].hidden,mol->showatoms[i].peakHeight,mol->showatoms[i].peakHeight<cutoff);
3442 // if (mol->showatoms[i].an == -66) mol->showatoms[i].hidden = 0;
3443 // if (mol->showatoms[i].an == -42) mol->showatoms[i].hidden = 0;
3444 // if (mol->showatoms[i].an < 0) printf("!%d %g %d\n",mol->showatoms[i].hidden,mol->showatoms[i].peakHeight,mol->showatoms[i].peakHeight<cutoff);
3445 nach += mol->showatoms[i].hidden;
3446 }
3447 for (int i=0;i<mol->legendAtoms.size();i++){
3448 if ((mol->legendAtoms[i].an == -1)&&(cutoff>0)) mol->legendAtoms[i].hidden = ((mol->legendAtoms[i].peakHeight>=0)&&(mol->legendAtoms[i].peakHeight<cutoff))?1:0;
3449 else if ((mol->legendAtoms[i].an ==-1)&&(cutoff<0)) mol->legendAtoms[i].hidden = ((mol->legendAtoms[i].peakHeight<=0)&&(mol->legendAtoms[i].peakHeight>cutoff))?1:0;
3450 // if (mol->legendAtoms[i].an == -66) mol->legendAtoms[i].hidden = 0;
3451 // if (mol->legendAtoms[i].an == -42) mol->legendAtoms[i].hidden = 0;
3452 }
3453 if (vor==nach) return;
3454 hiddenThings=true;
3455 hideReason|=HIDE_REASON_QPEAK;
3456 qcutoff=cutoff;
3457 mol->selectedatoms.clear();
3458 murx=-__LINE__;
3459 updateBondActions();
3460 update();
3461 }
3462
3463 void ChGL::showHidden(){//! shows all hidden objects.
3464 int h=0;
3465 for (int i=0;i<mol->showatoms.size();i++){
3466 mol->showatoms[i].hidden=0;
3467 if (mol->showatoms[i].an==0)h++;
3468 }
3469 for (int i=0;i<mol->legendAtoms.size();i++){
3470 mol->legendAtoms[i].hidden=0;
3471 if (mol->legendAtoms[i].an==0)h++;
3472 }
3473 if (h)
3474 hideh->setVisible(true);
3475 hiddenThings=false;
3476 hideBeLo->setChecked(true);//toggle state is OK this way
3477 wuff();
3478 hideReason=0;
3479 murx=-__LINE__;
3480 updateBondActions();
3481 update();
3482 }
3483
3484 void ChGL::hidePartMinusOne(bool off){//! toggles the visibility state of part -N ghost atoms @param off if true no ghosts are visible.
3485
3486 mol->nopm1=off;
3487 murx=-__LINE__;
3488 updateBondActions();
3489 update();
3490 }
3491
3492 void ChGL::setupTexture(){//!loads the texture images
3493 makeCurrent();
3494 pause=true;
3495 //printf("setupTexture() %p\n",mol->hbtex);
3496 if (mol->hbtex) mol->hbtex->destroy();
3497 //printf("2setupTexture() %d\n",mol->hbtex);
3498 mol->hbtex = new QOpenGLTexture(QImage(QString(theIconPath+"hbb.png")).mirrored());
3499 //mol->hbtex=bindTexture(QImage(QString(theIconPath+"hbb.png")),GL_TEXTURE_2D);
3500 mol->hbtex->bind();
3501 //printf("3setupTexture() %p\n",mol->hbtex);
3502 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
3503 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
3504 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
3505 glBindTexture(GL_TEXTURE_2D, 0);
3506 //printf("4setupTexture()\n");
3507 pause=false;
3508 }
3509
3510 void ChGL::homeXY(){//! Resets the molecule to rotate in the middle of the viewport.
3511 makeCurrent();
3512 glGetDoublev(GL_MODELVIEW_MATRIX,MM);
3513 MM[12]=MM[13]=0;
3514 glLoadMatrixd(MM);
3515 update();
3516 }
3517
3518 void ChGL::draw(){//! draws everything some times
3519 //printf("draw %d pause%d\n",__LINE__,pause);
3520 if (murx) {
3521 rehide();
3522 //printf("draw->murx %d %d \n",murx,mol->monoQrom);
3523 murx=0;
3524
3525 }
3526 makeCurrent();
3527 glCullFace(GL_BACK);
3528 glEnable(GL_DEPTH_TEST );
3529 QFontMetrics fmtr(myFont);
3530 nonAtomFont = myFont;
3531 nonAtomFont.setPointSize(qMax(((myFont.pointSize()*2)/3),7));
3532 QFontMetrics fmtr2(nonAtomFont);
3533 if (exporting) LabelZ.clear();
3534 const GLfloat OBJ_SPE[] = { 0.8f, 0.8f, 0.8f, 1.0f };
3535 const GLfloat OBJ_SHIN = 32.0f;
3536 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, OBJ_SPE );
3537 glEnable ( GL_COLOR_MATERIAL ) ;
3538 glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
3539 glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, OBJ_SHIN );
3540 V3 ori=V3(0,0,0);///rotation origin
3541 V3 sumse=V3(0,0,0);
3542 int zz=0;
3543 objCnt=0;
3544 if (mol->showatoms.size()){
3545 for (int i=0;i<mol->showatoms.size();i++){
3546 if (!mol->showatoms[i].hidden) objCnt++;
3547 if ((!mol->showatoms.at(i).hidden)) {//(mol->showatoms.at(i).an>-1)&&
3548 sumse+=mol->showatoms[i].pos;
3549 zz++;
3550 }
3551 }
3552
3553 if (zz) sumse*=1.0/zz;
3554 else {
3555 for (int i=0;i<mol->showatoms.size();i++){
3556 if (!mol->showatoms.at(i).hidden) {
3557 sumse+=mol->showatoms[i].pos;
3558 zz++;
3559 }
3560 }
3561 if (zz) sumse*=1.0/zz;
3562 }
3563 }
3564 //printf(" zz %d %d \n",zz,mol->showatoms.size());
3565 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)MM );
3566 double gmat[16];
3567 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)gmat );
3568 ori.x=gmat[0] * sumse.x + gmat[4] * sumse.y + gmat[8] * sumse.z;
3569 ori.y=gmat[1] * sumse.x + gmat[5] * sumse.y + gmat[9] * sumse.z;
3570 ori.z=gmat[2] * sumse.x + gmat[6] * sumse.y + gmat[10] * sumse.z;
3571 if (mol->showatoms.size()<=rotze){
3572 rotze=-1;
3573 rCenter->hide();
3574 }
3575 if (rotze>-1) {
3576 double gmat[16];
3577 sumse=mol->showatoms.at(rotze).pos;
3578 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)gmat );
3579 ori.x=gmat[0] * mol->showatoms.at(rotze).pos.x + gmat[4] * mol->showatoms.at(rotze).pos.y + gmat[8] * mol->showatoms.at(rotze).pos.z;
3580 ori.y=gmat[1] * mol->showatoms.at(rotze).pos.x + gmat[5] * mol->showatoms.at(rotze).pos.y + gmat[9] * mol->showatoms.at(rotze).pos.z;
3581 ori.z=gmat[2] * mol->showatoms.at(rotze).pos.x + gmat[6] * mol->showatoms.at(rotze).pos.y + gmat[10] * mol->showatoms.at(rotze).pos.z;
3582 }
3583 if (centerSelection->isChecked()){
3584 if (mol->selectedatoms.isEmpty()) {
3585 sumse=altemitte;//centerSelection->setChecked(false);
3586 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)gmat );
3587 ori.x=gmat[0] * sumse.x + gmat[4] * sumse.y + gmat[8] * sumse.z;
3588 ori.y=gmat[1] * sumse.x + gmat[5] * sumse.y + gmat[9] * sumse.z;
3589 ori.z=gmat[2] * sumse.x + gmat[6] * sumse.y + gmat[10] * sumse.z;
3590 }
3591 else {
3592 sumse=V3(0,0,0);
3593 for (int i=0;i<mol->selectedatoms.size();i++)
3594 sumse+=mol->selectedatoms[i].pos;
3595 sumse*=1.0/mol->selectedatoms.size();
3596 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)gmat );
3597 ori.x=gmat[0] * sumse.x + gmat[4] * sumse.y + gmat[8] * sumse.z;
3598 ori.y=gmat[1] * sumse.x + gmat[5] * sumse.y + gmat[9] * sumse.z;
3599 ori.z=gmat[2] * sumse.x + gmat[6] * sumse.y + gmat[10] * sumse.z;
3600
3601
3602 }
3603 }
3604 //glPushMatrix();
3605 double mat[16];
3606 glEnable(GL_BLEND);
3607 glEnable(GL_COLOR_MATERIAL);
3608 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mat );
3609 glLoadIdentity();
3610 glDisable( GL_LIGHTING );
3611 glDisable( GL_DEPTH_TEST );
3612 if ((bggradient)&&(!depthcueing)) {
3613 glMatrixMode(GL_PROJECTION);
3614 glLoadIdentity();
3615 gluPerspective_( 29, (double)ww/wh, 5.0, 8000.0 );
3616 glMatrixMode(GL_MODELVIEW);
3617 glBegin(GL_QUADS);
3618 double xx = ((double) ww / wh) * 2.0,
3619 yy = 1.77777777778;
3620 glColor4f(1.0f,1.0f,1.0f,0.5f);
3621 //glTexCoord2d(-1,-1);
3622 glVertex3d(-xx,-yy,-6.0);
3623 glColor4f(1.0f,1.0f,1.0f,0.5f);
3624 //glTexCoord2d(0,-1);
3625 glVertex3f( xx,-yy,-6.0);
3626 //glTexCoord2d(0,0);
3627 glColor4f(0.3f,0.3f,0.3f,0.7f);
3628 glVertex3d( xx, yy,-6.0);
3629 glColor4f(0.3f,0.3f,0.3f,0.7f);
3630 //glTexCoord2d(-1,0);
3631 glVertex3d(-xx, yy,-6.0);
3632 glEnd();
3633
3634 glMatrixMode(GL_PROJECTION);
3635 glLoadIdentity();
3636 gluPerspective_( viewAngle, (double)ww/wh, 5.0, 8000.0 );
3637 glMatrixMode(GL_MODELVIEW);
3638 }
3639 if (showPickRad){//visualize pickradius
3640 glMatrixMode(GL_PROJECTION);
3641 glLoadIdentity();
3642 glOrtho(0.0,ww,0.0,wh,-1.0,1.0);
3643 glMatrixMode(GL_MODELVIEW);
3644 double pr=sqrt(pickradius);
3645 double pr2=sqrt(0.5)*pr;
3646 glEnable(GL_LINE_STIPPLE);
3647 glEnable(GL_BLEND);
3648 glLineWidth(1.3f);
3649 glDisable(GL_LIGHTING);
3650 glLineStipple(1,21845);
3651 for (int ij=0; ij<mol->showatoms.size(); ij++){
3652 glBegin(GL_LINE_STRIP);
3653 qglColor(labelColor);
3654 glVertex3d(mol->showatoms.at(ij).screenX*retinafktr+pr, wh-1.0*(mol->showatoms.at(ij).screenY*retinafktr) , 0.0);
3655 glVertex3d(mol->showatoms.at(ij).screenX*retinafktr+pr2,wh-1.0*(mol->showatoms.at(ij).screenY*retinafktr+pr2) , 0.0);
3656 glVertex3d(mol->showatoms.at(ij).screenX*retinafktr, wh-1.0*(mol->showatoms.at(ij).screenY*retinafktr+pr), 0.0);
3657 glVertex3d(mol->showatoms.at(ij).screenX*retinafktr-pr2,wh-1.0*(mol->showatoms.at(ij).screenY*retinafktr+pr2), 0.0);
3658 glVertex3d(mol->showatoms.at(ij).screenX*retinafktr-pr, wh-1.0*(mol->showatoms.at(ij).screenY*retinafktr) , 0.0);
3659 glVertex3d(mol->showatoms.at(ij).screenX*retinafktr-pr2,wh-1.0*(mol->showatoms.at(ij).screenY*retinafktr-pr2) , 0.0);
3660 glVertex3d(mol->showatoms.at(ij).screenX*retinafktr, wh-1.0*(mol->showatoms.at(ij).screenY*retinafktr-pr), 0.0);
3661 glVertex3d(mol->showatoms.at(ij).screenX*retinafktr+pr2,wh-1.0*(mol->showatoms.at(ij).screenY*retinafktr-pr2), 0.0);
3662 glVertex3d(mol->showatoms.at(ij).screenX*retinafktr+pr, wh-1.0*(mol->showatoms.at(ij).screenY*retinafktr) , 0.0);
3663 glEnd();
3664 }
3665 glDisable(GL_LINE_STIPPLE);
3666 glDisable(GL_BLEND);
3667 glEnable(GL_LIGHTING);
3668 glMatrixMode(GL_PROJECTION);
3669 glLoadIdentity();
3670 gluPerspective_( viewAngle, (double)ww/wh, 5.0, 8000.0 );
3671 glMatrixMode(GL_MODELVIEW);
3672 showPickRad=false;
3673 }
3674 if (rectangle){
3675 glMatrixMode(GL_PROJECTION);
3676 glLoadIdentity();
3677 glOrtho(0.0,ww,0.0,wh,-1.0,1.0);
3678 glMatrixMode(GL_MODELVIEW);
3679
3680 glEnable(GL_LINE_STIPPLE);
3681 glEnable(GL_BLEND);
3682 glLineWidth(0.3f);
3683 glDisable(GL_LIGHTING);
3684 glLineStipple(3,21845);
3685 glBegin(GL_LINE_STRIP);
3686 qglColor(labelColor);
3687 glVertex3f(scrx0*retinafktr,(wh-scry0*retinafktr),0.0f);
3688 glVertex3f(scrx *retinafktr,(wh-scry0*retinafktr),0.0f);
3689 glVertex3f(scrx *retinafktr,(wh-scry *retinafktr),0.0f);
3690 glVertex3f(scrx0*retinafktr,(wh-scry *retinafktr),0.0f);
3691 glVertex3f(scrx0*retinafktr,(wh-scry0*retinafktr),0.0f);
3692 glEnd();
3693 glDisable(GL_LINE_STIPPLE);
3694 glDisable(GL_BLEND);
3695 glEnable(GL_LIGHTING);
3696 glMatrixMode(GL_PROJECTION);
3697 glLoadIdentity();
3698 gluPerspective_( viewAngle, (double)ww/wh, 5.0, 8000.0 );
3699 glMatrixMode(GL_MODELVIEW);
3700 }
3701 glEnable( GL_LIGHTING );
3702 glEnable( GL_DEPTH_TEST );
3703 if (depthcueing){
3704 glEnable(GL_FOG);
3705 }else{
3706 glDisable(GL_FOG);
3707 }
3708
3709 glLoadMatrixd(mat);
3710 //glPopMatrix();
3711
3712
3713 glPushMatrix();//1
3714 if ((!(sumse==V3(0,0,0)))&&(Distance(altemitte,sumse)>0.2)){
3715 //printf("neuemitte %f %f %f %f %f %f\n",sumse.x,sumse.y,sumse.z,altemitte.x,altemitte.y,altemitte.z);
3716 if(!(altemitte==V3(0,0,0))) emit neuemitte(altemitte);
3717 altemitte=sumse;
3718 }
3719 if (rotze==-76185){
3720 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)gmat );
3721 ori.x=gmat[0] * altcenter.x + gmat[4] * altcenter.y + gmat[8] * altcenter.z;
3722 ori.y=gmat[1] * altcenter.x + gmat[5] * altcenter.y + gmat[9] * altcenter.z;
3723 ori.z=gmat[2] * altcenter.x + gmat[6] * altcenter.y + gmat[10] * altcenter.z;
3724 }
3725 glTranslateL(-L*ori.x,-L*ori.y,-L*ori.z);
3726 //printf("ORI %f %f %f L=%f\n",-L*ori.x,-L*ori.y,-L*ori.z,L);
3727 glPushMatrix();//2
3728 {
3729 glScaled( L, L, L );
3730 if (!mol->splitLeftAtoms.isEmpty()){
3731 if (manualAx->isChecked()){
3732 qglColor(QColor("fuchsia"));
3733 glBegin(GL_LINES);
3734 V3 axo=V3(orgx->value(),orgy->value(),orgz->value());
3735 V3 axe=axo - Normalize(V3(axx->value(),axy->value(),axz->value()));
3736 glVertex3d(axo.x, axo.y, axo.z);
3737 glVertex3d(axe.x, axe.y, axe.z);
3738 glEnd();
3739 glPushMatrix();
3740 glTranslated(axe.x,axe.y,axe.z);
3741 mol->triacontaeder(0.05f);
3742 glPopMatrix();
3743 }
3744 mol->dratom=5;
3745 mol->intern=0;
3746 mol->adp=0;
3747 mol->dbond(mol->splitLbonds);
3748
3749 mol->dbond(mol->splitRbonds);
3750 mol->atoms(mol->splitLeftAtoms,mol->proba);
3751 mol->atoms(mol->splitRightAtoms,mol->proba);
3752
3753 mol->dratom=0;
3754 mol->intern=1;
3755 }
3756 if ((wireButt->isChecked())&&(moving->isActive())) {
3757 mol->dratom=5;
3758 mol->intern=0;
3759 mol->adp=(drawADP)?1:0;
3760 mol->dbond(mol->showbonds);
3761 mol->atoms(mol->showatoms,mol->proba);
3762 mol->lbond();
3763 }
3764 else {
3765 if (!apair.isEmpty()){
3766 mol->dbond(apair);
3767 }
3768 if (drawHb) {
3769 mol->tubes=(tubes&&!drawADP)?1:0;
3770 mol->adp=(drawADP)?1:0;
3771 mol->h_bonds2(mol->showbonds,mol->showatoms);
3772
3773 }
3774 // printf("qPeakBonds %d !%d\n",mol->lbonds.size(),mol->showatoms.size());
3775 if (qPeakBonds->isChecked())mol->lbond();//bonds
3776 if (drawAt) {
3777 mol->intern=1;
3778 mol->adp=(drawADP)?1:0;
3779 mol->tubes=(tubes&&!drawADP)?1:0;
3780 mol->atoms(mol->showatoms,mol->proba);
3781 /*if (drawADP&&(!mol->useShaders)) {
3782 mol->intern=0;
3783 mol->atoms(mol->showatoms,mol->proba);
3784 }*/
3785
3786 }
3787
3788 if (drawBo) {
3789 if (mol->bondColorStyle){
3790 qglColor(mol->bondColor);
3791 glDisable(GL_COLOR_MATERIAL);
3792 }
3793 mol->adp=(drawADP)?1:0;
3794 mol->tubes=(tubes)?1:0;
3795 glEnable(GL_CULL_FACE);
3796 glCullFace(GL_FRONT);
3797 mol->bonds(mol->showbonds);
3798 glDisable(GL_CULL_FACE);
3799 glCullFace(GL_BACK);
3800
3801 glEnable(GL_COLOR_MATERIAL);
3802 }
3803 }//wireButt
3804 }glPopMatrix();//2
3805
3806 if ((!habzutun)&&(!fVertexes[0].isEmpty()||!fVertexes[1].isEmpty())) {
3807 //printf("maps\n");
3808 double max;
3809 int Pers=0;
3810 if (niceTrans->isChecked()){
3811 double mm[16];
3812
3813 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mm );
3814 max= (fabs(mm[2])>fabs(mm[6]))?mm[2]:mm[6];
3815 max=(fabs(max)<fabs(mm[10]))?mm[10]:max;
3816 if ((max==mm[2])&&(max>0.0)) Pers=0; else
3817 if ((max==mm[2])&&(max<0.0)) Pers=1; else
3818 if ((max==mm[6])&&(max>0.0)) Pers=2; else
3819 if ((max==mm[6])&&(max<0.0)) Pers=3; else
3820 if ((max==mm[10])&&(max>0.0)) Pers=4; else
3821 if ((max==mm[10])&&(max<0.0)) Pers=5;
3822 /*
3823 printf("Perspective %d [0-5] \n%12.5f %8.5f %8.5f%s\n%12.5f %8.5f %8.5f%s\n%12.5f %8.5f %8.5f%s\n",Pers
3824 ,mm[ 0]
3825 ,mm[ 1]
3826 ,mm[ 2],(max==mm[2])?"<--":""
3827
3828 ,mm[ 4]
3829 ,mm[ 5]
3830 ,mm[ 6],(max==mm[6])?"<--":""
3831
3832 ,mm[ 8]
3833 ,mm[ 9]
3834 ,mm[10],(max==mm[10])?"<--":""
3835 );// */
3836 }else Pers=0;
3837 glDisable(GL_CULL_FACE);
3838 if (fillMap->isChecked()) glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
3839 else glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
3840 if (lighting->isChecked()) glEnable(GL_LIGHTING);
3841 else glDisable(GL_LIGHTING);
3842 glEnable(GL_BLEND);
3843 glLineWidth(linwidth);
3844
3845 glPushMatrix();//2
3846 glScaled( L, L, L);
3847 glEnableClientState(GL_VERTEX_ARRAY);
3848 glEnableClientState(GL_NORMAL_ARRAY);
3849 if (fofcact->isChecked()) {
3850 dipc.setAlphaF(lintrans);
3851 qglColor(dipc);
3852 glVertexPointer(3, GL_FLOAT, 0, fVertexes[0+4*Pers].data());
3853 glNormalPointer(GL_FLOAT, 0, fNormals[0+4*Pers].data());
3854 glDrawArrays(GL_TRIANGLES, 0, fVertexes[0+4*Pers].size()/3);
3855 dimc.setAlphaF(lintrans);
3856 qglColor(dimc);
3857 glVertexPointer(3, GL_FLOAT, 0, fVertexes[1+4*Pers].data());
3858 glNormalPointer(GL_FLOAT, 0, fNormals[1+4*Pers].data());
3859 glDrawArrays(GL_TRIANGLES, 0, fVertexes[1+4*Pers].size()/3);
3860 }
3861 if (foact->isChecked()) {
3862 fopc.setAlphaF(lintrans);
3863 qglColor(fopc);
3864 glVertexPointer(3, GL_FLOAT, 0, fVertexes[2+4*Pers].data());
3865 glNormalPointer(GL_FLOAT, 0, fNormals[2+4*Pers].data());
3866 glDrawArrays(GL_TRIANGLES, 0, fVertexes[2+4*Pers].size()/3);
3867 if (neutrons){
3868 fomc.setAlphaF(lintrans);
3869 qglColor(fomc);
3870 glVertexPointer(3, GL_FLOAT, 0, fVertexes[3+4*Pers].data());
3871 glNormalPointer(GL_FLOAT, 0, fNormals[3+4*Pers].data());
3872 glDrawArrays(GL_TRIANGLES, 0, fVertexes[3+4*Pers].size()/3);
3873 }
3874 }
3875 glDisableClientState(GL_VERTEX_ARRAY);
3876 glDisableClientState(GL_NORMAL_ARRAY);
3877 glPopMatrix();//2
3878
3879 glEnable(GL_LIGHTING);
3880 glDisable(GL_BLEND);
3881 glEnable(GL_CULL_FACE);
3882 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
3883 }
3884
3885 GLfloat lw;
3886 glGetFloatv(GL_LINE_WIDTH,&lw) ;
3887 if (!mol->selectedatoms.isEmpty()){
3888 glPushMatrix();{//2
3889 glLineWidth(2);
3890 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
3891 glScaled( L, L, L );
3892 mol->tubes=0;
3893 mol->intern=1;
3894 mol->adp=0;
3895 mol->dratom=1;
3896 glDisable(GL_DEPTH_TEST);
3897 glEnable(GL_DEPTH_TEST);
3898 mol->atoms(mol->selectedatoms);
3899 qglColor(labelColor);
3900 mol->dratom=0;
3901 mol->intern=1;
3902 mol->tubes=0;
3903 mol->adp=1;
3904 }glPopMatrix();//2
3905 }
3906 glLineWidth(lw);
3907 if (!mol->fitbonds.isEmpty()){
3908 glPushMatrix();{//2
3909 glLineWidth(1);
3910 glScaled( L, L, L );
3911 mol->tubes=0;
3912 mol->intern=1;
3913 mol->adp=0;
3914 mol->dratom=76;
3915 mol->atoms(mol->fitatoms);
3916 mol->dbond(mol->fitbonds,76);
3917 qglColor(labelColor);
3918 mol->dratom=0;
3919 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
3920 mol->intern=1;
3921 mol->tubes=0;
3922 mol->adp=1;
3923 }glPopMatrix();//2
3924 }
3925 glLineWidth(lw);
3926 if (highlightParts->isChecked()){//PART highlighter
3927 glPushMatrix();{//2
3928 glScaled( L, L, L );
3929 mol->tubes=(tubes&&!drawADP)?1:0;
3930 mol->intern=0;
3931 mol->adp=(drawADP)?1:0;
3932 mol->dratom=2;
3933 mol->atoms(mol->showatoms);
3934 qglColor(labelColor);
3935 }glPopMatrix();//2
3936 glPushMatrix();{//2
3937 glDisable(GL_CULL_FACE);
3938 glScaled( L, L, L );
3939 mol->bonds(mol->showbonds);
3940 glEnable(GL_CULL_FACE);
3941 }glPopMatrix();//2
3942 mol->dratom=0;
3943 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
3944 }
3945
3946
3947
3948
3949 if (mol->duplicateAtoms.size()){//Duplicate highlighter
3950 glPushMatrix();{//2
3951 glScaled( L, L, L );
3952 mol->tubes=(tubes&&!drawADP)?1:0;
3953 mol->intern=0;
3954 mol->adp=(drawADP)?1:0;
3955 mol->dratom=2;
3956 mol->atoms(mol->duplicateAtoms);
3957 }glPopMatrix();//2
3958 mol->dratom=0;
3959 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
3960 }
3961 if ((imFokus>-1)&&(!drawLa)&&(imFokus<mol->showatoms.size()))
3962 if (!warLabel){
3963 CEnvironment fokat;
3964 fokat.append(mol->showatoms.at(imFokus));
3965 glPushMatrix();{//2
3966 glScaled( L, L, L );
3967 mol->tubes=0;
3968 mol->intern=1;
3969 mol->adp=0;
3970 mol->dratom=3;
3971 mol->atoms(fokat);
3972 qglColor(labelColor);
3973 mol->dratom=0;
3974 glDisable(GL_DEPTH_TEST);
3975 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
3976 glEnable(GL_DEPTH_TEST);
3977 }glPopMatrix();//2
3978 ///
3979 {//if (useTextureLabels->isChecked()){
3980 glPushMatrix();//2
3981 glScaled(L,L,L);
3982 if (!mol->showatoms.isEmpty()){
3983 if (mol->showatoms.size()!=labelTextures.size()) updateLabelTextures();
3984 glDisable(GL_CULL_FACE);
3985 glDisable(GL_DEPTH_TEST);
3986
3987 glEnable(GL_BLEND);
3988 glEnable(GL_ALPHA_TEST);
3989
3990 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3991 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3992 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3993 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3994 glEnable(GL_TEXTURE_2D);
3995
3996 bool bigr=false;
3997 qglColor(labelColor);
3998 glPushMatrix();//3
3999 GLdouble mmm[16];
4000 //GLuint t=bindTexture(labelTextures.at(imFokus),GL_TEXTURE_2D);
4001 labelTextures.at(imFokus)->bind();
4002 double ratio=(double)labelTextures.at(imFokus)->width()/labelTextures.at(imFokus)->height();
4003 glTranslated(mol->showatoms.at(imFokus).pos.x,mol->showatoms.at(imFokus).pos.y,mol->showatoms.at(imFokus).pos.z);
4004 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mmm);
4005 double ddd = mmm[0] * (mmm[5] * mmm[10] - mmm[9] * mmm[6])
4006 - mmm[1] * (mmm[4] * mmm[10] - mmm[8] * mmm[6])
4007 + mmm[2] * (mmm[4] * mmm[9] - mmm[8] * mmm[5]);
4008 ddd=pow(ddd,1.0/3.0);
4009 ddd*=(mol->showatoms.at(imFokus).an>=0)?1.0:0.75;
4010 ddd*=(bigr)?1.2:1.0;
4011 mmm[0]=ddd*labScal*ratio;
4012 mmm[5]=ddd*labScal;
4013 mmm[10]=ddd*labScal;
4014 mmm[1]=mmm[2]=mmm[4]=mmm[6]=mmm[8]=mmm[9]=0.0;
4015 glLoadMatrixd(mmm);
4016 mol->billBoard();
4017 glPopMatrix();//3
4018 labelTextures.at(imFokus)->release();
4019 }
4020 glPopMatrix();//2
4021 }
4022 ///
4023
4024 }
4025
4026 if (enviPositions.size()){
4027 glPushMatrix();//2
4028 glDisable( GL_DEPTH_TEST );
4029 glEnable(GL_LINE_STIPPLE);
4030 glEnable(GL_BLEND);
4031 glLineWidth(2);
4032 glDisable(GL_LIGHTING);
4033 glLineStipple(3,21845);
4034
4035 glScaled( L, L, L );
4036 glBegin(GL_LINES);
4037 for (int k=0;k<enviPositions.size();k++){
4038 if ((enviNoQ->isChecked())&&(labs.at(k).startsWith('Q',Qt::CaseInsensitive))) continue;
4039 switch(enviKat.at(k)){
4040 case 1: qglColor(mol->enviBondColor);break;
4041 case 2: qglColor(mol->enviHBColor);break;
4042 default:
4043 qglColor(mol->enviDefaultColor);
4044 }
4045 //if ((Distance(enviP0,enviPositions.at(k)))<envirange*envirange)
4046 {
4047 glVertex3d(enviP0.x,enviP0.y,enviP0.z);
4048 glVertex3d(enviPositions.at(k).x,enviPositions.at(k).y,enviPositions.at(k).z);
4049 }
4050 }
4051 glEnd();
4052
4053 glDisable(GL_CULL_FACE);
4054 glDisable(GL_DEPTH_TEST);
4055
4056
4057 glEnable(GL_BLEND);
4058 glEnable(GL_ALPHA_TEST);
4059 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4060 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4061 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4062 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4063 glEnable(GL_TEXTURE_2D);
4064 for (int k=0;k<enviPositions.size();k++){
4065
4066 if ((enviNoQ->isChecked())&&(labs.at(k).startsWith('Q',Qt::CaseInsensitive))) continue;
4067 if ((k+labs.size()) >= enviTextures.size()) continue;
4068 switch(enviKat.at(k)){
4069 case 1: qglColor(mol->enviBondColor);break;
4070 case 2: qglColor(mol->enviHBColor);break;
4071 default:
4072 qglColor(mol->enviDefaultColor);
4073 }
4074 glPushMatrix();//3
4075 GLdouble mmm[16];
4076
4077 enviTextures.at(k+labs.size())->bind();
4078 double ratio=(double)enviTextures.at(k+labs.size())->width()/enviTextures.at(k+labs.size())->height();
4079 glTranslated((enviPositions.at(k).x+enviP0.x)/2.0,
4080 (enviPositions.at(k).y+enviP0.y)/2.0,
4081 (enviPositions.at(k).z+enviP0.z)/2.0);
4082 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mmm);
4083 double ddd = mmm[0] * (mmm[5] * mmm[10] - mmm[9] * mmm[6])
4084 - mmm[1] * (mmm[4] * mmm[10] - mmm[8] * mmm[6])
4085 + mmm[2] * (mmm[4] * mmm[9] - mmm[8] * mmm[5]);
4086 ddd=pow(ddd,1.0/3.0);
4087 mmm[0]=ddd*labScal*ratio;
4088 mmm[5]=ddd*labScal;
4089 mmm[10]=ddd*labScal;
4090 mmm[1]=mmm[2]=mmm[4]=mmm[6]=mmm[8]=mmm[9]=0.0;
4091 glLoadMatrixd(mmm);
4092 mol->billBoard();
4093 enviTextures.at(k+labs.size())->release();
4094 glPopMatrix();//3
4095 glPushMatrix();//3
4096 //t=bindTexture(enviTextures.at(k),GL_TEXTURE_2D);
4097 enviTextures.at(k)->bind();
4098 ratio=(double)enviTextures.at(k)->width()/enviTextures.at(k)->height();
4099 glTranslated(enviPositions.at(k).x,
4100 enviPositions.at(k).y,
4101 enviPositions.at(k).z);
4102 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mmm);
4103 ddd = mmm[0] * (mmm[5] * mmm[10] - mmm[9] * mmm[6])
4104 - mmm[1] * (mmm[4] * mmm[10] - mmm[8] * mmm[6])
4105 + mmm[2] * (mmm[4] * mmm[9] - mmm[8] * mmm[5]);
4106 ddd=pow(ddd,1.0/3.0);
4107 mmm[0]=ddd*labScal*ratio;
4108 mmm[5]=ddd*labScal;
4109 mmm[10]=ddd*labScal;
4110 mmm[1]=mmm[2]=mmm[4]=mmm[6]=mmm[8]=mmm[9]=0.0;
4111 glLoadMatrixd(mmm);
4112 mol->billBoard();
4113 glPopMatrix();//3
4114 enviTextures.at(k)->release();
4115 }
4116 glDisable(GL_LINE_STIPPLE);
4117 glEnable(GL_LIGHTING);
4118 glEnable( GL_DEPTH_TEST );
4119 glPopMatrix();//2
4120 }
4121 glLineWidth(lw);
4122 if (drawUc) {
4123 glPushMatrix();//2
4124 glScaled( L, L, L );
4125 mol->unitCell();
4126 glPopMatrix();//2
4127 }
4128 if ((drawLa)){//(useTextureLabels->isChecked())&&
4129 glPushMatrix();//2
4130 glScaled(L,L,L);
4131 if (!mol->showatoms.isEmpty()){
4132 if (mol->showatoms.size()!=labelTextures.size()) {
4133 updateLabelTextures();
4134 //printf("called from 4081\n");
4135 }
4136 glDisable(GL_CULL_FACE);
4137 glDisable(GL_DEPTH_TEST);
4138
4139
4140 glEnable(GL_BLEND);
4141 glEnable(GL_ALPHA_TEST);
4142
4143 //glBindTexture(GL_TEXTURE_2D, t);
4144 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4145 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4146 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4147 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4148 glEnable(GL_TEXTURE_2D);
4149 for (int li=0; li<mol->showatoms.size();li++){
4150 if (mol->showatoms.at(li).hidden) continue;
4151 if ((mol->noQPeaksPlease)&&(mol->showatoms.at(li).an<0))continue;
4152 if ((mol->nopm1)&&(mol->showatoms.at(li).symmGroup)&&(mol->showatoms.at(li).part<-0)) continue;
4153 if ((mol->AtomStyle[mol->showatoms.at(li).an]&ATOM_STYLE_NOLABEL)&&(imFokus!=li)) continue;
4154 if ((!mol->beloLabels)&&(mol->showatoms.at(li).an==-42)) continue;
4155 bool bigr=false;
4156 bool sel=false;
4157 qglColor(labelColor);
4158 for (int si=0; si<mol->selectedatoms.size(); si++){
4159 if (li==mol->selectedatoms.at(si).style) {qglColor(QColor("#3388FF"));bigr=true;sel=true;}
4160 }
4161 for (int di=0; di<mol->duplicateAtoms.size(); di++){
4162 //printf("style %d\n",mol->duplicateAtoms.at(di).style,li);
4163 if (li==mol->duplicateAtoms.at(di).style) {qglColor((sel)?QColor("#ff99a9"):QColor("#ff00ff"));bigr=true;}
4164 }
4165 if (imFokus==li) {bigr=true;qglColor(QColor("#FF9900"));}
4166 //renderText(mol->showatoms.at(li).screenX, mol->showatoms.at(li).screenY, mol->showatoms.at(li).Label, mol->showatoms.at(li).an);
4167 glPushMatrix();//3
4168 GLdouble mmm[16];
4169 labelTextures.at(li)->bind();
4170 //GLuint t=bindTexture(labelTextures.at(li),GL_TEXTURE_2D);
4171 double ratio=(double)labelTextures.at(li)->width()/labelTextures.at(li)->height();
4172 glTranslated(mol->showatoms.at(li).pos.x,mol->showatoms.at(li).pos.y,mol->showatoms.at(li).pos.z);
4173 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mmm);
4174 double ddd = mmm[0] * (mmm[5] * mmm[10] - mmm[9] * mmm[6])
4175 - mmm[1] * (mmm[4] * mmm[10] - mmm[8] * mmm[6])
4176 + mmm[2] * (mmm[4] * mmm[9] - mmm[8] * mmm[5]);
4177 ddd=pow(ddd,1.0/3.0);
4178 ddd*=(mol->showatoms.at(li).an>=0)?1.0:0.75;
4179 ddd*=(bigr)?1.2:1.0;
4180 mmm[0]=ddd*labScal*ratio;
4181 mmm[5]=ddd*labScal;
4182 mmm[10]=ddd*labScal;
4183 mmm[1]=mmm[2]=mmm[4]=mmm[6]=mmm[8]=mmm[9]=0.0;
4184 glLoadMatrixd(mmm);
4185 mol->billBoard();
4186 glPopMatrix();//3
4187 labelTextures.at(li)->release();
4188 //deleteTexture(t);
4189 }
4190 if (drawUc){
4191 V3 uz0f,uz1f,uz2f,uz3f;
4192 V3 uz0k,uz1k,uz2k,uz3k;
4193 uz0f.x=0.0; uz0f.y=0.0; uz0f.z=0.0;
4194 uz1f.x=1.0; uz1f.y=0.0; uz1f.z=0.0;
4195 uz2f.x=0.0; uz2f.y=1.0; uz2f.z=0.0;
4196 uz3f.x=0.0; uz3f.y=0.0; uz3f.z=1.0;
4197 mol->frac2kart(uz0f,uz0k);
4198 mol->frac2kart(uz1f,uz1k);
4199 mol->frac2kart(uz2f,uz2k);
4200 mol->frac2kart(uz3f,uz3k);
4201 for (int li=0; li<4; li++){
4202 glPushMatrix();//3
4203 GLdouble mmm[16];
4204 extraTextures.at(li)->bind();
4205 //GLuint t=bindTexture(extraTextures.at(li),GL_TEXTURE_2D);
4206 double ratio=(double)extraTextures.at(li)->width()/extraTextures.at(li)->height();
4207 switch (li){
4208 case 0:
4209 qglColor(labelColor);
4210 glTranslated(uz0k.x,uz0k.y,uz0k.z);
4211 break;
4212 case 1:
4213 glColor4f(1.0f,0.0f,0.0f,1.0);
4214 glTranslated(uz1k.x,uz1k.y,uz1k.z);
4215 break;
4216 case 2:
4217 glColor4f(0.0f,1.0f,0.0f,1.0);
4218 glTranslated(uz2k.x,uz2k.y,uz2k.z);
4219 break;
4220 case 3:
4221 glColor4f(0.0f,0.0f,1.0f,1.0);
4222 glTranslated(uz3k.x,uz3k.y,uz3k.z);
4223 break;
4224 }
4225 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mmm);
4226 double ddd = mmm[0] * (mmm[5] * mmm[10] - mmm[9] * mmm[6])
4227 - mmm[1] * (mmm[4] * mmm[10] - mmm[8] * mmm[6])
4228 + mmm[2] * (mmm[4] * mmm[9] - mmm[8] * mmm[5]);
4229 ddd=pow(ddd,1.0/3.0);
4230 mmm[0]=ddd*labScal*ratio;
4231 mmm[5]=ddd*labScal;
4232 mmm[10]=ddd*labScal;
4233 mmm[1]=mmm[2]=mmm[4]=mmm[6]=mmm[8]=mmm[9]=0.0;
4234 glLoadMatrixd(mmm);
4235 mol->billBoard();
4236 glPopMatrix();//3
4237 extraTextures.at(li)->release();
4238 }
4239 }/*else {
4240 V3 uz0f,uz1f,uz2f,uz3f;
4241 V3 uz0k,uz1k,uz2k,uz3k;
4242 uz0f.x=0.0; uz0f.y=0.0; uz0f.z=0.0;
4243 uz1f.x=1.0; uz1f.y=0.0; uz1f.z=0.0;
4244 uz2f.x=0.0; uz2f.y=1.0; uz2f.z=0.0;
4245 uz3f.x=0.0; uz3f.y=0.0; uz3f.z=1.0;
4246 mol->frac2kart(uz0f,uz0k);
4247 mol->frac2kart(uz1f,uz1k);
4248 mol->frac2kart(uz2f,uz2k);
4249 mol->frac2kart(uz3f,uz3k);
4250 renderText(uz0k.x,uz0k.y,uz0k.z,"0");
4251 renderText(uz1k.x,uz1k.y,uz1k.z,"a");
4252 renderText(uz2k.x,uz2k.y,uz2k.z,"b");
4253 renderText(uz3k.x,uz3k.y,uz3k.z,"c");
4254 }*/
4255 glDisable(GL_TEXTURE_2D);
4256 glEnable(GL_BLEND);
4257 glDisable(GL_ALPHA_TEST);
4258 glEnable(GL_DEPTH_TEST);
4259 }
4260 glPopMatrix();//2
4261 }
4262 {
4263 glPushMatrix();//2
4264 glScaled(L,L,L);{
4265 GLdouble model[16];
4266 GLdouble proj[16];
4267 GLint viewport[4];
4268 glGetIntegerv(GL_VIEWPORT, viewport);
4269 glGetDoublev( GL_PROJECTION_MATRIX , (double*)proj );
4270 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)model );
4271 for (int j=0;j<mol->showatoms.size();j++){
4272 {mol->showatoms[j].screenX=-200; mol->showatoms[j].screenY=-200;}
4273 if (mol->showatoms.at(j).hidden) continue;
4274 //{1.0,0.0,-1.0,-190},
4275 GLdouble in[4], out[4];
4276
4277 in[0] = mol->showatoms.at(j).pos.x;
4278 in[1] = mol->showatoms.at(j).pos.y;
4279 in[2] = mol->showatoms.at(j).pos.z;
4280 in[3] = 1.0;
4281 transform_point(out, model, in);
4282
4283 if ((mol->nopm1)&&(mol->showatoms.at(j).symmGroup)&&(mol->showatoms.at(j).part<-0)) continue;
4284 if (!posTo2D(mol->showatoms.at(j).pos,model,proj,viewport, &mol->showatoms[j].screenX, &mol->showatoms[j].screenY,retinafktr))
4285 {mol->showatoms[j].screenX=-200; mol->showatoms[j].screenY=-200;}
4286 }
4287 }
4288 glPopMatrix();//2
4289 }
4290 // */
4291 glPopMatrix();//1
4292
4293 V3 auge=V3(0,0,206);
4294 if (mol->vorobas){
4295 glPushMatrix();//1
4296 glDisable(GL_CULL_FACE);
4297 glEnable(GL_DEPTH_TEST);
4298 glEnable(GL_BLEND);
4299 glEnable(GL_ALPHA_TEST);
4300
4301 glEnable( GL_LIGHTING );
4302 glTranslateL(-L*ori.x,-L*ori.y,-L*ori.z);
4303 glScaled( L, L, L );
4304
4305 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)gmat );
4306 Matrix mvm=Matrix(gmat[0],gmat[1],gmat[2], gmat[4],gmat[5],gmat[6], gmat[8],gmat[9],gmat[10]);
4307 auge=mvm*auge;
4308 mol->drawVoronoi(auge);
4309 glPopMatrix();//1
4310 glLineWidth(linwidth);
4311 glDisable( GL_LIGHTING );
4312 }
4313 if (mol->ptriangles.size()||mol->axvecs.size()||mol->invvecs.size()){
4314 glPushMatrix();//1
4315 glDisable(GL_CULL_FACE);
4316 glEnable(GL_DEPTH_TEST);
4317 glEnable(GL_BLEND);
4318 glEnable(GL_ALPHA_TEST);
4319
4320 glEnable( GL_LIGHTING );
4321 glTranslateL(-L*ori.x,-L*ori.y,-L*ori.z);
4322 glScaled( L, L, L );
4323
4324 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)gmat );
4325 Matrix mvm=Matrix(gmat[0],gmat[1],gmat[2], gmat[4],gmat[5],gmat[6], gmat[8],gmat[9],gmat[10]);
4326 auge=mvm*auge;
4327 mol->drawAxses();
4328 mol->drawInversionCenters();
4329 mol->drawPlanes();
4330 glPopMatrix();//1
4331 glLineWidth(linwidth);
4332 glDisable( GL_LIGHTING );
4333 }
4334 if (!cont.isEmpty()){
4335 glPushMatrix();{//1
4336 glTranslateL(-L*ori.x,-L*ori.y,-L*ori.z);
4337 glScaled( L, L, L );
4338 glDisable( GL_LIGHTING );
4339 glEnable( GL_DEPTH_TEST );
4340 glLineWidth(2.5f);
4341
4342 glBegin(GL_LINES);
4343 for (int ci=0;ci<cont.size();ci++){
4344 if (contval.contains(ci)) {
4345 if (rainbowPlot->isChecked()) farbverlauf(contval.value(ci),contMin,contMax);
4346 else{
4347 if (contval.value(ci)>0.0001f) {
4348 glColor4d(0.0,0.0,1.0,1.0);
4349 } else if (contval.value(ci)<-0.0001f){
4350 glColor4d(1.0,0.0,0.0,1.0);
4351 } else {
4352 glColor4d(0.0,0.0,0.0,1.0);
4353 }
4354 }
4355 }
4356 glVertex3d(cont.at(ci).x,cont.at(ci).y,cont.at(ci).z);
4357 }
4358 glEnd();
4359 glEnable( GL_LIGHTING );
4360 //glEnable( GL_DEPTH_TEST );
4361 }glPopMatrix();//1
4362 glLineWidth(0.7f);
4363 }
4364
4365 if (atomLegend->isChecked()){
4366 glDisable(GL_FOG);
4367 mol->mist=false;
4368 for (int ali=0,alj=0; ali<mol->legendAtoms.size(); ali++){
4369 mol->legendAtoms[ali].pos.y=-6.8+alj*0.5;
4370 //printf("legend %f %f \n",mol->legendAtoms[ali].pos.x, mol->legendAtoms[ali].pos.y);
4371 if (mol->legendAtoms.at(ali).hidden) continue;
4372 alj++;
4373 }
4374 glPushMatrix();{//1
4375 GLsizei lw=415;
4376 GLsizei lh=950;
4377 glViewport(0, 0, lw, lh);
4378 double mat[16],mleg[16];
4379 glEnable(GL_BLEND);
4380 glEnable(GL_COLOR_MATERIAL);
4381 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mat );
4382 for (int i=0; i<16; i++) mleg[i]=mat[i];
4383 mleg[0]=mleg[5]=mleg[10]=1.0;
4384 mleg[1]=mleg[2]=mleg[4]=mleg[6]=mleg[8]=mleg[9]=0.0;
4385 mleg[12]=mleg[13]=0;
4386 glLoadMatrixd(mleg);
4387 glPushMatrix();{//2
4388 glMatrixMode(GL_PROJECTION);
4389 glLoadIdentity();
4390 gluPerspective_( .1, (double)lw/lh, 5.0, 8000.0 );
4391 glMatrixMode(GL_MODELVIEW);
4392 glPushMatrix();{//3
4393 glDisable( GL_DEPTH_TEST );
4394 glScaled(.025,.025,.025);
4395 mol->tubes=0;
4396 mol->dratom=0;
4397 mol->intern=1;
4398 mol->adp=(drawADP)?1:0;
4399 glEnable(GL_CULL_FACE);
4400 mol->atoms(mol->legendAtoms,50,0.5);
4401 if (true){
4402 double labScal_=0.35;
4403 if (mol->legendAtoms.size()+4!=extraTextures.size()) {
4404 updateLabelTextures();
4405 //printf("called from 4347\n");
4406 }
4407 glDisable(GL_CULL_FACE);
4408 glDisable(GL_DEPTH_TEST);
4409 glEnable(GL_BLEND);
4410 glEnable(GL_ALPHA_TEST);
4411 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4412 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4413 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
4414 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
4415 glEnable(GL_TEXTURE_2D);
4416 for (int li=0; li<mol->legendAtoms.size();li++){
4417 if (mol->legendAtoms.at(li).hidden) continue;
4418 if ((mol->legendAtoms.at(li).an==-1)&&(mol->noQPeaksPlease)) continue;
4419 qglColor(labelColor);
4420 glPushMatrix();{//4
4421 GLdouble mmm[16];
4422 extraTextures.at(li+4)->bind();
4423 //GLuint t=bindTexture(extraTextures.at(li+4),GL_TEXTURE_2D);
4424 double ratio=(double)extraTextures.at(li+4)->width()/extraTextures.at(li+4)->height();
4425 glTranslated(mol->legendAtoms.at(li).pos.x,mol->legendAtoms.at(li).pos.y-0.2,mol->legendAtoms.at(li).pos.z);
4426 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)mmm);
4427 double ddd = mmm[0] * (mmm[5] * mmm[10] - mmm[9] * mmm[6])
4428 - mmm[1] * (mmm[4] * mmm[10] - mmm[8] * mmm[6])
4429 + mmm[2] * (mmm[4] * mmm[9] - mmm[8] * mmm[5]);
4430 ddd=pow(ddd,1.0/3.0);
4431 ddd*=(mol->legendAtoms.at(li).an>=0)?1.0:0.75;
4432 mmm[0]= ddd * labScal_ * ratio;
4433 mmm[5]= ddd * labScal_;
4434 mmm[10]=ddd * labScal_;
4435 mmm[1]=mmm[2]=mmm[4]=mmm[6]=mmm[8]=mmm[9]=0.0;
4436 glLoadMatrixd(mmm);
4437 mol->billBoard();
4438 extraTextures.at(li+4)->release();
4439 glPopMatrix();}//4
4440 }
4441 glDisable(GL_TEXTURE_2D);
4442 glEnable(GL_BLEND);
4443 glDisable(GL_ALPHA_TEST);
4444 glEnable(GL_DEPTH_TEST);
4445
4446 }
4447 glPopMatrix();}//3
4448 glEnable( GL_DEPTH_TEST );
4449 glPopMatrix();}//2
4450 glMatrixMode(GL_PROJECTION);
4451 glLoadIdentity();
4452 gluPerspective_( viewAngle, (double)ww/wh, 5.0, 8000.0 );
4453 glMatrixMode(GL_MODELVIEW);
4454 glViewport(0, 0, ww, wh);
4455 glLoadMatrixd(mat);
4456 glPopMatrix();}//1
4457 }///*
4458 mol->mist=depthcueing;
4459 // */
4460 afok=imFokus;
4461 //printf("draw %d objs%d\n",__LINE__,objCnt);
4462 /*
4463 m_shader.bind();
4464 m_shader.setAttributeBuffer( "vertex", GL_FLOAT, 0, 4 );
4465 angleH = m_shader.uniformLocation( "angle");
4466 m_shader.setUniformValue(angleH, ang);
4467 colorH = m_shader.uniformLocation( "Color");
4468 m_shader.setUniformValue(colorH, QColor("teal"));
4469 m_shader.enableAttributeArray( "vertex" );
4470 ang+=0.1;
4471 m_shader.setUniformValue(angleH, ang);
4472 // Draw stuff
4473
4474 glDrawArrays( GL_POINTS, 0, 9 );
4475 m_shader.release();
4476 */
4477 }
4478
4479 void ChGL::qglColor(const QColor color) {
4480 glColor4d(color.redF(), color.greenF(), color.blueF(), color.alphaF());
4481 }
4482
4483 void ChGL::qglClearColor(const QColor clearColor) {
4484 glClearColor(clearColor.redF(), clearColor.greenF(), clearColor.blueF(), clearColor.alphaF());
4485 }
4486
4487
4488 void ChGL::project(double x, double y, double z, GLdouble &tx, GLdouble &ty){
4489 makeCurrent();
4490 GLdouble model[16];
4491 GLdouble proj[16];
4492 GLint viewport[4];
4493 glGetIntegerv(GL_VIEWPORT, viewport);
4494 glGetDoublev( GL_PROJECTION_MATRIX , (double*)proj );
4495 glGetDoublev( GL_MODELVIEW_MATRIX, (double*)model );
4496 V3 pos(x,y,z);
4497 posTo2D(pos, model, proj, viewport, &tx, &ty, retinafktr);
4498 }
4499
4500 void ChGL::renderText(double x, double y, double z, const QString &text){
4501 // Identify x and y locations to render text within widget
4502 GLdouble textPosX = 0.0, textPosY = 0.0;
4503 project(x, y, z, textPosX, textPosY);
4504 //printf("%f %f %f -> %f %f\n",x,y,z,textPosX,textPosY);
4505 // Render text
4506 QPainter painter(this);
4507 QFontMetrics mtr(myFont);
4508 QRect rc=mtr.boundingRect(text+"L");
4509 QImage image(rc.width(),rc.height(), QImage::Format_ARGB32_Premultiplied);
4510 image.fill(0);
4511 QPainter p;
4512 p.begin(&image);
4513 p.setPen(labelColor);
4514 p.setBackground(Qt::NoBrush);
4515 p.setFont(myFont);
4516 p.drawText(image.rect(), Qt::AlignCenter, text);
4517 p.end();
4518 painter.drawImage(textPosX, textPosY-rc.height(), image);
4519 painter.end();
4520 }
4521
4522 void ChGL::renderText(double x, double y, const QString &text, int an){
4523 // Identify x and y locations to render text within widget
4524
4525 //printf("%f %f %f -> %f %f\n",x,y,z,textPosX,textPosY);
4526 // Render text
4527 QPainter painter(this);
4528 QFontMetrics mtr((an<0)?nonAtomFont:myFont);
4529 QRect rc=mtr.boundingRect(text+"L");
4530 QImage image(rc.width(),rc.height(), QImage::Format_ARGB32_Premultiplied);
4531 image.fill(0);
4532 QPainter p;
4533 p.begin(&image);
4534 p.setPen(labelColor);
4535 p.setBackground(Qt::NoBrush);
4536 p.setFont(myFont);
4537 p.drawText(image.rect(), Qt::AlignCenter, text);
4538 p.end();
4539 painter.drawImage(x, y-rc.height(), image);
4540 painter.end();
4541 }
4542
4543
4544 bool ChGL::prepareShaderProgram(const QString& vertexShaderPath, const QString& geometryShaderPath, const QString& fragmentShaderPath){
4545 // First we load and compile the vertex shader...
4546
4547 bool result = m_shader.addShaderFromSourceFile( QOpenGLShader::Vertex, vertexShaderPath );
4548 if ( !result )
4549 qWarning() << m_shader.log();
4550
4551
4552 printf("maxGeometryOutputVertices() = %d\n",m_shader.maxGeometryOutputVertices());
4553 result = m_shader.addShaderFromSourceFile( QOpenGLShader::Geometry, geometryShaderPath );
4554 if ( !result )
4555 qWarning() << m_shader.log();
4556
4557
4558
4559 // ...now the fragment shader...
4560 result = m_shader.addShaderFromSourceFile( QOpenGLShader::Fragment, fragmentShaderPath );
4561 if ( !result )
4562 qWarning() << m_shader.log();
4563
4564 // ...and finally we link them to resolve any references.
4565 result = m_shader.link();
4566 if ( !result )
4567 qWarning() << "Could not link shader program:" << m_shader.log();
4568
4569 return result;
4570 }