| 1 | #include "opengltestwidget.h" |
| 2 | #include <QVBoxLayout> |
| 3 | #include <QHBoxLayout> |
| 4 | #include <QDoubleSpinBox> |
| 5 | #include <QSpinBox> |
| 6 | #include <QLineEdit> |
| 7 | #include <QComboBox> |
| 8 | #include <QDialogButtonBox> |
| 9 | #include <QPushButton> |
| 10 | #include <QToolButton> |
| 11 | #include <QApplication> |
| 12 | #include <QInputDialog> |
| 13 | #include <QThread> |
| 14 | |
| 15 | |
| 16 | /*void GLAPIENTRY |
| 17 | MessageCallback( GLenum source, |
| 18 | GLenum type, |
| 19 | GLuint id, |
| 20 | GLenum severity, |
| 21 | GLsizei length, |
| 22 | const GLchar* message, |
| 23 | const void* userParam ) |
| 24 | { |
| 25 | fprintf( stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", |
| 26 | ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ), |
| 27 | type, severity, message ); |
| 28 | } |
| 29 | */ |
| 30 | |
| 31 | OpenGLTestWidget::OpenGLTestWidget(Molecule *externMole, QList<QAction*> &acts, QWidget *parent) : QDialog(parent){ |
| 32 | setObjectName("OpenGLTestWidget\n"); |
| 33 | ogl = new PlayOpenGL(externMole); |
| 34 | |
| 35 | //connect(ogl, SIGNAL(initialized()),ogl, SLOT(orthor())); |
| 36 | vito = new QToolBar(this); |
| 37 | QHBoxLayout *hlt = new QHBoxLayout(); |
| 38 | QHBoxLayout *hlt0 = new QHBoxLayout(); |
| 39 | QHBoxLayout *hlt1 = new QHBoxLayout(); |
| 40 | QVBoxLayout *lt = new QVBoxLayout(); |
| 41 | printf("31 \n"); |
| 42 | #if defined (Q_OS_MAC) |
| 43 | container = QWidget::createWindowContainer(ogl); |
| 44 | container->setMinimumHeight(400); |
| 45 | hlt0->addWidget(container); |
| 46 | #else |
| 47 | hlt0->addWidget(ogl); |
| 48 | #endif |
| 49 | printf("35 \n"); |
| 50 | |
| 51 | qpv = new QPeakView(this); |
| 52 | qpv->setMinimumWidth(50); |
| 53 | qpv->setMin(externMole->pmin); |
| 54 | qpv->setMax(externMole->pmax); |
| 55 | |
| 56 | ogl->fVertexes.resize(28); |
| 57 | ogl->fNormals.resize(28); |
| 58 | printf("%s, %s\n", |
| 59 | QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation).toStdString().c_str(), |
| 60 | QStandardPaths::writableLocation(QStandardPaths::CacheLocation).toStdString().c_str()); |
| 61 | |
| 62 | printf("qpeak %f %f\n",externMole->pmin,externMole->pmax); |
| 63 | connect(qpv, SIGNAL(cutOffChanged(double)), ogl, SLOT(setQpeakCutoff(double))); |
| 64 | connect(qpv,SIGNAL(findQP(double)),ogl,SLOT(highliteQPeak(double))); |
| 65 | connect(ogl,SIGNAL(qpfoci(double)),qpv,SLOT(qpeaksInFocus(double))); |
| 66 | //setQpeakCutoff |
| 67 | hlt0->addWidget(qpv); |
| 68 | qpv->dark=false; |
| 69 | qpv->update(); |
| 70 | hlt0->setStretch(0,100); |
| 71 | lt->addLayout(hlt0); |
| 72 | fpslabel = new QLabel("label"); |
| 73 | messagelabel = new QLabel("label"); |
| 74 | //printf("44! %d\n", acts.size()); |
| 75 | /*{ |
| 76 | QAction *a =vito->addAction("=>"); |
| 77 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(rotY90())); |
| 78 | a =vito->addAction("|"); |
| 79 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(rotX90())); |
| 80 | a =vito->addAction("O"); |
| 81 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(along001())); |
| 82 | }// */ |
| 83 | { |
| 84 | QAction *a =vito->addAction("F6"); |
| 85 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(setBGGradient(bool))); |
| 86 | a->setShortcut(QKeySequence("F6")); |
| 87 | a->setCheckable(true); |
| 88 | a->setChecked(true); |
| 89 | } |
| 90 | int conectedActions=0; |
| 91 | for (int i = 0, j = 1; i< acts.size(); i++){ |
| 92 | QAction *a = acts.at(i); |
| 93 | if (a->text().isEmpty()) continue; |
| 94 | if (a->icon().isNull()) continue; |
| 95 | printf("viewActions%d %s\n", j, a->text().toStdString().c_str()); |
| 96 | vito->addAction(a); |
| 97 | if (0==a->text().compare("Toggle Atoms", Qt::CaseInsensitive)) { |
| 98 | ogl->setAtoms(a->isChecked()); |
| 99 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(setAtoms(bool))); |
| 100 | printf("conectedActions %d\n",++conectedActions); |
| 101 | } |
| 102 | else if (0==a->text().compare("Toggle Bonds", Qt::CaseInsensitive)) { |
| 103 | ogl->setBonds(a->isChecked()); |
| 104 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(setBonds(bool))); |
| 105 | printf("conectedActions %d\n",++conectedActions); |
| 106 | } |
| 107 | else if (0==a->text().compare("Toggle Labels", Qt::CaseInsensitive)) { |
| 108 | ogl->setLabels(a->isChecked()); |
| 109 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(setLabels(bool))); |
| 110 | printf("conectedActions %d\n",++conectedActions); |
| 111 | } |
| 112 | else if (0==a->text().compare("Toggle H-bonds", Qt::CaseInsensitive)) { |
| 113 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 114 | printf("conectedActions %d\n",++conectedActions); |
| 115 | ogl->h_bonds = a; |
| 116 | } |
| 117 | else if (0==a->text().compare("Toggle ADPs", Qt::CaseInsensitive)){ |
| 118 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 119 | printf("conectedActions %d\n",++conectedActions); |
| 120 | ogl->adp = a; |
| 121 | } |
| 122 | else if (0==a->text().compare("Toggle Unit Cell", Qt::CaseInsensitive)){ |
| 123 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 124 | printf("conectedActions %d\n",++conectedActions); |
| 125 | ogl->togUnit = a; |
| 126 | } |
| 127 | else if (0==a->text().compare("Ball-Stick", Qt::CaseInsensitive)){ |
| 128 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 129 | printf("conectedActions %d\n",++conectedActions); |
| 130 | ogl->ballStick = a; |
| 131 | } |
| 132 | else if (0==a->text().compare("Tubes", Qt::CaseInsensitive)){ |
| 133 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 134 | printf("conectedActions %d\n",++conectedActions); |
| 135 | ogl->tubes = a; |
| 136 | } |
| 137 | else if (0==a->text().compare("Ortho-projection", Qt::CaseInsensitive)){ |
| 138 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(toggleOrtho(bool))); |
| 139 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 140 | |
| 141 | printf("conectedActions %d\n",++conectedActions); |
| 142 | if (a->isChecked()) {ogl->isOrtho=true; ogl->viewAngle=0.01;} |
| 143 | else {ogl->isOrtho=false; ogl->viewAngle=29.0;} |
| 144 | ogl->toggleOrthoView = a; |
| 145 | } |
| 146 | else if (0==a->text().compare("Q-Peak-Bonds", Qt::CaseInsensitive)){ |
| 147 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 148 | printf("conectedActions %d\n",++conectedActions); |
| 149 | ogl->qPeakBonds = a; |
| 150 | } |
| 151 | else if (0==a->text().compare("Q-Peak-Legend", Qt::CaseInsensitive)){ |
| 152 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 153 | printf("conectedActions %d\n",++conectedActions); |
| 154 | ogl->QPeakLegend = a; |
| 155 | connect(a, SIGNAL(toggled(bool)), qpv, SLOT(setVisible(bool))); |
| 156 | qpv->setVisible(a->isChecked()); |
| 157 | } |
| 158 | else if (0==a->text().compare("Toggle BEDE and LONE Objects (IDEAL)", Qt::CaseInsensitive)){ |
| 159 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 160 | printf("conectedActions %d\n",++conectedActions); |
| 161 | ogl->hideBeLo = a; |
| 162 | } |
| 163 | else if (0==a->text().compare("Toggle Atom Legend", Qt::CaseInsensitive)){ |
| 164 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 165 | printf("conectedActions %d\n",++conectedActions); |
| 166 | ogl->atomLegend = a; |
| 167 | } |
| 168 | else if (0==a->text().compare("Hide Hydrogen Atoms", Qt::CaseInsensitive)){ |
| 169 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 170 | printf("conectedActions %d\n",++conectedActions); |
| 171 | ogl->hideHydrogen = a; |
| 172 | //"Hide Hydrogen atoms",ogl,SLOT(hideHydrogens())); |
| 173 | } |
| 174 | else if (0==a->text().compare("Show all hidden", Qt::CaseInsensitive)){ |
| 175 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 176 | printf("conectedActions %d\n",++conectedActions); |
| 177 | ogl->unhide = a; |
| 178 | // "Show all hidden",chgl,SLOT(showHidden())); |
| 179 | } |
| 180 | else if (0==a->text().compare("Hide PART -N ghost", Qt::CaseInsensitive)){ |
| 181 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 182 | printf("conectedActions %d\n",++conectedActions); |
| 183 | ogl->shpm1 = a; |
| 184 | } |
| 185 | else if (0==a->text().compare("Highlight PARTs", Qt::CaseInsensitive)){ |
| 186 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 187 | printf("conectedActions %d\n",++conectedActions); |
| 188 | ogl->highlightParts = a; |
| 189 | } |
| 190 | else if (0==a->text().compare("Center Selected Atoms", Qt::CaseInsensitive)){ |
| 191 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 192 | printf("conectedActions %d\n",++conectedActions); |
| 193 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(updateSceenAtoms())); |
| 194 | ogl->centerSelection = a; |
| 195 | // "Center selected atoms",chgl,SLOT(homeXY())); |
| 196 | } |
| 197 | /////sss |
| 198 | /// |
| 199 | else if (0==a->text().compare("Bind Selected Atoms", Qt::CaseInsensitive)){//,editor,SLOT(insertBind())); |
| 200 | ogl->addBond = a; |
| 201 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 202 | printf("conectedActions %d\n",++conectedActions); |
| 203 | } |
| 204 | else if (0==a->text().compare("Free selected atoms", Qt::CaseInsensitive)){//,editor,SLOT(insertFree())); |
| 205 | ogl->killBond = a; |
| 206 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 207 | printf("conectedActions %d\n",++conectedActions); |
| 208 | } |
| 209 | else if (0==a->text().compare("Deselect", Qt::CaseInsensitive)){//,chgl,SLOT(disSelection())); |
| 210 | ogl->clearSelection = a; |
| 211 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 212 | printf("conectedActions %d\n",++conectedActions); |
| 213 | } |
| 214 | else if (0==a->text().compare("Create centroid", Qt::CaseInsensitive)){//, this , SLOT(createCentroid())); |
| 215 | ogl->centroid = a; |
| 216 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 217 | printf("conectedActions %d\n",++conectedActions); |
| 218 | } |
| 219 | else if (0==a->text().compare("Create Contour Plot", Qt::CaseInsensitive)){//,this, SLOT(contourPlot())); |
| 220 | ogl->cntrPlot = a; |
| 221 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 222 | printf("conectedActions %d\n",++conectedActions); |
| 223 | } |
| 224 | else if (0==a->text().compare("Remove Contour Plot", Qt::CaseInsensitive)){//,this, SLOT(nocontourPlot())); |
| 225 | ogl->nocntrPlot = a; |
| 226 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 227 | printf("conectedActions %d\n",++conectedActions); |
| 228 | } |
| 229 | else if (0==a->text().compare("Invert selection", Qt::CaseInsensitive)){//,chgl,SLOT(invertSelection())); |
| 230 | ogl->invSelection = a; |
| 231 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 232 | printf("conectedActions %d\n",++conectedActions); |
| 233 | } |
| 234 | else if (0==a->text().compare("Hide other atoms", Qt::CaseInsensitive)){//,chgl,SLOT(hideNonSelected())); |
| 235 | ogl->hideNotSelection = a; |
| 236 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 237 | printf("conectedActions %d\n",++conectedActions); |
| 238 | } |
| 239 | else if (0==a->text().compare("Toggle visibility ", Qt::CaseInsensitive)){//,chgl,SLOT(invertHidden())); |
| 240 | ogl->invhide = a; |
| 241 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 242 | printf("conectedActions %d\n",++conectedActions); |
| 243 | } |
| 244 | else if (0==a->text().compare("Delete selected atoms", Qt::CaseInsensitive)){ |
| 245 | ogl->delSelAt = a; |
| 246 | connect(a, SIGNAL(triggered(bool)), ogl, SLOT(update())); |
| 247 | printf("conectedActions %d\n",++conectedActions); |
| 248 | } |
| 249 | j++; |
| 250 | } |
| 251 | if (ogl->QPeakLegend == nullptr) { |
| 252 | /*if (externMole->mynewnameis.startsWith("shelXle")){ |
| 253 | ogl->theIconPath=QString(":/xle-icons/"); |
| 254 | }else{ |
| 255 | ogl->theIconPath=QString(":/bicons/"); |
| 256 | }*/ |
| 257 | QAction *a = new QAction(QIcon(ogl->theIconPath+"qlegend.svg"),"Q-Peak-Legend"); |
| 258 | a->setCheckable(true); |
| 259 | a->setChecked(true); |
| 260 | vito->addAction(a); |
| 261 | connect(a, SIGNAL(toggled(bool)), ogl, SLOT(update())); |
| 262 | ogl->QPeakLegend = a; |
| 263 | connect(a, SIGNAL(toggled(bool)), qpv, SLOT(setVisible(bool))); |
| 264 | qpv->setVisible(a->isChecked()); |
| 265 | } |
| 266 | QCheckBox *autoupdate = new QCheckBox("meassure FPS"); |
| 267 | autoupdate->setChecked(false); |
| 268 | connect(autoupdate, &QCheckBox::stateChanged, ogl, &PlayOpenGL::toggleAutoUpdate); |
| 269 | |
| 270 | QDoubleSpinBox *bsdsp = new QDoubleSpinBox(); |
| 271 | bsdsp->setPrefix("bond strength = "); |
| 272 | bsdsp->setRange(0.01,0.3); |
| 273 | bsdsp->setSingleStep(0.01); |
| 274 | bsdsp->setValue(externMole->bondStrength); |
| 275 | #if (QT_VERSION >= 0x050f10) |
| 276 | connect(bsdsp, &QDoubleSpinBox::valueChanged, ogl, &PlayOpenGL::setBondStrength); |
| 277 | #else |
| 278 | connect(bsdsp, SIGNAL(valueChanged(double)), ogl, SLOT(setBondStrength(double))); |
| 279 | #endif |
| 280 | QSpinBox *lodsp = new QSpinBox(); |
| 281 | lodsp->setPrefix("LOD = "); |
| 282 | lodsp->setRange(2, 8); |
| 283 | lodsp->setValue(ogl->mol->LOD); |
| 284 | #if (QT_VERSION >= 0x050f10) |
| 285 | connect(lodsp, &QSpinBox::valueChanged, ogl, &PlayOpenGL::setLOD); |
| 286 | #else |
| 287 | connect(lodsp, SIGNAL(valueChanged(int)), ogl, SLOT(setLOD(int))); |
| 288 | #endif |
| 289 | ogl->rCenter = new QToolButton(); |
| 290 | ogl->rCenter->setText("Reset rotation center"); |
| 291 | connect(ogl->rCenter,SIGNAL(clicked()), ogl,SLOT( rotCenter())); |
| 292 | ogl->rCenter->hide(); |
| 293 | fov = new QDoubleSpinBox(); |
| 294 | fov->setPrefix("view angle ="); |
| 295 | fov->setRange(0.0,160); |
| 296 | fov->setValue(ogl->viewAngle); |
| 297 | fov->setSingleStep(1.0); |
| 298 | connect(ogl, SIGNAL(viewAngeleChanged(double)),fov,SLOT(setValue(double))); |
| 299 | #if (QT_VERSION >= 0x050f10) |
| 300 | connect(fov, &QDoubleSpinBox::valueChanged, this, &OpenGLTestWidget::setViewAngle); |
| 301 | #else |
| 302 | connect(fov, SIGNAL(valueChanged(double)), this, SLOT(setViewAngle(double))); |
| 303 | #endif |
| 304 | |
| 305 | hlt1->addWidget(fpslabel); |
| 306 | hlt1->addWidget(messagelabel); |
| 307 | lt->addLayout(hlt1); |
| 308 | lt->addLayout(hlt); |
| 309 | lt->addWidget(vito); |
| 310 | hlt->addWidget(autoupdate); |
| 311 | hlt->addWidget(fov); |
| 312 | hlt->addWidget(bsdsp); |
| 313 | hlt->addWidget(lodsp); |
| 314 | hlt->addWidget(ogl->rCenter); |
| 315 | hlt->addWidget(ogl->enviButt); |
| 316 | hlt->addWidget(ogl->enviSelect); |
| 317 | lt->setStretch(0,100); |
| 318 | setLayout(lt); |
| 319 | connect(ogl, SIGNAL(message(QString)),this, SLOT(updateMessage(QString))); |
| 320 | QTimer *tmr = new QTimer(); |
| 321 | connect(tmr, &QTimer::timeout, this, &OpenGLTestWidget::printFPS); |
| 322 | tmr->start(2000); |
| 323 | } |
| 324 | |
| 325 | void OpenGLTestWidget::printFPS(){ |
| 326 | fpslabel->setText(QString("FPS: %1").arg(ogl->frame_cnt / 2.0,0,'f',1)); |
| 327 | ogl->frame_cnt = 0; |
| 328 | } |
| 329 | |
| 330 | void OpenGLTestWidget::updateMessage(QString s){ |
| 331 | messagelabel->setText(s); |
| 332 | update(); |
| 333 | } |
| 334 | |
| 335 | void OpenGLTestWidget::setViewAngle(double ang){ |
| 336 | if (fov->hasFocus()){ |
| 337 | ogl->setViewAngle(ang); |
| 338 | fov->clearFocus(); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | QSize OpenGLTestWidget::sizeHint() const {return QSize(800,800);} |
| 343 | |
| 344 | QSize OpenGLTestWidget::minimumSizeHint() const {return QSize(60,60);} |
| 345 | |
| 346 | /////////////////////////////////////////////////////////////////////// |
| 347 | #if defined (Q_OS_MAC) |
| 348 | PlayOpenGL::PlayOpenGL( Molecule *externMole): QOpenGLWindow(){ |
| 349 | #else |
| 350 | PlayOpenGL::PlayOpenGL( Molecule *externMole): QOpenGLWidget(){ |
| 351 | #endif |
| 352 | mol = externMole; |
| 353 | printf("line %d parent pointer = %p \n", __LINE__, parent()) ; |
| 354 | connect(this,SIGNAL(initialized()),this, SLOT(getReady())); |
| 355 | //QSurfaceFormat glFormat(QSurfaceFormat::DebugContext); |
| 356 | //myFont = QFont("Arial", 24); |
| 357 | //nonAtomFont = myFont; |
| 358 | if (parent()){ |
| 359 | isMainWindow = (parent()->objectName()=="The Main Window"); |
| 360 | } |
| 361 | //setMouseTracking(true); |
| 362 | nonAtomFont.setPointSize(qMax(((myFont.pointSize()*2)/3),7)); |
| 363 | QSurfaceFormat glFormat; |
| 364 | glFormat.setSwapInterval(0); |
| 365 | glFormat.setVersion( 3, 3 ); |
| 366 | glFormat.setSamples(4); |
| 367 | glFormat.setDepthBufferSize(24); |
| 368 | glFormat.setProfile( QSurfaceFormat::CoreProfile ); // Requires >=Qt-4.8.0 |
| 369 | glFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer); |
| 370 | //QSurfaceFormat::setDefaultFormat(glFormat); |
| 371 | setFormat(glFormat); |
| 372 | //printf("%d %s\n",__LINE__,(char*)glGetString(GL_VERSION)); |
| 373 | |
| 374 | if (externMole->mynewnameis.startsWith("shelXle")){ |
| 375 | theIconPath=QString(":/xle-icons/"); |
| 376 | }else{ |
| 377 | theIconPath=QString(":/bicons/"); |
| 378 | } |
| 379 | //printf("!! -}%s{- %d %s\n",externMole->mynewnameis.toStdString().c_str(), externMole->mynewnameis.startsWith("shelXle") ,theIconPath.toStdString().c_str()); |
| 380 | |
| 381 | envirange = 3.2; |
| 382 | //apair.clear(); |
| 383 | enviNoQ = new QAction("Exclude Q-peaks from environment listing", this); |
| 384 | enviCova = new QAction("List only covalent bonds.",this); |
| 385 | |
| 386 | enviButt = new QToolButton(); |
| 387 | enviButt->setText("clear ENVI"); |
| 388 | //enviButt->setIcon(QIcon(theIconPath+"cancel.svg")); |
| 389 | enviSelect = new QToolButton(); |
| 390 | enviSelect->setText("Select ENVI"); |
| 391 | enviButt->hide(); |
| 392 | enviSelect->hide(); |
| 393 | //enviSelect->setIcon(QIcon(theIconPath+"cancel.svg")); |
| 394 | connect(enviButt,SIGNAL(clicked()),this,SLOT(clearEnvi())); |
| 395 | connect(enviSelect,SIGNAL(clicked()),this,SLOT(selectEnvi())); |
| 396 | /*wireButt = new QAction("Wiremodel while rotate",this); |
| 397 | wireButt->setCheckable(true); |
| 398 | wireButt->setChecked(false);//defaut changed 13.12.2019*/ |
| 399 | rainbowPlot = new QAction("Contour plot in rainbow colors",this); |
| 400 | rainbowPlot->setCheckable(true); |
| 401 | rainbowPlot->setChecked(false); |
| 402 | rainbowPlot->setVisible(false); |
| 403 | enviNoQ->setCheckable(true); |
| 404 | enviNoQ->setChecked(false); |
| 405 | enviCova->setCheckable(true); |
| 406 | enviCova->setChecked(false); |
| 407 | //printf("line %d\n", __LINE__); |
| 408 | } |
| 409 | PlayOpenGL::~PlayOpenGL(){ |
| 410 | makeCurrent(); |
| 411 | //printf("?bye-bye-opengl?\n"); |
| 412 | |
| 413 | if (voro_vao.isCreated()) { |
| 414 | voro_vao.release(); |
| 415 | voro_vao.destroy(); |
| 416 | voro_vertexBuffer.destroy(); |
| 417 | } |
| 418 | if (uc_vao.isCreated()) { |
| 419 | uc_vao.release(); |
| 420 | uc_vao.destroy(); |
| 421 | uc_vertexBuffer.destroy(); |
| 422 | uc_program->release(); |
| 423 | uc_program->removeAllShaders(); |
| 424 | } |
| 425 | if (slct_vao.isCreated()) { |
| 426 | slct_vao.release(); |
| 427 | slct_vao.destroy(); |
| 428 | satom_vertexBuffer.destroy(); |
| 429 | satom_indexBuffer.destroy(); |
| 430 | satom_program->release(); |
| 431 | satom_program->removeAllShaders(); |
| 432 | } |
| 433 | if (map_vao.isCreated()) { |
| 434 | map_vao.release(); |
| 435 | map_vao.destroy(); |
| 436 | map_vertexBuffer.destroy(); |
| 437 | map_program->release(); |
| 438 | map_program->removeAllShaders(); |
| 439 | } |
| 440 | if (latom_vao.isCreated()) { |
| 441 | latom_vao.release(); |
| 442 | latom_vao.destroy(); |
| 443 | latom_vertexBuffer.destroy(); |
| 444 | latom_indexBuffer.destroy(); |
| 445 | //latom_program->release(); |
| 446 | //latom_program->removeAllShaders(); |
| 447 | } |
| 448 | |
| 449 | if (envi_vao.isCreated()) { |
| 450 | envi_vao.release(); |
| 451 | envi_vao.destroy(); |
| 452 | envi_vertexBuffer.destroy(); |
| 453 | envi_program->release(); |
| 454 | envi_program->removeAllShaders(); |
| 455 | } |
| 456 | |
| 457 | if (cont_vao.isCreated()) { |
| 458 | cont_vao.release(); |
| 459 | cont_vao.destroy(); |
| 460 | cont_vertexBuffer.destroy(); |
| 461 | cont_program->release(); |
| 462 | cont_program->removeAllShaders(); |
| 463 | } |
| 464 | if (atom_vao.isCreated()) { |
| 465 | atom_vao.release(); |
| 466 | atom_vao.destroy(); |
| 467 | atom_vertexBuffer.destroy(); |
| 468 | atom_indexBuffer.destroy(); |
| 469 | atom_program->release(); |
| 470 | atom_program->removeAllShaders(); |
| 471 | } |
| 472 | |
| 473 | if (bond_vao.isCreated()) { |
| 474 | bond_vao.release(); |
| 475 | bond_vao.destroy(); |
| 476 | bond_vertexBuffer.destroy(); |
| 477 | bond_indexBuffer.destroy(); |
| 478 | } |
| 479 | |
| 480 | if (bg_vao.isCreated()) { |
| 481 | bg_vao.release(); |
| 482 | bg_vao.destroy(); |
| 483 | backGround_vertexBuffer.destroy(); |
| 484 | bg_program->release(); |
| 485 | bg_program->removeAllShaders(); |
| 486 | } |
| 487 | //printf("bye-bye-opengl!\n"); |
| 488 | } |
| 489 | |
| 490 | |
| 491 | |
| 492 | void PlayOpenGL::setMolecule(Molecule *m){ |
| 493 | mol = m; |
| 494 | |
| 495 | //printf("line %d\n", __LINE__); |
| 496 | if (mol->mynewnameis.startsWith("shelXle")){ |
| 497 | theIconPath=QString(":/xle-icons/"); |
| 498 | }else{ |
| 499 | theIconPath=QString(":/bicons/"); |
| 500 | } |
| 501 | if (mol!=m) { |
| 502 | if (mol) delete mol; |
| 503 | mol=m; |
| 504 | } |
| 505 | double dim=mol->dimension(); |
| 506 | L=100.0/dim; |
| 507 | //printf("line %d\n", __LINE__); |
| 508 | } |
| 509 | //QSize PlayOpenGL::sizeHint() const {return QSize(800,800);} |
| 510 | //QSize PlayOpenGL::minimumSizeHint() const {return QSize(60,60);} |
| 511 | |
| 512 | int PlayOpenGL::commonFaces(Vert a,Vert b, int f[2]){ |
| 513 | int matches=0; |
| 514 | for (int i=0; i<3; i++) |
| 515 | for (int j=0; j<3; j++) |
| 516 | if (a.faces[i]==b.faces[j])f[matches++]=a.faces[i]; |
| 517 | return matches; |
| 518 | } |
| 519 | |
| 520 | void PlayOpenGL::voronoij(CEnvironment au, int intat){ |
| 521 | double dk,range=5.0; |
| 522 | QString voroMsg; |
| 523 | voroMsg.clear(); |
| 524 | voroMsg.append("<b>Voronoi:</b><br>"); |
| 525 | //QTime speedTest; |
| 526 | //speedTest.start(); |
| 527 | vtriangles.clear(); |
| 528 | VPoly triangle; |
| 529 | //vorobas=1; |
| 530 | V3 prime,dp,D,floorD; |
| 531 | QList<SdmItem> sdm; |
| 532 | SdmItem sdmItem; |
| 533 | sdmItem.a1=0; |
| 534 | sdmItem.a2=1; |
| 535 | sdmItem.sn=0; |
| 536 | //sdmItem.p1=sdmItem.p2=V3(0,0,0); |
| 537 | for (int i=0; i<au.size(); i++){ |
| 538 | for (int j=0; j<au.size(); j++ ){ |
| 539 | if ((au.at(i).sg)||(au.at(j).sg)) continue; |
| 540 | // bool hma=false; |
| 541 | for (int n=0;n<mol->cell.symmops.size(); n++){ |
| 542 | prime=mol->cell.symmops.at(n) * au.at(i).frac + mol->cell.trans.at(n); |
| 543 | D=prime - au.at(j).frac+ V3(0.5,0.5,0.5) ; |
| 544 | floorD=V3(floor(D.x),floor(D.y),floor(D.z)); |
| 545 | for (int h=-1; h<2; h++){ |
| 546 | for (int k=-1; k<2; k++){ |
| 547 | for (int l=-1; l<2; l++){ |
| 548 | V3 fD=floorD+V3(h,k,l); |
| 549 | dp=D - fD - V3(0.5,0.5,0.5); |
| 550 | dk = mol->fl(dp.x,dp.y,dp.z); |
| 551 | if ((dk>0.01)&&((range)>=dk)){ |
| 552 | sdmItem.d=dk; |
| 553 | sdmItem.floorD=fD; |
| 554 | sdmItem.a1=i; |
| 555 | sdmItem.a2=j; |
| 556 | sdmItem.sn=n; |
| 557 | sdm.append(sdmItem); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | #if (QT_VERSION >= 0x050000) |
| 566 | std::sort(sdm.begin(),sdm.end()); |
| 567 | #else |
| 568 | qSort(sdm.begin(),sdm.end()); |
| 569 | #endif |
| 570 | //SDMprint(sdm,au); |
| 571 | QList<V3> n,m,doneLine; |
| 572 | QList<int> intra, altcol; |
| 573 | QList<Vert> v; |
| 574 | Vert vert; |
| 575 | V3 pf,pc,mx,nx,of,oc; |
| 576 | Matrix mat; |
| 577 | double vol=0.0,avol,tvol; |
| 578 | for (int i=(intat>-1)?intat:0; i<au.size(); i++){ |
| 579 | if (au.at(i).an<0) continue; |
| 580 | //find faces |
| 581 | n.clear(); |
| 582 | m.clear(); |
| 583 | v.clear(); |
| 584 | doneLine.clear(); |
| 585 | intra.clear(); |
| 586 | avol=0.0; |
| 587 | int faci=0; |
| 588 | //int vcnt=0; |
| 589 | mol->frac2kart(au.at(i).frac,oc); |
| 590 | int tris=0; |
| 591 | for (int j=0; j<sdm.size();j++){ |
| 592 | if(sdm.at(j).d<0.1) continue; |
| 593 | if ((sdm.at(j).a2==i)&&(au[sdm.at(j).a1].an>-1)) { |
| 594 | pf = mol->cell.symmops.at(sdm.at(j).sn) * au[sdm.at(j).a1].frac + mol->cell.trans.at(sdm.at(j).sn) - sdm.at(j).floorD; |
| 595 | mol->frac2kart(pf,pc); |
| 596 | mx =0.5*(oc+pc); |
| 597 | nx = Normalize(pc-oc); |
| 598 | bool exists = false; |
| 599 | double dpl; |
| 600 | for (int tp=0; tp<m.size(); tp++){ |
| 601 | dpl=n.at(tp)*(mx-m.at(tp)); |
| 602 | if (fabs(dpl)<0.001){exists=true;break;} |
| 603 | } |
| 604 | if (!exists){ |
| 605 | m.append(mx); |
| 606 | n.append(nx); |
| 607 | intra.append((sdm.at(j).sn==0)&&(Norm(sdm.at(j).floorD)==0.0)); |
| 608 | if (intat>-1)altcol.append(au[sdm.at(j).a1].an); |
| 609 | } |
| 610 | }//is neighbour of i |
| 611 | }// j sdm |
| 612 | for (int h=0; h<n.size()-2; h++) |
| 613 | for (int k=h+1; k<n.size()-1; k++) |
| 614 | for (int l=k+1; l<n.size(); l++){ |
| 615 | mat=Matrix(n.at(h),n.at(k),n.at(l)); |
| 616 | double d=determinant(mat),dpl; |
| 617 | //printf("%d,%d,%d %9.5f\n",h,k,l,d); |
| 618 | if (fabs(d)<0.0002) continue; |
| 619 | |
| 620 | //p = (dot(p1,n1)*cross(n2,n3)-dot(p2,n2)*cross(n1,n3)+dot(p3,n3)*cross(n1,n2))/d |
| 621 | bool out=false; |
| 622 | vert.pos=( |
| 623 | (m.at(h)*n.at(h))*(n.at(k)%n.at(l))+ |
| 624 | (m.at(k)*n.at(k))*(n.at(l)%n.at(h))+ |
| 625 | (m.at(l)*n.at(l))*(n.at(h)%n.at(k)))*(1.0/d); |
| 626 | vert.faces[0]=h; |
| 627 | vert.faces[1]=k; |
| 628 | vert.faces[2]=l; |
| 629 | for (int pli=0; pli<n.size(); pli++){//teste lage zu allen ebenen |
| 630 | dpl=n.at(pli)*(vert.pos-m.at(pli)); |
| 631 | if (dpl>0.00001) { |
| 632 | out=true; |
| 633 | break; |
| 634 | } |
| 635 | } |
| 636 | if (!out) { |
| 637 | v.append(vert); |
| 638 | // printf("[%d,%d,%d] %9.5f%9.5f%9.5f \n",h,k,l,vert.pos.x,vert.pos.y,vert.pos.z); |
| 639 | } |
| 640 | } |
| 641 | for (int mi=0; mi<m.size();mi++){// this is to get the midpoint of a face in its actual center |
| 642 | V3 mnew=V3(0,0,0); |
| 643 | int poli=0; |
| 644 | for (int vi=0; vi<v.size(); vi++){ |
| 645 | if ((v.at(vi).faces[0]==mi)||(v.at(vi).faces[1]==mi)||(v.at(vi).faces[2]==mi)){ |
| 646 | mnew+=v.at(vi).pos; |
| 647 | poli++; |
| 648 | } |
| 649 | } |
| 650 | mnew*=1.0/poli; |
| 651 | // printf("%dsoll 0=%f\n",poli,n.at(mi)*(mnew-m.at(mi))); |
| 652 | if (poli) {m[mi]=mnew;faci++;} |
| 653 | } |
| 654 | |
| 655 | for(int vi=0; vi<v.size()-1; vi++) |
| 656 | for(int vj=vi+1; vj<v.size(); vj++){ |
| 657 | int fc[2]; |
| 658 | if (commonFaces(v.at(vi),v.at(vj),fc)==2){ |
| 659 | V3 lin=v.at(vi).pos+v.at(vj).pos; |
| 660 | double dis; |
| 661 | bool done=false; |
| 662 | for (int di=0; di<doneLine.size(); di++){ |
| 663 | dis=Distance(lin,doneLine.at(di)); |
| 664 | if (dis<0.000001) {done=true; break;} |
| 665 | } |
| 666 | if (done) continue; |
| 667 | doneLine.append(lin); |
| 668 | tvol=determinant(Matrix(m.at(fc[0])-oc, v.at(vi).pos-oc,v.at(vj).pos-oc)); |
| 669 | int v1=(tvol<0)?vj:vi, |
| 670 | v2=(tvol<0)?vi:vj; |
| 671 | triangle.mid=m.at(fc[0]); |
| 672 | triangle.nor=n.at(fc[0]); |
| 673 | triangle.acol=(intat>-1)?altcol.at(fc[0]):au[i].an; |
| 674 | triangle.intra=(intat>-1)?0:intra.at(fc[0]); |
| 675 | triangle.verts0=v[v1].pos; |
| 676 | triangle.verts1=v[v2].pos; |
| 677 | |
| 678 | vtriangles.append(triangle); |
| 679 | |
| 680 | tris++; |
| 681 | double tv=fabs(tvol)/6.0; |
| 682 | avol+=tv; |
| 683 | vol+=tv*au[i].sof; |
| 684 | tvol=determinant(Matrix(m.at(fc[1])-oc, v.at(vi).pos-oc,v.at(vj).pos-oc)); |
| 685 | v1=(tvol<0)?vj:vi; |
| 686 | v2=(tvol<0)?vi:vj; |
| 687 | triangle.mid=m.at(fc[1]); |
| 688 | triangle.nor=n.at(fc[1]); |
| 689 | |
| 690 | triangle.acol=(intat>-1)?altcol.at(fc[1]):au[i].an; |
| 691 | triangle.intra=(intat>-1)?0:intra.at(fc[1]); |
| 692 | // triangle.col[3]=((intat>-1)&&(intra.at(fc[1])))?0.8:0.4; |
| 693 | triangle.verts0=v[v1].pos; |
| 694 | triangle.verts1=v[v2].pos; |
| 695 | vtriangles.append(triangle); |
| 696 | tris++; |
| 697 | tv=fabs(tvol)/6.0; |
| 698 | avol+=tv; |
| 699 | vol+=tv*au[i].sof; |
| 700 | } |
| 701 | } |
| 702 | printf("%-12s: Triangles %6d Volume %18.5f\n", au.at(i).Label.toStdString().c_str(), tris, avol); |
| 703 | voroMsg.append(QString("%1 : EulerTest: %2 Volume %3 Å<sup>3</sup>.<br>").arg(au.at(i).Label).arg(-tris/2+faci+v.size()).arg(avol)); |
| 704 | |
| 705 | if (intat>-1) break; |
| 706 | }//i atoms au |
| 707 | if (intat==-1) { |
| 708 | printf("Total Volume= %18.5f Total Volume * z = %18.5f cell volume %18.5f delta =%f%%\n", |
| 709 | vol, |
| 710 | vol*mol->cell.symmops.size(), |
| 711 | mol->cell.V, |
| 712 | (vol*mol->cell.symmops.size()-mol->cell.V)/mol->cell.V*100.0); |
| 713 | voroMsg.append(QString("Total Volume= %1 Å<sup>3</sup> cell volume %2 Å<sup>3</sup> ΔV %3%<br>") |
| 714 | .arg(vol*mol->cell.symmops.size()) |
| 715 | .arg(mol->cell.V) |
| 716 | .arg((vol*mol->cell.symmops.size()-mol->cell.V)/mol->cell.V*100.0)); |
| 717 | } |
| 718 | emit bigmessage(voroMsg); |
| 719 | // printf("drawing %dms\n",speedTest.restart()); |
| 720 | // eye=auge; |
| 721 | /* |
| 722 | #if (QT_VERSION >= 0x050000) |
| 723 | std::sort(vtriangles.begin(),vtriangles.end(),vbyeye); |
| 724 | #else |
| 725 | qSort(vtriangles.begin(),vtriangles.end(),vbyeye); |
| 726 | #endif |
| 727 | */ |
| 728 | QVector<float> vp; |
| 729 | for (int ti=0; ti<vtriangles.size(); ti++){ |
| 730 | QColor c=mol->atomColor(vtriangles.at(ti).acol); |
| 731 | vp.append(vtriangles.at(ti).mid.x); |
| 732 | vp.append(vtriangles.at(ti).mid.y); |
| 733 | vp.append(vtriangles.at(ti).mid.z); |
| 734 | vp.append(static_cast<float>(vtriangles.at(ti).acol)+0.99*c.blueF()); |
| 735 | |
| 736 | vp.append(vtriangles.at(ti).nor.x); |
| 737 | vp.append(vtriangles.at(ti).nor.y); |
| 738 | vp.append(vtriangles.at(ti).nor.z); |
| 739 | vp.append(static_cast<float>(vtriangles.at(ti).intra)); |
| 740 | |
| 741 | vp.append(vtriangles.at(ti).verts0.x); |
| 742 | vp.append(vtriangles.at(ti).verts0.y); |
| 743 | vp.append(vtriangles.at(ti).verts0.z); |
| 744 | vp.append(c.redF()); |
| 745 | |
| 746 | vp.append(vtriangles.at(ti).verts1.x); |
| 747 | vp.append(vtriangles.at(ti).verts1.y); |
| 748 | vp.append(vtriangles.at(ti).verts1.z); |
| 749 | vp.append(c.greenF()); |
| 750 | |
| 751 | } |
| 752 | |
| 753 | makeCurrent(); |
| 754 | voro_vao.release(); |
| 755 | if (voro_vao.isCreated()) { |
| 756 | voro_vao.release(); |
| 757 | voro_vao.destroy(); |
| 758 | voro_vertexBuffer.destroy(); |
| 759 | //voro_indexBuffer.destroy(); |
| 760 | } |
| 761 | voro_vao.create(); |
| 762 | voro_vao.bind(); |
| 763 | voro_vertexBuffer.create(); |
| 764 | voro_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 765 | //glDisable(GL_BLEND); |
| 766 | if (!voro_vertexBuffer.bind()) {printf("voro_vertexBuffer: I was unable to bind!\n");} |
| 767 | voro_vertexBuffer.allocate(vp.data(), vp.size()*sizeof(float)); |
| 768 | if (!voro_program) voro_program = new QOpenGLShaderProgram(this); |
| 769 | else voro_program->removeAllShaders(); |
| 770 | //printf("%p %d\n",voro_program, voro_program->programId()); |
| 771 | |
| 772 | bool result = voro_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/voro.vert"); |
| 773 | //printf("%d\n",__LINE__); |
| 774 | if ( !result ) qWarning() << voro_program->log(); |
| 775 | result = voro_program->addCacheableShaderFromSourceFile( QOpenGLShader::Geometry, ":/shaders/voro.geom"); |
| 776 | //printf("%d\n",__LINE__); |
| 777 | if ( !result ) qWarning() << voro_program->log(); |
| 778 | result = voro_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/voro.frag"); |
| 779 | |
| 780 | if ( !result ) qWarning() << voro_program->log(); |
| 781 | result = voro_program->link(); |
| 782 | if ( !result ) qWarning() << voro_program->log(); |
| 783 | if ( !voro_program->bind() ) { |
| 784 | qWarning() << "Could not bind shader program to context"; |
| 785 | return; |
| 786 | } |
| 787 | |
| 788 | |
| 789 | programInfo(voro_program,"voro"); |
| 790 | |
| 791 | voro_program->enableAttributeArray(0);//mid |
| 792 | voro_program->enableAttributeArray(1);//nor |
| 793 | voro_program->enableAttributeArray(2);//vert0 |
| 794 | voro_program->enableAttributeArray(3);//vert1 |
| 795 | //printf("%d\n",__LINE__); |
| 796 | int stride = 4 * 4 * sizeof(float); |
| 797 | voro_program->setAttributeBuffer(0, GL_FLOAT, 0, 4, stride); |
| 798 | voro_program->setAttributeBuffer(1, GL_FLOAT, sizeof(float)*4 , 4, stride); |
| 799 | voro_program->setAttributeBuffer(2, GL_FLOAT, sizeof(float)*8 , 4, stride); |
| 800 | voro_program->setAttributeBuffer(3, GL_FLOAT, sizeof(float)*12 , 4, stride); |
| 801 | |
| 802 | |
| 803 | voro_program->release(); |
| 804 | voro_vao.release(); |
| 805 | voro_vertexBuffer.release(); |
| 806 | voro_vertexBuffer.destroy(); |
| 807 | update(); |
| 808 | |
| 809 | }//voronoij |
| 810 | /*V3 eye; |
| 811 | bool PlayOpenGL::vbyeye(VPoly a,VPoly b){ |
| 812 | //return (Distance((a.mid+a.verts0+a.verts1)*0.33333,eye)>Distance((b.mid+b.verts0+b.verts1)*0.33333,eye)); |
| 813 | return (mol->Distance(a.mid,eye)>Distance(b.mid,eye)); |
| 814 | }*/ |
| 815 | |
| 816 | |
| 817 | |
| 818 | void PlayOpenGL::connectSelection(){//!creates a bond betwen two selected atoms. |
| 819 | if (mol->selectedatoms.size()!=2) return; |
| 820 | MyBond b; |
| 821 | b.a1=mol->selectedatoms.at(0).style; |
| 822 | b.a2=mol->selectedatoms.at(1).style; |
| 823 | b.ato1=&mol->showatoms[mol->selectedatoms.at(0).style]; |
| 824 | b.ato2=&mol->showatoms[mol->selectedatoms.at(1).style]; |
| 825 | b.length=sqrt(Distance(b.ato1->pos,b.ato2->pos)); |
| 826 | mol->showbonds.append(b); |
| 827 | mol->selectedatoms.clear(); |
| 828 | updateBondActions(); |
| 829 | update(); |
| 830 | } |
| 831 | |
| 832 | void PlayOpenGL::disConnectSelection(int index){//! destroyes the bond between two selected atoms. |
| 833 | mol->showbonds.removeAt(index); |
| 834 | mol->selectedatoms.clear(); |
| 835 | updateBondActions(); |
| 836 | update(); |
| 837 | } |
| 838 | |
| 839 | void PlayOpenGL::disSelection(){//! Un select everything. |
| 840 | mol->selectedatoms.clear(); |
| 841 | //apair.clear(); |
| 842 | updateBondActions(); |
| 843 | update(); |
| 844 | } |
| 845 | |
| 846 | void PlayOpenGL::addANIS(){ |
| 847 | emit insertANIS(mol->selectedatoms); |
| 848 | mol->selectedatoms.clear(); |
| 849 | } |
| 850 | |
| 851 | void PlayOpenGL::addCHIV(){ |
| 852 | QDialog *dia = new QDialog(); |
| 853 | dia->setWindowTitle(tr("CHIV: Geometrical restraint")); |
| 854 | dia->setModal(false); |
| 855 | |
| 856 | QGridLayout *grid = new QGridLayout(dia); |
| 857 | QLineEdit *volline = new QLineEdit(dia); |
| 858 | QLineEdit *esd1line = new QLineEdit(dia); |
| 859 | QLabel *vol = new QLabel("Volume:", dia); |
| 860 | QLabel *esd1 = new QLabel("ESD:", dia); |
| 861 | // Set default value for distance and esd |
| 862 | volline->setText("0.0"); |
| 863 | esd1line->setText("0.1"); |
| 864 | int i(0); // index for position of widgets in the container |
| 865 | grid->addWidget(vol,i,0); |
| 866 | grid->addWidget(volline,i++,1); |
| 867 | grid->addWidget(esd1,i,0); |
| 868 | grid->addWidget(esd1line,i++,1); |
| 869 | QStringList rl = resis(); |
| 870 | QComboBox *resiCom = NULL; |
| 871 | if (!rl.isEmpty()){ |
| 872 | QLabel *resi = new QLabel("Residue specific",dia); |
| 873 | resiCom = new QComboBox(dia); |
| 874 | resiCom->addItem(""); |
| 875 | resiCom->addItems(rl); |
| 876 | grid->addWidget(resi,i,0); |
| 877 | grid->addWidget(resiCom,i++,1); |
| 878 | } |
| 879 | |
| 880 | QDialogButtonBox *buttonBox = new QDialogButtonBox(); |
| 881 | |
| 882 | QPushButton *OkButton; |
| 883 | QPushButton *CancelButton; |
| 884 | |
| 885 | OkButton = buttonBox->addButton(QDialogButtonBox::Ok); |
| 886 | CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); |
| 887 | |
| 888 | buttonBox->setOrientation(Qt::Horizontal); |
| 889 | |
| 890 | grid->addWidget(buttonBox,i,0); |
| 891 | |
| 892 | dia->setLayout(grid); |
| 893 | connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept())); |
| 894 | connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject())); |
| 895 | |
| 896 | dia->show(); |
| 897 | int a = dia->exec(); |
| 898 | |
| 899 | if(a == QDialog::Accepted) |
| 900 | { |
| 901 | // read value from value line |
| 902 | QString s=(rl.isEmpty())?"":resiCom->currentText(); |
| 903 | emit insertCHIV(volline->text().toDouble(),esd1line->text().toDouble(),mol->selectedatoms,s); |
| 904 | mol->selectedatoms.clear(); |
| 905 | } |
| 906 | else |
| 907 | { |
| 908 | if(a == QDialog::Rejected) |
| 909 | dia->close(); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | void PlayOpenGL::addDANG(){ |
| 914 | QDialog *dia = new QDialog(); |
| 915 | dia->setWindowTitle(tr("DANG: Geometrical restraint")); |
| 916 | dia->setModal(false); |
| 917 | |
| 918 | QGridLayout *grid = new QGridLayout(dia); |
| 919 | QLineEdit *valueline = new QLineEdit(dia); |
| 920 | QLineEdit *esdline = new QLineEdit(dia); |
| 921 | QLabel *value = new QLabel("Value:", dia); |
| 922 | QLabel *esd = new QLabel("ESD:", dia); |
| 923 | QStringList rl = resis(); |
| 924 | QComboBox *resiCom = NULL; |
| 925 | if (!rl.isEmpty()){ |
| 926 | QLabel *resi = new QLabel("Residue specific",dia); |
| 927 | resiCom = new QComboBox(dia); |
| 928 | resiCom->addItem(""); |
| 929 | resiCom->addItems(rl); |
| 930 | grid->addWidget(resi,2,0); |
| 931 | grid->addWidget(resiCom,2,1); |
| 932 | } |
| 933 | // Set default value for distance and esd |
| 934 | // Get value for DANG. Current bond distance and default esd - 0.04 |
| 935 | valueline->setText(QString::number(sqrt(Distance(mol->selectedatoms.at(0).pos,mol->selectedatoms.at(1).pos)),10,3)); |
| 936 | esdline->setText("0.04"); |
| 937 | |
| 938 | grid->addWidget(value,0,0); |
| 939 | grid->addWidget(valueline,0,1); |
| 940 | grid->addWidget(esd,1,0); |
| 941 | grid->addWidget(esdline,1,1); |
| 942 | |
| 943 | QDialogButtonBox *buttonBox = new QDialogButtonBox(); |
| 944 | |
| 945 | QPushButton *OkButton; |
| 946 | QPushButton *CancelButton; |
| 947 | |
| 948 | OkButton = buttonBox->addButton(QDialogButtonBox::Ok); |
| 949 | CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); |
| 950 | |
| 951 | buttonBox->setOrientation(Qt::Horizontal); |
| 952 | |
| 953 | grid->addWidget(buttonBox,4,0); |
| 954 | |
| 955 | dia->setLayout(grid); |
| 956 | connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept())); |
| 957 | connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject())); |
| 958 | |
| 959 | dia->show(); |
| 960 | int a = dia->exec(); |
| 961 | |
| 962 | if(a == QDialog::Accepted) |
| 963 | { |
| 964 | // read value from value line |
| 965 | QString s=(rl.isEmpty())?"":resiCom->currentText(); |
| 966 | emit insertDANG(valueline->text().toDouble(),esdline->text().toDouble(),mol->selectedatoms,s); |
| 967 | mol->selectedatoms.clear(); |
| 968 | } |
| 969 | else |
| 970 | { |
| 971 | if(a == QDialog::Rejected) |
| 972 | dia->close(); |
| 973 | } |
| 974 | |
| 975 | } |
| 976 | |
| 977 | void PlayOpenGL::addDELU(){ |
| 978 | QDialog *dia = new QDialog(); |
| 979 | dia->setWindowTitle(tr("DELU: ADP restraint")); |
| 980 | dia->setModal(false); |
| 981 | |
| 982 | QGridLayout *grid = new QGridLayout(dia); |
| 983 | QLineEdit *esd1line = new QLineEdit(dia); |
| 984 | QLineEdit *esd2line = new QLineEdit(dia); |
| 985 | QLabel *esd1 = new QLabel("ESD1:", dia); |
| 986 | QLabel *esd2 = new QLabel("ESD2:", dia); |
| 987 | // Set default value for distance and esd |
| 988 | esd1line->setText("0.01"); |
| 989 | esd2line->setText("0.01"); |
| 990 | |
| 991 | grid->addWidget(esd1,0,0); |
| 992 | grid->addWidget(esd1line,0,1); |
| 993 | grid->addWidget(esd2,1,0); |
| 994 | grid->addWidget(esd2line,1,1); |
| 995 | QStringList rl = resis(); |
| 996 | QComboBox *resiCom = NULL; |
| 997 | if (!rl.isEmpty()){ |
| 998 | QLabel *resi = new QLabel("Residue specific",dia); |
| 999 | resiCom = new QComboBox(dia); |
| 1000 | resiCom->addItem(""); |
| 1001 | resiCom->addItems(rl); |
| 1002 | grid->addWidget(resi,3,0); |
| 1003 | grid->addWidget(resiCom,3,1); |
| 1004 | } |
| 1005 | |
| 1006 | QDialogButtonBox *buttonBox = new QDialogButtonBox(); |
| 1007 | |
| 1008 | QPushButton *OkButton; |
| 1009 | QPushButton *CancelButton; |
| 1010 | |
| 1011 | OkButton = buttonBox->addButton(QDialogButtonBox::Ok); |
| 1012 | CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); |
| 1013 | |
| 1014 | buttonBox->setOrientation(Qt::Horizontal); |
| 1015 | |
| 1016 | grid->addWidget(buttonBox,4,0); |
| 1017 | |
| 1018 | dia->setLayout(grid); |
| 1019 | connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept())); |
| 1020 | connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject())); |
| 1021 | |
| 1022 | dia->show(); |
| 1023 | int a = dia->exec(); |
| 1024 | |
| 1025 | if(a == QDialog::Accepted) |
| 1026 | { |
| 1027 | // read value from value line |
| 1028 | QString s=(rl.isEmpty())?"":resiCom->currentText(); |
| 1029 | emit insertDELU(esd1line->text().toDouble(),esd2line->text().toDouble(),mol->selectedatoms,s); |
| 1030 | mol->selectedatoms.clear(); |
| 1031 | } |
| 1032 | else |
| 1033 | { |
| 1034 | if(a == QDialog::Rejected) |
| 1035 | dia->close(); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | void PlayOpenGL::addDFIX(){ |
| 1040 | if (mol->selectedatoms.size()!=2)return; |
| 1041 | QDialog *dia = new QDialog(); |
| 1042 | dia->setWindowTitle("DFIX: Geometrical restraint"); |
| 1043 | dia->setModal(false); |
| 1044 | |
| 1045 | QGridLayout *grid = new QGridLayout(dia); |
| 1046 | QLineEdit *valueline = new QLineEdit(dia); |
| 1047 | valueline->setObjectName("DFIX_DIST"); |
| 1048 | QLineEdit *esdline = new QLineEdit(dia); |
| 1049 | QLabel *value = new QLabel("Value:", dia); |
| 1050 | QLabel *esd = new QLabel("ESD:", dia); |
| 1051 | QLabel *atoms = new QLabel(QString("%1==%2 : %3 A") |
| 1052 | .arg(mol->selectedatoms.at(0).Label) |
| 1053 | .arg(mol->selectedatoms.at(1).Label) |
| 1054 | .arg( sqrt(Distance(mol->selectedatoms.at(0).pos,mol->selectedatoms.at(1).pos)),10,'f',3)); |
| 1055 | QCheckBox *bindit = new QCheckBox("Insert BIND instruction",dia); |
| 1056 | QStringList rl = resis(); |
| 1057 | QComboBox *resiCom = NULL; |
| 1058 | if (!rl.isEmpty()){ |
| 1059 | QLabel *resi = new QLabel("Residue specific",dia); |
| 1060 | resiCom = new QComboBox(dia); |
| 1061 | // Usually you want to define residue restraints with numbers at the atom: |
| 1062 | resiCom->addItem(""); |
| 1063 | resiCom->addItems(rl); |
| 1064 | grid->addWidget(resi,3,0); |
| 1065 | grid->addWidget(resiCom,3,1); |
| 1066 | } |
| 1067 | // Set default value for distance and esd |
| 1068 | // Get value for DFIX. Current bond distance and default esd - 0.02 |
| 1069 | valueline->setText(QString::number(sqrt(Distance(mol->selectedatoms.at(0).pos,mol->selectedatoms.at(1).pos)),10,3)); |
| 1070 | esdline->setText("0.02"); |
| 1071 | grid->addWidget(atoms,0,0,1,2); |
| 1072 | grid->addWidget(value,1,0); |
| 1073 | grid->addWidget(valueline,1,1); |
| 1074 | grid->addWidget(esd,2,0); |
| 1075 | grid->addWidget(esdline,2,1); |
| 1076 | grid->addWidget(bindit,4,0); |
| 1077 | QDialogButtonBox *buttonBox = new QDialogButtonBox(); |
| 1078 | |
| 1079 | QPushButton *OkButton; |
| 1080 | QPushButton *CancelButton; |
| 1081 | 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]))); |
| 1082 | |
| 1083 | OkButton = buttonBox->addButton(QDialogButtonBox::Ok); |
| 1084 | CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); |
| 1085 | buttonBox->addButton(singleBondButton,QDialogButtonBox::ActionRole); |
| 1086 | |
| 1087 | |
| 1088 | buttonBox->setOrientation(Qt::Horizontal); |
| 1089 | |
| 1090 | grid->addWidget(buttonBox,10,0); |
| 1091 | |
| 1092 | dia->setLayout(grid); |
| 1093 | connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept())); |
| 1094 | connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject())); |
| 1095 | connect(singleBondButton, SIGNAL(clicked()), this, SLOT(singleBondDistance())); |
| 1096 | |
| 1097 | dia->show(); |
| 1098 | int a = dia->exec(); |
| 1099 | |
| 1100 | if(a == QDialog::Accepted) { |
| 1101 | // read value from value line |
| 1102 | QString s=(rl.isEmpty())?"":resiCom->currentText(); |
| 1103 | emit insertDFIX(valueline->text().toDouble(),esdline->text().toDouble(),mol->selectedatoms,s); |
| 1104 | if (bindit->isChecked()) emit bindthem(); |
| 1105 | mol->selectedatoms.clear(); |
| 1106 | } |
| 1107 | else { |
| 1108 | if(a == QDialog::Rejected) |
| 1109 | dia->close(); |
| 1110 | } |
| 1111 | // updateBondActions(); |
| 1112 | } |
| 1113 | |
| 1114 | void PlayOpenGL::addEADP(){ |
| 1115 | emit insertEADP(mol->selectedatoms); |
| 1116 | mol->selectedatoms.clear(); |
| 1117 | } |
| 1118 | |
| 1119 | void PlayOpenGL::addEXYZ(){ |
| 1120 | emit insertEXYZ(mol->selectedatoms); |
| 1121 | mol->selectedatoms.clear(); |
| 1122 | } |
| 1123 | |
| 1124 | void PlayOpenGL::addFLAT(){ |
| 1125 | QDialog *dia = new QDialog(); |
| 1126 | dia->setWindowTitle(tr("FLAT: Geometrical restraint")); |
| 1127 | dia->setModal(false); |
| 1128 | |
| 1129 | QGridLayout *grid = new QGridLayout(dia); |
| 1130 | QLineEdit *esdline = new QLineEdit(dia); |
| 1131 | QLabel *esd = new QLabel("ESD:", dia); |
| 1132 | QStringList rl = resis(); |
| 1133 | QComboBox *resiCom = NULL; |
| 1134 | if (!rl.isEmpty()){ |
| 1135 | QLabel *resi = new QLabel("Residue specific",dia); |
| 1136 | resiCom = new QComboBox(dia); |
| 1137 | resiCom->addItem(""); |
| 1138 | resiCom->addItems(rl); |
| 1139 | grid->addWidget(resi,2,0); |
| 1140 | grid->addWidget(resiCom,2,1); |
| 1141 | } |
| 1142 | // Set default value for esd |
| 1143 | esdline->setText("0.1"); |
| 1144 | |
| 1145 | grid->addWidget(esd,0,0); |
| 1146 | grid->addWidget(esdline,0,1); |
| 1147 | |
| 1148 | QDialogButtonBox *buttonBox = new QDialogButtonBox(); |
| 1149 | |
| 1150 | QPushButton *OkButton; |
| 1151 | QPushButton *CancelButton; |
| 1152 | |
| 1153 | OkButton = buttonBox->addButton(QDialogButtonBox::Ok); |
| 1154 | CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); |
| 1155 | |
| 1156 | buttonBox->setOrientation(Qt::Horizontal); |
| 1157 | |
| 1158 | grid->addWidget(buttonBox,1,0); |
| 1159 | |
| 1160 | dia->setLayout(grid); |
| 1161 | connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept())); |
| 1162 | connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject())); |
| 1163 | |
| 1164 | dia->show(); |
| 1165 | int a = dia->exec(); |
| 1166 | |
| 1167 | if(a == QDialog::Accepted) |
| 1168 | { |
| 1169 | // read value from value line |
| 1170 | QString s=(rl.isEmpty())?"":resiCom->currentText(); |
| 1171 | emit insertFLAT(esdline->text().toDouble(),mol->selectedatoms,s); |
| 1172 | mol->selectedatoms.clear(); |
| 1173 | } |
| 1174 | else |
| 1175 | { |
| 1176 | if(a == QDialog::Rejected) |
| 1177 | dia->close(); |
| 1178 | } |
| 1179 | |
| 1180 | } |
| 1181 | |
| 1182 | void PlayOpenGL::addISOR(){ |
| 1183 | QDialog *dia = new QDialog(); |
| 1184 | dia->setWindowTitle(tr("ISOR: ADP restraint")); |
| 1185 | dia->setModal(false); |
| 1186 | |
| 1187 | QGridLayout *grid = new QGridLayout(dia); |
| 1188 | QLineEdit *esd1line = new QLineEdit(dia); |
| 1189 | QLineEdit *esd2line = new QLineEdit(dia); |
| 1190 | QLabel *esd1 = new QLabel("ESD1:", dia); |
| 1191 | QLabel *esd2 = new QLabel("ESD2:", dia); |
| 1192 | QStringList rl = resis(); |
| 1193 | QComboBox *resiCom = NULL; |
| 1194 | if (!rl.isEmpty()){ |
| 1195 | QLabel *resi = new QLabel("Residue specific",dia); |
| 1196 | resiCom = new QComboBox(dia); |
| 1197 | resiCom->addItem(""); |
| 1198 | resiCom->addItems(rl); |
| 1199 | grid->addWidget(resi,3,0); |
| 1200 | grid->addWidget(resiCom,3,1); |
| 1201 | } |
| 1202 | // Set default values for s and st |
| 1203 | esd1line->setText("0.1"); |
| 1204 | esd2line->setText("0.2"); |
| 1205 | |
| 1206 | grid->addWidget(esd1,0,0); |
| 1207 | grid->addWidget(esd1line,0,1); |
| 1208 | grid->addWidget(esd2,1,0); |
| 1209 | grid->addWidget(esd2line,1,1); |
| 1210 | |
| 1211 | QDialogButtonBox *buttonBox = new QDialogButtonBox(); |
| 1212 | |
| 1213 | QPushButton *OkButton; |
| 1214 | QPushButton *CancelButton; |
| 1215 | |
| 1216 | OkButton = buttonBox->addButton(QDialogButtonBox::Ok); |
| 1217 | CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); |
| 1218 | |
| 1219 | buttonBox->setOrientation(Qt::Horizontal); |
| 1220 | |
| 1221 | grid->addWidget(buttonBox,4,0); |
| 1222 | |
| 1223 | dia->setLayout(grid); |
| 1224 | connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept())); |
| 1225 | connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject())); |
| 1226 | |
| 1227 | dia->show(); |
| 1228 | int a = dia->exec(); |
| 1229 | |
| 1230 | if(a == QDialog::Accepted) |
| 1231 | { |
| 1232 | // read value from value line |
| 1233 | QString s=(rl.isEmpty())?"":resiCom->currentText(); |
| 1234 | emit insertISOR(esd1line->text().toDouble(),esd2line->text().toDouble(),mol->selectedatoms,s); |
| 1235 | mol->selectedatoms.clear(); |
| 1236 | } |
| 1237 | else |
| 1238 | { |
| 1239 | if(a == QDialog::Rejected) |
| 1240 | dia->close(); |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | void PlayOpenGL::addRIGU(){ |
| 1245 | QDialog *dia = new QDialog(); |
| 1246 | dia->setWindowTitle(tr("RIGU: ADP restraint")); |
| 1247 | dia->setModal(false); |
| 1248 | |
| 1249 | QGridLayout *grid = new QGridLayout(dia); |
| 1250 | QLineEdit *esd1line = new QLineEdit(dia); |
| 1251 | QLineEdit *esd2line = new QLineEdit(dia); |
| 1252 | QLabel *esd1 = new QLabel("ESD1:", dia); |
| 1253 | QLabel *esd2 = new QLabel("ESD2:", dia); |
| 1254 | // Set default value for distance and esd |
| 1255 | esd1line->setText("0.004"); |
| 1256 | esd2line->setText("0.004"); |
| 1257 | int i(0); // index for position of widgets in the container |
| 1258 | grid->addWidget(esd1,i,0); |
| 1259 | grid->addWidget(esd1line,i++,1); |
| 1260 | grid->addWidget(esd2,i,0); |
| 1261 | grid->addWidget(esd2line,i++,1); |
| 1262 | QStringList rl = resis(); |
| 1263 | QComboBox *resiCom = NULL; |
| 1264 | if (!rl.isEmpty()){ |
| 1265 | QLabel *resi = new QLabel("Residue specific",dia); |
| 1266 | resiCom = new QComboBox(dia); |
| 1267 | resiCom->addItem(""); |
| 1268 | resiCom->addItems(rl); |
| 1269 | grid->addWidget(resi,i,0); |
| 1270 | grid->addWidget(resiCom,i++,1); |
| 1271 | } |
| 1272 | |
| 1273 | QDialogButtonBox *buttonBox = new QDialogButtonBox(); |
| 1274 | |
| 1275 | QPushButton *OkButton; |
| 1276 | QPushButton *CancelButton; |
| 1277 | |
| 1278 | OkButton = buttonBox->addButton(QDialogButtonBox::Ok); |
| 1279 | CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); |
| 1280 | |
| 1281 | buttonBox->setOrientation(Qt::Horizontal); |
| 1282 | |
| 1283 | grid->addWidget(buttonBox,i,0); |
| 1284 | |
| 1285 | dia->setLayout(grid); |
| 1286 | connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept())); |
| 1287 | connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject())); |
| 1288 | |
| 1289 | dia->show(); |
| 1290 | int a = dia->exec(); |
| 1291 | |
| 1292 | if(a == QDialog::Accepted) |
| 1293 | { |
| 1294 | // read value from value line |
| 1295 | QString s=(rl.isEmpty())?"":resiCom->currentText(); |
| 1296 | emit insertRIGU(esd1line->text().toDouble(),esd2line->text().toDouble(),mol->selectedatoms,s); |
| 1297 | mol->selectedatoms.clear(); |
| 1298 | } |
| 1299 | else |
| 1300 | { |
| 1301 | if(a == QDialog::Rejected) |
| 1302 | dia->close(); |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | void PlayOpenGL::addSADI() { |
| 1307 | //! Adds SADI restraints between the selected atom and all bonded atoms. |
| 1308 | QAction *action = qobject_cast<QAction *>(sender()); |
| 1309 | int index=-1; |
| 1310 | if (action) |
| 1311 | index=action->data().toInt(); |
| 1312 | else index=-1; |
| 1313 | if (index>mol->asymm.size()) index=-1; |
| 1314 | if (index!=-1) { |
| 1315 | emit insertSADI(index); |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | QList<int> PlayOpenGL::lastClicked(){ |
| 1320 | QList<int> pppp; |
| 1321 | //if ((ppp>=0)&&(ppp<mol->showatoms.size())&&(ppp!=pp)&&(ppp!=p)) pppp.append(ppp); |
| 1322 | if (( p>=0)&&( p<mol->showatoms.size())) pppp.append(p); |
| 1323 | if (( pp>=0)&&( pp<mol->showatoms.size())&&(pp!=p)) pppp.append(pp); |
| 1324 | return pppp; |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | void PlayOpenGL::addSIMU(){ |
| 1329 | QDialog *dia = new QDialog(); |
| 1330 | dia->setWindowTitle(tr("SIMU: ADP restraint")); |
| 1331 | dia->setModal(false); |
| 1332 | |
| 1333 | QGridLayout *grid = new QGridLayout(dia); |
| 1334 | QLineEdit *esd1line = new QLineEdit(dia); |
| 1335 | QLineEdit *esd2line = new QLineEdit(dia); |
| 1336 | QLineEdit *dmaxline = new QLineEdit(dia); |
| 1337 | QLabel *esd1 = new QLabel("ESD1:", dia); |
| 1338 | QLabel *esd2 = new QLabel("ESD2:", dia); |
| 1339 | QLabel *dmax = new QLabel("dmax:", dia); |
| 1340 | // Set default value for distance and esd |
| 1341 | esd1line->setText("0.04"); |
| 1342 | esd2line->setText("0.08"); |
| 1343 | dmaxline->setText("2.00"); |
| 1344 | |
| 1345 | grid->addWidget(esd1,0,0); |
| 1346 | grid->addWidget(esd1line,0,1); |
| 1347 | grid->addWidget(esd2,1,0); |
| 1348 | grid->addWidget(esd2line,1,1); |
| 1349 | grid->addWidget(dmax,2,0); |
| 1350 | grid->addWidget(dmaxline,2,1); |
| 1351 | QStringList rl = resis(); |
| 1352 | QComboBox *resiCom = NULL; |
| 1353 | if (!rl.isEmpty()){ |
| 1354 | QLabel *resi = new QLabel("Residue specific", dia); |
| 1355 | resiCom = new QComboBox(dia); |
| 1356 | // Usually you want to define residue restraints with numbers at the atom: |
| 1357 | resiCom->addItem(""); |
| 1358 | resiCom->addItems(rl); |
| 1359 | grid->addWidget(resi,3,0); |
| 1360 | grid->addWidget(resiCom,3,1); |
| 1361 | } |
| 1362 | |
| 1363 | QDialogButtonBox *buttonBox = new QDialogButtonBox(); |
| 1364 | |
| 1365 | QPushButton *OkButton; |
| 1366 | QPushButton *CancelButton; |
| 1367 | |
| 1368 | OkButton = buttonBox->addButton(QDialogButtonBox::Ok); |
| 1369 | CancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); |
| 1370 | |
| 1371 | buttonBox->setOrientation(Qt::Horizontal); |
| 1372 | |
| 1373 | grid->addWidget(buttonBox,4,0); |
| 1374 | |
| 1375 | dia->setLayout(grid); |
| 1376 | connect(OkButton, SIGNAL(clicked()), dia, SLOT(accept())); |
| 1377 | connect(CancelButton, SIGNAL(clicked()), dia, SLOT(reject())); |
| 1378 | |
| 1379 | dia->show(); |
| 1380 | int a = dia->exec(); |
| 1381 | |
| 1382 | if(a == QDialog::Accepted) |
| 1383 | { |
| 1384 | // read value from value line |
| 1385 | QString s=(rl.isEmpty())?"":resiCom->currentText(); |
| 1386 | emit insertSIMU(esd1line->text().toDouble(),esd2line->text().toDouble(),dmaxline->text().toDouble(),mol->selectedatoms,s); |
| 1387 | mol->selectedatoms.clear(); |
| 1388 | } |
| 1389 | else |
| 1390 | { |
| 1391 | if(a == QDialog::Rejected) |
| 1392 | dia->close(); |
| 1393 | } |
| 1394 | |
| 1395 | } |
| 1396 | |
| 1397 | QStringList PlayOpenGL::resis(){ |
| 1398 | QStringList l; |
| 1399 | for (int i=0; i<mol->asymm.size(); i++){ |
| 1400 | if (mol->asymm.at(i).an<0)continue; |
| 1401 | if (mol->asymm.at(i).resiNr>0){ |
| 1402 | if (!l.contains(QString::number(mol->asymm.at(i).resiNr),Qt::CaseInsensitive)) |
| 1403 | l.append(QString::number(mol->asymm.at(i).resiNr)); |
| 1404 | if (!l.contains(mol->asymm.at(i).ResiClass)) |
| 1405 | l.append(mol->asymm.at(i).ResiClass); |
| 1406 | } |
| 1407 | } |
| 1408 | if (!l.isEmpty()) l.insert(0,"*"); |
| 1409 | return l; |
| 1410 | } |
| 1411 | |
| 1412 | void PlayOpenGL::singleBondDistance(){ |
| 1413 | if (mol->selectedatoms.size()!=2)return; |
| 1414 | QWidgetList wl = QApplication::allWidgets(); |
| 1415 | for (int i=0; i<wl.size(); i++){ |
| 1416 | if (wl.at(i)->objectName()=="DFIX_DIST"){ |
| 1417 | QLineEdit *valueline = qobject_cast<QLineEdit *>(wl[i]); |
| 1418 | valueline->setText(QString::number(0.01*(mol->Kovalenz_Radien[mol->selectedatoms.at(0).an]+mol->Kovalenz_Radien[mol->selectedatoms.at(1).an]),10,3)); |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | void PlayOpenGL::changeEnviRange(){//! a dialog for a new ChGL.envirange. |
| 1424 | bool ok; |
| 1425 | double r=QInputDialog::getDouble (nullptr,"Envi-Range", "change environment range", envirange,0.7,8.0,2,&ok); |
| 1426 | if (ok) envirange=r; |
| 1427 | QAction *action = qobject_cast<QAction *>(sender()); |
| 1428 | int index=0; |
| 1429 | if (action) |
| 1430 | index=action->data().toInt(); |
| 1431 | else index=rotze;//return; |
| 1432 | if (index<0) return; |
| 1433 | if (ok) envi(); |
| 1434 | } |
| 1435 | |
| 1436 | void PlayOpenGL::growEnvi(){ |
| 1437 | QAction *action = qobject_cast<QAction *>(sender()); |
| 1438 | int index=0; |
| 1439 | if (action) |
| 1440 | index=action->data().toInt(); |
| 1441 | else index=rotze;//return; |
| 1442 | if (index<0) return; |
| 1443 | if (!isMainWindow) return; |
| 1444 | if (index>=mol->asymm.size())return; |
| 1445 | mol->enviSDM(envirange); |
| 1446 | |
| 1447 | QString systr; |
| 1448 | QStringList bs; |
| 1449 | for (int i = 0; i < mol->envi_sdm.size(); i++){ |
| 1450 | if ((mol->envi_sdm.at(i).a2==index)&&mol->envi_sdm.at(i).d<envirange) { |
| 1451 | if ((!mol->envi_sdm.at(i).covalent)&&(enviCova->isChecked())) continue; |
| 1452 | if ((mol->asymm[mol->envi_sdm.at(i).a1].an==-1)&&(enviNoQ->isChecked())) continue; |
| 1453 | bool symm=((mol->envi_sdm.at(i).sn)||(!(mol->envi_sdm.at(i).floorD==V3(0,0,0)))); |
| 1454 | if (symm) { |
| 1455 | 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); |
| 1456 | if (!bs.contains(sss)){ |
| 1457 | bs.append(sss); |
| 1458 | } |
| 1459 | systr=QString("%1%2").arg(QString::fromUtf8("»")).arg(bs.indexOf(sss)+1); |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | mol->usedSymmetry+=bs; |
| 1464 | mol->complete(); |
| 1465 | |
| 1466 | fuse->setVisible(true); |
| 1467 | grow->setVisible(false); |
| 1468 | emit bigmessage(mol->HumanSymmetry); |
| 1469 | makeAtoms(mol->showatoms); |
| 1470 | makeBonds(mol->showatoms, mol->showbonds, mol->lbonds, mol->theH_Bonds); |
| 1471 | update(); |
| 1472 | } |
| 1473 | |
| 1474 | void PlayOpenGL::showEnvi(){ |
| 1475 | QAction *action = qobject_cast<QAction *>(sender()); |
| 1476 | int index=0; |
| 1477 | if (action) |
| 1478 | index=action->data().toInt(); |
| 1479 | else index=rotze;//return; |
| 1480 | if (index<0) return; |
| 1481 | if (!isMainWindow) return; |
| 1482 | if (index>=mol->asymm.size())return; |
| 1483 | mol->enviSDM(envirange); |
| 1484 | |
| 1485 | QString systr; |
| 1486 | QStringList bs; |
| 1487 | for (int i = 0; i < mol->envi_sdm.size(); i++){ |
| 1488 | if ((mol->envi_sdm.at(i).a2==index)&&mol->envi_sdm.at(i).d<envirange) { |
| 1489 | if ((!mol->envi_sdm.at(i).covalent)&&(enviCova->isChecked())) continue; |
| 1490 | if ((mol->asymm[mol->envi_sdm.at(i).a1].an==-1)&&(enviNoQ->isChecked())) continue; |
| 1491 | bool symm=((mol->envi_sdm.at(i).sn)||(!(mol->envi_sdm.at(i).floorD==V3(0,0,0)))); |
| 1492 | if (symm) { |
| 1493 | 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); |
| 1494 | if (!bs.contains(sss)){ |
| 1495 | bs.append(sss); |
| 1496 | } |
| 1497 | systr=QString("%1%2").arg(QString::fromUtf8("»")).arg(bs.indexOf(sss)+1); |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | mol->usedSymmetry+=bs; |
| 1502 | mol->complete(); |
| 1503 | V3 p0 = mol->asymm.at(index).pos; |
| 1504 | double er2=envirange*envirange; |
| 1505 | for (int i = 0; i < mol->showatoms.size(); i++){ |
| 1506 | double d = Distance(p0, mol->showatoms.at(i).pos); |
| 1507 | //printf("s env %f %d %d\n", d, i, mol->showatoms.size()); |
| 1508 | if (d > er2) mol->showatoms[i].hidden=1; |
| 1509 | } |
| 1510 | hiddenThings = true; |
| 1511 | fuse->setVisible(true); |
| 1512 | grow->setVisible(false); |
| 1513 | emit bigmessage(mol->HumanSymmetry); |
| 1514 | //printf("show envi\n"); |
| 1515 | makeAtoms(mol->showatoms); |
| 1516 | //printf("show envi\n"); |
| 1517 | makeBonds(mol->showatoms, mol->showbonds, mol->lbonds, mol->theH_Bonds); |
| 1518 | |
| 1519 | makeSelectedAtoms(); |
| 1520 | // murx=-__LINE__; |
| 1521 | updateBondActions(); |
| 1522 | //printf("show envi\n"); |
| 1523 | update(); |
| 1524 | } |
| 1525 | |
| 1526 | void PlayOpenGL::envi(){ |
| 1527 | /*! Finds neighboring atoms around a ChGL.envirange the spezified atom and passes a html table via ChGL.bigmessage |
| 1528 | * Feeds ChGL.enviPositions, ChGL.labs and ChGL.enviKat. |
| 1529 | * sets the rotation center to the spezified atom. |
| 1530 | * */ |
| 1531 | printf("->-ENVI-<- %d\n",mol->asymm.size()); |
| 1532 | QAction *action = qobject_cast<QAction *>(sender()); |
| 1533 | int index=0; |
| 1534 | if (action) |
| 1535 | index=action->data().toInt(); |
| 1536 | else index=rotze;//return; |
| 1537 | if (index<0) return; |
| 1538 | if (!isMainWindow){ |
| 1539 | enviP0=mol->showatoms.at(index).pos; |
| 1540 | |
| 1541 | for (int i=0; i<mol->showatoms.size(); i++){ |
| 1542 | double d = sqrt(Distance(mol->showatoms.at(index).pos,mol->showatoms.at(i).pos)); |
| 1543 | int an1=mol->showatoms.at(i).an; |
| 1544 | int an2=mol->showatoms.at(index).an; |
| 1545 | double dddd=(mol->Kovalenz_Radien[an1]+ mol->Kovalenz_Radien[an2])*0.012; |
| 1546 | bool cov=(d<dddd); |
| 1547 | if (d<envirange) { |
| 1548 | if ((!cov)&&(enviCova->isChecked())) continue; |
| 1549 | if ((an1<0)&&(enviNoQ->isChecked())) continue; |
| 1550 | enviPositions.append(mol->showatoms.at(i).pos); |
| 1551 | enviKat.append((cov)?1:0); |
| 1552 | labs.append(mol->showatoms.at(i).Label); |
| 1553 | } |
| 1554 | } |
| 1555 | enviButt->show(); |
| 1556 | enviSelect->show(); |
| 1557 | makeEnvi(); |
| 1558 | return; |
| 1559 | } |
| 1560 | if (index>=mol->asymm.size())return; |
| 1561 | mol->enviSDM(envirange); |
| 1562 | enviPositions.clear(); |
| 1563 | enviKat.clear(); |
| 1564 | labs.clear(); |
| 1565 | QList<bool> covs; |
| 1566 | //pause=true; |
| 1567 | |
| 1568 | V3 ppc,ppf,p0; |
| 1569 | // int ssy=0; |
| 1570 | QString systr; |
| 1571 | QStringList bs; |
| 1572 | QString info; |
| 1573 | enviP0=mol->asymm.at(index).pos; |
| 1574 | info.append(QString("<hr><b>Environment of %1 </b><table border=\"0\" cellspacing=\"0\" cellpadding=\"5\">").arg(mol->asymm[index].Label)); |
| 1575 | for (int i = 0; i < mol->envi_sdm.size(); i++){ |
| 1576 | if ((mol->envi_sdm.at(i).a2==index)&&mol->envi_sdm.at(i).d<envirange) { |
| 1577 | if ((!mol->envi_sdm.at(i).covalent)&&(enviCova->isChecked())) continue; |
| 1578 | if ((mol->asymm[mol->envi_sdm.at(i).a1].an==-1)&&(enviNoQ->isChecked())) continue; |
| 1579 | ppf=mol->cell.symmops.at(mol->envi_sdm.at(i).sn) * |
| 1580 | mol->asymm[mol->envi_sdm.at(i).a1].frac + |
| 1581 | mol->cell.trans.at(mol->envi_sdm.at(i).sn) -//- |
| 1582 | mol->envi_sdm.at(i).floorD; |
| 1583 | mol->frac2kart(ppf,ppc); |
| 1584 | mol->frac2kart(mol->asymm[index].frac,p0); |
| 1585 | /* |
| 1586 | if (fabs(mol->envi_sdm.at(i).d-sqrt(Distance(p0,ppc)))>0.5){ |
| 1587 | ppf=mol->cell.symmops.at(mol->envi_sdm.at(i).sn) * |
| 1588 | mol->asymm[mol->envi_sdm.at(i).a2].frac - |
| 1589 | mol->cell.trans.at(mol->envi_sdm.at(i).sn) - |
| 1590 | mol->envi_sdm.at(i).floorD; |
| 1591 | mol->frac2kart(ppf,ppc); |
| 1592 | |
| 1593 | }// */ |
| 1594 | enviPositions.append(ppc); |
| 1595 | covs.append(mol->envi_sdm.at(i).covalent); |
| 1596 | enviKat.append((mol->envi_sdm.at(i).covalent)?1:0); |
| 1597 | if((abs(mol->asymm[mol->envi_sdm.at(i).a1].an-7)<2) |
| 1598 | &&(abs(mol->asymm[mol->envi_sdm.at(i).a2].an-7)<2) |
| 1599 | &&(fabs(mol->envi_sdm.at(i).d-2.725)<0.275)){enviKat.last()=2;} |
| 1600 | |
| 1601 | 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;} |
| 1602 | 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;} |
| 1603 | bool symm=((mol->envi_sdm.at(i).sn)||(!(mol->envi_sdm.at(i).floorD==V3(0,0,0)))); |
| 1604 | if (symm) { |
| 1605 | 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); |
| 1606 | if (!bs.contains(sss)){ |
| 1607 | bs.append(sss); |
| 1608 | } |
| 1609 | |
| 1610 | systr=QString("%1%2").arg(QString::fromUtf8("»")).arg(bs.indexOf(sss)+1); |
| 1611 | labs.append(mol->asymm[ mol->envi_sdm.at(i).a1].Label+systr); |
| 1612 | } |
| 1613 | else labs.append(mol->asymm[ mol->envi_sdm.at(i).a1].Label); |
| 1614 | info.append(QString("<tr><th style=\"background:%6\" >%1%4</th><td style=\"background:%5\" >%7<font color=%3> %2 Å</font></b></td>") |
| 1615 | .arg(mol->asymm[ mol->envi_sdm.at(i).a1].Label) |
| 1616 | .arg(mol->envi_sdm.at(i).d,8,'f',3) |
| 1617 | .arg((mol->envi_sdm.at(i).covalent)?"green":"black") |
| 1618 | .arg(symm?systr:"").arg((labs.size()%2)?"#eeeeee":"white") |
| 1619 | .arg((labs.size()%2)?"#d4d4e4":"#efefff") |
| 1620 | .arg((mol->envi_sdm.at(i).covalent)?"<b>":"")); |
| 1621 | for (int j=0; j<enviPositions.size()-1; j++){ |
| 1622 | double w= |
| 1623 | mol->winkel(p0-enviPositions.at(j), |
| 1624 | p0-enviPositions.last()); |
| 1625 | // 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); |
| 1626 | info.append(QString("<td style=\"background:%3\" align=right>%4<font color=%2> %1°</font></b></td>") |
| 1627 | .arg(w,8,'f',2) |
| 1628 | .arg(((mol->envi_sdm.at(i).covalent)&&(covs.at(j)))?"green":"black") |
| 1629 | .arg(((j+1)%2)?(labs.size()%2)?"#d4d4d4":"#e4e4e4":(labs.size()%2)?"#eeeeee":"#ffffff") |
| 1630 | .arg(((mol->envi_sdm.at(i).covalent)&&(covs.at(j)))?"<b>":"")); |
| 1631 | |
| 1632 | } |
| 1633 | info.append("</tr>\n"); |
| 1634 | } |
| 1635 | } |
| 1636 | info.append("<tr><td style=\"background:#efefff\"></td><td style=\"background:#efefff\"></td>"); |
| 1637 | for (int j=0; j<enviPositions.size()-1; j++){ |
| 1638 | info.append(QString("<th style=\"background:%2\">%1</th>").arg(labs.at(j)).arg(((j+1)%2)?"#d4d4e4":"#efefff")); |
| 1639 | } |
| 1640 | QString symml=""; |
| 1641 | for (int j=0; j<bs.size(); j++){ |
| 1642 | symml+=mol->symmcode2human(bs.at(j),j+1); |
| 1643 | } |
| 1644 | info.append(QString("</tr>\n</table>%1<hr>\n").arg(symml)); |
| 1645 | emit bigmessage(info); |
| 1646 | enviButt->show(); |
| 1647 | enviSelect->show(); |
| 1648 | //pause=false; |
| 1649 | makeEnvi(); |
| 1650 | setRotationCenter(index); |
| 1651 | printf("--ENVI-- %d %d\n",enviButt->isVisible(),enviSelect->isVisible()); |
| 1652 | update(); |
| 1653 | |
| 1654 | } |
| 1655 | |
| 1656 | //* |
| 1657 | void PlayOpenGL::clearEnvi(){ |
| 1658 | // *! Clears ChGL.enviPositions, ChGL.enviKat. and ChGL.labs * / |
| 1659 | if (enviPositions.isEmpty()) return; |
| 1660 | enviPositions.clear(); |
| 1661 | labs.clear(); |
| 1662 | enviKat.clear(); |
| 1663 | enviButt->hide(); |
| 1664 | enviSelect->hide(); |
| 1665 | makeEnvi(); |
| 1666 | if (isMainWindow) rotCenter(); |
| 1667 | } |
| 1668 | |
| 1669 | void PlayOpenGL::selectEnvi(){ |
| 1670 | mol->selectedatoms.clear(); |
| 1671 | if (rotze>=0) { |
| 1672 | mol->selectedatoms.append(mol->showatoms[rotze]); |
| 1673 | mol->selectedatoms.last().style=rotze; |
| 1674 | } |
| 1675 | for (int i=0; i<mol->showatoms.size(); i++){ |
| 1676 | for (int j=0; j< enviPositions.size(); j++){ |
| 1677 | if (mol->showatoms.at(i).pos==enviPositions.at(j)) { |
| 1678 | mol->selectedatoms.append(mol->showatoms[i]); |
| 1679 | mol->selectedatoms.last().style=i; |
| 1680 | } |
| 1681 | } |
| 1682 | } |
| 1683 | updateBondActions(); |
| 1684 | update(); |
| 1685 | |
| 1686 | } |
| 1687 | // */ |
| 1688 | |
| 1689 | |
| 1690 | |
| 1691 | void PlayOpenGL::setRotationCenter(){ |
| 1692 | //! Sets the rotation center to the spezified atom |
| 1693 | QAction *action = qobject_cast<QAction *>(sender()); |
| 1694 | int index=0; |
| 1695 | if (action) |
| 1696 | index=action->data().toInt(); |
| 1697 | else return; |
| 1698 | if (index==(int)((GLuint)-1))return; |
| 1699 | rotze=((int)index<mol->showatoms.size())?index:-1; |
| 1700 | if (rotze>-1){ |
| 1701 | rCenter->show(); |
| 1702 | homeXY(); |
| 1703 | updateSceenAtoms(); |
| 1704 | } |
| 1705 | update(); |
| 1706 | } |
| 1707 | |
| 1708 | void PlayOpenGL::setRotationCenter(V3 center){ |
| 1709 | // printf("%f %f %f \n%f %f %f\n", altemitte.x, altemitte.y, altemitte.z, center.x, center.y, center.z); |
| 1710 | //altcenter=center; |
| 1711 | rotze=-76185;//zip code |
| 1712 | rCenter->show(); |
| 1713 | update(); |
| 1714 | } |
| 1715 | |
| 1716 | |
| 1717 | void PlayOpenGL::setRotationCenter(int rz){ |
| 1718 | /*! Sets the rotation center to the spezified atom |
| 1719 | * @param index of the spezified atom. |
| 1720 | */ |
| 1721 | rotze=((int)rz<mol->showatoms.size())?rz:-1; |
| 1722 | if (rotze>-1){ |
| 1723 | rCenter->show(); |
| 1724 | homeXY(); |
| 1725 | updateSceenAtoms(); |
| 1726 | } |
| 1727 | update(); |
| 1728 | } |
| 1729 | |
| 1730 | |
| 1731 | void PlayOpenGL::findPivot(){ |
| 1732 | //printf("findpv %d %p\n",altpivot,whyNotSplit); |
| 1733 | if ((altpivot)||(whyNotSplit==nullptr)) return; |
| 1734 | // for(int i=0; i<mol->showatoms.size(); i++) mol->showatoms[i].hidden=0; |
| 1735 | if (mol->selectedatoms.size()<3) { |
| 1736 | whyNotSplit->setText("<h2>Select at least 3 atoms first.</h2>"); |
| 1737 | emit splitable(canSplitRotate()); |
| 1738 | return; |
| 1739 | } |
| 1740 | //printf("findPivot: "); |
| 1741 | pivot=-1;pivot2=-1; |
| 1742 | emit pivot2Changed(pivot2); |
| 1743 | emit pivot1Changed(pivot); |
| 1744 | int molidx=-1,mi; |
| 1745 | seat.clear(); |
| 1746 | for (int i=0; i<mol->selectedatoms.size();i++){//all selectet atoms have to be in the same molecule |
| 1747 | int ii=mol->selectedatoms.at(i).style; |
| 1748 | if ((ii<0)||(ii>=mol->asymm.size()))continue; |
| 1749 | mi=mol->asymm.at(ii).molindex; |
| 1750 | if ((molidx!=-1)&&(molidx!=mi)) { |
| 1751 | whyNotSplit->setText("<h2>Selected atoms have to be in the same molecule.</h2>"); |
| 1752 | emit splitable(canSplitRotate()); |
| 1753 | return; |
| 1754 | } |
| 1755 | molidx=mi; |
| 1756 | seat.append(ii); |
| 1757 | } |
| 1758 | int atinmol=0; |
| 1759 | for (int i=0; i<mol->asymm.size();i++){ |
| 1760 | if (mol->asymm.at(i).molindex==molidx) atinmol++; |
| 1761 | } |
| 1762 | //printf("==%d\n",__LINE__); |
| 1763 | if (mol->selectedatoms.size()>atinmol) { |
| 1764 | 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>"); |
| 1765 | emit splitable(canSplitRotate()); |
| 1766 | return; |
| 1767 | } //only a part of the molecule may be selected |
| 1768 | // */ |
| 1769 | for (int i=0;i<seat.size();i++){ |
| 1770 | //printf("**%d %d\n",mol->knoepfe.size(),seat.at(i)); |
| 1771 | int isin=0,ks=mol->knoepfe.at(seat.at(i)).neighbors.size(); |
| 1772 | for (int j=0;j<ks; j++){ |
| 1773 | int nb=mol->knoepfe.at(seat.at(i)).neighbors.at(j); |
| 1774 | if (seat.contains(nb))isin++; |
| 1775 | } |
| 1776 | if ((pivot==-1)&&(isin<ks)) {pivot=seat.at(i);emit pivot1Changed(pivot);} |
| 1777 | else if (isin<ks) { |
| 1778 | whyNotSplit->setText("<h2>Only one atom is allowed to have bonds to none selected atoms.</h2>"); |
| 1779 | emit splitable(canSplitRotate()); |
| 1780 | return; |
| 1781 | } |
| 1782 | } |
| 1783 | //printf("==%d\n",__LINE__); |
| 1784 | if (pivot<0) { |
| 1785 | emit splitable(canSplitRotate()); |
| 1786 | return; |
| 1787 | } |
| 1788 | int isin=0,ks=mol->knoepfe.at(pivot).neighbors.size(); |
| 1789 | for (int j=0;j<ks; j++){ |
| 1790 | int nb=mol->knoepfe.at(pivot).neighbors.at(j); |
| 1791 | if (seat.contains(nb)){pivot2=nb;emit pivot2Changed(pivot2);isin++;} |
| 1792 | } |
| 1793 | if (isin>1) { |
| 1794 | whyNotSplit->setText("<h2>pivot atom may be bonded to only one selected atoms.</h2>"); |
| 1795 | emit splitable(canSplitRotate()); |
| 1796 | return; |
| 1797 | } |
| 1798 | whyNotSplit->setText(QString("<h2>You can rotate around %1=%2</h2>").arg(mol->asymm.at(pivot).Label).arg(mol->asymm.at(pivot2).Label)); |
| 1799 | emit splitable(canSplitRotate()); |
| 1800 | } |
| 1801 | |
| 1802 | void PlayOpenGL::splitRotate(){ |
| 1803 | mol->splitLbonds.clear(); |
| 1804 | mol->splitRbonds.clear(); |
| 1805 | mol->splitLeftAtoms.clear(); |
| 1806 | mol->splitRightAtoms.clear(); |
| 1807 | if (freeRot->isChecked()){ |
| 1808 | // updateBondActions(); |
| 1809 | } |
| 1810 | //printf("?splitRotate\n"); |
| 1811 | if (!canSplitRotate()){makeSplitRot();return;} |
| 1812 | //printf("splitRotate!\n"); |
| 1813 | if (!freeRot->isChecked()&&((pivot<0)||(pivot2<0))) {makeSplitRot();return;} |
| 1814 | for (int i=0; i<seat.size();i++){ |
| 1815 | mol->splitLeftAtoms.append(mol->asymm[seat.at(i)]); |
| 1816 | mol->splitRightAtoms.append(mol->asymm[seat.at(i)]); |
| 1817 | // if (seat.at(i)!=pivot) mol->showatoms[seat.at(i)].hidden=1; |
| 1818 | } |
| 1819 | /*printf("?splitRotate %d %d %d\n", |
| 1820 | mol->splitLeftAtoms.size(), |
| 1821 | mol->splitRightAtoms.size(), |
| 1822 | seat.size());*/ |
| 1823 | //mol->selectedatoms.clear(); |
| 1824 | //printf("%p %p\n", angle1, angle2); |
| 1825 | double arr[4]; |
| 1826 | arr[0]=angle1->value(); |
| 1827 | V3 ax=((manualAx->isChecked())||(freeRot->isChecked()))? |
| 1828 | Normalize(V3(axx->value(),axy->value(),axz->value())): |
| 1829 | Normalize(mol->asymm.at(pivot).pos-mol->asymm.at(pivot2).pos); |
| 1830 | arr[1]=ax.x; |
| 1831 | arr[2]=ax.y; |
| 1832 | arr[3]=ax.z; |
| 1833 | if ((!manualAx->isChecked())&&(!freeRot->isChecked())){ |
| 1834 | axx->setValue(ax.x); |
| 1835 | axy->setValue(ax.y); |
| 1836 | axz->setValue(ax.z); |
| 1837 | } |
| 1838 | if (!freeRot->isChecked()){ |
| 1839 | screenRotx=ax; |
| 1840 | Matrix M90 = mol->rotarb(90,ax); |
| 1841 | V3 cx = ax % V3(0,1,0); |
| 1842 | |
| 1843 | |
| 1844 | V3 cy = Normalize(M90 * cx); |
| 1845 | V3 cz = ax % cy; |
| 1846 | |
| 1847 | screenRoty = Normalize(cz); |
| 1848 | } |
| 1849 | if ((freeRot->isChecked())&&(pivot1cb->isEnabled())){ |
| 1850 | V3 o(0,0,0); |
| 1851 | for (int i=0; i<mol->selectedatoms.size(); i++){ |
| 1852 | o+=mol->selectedatoms.at(i).pos; |
| 1853 | } |
| 1854 | o*=1.0/mol->selectedatoms.size(); |
| 1855 | orgx->setValue(o.x); |
| 1856 | orgy->setValue(o.y); |
| 1857 | orgz->setValue(o.z); |
| 1858 | } |
| 1859 | if (freeRot->isChecked()){ |
| 1860 | V3 o(0,0,0); |
| 1861 | for (int i=0; i<mol->splitLeftAtoms.size(); i++){ |
| 1862 | o+=mol->splitLeftAtoms.at(i).pos; |
| 1863 | } |
| 1864 | o*=1.0/mol->splitLeftAtoms.size(); |
| 1865 | V3 no(orgx->value(), orgy->value(), orgz->value()); |
| 1866 | for (int i=0; i<mol->splitLeftAtoms.size(); i++){ |
| 1867 | mol->splitLeftAtoms[i].pos+=no-o; |
| 1868 | } |
| 1869 | } |
| 1870 | pivot1cb->setEnabled(!freeRot->isChecked()); |
| 1871 | pivot2cb->setEnabled(!freeRot->isChecked()); |
| 1872 | |
| 1873 | |
| 1874 | Matrix R = ((freeRot->isChecked()))?freeRotMat : mol->rotarb(arr); |
| 1875 | /* |
| 1876 | V3 axe = V3((R.m23 - R.m32), (R.m31 - R.m13), (R.m12 - R.m21)); |
| 1877 | double _si = sqrt(Norm(axe)) / 2.0; |
| 1878 | double _co = ((R.m11 + R.m22 + R.m33) - 1.0)/ 2.0; |
| 1879 | axe=Normalize(axe); |
| 1880 | double wt = atan2(_si, _co) / M_PI * 180.0; |
| 1881 | printf("%f grad %f %f %f\n", wt, axe.x, axe.y, axe.z); |
| 1882 | */ |
| 1883 | arr[0]=-angle2->value(); |
| 1884 | Matrix Rbar=mol->rotarb(arr); |
| 1885 | SRorg=V3(orgx->value(), orgy->value(), orgz->value()); |
| 1886 | if (!freeRot->isChecked()){ |
| 1887 | SRorg=mol->asymm.at(pivot).pos; |
| 1888 | orgx->setValue(SRorg.x); |
| 1889 | orgy->setValue(SRorg.y); |
| 1890 | orgz->setValue(SRorg.z); |
| 1891 | } |
| 1892 | for (int i=0; i<seat.size();i++){ |
| 1893 | mol->splitLeftAtoms[i].pos=R*(mol->splitLeftAtoms.at(i).pos-SRorg)+SRorg; |
| 1894 | mol->splitRightAtoms[i].pos=Rbar*(mol->splitRightAtoms.at(i).pos-SRorg)+SRorg; |
| 1895 | } |
| 1896 | mol->splitRbonds=mol->connecting(mol->splitRightAtoms,true); |
| 1897 | mol->splitLbonds=mol->connecting(mol->splitLeftAtoms,true); |
| 1898 | //rotze=pivot; |
| 1899 | makeSplitRot(); |
| 1900 | update(); |
| 1901 | } |
| 1902 | |
| 1903 | bool PlayOpenGL::canSplitRotate(){ |
| 1904 | //printf("canSplitRotate? %d \n",(freeRot!=nullptr)&&(freeRot->isChecked())&&(mol->selectedatoms.size()>2)); |
| 1905 | if (freeRot==nullptr) return false;//!!! |
| 1906 | if ((freeRot!=nullptr)&&(freeRot->isChecked())&&(mol->selectedatoms.size()>2)) return true; |
| 1907 | if ((pivot>-1)&&(pivot2>-1)&&(pivot<mol->asymm.size())&&(pivot2<mol->asymm.size())&&(mol->selectedatoms.size()>2)) return true; |
| 1908 | return false; |
| 1909 | } |
| 1910 | |
| 1911 | |
| 1912 | void PlayOpenGL::highliteQPeak(double co){ |
| 1913 | |
| 1914 | inFocus=-1; |
| 1915 | //printf("co %f\n",co) |
| 1916 | for (int i=0;i<mol->showatoms.size();i++){ |
| 1917 | if (mol->showatoms[i].an==-66) continue; |
| 1918 | if (mol->showatoms[i].an>=0) continue; |
| 1919 | if (mol->showatoms[i].hidden)continue; |
| 1920 | if (mol->showatoms[i].peakHeight<=co) { |
| 1921 | inFocus=i; |
| 1922 | emit message(QString("%1 %2").arg(mol->showatoms.at(inFocus).Label).arg(mol->showatoms.at(inFocus).peakHeight)); |
| 1923 | break; |
| 1924 | } |
| 1925 | } |
| 1926 | update(); |
| 1927 | } |
| 1928 | |
| 1929 | void PlayOpenGL::renderText(const QVector2D &scpos, const QString &text, int an, int pts){ |
| 1930 | QPainter painter(this); |
| 1931 | |
| 1932 | QFont f = myFont; |
| 1933 | f.setPointSize((an<0)? (pts*2)/3: pts); |
| 1934 | QFontMetrics mtr(f); |
| 1935 | QRect rc=mtr.boundingRect(text+"L"); |
| 1936 | QImage image(rc.width(),rc.height(), QImage::Format_ARGB32_Premultiplied); |
| 1937 | image.fill(0); |
| 1938 | QPainter p; |
| 1939 | p.begin(&image); |
| 1940 | p.setPen(labelColor); |
| 1941 | p.setBackground(Qt::NoBrush); |
| 1942 | p.setFont(f); |
| 1943 | p.drawText(image.rect(), Qt::AlignCenter, text); |
| 1944 | p.end(); |
| 1945 | painter.drawImage(scpos.x(), scpos.y()-rc.height(), image); |
| 1946 | painter.end(); |
| 1947 | } |
| 1948 | |
| 1949 | void PlayOpenGL::renderText(const QVector2D &scpos, const QString &text, int an){ |
| 1950 | QPainter painter(this); |
| 1951 | QFont f = (an<0)?nonAtomFont:myFont; |
| 1952 | QFontMetrics mtr(f); |
| 1953 | QRect rc=mtr.boundingRect(text+"L"); |
| 1954 | QImage image(rc.width(),rc.height(), QImage::Format_ARGB32_Premultiplied); |
| 1955 | image.fill(focusedLabelBGColor.rgba()); |
| 1956 | QPainter p; |
| 1957 | p.begin(&image); |
| 1958 | p.setPen(focusedLabelColor); |
| 1959 | p.setBackground(Qt::black); |
| 1960 | p.setFont(f); |
| 1961 | p.drawText(image.rect(), Qt::AlignCenter, text); |
| 1962 | p.end(); |
| 1963 | painter.drawImage(scpos.x(), scpos.y()-rc.height(), image); |
| 1964 | painter.end(); |
| 1965 | } |
| 1966 | |
| 1967 | |
| 1968 | void PlayOpenGL::renderText(const QVector2D &scpos, int i){ |
| 1969 | QPainter painter(this); |
| 1970 | QRect rc = altLabels.at(i).rect(); |
| 1971 | painter.drawImage(scpos.x(), scpos.y()-rc.height(), altLabels.at(i)); |
| 1972 | painter.end(); |
| 1973 | } |
| 1974 | |
| 1975 | void PlayOpenGL::renderRect(){ |
| 1976 | makeCurrent(); |
| 1977 | QPainter painter(this); |
| 1978 | QPen pen(labelColor); |
| 1979 | pen.setStyle(Qt::DotLine); |
| 1980 | painter.setPen(pen); |
| 1981 | painter.drawRect(scrx0,scry0,scrx-scrx0,scry-scry0); |
| 1982 | painter.end(); |
| 1983 | } |
| 1984 | |
| 1985 | void PlayOpenGL::renderText(const V3 &pos, const QString &text, QColor &color, uint bg){ |
| 1986 | QVector3D mapped3d = pmv.map(QVector3D(pos.x, pos.y, pos.z)); |
| 1987 | int w=width(); |
| 1988 | int h=height(); |
| 1989 | QVector2D vec2 = QVector2D((1 + mapped3d.x()) * (w / 2), (1 - mapped3d.y()) * (h / 2)); |
| 1990 | QPainter painter(this); |
| 1991 | QFontMetrics mtr(myFont); |
| 1992 | QRect rc=mtr.boundingRect(text+"L"); |
| 1993 | QImage image(rc.width(),rc.height(), QImage::Format_ARGB32_Premultiplied); |
| 1994 | image.fill(bg); |
| 1995 | QPainter p; |
| 1996 | p.begin(&image); |
| 1997 | p.setPen(color); |
| 1998 | p.setBackground(Qt::NoBrush); |
| 1999 | p.setFont(myFont); |
| 2000 | p.drawText(image.rect(), Qt::AlignCenter, text); |
| 2001 | p.end(); |
| 2002 | painter.drawImage(vec2.x(), vec2.y()-rc.height(), image); |
| 2003 | painter.end(); |
| 2004 | } |
| 2005 | |
| 2006 | |
| 2007 | void PlayOpenGL::renderText(QMatrix4x4 mat,int w, int h, const V3 &pos, const QString &text, QColor &color, uint bg){ |
| 2008 | QVector3D mapped3d = mat.map(QVector3D(pos.x, pos.y, pos.z)); |
| 2009 | QVector2D vec2 = QVector2D((1 + mapped3d.x()) * (w / 2), (1 - mapped3d.y()) * (h / 2)); |
| 2010 | QPainter painter(this); |
| 2011 | QFontMetrics mtr(nonAtomFont); |
| 2012 | QRect rc=mtr.boundingRect(text+"L"); |
| 2013 | QImage image(rc.width(),rc.height(), QImage::Format_ARGB32_Premultiplied); |
| 2014 | image.fill(bg); |
| 2015 | QPainter p; |
| 2016 | p.begin(&image); |
| 2017 | p.setPen(color); |
| 2018 | p.setBackground(Qt::NoBrush); |
| 2019 | p.setFont(nonAtomFont); |
| 2020 | p.drawText(image.rect(), Qt::AlignCenter, text); |
| 2021 | p.end(); |
| 2022 | painter.drawImage(vec2.x(), vec2.y()-rc.height(), image); |
| 2023 | painter.end(); |
| 2024 | } |
| 2025 | |
| 2026 | |
| 2027 | void PlayOpenGL::makeLabels(){ |
| 2028 | altLabels.clear(); |
| 2029 | nonAtomFont = myFont; |
| 2030 | QString label; |
| 2031 | nonAtomFont.setPointSize(qMax(((myFont.pointSize()*2)/3),7)); |
| 2032 | for (int i = 0; i < mol->showatoms.size(); i++){ |
| 2033 | QFont f = (mol->showatoms.at(i).an<0)?nonAtomFont:myFont; |
| 2034 | QFontMetrics mtr(f); |
| 2035 | label = mol->showatoms.at(i).Label; |
| 2036 | if (shortLabels->isChecked()) { |
| 2037 | label=label.section("_",0,0); |
| 2038 | label=label.section(QString::fromUtf8("»"),0,0); |
| 2039 | } |
| 2040 | QRect rc=mtr.boundingRect(label+"L"); |
| 2041 | QImage image(rc.width(),rc.height(), QImage::Format_ARGB32_Premultiplied); |
| 2042 | image.fill(labelBGColor.rgba()); |
| 2043 | QPainter p; |
| 2044 | p.begin(&image); |
| 2045 | p.setPen(labelColor); |
| 2046 | p.setBackground(Qt::NoBrush); |
| 2047 | p.setFont(f); |
| 2048 | p.drawText(image.rect(), Qt::AlignCenter, label); |
| 2049 | p.end(); |
| 2050 | altLabels.append(image); |
| 2051 | } |
| 2052 | update(); |
| 2053 | //printf("makeLabels %d %d short?%d\n",altLabels.size(), mol->showatoms.size(),shortLabels->isChecked()); |
| 2054 | } |
| 2055 | |
| 2056 | void PlayOpenGL::updateBondActions(){//!<changes the visibility state of QActions in the 'Selection Toolbar'. |
| 2057 | //bool p=pause; |
| 2058 | //pause=true; |
| 2059 | //printf("%p %p %p %p %p %p %p %p %p \n",clearSelection,invSelection,centroid,centerSelection,delSelAt,delSelAt,hideNotSelection,addBond,killBond); |
| 2060 | clearSelection->setVisible(!mol->selectedatoms.isEmpty()); |
| 2061 | //printf("line:%d hiddenThings %d\n",__LINE__,hiddenThings); |
| 2062 | invSelection->setVisible(!mol->selectedatoms.isEmpty()); |
| 2063 | centroid->setVisible(mol->selectedatoms.size()>1); |
| 2064 | centerSelection->setVisible((!mol->selectedatoms.isEmpty())||(centerSelection->isChecked())); |
| 2065 | delSelAt->setVisible(!mol->selectedatoms.isEmpty()); |
| 2066 | delSelAt->setEnabled(!mol->selectedatoms.isEmpty()); |
| 2067 | hideNotSelection->setVisible(!mol->selectedatoms.isEmpty()); |
| 2068 | if (fVertexes.size()>1)cntrPlot->setVisible(((!fVertexes[0].isEmpty()||!fVertexes[1].isEmpty())&&(mol->selectedatoms.size()==3))); |
| 2069 | unhide->setVisible(hiddenThings); |
| 2070 | invhide->setVisible(hiddenThings); |
| 2071 | if (mol->selectedatoms.size()!=2){ |
| 2072 | addBond->setVisible(false); |
| 2073 | killBond->setVisible(false); |
| 2074 | } |
| 2075 | else{ |
| 2076 | int da=0; |
| 2077 | for (int i=0; i<mol->showbonds.size();i++){ |
| 2078 | if (((mol->selectedatoms.at(0).style==mol->showbonds.at(i).a1)|| |
| 2079 | (mol->selectedatoms.at(0).style==mol->showbonds.at(i).a2))&& |
| 2080 | ((mol->selectedatoms.at(1).style==mol->showbonds.at(i).a1)|| |
| 2081 | (mol->selectedatoms.at(1).style==mol->showbonds.at(i).a2))) da=i; |
| 2082 | } |
| 2083 | if (da){ |
| 2084 | addBond->setVisible(false); |
| 2085 | killBond->setVisible(true); |
| 2086 | killBond->setData(da); |
| 2087 | } |
| 2088 | else{ |
| 2089 | addBond->setVisible(true); |
| 2090 | killBond->setVisible(false); |
| 2091 | } |
| 2092 | } |
| 2093 | findPivot(); |
| 2094 | makeBonds(mol->showatoms, mol->showbonds, mol->lbonds, mol->theH_Bonds); |
| 2095 | //pause=p; |
| 2096 | } |
| 2097 | |
| 2098 | void PlayOpenGL::updateSceenAtoms(){ |
| 2099 | //QList<QVector2D> screenAtoms; |
| 2100 | //CEnvironment mol->showatoms; |
| 2101 | if (mol->showatoms.isEmpty())return; |
| 2102 | V3 org = sumse; |
| 2103 | if ((rotze>-1)&&(rotze<mol->showatoms.size())) org = mol->showatoms.at(rotze).pos; |
| 2104 | if (centerSelection->isChecked()){ |
| 2105 | if (mol->selectedatoms.isEmpty()) { |
| 2106 | org = sumse; |
| 2107 | } |
| 2108 | else { |
| 2109 | V3 sums=V3(0,0,0); |
| 2110 | for (int i = 0; i < mol->selectedatoms.size(); i++) sums += mol->selectedatoms[i].pos; |
| 2111 | sums *= 1.0 / mol->selectedatoms.size(); |
| 2112 | org = sums; |
| 2113 | } |
| 2114 | } |
| 2115 | if (mol->showatoms.size()<screenAtoms.size()) screenAtoms.clear(); |
| 2116 | for (int i = 0; i < mol->showatoms.size(); i++){ |
| 2117 | QVector3D mapped3d = pmv.map(QVector3D(mol->showatoms.at(i).pos.x - org.x, mol->showatoms.at(i).pos.y - org.y, mol->showatoms.at(i).pos.z - org.z)); |
| 2118 | int w=width(); |
| 2119 | int h=height(); |
| 2120 | QVector2D vec2 = QVector2D((1 + mapped3d.x()) * (w / 2), (1 - mapped3d.y()) * (h / 2)); |
| 2121 | if (screenAtoms.size() < i + 1) screenAtoms.append(vec2); |
| 2122 | else screenAtoms[i] = vec2; |
| 2123 | /*printf("%s %f %f %f %f %f %d %d %d %d\n",mol->showatoms.at(i).Label.toStdString().c_str(),vec2.x(),vec2.y(), mapped3d.x(), mapped3d.y(), mapped3d.z() |
| 2124 | ,w,h,w/2,h/2);// */ |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | |
| 2129 | void PlayOpenGL::makeEnvi(){ |
| 2130 | //printf("make ENVI\n"); |
| 2131 | makeCurrent(); |
| 2132 | envi_vao.release(); |
| 2133 | if (envi_vao.isCreated()) { |
| 2134 | envi_vao.release(); |
| 2135 | envi_vao.destroy(); |
| 2136 | envi_vertexBuffer.destroy(); |
| 2137 | envi_program->release(); |
| 2138 | envi_program->removeAllShaders(); |
| 2139 | } |
| 2140 | envi_vao.create(); |
| 2141 | envi_vao.bind(); |
| 2142 | envi_vertexBuffer.create(); |
| 2143 | envi_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 2144 | if (!envi_program) envi_program = new QOpenGLShaderProgram(this); |
| 2145 | else envi_program->removeAllShaders(); |
| 2146 | //printf("envi_program %p %d\n",envi_program, envi_program->programId()); |
| 2147 | bool result = envi_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/envi.vert"); |
| 2148 | if (!result) qWarning() << envi_program->log(); |
| 2149 | result = envi_program->addCacheableShaderFromSourceFile( QOpenGLShader::Geometry, ":/shaders/envi.geom"); |
| 2150 | if (!result) qWarning() << envi_program->log(); |
| 2151 | result = envi_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/envi.frag"); |
| 2152 | if (!result) qWarning() << envi_program->log(); |
| 2153 | result = envi_program->link(); |
| 2154 | if (!result) qWarning() << envi_program->log(); |
| 2155 | QVector<float> p; |
| 2156 | for (int i=0; i<enviPositions.size(); i++){ |
| 2157 | p.append(enviP0.x); |
| 2158 | p.append(enviP0.y); |
| 2159 | p.append(enviP0.z); |
| 2160 | p.append(static_cast<float>(enviKat.at(i))); |
| 2161 | p.append(enviPositions.at(i).x); |
| 2162 | p.append(enviPositions.at(i).y); |
| 2163 | p.append(enviPositions.at(i).z); |
| 2164 | p.append(static_cast<float>(enviKat.at(i))); |
| 2165 | } |
| 2166 | if (!envi_vertexBuffer.bind()) {printf("I was unable to bind envi_vertexBuffer.\n");} |
| 2167 | envi_vertexBuffer.allocate((p.size()) * sizeof(float)); |
| 2168 | envi_vertexBuffer.write(0,p.data(),p.size() * sizeof(float)); |
| 2169 | |
| 2170 | envi_program->enableAttributeArray("L0" ); |
| 2171 | envi_program->setAttributeBuffer("L0", GL_FLOAT, 0, 4 ); |
| 2172 | bool b=shaderInfo; |
| 2173 | shaderInfo=true; |
| 2174 | programInfo(envi_program, "envi"); |
| 2175 | shaderInfo=b; |
| 2176 | envi_program->release(); |
| 2177 | envi_vertexBuffer.release(); |
| 2178 | envi_vao.release(); |
| 2179 | |
| 2180 | update(); |
| 2181 | } |
| 2182 | |
| 2183 | void PlayOpenGL::makeMaps( |
| 2184 | QVector< QVector< float > > &_fVertexes, |
| 2185 | QVector< QVector< float > > &_fNormals){ |
| 2186 | fVertexes = _fVertexes; |
| 2187 | fNormals = _fNormals; |
| 2188 | |
| 2189 | makeCurrent(); |
| 2190 | map_vao.release(); |
| 2191 | if (map_vao.isCreated()) { |
| 2192 | map_vao.release(); |
| 2193 | map_vao.destroy(); |
| 2194 | map_vertexBuffer.destroy(); |
| 2195 | map_program->release(); |
| 2196 | map_program->removeAllShaders(); |
| 2197 | } |
| 2198 | map_vao.create(); |
| 2199 | map_vao.bind(); |
| 2200 | map_vertexBuffer.create(); |
| 2201 | map_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 2202 | GLenum err = GL_NO_ERROR; |
| 2203 | while((err = glGetError()) != GL_NO_ERROR) |
| 2204 | { |
| 2205 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 2206 | //printf("%s\n",(char*)gluErrorString(err)); |
| 2207 | } |
| 2208 | if (!map_program) map_program = new QOpenGLShaderProgram(this); |
| 2209 | else map_program->removeAllShaders(); |
| 2210 | //printf("map_program %p %d\n",map_program, map_program->programId()); |
| 2211 | bool result = map_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/waldwiesen.vert"); |
| 2212 | //printf("%d\n",__LINE__); |
| 2213 | if ( !result ) qWarning() << map_program->log(); |
| 2214 | result = map_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/waldwiesen.frag"); |
| 2215 | if ( !result ) qWarning() << map_program->log(); |
| 2216 | result = map_program->link(); |
| 2217 | if ( !result ) qWarning() << map_program->log(); |
| 2218 | int siz = fVertexes[0].size() + sizeof(float); |
| 2219 | size_t mapsiz = 0;//fVertexes[0].size()* sizeof(float); |
| 2220 | for (int i=0; i<28; i++) mapsiz+=fVertexes[i].size()* sizeof(float); |
| 2221 | if (!map_vertexBuffer.bind()) {printf("I was unable to bind map_vertexBuffer.\n");} |
| 2222 | map_vertexBuffer.allocate(mapsiz*2); |
| 2223 | int offs=0; |
| 2224 | V3 ctr=V3(0,0,0); |
| 2225 | const float * fv = fVertexes[0].data(); |
| 2226 | for (int i=0; i<fVertexes[0].size()/3; i++){ |
| 2227 | ctr+=V3(fv[i*3], fv[i*3+1], fv[i*3+2]); |
| 2228 | } |
| 2229 | ctr*=3.0/fVertexes[0].size(); |
| 2230 | //printf(" %f %f %f\n", sumse.x, sumse.y, sumse.z); |
| 2231 | //printf("CENTER of maps %d points: %f %f %f\n", fVertexes[0].size()/3, ctr.x, ctr.y, ctr.z); |
| 2232 | |
| 2233 | offsets.clear(); |
| 2234 | for (int i=0; i<28; i++){ |
| 2235 | offsets.append(offs); |
| 2236 | int siz = fVertexes[i].size() * sizeof(float); |
| 2237 | map_vertexBuffer.write(offs, fVertexes[i].data(), siz); |
| 2238 | offs+=siz; |
| 2239 | }//*/ |
| 2240 | int normaloffset=offs; |
| 2241 | for (int i=0; i<28; i++){ |
| 2242 | //offsets.append(offs); |
| 2243 | int siz = fNormals[i].size() * sizeof(float); |
| 2244 | map_vertexBuffer.write(offs, fNormals[i].data(), siz); |
| 2245 | offs+=siz; |
| 2246 | }//*/ |
| 2247 | //qDebug()<<offsets; |
| 2248 | |
| 2249 | map_program->enableAttributeArray("normal" );// */ |
| 2250 | map_program->enableAttributeArray("vertex" ); |
| 2251 | map_program->setAttributeBuffer("normal", GL_FLOAT, normaloffset, 3 ); |
| 2252 | map_program->setAttributeBuffer("vertex", GL_FLOAT, 0, 3 ); |
| 2253 | //printf("map stuff and program %lld %d %d\n",mapsiz ,siz , normaloffset); |
| 2254 | |
| 2255 | programInfo(map_program, "waldwiesen"); |
| 2256 | err = GL_NO_ERROR; |
| 2257 | while((err = glGetError()) != GL_NO_ERROR) |
| 2258 | { |
| 2259 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 2260 | //printf("%s\n",(char*)gluErrorString(err)); |
| 2261 | } |
| 2262 | map_vertexBuffer.release(); |
| 2263 | map_program->release(); |
| 2264 | map_vao.release(); |
| 2265 | //update(); |
| 2266 | } |
| 2267 | |
| 2268 | /*void PlayOpenGL::setMapsStuff( |
| 2269 | QVector< QVector< float > > &_fVertexes, |
| 2270 | QVector< QVector< float > > &_fNormals, |
| 2271 | double *_lintrans, |
| 2272 | double *_linwidth, |
| 2273 | QColor *_fopc, |
| 2274 | QColor *_fomc, |
| 2275 | QColor *_dipc, |
| 2276 | QColor *_dimc, |
| 2277 | QCheckBox *_lighting, |
| 2278 | QCheckBox *_niceTrans, |
| 2279 | QCheckBox *_fillMap, |
| 2280 | QAction *_foact, |
| 2281 | QAction *_fofcact |
| 2282 | ){ |
| 2283 | fVertexes = _fVertexes; |
| 2284 | fNormals = _fNormals; |
| 2285 | lintrans = *_lintrans; |
| 2286 | linwidth = *_linwidth; |
| 2287 | fopc = *_fopc; |
| 2288 | fomc = *_fomc; |
| 2289 | dipc = *_dipc; |
| 2290 | dimc = *_dimc; |
| 2291 | lighting = *_lighting; |
| 2292 | niceTrans = *_niceTrans; |
| 2293 | fillMap = *_fillMap; |
| 2294 | foact = *_foact; |
| 2295 | fofcact = *_fofcact; |
| 2296 | connect(foact, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 2297 | connect(fofcact, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 2298 | connect(niceTrans, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 2299 | connect(lighting, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 2300 | connect(fillMap, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 2301 | makeMaps(_fVertexes,_fNormals); |
| 2302 | } |
| 2303 | */ |
| 2304 | void PlayOpenGL::setMapsStuff(){ |
| 2305 | connect(foact, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 2306 | connect(fofcact, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 2307 | connect(niceTrans, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 2308 | connect(lighting, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 2309 | connect(fillMap, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 2310 | makeMaps(fVertexes,fNormals); |
| 2311 | } |
| 2312 | |
| 2313 | void PlayOpenGL::makeUnitCell(){ |
| 2314 | //printf("makeUnitCell\n"); |
| 2315 | makeCurrent(); |
| 2316 | uc_vao.release(); |
| 2317 | if (uc_vao.isCreated()) { |
| 2318 | uc_vao.release(); |
| 2319 | uc_vao.destroy(); |
| 2320 | uc_vertexBuffer.destroy(); |
| 2321 | uc_program->release(); |
| 2322 | uc_program->removeAllShaders(); |
| 2323 | } |
| 2324 | uc_vao.create(); |
| 2325 | uc_vao.bind(); |
| 2326 | uc_vertexBuffer.create(); |
| 2327 | uc_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 2328 | if (!uc_vertexBuffer.bind()) {printf("I was unable to bind uc_vertexBuffer.\n");} |
| 2329 | GLfloat vert[] = {0.0, 0.0, 0.0}; |
| 2330 | if (!uc_program) uc_program = new QOpenGLShaderProgram(this); |
| 2331 | else uc_program->removeAllShaders(); |
| 2332 | bool result = uc_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/uc.vert"); |
| 2333 | //printf("%d\n",__LINE__); |
| 2334 | if ( !result ) qWarning() << uc_program->log(); |
| 2335 | result = uc_program->addCacheableShaderFromSourceFile( QOpenGLShader::Geometry, ":/shaders/uc.geom"); |
| 2336 | if ( !result ) qWarning() << uc_program->log(); |
| 2337 | result = uc_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/uc.frag"); |
| 2338 | if ( !result ) qWarning() << uc_program->log(); |
| 2339 | result = uc_program->link(); |
| 2340 | if ( !result ) qWarning() << uc_program->log(); |
| 2341 | if ( !uc_program->bind() ) { |
| 2342 | qWarning() << "Could not bind shader program to context"; |
| 2343 | return; |
| 2344 | } |
| 2345 | uc_vertexBuffer.allocate(vert, 3 * sizeof( float )) ; |
| 2346 | //uc_program->setAttributeBuffer(uc_vertexBuffer.bufferId(), GL_FLOAT, 0, 3 ); |
| 2347 | uc_program->setAttributeBuffer("vertex", GL_FLOAT, 0, 3 ); |
| 2348 | uc_program->enableAttributeArray("vertex" ); |
| 2349 | //uc_program->enableAttributeArray(uc_vertexBuffer.bufferId()); |
| 2350 | //printf("uc_vertexBuffer.bufferId() %d\n",uc_vertexBuffer.bufferId()); |
| 2351 | programInfo(uc_program,"unit cell"); |
| 2352 | uc_program->release(); |
| 2353 | uc_vao.release(); |
| 2354 | uc_vertexBuffer.release(); |
| 2355 | uc_vertexBuffer.destroy(); |
| 2356 | update(); |
| 2357 | } |
| 2358 | |
| 2359 | void PlayOpenGL::contDestruct(){ |
| 2360 | cont_vao.release(); |
| 2361 | cont_vao.destroy(); |
| 2362 | cont_vertexBuffer.destroy(); |
| 2363 | cont_program->release(); |
| 2364 | cont_program->removeAllShaders(); |
| 2365 | } |
| 2366 | |
| 2367 | void PlayOpenGL::voroDestruct(){ |
| 2368 | voro_vao.release(); |
| 2369 | voro_vao.destroy(); |
| 2370 | voro_vertexBuffer.destroy(); |
| 2371 | voro_program->release(); |
| 2372 | voro_program->removeAllShaders(); |
| 2373 | } |
| 2374 | |
| 2375 | void PlayOpenGL::makeContours(){ |
| 2376 | //printf("makeContours\n"); |
| 2377 | makeCurrent(); |
| 2378 | cont_vao.release(); |
| 2379 | if (cont_vao.isCreated()) { |
| 2380 | cont_vao.release(); |
| 2381 | cont_vao.destroy(); |
| 2382 | cont_vertexBuffer.destroy(); |
| 2383 | cont_program->release(); |
| 2384 | cont_program->removeAllShaders(); |
| 2385 | } |
| 2386 | cont_vao.create(); |
| 2387 | cont_vao.bind(); |
| 2388 | //glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
| 2389 | cont_vertexBuffer.create(); |
| 2390 | cont_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 2391 | if (!cont_vertexBuffer.bind()) {printf("I was unable to bind cont_vertexBuffer.\n");} |
| 2392 | ///////////// |
| 2393 | QVector<float> p; |
| 2394 | float val=0.0f; |
| 2395 | for (int ci=0;ci<cont.size();ci++){ |
| 2396 | if (contval.contains(ci)) val = contval.value(ci); |
| 2397 | p.append(cont.at(ci).x); |
| 2398 | p.append(cont.at(ci).y); |
| 2399 | p.append(cont.at(ci).z); |
| 2400 | p.append(val); |
| 2401 | } |
| 2402 | if (!cont_program) cont_program = new QOpenGLShaderProgram(this); |
| 2403 | else cont_program->removeAllShaders(); |
| 2404 | bool result = cont_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/contour.vert"); |
| 2405 | //printf("%d\n",__LINE__); |
| 2406 | if ( !result ) qWarning() << cont_program->log(); |
| 2407 | result = cont_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/contour.frag"); |
| 2408 | |
| 2409 | if ( !result ) qWarning() << cont_program->log(); |
| 2410 | result = cont_program->link(); |
| 2411 | if ( !result ) qWarning() << cont_program->log(); |
| 2412 | |
| 2413 | if ( !cont_program->bind() ) { |
| 2414 | qWarning() << "Could not bind shader program to context"; |
| 2415 | return; |
| 2416 | } |
| 2417 | //printf("%d %d\n",cont.size(), p.size()); |
| 2418 | cont_vertexBuffer.allocate(p.data(),p.size()*sizeof(float)); |
| 2419 | cont_program->setAttributeBuffer("vertex", GL_FLOAT, 0, 4 ); |
| 2420 | cont_program->enableAttributeArray("vertex" ); |
| 2421 | |
| 2422 | programInfo(cont_program,"Contour"); |
| 2423 | |
| 2424 | cont_program->release(); |
| 2425 | cont_vao.release(); |
| 2426 | cont_vertexBuffer.release(); |
| 2427 | cont_vertexBuffer.destroy(); |
| 2428 | update(); |
| 2429 | } |
| 2430 | |
| 2431 | void PlayOpenGL::makeBackGround(){ |
| 2432 | //printf("makeBackGround\n"); |
| 2433 | makeCurrent(); |
| 2434 | GLenum err = GL_NO_ERROR; |
| 2435 | while((err = glGetError()) != GL_NO_ERROR) |
| 2436 | { |
| 2437 | printf("before makeBackGround %s error %X\n", parent()->objectName().toStdString().c_str(),err); |
| 2438 | //printf("%s\n",(char*)gluErrorString(err)); |
| 2439 | } |
| 2440 | |
| 2441 | bg_vao.release(); |
| 2442 | if (bg_vao.isCreated()) { |
| 2443 | bg_vao.release(); |
| 2444 | bg_vao.destroy(); |
| 2445 | backGround_vertexBuffer.destroy(); |
| 2446 | bg_program->release(); |
| 2447 | bg_program->removeAllShaders(); |
| 2448 | } |
| 2449 | bg_vao.create(); |
| 2450 | bg_vao.bind(); |
| 2451 | //glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
| 2452 | backGround_vertexBuffer.create(); |
| 2453 | backGround_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 2454 | if (!backGround_vertexBuffer.bind()) {printf("I was unable to bind backGround_vertexBuffer.\n");} |
| 2455 | GLfloat vert[] ={-1.0,-1.0,0.0, -1.0, 1.0,0.0, 1.0,-1.0,0.0, 1.0, 1.0,0.0}; |
| 2456 | if (!bg_program) bg_program = new QOpenGLShaderProgram(this); |
| 2457 | else bg_program->removeAllShaders(); |
| 2458 | |
| 2459 | //printf("%p %d\n",bg_program, bg_program->programId()); |
| 2460 | |
| 2461 | bool result = bg_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/bg.vert"); |
| 2462 | //printf("%d\n",__LINE__); |
| 2463 | if ( !result ) qWarning() << bg_program->log(); |
| 2464 | result = bg_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/bg.frag"); |
| 2465 | |
| 2466 | if ( !result ) qWarning() << bg_program->log(); |
| 2467 | result = bg_program->link(); |
| 2468 | if ( !result ) qWarning() << bg_program->log(); |
| 2469 | |
| 2470 | if ( !bg_program->bind() ) { |
| 2471 | qWarning() << "Could not bind shader program to context"; |
| 2472 | return; |
| 2473 | } |
| 2474 | backGround_vertexBuffer.allocate(vert, 4 *3 * sizeof( float )) ; |
| 2475 | bg_program->setAttributeBuffer(backGround_vertexBuffer.bufferId(), GL_FLOAT, 0, 3 ); |
| 2476 | bg_program->setAttributeBuffer("vertex", GL_FLOAT, 0, 3 ); |
| 2477 | bg_program->enableAttributeArray("vertex" ); |
| 2478 | bg_program->enableAttributeArray(backGround_vertexBuffer.bufferId()); |
| 2479 | |
| 2480 | bg_program->setUniformValue("bgcolor", backGroundColor); |
| 2481 | bg_program->setUniformValue("bggradient", bggradient); |
| 2482 | programInfo(bg_program,"bg"); |
| 2483 | |
| 2484 | bg_program->release(); |
| 2485 | bg_vao.release(); |
| 2486 | backGround_vertexBuffer.release(); |
| 2487 | backGround_vertexBuffer.destroy(); |
| 2488 | while((err = glGetError()) != GL_NO_ERROR) |
| 2489 | { |
| 2490 | printf("after makeBackGround %s error %X\n", parent()->objectName().toStdString().c_str(),err); |
| 2491 | //printf("%s\n",(char*)gluErrorString(err)); |
| 2492 | } |
| 2493 | |
| 2494 | |
| 2495 | } |
| 2496 | |
| 2497 | void PlayOpenGL::makeSelectedAtoms(){ |
| 2498 | |
| 2499 | //printf("makeSelectedAtoms\n"); |
| 2500 | makeCurrent(); |
| 2501 | slct_vao.release(); |
| 2502 | if (slct_vao.isCreated()) { |
| 2503 | slct_vao.release(); |
| 2504 | slct_vao.destroy(); |
| 2505 | satom_vertexBuffer.destroy(); |
| 2506 | satom_indexBuffer.destroy(); |
| 2507 | satom_program->release(); |
| 2508 | satom_program->removeAllShaders(); |
| 2509 | } |
| 2510 | //if (mol->selectedatoms.isEmpty()) return; |
| 2511 | slct_vao.create(); |
| 2512 | slct_vao.bind(); |
| 2513 | //glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
| 2514 | satom_vertexBuffer.create(); |
| 2515 | satom_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 2516 | if (!satom_vertexBuffer.bind()) {printf("I was unable to bind atom_vertexBuffer.\n");} |
| 2517 | //glDisable(GL_BLEND); |
| 2518 | //printf("makeAtoms\n"); |
| 2519 | |
| 2520 | int na = mol->selectedatoms.size(); |
| 2521 | |
| 2522 | //printf("makeSelectedAtoms na %d\n",na); |
| 2523 | //* |
| 2524 | if (!satom_program) satom_program = new QOpenGLShaderProgram(this); |
| 2525 | else satom_program->removeAllShaders(); |
| 2526 | |
| 2527 | bool result = satom_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/std.vert"); |
| 2528 | if ( !result ) qWarning() << satom_program->log(); |
| 2529 | result = satom_program->addCacheableShaderFromSourceFile( QOpenGLShader::Geometry, ":/shaders/std.geom" ); |
| 2530 | if ( !result ) qWarning() << satom_program->log(); |
| 2531 | result = satom_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/std.frag" ); |
| 2532 | if ( !result ) qWarning() << satom_program->log(); |
| 2533 | // ...and finally we link them to resolve any references. |
| 2534 | result = satom_program->link(); |
| 2535 | if ( !result ) qWarning() << "Could not link shader satom_program:" << satom_program->log(); |
| 2536 | |
| 2537 | QVector<float> pos; |
| 2538 | for (int i=0; i<mol->selectedatoms.size(); i++){ |
| 2539 | pos.append(mol->selectedatoms.at(i).pos.x); |
| 2540 | pos.append(mol->selectedatoms.at(i).pos.y); |
| 2541 | pos.append(mol->selectedatoms.at(i).pos.z); |
| 2542 | /*printf("select? %f %f %f %f %f %f \n", |
| 2543 | mol->selectedatoms.at(i).pos.x-sumse.x, |
| 2544 | mol->selectedatoms.at(i).pos.y-sumse.y, |
| 2545 | mol->selectedatoms.at(i).pos.z-sumse.z, |
| 2546 | sumse.x,sumse.y,sumse.z); // */ |
| 2547 | } |
| 2548 | for (int i=0; i<mol->duplicateAtoms.size(); i++){ |
| 2549 | pos.append (mol->duplicateAtoms.at(i).pos.x); |
| 2550 | pos.append (mol->duplicateAtoms.at(i).pos.y); |
| 2551 | pos.append (mol->duplicateAtoms.at(i).pos.z); |
| 2552 | /*printf("select? %f %f %f %f %f %f \n", |
| 2553 | mol->selectedatoms.at(i).pos.x-sumse.x, |
| 2554 | mol->selectedatoms.at(i).pos.y-sumse.y, |
| 2555 | mol->selectedatoms.at(i).pos.z-sumse.z, |
| 2556 | sumse.x,sumse.y,sumse.z); // */ |
| 2557 | } |
| 2558 | pos.append(0.1);//inFocus dummy atom |
| 2559 | pos.append(0.2); |
| 2560 | pos.append(0.3); |
| 2561 | |
| 2562 | satom_vertexBuffer.allocate( pos.data(), (na+1+mol->duplicateAtoms.size()) * 3 * sizeof( float ) );//na + dummy |
| 2563 | if ( !satom_program->bind() ) { |
| 2564 | qWarning() << "Could not bind shader satom_program to context"; |
| 2565 | return; |
| 2566 | } |
| 2567 | satom_program->setAttributeBuffer(satom_vertexBuffer.bufferId(), GL_FLOAT, 0, 3 ); |
| 2568 | satom_program->setAttributeBuffer("vertex", GL_FLOAT, 0, 3 ); |
| 2569 | satom_program->enableAttributeArray("vertex" ); |
| 2570 | satom_program->enableAttributeArray(satom_vertexBuffer.bufferId()); |
| 2571 | satom_program->setUniformValue("pmv", pmv); |
| 2572 | satom_program->setUniformValue("normalMatrix", nm); |
| 2573 | satom_program->setUniformValue("Color", QColor("yellow")); |
| 2574 | satom_program->setUniformValue("lightPos", QVector3D(100,100,100)); |
| 2575 | programInfo(satom_program, "std"); |
| 2576 | satom_program->release(); |
| 2577 | satom_vertexBuffer.release(); |
| 2578 | slct_vao.release(); |
| 2579 | //printf("!makeSelectedAtoms %d %p\n",mol->selectedatoms.size(),satom_program); |
| 2580 | update(); |
| 2581 | // */ |
| 2582 | } |
| 2583 | |
| 2584 | void PlayOpenGL::makeLegendAtoms(){ |
| 2585 | |
| 2586 | //printf("makeLegendAtoms\n"); |
| 2587 | makeCurrent(); |
| 2588 | latom_vao.release(); |
| 2589 | if (latom_vao.isCreated()) { |
| 2590 | latom_vao.release(); |
| 2591 | latom_vao.destroy(); |
| 2592 | latom_vertexBuffer.destroy(); |
| 2593 | latom_indexBuffer.destroy(); |
| 2594 | //latom_program->release(); |
| 2595 | //latom_program->removeAllShaders(); |
| 2596 | } |
| 2597 | latom_vao.create(); |
| 2598 | latom_vao.bind(); |
| 2599 | //glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
| 2600 | latom_vertexBuffer.create(); |
| 2601 | latom_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 2602 | if (!latom_vertexBuffer.bind()) {printf("I was unable to bind latom_vertexBuffer.\n");} |
| 2603 | |
| 2604 | int na = mol->legendAtoms.size(); |
| 2605 | const float phi = (1.0f + sqrtf(5.0f)) / 2.0f; |
| 2606 | const float du = 1.0f / sqrtf(phi * phi + 1.0f); |
| 2607 | const float dv = phi * du; |
| 2608 | //printf("phi = %f du = %f dv = %f\n",phi, du, dv); |
| 2609 | const float eckn[] ={ 0.0f, dv, du, |
| 2610 | 0.0f, dv, -du, |
| 2611 | 0.0f, -dv, du, |
| 2612 | 0.0f, -dv, -du, |
| 2613 | du, 0.0f, dv, |
| 2614 | -du, 0.0f, dv, |
| 2615 | du, 0.0f, -dv, |
| 2616 | -du, 0.0f, -dv, |
| 2617 | dv, du, 0.0f, |
| 2618 | dv, -du, 0.0f, |
| 2619 | -dv, du, 0.0f, |
| 2620 | -dv, -du, 0.0f}; |
| 2621 | const GLuint triangle[] = { |
| 2622 | 1, 0, 8, |
| 2623 | 4, 0, 5, |
| 2624 | 5, 0, 10, |
| 2625 | 8, 0, 4, |
| 2626 | 10, 0, 1, |
| 2627 | 6, 1, 8, |
| 2628 | 7, 1, 6, |
| 2629 | 10, 1, 7, |
| 2630 | 3, 2, 11, |
| 2631 | 4, 2, 9, |
| 2632 | 5, 2, 4, |
| 2633 | 9, 2, 3, |
| 2634 | 11, 2, 5, |
| 2635 | 6, 3, 7, |
| 2636 | 7, 3, 11, |
| 2637 | 9, 3, 6, |
| 2638 | 8, 4, 9, |
| 2639 | 11, 5, 10, |
| 2640 | 9, 6, 8, |
| 2641 | 10, 7, 11};//*/ |
| 2642 | /*const GLuint triangle_strips[] = { |
| 2643 | 1, 0, 8, 4, 9, 2, 3, 11, 7, 10, 1, 0, 0xFFFFFFFF, |
| 2644 | 3, 9, 6, 8, 1, 0xFFFFFFFF, |
| 2645 | 2, 11, 5, 10, 0, 0xFFFFFFFF, |
| 2646 | 1, 7, 6, 3, 0xFFFFFFFF, //3, 7, 6, 1, 0xFFFF, |
| 2647 | 2, 4, 5, 0, 0xFFFFFFFF//0, 5, 4, 2, 0xFFFF, |
| 2648 | };//, 10, 5, 11, 2}; */ |
| 2649 | //0xFFFF |
| 2650 | double yofs=-6.7; |
| 2651 | double xofs=0; |
| 2652 | for (int ali=0; ali<na; ali++){ |
| 2653 | xofs=qMax(mol->arad[qMax(mol->legendAtoms[ali].an,0)],xofs); |
| 2654 | } |
| 2655 | xofs-=3.0; |
| 2656 | for (int ali=0; ali<na; ali++){ |
| 2657 | mol->legendAtoms[ali].pos.y=yofs; |
| 2658 | if ((adp->isChecked())&&(mol->legendAtoms[ali].an>=0)){ |
| 2659 | yofs+=0.5; |
| 2660 | } |
| 2661 | else{ |
| 2662 | if (tubes->isChecked()) { |
| 2663 | yofs+=2*mol->bondStrength+0.15; |
| 2664 | }else{ |
| 2665 | yofs+=mol->arad[qMax(mol->legendAtoms[ali].an,0)]+0.07; |
| 2666 | if (ali+1<na) yofs+=mol->arad[qMax(mol->legendAtoms[ali+1].an,0)]+0.07; |
| 2667 | } |
| 2668 | } |
| 2669 | mol->legendAtoms[ali].pos.x=xofs; |
| 2670 | //printf("legend %f %f %f %f\n",mol->legendAtoms[ali].pos.x, mol->legendAtoms[ali].pos.y,yofs,mol->arad[qMax(mol->legendAtoms[ali].an,0)]); |
| 2671 | //if (mol->legendAtoms.at(ali).hidden) continue; |
| 2672 | } |
| 2673 | QVector<float> stuff; |
| 2674 | for (int i = 0; i < na; i++){ |
| 2675 | bool isd=((mol->legendAtoms.at(i).an==0)&&(mol->legendAtoms.at(i).Label[0]=='D')); |
| 2676 | int style = (mol->legendAtoms.at(i).an<0)?0: |
| 2677 | (0xFF&mol->AtomStyle[mol->legendAtoms.at(i).an]) |
| 2678 | |((mol->legendAtoms.at(i).hidden)?512:0) |
| 2679 | |((isd)?1024:0) |
| 2680 | |(((mol->legendAtoms.at(i).isIso))?2048:0); |
| 2681 | //printf("legend %s %d %d\n",mol->legendAtoms.at(i).Label.toStdString().c_str(), mol->legendAtoms.at(i).an,mol->legendAtoms.at(i).hidden); |
| 2682 | V3 ev=V3(0,0,0); |
| 2683 | double *arr = mol->jacobi(mol->legendAtoms.at(i).uc, ev); |
| 2684 | //printf("Legend: %fdeg x%f y%f z%f ev1:%f ev2:%f ev3:%f %X %X\n", arr[0], arr[1], arr[2], arr[3], ev.x, ev.y, ev.z, style, mol->AtomStyle[mol->legendAtoms.at(i).an]); |
| 2685 | for (int j = 0; j < 12; j++){ |
| 2686 | stuff.append(mol->legendAtoms.at(i).pos.x);//the center |
| 2687 | stuff.append(mol->legendAtoms.at(i).pos.y); |
| 2688 | stuff.append(mol->legendAtoms.at(i).pos.z); |
| 2689 | //printf("LLL %f %f %f \n", mol->legendAtoms.at(i).pos.x, mol->legendAtoms.at(i).pos.y, mol->legendAtoms.at(i).pos.z); |
| 2690 | stuff.append(static_cast<float>(mol->legendAtoms.at(i).an)); |
| 2691 | |
| 2692 | stuff.append(eckn[3*j]);// an icosahedron corner |
| 2693 | stuff.append(eckn[3*j+1]); |
| 2694 | stuff.append(eckn[3*j+2]); |
| 2695 | stuff.append(static_cast<float>(j)); |
| 2696 | |
| 2697 | stuff.append(static_cast<float>(arr[0])); |
| 2698 | stuff.append(static_cast<float>(arr[1])); |
| 2699 | stuff.append(static_cast<float>(arr[2])); |
| 2700 | stuff.append(static_cast<float>(arr[3])); |
| 2701 | |
| 2702 | stuff.append(ev.x); |
| 2703 | stuff.append(ev.y); |
| 2704 | stuff.append(ev.z); |
| 2705 | stuff.append(static_cast<float>(style)); |
| 2706 | |
| 2707 | stuff.append(static_cast<float>((mol->legendAtoms.at(i).an==-42)?mol->legendAtoms.at(i).sof:mol->legendAtoms.at(i).peakHeight)); |
| 2708 | stuff.append(static_cast<float>(qMax(0, mol->legendAtoms.at(i).symmGroup))); |
| 2709 | stuff.append(static_cast<float>(mol->legendAtoms.at(i).part)); |
| 2710 | stuff.append(static_cast<float>(mol->legendAtoms.at(i).molindex)); |
| 2711 | |
| 2712 | stuff.append(static_cast<float>(i)); |
| 2713 | stuff.append(static_cast<float>(mol->legendAtoms.at(i).auidx)); |
| 2714 | stuff.append(static_cast<float>(mol->legendAtoms.at(i).resiNr)); |
| 2715 | stuff.append(0.0f); |
| 2716 | |
| 2717 | } |
| 2718 | latom_vertexBuffer.allocate(stuff.data(),stuff.size()*sizeof(float)); |
| 2719 | } |
| 2720 | QVector<GLuint> indexes; |
| 2721 | uint una = static_cast<uint>(na); |
| 2722 | for (uint i = 0; i < una; i++){ |
| 2723 | for (uint j = 0; j < 60; j++){ |
| 2724 | indexes.append(triangle[j]+12*i);//_strips |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | latom_indexBuffer = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer); // Mind: use 'IndexBuffer' here |
| 2729 | latom_indexBuffer.create(); |
| 2730 | latom_indexBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw); |
| 2731 | if (!latom_indexBuffer.bind()) {printf("I was unable to bind atom_indexBuffer!\n");} |
| 2732 | latom_indexBuffer.allocate( indexes.size() * sizeof(GLuint) ); |
| 2733 | latom_indexBuffer.write(0, indexes.data(), indexes.size()* sizeof(GLuint)); |
| 2734 | latom_index_size = indexes.size(); |
| 2735 | |
| 2736 | //printf("%d\n",__LINE__); |
| 2737 | atom_program->bind(); |
| 2738 | atom_program->enableAttributeArray(0); |
| 2739 | atom_program->enableAttributeArray(1); |
| 2740 | atom_program->enableAttributeArray(2); |
| 2741 | atom_program->enableAttributeArray(3); |
| 2742 | atom_program->enableAttributeArray(4); |
| 2743 | atom_program->enableAttributeArray(5); |
| 2744 | //printf("%d\n",__LINE__); |
| 2745 | int stride = 6 * 4 * sizeof(float); |
| 2746 | atom_program->setAttributeBuffer(0, GL_FLOAT, 0, 4, stride); |
| 2747 | atom_program->setAttributeBuffer(1, GL_FLOAT, sizeof(float)*4 , 4, stride); |
| 2748 | atom_program->setAttributeBuffer(2, GL_FLOAT, sizeof(float)*8 , 4, stride); |
| 2749 | atom_program->setAttributeBuffer(3, GL_FLOAT, sizeof(float)*12 , 4, stride); |
| 2750 | atom_program->setAttributeBuffer(4, GL_FLOAT, sizeof(float)*16 , 4, stride); |
| 2751 | atom_program->setAttributeBuffer(5, GL_FLOAT, sizeof(float)*20 , 4, stride);// 20*sizeof(float) |
| 2752 | |
| 2753 | atom_program->release(); |
| 2754 | |
| 2755 | latom_vao.release(); |
| 2756 | latom_indexBuffer.release(); |
| 2757 | latom_vertexBuffer.release(); |
| 2758 | latom_vertexBuffer.destroy(); |
| 2759 | latom_indexBuffer.destroy(); |
| 2760 | //printf("thumbup\n"); |
| 2761 | update(); |
| 2762 | |
| 2763 | } |
| 2764 | |
| 2765 | |
| 2766 | void PlayOpenGL::makeSplitRot(){ |
| 2767 | //printf("makeSplitRot\n"); |
| 2768 | makeCurrent(); |
| 2769 | splitrot_vao.release(); |
| 2770 | if (splitrot_vao.isCreated()) { |
| 2771 | splitrot_vao.release(); |
| 2772 | splitrot_vao.destroy(); |
| 2773 | splitrot_vertexBuffer.destroy(); |
| 2774 | splitrot_indexBuffer.destroy(); |
| 2775 | } |
| 2776 | splitrot_vao.create(); |
| 2777 | splitrot_vao.bind(); |
| 2778 | splitrot_vertexBuffer.create(); |
| 2779 | splitrot_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 2780 | //glDisable(GL_BLEND); |
| 2781 | if (!splitrot_vertexBuffer.bind()) {printf("m_vertexBufferObject2 I was unable to bind!\n");} |
| 2782 | |
| 2783 | QVector<float> pos; |
| 2784 | //QVector<float> col; |
| 2785 | QVector<GLuint> nbonds; |
| 2786 | for (int i=0; i<mol->splitLeftAtoms.size(); i++){ |
| 2787 | pos.append(mol->splitLeftAtoms.at(i).pos.x); |
| 2788 | pos.append(mol->splitLeftAtoms.at(i).pos.y); |
| 2789 | pos.append(mol->splitLeftAtoms.at(i).pos.z); |
| 2790 | pos.append(1.0); |
| 2791 | /*printf("%4d %f %f %f %f \n",i, |
| 2792 | mol->splitLeftAtoms.at(i).pos.x, |
| 2793 | mol->splitLeftAtoms.at(i).pos.y, |
| 2794 | mol->splitLeftAtoms.at(i).pos.z, |
| 2795 | 1.0 |
| 2796 | );// */ |
| 2797 | } |
| 2798 | for (int i=0; i<mol->splitRightAtoms.size(); i++){ |
| 2799 | pos.append(mol->splitRightAtoms.at(i).pos.x); |
| 2800 | pos.append(mol->splitRightAtoms.at(i).pos.y); |
| 2801 | pos.append(mol->splitRightAtoms.at(i).pos.z); |
| 2802 | pos.append(2.0); |
| 2803 | |
| 2804 | /*printf("%4d %f %f %f %f \n",i+mol->splitLeftAtoms.size(), |
| 2805 | mol->splitRightAtoms.at(i).pos.x, |
| 2806 | mol->splitRightAtoms.at(i).pos.y, |
| 2807 | mol->splitRightAtoms.at(i).pos.z, |
| 2808 | 2.0 |
| 2809 | );// */ |
| 2810 | } |
| 2811 | for (int i=0; i<mol->splitLbonds.size(); i++){ |
| 2812 | nbonds.append(mol->splitLbonds.at(i).a1); |
| 2813 | nbonds.append(mol->splitLbonds.at(i).a2); |
| 2814 | //printf("L %d %d\n",mol->splitLbonds.at(i).a1,mol->splitLbonds.at(i).a2); |
| 2815 | } |
| 2816 | for (int i=0; i<mol->splitRbonds.size(); i++){ |
| 2817 | nbonds.append(mol->splitRbonds.at(i).a1+mol->splitLeftAtoms.size()); |
| 2818 | nbonds.append(mol->splitRbonds.at(i).a2+mol->splitLeftAtoms.size()); |
| 2819 | |
| 2820 | //printf("R %d %d\n",mol->splitRbonds.at(i).a1+mol->splitLeftAtoms.size(),mol->splitRbonds.at(i).a2+mol->splitLeftAtoms.size()); |
| 2821 | } |
| 2822 | splitrot_vertexBuffer.allocate(pos.size() * sizeof(float)); |
| 2823 | splitrot_vertexBuffer.write(0, (void*)pos.data(), pos.size() * sizeof(float)); |
| 2824 | |
| 2825 | nbonds.size(); |
| 2826 | printf("splitbond = %d %d %d seat=%d\n", nbonds.size(),mol->splitLbonds.size()+mol->splitRbonds.size(),mol->splitRbonds.size(),seat.size()); |
| 2827 | // create a new buffer for the indexes |
| 2828 | splitrot_indexBuffer = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer); // Mind: use 'IndexBuffer' here |
| 2829 | splitrot_indexBuffer.create(); |
| 2830 | splitrot_indexBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw); |
| 2831 | if (!splitrot_indexBuffer.bind()) {printf("splitrot_indexBuffer I was unable to bind!\n");} |
| 2832 | splitrot_indexBuffer.allocate(nbonds.data(), nbonds.size() * sizeof(GLuint) ); |
| 2833 | if (!splitrot_program) splitrot_program = new QOpenGLShaderProgram(this); |
| 2834 | else splitrot_program->removeAllShaders(); |
| 2835 | |
| 2836 | //printf("splitrot_program: %p id = %d\n",splitrot_program, splitrot_program->programId()); |
| 2837 | bool result2 = splitrot_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/splitrot.vert"); |
| 2838 | if ( !result2 ) qWarning() << splitrot_program->log(); |
| 2839 | result2 = splitrot_program->addCacheableShaderFromSourceFile( QOpenGLShader::Geometry, ":/shaders/splitrot.geom"); |
| 2840 | if ( !result2 ) qWarning() << splitrot_program->log(); |
| 2841 | result2 = splitrot_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/splitrot.frag"); |
| 2842 | if ( !result2 ) qWarning() << splitrot_program->log(); |
| 2843 | result2 = splitrot_program->link(); |
| 2844 | programInfo(splitrot_program,"splitrot"); |
| 2845 | if ( !result2 ) qWarning() << splitrot_program->log(); |
| 2846 | if ( !splitrot_program->bind() ) { |
| 2847 | qWarning() << "2Could not bind shader program to context"; |
| 2848 | return; |
| 2849 | } |
| 2850 | |
| 2851 | splitrot_program->setUniformValue("radius", static_cast<float>(mol->bondStrength)); |
| 2852 | splitrot_program->setUniformValue("lightPos", QVector3D(100.0, 100.0, 100.0)); |
| 2853 | |
| 2854 | splitrot_program->setUniformValue("pmv", pmv); |
| 2855 | int stride = 0;//6*sizeof(float); |
| 2856 | splitrot_program->setAttributeBuffer( "VertexPosition", GL_FLOAT, 0, 4, stride ); |
| 2857 | splitrot_program->enableAttributeArray( "VertexPosition" ); |
| 2858 | splitrot_program->release(); |
| 2859 | splitrot_vao.release(); |
| 2860 | splitrot_indexBuffer.release(); |
| 2861 | splitrot_vertexBuffer.release(); |
| 2862 | splitrot_vertexBuffer.destroy(); |
| 2863 | bond_indexBuffer.destroy(); |
| 2864 | update(); |
| 2865 | } |
| 2866 | |
| 2867 | void PlayOpenGL::makeSymmetryElements(){ |
| 2868 | //printf("makeLegendAtoms\n"); |
| 2869 | makeCurrent(); |
| 2870 | symm_vao0.release(); |
| 2871 | symm_vao1.release(); |
| 2872 | symm_vao2.release(); |
| 2873 | if (symm_vao0.isCreated()) { |
| 2874 | symm_vao0.release(); |
| 2875 | symm_vao0.destroy(); |
| 2876 | symm_vao1.release(); |
| 2877 | symm_vao1.destroy(); |
| 2878 | symm_vao2.release(); |
| 2879 | symm_vao2.destroy(); |
| 2880 | symm_vertexBuffer0.destroy(); |
| 2881 | symm_vertexBuffer1.destroy(); |
| 2882 | symm_vertexBuffer2.destroy(); |
| 2883 | symm_program0->release(); |
| 2884 | symm_program0->removeAllShaders(); |
| 2885 | symm_program1->release(); |
| 2886 | symm_program1->removeAllShaders(); |
| 2887 | symm_program2->release(); |
| 2888 | symm_program2->removeAllShaders(); |
| 2889 | } |
| 2890 | symm_vao0.create(); |
| 2891 | symm_vao0.bind(); |
| 2892 | //glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
| 2893 | GLfloat scv[18*4]; |
| 2894 | for (int i=0;i<18;i++) { |
| 2895 | scv[4*i]=mol->symmColors.at(i).redF(); |
| 2896 | scv[4*i+1]=mol->symmColors.at(i).greenF(); |
| 2897 | scv[4*i+2]=mol->symmColors.at(i).blueF(); |
| 2898 | scv[4*i+3]=mol->symmColors.at(i).alphaF(); |
| 2899 | //printf("symcol %d %f %f %f %f\n",i,scv[4*i+0],scv[4*i+1],scv[4*i+2],scv[4*i+3]); |
| 2900 | } |
| 2901 | symm_vertexBuffer0.create(); |
| 2902 | symm_vertexBuffer0.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 2903 | if (!symm_vertexBuffer0.bind()) {printf("I was unable to bind symm_vertexBuffer.\n");} |
| 2904 | |
| 2905 | |
| 2906 | QVector<float> p; |
| 2907 | axend = 0; |
| 2908 | invend = 0; |
| 2909 | planend = 0; |
| 2910 | for (int i = 0; i < mol->axvecs.size(); i++){ |
| 2911 | p.append(mol->axvecs.at(i).x); |
| 2912 | p.append(mol->axvecs.at(i).y); |
| 2913 | p.append(mol->axvecs.at(i).z); |
| 2914 | p.append(mol->axoprs.at(i)); |
| 2915 | p.append(mol->axcols.at(i)); |
| 2916 | printf("i=%4d %8.4f %8.4f %8.4f %2d %2d\n", |
| 2917 | i, |
| 2918 | mol->axvecs.at(i).x, |
| 2919 | mol->axvecs.at(i).y, |
| 2920 | mol->axvecs.at(i).z, |
| 2921 | mol->axoprs.at(i), |
| 2922 | mol->axcols.at(i)); |
| 2923 | |
| 2924 | } |
| 2925 | axend = p.size(); |
| 2926 | symm_vertexBuffer0.allocate(p.data(),(p.size()*sizeof(float))); |
| 2927 | |
| 2928 | if (!symm_program0) symm_program0 = new QOpenGLShaderProgram(this); |
| 2929 | else symm_program0->removeAllShaders(); |
| 2930 | bool result = symm_program0->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/symm.vert"); |
| 2931 | if ( !result ) qWarning() << symm_program0->log(); |
| 2932 | result = symm_program0->addCacheableShaderFromSourceFile( QOpenGLShader::Geometry, ":/shaders/symmaxe.geom"); |
| 2933 | if ( !result ) qWarning() << symm_program0->log(); |
| 2934 | result = symm_program0->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/symm.frag"); |
| 2935 | if ( !result ) qWarning() << symm_program0->log(); |
| 2936 | result = symm_program0->link(); |
| 2937 | if ( !result ) qWarning() << symm_program0->log(); |
| 2938 | if ( !symm_program0->bind() ) { |
| 2939 | qWarning() << "Could not bind shader program to context"; |
| 2940 | return; |
| 2941 | } |
| 2942 | bool beforeInfo = shaderInfo; |
| 2943 | shaderInfo=false;//true; |
| 2944 | |
| 2945 | symm_program0->enableAttributeArray("vertex" ); |
| 2946 | symm_program0->enableAttributeArray("oprf" );// */ |
| 2947 | symm_program0->enableAttributeArray("colf" );// */ |
| 2948 | int stride = 5 * sizeof(float); |
| 2949 | |
| 2950 | symm_program0->setAttributeBuffer("vertex", GL_FLOAT, 0, 3 , stride); |
| 2951 | symm_program0->setAttributeBuffer("oprf", GL_FLOAT, sizeof(float)*3, 1, stride); |
| 2952 | symm_program0->setAttributeBuffer("colf", GL_FLOAT, sizeof(float)*4, 1, stride); |
| 2953 | |
| 2954 | symm_program0->setUniformValueArray("Color",scv,18,4);//we have to this for color changes too |
| 2955 | |
| 2956 | symm_program0->setUniformValue("lightPos", QVector3D(100.0, 100.0, 100.0)); |
| 2957 | programInfo(symm_program0, "symm0"); |
| 2958 | symm_program0->release(); |
| 2959 | symm_vertexBuffer0.release(); |
| 2960 | p.clear(); |
| 2961 | |
| 2962 | symm_vao0.release(); |
| 2963 | symm_vao1.create(); |
| 2964 | symm_vao1.bind(); |
| 2965 | |
| 2966 | for (int i = 0; i < mol->invvecs.size(); i++){ |
| 2967 | p.append(mol->invvecs.at(i).x); |
| 2968 | p.append(mol->invvecs.at(i).y); |
| 2969 | p.append(mol->invvecs.at(i).z); |
| 2970 | p.append(mol->invoprs.at(i)); |
| 2971 | p.append(5.0f); |
| 2972 | } |
| 2973 | symm_vertexBuffer1.create(); |
| 2974 | symm_vertexBuffer1.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 2975 | if (!symm_vertexBuffer1.bind()) {printf("I was unable to bind symm_vertexBuffer.\n");} |
| 2976 | invend = p.size(); |
| 2977 | symm_vertexBuffer1.allocate(p.data(),(p.size()*sizeof(float))); |
| 2978 | |
| 2979 | if (!symm_program1) symm_program1 = new QOpenGLShaderProgram(this); |
| 2980 | else symm_program1->removeAllShaders(); |
| 2981 | result = symm_program1->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/symm.vert"); |
| 2982 | //printf("%d\n",__LINE__); |
| 2983 | if ( !result ) qWarning() << symm_program1->log(); |
| 2984 | result = symm_program1->addCacheableShaderFromSourceFile( QOpenGLShader::Geometry, ":/shaders/symm.geom"); |
| 2985 | if ( !result ) qWarning() << symm_program1->log(); |
| 2986 | result = symm_program1->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/symm.frag"); |
| 2987 | if ( !result ) qWarning() << symm_program1->log(); |
| 2988 | result = symm_program1->link(); |
| 2989 | if ( !result ) qWarning() << symm_program1->log(); |
| 2990 | if ( !symm_program1->bind() ) { |
| 2991 | qWarning() << "Could not bind shader program to context"; |
| 2992 | return; |
| 2993 | } |
| 2994 | symm_program1->setUniformValueArray("Color",scv,18,4);//we have to this for color changes too |
| 2995 | symm_program1->setUniformValue("lightPos", QVector3D(100.0, 100.0, 100.0)); |
| 2996 | //* |
| 2997 | symm_program1->enableAttributeArray("vertex" ); |
| 2998 | symm_program1->enableAttributeArray("oprf" ); |
| 2999 | symm_program1->enableAttributeArray("colf" ); |
| 3000 | symm_program1->setAttributeBuffer("vertex", GL_FLOAT, 0, 3 , stride); |
| 3001 | symm_program1->setAttributeBuffer("oprf", GL_FLOAT, sizeof(float)*3, 1, stride); |
| 3002 | symm_program1->setAttributeBuffer("colf", GL_FLOAT, sizeof(float)*4, 1, stride); |
| 3003 | // */ |
| 3004 | programInfo(symm_program1, "symm1"); |
| 3005 | symm_program1->release(); |
| 3006 | symm_vao1.release(); |
| 3007 | p.clear(); |
| 3008 | symm_vao2.create(); |
| 3009 | symm_vao2.bind(); |
| 3010 | |
| 3011 | for (int ti = 0; ti < mol->ptriangles.size(); ti++){ |
| 3012 | p.append(mol->ptriangles.at(ti).nor.x); |
| 3013 | p.append(mol->ptriangles.at(ti).nor.y); |
| 3014 | p.append(mol->ptriangles.at(ti).nor.z); |
| 3015 | |
| 3016 | p.append(mol->ptriangles.at(ti).mid.x); |
| 3017 | p.append(mol->ptriangles.at(ti).mid.y); |
| 3018 | p.append(mol->ptriangles.at(ti).mid.z); |
| 3019 | |
| 3020 | p.append(mol->ptriangles.at(ti).verts0.x); |
| 3021 | p.append(mol->ptriangles.at(ti).verts0.y); |
| 3022 | p.append(mol->ptriangles.at(ti).verts0.z); |
| 3023 | |
| 3024 | p.append(mol->ptriangles.at(ti).verts1.x); |
| 3025 | p.append(mol->ptriangles.at(ti).verts1.y); |
| 3026 | p.append(mol->ptriangles.at(ti).verts1.z); |
| 3027 | |
| 3028 | p.append(mol->ptriangles.at(ti).glide.x); |
| 3029 | p.append(mol->ptriangles.at(ti).glide.y); |
| 3030 | p.append(mol->ptriangles.at(ti).glide.z); |
| 3031 | |
| 3032 | p.append(mol->ptriangles.at(ti).n); |
| 3033 | p.append(mol->ptriangles.at(ti).colr); |
| 3034 | //printf("ti %d n %d c %d\n",ti, mol->ptriangles.at(ti).n, mol->ptriangles.at(ti).colr); |
| 3035 | |
| 3036 | //p.append(ti%18); |
| 3037 | /* |
| 3038 | int pp = p.size(); |
| 3039 | printf("n%8.4f %8.4f %8.4f m%8.4f %8.4f %8.4f I:%8.4f %8.4f %8.4f II:%8.4f %8.4f %8.4f g %8.4f %3.0f %f n=%3.0f c=%f\n", |
| 3040 | p[pp-17], p[pp-16], p[pp-15], |
| 3041 | p[pp-14], p[pp-13], p[pp-12], |
| 3042 | p[pp-11], p[pp-10], p[pp-9], |
| 3043 | p[pp-8], p[pp-7], p[pp-6], |
| 3044 | p[pp-5], p[pp-4], p[pp-3], |
| 3045 | p[pp-2], |
| 3046 | p[pp-1]);// * / |
| 3047 | { |
| 3048 | V3 start = mol->ptriangles.at(ti).verts0; |
| 3049 | V3 end = mol->ptriangles.at(ti).verts1; |
| 3050 | V3 direction = Normalize(end - start); |
| 3051 | double l = sqrt(Norm(end - start)); |
| 3052 | V3 lot = (direction*V3(1, 0, 0) > 0.8)? |
| 3053 | (direction*V3(0, 1, 0) > 0.8)? |
| 3054 | Normalize(direction% V3(0, 0, 1)): |
| 3055 | Normalize(direction% V3(0, 1, 0)): |
| 3056 | Normalize(direction% V3(1, 0, 0)); |
| 3057 | V3 lot2 = Normalize(direction % lot); |
| 3058 | printf("%f (%f %f %f) lot (%f %f %f) lot2 (%f %f %f)\n",l,direction.x,direction.y,direction.z,lot.x,lot.y,lot.z,lot2.x,lot2.y,lot2.z); |
| 3059 | }// */ |
| 3060 | } |
| 3061 | |
| 3062 | |
| 3063 | |
| 3064 | glend = p.size(); |
| 3065 | symm_vertexBuffer2.create(); |
| 3066 | symm_vertexBuffer2.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 3067 | if (!symm_vertexBuffer2.bind()) {printf("I was unable to bind symm_vertexBuffer.\n");} |
| 3068 | symm_vertexBuffer2.allocate(p.data(),(p.size()*sizeof(float))); |
| 3069 | |
| 3070 | if (!symm_program2) symm_program2 = new QOpenGLShaderProgram(this); |
| 3071 | else symm_program2->removeAllShaders(); |
| 3072 | result = symm_program2->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/symmplane.vert"); |
| 3073 | //printf("%d\n",__LINE__); |
| 3074 | if ( !result ) qWarning() << symm_program2->log(); |
| 3075 | result = symm_program2->addCacheableShaderFromSourceFile( QOpenGLShader::Geometry, ":/shaders/symmplane.geom"); |
| 3076 | if ( !result ) qWarning() << symm_program2->log(); |
| 3077 | result = symm_program2->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/symmplane.frag"); |
| 3078 | if ( !result ) qWarning() << symm_program2->log(); |
| 3079 | result = symm_program2->link(); |
| 3080 | if ( !result ) qWarning() << symm_program2->log(); |
| 3081 | if ( !symm_program2->bind() ) { |
| 3082 | qWarning() << "Could not bind shader program to context"; |
| 3083 | return; |
| 3084 | } |
| 3085 | stride = 17 * sizeof(float); |
| 3086 | symm_program2->setUniformValueArray("Color",scv,18,4);//we have to this for color changes too |
| 3087 | symm_program2->setUniformValue("lightPos", QVector3D(100.0, 100.0, 100.0)); |
| 3088 | //* |
| 3089 | symm_program2->enableAttributeArray("nor"); |
| 3090 | symm_program2->enableAttributeArray("mid"); |
| 3091 | symm_program2->enableAttributeArray("verts0"); |
| 3092 | symm_program2->enableAttributeArray("verts1"); |
| 3093 | symm_program2->enableAttributeArray("glide"); |
| 3094 | symm_program2->enableAttributeArray("oprf"); |
| 3095 | symm_program2->enableAttributeArray("colf"); |
| 3096 | symm_program2->setAttributeBuffer("nor", GL_FLOAT, 0, 3 , stride); |
| 3097 | symm_program2->setAttributeBuffer("mid", GL_FLOAT, sizeof(float)*3, 3, stride); |
| 3098 | symm_program2->setAttributeBuffer("verts0", GL_FLOAT, sizeof(float)*6, 3, stride); |
| 3099 | symm_program2->setAttributeBuffer("verts1", GL_FLOAT, sizeof(float)*9, 3, stride); |
| 3100 | symm_program2->setAttributeBuffer("glide", GL_FLOAT, sizeof(float)*12, 3, stride); |
| 3101 | symm_program2->setAttributeBuffer("oprf", GL_FLOAT, sizeof(float)*15, 1, stride); |
| 3102 | symm_program2->setAttributeBuffer("colf", GL_FLOAT, sizeof(float)*16, 1, stride); |
| 3103 | |
| 3104 | programInfo(symm_program2, "symm2"); |
| 3105 | symm_program2->release(); |
| 3106 | symm_vao2.release(); |
| 3107 | |
| 3108 | printf("%d axend=%d invend=%d planend=%d glend=%d = %d ptriangles=%d \n",__LINE__,axend,invend,planend,glend,p.size(), mol->ptriangles.size()); |
| 3109 | shaderInfo=beforeInfo; |
| 3110 | } |
| 3111 | |
| 3112 | |
| 3113 | void PlayOpenGL::programInfo(QOpenGLShaderProgram *p, const QString pname){ |
| 3114 | if (!shaderInfo) return; |
| 3115 | GLint count; |
| 3116 | |
| 3117 | GLint size; // size of the variable |
| 3118 | GLenum type; // type of the variable (float, vec3 or mat4, etc) |
| 3119 | char cnam[100]; |
| 3120 | sprintf(cnam, "%s", pname.toStdString().c_str()); |
| 3121 | |
| 3122 | const GLsizei bufSize = 20; // maximum name length |
| 3123 | GLchar name[bufSize]; // variable name in GLSL |
| 3124 | GLsizei length; // name length |
| 3125 | //glGetProgramiv(p->programId(), GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &count); |
| 3126 | |
| 3127 | //printf("GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: %d\n", count); |
| 3128 | glGetProgramiv(p->programId(), GL_ACTIVE_ATTRIBUTES, &count); |
| 3129 | printf("\n#######################################################################################################################\n" |
| 3130 | "%-20s Active Attributes: %d\n#######################################################################################################################\n", cnam, count); |
| 3131 | |
| 3132 | |
| 3133 | for (GLint i = 0; i < count; i++){ |
| 3134 | glGetActiveAttrib(p->programId(), (GLuint)i, bufSize, &length, &size, &type, name); |
| 3135 | |
| 3136 | printf("%-20s Attribute #%-2d Type: %-23s Name: %-20s stringlength=%2d size=%d (%d)\n" |
| 3137 | , cnam |
| 3138 | , i |
| 3139 | , glTypeInt2String(type).toStdString().c_str() |
| 3140 | , name, length |
| 3141 | , size, p->attributeLocation(name)); |
| 3142 | } |
| 3143 | glGetProgramiv(p->programId(), GL_ACTIVE_UNIFORMS, &count); |
| 3144 | printf("%-20s Active Uniforms: %d\n#######################################################################################################################\n", cnam, count); |
| 3145 | |
| 3146 | for (GLint i = 0; i < count; i++){ |
| 3147 | glGetActiveUniform(p->programId(), (GLuint)i, bufSize, &length, &size, &type, name); |
| 3148 | |
| 3149 | printf("%-20s Uniform #%-2d Type: %-23s Name: %-20s stringlength=%2d size=%d\n", cnam, i, glTypeInt2String(type).toStdString().c_str(), name,length, size); |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | void PlayOpenGL::makeClassicAtoms(const CEnvironment &atoms){ |
| 3154 | |
| 3155 | printf("makeClassicAtoms\n"); |
| 3156 | rotze = (!isMainWindow)?0:-1; |
| 3157 | printf("makeAtoms rotation center set to: %d\n",rotze); |
| 3158 | makeCurrent(); |
| 3159 | GLenum err = GL_NO_ERROR; |
| 3160 | while((err = glGetError()) != GL_NO_ERROR) |
| 3161 | { |
| 3162 | printf("before makeAtoms %s error %X\n", parent()->objectName().toStdString().c_str(),err); |
| 3163 | //printf("%s\n",(char*)gluErrorString(err)); |
| 3164 | } |
| 3165 | catom_vao.release(); |
| 3166 | if (catom_vao.isCreated()) { |
| 3167 | catom_vao.release(); |
| 3168 | catom_vao.destroy(); |
| 3169 | catom_vertexBuffer.destroy(); |
| 3170 | catom_indexBuffer.destroy(); |
| 3171 | catom_program->release(); |
| 3172 | catom_program->removeAllShaders(); |
| 3173 | } |
| 3174 | catom_vao.create(); |
| 3175 | catom_vao.bind(); |
| 3176 | //glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
| 3177 | catom_vertexBuffer.create(); |
| 3178 | catom_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 3179 | if (!catom_vertexBuffer.bind()) {printf("I was unable to bind classic atom_vertexBuffer.\n");} |
| 3180 | static const GLuint idx2[960] = { |
| 3181 | 1, 42, 44,// 0 0.275904 0.321244 0.275904 |
| 3182 | 42, 12, 43,// 1 0.275904 0.312869 0.285473 |
| 3183 | 43, 14, 44,// 2 0.312869 0.275904 0.285473 |
| 3184 | 42, 43, 44,// 3 0.285473 0.285473 0.321244 |
| 3185 | 12, 45, 47,// 4 0.275904 0.285473 0.312869 |
| 3186 | 45, 0, 46,// 5 0.275904 0.275904 0.321244 |
| 3187 | 46, 13, 47,// 6 0.275904 0.312869 0.285473 |
| 3188 | 45, 46, 47,// 7 0.321244 0.285473 0.285473 |
| 3189 | 13, 48, 50,// 8 0.275904 0.285473 0.312869 |
| 3190 | 48, 5, 49,// 9 0.275904 0.275904 0.321244 |
| 3191 | 49, 14, 50,// 10 0.275904 0.312869 0.285473 |
| 3192 | 48, 49, 50,// 11 0.321244 0.285473 0.285473 |
| 3193 | 12, 47, 43,// 12 0.312869 0.324920 0.312869 |
| 3194 | 47, 13, 50,// 13 0.312869 0.312869 0.324920 |
| 3195 | 50, 14, 43,// 14 0.312869 0.312869 0.324920 |
| 3196 | 47, 50, 43,// 15 0.324920 0.324920 0.324920 |
| 3197 | 0, 45, 52,// 16 0.275904 0.321244 0.275904 |
| 3198 | 45, 12, 51,// 17 0.275904 0.312869 0.285473 |
| 3199 | 51, 16, 52,// 18 0.312869 0.275904 0.285473 |
| 3200 | 45, 51, 52,// 19 0.285473 0.285473 0.321244 |
| 3201 | 12, 42, 54,// 20 0.275904 0.285473 0.312869 |
| 3202 | 42, 1, 53,// 21 0.275904 0.275904 0.321244 |
| 3203 | 53, 15, 54,// 22 0.275904 0.312869 0.285473 |
| 3204 | 42, 53, 54,// 23 0.321244 0.285473 0.285473 |
| 3205 | 15, 55, 57,// 24 0.275904 0.285473 0.312869 |
| 3206 | 55, 7, 56,// 25 0.275904 0.275904 0.321244 |
| 3207 | 56, 16, 57,// 26 0.275904 0.312869 0.285473 |
| 3208 | 55, 56, 57,// 27 0.321244 0.285473 0.285473 |
| 3209 | 12, 54, 51,// 28 0.312869 0.324920 0.312869 |
| 3210 | 54, 15, 57,// 29 0.312869 0.312869 0.324920 |
| 3211 | 57, 16, 51,// 30 0.312869 0.312869 0.324920 |
| 3212 | 54, 57, 51,// 31 0.324920 0.324920 0.324920 |
| 3213 | 10, 58, 60,// 32 0.275904 0.321244 0.275904 |
| 3214 | 58, 17, 59,// 33 0.275904 0.312869 0.285473 |
| 3215 | 59, 18, 60,// 34 0.312869 0.275904 0.285473 |
| 3216 | 58, 59, 60,// 35 0.285473 0.285473 0.321244 |
| 3217 | 17, 61, 62,// 36 0.275904 0.285473 0.312869 |
| 3218 | 61, 0, 52,// 37 0.275904 0.275904 0.321244 |
| 3219 | 52, 16, 62,// 38 0.275904 0.312869 0.285473 |
| 3220 | 61, 52, 62,// 39 0.321244 0.285473 0.285473 |
| 3221 | 16, 56, 64,// 40 0.275904 0.285473 0.312869 |
| 3222 | 56, 7, 63,// 41 0.275904 0.275904 0.321244 |
| 3223 | 63, 18, 64,// 42 0.275904 0.312869 0.285473 |
| 3224 | 56, 63, 64,// 43 0.321244 0.285473 0.285473 |
| 3225 | 17, 62, 59,// 44 0.312869 0.324920 0.312869 |
| 3226 | 62, 16, 64,// 45 0.312869 0.312869 0.324920 |
| 3227 | 64, 18, 59,// 46 0.312869 0.312869 0.324920 |
| 3228 | 62, 64, 59,// 47 0.324920 0.324920 0.324920 |
| 3229 | 0, 61, 66,// 48 0.275904 0.321244 0.275904 |
| 3230 | 61, 17, 65,// 49 0.275904 0.312869 0.285473 |
| 3231 | 65, 20, 66,// 50 0.312869 0.275904 0.285473 |
| 3232 | 61, 65, 66,// 51 0.285473 0.285473 0.321244 |
| 3233 | 17, 58, 68,// 52 0.275904 0.285473 0.312869 |
| 3234 | 58, 10, 67,// 53 0.275904 0.275904 0.321244 |
| 3235 | 67, 19, 68,// 54 0.275904 0.312869 0.285473 |
| 3236 | 58, 67, 68,// 55 0.321244 0.285473 0.285473 |
| 3237 | 19, 69, 71,// 56 0.275904 0.285473 0.312869 |
| 3238 | 69, 11, 70,// 57 0.275904 0.275904 0.321244 |
| 3239 | 70, 20, 71,// 58 0.275904 0.312869 0.285473 |
| 3240 | 69, 70, 71,// 59 0.321244 0.285473 0.285473 |
| 3241 | 17, 68, 65,// 60 0.312869 0.324920 0.312869 |
| 3242 | 68, 19, 71,// 61 0.312869 0.312869 0.324920 |
| 3243 | 71, 20, 65,// 62 0.312869 0.312869 0.324920 |
| 3244 | 68, 71, 65,// 63 0.324920 0.324920 0.324920 |
| 3245 | 11, 72, 70,// 64 0.275904 0.321244 0.275904 |
| 3246 | 72, 21, 73,// 65 0.275904 0.312869 0.285473 |
| 3247 | 73, 20, 70,// 66 0.312869 0.275904 0.285473 |
| 3248 | 72, 73, 70,// 67 0.285473 0.285473 0.321244 |
| 3249 | 21, 74, 75,// 68 0.275904 0.285473 0.312869 |
| 3250 | 74, 5, 48,// 69 0.275904 0.275904 0.321244 |
| 3251 | 48, 13, 75,// 70 0.275904 0.312869 0.285473 |
| 3252 | 74, 48, 75,// 71 0.321244 0.285473 0.285473 |
| 3253 | 13, 46, 76,// 72 0.275904 0.285473 0.312869 |
| 3254 | 46, 0, 66,// 73 0.275904 0.275904 0.321244 |
| 3255 | 66, 20, 76,// 74 0.275904 0.312869 0.285473 |
| 3256 | 46, 66, 76,// 75 0.321244 0.285473 0.285473 |
| 3257 | 21, 75, 73,// 76 0.312869 0.324920 0.312869 |
| 3258 | 75, 13, 76,// 77 0.312869 0.312869 0.324920 |
| 3259 | 76, 20, 73,// 78 0.312869 0.312869 0.324920 |
| 3260 | 75, 76, 73,// 79 0.324920 0.324920 0.324920 |
| 3261 | 5, 74, 78,// 80 0.275904 0.321244 0.275904 |
| 3262 | 74, 21, 77,// 81 0.275904 0.312869 0.285473 |
| 3263 | 77, 23, 78,// 82 0.312869 0.275904 0.285473 |
| 3264 | 74, 77, 78,// 83 0.285473 0.285473 0.321244 |
| 3265 | 21, 72, 80,// 84 0.275904 0.285473 0.312869 |
| 3266 | 72, 11, 79,// 85 0.275904 0.275904 0.321244 |
| 3267 | 79, 22, 80,// 86 0.275904 0.312869 0.285473 |
| 3268 | 72, 79, 80,// 87 0.321244 0.285473 0.285473 |
| 3269 | 22, 81, 83,// 88 0.275904 0.285473 0.312869 |
| 3270 | 81, 4, 82,// 89 0.275904 0.275904 0.321244 |
| 3271 | 82, 23, 83,// 90 0.275904 0.312869 0.285473 |
| 3272 | 81, 82, 83,// 91 0.321244 0.285473 0.285473 |
| 3273 | 21, 80, 77,// 92 0.312869 0.324920 0.312869 |
| 3274 | 80, 22, 83,// 93 0.312869 0.312869 0.324920 |
| 3275 | 83, 23, 77,// 94 0.312869 0.312869 0.324920 |
| 3276 | 80, 83, 77,// 95 0.324920 0.324920 0.324920 |
| 3277 | 2, 84, 86,// 96 0.275904 0.321244 0.275904 |
| 3278 | 84, 24, 85,// 97 0.275904 0.312869 0.285473 |
| 3279 | 85, 25, 86,// 98 0.312869 0.275904 0.285473 |
| 3280 | 84, 85, 86,// 99 0.285473 0.285473 0.321244 |
| 3281 | 24, 87, 88,//100 0.275904 0.285473 0.312869 |
| 3282 | 87, 11, 69,//101 0.275904 0.275904 0.321244 |
| 3283 | 69, 19, 88,//102 0.275904 0.312869 0.285473 |
| 3284 | 87, 69, 88,//103 0.321244 0.285473 0.285473 |
| 3285 | 19, 67, 90,//104 0.275904 0.285473 0.312869 |
| 3286 | 67, 10, 89,//105 0.275904 0.275904 0.321244 |
| 3287 | 89, 25, 90,//106 0.275904 0.312869 0.285473 |
| 3288 | 67, 89, 90,//107 0.321244 0.285473 0.285473 |
| 3289 | 24, 88, 85,//108 0.312869 0.324920 0.312869 |
| 3290 | 88, 19, 90,//109 0.312869 0.312869 0.324920 |
| 3291 | 90, 25, 85,//110 0.312869 0.312869 0.324920 |
| 3292 | 88, 90, 85,//111 0.324920 0.324920 0.324920 |
| 3293 | 11, 87, 79,//112 0.275904 0.321244 0.275904 |
| 3294 | 87, 24, 91,//113 0.275904 0.312869 0.285473 |
| 3295 | 91, 22, 79,//114 0.312869 0.275904 0.285473 |
| 3296 | 87, 91, 79,//115 0.285473 0.285473 0.321244 |
| 3297 | 24, 84, 93,//116 0.275904 0.285473 0.312869 |
| 3298 | 84, 2, 92,//117 0.275904 0.275904 0.321244 |
| 3299 | 92, 26, 93,//118 0.275904 0.312869 0.285473 |
| 3300 | 84, 92, 93,//119 0.321244 0.285473 0.285473 |
| 3301 | 26, 94, 95,//120 0.275904 0.285473 0.312869 |
| 3302 | 94, 4, 81,//121 0.275904 0.275904 0.321244 |
| 3303 | 81, 22, 95,//122 0.275904 0.312869 0.285473 |
| 3304 | 94, 81, 95,//123 0.321244 0.285473 0.285473 |
| 3305 | 24, 93, 91,//124 0.312869 0.324920 0.312869 |
| 3306 | 93, 26, 95,//125 0.312869 0.312869 0.324920 |
| 3307 | 95, 22, 91,//126 0.312869 0.312869 0.324920 |
| 3308 | 93, 95, 91,//127 0.324920 0.324920 0.324920 |
| 3309 | 10, 96, 89,//128 0.275904 0.321244 0.275904 |
| 3310 | 96, 27, 97,//129 0.275904 0.312869 0.285473 |
| 3311 | 97, 25, 89,//130 0.312869 0.275904 0.285473 |
| 3312 | 96, 97, 89,//131 0.285473 0.285473 0.321244 |
| 3313 | 27, 98, 100,//132 0.275904 0.285473 0.312869 |
| 3314 | 98, 6, 99,//133 0.275904 0.275904 0.321244 |
| 3315 | 99, 28, 100,//134 0.275904 0.312869 0.285473 |
| 3316 | 98, 99, 100,//135 0.321244 0.285473 0.285473 |
| 3317 | 28, 101, 102,//136 0.275904 0.285473 0.312869 |
| 3318 | 101, 2, 86,//137 0.275904 0.275904 0.321244 |
| 3319 | 86, 25, 102,//138 0.275904 0.312869 0.285473 |
| 3320 | 101, 86, 102,//139 0.321244 0.285473 0.285473 |
| 3321 | 27, 100, 97,//140 0.312869 0.324920 0.312869 |
| 3322 | 100, 28, 102,//141 0.312869 0.312869 0.324920 |
| 3323 | 102, 25, 97,//142 0.312869 0.312869 0.324920 |
| 3324 | 100, 102, 97,//143 0.324920 0.324920 0.324920 |
| 3325 | 6, 98, 104,//144 0.275904 0.321244 0.275904 |
| 3326 | 98, 27, 103,//145 0.275904 0.312869 0.285473 |
| 3327 | 103, 29, 104,//146 0.312869 0.275904 0.285473 |
| 3328 | 98, 103, 104,//147 0.285473 0.285473 0.321244 |
| 3329 | 27, 96, 105,//148 0.275904 0.285473 0.312869 |
| 3330 | 96, 10, 60,//149 0.275904 0.275904 0.321244 |
| 3331 | 60, 18, 105,//150 0.275904 0.312869 0.285473 |
| 3332 | 96, 60, 105,//151 0.321244 0.285473 0.285473 |
| 3333 | 18, 63, 107,//152 0.275904 0.285473 0.312869 |
| 3334 | 63, 7, 106,//153 0.275904 0.275904 0.321244 |
| 3335 | 106, 29, 107,//154 0.275904 0.312869 0.285473 |
| 3336 | 63, 106, 107,//155 0.321244 0.285473 0.285473 |
| 3337 | 27, 105, 103,//156 0.312869 0.324920 0.312869 |
| 3338 | 105, 18, 107,//157 0.312869 0.312869 0.324920 |
| 3339 | 107, 29, 103,//158 0.312869 0.312869 0.324920 |
| 3340 | 105, 107, 103,//159 0.324920 0.324920 0.324920 |
| 3341 | 7, 108, 106,//160 0.275904 0.321244 0.275904 |
| 3342 | 108, 30, 109,//161 0.275904 0.312869 0.285473 |
| 3343 | 109, 29, 106,//162 0.312869 0.275904 0.285473 |
| 3344 | 108, 109, 106,//163 0.285473 0.285473 0.321244 |
| 3345 | 30, 110, 112,//164 0.275904 0.285473 0.312869 |
| 3346 | 110, 8, 111,//165 0.275904 0.275904 0.321244 |
| 3347 | 111, 31, 112,//166 0.275904 0.312869 0.285473 |
| 3348 | 110, 111, 112,//167 0.321244 0.285473 0.285473 |
| 3349 | 31, 113, 114,//168 0.275904 0.285473 0.312869 |
| 3350 | 113, 6, 104,//169 0.275904 0.275904 0.321244 |
| 3351 | 104, 29, 114,//170 0.275904 0.312869 0.285473 |
| 3352 | 113, 104, 114,//171 0.321244 0.285473 0.285473 |
| 3353 | 30, 112, 109,//172 0.312869 0.324920 0.312869 |
| 3354 | 112, 31, 114,//173 0.312869 0.312869 0.324920 |
| 3355 | 114, 29, 109,//174 0.312869 0.312869 0.324920 |
| 3356 | 112, 114, 109,//175 0.324920 0.324920 0.324920 |
| 3357 | 8, 110, 116,//176 0.275904 0.321244 0.275904 |
| 3358 | 110, 30, 115,//177 0.275904 0.312869 0.285473 |
| 3359 | 115, 32, 116,//178 0.312869 0.275904 0.285473 |
| 3360 | 110, 115, 116,//179 0.285473 0.285473 0.321244 |
| 3361 | 30, 108, 117,//180 0.275904 0.285473 0.312869 |
| 3362 | 108, 7, 55,//181 0.275904 0.275904 0.321244 |
| 3363 | 55, 15, 117,//182 0.275904 0.312869 0.285473 |
| 3364 | 108, 55, 117,//183 0.321244 0.285473 0.285473 |
| 3365 | 15, 53, 119,//184 0.275904 0.285473 0.312869 |
| 3366 | 53, 1, 118,//185 0.275904 0.275904 0.321244 |
| 3367 | 118, 32, 119,//186 0.275904 0.312869 0.285473 |
| 3368 | 53, 118, 119,//187 0.321244 0.285473 0.285473 |
| 3369 | 30, 117, 115,//188 0.312869 0.324920 0.312869 |
| 3370 | 117, 15, 119,//189 0.312869 0.312869 0.324920 |
| 3371 | 119, 32, 115,//190 0.312869 0.312869 0.324920 |
| 3372 | 117, 119, 115,//191 0.324920 0.324920 0.324920 |
| 3373 | 9, 120, 122,//192 0.275904 0.321244 0.275904 |
| 3374 | 120, 33, 121,//193 0.275904 0.312869 0.285473 |
| 3375 | 121, 34, 122,//194 0.312869 0.275904 0.285473 |
| 3376 | 120, 121, 122,//195 0.285473 0.285473 0.321244 |
| 3377 | 33, 123, 124,//196 0.275904 0.285473 0.312869 |
| 3378 | 123, 1, 44,//197 0.275904 0.275904 0.321244 |
| 3379 | 44, 14, 124,//198 0.275904 0.312869 0.285473 |
| 3380 | 123, 44, 124,//199 0.321244 0.285473 0.285473 |
| 3381 | 14, 49, 126,//200 0.275904 0.285473 0.312869 |
| 3382 | 49, 5, 125,//201 0.275904 0.275904 0.321244 |
| 3383 | 125, 34, 126,//202 0.275904 0.312869 0.285473 |
| 3384 | 49, 125, 126,//203 0.321244 0.285473 0.285473 |
| 3385 | 33, 124, 121,//204 0.312869 0.324920 0.312869 |
| 3386 | 124, 14, 126,//205 0.312869 0.312869 0.324920 |
| 3387 | 126, 34, 121,//206 0.312869 0.312869 0.324920 |
| 3388 | 124, 126, 121,//207 0.324920 0.324920 0.324920 |
| 3389 | 1, 123, 118,//208 0.275904 0.321244 0.275904 |
| 3390 | 123, 33, 127,//209 0.275904 0.312869 0.285473 |
| 3391 | 127, 32, 118,//210 0.312869 0.275904 0.285473 |
| 3392 | 123, 127, 118,//211 0.285473 0.285473 0.321244 |
| 3393 | 33, 120, 129,//212 0.275904 0.285473 0.312869 |
| 3394 | 120, 9, 128,//213 0.275904 0.275904 0.321244 |
| 3395 | 128, 35, 129,//214 0.275904 0.312869 0.285473 |
| 3396 | 120, 128, 129,//215 0.321244 0.285473 0.285473 |
| 3397 | 35, 130, 131,//216 0.275904 0.285473 0.312869 |
| 3398 | 130, 8, 116,//217 0.275904 0.275904 0.321244 |
| 3399 | 116, 32, 131,//218 0.275904 0.312869 0.285473 |
| 3400 | 130, 116, 131,//219 0.321244 0.285473 0.285473 |
| 3401 | 33, 129, 127,//220 0.312869 0.324920 0.312869 |
| 3402 | 129, 35, 131,//221 0.312869 0.312869 0.324920 |
| 3403 | 131, 32, 127,//222 0.312869 0.312869 0.324920 |
| 3404 | 129, 131, 127,//223 0.324920 0.324920 0.324920 |
| 3405 | 4, 132, 82,//224 0.275904 0.321244 0.275904 |
| 3406 | 132, 36, 133,//225 0.275904 0.312869 0.285473 |
| 3407 | 133, 23, 82,//226 0.312869 0.275904 0.285473 |
| 3408 | 132, 133, 82,//227 0.285473 0.285473 0.321244 |
| 3409 | 36, 134, 135,//228 0.275904 0.285473 0.312869 |
| 3410 | 134, 9, 122,//229 0.275904 0.275904 0.321244 |
| 3411 | 122, 34, 135,//230 0.275904 0.312869 0.285473 |
| 3412 | 134, 122, 135,//231 0.321244 0.285473 0.285473 |
| 3413 | 34, 125, 136,//232 0.275904 0.285473 0.312869 |
| 3414 | 125, 5, 78,//233 0.275904 0.275904 0.321244 |
| 3415 | 78, 23, 136,//234 0.275904 0.312869 0.285473 |
| 3416 | 125, 78, 136,//235 0.321244 0.285473 0.285473 |
| 3417 | 36, 135, 133,//236 0.312869 0.324920 0.312869 |
| 3418 | 135, 34, 136,//237 0.312869 0.312869 0.324920 |
| 3419 | 136, 23, 133,//238 0.312869 0.312869 0.324920 |
| 3420 | 135, 136, 133,//239 0.324920 0.324920 0.324920 |
| 3421 | 9, 134, 138,//240 0.275904 0.321244 0.275904 |
| 3422 | 134, 36, 137,//241 0.275904 0.312869 0.285473 |
| 3423 | 137, 38, 138,//242 0.312869 0.275904 0.285473 |
| 3424 | 134, 137, 138,//243 0.285473 0.285473 0.321244 |
| 3425 | 36, 132, 140,//244 0.275904 0.285473 0.312869 |
| 3426 | 132, 4, 139,//245 0.275904 0.275904 0.321244 |
| 3427 | 139, 37, 140,//246 0.275904 0.312869 0.285473 |
| 3428 | 132, 139, 140,//247 0.321244 0.285473 0.285473 |
| 3429 | 37, 141, 143,//248 0.275904 0.285473 0.312869 |
| 3430 | 141, 3, 142,//249 0.275904 0.275904 0.321244 |
| 3431 | 142, 38, 143,//250 0.275904 0.312869 0.285473 |
| 3432 | 141, 142, 143,//251 0.321244 0.285473 0.285473 |
| 3433 | 36, 140, 137,//252 0.312869 0.324920 0.312869 |
| 3434 | 140, 37, 143,//253 0.312869 0.312869 0.324920 |
| 3435 | 143, 38, 137,//254 0.312869 0.312869 0.324920 |
| 3436 | 140, 143, 137,//255 0.324920 0.324920 0.324920 |
| 3437 | 3, 144, 142,//256 0.275904 0.321244 0.275904 |
| 3438 | 144, 39, 145,//257 0.275904 0.312869 0.285473 |
| 3439 | 145, 38, 142,//258 0.312869 0.275904 0.285473 |
| 3440 | 144, 145, 142,//259 0.285473 0.285473 0.321244 |
| 3441 | 39, 146, 147,//260 0.275904 0.285473 0.312869 |
| 3442 | 146, 8, 130,//261 0.275904 0.275904 0.321244 |
| 3443 | 130, 35, 147,//262 0.275904 0.312869 0.285473 |
| 3444 | 146, 130, 147,//263 0.321244 0.285473 0.285473 |
| 3445 | 35, 128, 148,//264 0.275904 0.285473 0.312869 |
| 3446 | 128, 9, 138,//265 0.275904 0.275904 0.321244 |
| 3447 | 138, 38, 148,//266 0.275904 0.312869 0.285473 |
| 3448 | 128, 138, 148,//267 0.321244 0.285473 0.285473 |
| 3449 | 39, 147, 145,//268 0.312869 0.324920 0.312869 |
| 3450 | 147, 35, 148,//269 0.312869 0.312869 0.324920 |
| 3451 | 148, 38, 145,//270 0.312869 0.312869 0.324920 |
| 3452 | 147, 148, 145,//271 0.324920 0.324920 0.324920 |
| 3453 | 8, 146, 111,//272 0.275904 0.321244 0.275904 |
| 3454 | 146, 39, 149,//273 0.275904 0.312869 0.285473 |
| 3455 | 149, 31, 111,//274 0.312869 0.275904 0.285473 |
| 3456 | 146, 149, 111,//275 0.285473 0.285473 0.321244 |
| 3457 | 39, 144, 151,//276 0.275904 0.285473 0.312869 |
| 3458 | 144, 3, 150,//277 0.275904 0.275904 0.321244 |
| 3459 | 150, 40, 151,//278 0.275904 0.312869 0.285473 |
| 3460 | 144, 150, 151,//279 0.321244 0.285473 0.285473 |
| 3461 | 40, 152, 153,//280 0.275904 0.285473 0.312869 |
| 3462 | 152, 6, 113,//281 0.275904 0.275904 0.321244 |
| 3463 | 113, 31, 153,//282 0.275904 0.312869 0.285473 |
| 3464 | 152, 113, 153,//283 0.321244 0.285473 0.285473 |
| 3465 | 39, 151, 149,//284 0.312869 0.324920 0.312869 |
| 3466 | 151, 40, 153,//285 0.312869 0.312869 0.324920 |
| 3467 | 153, 31, 149,//286 0.312869 0.312869 0.324920 |
| 3468 | 151, 153, 149,//287 0.324920 0.324920 0.324920 |
| 3469 | 3, 154, 150,//288 0.275904 0.321244 0.275904 |
| 3470 | 154, 41, 155,//289 0.275904 0.312869 0.285473 |
| 3471 | 155, 40, 150,//290 0.312869 0.275904 0.285473 |
| 3472 | 154, 155, 150,//291 0.285473 0.285473 0.321244 |
| 3473 | 41, 156, 157,//292 0.275904 0.285473 0.312869 |
| 3474 | 156, 2, 101,//293 0.275904 0.275904 0.321244 |
| 3475 | 101, 28, 157,//294 0.275904 0.312869 0.285473 |
| 3476 | 156, 101, 157,//295 0.321244 0.285473 0.285473 |
| 3477 | 28, 99, 158,//296 0.275904 0.285473 0.312869 |
| 3478 | 99, 6, 152,//297 0.275904 0.275904 0.321244 |
| 3479 | 152, 40, 158,//298 0.275904 0.312869 0.285473 |
| 3480 | 99, 152, 158,//299 0.321244 0.285473 0.285473 |
| 3481 | 41, 157, 155,//300 0.312869 0.324920 0.312869 |
| 3482 | 157, 28, 158,//301 0.312869 0.312869 0.324920 |
| 3483 | 158, 40, 155,//302 0.312869 0.312869 0.324920 |
| 3484 | 157, 158, 155,//303 0.324920 0.324920 0.324920 |
| 3485 | 2, 156, 92,//304 0.275904 0.321244 0.275904 |
| 3486 | 156, 41, 159,//305 0.275904 0.312869 0.285473 |
| 3487 | 159, 26, 92,//306 0.312869 0.275904 0.285473 |
| 3488 | 156, 159, 92,//307 0.285473 0.285473 0.321244 |
| 3489 | 41, 154, 160,//308 0.275904 0.285473 0.312869 |
| 3490 | 154, 3, 141,//309 0.275904 0.275904 0.321244 |
| 3491 | 141, 37, 160,//310 0.275904 0.312869 0.285473 |
| 3492 | 154, 141, 160,//311 0.321244 0.285473 0.285473 |
| 3493 | 37, 139, 161,//312 0.275904 0.285473 0.312869 |
| 3494 | 139, 4, 94,//313 0.275904 0.275904 0.321244 |
| 3495 | 94, 26, 161,//314 0.275904 0.312869 0.285473 |
| 3496 | 139, 94, 161,//315 0.321244 0.285473 0.285473 |
| 3497 | 41, 160, 159,//316 0.312869 0.324920 0.312869 |
| 3498 | 160, 37, 161,//317 0.312869 0.312869 0.324920 |
| 3499 | 161, 26, 159,//318 0.312869 0.312869 0.324920 |
| 3500 | 160, 161, 159 //319 0.324920 0.324920 0.324920 |
| 3501 | }; |
| 3502 | static const GLfloat v[486] = { |
| 3503 | -0.525731f, 0.850651f, 0.000000f,//0 |
| 3504 | 0.525731f, 0.850651f, 0.000000f,//1 |
| 3505 | -0.525731f, -0.850651f, 0.000000f,//2 |
| 3506 | 0.525731f, -0.850651f, 0.000000f,//3 |
| 3507 | 0.000000f, -0.525731f, 0.850651f,//4 |
| 3508 | 0.000000f, 0.525731f, 0.850651f,//5 |
| 3509 | 0.000000f, -0.525731f, -0.850651f,//6 |
| 3510 | 0.000000f, 0.525731f, -0.850651f,//7 |
| 3511 | 0.850651f, 0.000000f, -0.525731f,//8 |
| 3512 | 0.850651f, 0.000000f, 0.525731f,//9 |
| 3513 | -0.850651f, 0.000000f, -0.525731f,//10 |
| 3514 | -0.850651f, 0.000000f, 0.525731f,//11 |
| 3515 | 0.000000f, 1.000000f, 0.000000f,//12 |
| 3516 | -0.309017f, 0.809017f, 0.500000f,//13 |
| 3517 | 0.309017f, 0.809017f, 0.500000f,//14 |
| 3518 | 0.309017f, 0.809017f, -0.500000f,//15 |
| 3519 | -0.309017f, 0.809017f, -0.500000f,//16 |
| 3520 | -0.809017f, 0.500000f, -0.309017f,//17 |
| 3521 | -0.500000f, 0.309017f, -0.809017f,//18 |
| 3522 | -1.000000f, 0.000000f, 0.000000f,//19 |
| 3523 | -0.809017f, 0.500000f, 0.309017f,//20 |
| 3524 | -0.500000f, 0.309017f, 0.809017f,//21 |
| 3525 | -0.500000f, -0.309017f, 0.809017f,//22 |
| 3526 | 0.000000f, 0.000000f, 1.000000f,//23 |
| 3527 | -0.809017f, -0.500000f, 0.309017f,//24 |
| 3528 | -0.809017f, -0.500000f, -0.309017f,//25 |
| 3529 | -0.309017f, -0.809017f, 0.500000f,//26 |
| 3530 | -0.500000f, -0.309017f, -0.809017f,//27 |
| 3531 | -0.309017f, -0.809017f, -0.500000f,//28 |
| 3532 | 0.000000f, 0.000000f, -1.000000f,//29 |
| 3533 | 0.500000f, 0.309017f, -0.809017f,//30 |
| 3534 | 0.500000f, -0.309017f, -0.809017f,//31 |
| 3535 | 0.809017f, 0.500000f, -0.309017f,//32 |
| 3536 | 0.809017f, 0.500000f, 0.309017f,//33 |
| 3537 | 0.500000f, 0.309017f, 0.809017f,//34 |
| 3538 | 1.000000f, 0.000000f, 0.000000f,//35 |
| 3539 | 0.500000f, -0.309017f, 0.809017f,//36 |
| 3540 | 0.309017f, -0.809017f, 0.500000f,//37 |
| 3541 | 0.809017f, -0.500000f, 0.309017f,//38 |
| 3542 | 0.809017f, -0.500000f, -0.309017f,//39 |
| 3543 | 0.309017f, -0.809017f, -0.500000f,//40 |
| 3544 | 0.000000f, -1.000000f, 0.000000f,//41 |
| 3545 | 0.273267f, 0.961938f, 0.000000f,//42 |
| 3546 | 0.162460f, 0.951057f, 0.262866f,//43 |
| 3547 | 0.433889f, 0.862668f, 0.259892f,//44 |
| 3548 | -0.273267f, 0.961938f, 0.000000f,//45 |
| 3549 | -0.433889f, 0.862668f, 0.259892f,//46 |
| 3550 | -0.162460f, 0.951057f, 0.262866f,//47 |
| 3551 | -0.160622f, 0.693780f, 0.702046f,//48 |
| 3552 | 0.160622f, 0.693780f, 0.702046f,//49 |
| 3553 | 0.000000f, 0.850651f, 0.525731f,//50 |
| 3554 | -0.162460f, 0.951057f, -0.262866f,//51 |
| 3555 | -0.433889f, 0.862668f, -0.259892f,//52 |
| 3556 | 0.433889f, 0.862668f, -0.259892f,//53 |
| 3557 | 0.162460f, 0.951057f, -0.262866f,//54 |
| 3558 | 0.160622f, 0.693780f, -0.702046f,//55 |
| 3559 | -0.160622f, 0.693780f, -0.702046f,//56 |
| 3560 | 0.000000f, 0.850651f, -0.525731f,//57 |
| 3561 | -0.862668f, 0.259892f, -0.433889f,//58 |
| 3562 | -0.688191f, 0.425325f, -0.587785f,//59 |
| 3563 | -0.702046f, 0.160622f, -0.693780f,//60 |
| 3564 | -0.693780f, 0.702046f, -0.160622f,//61 |
| 3565 | -0.587785f, 0.688191f, -0.425325f,//62 |
| 3566 | -0.259892f, 0.433889f, -0.862668f,//63 |
| 3567 | -0.425325f, 0.587785f, -0.688191f,//64 |
| 3568 | -0.850651f, 0.525731f, 0.000000f,//65 |
| 3569 | -0.693780f, 0.702046f, 0.160622f,//66 |
| 3570 | -0.961938f, 0.000000f, -0.273267f,//67 |
| 3571 | -0.951057f, 0.262866f, -0.162460f,//68 |
| 3572 | -0.961938f, 0.000000f, 0.273267f,//69 |
| 3573 | -0.862668f, 0.259892f, 0.433889f,//70 |
| 3574 | -0.951057f, 0.262866f, 0.162460f,//71 |
| 3575 | -0.702046f, 0.160622f, 0.693780f,//72 |
| 3576 | -0.688191f, 0.425325f, 0.587785f,//73 |
| 3577 | -0.259892f, 0.433889f, 0.862668f,//74 |
| 3578 | -0.425325f, 0.587785f, 0.688191f,//75 |
| 3579 | -0.587785f, 0.688191f, 0.425325f,//76 |
| 3580 | -0.262866f, 0.162460f, 0.951057f,//77 |
| 3581 | 0.000000f, 0.273267f, 0.961938f,//78 |
| 3582 | -0.702046f, -0.160622f, 0.693780f,//79 |
| 3583 | -0.525731f, 0.000000f, 0.850651f,//80 |
| 3584 | -0.259892f, -0.433889f, 0.862668f,//81 |
| 3585 | 0.000000f, -0.273267f, 0.961938f,//82 |
| 3586 | -0.262866f, -0.162460f, 0.951057f,//83 |
| 3587 | -0.693780f, -0.702046f, 0.160622f,//84 |
| 3588 | -0.850651f, -0.525731f, 0.000000f,//85 |
| 3589 | -0.693780f, -0.702046f, -0.160622f,//86 |
| 3590 | -0.862668f, -0.259892f, 0.433889f,//87 |
| 3591 | -0.951057f, -0.262866f, 0.162460f,//88 |
| 3592 | -0.862668f, -0.259892f, -0.433889f,//89 |
| 3593 | -0.951057f, -0.262866f, -0.162460f,//90 |
| 3594 | -0.688191f, -0.425325f, 0.587785f,//91 |
| 3595 | -0.433889f, -0.862668f, 0.259892f,//92 |
| 3596 | -0.587785f, -0.688191f, 0.425325f,//93 |
| 3597 | -0.160622f, -0.693780f, 0.702046f,//94 |
| 3598 | -0.425325f, -0.587785f, 0.688191f,//95 |
| 3599 | -0.702046f, -0.160622f, -0.693780f,//96 |
| 3600 | -0.688191f, -0.425325f, -0.587785f,//97 |
| 3601 | -0.259892f, -0.433889f, -0.862668f,//98 |
| 3602 | -0.160622f, -0.693780f, -0.702046f,//99 |
| 3603 | -0.425325f, -0.587785f, -0.688191f,//100 |
| 3604 | -0.433889f, -0.862668f, -0.259892f,//101 |
| 3605 | -0.587785f, -0.688191f, -0.425325f,//102 |
| 3606 | -0.262866f, -0.162460f, -0.951057f,//103 |
| 3607 | 0.000000f, -0.273267f, -0.961938f,//104 |
| 3608 | -0.525731f, 0.000000f, -0.850651f,//105 |
| 3609 | 0.000000f, 0.273267f, -0.961938f,//106 |
| 3610 | -0.262866f, 0.162460f, -0.951057f,//107 |
| 3611 | 0.259892f, 0.433889f, -0.862668f,//108 |
| 3612 | 0.262866f, 0.162460f, -0.951057f,//109 |
| 3613 | 0.702046f, 0.160622f, -0.693780f,//110 |
| 3614 | 0.702046f, -0.160622f, -0.693780f,//111 |
| 3615 | 0.525731f, 0.000000f, -0.850651f,//112 |
| 3616 | 0.259892f, -0.433889f, -0.862668f,//113 |
| 3617 | 0.262866f, -0.162460f, -0.951057f,//114 |
| 3618 | 0.688191f, 0.425325f, -0.587785f,//115 |
| 3619 | 0.862668f, 0.259892f, -0.433889f,//116 |
| 3620 | 0.425325f, 0.587785f, -0.688191f,//117 |
| 3621 | 0.693780f, 0.702046f, -0.160622f,//118 |
| 3622 | 0.587785f, 0.688191f, -0.425325f,//119 |
| 3623 | 0.862668f, 0.259892f, 0.433889f,//120 |
| 3624 | 0.688191f, 0.425325f, 0.587785f,//121 |
| 3625 | 0.702046f, 0.160622f, 0.693780f,//122 |
| 3626 | 0.693780f, 0.702046f, 0.160622f,//123 |
| 3627 | 0.587785f, 0.688191f, 0.425325f,//124 |
| 3628 | 0.259892f, 0.433889f, 0.862668f,//125 |
| 3629 | 0.425325f, 0.587785f, 0.688191f,//126 |
| 3630 | 0.850651f, 0.525731f, 0.000000f,//127 |
| 3631 | 0.961938f, 0.000000f, 0.273267f,//128 |
| 3632 | 0.951057f, 0.262866f, 0.162460f,//129 |
| 3633 | 0.961938f, 0.000000f, -0.273267f,//130 |
| 3634 | 0.951057f, 0.262866f, -0.162460f,//131 |
| 3635 | 0.259892f, -0.433889f, 0.862668f,//132 |
| 3636 | 0.262866f, -0.162460f, 0.951057f,//133 |
| 3637 | 0.702046f, -0.160622f, 0.693780f,//134 |
| 3638 | 0.525731f, 0.000000f, 0.850651f,//135 |
| 3639 | 0.262866f, 0.162460f, 0.951057f,//136 |
| 3640 | 0.688191f, -0.425325f, 0.587785f,//137 |
| 3641 | 0.862668f, -0.259892f, 0.433889f,//138 |
| 3642 | 0.160622f, -0.693780f, 0.702046f,//139 |
| 3643 | 0.425325f, -0.587785f, 0.688191f,//140 |
| 3644 | 0.433889f, -0.862668f, 0.259892f,//141 |
| 3645 | 0.693780f, -0.702046f, 0.160622f,//142 |
| 3646 | 0.587785f, -0.688191f, 0.425325f,//143 |
| 3647 | 0.693780f, -0.702046f, -0.160622f,//144 |
| 3648 | 0.850651f, -0.525731f, 0.000000f,//145 |
| 3649 | 0.862668f, -0.259892f, -0.433889f,//146 |
| 3650 | 0.951057f, -0.262866f, -0.162460f,//147 |
| 3651 | 0.951057f, -0.262866f, 0.162460f,//148 |
| 3652 | 0.688191f, -0.425325f, -0.587785f,//149 |
| 3653 | 0.433889f, -0.862668f, -0.259892f,//150 |
| 3654 | 0.587785f, -0.688191f, -0.425325f,//151 |
| 3655 | 0.160622f, -0.693780f, -0.702046f,//152 |
| 3656 | 0.425325f, -0.587785f, -0.688191f,//153 |
| 3657 | 0.273267f, -0.961938f, 0.000000f,//154 |
| 3658 | 0.162460f, -0.951057f, -0.262866f,//155 |
| 3659 | -0.273267f, -0.961938f, 0.000000f,//156 |
| 3660 | -0.162460f, -0.951057f, -0.262866f,//157 |
| 3661 | 0.000000f, -0.850651f, -0.525731f,//158 |
| 3662 | -0.162460f, -0.951057f, 0.262866f,//159 |
| 3663 | 0.162460f, -0.951057f, 0.262866f,//160 |
| 3664 | 0.000000f, -0.850651f, 0.525731f//161 |
| 3665 | }; |
| 3666 | |
| 3667 | catom_vertexBuffer.allocate(v, 486 * sizeof(float)); |
| 3668 | |
| 3669 | catom_indexBuffer = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer); // Mind: use 'IndexBuffer' here |
| 3670 | catom_indexBuffer.create(); |
| 3671 | catom_indexBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw); |
| 3672 | if (!catom_indexBuffer.bind()) {printf("I was unable to bind atom_indexBuffer!\n");} |
| 3673 | catom_indexBuffer.allocate( 960 * sizeof(GLuint) ); |
| 3674 | catom_indexBuffer.write(0, idx2, 960* sizeof(GLuint)); |
| 3675 | catom_index_size = 960; |
| 3676 | |
| 3677 | |
| 3678 | if (!catom_program) catom_program = new QOpenGLShaderProgram(this); |
| 3679 | else catom_program->removeAllShaders(); |
| 3680 | |
| 3681 | //printf("%p %d\n",atom_program, atom_program->programId()); |
| 3682 | |
| 3683 | bool result = catom_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/catom.vert"); |
| 3684 | //printf("%d\n",__LINE__); |
| 3685 | if ( !result ) qWarning() << catom_program->log(); |
| 3686 | result = catom_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/catom.frag"); |
| 3687 | |
| 3688 | if ( !result ) qWarning() << catom_program->log(); |
| 3689 | result = catom_program->link(); |
| 3690 | if ( !result ) qWarning() << catom_program->log(); |
| 3691 | |
| 3692 | if ( !catom_program->bind() ) { |
| 3693 | qWarning() << "Could not bind shader program to context"; |
| 3694 | return; |
| 3695 | } |
| 3696 | //printf("!!! %d !!!\n",shaderInfo); |
| 3697 | programInfo(catom_program,"atom"); |
| 3698 | GLfloat acv[109*3]; |
| 3699 | for (int i=0;i<109;i++) { |
| 3700 | acv[3*i]=mol->atomColor(i,false).redF(); |
| 3701 | acv[3*i+1]=mol->atomColor(i,false).greenF(); |
| 3702 | acv[3*i+2]=mol->atomColor(i,false).blueF(); |
| 3703 | } |
| 3704 | GLfloat arv[109]; |
| 3705 | for (int i=0;i<109;i++) { |
| 3706 | arv[i]=static_cast<GLfloat>(mol->arad[i]); |
| 3707 | } |
| 3708 | |
| 3709 | atom_program->setUniformValueArray("atomColors",acv, 109,3); |
| 3710 | atom_program->setUniformValueArray("arad",arv, 109,1); |
| 3711 | |
| 3712 | atom_program->setUniformValue("pmv", pmv); |
| 3713 | /*for (int i = 0; i < atoms.size(); i++){ |
| 3714 | qDebug()<<pmv.map(QVector3D(atoms.at(i).pos.x-sumse.x,atoms.at(i).pos.y-sumse.y,atoms.at(i).pos.z-sumse.z)); |
| 3715 | }// */ |
| 3716 | |
| 3717 | //printf("%d\n",__LINE__); |
| 3718 | atom_program->enableAttributeArray(0); |
| 3719 | atom_program->enableAttributeArray(1); |
| 3720 | atom_program->enableAttributeArray(2); |
| 3721 | atom_program->enableAttributeArray(3); |
| 3722 | atom_program->enableAttributeArray(4); |
| 3723 | atom_program->enableAttributeArray(5); |
| 3724 | //printf("%d\n",__LINE__); |
| 3725 | int stride = 6 * 4 * sizeof(float); |
| 3726 | atom_program->setAttributeBuffer(0, GL_FLOAT, 0, 4, stride); |
| 3727 | atom_program->setAttributeBuffer(1, GL_FLOAT, sizeof(float)*4 , 4, stride); |
| 3728 | atom_program->setAttributeBuffer(2, GL_FLOAT, sizeof(float)*8 , 4, stride); |
| 3729 | atom_program->setAttributeBuffer(3, GL_FLOAT, sizeof(float)*12 , 4, stride); |
| 3730 | atom_program->setAttributeBuffer(4, GL_FLOAT, sizeof(float)*16 , 4, stride); |
| 3731 | atom_program->setAttributeBuffer(5, GL_FLOAT, sizeof(float)*20 , 4, stride);// 20*sizeof(float) |
| 3732 | |
| 3733 | atom_program->release(); |
| 3734 | atom_vao.release(); |
| 3735 | atom_indexBuffer.release(); |
| 3736 | atom_vertexBuffer.release(); |
| 3737 | atom_vertexBuffer.destroy(); |
| 3738 | atom_indexBuffer.destroy(); |
| 3739 | } |
| 3740 | void PlayOpenGL::makeAtoms(const CEnvironment &atoms){ |
| 3741 | /** |
| 3742 | * @brief this the initializer of a (crazy) idea of shader program. |
| 3743 | * @param atoms is a QList of MyAtoms |
| 3744 | * the idea is to construct atoms based on an icosahedron geometry and pass atom properties via 6 vec4 attributes. |
| 3745 | * from an icosahedron it creates |
| 3746 | * - an icosahedron |
| 3747 | * - a ball |
| 3748 | * - an ellipsoid |
| 3749 | * - a dodecahedron |
| 3750 | * - a cube |
| 3751 | * - a triacontahedron |
| 3752 | * - intersecting planes for adp |
| 3753 | **/ |
| 3754 | //printf("makeAtoms\n"); |
| 3755 | rotze = (!isMainWindow)?0:(rotze>=atoms.size())?-1:rotze; |
| 3756 | //printf("makeAtoms rotation center set to: %d\n",rotze); |
| 3757 | makeCurrent(); |
| 3758 | GLenum err = GL_NO_ERROR; |
| 3759 | while((err = glGetError()) != GL_NO_ERROR) |
| 3760 | { |
| 3761 | printf("before makeAtoms %s error %X\n", parent()->objectName().toStdString().c_str(),err); |
| 3762 | //printf("%s\n",(char*)gluErrorString(err)); |
| 3763 | } |
| 3764 | atom_vao.release(); |
| 3765 | if (atom_vao.isCreated()) { |
| 3766 | atom_vao.release(); |
| 3767 | atom_vao.destroy(); |
| 3768 | atom_vertexBuffer.destroy(); |
| 3769 | atom_indexBuffer.destroy(); |
| 3770 | atom_program->release(); |
| 3771 | atom_program->removeAllShaders(); |
| 3772 | } |
| 3773 | atom_vao.create(); |
| 3774 | atom_vao.bind(); |
| 3775 | //glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
| 3776 | atom_vertexBuffer.create(); |
| 3777 | atom_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 3778 | if (!atom_vertexBuffer.bind()) {printf("I was unable to bind atom_vertexBuffer.\n");} |
| 3779 | //glDisable(GL_BLEND); |
| 3780 | //printf("makeAtoms\n"); |
| 3781 | |
| 3782 | int na = atoms.size(); |
| 3783 | // the Atoms = atoms; |
| 3784 | |
| 3785 | makeLabels(); |
| 3786 | int zz=0; |
| 3787 | sumse=V3(0,0,0); |
| 3788 | for (int i = 0; i < atoms.size(); i++){ |
| 3789 | if ((!atoms.at(i).hidden)) {//(mol->showatoms.at(i).an>-1)&& |
| 3790 | sumse += atoms[i].pos; |
| 3791 | zz++; |
| 3792 | } |
| 3793 | } |
| 3794 | if (zz) sumse*=1.0/zz; |
| 3795 | const float phi = (1.0f + sqrtf(5.0f)) / 2.0f; |
| 3796 | const float du = 1.0f / sqrtf(phi * phi + 1.0f); |
| 3797 | const float dv = phi * du; |
| 3798 | //printf("phi = %f du = %f dv = %f\n",phi, du, dv); |
| 3799 | const float eckn[] ={ 0.0f, dv, du, |
| 3800 | 0.0f, dv, -du, |
| 3801 | 0.0f, -dv, du, |
| 3802 | 0.0f, -dv, -du, |
| 3803 | du, 0.0f, dv, |
| 3804 | -du, 0.0f, dv, |
| 3805 | du, 0.0f, -dv, |
| 3806 | -du, 0.0f, -dv, |
| 3807 | dv, du, 0.0f, |
| 3808 | dv, -du, 0.0f, |
| 3809 | -dv, du, 0.0f, |
| 3810 | -dv, -du, 0.0f}; |
| 3811 | const GLuint triangle[] = { |
| 3812 | 1, 0, 8, |
| 3813 | 4, 0, 5, |
| 3814 | 5, 0, 10, |
| 3815 | 8, 0, 4, |
| 3816 | 10, 0, 1, |
| 3817 | 6, 1, 8, |
| 3818 | 7, 1, 6, |
| 3819 | 10, 1, 7, |
| 3820 | 3, 2, 11, |
| 3821 | 4, 2, 9, |
| 3822 | 5, 2, 4, |
| 3823 | 9, 2, 3, |
| 3824 | 11, 2, 5, |
| 3825 | 6, 3, 7, |
| 3826 | 7, 3, 11, |
| 3827 | 9, 3, 6, |
| 3828 | 8, 4, 9, |
| 3829 | 11, 5, 10, |
| 3830 | 9, 6, 8, |
| 3831 | 10, 7, 11};//*/ |
| 3832 | /*const GLuint triangle_strips[] = { |
| 3833 | 1, 0, 8, 4, 9, 2, 3, 11, 7, 10, 1, 0, 0xFFFFFFFF, |
| 3834 | 3, 9, 6, 8, 1, 0xFFFFFFFF, |
| 3835 | 2, 11, 5, 10, 0, 0xFFFFFFFF, |
| 3836 | 1, 7, 6, 3, 0xFFFFFFFF, //3, 7, 6, 1, 0xFFFF, |
| 3837 | 2, 4, 5, 0, 0xFFFFFFFF//0, 5, 4, 2, 0xFFFF, |
| 3838 | };//, 10, 5, 11, 2}; */ |
| 3839 | //0xFFFF |
| 3840 | QVector<float> stuff; |
| 3841 | bool wehaveh=false; |
| 3842 | stuff.reserve(na*12*24); |
| 3843 | for (int i = 0; i < na; i++){ |
| 3844 | bool isd=((atoms.at(i).an==0)&&(atoms.at(i).Label[0]=='D')); |
| 3845 | int style = (atoms.at(i).an<0)? (atoms.at(i).hidden)?512:0: |
| 3846 | mol->AtomStyle[atoms.at(i).an] |
| 3847 | |((atoms.at(i).hidden)?512:0) |
| 3848 | |((isd)?1024:0) |
| 3849 | |(((atoms.at(i).isIso))?2048:0); |
| 3850 | if (atoms.at(i).Label.contains("noADP"))style |=ATOM_STYLE_NOADP; |
| 3851 | if ((atoms.at(i).an==0)&&((style&512)!=512)) { |
| 3852 | //printf("%d %d ein h in der suppe %d %X %d %d\n",atoms.at(i).an, i, style, style, style&512, style&2048); |
| 3853 | wehaveh=true; |
| 3854 | } |
| 3855 | V3 ev=V3(0,0,0); |
| 3856 | double *arr = mol->jacobi(atoms.at(i).uc, ev); |
| 3857 | for (int j = 0; j < 12; j++){ |
| 3858 | stuff.append(atoms.at(i).pos.x);//the center |
| 3859 | stuff.append(atoms.at(i).pos.y); |
| 3860 | stuff.append(atoms.at(i).pos.z); |
| 3861 | stuff.append(static_cast<float>(atoms.at(i).an)); |
| 3862 | |
| 3863 | stuff.append(eckn[3*j]);// an icosahedron corner |
| 3864 | stuff.append(eckn[3*j+1]); |
| 3865 | stuff.append(eckn[3*j+2]); |
| 3866 | stuff.append(static_cast<float>(j)); |
| 3867 | |
| 3868 | stuff.append(static_cast<float>(arr[0])); |
| 3869 | stuff.append(static_cast<float>(arr[1])); |
| 3870 | stuff.append(static_cast<float>(arr[2])); |
| 3871 | stuff.append(static_cast<float>(arr[3])); |
| 3872 | |
| 3873 | stuff.append(ev.x); |
| 3874 | stuff.append(ev.y); |
| 3875 | stuff.append(ev.z); |
| 3876 | stuff.append(static_cast<float>(style)); |
| 3877 | |
| 3878 | stuff.append(static_cast<float>((atoms.at(i).an==-42)?atoms.at(i).sof:atoms.at(i).peakHeight)); |
| 3879 | stuff.append(static_cast<float>(qMax(0, atoms.at(i).symmGroup))); |
| 3880 | stuff.append(static_cast<float>(atoms.at(i).part)); |
| 3881 | stuff.append(static_cast<float>(atoms.at(i).molindex)); |
| 3882 | |
| 3883 | stuff.append(static_cast<float>(i)); |
| 3884 | stuff.append(static_cast<float>(atoms.at(i).auidx)); |
| 3885 | stuff.append(static_cast<float>(atoms.at(i).resiNr)); |
| 3886 | stuff.append(0.0f); |
| 3887 | |
| 3888 | } |
| 3889 | } |
| 3890 | hideHydrogen->setVisible(wehaveh); |
| 3891 | atom_vertexBuffer.allocate(stuff.data(),stuff.size()*sizeof(float)); |
| 3892 | QVector<GLuint> indexes; |
| 3893 | uint una = static_cast<uint>(na); |
| 3894 | for (uint i = 0; i < una; i++){ |
| 3895 | for (uint j = 0; j < 60; j++){ |
| 3896 | indexes.append(triangle[j]+12*i);//_strips |
| 3897 | } |
| 3898 | } |
| 3899 | |
| 3900 | atom_indexBuffer = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer); // Mind: use 'IndexBuffer' here |
| 3901 | atom_indexBuffer.create(); |
| 3902 | atom_indexBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw); |
| 3903 | if (!atom_indexBuffer.bind()) {printf("I was unable to bind atom_indexBuffer!\n");} |
| 3904 | atom_indexBuffer.allocate( indexes.size() * sizeof(GLuint) ); |
| 3905 | atom_indexBuffer.write(0, indexes.data(), indexes.size()* sizeof(GLuint)); |
| 3906 | atom_index_size = indexes.size(); |
| 3907 | //printf("%d %d ?=? %d na=%d\n",__LINE__, indexes.size() * sizeof(GLuint) , atom_index_size, na); |
| 3908 | if (!atom_program) atom_program = new QOpenGLShaderProgram(this); |
| 3909 | else atom_program->removeAllShaders(); |
| 3910 | |
| 3911 | //printf("%p %d\n",atom_program, atom_program->programId()); |
| 3912 | |
| 3913 | bool result = atom_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/atom.vert"); |
| 3914 | //printf("%d\n",__LINE__); |
| 3915 | if ( !result ) qWarning() << atom_program->log(); |
| 3916 | result = atom_program->addCacheableShaderFromSourceFile( QOpenGLShader::Geometry, ":/shaders/atom.geom"); |
| 3917 | //printf("%d\n",__LINE__); |
| 3918 | if ( !result ) qWarning() << atom_program->log(); |
| 3919 | result = atom_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/atom.frag"); |
| 3920 | |
| 3921 | if ( !result ) qWarning() << atom_program->log(); |
| 3922 | result = atom_program->link(); |
| 3923 | if ( !result ) qWarning() << atom_program->log(); |
| 3924 | \ |
| 3925 | if ( !atom_program->bind() ) { |
| 3926 | qWarning() << "Could not bind shader program to context"; |
| 3927 | return; |
| 3928 | } |
| 3929 | //printf("!!! %d !!!\n",shaderInfo); |
| 3930 | programInfo(atom_program,"atom"); |
| 3931 | GLfloat acv[109*3]; |
| 3932 | for (int i=0;i<109;i++) { |
| 3933 | acv[3*i]=mol->atomColor(i,false).redF(); |
| 3934 | acv[3*i+1]=mol->atomColor(i,false).greenF(); |
| 3935 | acv[3*i+2]=mol->atomColor(i,false).blueF(); |
| 3936 | } |
| 3937 | GLfloat arv[109]; |
| 3938 | for (int i=0;i<109;i++) { |
| 3939 | arv[i]=static_cast<GLfloat>(mol->arad[i]); |
| 3940 | } |
| 3941 | |
| 3942 | atom_program->setUniformValueArray("atomColors",acv, 109,3); |
| 3943 | atom_program->setUniformValueArray("arad",arv, 109,1); |
| 3944 | |
| 3945 | atom_program->setUniformValue("pmv", pmv); |
| 3946 | /*for (int i = 0; i < atoms.size(); i++){ |
| 3947 | qDebug()<<pmv.map(QVector3D(atoms.at(i).pos.x-sumse.x,atoms.at(i).pos.y-sumse.y,atoms.at(i).pos.z-sumse.z)); |
| 3948 | }// */ |
| 3949 | |
| 3950 | //printf("%d\n",__LINE__); |
| 3951 | atom_program->enableAttributeArray(0); |
| 3952 | atom_program->enableAttributeArray(1); |
| 3953 | atom_program->enableAttributeArray(2); |
| 3954 | atom_program->enableAttributeArray(3); |
| 3955 | atom_program->enableAttributeArray(4); |
| 3956 | atom_program->enableAttributeArray(5); |
| 3957 | //printf("%d\n",__LINE__); |
| 3958 | int stride = 6 * 4 * sizeof(float); |
| 3959 | atom_program->setAttributeBuffer(0, GL_FLOAT, 0, 4, stride); |
| 3960 | atom_program->setAttributeBuffer(1, GL_FLOAT, sizeof(float)*4 , 4, stride); |
| 3961 | atom_program->setAttributeBuffer(2, GL_FLOAT, sizeof(float)*8 , 4, stride); |
| 3962 | atom_program->setAttributeBuffer(3, GL_FLOAT, sizeof(float)*12 , 4, stride); |
| 3963 | atom_program->setAttributeBuffer(4, GL_FLOAT, sizeof(float)*16 , 4, stride); |
| 3964 | atom_program->setAttributeBuffer(5, GL_FLOAT, sizeof(float)*20 , 4, stride);// 20*sizeof(float) |
| 3965 | |
| 3966 | atom_program->release(); |
| 3967 | atom_vao.release(); |
| 3968 | atom_indexBuffer.release(); |
| 3969 | atom_vertexBuffer.release(); |
| 3970 | atom_vertexBuffer.destroy(); |
| 3971 | atom_indexBuffer.destroy(); |
| 3972 | while((err = glGetError()) != GL_NO_ERROR) |
| 3973 | { |
| 3974 | printf("after1 makeAtoms %s error %X\n", parent()->objectName().toStdString().c_str(),err); |
| 3975 | //printf("%s\n",(char*)gluErrorString(err)); |
| 3976 | } |
| 3977 | //double va = viewAngle; |
| 3978 | //setViewAngle(29.0); |
| 3979 | |
| 3980 | pushRotStat(); |
| 3981 | popRotStat(); |
| 3982 | makeSelectedAtoms(); |
| 3983 | updateSceenAtoms(); |
| 3984 | makeLegendAtoms(); |
| 3985 | //setViewAngle(va); |
| 3986 | update(); |
| 3987 | while((err = glGetError()) != GL_NO_ERROR) |
| 3988 | { |
| 3989 | printf("after2 makeAtoms %s error %X\n", parent()->objectName().toStdString().c_str(),err); |
| 3990 | //printf("%s\n",(char*)gluErrorString(err)); |
| 3991 | } |
| 3992 | } |
| 3993 | |
| 3994 | |
| 3995 | void PlayOpenGL::pushRotStat(){ |
| 3996 | double ll=L; |
| 3997 | double dim=mol->dimension(mol->showatoms); |
| 3998 | L = (isOrtho)?2/dim: viewAngle * 100.0 / (dim *29.0); |
| 3999 | Matrix m = Matrix( |
| 4000 | mvmat(0,0), |
| 4001 | mvmat(0,1), |
| 4002 | mvmat(0,2), |
| 4003 | mvmat(1,0), |
| 4004 | mvmat(1,1), |
| 4005 | mvmat(1,2), |
| 4006 | mvmat(2,0), |
| 4007 | mvmat(2,1), |
| 4008 | mvmat(2,2)); |
| 4009 | double det = determinant(m); |
| 4010 | //printf("Adie Determinante der Drehmatrix ist: %g %g L = %g ll = %g %f\n", det, pow(det,1.0/3.0), L, ll, L/ll); |
| 4011 | ll=L/pow(det,1.0/3.0); |
| 4012 | if (!inRenameMode) mvmat.scale(ll, ll, ll); |
| 4013 | pmv = pmat*mvmat; |
| 4014 | nm = mvmat.normalMatrix(); |
| 4015 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 4016 | } |
| 4017 | |
| 4018 | void PlayOpenGL::popRotStat(){ |
| 4019 | return; |
| 4020 | } |
| 4021 | |
| 4022 | void PlayOpenGL::makeBonds(const CEnvironment &atoms, const Connection &bonds, const Connection &lbonds, Connection &hbonds){ |
| 4023 | //printf("makeBonds\n"); |
| 4024 | makeCurrent(); |
| 4025 | bond_vao.release(); |
| 4026 | if (bond_vao.isCreated()) { |
| 4027 | bond_vao.release(); |
| 4028 | bond_vao.destroy(); |
| 4029 | bond_vertexBuffer.destroy(); |
| 4030 | bond_indexBuffer.destroy(); |
| 4031 | } |
| 4032 | bond_vao.create(); |
| 4033 | bond_vao.bind(); |
| 4034 | bond_vertexBuffer.create(); |
| 4035 | bond_vertexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw ); |
| 4036 | //glDisable(GL_BLEND); |
| 4037 | if (!bond_vertexBuffer.bind()) {printf("m_vertexBufferObject2 I was unable to bind!\n");} |
| 4038 | GLenum err = GL_NO_ERROR; |
| 4039 | while((err = glGetError()) != GL_NO_ERROR) |
| 4040 | { |
| 4041 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 4042 | //printf("%s\n",(char*)gluErrorString(err)); |
| 4043 | } |
| 4044 | int zz=0; |
| 4045 | sumse=V3(0,0,0); |
| 4046 | for (int i=0;i<atoms.size();i++){ |
| 4047 | if ((!atoms.at(i).hidden)) {//(mol->showatoms.at(i).an>-1)&& |
| 4048 | sumse+=atoms[i].pos; |
| 4049 | zz++; |
| 4050 | } |
| 4051 | } |
| 4052 | if (zz) sumse*=1.0/zz; |
| 4053 | QVector<float> pos; |
| 4054 | //QVector<float> col; |
| 4055 | QVector<float> an; |
| 4056 | QVector<float> styles; |
| 4057 | QVector<float> peakHeights; |
| 4058 | QVector<float> symmGroups; |
| 4059 | mol->h_bonds3(bonds,atoms); |
| 4060 | hbonds=mol->theH_Bonds; |
| 4061 | QVector<GLuint> nbonds; |
| 4062 | for (int i=0; i<atoms.size(); i++){ |
| 4063 | pos.append(atoms.at(i).pos.x); |
| 4064 | pos.append(atoms.at(i).pos.y); |
| 4065 | pos.append(atoms.at(i).pos.z); |
| 4066 | bool isd=((atoms.at(i).an==0)&&(atoms.at(i).Label[0]=='D')); |
| 4067 | //col.append(chgl->mol->atomColor(chgl->mol->showatoms.at(i).an,isd).redF()); |
| 4068 | //col.append(chgl->mol->atomColor(chgl->mol->showatoms.at(i).an,isd).greenF()); |
| 4069 | //col.append(chgl->mol->atomColor(chgl->mol->showatoms.at(i).an,isd).blueF()); |
| 4070 | an.append(static_cast<float>(atoms.at(i).an)); |
| 4071 | //styles.append(7); |
| 4072 | peakHeights.append((atoms.at(i).an<0)?atoms.at(i).peakHeight:atoms.at(i).part); |
| 4073 | symmGroups.append(qMax(0, atoms.at(i).symmGroup)); |
| 4074 | if (atoms.at(i).an<0) styles.append((atoms.at(i).hidden)?512:0); |
| 4075 | else styles.append(static_cast<float>(mol->AtomStyle[atoms.at(i).an] |
| 4076 | |((atoms.at(i).hidden)?512:0) |
| 4077 | |((isd)?1024:0) |
| 4078 | |(((atoms.at(i).symmGroup)&&(atoms.at(i).part<0))?2048:0))); |
| 4079 | } |
| 4080 | for (int i=0; i<bonds.size(); i++){ |
| 4081 | nbonds.append(bonds.at(i).a1); |
| 4082 | nbonds.append(bonds.at(i).a2); |
| 4083 | } |
| 4084 | for (int i=0; i<lbonds.size(); i++){ |
| 4085 | nbonds.append(lbonds.at(i).a1); |
| 4086 | nbonds.append(lbonds.at(i).a2); |
| 4087 | } |
| 4088 | for (int i=0; i<hbonds.size(); i++){ |
| 4089 | nbonds.append(hbonds.at(i).a1); |
| 4090 | nbonds.append(hbonds.at(i).a2); |
| 4091 | } |
| 4092 | printf("h_bonds %d q-peak-bonds %d\n", hbonds.size(),lbonds.size()); |
| 4093 | bond_vertexBuffer.allocate(atoms.size() * 7 * sizeof(float)); |
| 4094 | bond_vertexBuffer.write(0, (void*)pos.data(), atoms.size() * 3 * sizeof(float)); |
| 4095 | bond_vertexBuffer.write(atoms.size() * 3 * sizeof(float), (void*)an.data(), atoms.size() * sizeof(float)); |
| 4096 | bond_vertexBuffer.write(atoms.size() * 4 * sizeof(float), (void*)styles.data(), atoms.size() * sizeof(float)); |
| 4097 | bond_vertexBuffer.write(atoms.size() * 5 * sizeof(float), (void*)peakHeights.data(), atoms.size() * sizeof(float)); |
| 4098 | bond_vertexBuffer.write(atoms.size() * 6 * sizeof(float), (void*)symmGroups.data(), atoms.size() * sizeof(float)); |
| 4099 | |
| 4100 | nbondx2 = nbonds.size(); |
| 4101 | //printf("nbondx2 = %d\n", nbondx2); |
| 4102 | // create a new buffer for the indexes |
| 4103 | bond_indexBuffer = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer); // Mind: use 'IndexBuffer' here |
| 4104 | bond_indexBuffer.create(); |
| 4105 | bond_indexBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw); |
| 4106 | if (!bond_indexBuffer.bind()) {printf("bond_indexBuffer I was unable to bind!\n");} |
| 4107 | bond_indexBuffer.allocate(nbonds.data(), nbonds.size() * sizeof(GLuint) ); |
| 4108 | if (!bond_program) bond_program = new QOpenGLShaderProgram(this); |
| 4109 | else bond_program->removeAllShaders(); |
| 4110 | |
| 4111 | //printf("bond_program: %p id = %d\n",bond_program, bond_program->programId()); |
| 4112 | bool result2 = bond_program->addCacheableShaderFromSourceFile( QOpenGLShader::Vertex, ":/shaders/bond.vert"); |
| 4113 | if ( !result2 ) qWarning() << bond_program->log(); |
| 4114 | result2 = bond_program->addCacheableShaderFromSourceFile( QOpenGLShader::Geometry, ":/shaders/bond.geom"); |
| 4115 | if ( !result2 ) qWarning() << bond_program->log(); |
| 4116 | result2 = bond_program->addCacheableShaderFromSourceFile( QOpenGLShader::Fragment, ":/shaders/bond.frag"); |
| 4117 | if ( !result2 ) qWarning() << bond_program->log(); |
| 4118 | result2 = bond_program->link(); |
| 4119 | |
| 4120 | programInfo(bond_program,"bond"); |
| 4121 | if ( !result2 ) qWarning() << bond_program->log(); |
| 4122 | if ( !bond_program->bind() ) { |
| 4123 | qWarning() << "2Could not bind shader program to context"; |
| 4124 | return; |
| 4125 | } |
| 4126 | GLfloat acv[109*3]; |
| 4127 | for (int i=0;i<109;i++) { |
| 4128 | acv[3*i]=mol->atomColor(i,false).redF(); |
| 4129 | acv[3*i+1]=mol->atomColor(i,false).greenF(); |
| 4130 | acv[3*i+2]=mol->atomColor(i,false).blueF(); |
| 4131 | } |
| 4132 | bond_program->setUniformValue("radius", static_cast<float>(mol->bondStrength)); |
| 4133 | bond_program->setUniformValue("segments", mol->LOD); |
| 4134 | bond_program->setUniformValue("lightPos", QVector3D(100.0, 100.0, 100.0)); |
| 4135 | bond_program->setUniformValueArray("atomColors",acv, 109,3); |
| 4136 | |
| 4137 | bond_program->setUniformValue("pmv", pmv); |
| 4138 | int stride = 0;//6*sizeof(float); |
| 4139 | bond_program->setAttributeBuffer( "VertexPosition", GL_FLOAT, 0, 3, stride ); |
| 4140 | bond_program->enableAttributeArray( "VertexPosition" ); |
| 4141 | //bond_program->setAttributeBuffer( "VertexColor", GL_FLOAT, sizeof(float)*atoms.size()*3, 3, stride ); |
| 4142 | bond_program->setAttributeBuffer( "atomicnumbers", GL_FLOAT, sizeof(float)*atoms.size()*3, 1, stride ); |
| 4143 | bond_program->enableAttributeArray( "atomicnumbers" ); |
| 4144 | bond_program->setAttributeBuffer( "Styles", GL_FLOAT, sizeof(float)*atoms.size()*4, 1, stride ); |
| 4145 | bond_program->enableAttributeArray( "Styles" ); |
| 4146 | bond_program->setAttributeBuffer( "peakHeights", GL_FLOAT, sizeof(float)*atoms.size()*5, 1, stride ); |
| 4147 | bond_program->enableAttributeArray( "peakHeights" ); |
| 4148 | bond_program->setAttributeBuffer( "symmGroup", GL_FLOAT, sizeof(float)*atoms.size()*6, 1, stride ); |
| 4149 | bond_program->enableAttributeArray( "symmGroup" ); |
| 4150 | |
| 4151 | bond_program->release(); |
| 4152 | bond_vao.release(); |
| 4153 | bond_indexBuffer.release(); |
| 4154 | bond_vertexBuffer.release(); |
| 4155 | bond_vertexBuffer.destroy(); |
| 4156 | bond_indexBuffer.destroy(); |
| 4157 | } |
| 4158 | |
| 4159 | QString PlayOpenGL::glTypeInt2String(int ityp){ |
| 4160 | QString s; |
| 4161 | /* |
| 4162 | |
| 4163 | #define GL_FLOAT_VEC2 0x8B50 |
| 4164 | #define GL_FLOAT_VEC3 0x8B51 |
| 4165 | #define GL_FLOAT_VEC4 0x8B52 |
| 4166 | #define GL_INT_VEC2 0x8B53 |
| 4167 | #define GL_INT_VEC3 0x8B54 |
| 4168 | #define GL_INT_VEC4 0x8B55 |
| 4169 | #define GL_BOOL 0x8B56 |
| 4170 | #define GL_BOOL_VEC2 0x8B57 |
| 4171 | #define GL_BOOL_VEC3 0x8B58 |
| 4172 | #define GL_BOOL_VEC4 0x8B59 |
| 4173 | #define GL_FLOAT_MAT2 0x8B5A |
| 4174 | #define GL_FLOAT_MAT3 0x8B5B |
| 4175 | #define GL_FLOAT_MAT4 0x8B5C |
| 4176 | |
| 4177 | #define GL_BYTE 0x1400 |
| 4178 | #define GL_UNSIGNED_BYTE 0x1401 |
| 4179 | #define GL_SHORT 0x1402 |
| 4180 | #define GL_UNSIGNED_SHORT 0x1403 |
| 4181 | #define GL_INT 0x1404 |
| 4182 | #define GL_UNSIGNED_INT 0x1405 |
| 4183 | #define GL_FLOAT 0x1406 |
| 4184 | #define GL_2_BYTES 0x1407 |
| 4185 | #define GL_3_BYTES 0x1408 |
| 4186 | #define GL_4_BYTES 0x1409 |
| 4187 | #define GL_DOUBLE 0x140A |
| 4188 | |
| 4189 | */ |
| 4190 | switch (ityp){ |
| 4191 | case 0x8B50: s = "GL_FLOAT_VEC2"; break; |
| 4192 | case 0x8B51: s = "GL_FLOAT_VEC3"; break; |
| 4193 | case 0x8B52: s = "GL_FLOAT_VEC4"; break; |
| 4194 | case 0x8B53: s = "GL_INT_VEC2"; break; |
| 4195 | case 0x8B54: s = "GL_INT_VEC3"; break; |
| 4196 | case 0x8B55: s = "GL_INT_VEC4"; break; |
| 4197 | case 0x8B56: s = "GL_BOOL"; break; |
| 4198 | case 0x8B57: s = "GL_BOOL_VEC2"; break; |
| 4199 | case 0x8B58: s = "GL_BOOL_VEC3"; break; |
| 4200 | case 0x8B59: s = "GL_BOOL_VEC4"; break; |
| 4201 | case 0x8B5A: s = "GL_FLOAT_MAT2"; break; |
| 4202 | case 0x8B5B: s = "GL_FLOAT_MAT3"; break; |
| 4203 | case 0x8B5C: s = "GL_FLOAT_MAT4"; break; |
| 4204 | case 0x1400: s = "GL_BYTE"; break; |
| 4205 | case 0x1401: s = "GL_UNSIGNED_BYTE"; break; |
| 4206 | case 0x1402: s = "GL_SHORT"; break; |
| 4207 | case 0x1403: s = "GL_UNSIGNED_SHORT"; break; |
| 4208 | case 0x1404: s = "GL_INT"; break; |
| 4209 | case 0x1405: s = "GL_UNSIGNED_INT"; break; |
| 4210 | case 0x1406: s = "GL_FLOAT"; break; |
| 4211 | case 0x1407: s = "GL_2_BYTES"; break; |
| 4212 | case 0x1408: s = "GL_3_BYTES"; break; |
| 4213 | case 0x1409: s = "GL_4_BYTES"; break; |
| 4214 | case 0x140A: s = "GL_DOUBLE"; break; |
| 4215 | //case : s = ""; break; |
| 4216 | //case : s = ""; break; |
| 4217 | default: s = "no clue?"; |
| 4218 | } |
| 4219 | return s; |
| 4220 | } |
| 4221 | |
| 4222 | void PlayOpenGL::initializeGL(){ |
| 4223 | if (parent()){ |
| 4224 | isMainWindow = (parent()->objectName().startsWith("The Main Window")); |
| 4225 | printf("parent not null\n"); |
| 4226 | } |
| 4227 | printf("%d initializeGL parent: %s\n", isMainWindow, parent()->objectName().toStdString().c_str()); |
| 4228 | makeCurrent(); |
| 4229 | initializeOpenGLFunctions(); |
| 4230 | // During init, enable debug output |
| 4231 | //glEnable ( GL_DEBUG_OUTPUT ); |
| 4232 | //glDebugMessageCallback( MessageCallback, 0 ); |
| 4233 | |
| 4234 | const QOpenGLContext *context = this->context(); |
| 4235 | QSurface *surf = this->context()->surface(); |
| 4236 | printf("Widget OpenGl: %d.%d\n",format().majorVersion(),format().minorVersion()); |
| 4237 | printf("Context valid: %d\n",context->isValid()); |
| 4238 | printf("Really used OpenGl: %d.%d\n",context->format().majorVersion(),context->format().minorVersion()); |
| 4239 | GLenum err = GL_NO_ERROR; |
| 4240 | while((err = glGetError()) != GL_NO_ERROR) |
| 4241 | { |
| 4242 | printf("test3525 %s error %X\n", parent()->objectName().toStdString().c_str(),err); |
| 4243 | //printf("%s\n",(char*)gluErrorString(err)); |
| 4244 | } |
| 4245 | GLint nrAttributes; |
| 4246 | glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nrAttributes); |
| 4247 | printf("GL_MAX_VERTEX_ATTRIBS =%d\n",nrAttributes); |
| 4248 | glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &nrAttributes); |
| 4249 | printf("GL_MAX_VERTEX_UNIFORM_COMPONENTS=%d\n",nrAttributes); |
| 4250 | glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &nrAttributes); |
| 4251 | printf("GL_MAX_FRAGMENT_UNIFORM_COMPONENTS=%d\n",nrAttributes); |
| 4252 | //glGetIntegerv(GL_MAX_VARYING_FLOATS, &nrAttributes); |
| 4253 | //printf("GL_MAX_VARYING_FLOATS=%d\n",nrAttributes); |
| 4254 | //glGetIntegerv(GL_MAX_VARYING_COMPONENTS, &nrAttributes); |
| 4255 | //printf("GL_MAX_VARYING_COMPONENTS=%d\n",nrAttributes); |
| 4256 | err = GL_NO_ERROR; |
| 4257 | while((err = glGetError()) != GL_NO_ERROR) |
| 4258 | { |
| 4259 | printf("before gl_blend %s error %X\n", parent()->objectName().toStdString().c_str(),err); |
| 4260 | //printf("%s\n",(char*)gluErrorString(err)); |
| 4261 | } |
| 4262 | //glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
| 4263 | glEnable(GL_BLEND); |
| 4264 | //glDisable(GL_BLEND); |
| 4265 | glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; |
| 4266 | //glClearColor(0.4f,0.4f,0.4f,1.0f); |
| 4267 | //glClearColor(0.f,0.f,0.f,1.0f); |
| 4268 | glClearColor(1.f,1.f,1.f,1.0f); |
| 4269 | glEnable(GL_DEPTH_TEST ); |
| 4270 | glEnable(GL_LINE_SMOOTH); |
| 4271 | glHint(GL_LINE_SMOOTH_HINT,GL_NICEST); |
| 4272 | //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |
| 4273 | //GLenum err = GL_NO_ERROR; |
| 4274 | err=GL_NO_ERROR; |
| 4275 | while((err = glGetError()) != GL_NO_ERROR) |
| 4276 | { |
| 4277 | printf("after GL_PERSPECTIVE_CORRECTION_HINT %s error %X\n", parent()->objectName().toStdString().c_str(),err); |
| 4278 | //printf("%s\n",(char*)gluErrorString(err)); |
| 4279 | } |
| 4280 | #if not defined (Q_OS_MAC) |
| 4281 | setMouseTracking(true); |
| 4282 | #endif |
| 4283 | float ratio = width() / static_cast<float>(height()); |
| 4284 | pmat.setToIdentity(); |
| 4285 | printf("%pmol viewAngle = %f\n",mol,viewAngle); |
| 4286 | if (viewAngle<0.1) { |
| 4287 | //printf("ident %d\n",__LINE__); |
| 4288 | L=(mol->showatoms.isEmpty())?2.0:2.0/mol->dimension(mol->showatoms); |
| 4289 | //printf("ident %d\n",__LINE__); |
| 4290 | mvmat.setToIdentity(); |
| 4291 | mvmat.lookAt(QVector3D(0.0, 200, 50) , QVector3D( 0.0, 0.0, 0.0), QVector3D(0.0, -100, 400 )); |
| 4292 | mvmat.scale(L,L,L); |
| 4293 | pmat.ortho(-ratio, ratio, -1.0f, 1.0f, -5.0f, 8000.0f); |
| 4294 | previousViewAngle = qMax(viewAngle, 29.0); |
| 4295 | viewAngle=0.01; |
| 4296 | isOrtho=true; |
| 4297 | if (toggleOrthoView!=nullptr)toggleOrthoView->setChecked(true); |
| 4298 | printf("ORTHO\n"); |
| 4299 | }else{ |
| 4300 | printf("PERSPECTIVE %f\n", viewAngle); |
| 4301 | pmat.perspective(viewAngle, ratio, -5.0f, 8000.0f ); |
| 4302 | isOrtho=false; |
| 4303 | if (toggleOrthoView!=nullptr) toggleOrthoView->setChecked(false); |
| 4304 | L=100.0; |
| 4305 | //printf("ident %d\n",__LINE__); |
| 4306 | mvmat.setToIdentity(); |
| 4307 | mvmat.lookAt(QVector3D(0.0, 200, 50) , QVector3D( 0.0, 0.0, 0.0), QVector3D(0.0, -100, 400 )); |
| 4308 | mvmat.scale(L,L,L); |
| 4309 | } |
| 4310 | pmv = pmat*mvmat; |
| 4311 | nm = mvmat.normalMatrix(); |
| 4312 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 4313 | makeBackGround(); |
| 4314 | bool cu= this->context()->makeCurrent(surf); |
| 4315 | |
| 4316 | printf("Context valid: %d v %d widget %d window %d current %d\n",context->isValid(), this->context()->isValid(), context->isWidgetType(), context->isWindowType(),cu); |
| 4317 | printf("initialized \n"); |
| 4318 | emit initialized(); |
| 4319 | update(); |
| 4320 | // */ |
| 4321 | } |
| 4322 | |
| 4323 | void PlayOpenGL::resizeGL(int width, int height){ |
| 4324 | //printf("rezi %d %d\n",width,height); |
| 4325 | retinafktr=devicePixelRatio(); |
| 4326 | glViewport(0, 0, width*retinafktr, qMax(height*retinafktr, 1.0)); |
| 4327 | pmat.setToIdentity(); |
| 4328 | float ratio = width / static_cast<float>(height); |
| 4329 | if (isOrtho) pmat.ortho(-ratio, ratio, -1.0f, 1.0f, -5.0f, 8000.0f); |
| 4330 | else pmat.perspective(viewAngle, ratio, 5.0f, 8000.0f ); |
| 4331 | |
| 4332 | pmv = pmat*mvmat; |
| 4333 | nm = mvmat.normalMatrix(); |
| 4334 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 4335 | updateSceenAtoms(); |
| 4336 | update(); |
| 4337 | } |
| 4338 | |
| 4339 | inline void PlayOpenGL::__RotateCS( float c, float s, float& X, float& Y ) { |
| 4340 | float T = X; |
| 4341 | X = c*X - s*Y; |
| 4342 | Y = s*T + c*Y; |
| 4343 | } |
| 4344 | |
| 4345 | inline void PlayOpenGL::__RotateCS( double c, double s, double& X, double& Y ) { |
| 4346 | double T = X; |
| 4347 | X = c*X - s*Y; |
| 4348 | Y = s*T + c*Y; |
| 4349 | } |
| 4350 | |
| 4351 | void PlayOpenGL::glRotateMat( QMatrix4x4 &mat, const float dang, const float x , const float y, const float z ) { |
| 4352 | float s = z; |
| 4353 | s = sinf(dang*M_PIf/180); |
| 4354 | const float c = cosf(dang*M_PIf/180); |
| 4355 | if( x!=0.0f ){ |
| 4356 | __RotateCS( c, s, mat(1,0), mat(2,0) ); |
| 4357 | __RotateCS( c, s, mat(1,1), mat(2,1) ); |
| 4358 | __RotateCS( c, s, mat(1,2), mat(2,2) ); |
| 4359 | // printf("x\n"); |
| 4360 | }else if( y!=0.0f ){ |
| 4361 | __RotateCS( c, s, mat(2,0), mat(0,0) ); |
| 4362 | __RotateCS( c, s, mat(2,1), mat(0,1) ); |
| 4363 | __RotateCS( c, s, mat(2,2), mat(0,2) ); |
| 4364 | // printf("y\n"); |
| 4365 | }else{ |
| 4366 | __RotateCS( c, s, mat(0,0), mat(1,0) ); |
| 4367 | __RotateCS( c, s, mat(0,1), mat(1,1) ); |
| 4368 | __RotateCS( c, s, mat(0,2), mat(1,2) ); |
| 4369 | // printf("z\n"); |
| 4370 | } |
| 4371 | } |
| 4372 | |
| 4373 | void PlayOpenGL::glRotateMat( Matrix &mat, const float dang, const double x , const double y, const double z ) { |
| 4374 | double s = z; |
| 4375 | s = sin(dang*M_PI/180); |
| 4376 | const double c = cos(dang*M_PI/180); |
| 4377 | if( x!=0.0f ){ |
| 4378 | __RotateCS( c, s, mat.m21, mat.m31 ); |
| 4379 | __RotateCS( c, s, mat.m22, mat.m32 ); |
| 4380 | __RotateCS( c, s, mat.m23, mat.m33 ); |
| 4381 | // printf("x\n"); |
| 4382 | }else if( y!=0.0f ){ |
| 4383 | __RotateCS( c, s, mat.m31, mat.m11 ); |
| 4384 | __RotateCS( c, s, mat.m32, mat.m12 ); |
| 4385 | __RotateCS( c, s, mat.m33, mat.m13 ); |
| 4386 | // printf("y\n"); |
| 4387 | }else{ |
| 4388 | __RotateCS( c, s, mat.m11, mat.m21 ); |
| 4389 | __RotateCS( c, s, mat.m12, mat.m22 ); |
| 4390 | __RotateCS( c, s, mat.m13, mat.m23 ); |
| 4391 | // printf("z\n"); |
| 4392 | } |
| 4393 | } |
| 4394 | |
| 4395 | void PlayOpenGL::setLabelSize(int s){ |
| 4396 | myFont.setPointSize(s); |
| 4397 | makeLabels(); |
| 4398 | update(); |
| 4399 | } |
| 4400 | |
| 4401 | void PlayOpenGL::wheelEvent(QWheelEvent *event){ |
| 4402 | |
| 4403 | #if (QT_VERSION>0x050000) |
| 4404 | int numDegrees = (event->angleDelta().y()==0)?event->angleDelta().x():event->angleDelta().y(); |
| 4405 | #else |
| 4406 | int numDegrees = event->delta(); |
| 4407 | #endif |
| 4408 | int numSteps = numDegrees / 120; |
| 4409 | if (event->modifiers()==Qt::NoModifier){ |
| 4410 | int d = myFont.pointSize(); |
| 4411 | d = (d+numSteps>4)?d+numSteps:d; |
| 4412 | d = qMax(d,7); |
| 4413 | myFont.setPointSize(d); |
| 4414 | makeLabels(); |
| 4415 | update(); |
| 4416 | } |
| 4417 | else |
| 4418 | if (event->modifiers()==Qt::ControlModifier){ |
| 4419 | emit diffscroll(numSteps,1); |
| 4420 | } |
| 4421 | else |
| 4422 | if (event->modifiers()==Qt::ShiftModifier){ |
| 4423 | emit diffscroll(numSteps,0); |
| 4424 | } |
| 4425 | else |
| 4426 | if (event->modifiers()==(Qt::AltModifier|Qt::ShiftModifier)){ |
| 4427 | double va=qMax(viewAngle+0.1*numSteps,0.01); |
| 4428 | printf("va %f %f %d event->angleDelta().y() %d\n",va,0.1*numSteps,numSteps,event->angleDelta().x()); |
| 4429 | setViewAngle(va); |
| 4430 | } |
| 4431 | |
| 4432 | } |
| 4433 | |
| 4434 | void PlayOpenGL::mouseMoveEvent(QMouseEvent *event){ |
| 4435 | //printf("mouseMoveEvent %d %d %p %p %p\n",mol->showatoms.size(),screenAtoms.size(),sfacMenu,selSfacMenu,menu); |
| 4436 | double x = event->pos().x(); |
| 4437 | double y = event->pos().y(); |
| 4438 | double nahda=pickradius,da=0; |
| 4439 | rectangle=false; |
| 4440 | int nahdai=-1; |
| 4441 | bool changed=false; |
| 4442 | scrx=event->x(); |
| 4443 | scry=event->y(); |
| 4444 | for (int j=0; j<mol->showatoms.size();j++){ |
| 4445 | if (mol->showatoms.at(j).hidden) continue; |
| 4446 | if ((mol->showatoms.at(j).an==-1)&&(mol->showatoms.at(j).peakHeight<qcutoff)) continue; |
| 4447 | da=(((screenAtoms.at(j).x()-event->x())*( screenAtoms.at(j).x()-event->x()))+ |
| 4448 | ((screenAtoms.at(j).y()-event->y())*( screenAtoms.at(j).y()-event->y()))); |
| 4449 | nahdai=(da<nahda)?j:nahdai; |
| 4450 | nahda=qMin(nahda,da); |
| 4451 | } |
| 4452 | if ((!event->buttons())) {//(mouseOverInteraction)&& |
| 4453 | if (inFocus!=nahdai) changed=true; |
| 4454 | inFocus=nahdai; |
| 4455 | if (inFocus==-1) { |
| 4456 | emit qpfoci(-1.0); |
| 4457 | emit message(""); |
| 4458 | } else { |
| 4459 | emit message(mol->showatoms.at(inFocus).Label); |
| 4460 | if ((mol->showatoms.at(inFocus).an<0)) emit qpfoci(mol->showatoms.at(inFocus).peakHeight); |
| 4461 | else emit qpfoci(-1.0); |
| 4462 | } |
| 4463 | |
| 4464 | if (changed) { |
| 4465 | // printf("MouseMoveEvent changed %d %d %d\n",nahdai,mol->showatoms.size(),imFokus);fflush(stdout); |
| 4466 | update(); |
| 4467 | } |
| 4468 | } |
| 4469 | GLfloat dx = GLfloat( event->pos().x() - moux) / width(); |
| 4470 | GLfloat dy = GLfloat( event->pos().y() - mouy) / height(); |
| 4471 | if((event->buttons() & Qt::RightButton)) if (event->modifiers()==Qt::ShiftModifier){ |
| 4472 | double ddy = ((invertMouseZoom!=nullptr)&&(invertMouseZoom->isChecked()))?(-dy):(dy); |
| 4473 | double ll = 1.0 - ddy; |
| 4474 | legend_sc *= ll; |
| 4475 | }else{ |
| 4476 | double ddy = ((invertMouseZoom!=nullptr)&&(invertMouseZoom->isChecked()))?(-dy):(dy); |
| 4477 | double ll=1.0 - ddy; |
| 4478 | L*=ll; |
| 4479 | mvmat.scale(ll,ll,ll); |
| 4480 | pmv = pmat*mvmat; |
| 4481 | nm = mvmat.normalMatrix(); |
| 4482 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 4483 | updateSceenAtoms(); |
| 4484 | }else if ((event->buttons() & Qt::LeftButton && (event->modifiers()==(Qt::ShiftModifier|Qt::ControlModifier)))) { |
| 4485 | rectangle=true; |
| 4486 | int minxp=qMin(scrx0,scrx); |
| 4487 | int minyp=qMin(scry0,scry); |
| 4488 | int maxxp=qMax(scrx0,scrx); |
| 4489 | int maxyp=qMax(scry0,scry); |
| 4490 | mol->selectedatoms.clear(); |
| 4491 | printf("show%d screen%d\n",mol->showatoms.size(),screenAtoms.size()); |
| 4492 | for (int j=0; j<screenAtoms.size();j++){ |
| 4493 | if (mol->showatoms.at(j).hidden) continue; |
| 4494 | if ((screenAtoms.at(j).x()>minxp)&& |
| 4495 | (screenAtoms.at(j).x()<maxxp)&& |
| 4496 | (screenAtoms.at(j).y()>minyp)&& |
| 4497 | (screenAtoms.at(j).y()<maxyp)){ |
| 4498 | /*printf("%d < %f < %d | %d < %f < %d j = %d %s\n", |
| 4499 | minxp, screenAtoms.at(j).x(), maxxp, |
| 4500 | minyp, screenAtoms.at(j).y(), maxyp, |
| 4501 | j, mol->showatoms[j].Label.toStdString().c_str() );// */ |
| 4502 | mol->selectedatoms.append(mol->showatoms[j]); |
| 4503 | mol->selectedatoms.last().style = j; |
| 4504 | } |
| 4505 | } |
| 4506 | updateBondActions(); |
| 4507 | makeSelectedAtoms(); |
| 4508 | update(); |
| 4509 | } else if((event->buttons() & Qt::LeftButton)){ |
| 4510 | if (event->modifiers()==Qt::ShiftModifier) { |
| 4511 | pmat.translate(3*dx*viewAngle,-3*dy*viewAngle,0); |
| 4512 | pmv = pmat*mvmat; |
| 4513 | nm = mvmat.normalMatrix(); |
| 4514 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 4515 | updateSceenAtoms(); |
| 4516 | }else if ((manualAx!=nullptr)&&(manualAx->isChecked())&&(event->modifiers()==Qt::AltModifier)){ |
| 4517 | //printf("X\n"); |
| 4518 | makeCurrent(); |
| 4519 | GLdouble mm[16]; |
| 4520 | glGetDoublev(GL_MODELVIEW_MATRIX,mm); |
| 4521 | double det= |
| 4522 | mm[0]*mm[5]*mm[10] - mm[8]*mm[5]*mm[2]+ |
| 4523 | mm[1]*mm[6]*mm[8] - mm[9]*mm[6]*mm[0]+ |
| 4524 | mm[2]*mm[4]*mm[9] - mm[10]*mm[4]*mm[1]; |
| 4525 | Matrix mat=Matrix(mm[0],mm[1],mm[2],mm[4],mm[5],mm[6],mm[8],mm[9],mm[10]); |
| 4526 | //printf("A%g %g\n",determinant(mat),det); |
| 4527 | mat=mat*pow(det,-1.0/3.0); |
| 4528 | //printf("B%g %g\n",determinant(mat),det); |
| 4529 | |
| 4530 | V3 axe=Normalize(V3(axx->value(),axy->value(),axz->value())); |
| 4531 | axe=transponse(mat)*axe; |
| 4532 | double arr[4]; |
| 4533 | arr[0]=dx*360.0; |
| 4534 | arr[1]=0.0; |
| 4535 | arr[2]=1.0; |
| 4536 | arr[3]=0.0; |
| 4537 | axe=mol->rotarb(arr)*axe; |
| 4538 | V3 XX = mol->rotarb(arr)*V3(1, 0, 0); |
| 4539 | arr[0]=dy*360.0; |
| 4540 | arr[1]=XX.x; |
| 4541 | arr[2]=XX.y; |
| 4542 | arr[3]=XX.z; |
| 4543 | axe=mol->rotarb(arr)*axe; |
| 4544 | axe=mat*axe; |
| 4545 | axx->setValue(axe.x); |
| 4546 | axy->setValue(axe.y); |
| 4547 | axz->setValue(axe.z); |
| 4548 | splitRotate(); |
| 4549 | }else if ((freeRot!=nullptr)&&(freeRot->isChecked())&&(event->modifiers()==(Qt::AltModifier|Qt::ControlModifier))){ |
| 4550 | //printf("Y\n"); |
| 4551 | makeCurrent(); |
| 4552 | double arr[4]; |
| 4553 | /* |
| 4554 | QVector4D v4xy = QVector4D(dx*360, -dy*360, 0, 1); |
| 4555 | v4xy.normalize(); |
| 4556 | QMatrix4x4 ii= mvmat; |
| 4557 | ii=ii.inverted().transposed(); |
| 4558 | QVector4D v4xys = ii* v4xy; |
| 4559 | v4xys.normalize(); |
| 4560 | V3 xx(v4xys.x(), v4xys.y(), v4xys.z()); |
| 4561 | xx=Normalize(xx);// */ |
| 4562 | fdx+=dx; |
| 4563 | fdy+=dy; |
| 4564 | Matrix worldtoscreen=transponse(Matrix(mvmat)); |
| 4565 | double det=1.0/pow(determinant(worldtoscreen), 1.0/3.0); |
| 4566 | worldtoscreen *= det; |
| 4567 | /* |
| 4568 | freeRotMat = freeRotMat * worldtoscreen; |
| 4569 | glRotateMat(freeRotMat,dy*360.0f,1,0,0); |
| 4570 | glRotateMat(freeRotMat,-dx*360.0f,0,1,0); |
| 4571 | freeRotMat = freeRotMat * transponse(worldtoscreen); |
| 4572 | */ |
| 4573 | V3 wox(1,0,0); |
| 4574 | V3 woy(0,1,0); |
| 4575 | screenRotx = worldtoscreen * wox; |
| 4576 | screenRoty = worldtoscreen * woy; |
| 4577 | /* |
| 4578 | QQuaternion p(fdx * 36.0,screenRoty.x,screenRoty.y,screenRoty.z); |
| 4579 | QQuaternion q(fdy * 36.0,screenRotx.x,screenRotx.y,screenRotx.z); |
| 4580 | QQuaternion pq = QQuaternion::fromEulerAngles(0, fdx * 360.0, fdy * 360.0); |
| 4581 | freeRotMat = Matrix(pq.toRotationMatrix()); |
| 4582 | //V3 qax=Normalize(V3(pq.x(),pq.y(),pq.z())); |
| 4583 | //printf("fdx%g,fdy%g %f (%f %f %f)\n",fdx,fdy,pq.scalar(),qax.x,qax.y,qax.z); |
| 4584 | //freeRotMat = mol->rotarb(pq.scalar(),qax); |
| 4585 | //mol->rotarb(freeRotMat, fdy*360, screenRotx); |
| 4586 | // */ |
| 4587 | ///* |
| 4588 | arr[0] = dx * 360.0; |
| 4589 | arr[1] = screenRoty.x; |
| 4590 | arr[2] = screenRoty.y; |
| 4591 | arr[3] = screenRoty.z; |
| 4592 | freeRotMat = freeRotMat * mol->rotarb(arr); |
| 4593 | |
| 4594 | arr[0] = dy * 360.0; |
| 4595 | arr[1] = screenRotx.x; |
| 4596 | arr[2] = screenRotx.y; |
| 4597 | arr[3] = screenRotx.z; |
| 4598 | freeRotMat = freeRotMat * mol->rotarb(arr); |
| 4599 | //*/ |
| 4600 | det=1.0/pow(determinant(freeRotMat), 1.0/3.0); |
| 4601 | freeRotMat *= det; |
| 4602 | QMatrix3x3 frm; |
| 4603 | |
| 4604 | frm(0,0)=freeRotMat.m11; |
| 4605 | frm(0,1)=freeRotMat.m12; |
| 4606 | frm(0,2)=freeRotMat.m13; |
| 4607 | |
| 4608 | frm(1,0)=freeRotMat.m21; |
| 4609 | frm(1,1)=freeRotMat.m22; |
| 4610 | frm(1,2)=freeRotMat.m23; |
| 4611 | |
| 4612 | frm(2,0)=freeRotMat.m31; |
| 4613 | frm(2,1)=freeRotMat.m32; |
| 4614 | frm(2,2)=freeRotMat.m33; |
| 4615 | QQuaternion p=QQuaternion::fromRotationMatrix(frm); |
| 4616 | qDebug()<<p; |
| 4617 | qDebug()<<qRadiansToDegrees(p.scalar())<<p.vector().length(); |
| 4618 | splitRotate(); |
| 4619 | }else{ |
| 4620 | double slow=1.0; |
| 4621 | if (event->modifiers()==Qt::ShiftModifier) slow=0.25; |
| 4622 | if (event->modifiers()==Qt::ControlModifier) slow=0.06; |
| 4623 | glRotateMat(mvmat,slow*dy*360.0f,1,0,0); |
| 4624 | glRotateMat(mvmat,slow*dx*360.0f,0,1,0); |
| 4625 | pmv = pmat*mvmat; |
| 4626 | nm = mvmat.normalMatrix(); |
| 4627 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 4628 | if ((freeRot!=nullptr)&&(freeRot->isChecked())){ |
| 4629 | Matrix worldtoscreen=transponse(Matrix(mvmat)); |
| 4630 | double det=1.0/pow(determinant(worldtoscreen), 1.0/3.0); |
| 4631 | worldtoscreen *= det; |
| 4632 | V3 wox(1,0,0); |
| 4633 | V3 woy(0,1,0); |
| 4634 | screenRotx = worldtoscreen * wox; |
| 4635 | screenRoty = worldtoscreen * woy; |
| 4636 | } |
| 4637 | updateSceenAtoms(); |
| 4638 | } |
| 4639 | }else if (event->buttons() & Qt::MiddleButton){ |
| 4640 | if ((freeRot!=nullptr)&&(freeRot->isChecked())&&(event->modifiers()==(Qt::AltModifier|Qt::ControlModifier))){ |
| 4641 | V3 mv(dx, -dy, 0); |
| 4642 | makeCurrent(); |
| 4643 | Matrix worldtoscreen=transponse(Matrix(mvmat)); |
| 4644 | double det=1.0/pow(determinant(worldtoscreen), 1.0/3.0); |
| 4645 | worldtoscreen *= det; |
| 4646 | mv = worldtoscreen * mv; |
| 4647 | V3 o(orgx->value(), orgy->value(), orgz->value()); |
| 4648 | o+=mv; |
| 4649 | orgx->setValue(o.x); |
| 4650 | orgy->setValue(o.y); |
| 4651 | orgz->setValue(o.z); |
| 4652 | //printf("%f%f %f\n",mv.x,mv.x,mv.z); |
| 4653 | splitRotate(); |
| 4654 | }else{ |
| 4655 | pmat.translate(3*dx*viewAngle,-3*dy*viewAngle,0); |
| 4656 | pmv = pmat*mvmat; |
| 4657 | nm = mvmat.normalMatrix(); |
| 4658 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 4659 | updateSceenAtoms(); |
| 4660 | } |
| 4661 | } |
| 4662 | moux=x; |
| 4663 | mouy=y; |
| 4664 | update(); |
| 4665 | } |
| 4666 | |
| 4667 | void PlayOpenGL::toggleOrtho(bool b){ |
| 4668 | if (b) setViewAngle(0.05); |
| 4669 | else setViewAngle(previousViewAngle); |
| 4670 | } |
| 4671 | |
| 4672 | void PlayOpenGL::setViewAngle(double ang){ |
| 4673 | if ((ang>=0.00)&&(ang<160.0)){ |
| 4674 | //printf("before L %f %f %f ang%f va%f\n",lold,L, mvmat.determinant(),ang,viewAngle); |
| 4675 | double ll = ang / viewAngle; |
| 4676 | float ratio = static_cast<float>(width()) / static_cast<float>(height()); |
| 4677 | pmat.setToIdentity(); |
| 4678 | if (ang<0.1) { |
| 4679 | L=2.0/mol->dimension(mol->showatoms); |
| 4680 | printf("ident %d\n",__LINE__); |
| 4681 | mvmat.setToIdentity(); |
| 4682 | mvmat.lookAt(QVector3D(0.0, 200, 50) , QVector3D( 0.0, 0.0, 0.0), QVector3D(0.0, -100, 400 )); |
| 4683 | mvmat.scale(L,L,L); |
| 4684 | pmat.ortho(-ratio,ratio,-1.0f,1.0f,-5.0f,8000.0f); |
| 4685 | //printf("to ortho L %f %f %f\n",lold,L, mvmat.determinant()); |
| 4686 | previousViewAngle = qMax(viewAngle, 29.0); |
| 4687 | viewAngle=0.01; |
| 4688 | isOrtho=true; |
| 4689 | toggleOrthoView->setChecked(true); |
| 4690 | } |
| 4691 | else { |
| 4692 | viewAngle=ang; |
| 4693 | if (isOrtho){ |
| 4694 | double dim=mol->dimension(mol->showatoms); |
| 4695 | L=ang * 100.0 / (dim * 29.0); |
| 4696 | printf("ident %d\n",__LINE__); |
| 4697 | mvmat.setToIdentity(); |
| 4698 | mvmat.lookAt(QVector3D(0.0, 200, 50) , QVector3D( 0.0, 0.0, 0.0), QVector3D(0.0, -100, 400 )); |
| 4699 | mvmat.scale(L,L,L); |
| 4700 | //printf("L=> %f %f %f dim %f\n",lold,L, mvmat.determinant(),dim); |
| 4701 | }else { |
| 4702 | L*=ll; |
| 4703 | mvmat.scale(ll,ll,ll); |
| 4704 | //printf("<<==Lold = %f L = %f ll = %f\n",lold,L,ll); |
| 4705 | } |
| 4706 | isOrtho = false; |
| 4707 | pmat.perspective(static_cast<float>(viewAngle), ratio, 5.0f, 8000.0f ); |
| 4708 | toggleOrthoView->setChecked(false); |
| 4709 | } |
| 4710 | emit viewAngeleChanged(viewAngle); |
| 4711 | homeXY(); |
| 4712 | } |
| 4713 | } |
| 4714 | |
| 4715 | void PlayOpenGL::homeXY(){//! Resets the molecule to rotate in the middle of the viewport. |
| 4716 | QVector4D t = pmat.column(3); |
| 4717 | t.setX(0); |
| 4718 | t.setY(0); |
| 4719 | pmat.setColumn(3,t); |
| 4720 | pmv = pmat*mvmat; |
| 4721 | nm = mvmat.normalMatrix(); |
| 4722 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 4723 | updateSceenAtoms(); |
| 4724 | update(); |
| 4725 | } |
| 4726 | |
| 4727 | void PlayOpenGL::rotCenter(){//! reset the rotation center to the center of gravity. |
| 4728 | rotze=-1; |
| 4729 | update(); |
| 4730 | rCenter->hide(); |
| 4731 | updateSceenAtoms(); |
| 4732 | } |
| 4733 | |
| 4734 | void PlayOpenGL::toogleWithSymmetry(bool b){ |
| 4735 | withsymm=(b)?0:1; |
| 4736 | } |
| 4737 | |
| 4738 | void PlayOpenGL::expand(){//! Lets Molecule.expandAt(int index) serach for neighboring molecules around the specified atom. |
| 4739 | QAction *action = qobject_cast<QAction *>(sender()); |
| 4740 | int index=0; |
| 4741 | if (action) |
| 4742 | index=action->data().toInt(); |
| 4743 | else return; |
| 4744 | if (index==(int)((GLuint)-1))return; |
| 4745 | mol->expandAt(index); |
| 4746 | fuse->setVisible(true); |
| 4747 | grow->setVisible(false); |
| 4748 | emit bigmessage(mol->HumanSymmetry); |
| 4749 | makeAtoms(mol->showatoms); |
| 4750 | makeBonds(mol->showatoms, mol->showbonds, mol->lbonds, mol->theH_Bonds); |
| 4751 | update(); |
| 4752 | } |
| 4753 | |
| 4754 | |
| 4755 | void PlayOpenGL::hideThisFragment(){//! Hides the specified molecular fragment. |
| 4756 | //sdm(); |
| 4757 | QAction *action = qobject_cast<QAction *>(sender()); |
| 4758 | int index=0; |
| 4759 | if (action) |
| 4760 | index=action->data().toInt(); |
| 4761 | else return; |
| 4762 | if (index>mol->showatoms.size()) return; |
| 4763 | int gute=mol->showatoms.at(index).molindex+9999*mol->showatoms.at(index).symmGroup; |
| 4764 | //int gute=mol->showatoms.at(index).molindex; |
| 4765 | for (int i=0;i<mol->showatoms.size();i++) |
| 4766 | if (mol->showatoms.at(i).an>=0) |
| 4767 | mol->showatoms[i].hidden= |
| 4768 | (mol->showatoms.at(i).molindex+9999*mol->showatoms.at(i).symmGroup!=gute)?mol->showatoms.at(i).hidden:1; |
| 4769 | //(mol->showatoms.at(i).molindex!=gute)?mol->showatoms.at(i).hidden:1; |
| 4770 | // |
| 4771 | //frid=gute; |
| 4772 | hiddenThings=true; |
| 4773 | //hideReason|=HIDE_REASON_THIS_FRAGMENT; |
| 4774 | mol->selectedatoms.clear(); |
| 4775 | |
| 4776 | makeAtoms(mol->showatoms); |
| 4777 | makeBonds(mol->showatoms, mol->showbonds, mol->lbonds, mol->theH_Bonds); |
| 4778 | makeSelectedAtoms(); |
| 4779 | // murx=-__LINE__; |
| 4780 | updateBondActions(); |
| 4781 | update(); |
| 4782 | } |
| 4783 | |
| 4784 | void PlayOpenGL::selectThisFragment(){//! Selects the specified molecular fragment |
| 4785 | //sdm(); |
| 4786 | QAction *action = qobject_cast<QAction *>(sender()); |
| 4787 | int index=0; |
| 4788 | if (action) |
| 4789 | index=action->data().toInt(); |
| 4790 | else return; |
| 4791 | if (index>mol->showatoms.size()) return; |
| 4792 | mol->selectedatoms.clear(); |
| 4793 | int gute=mol->showatoms.at(index).molindex+9999*mol->showatoms.at(index).symmGroup; |
| 4794 | //int gute=mol->showatoms.at(index).molindex; |
| 4795 | for (int i=0;i<mol->showatoms.size();i++) |
| 4796 | if (mol->showatoms.at(i).an>=0) |
| 4797 | if(mol->showatoms.at(i).molindex+9999*mol->showatoms.at(i).symmGroup==gute){ |
| 4798 | mol->selectedatoms.append(mol->showatoms[i]); |
| 4799 | mol->selectedatoms.last().style=i; |
| 4800 | } |
| 4801 | //(mol->showatoms.at(i).molindex!=gute)?mol->showatoms.at(i).hidden:1; |
| 4802 | // |
| 4803 | updateBondActions(); |
| 4804 | makeSelectedAtoms(); |
| 4805 | update(); |
| 4806 | } |
| 4807 | |
| 4808 | void PlayOpenGL::hideSelected(){//! Hides the selected atoms |
| 4809 | for(int i=0;i<mol->selectedatoms.size();i++){ |
| 4810 | if (mol->selectedatoms.at(i).style < mol->showatoms.size()) |
| 4811 | mol->showatoms[mol->selectedatoms.at(i).style].hidden=1; |
| 4812 | // std::cout<<mol->showatoms.at(mol->selectedatoms.at(i).style).Label.toStdString()<<std::endl; |
| 4813 | } |
| 4814 | hiddenThings=true; |
| 4815 | mol->selectedatoms.clear(); |
| 4816 | //murx=-__LINE__; |
| 4817 | |
| 4818 | makeAtoms(mol->showatoms); |
| 4819 | makeBonds(mol->showatoms, mol->showbonds, mol->lbonds, mol->theH_Bonds); |
| 4820 | |
| 4821 | updateBondActions(); |
| 4822 | update(); |
| 4823 | } |
| 4824 | |
| 4825 | void PlayOpenGL::hideOtherFragments(){//! Hides all molecular fragments except from the specified one |
| 4826 | //sdm(); |
| 4827 | QAction *action = qobject_cast<QAction *>(sender()); |
| 4828 | int index=0; |
| 4829 | if (action) |
| 4830 | index=action->data().toInt(); |
| 4831 | else return; |
| 4832 | if (index==(int)((GLuint)-1))return; |
| 4833 | if (index>mol->showatoms.size()) return; |
| 4834 | int gute=mol->showatoms.at(index).molindex+withsymm*9999*mol->showatoms.at(index).symmGroup; |
| 4835 | //int gute=mol->showatoms.at(index).molindex; |
| 4836 | // printf("hide %d %d %d \n",withsymm,gute,mol->showatoms.at(index).molindex+9999*mol->showatoms.at(index).symmGroup); |
| 4837 | for (int i=0;i<mol->showatoms.size();i++) |
| 4838 | if (mol->showatoms.at(i).an>=0){ |
| 4839 | mol->showatoms[i].hidden= |
| 4840 | // (mol->showatoms.at(i).molindex!=gute)?1:mol->showatoms.at(i).hidden; |
| 4841 | (mol->showatoms.at(i).molindex+withsymm*9999*mol->showatoms.at(i).symmGroup!=gute)?1:mol->showatoms.at(i).hidden; |
| 4842 | // printf("%d %d \n",mol->showatoms[i].hidden,mol->showatoms.at(i).molindex+withsymm*9999*mol->showatoms.at(i).symmGroup); |
| 4843 | } |
| 4844 | hiddenThings=true; |
| 4845 | //frid=gute; |
| 4846 | //hideReason|=HIDE_REASON_OTHER_FRAGMENT; |
| 4847 | mol->selectedatoms.clear(); |
| 4848 | //murx=-__LINE__; |
| 4849 | makeAtoms(mol->showatoms); |
| 4850 | makeBonds(mol->showatoms, mol->showbonds, mol->lbonds, mol->theH_Bonds); |
| 4851 | updateBondActions(); |
| 4852 | update(); |
| 4853 | } |
| 4854 | |
| 4855 | QColor PlayOpenGL::farbverlaufQC(double wrt, double min, double max){ |
| 4856 | if (min>=max) max=min+0.001; |
| 4857 | double rot,gruen,blau,alpha; |
| 4858 | int lauf=0; |
| 4859 | double farbe[6][4]={{1.0,0.0,0.0,1.0}, |
| 4860 | {1.0,1.0,0.0,1.0}, |
| 4861 | {0.0,1.0,0.0,1.0}, |
| 4862 | {0.0,1.0,1.0,1.0}, |
| 4863 | {0.0,0.0,1.0,1.0}, |
| 4864 | {1.0,0.0,1.0,1.0}}; |
| 4865 | double nwrt=(wrt-min)/(max-min); |
| 4866 | nwrt=(nwrt>=1.0)?0.99999:nwrt; |
| 4867 | nwrt=(nwrt<=0.0)?0.00001:nwrt; |
| 4868 | lauf=(int (nwrt/0.2)); |
| 4869 | nwrt-=(0.2*lauf); |
| 4870 | nwrt/=(0.2); |
| 4871 | |
| 4872 | rot=(((1.0-nwrt)*farbe[lauf][0]+farbe[lauf+1][0]*nwrt)); |
| 4873 | gruen=(((1.0-nwrt)*farbe[lauf][1]+farbe[lauf+1][1]*nwrt)); |
| 4874 | blau=(((1.0-nwrt)*farbe[lauf][2]+farbe[lauf+1][2]*nwrt)); |
| 4875 | alpha=1.0; |
| 4876 | return QColor(static_cast<int>(255*rot), |
| 4877 | static_cast<int>(255*gruen), |
| 4878 | static_cast<int>(255*blau), |
| 4879 | static_cast<int>(255*alpha)); |
| 4880 | } |
| 4881 | |
| 4882 | |
| 4883 | void PlayOpenGL::contextMenuEvent(QMouseEvent *event){ |
| 4884 | //printf("contextMenuEvent %d %d %p %p %p\n",mol->showatoms.size(),screenAtoms.size(),sfacMenu,selSfacMenu,menu); |
| 4885 | QPoint menupoint = event->globalPos(); |
| 4886 | double nahda=pickradius,da=0; |
| 4887 | int nahdai=-1; |
| 4888 | for (int j=0; j<mol->showatoms.size();j++){ |
| 4889 | if (mol->showatoms.at(j).hidden) continue; |
| 4890 | da=(((screenAtoms.at(j).x()-event->x())*( screenAtoms.at(j).x()-event->x()))+ |
| 4891 | ((screenAtoms.at(j).y()-event->y())*( screenAtoms.at(j).y()-event->y()))); |
| 4892 | nahdai=(da<nahda)?j:nahdai; |
| 4893 | nahda=qMin(nahda,da); |
| 4894 | } |
| 4895 | //printf("da %d %f %d\n",da,nahda,nahdai); |
| 4896 | if ((nahdai < 0)||(mol->showatoms.size()<nahdai)) { |
| 4897 | return; |
| 4898 | } |
| 4899 | else { |
| 4900 | //printf("still here? %p %p %p\n",menu,restrMenu,constrMenu,enviMenu); |
| 4901 | int idx=nahdai; |
| 4902 | ImeanThisAtom=idx; |
| 4903 | if (idx>mol->showatoms.size()) return; |
| 4904 | if ((mol->showatoms.at(idx).an==-1)&&(mol->showatoms.at(idx).peakHeight<qcutoff)) return; |
| 4905 | if (menu == nullptr) menu = new QMenu(mol->showatoms.at(idx).Label); |
| 4906 | else { |
| 4907 | menu->setTitle(mol->showatoms.at(idx).Label); |
| 4908 | menu->clear(); |
| 4909 | } |
| 4910 | if (!isMainWindow) { |
| 4911 | if (enviMenu == nullptr) enviMenu = new QMenu("ENVI-Settings"); |
| 4912 | else enviMenu->clear(); |
| 4913 | enviMenu->addAction("Change envi range", this, SLOT(changeEnviRange())); |
| 4914 | enviMenu->addAction(enviNoQ); |
| 4915 | enviMenu->addAction(enviCova); |
| 4916 | menu->addMenu(enviMenu); |
| 4917 | if ((int) idx < mol->showatoms.size()){ |
| 4918 | QAction *a=nullptr; |
| 4919 | a=menu->addAction(QString("List ENVIronment of %1").arg(mol->showatoms.at(idx).Label),this,SLOT(envi())); |
| 4920 | a->setData(idx); |
| 4921 | } |
| 4922 | menu->exec(menupoint); |
| 4923 | return; |
| 4924 | } |
| 4925 | if (restrMenu == nullptr) restrMenu = new QMenu("Add restraints"); |
| 4926 | else restrMenu->clear(); |
| 4927 | if (constrMenu == nullptr) constrMenu = new QMenu("Add constraints"); |
| 4928 | else constrMenu->clear(); |
| 4929 | if (enviMenu == nullptr) enviMenu = new QMenu("ENVI-Settings"); |
| 4930 | else enviMenu->clear(); |
| 4931 | //printf("still here? %p %p %p %p %p\n",menu,restrMenu,constrMenu,enviMenu,selSfacMenu,sfacMenu); |
| 4932 | if ((selSfacMenu)&&(!mol->selectedatoms.isEmpty())) { |
| 4933 | menu->addMenu(selSfacMenu); |
| 4934 | //printf("selSfacMenu\n"); |
| 4935 | } |
| 4936 | if (sfacMenu){ |
| 4937 | QList<QAction *> sfas = sfacMenu->actions(); |
| 4938 | for (int k=0;k<sfas.size();k++){ |
| 4939 | sfas[k]->setEnabled(sfas[k]->text()!=mol->pse(mol->showatoms.at(idx).an)); |
| 4940 | } |
| 4941 | if (mol->showatoms.at(idx).symmGroup==0) menu->addMenu(sfacMenu); |
| 4942 | } |
| 4943 | //*/ |
| 4944 | //printf("still here? %p %p\n",chparent,parent()); |
| 4945 | //printf("still here? %s\n",parent()->objectName().toStdString().c_str()); |
| 4946 | |
| 4947 | QAction *a=nullptr; |
| 4948 | if (isMainWindow) { |
| 4949 | if ((mol->selectedatoms.isEmpty())&&(mol->showatoms.at(idx).symmGroup==0)) { |
| 4950 | a=menu->addAction(QIcon(theIconPath+"killselected.svg"),QString("Delete %1 ").arg(mol->showatoms.at(idx).Label), |
| 4951 | chparent,SLOT(deleteSelectedAtoms())); |
| 4952 | a->setData(idx); |
| 4953 | }else if ((mol->showatoms.at(idx).symmGroup==0)) { |
| 4954 | a=menu->addAction(QIcon(theIconPath+"killselected.svg"),QString("Delete selected atoms"), |
| 4955 | chparent,SLOT(deleteSelectedAtoms())); |
| 4956 | a->setData(-1); |
| 4957 | } |
| 4958 | if ((!mol->selectedatoms.isEmpty())) a=menu->addAction("Change RESI or PART of selected atoms",chparent,SLOT(changeResiPart())); |
| 4959 | } |
| 4960 | menu->addSeparator(); |
| 4961 | a=menu->addAction(QString("Set rotation center to %1").arg(mol->showatoms.at(idx).Label),this,SLOT(setRotationCenter())); |
| 4962 | a->setData(idx); |
| 4963 | a=menu->addAction(QString("Expand contacts around %1").arg(mol->showatoms.at(idx).Label),this,SLOT(expand())); |
| 4964 | a->setData(idx); |
| 4965 | a=menu->addAction(QString("Hide this fragment"),this,SLOT(hideThisFragment())); |
| 4966 | a->setData(idx); |
| 4967 | a=menu->addAction(QString("Select this fragment"),this,SLOT(selectThisFragment())); |
| 4968 | a->setData(idx); |
| 4969 | a=menu->addAction(QString("Hide other fragments"),this,SLOT(hideOtherFragments())); |
| 4970 | a->setData(idx); |
| 4971 | a=menu->addAction(QString("Fragment includes symmetry generated"), this ,SLOT(toogleWithSymmetry(bool))); |
| 4972 | a->setCheckable(true); |
| 4973 | a->setChecked(!(withsymm)); |
| 4974 | if (!mol->selectedatoms.isEmpty()) a=menu->addAction("Hide selected Atoms",this,SLOT(hideSelected())); |
| 4975 | bool hasSameBonds=false;//for sadi two neighbor) atoms need to be same atomic number and no hydrogen |
| 4976 | //it warks if they are not the same but gives a warning and does not make much sense |
| 4977 | if (idx<mol->asymm.size()) for (int nb=1; nb<mol->knoepfe.at(idx).neighbors.size(); nb++){ |
| 4978 | if ((mol->knoepfe.at(idx).neighbors.at(nb-1)>=mol->asymm.size())||(mol->knoepfe.at(idx).neighbors.at(nb)>=mol->asymm.size())) continue; |
| 4979 | if ((mol->asymm.at(mol->knoepfe.at(idx).neighbors.at(nb-1)).an>0)&& |
| 4980 | (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; |
| 4981 | } |
| 4982 | if(!mol->selectedatoms.isEmpty()){ |
| 4983 | restrMenu->addAction("ISOR", this, SLOT(addISOR())); |
| 4984 | if (hasSameBonds){ |
| 4985 | QAction *restr; |
| 4986 | restr=restrMenu->addAction("SADI", this, SLOT(addSADI())); |
| 4987 | restr->setData(idx); |
| 4988 | } |
| 4989 | if(mol->selectedatoms.size() == 2){ |
| 4990 | restrMenu->addAction("DFIX", this, SLOT(addDFIX())); |
| 4991 | restrMenu->addAction("DANG", this, SLOT(addDANG())); |
| 4992 | } |
| 4993 | if(mol->selectedatoms.size() >= 4){ |
| 4994 | restrMenu->addAction("FLAT", this, SLOT(addFLAT())); |
| 4995 | } |
| 4996 | if(mol->selectedatoms.size() > 1){ |
| 4997 | constrMenu->addAction("EXYZ", this, SLOT(addEXYZ())); |
| 4998 | constrMenu->addAction("EADP", this, SLOT(addEADP())); |
| 4999 | restrMenu->addAction("RIGU", this, SLOT(addRIGU())); |
| 5000 | restrMenu->addAction("DELU", this, SLOT(addDELU())); |
| 5001 | restrMenu->addAction("SIMU", this, SLOT(addSIMU())); |
| 5002 | restrMenu->addAction("CHIV", this, SLOT(addCHIV())); |
| 5003 | } |
| 5004 | menu->addMenu(restrMenu); |
| 5005 | menu->addMenu(constrMenu); |
| 5006 | }else if (hasSameBonds) { |
| 5007 | restrMenu = new QMenu("Add restraints"); |
| 5008 | QAction *restr; |
| 5009 | restr=restrMenu->addAction("SADI", this, SLOT(addSADI())); |
| 5010 | restr->setData(idx); |
| 5011 | menu->addMenu(restrMenu); |
| 5012 | } |
| 5013 | menu->addSeparator(); |
| 5014 | { |
| 5015 | QAction *a = nullptr; |
| 5016 | a = enviMenu->addAction("Change ENVI Range", this, SLOT(changeEnviRange())); |
| 5017 | a->setData(idx); |
| 5018 | enviMenu->addAction(enviNoQ); |
| 5019 | enviNoQ->setData(idx); |
| 5020 | connect(enviNoQ,SIGNAL(triggered(bool)),this,SLOT(envi())); |
| 5021 | enviMenu->addAction(enviCova); |
| 5022 | enviCova->setData(idx); |
| 5023 | connect(enviCova,SIGNAL(triggered(bool)),this,SLOT(envi())); |
| 5024 | } |
| 5025 | /* |
| 5026 | enviMenu->addAction(QString("Change ENVI Range (%1A)").arg(envirange), this, SLOT(changeEnviRange())); |
| 5027 | enviMenu->addAction(enviNoQ); |
| 5028 | enviMenu->addAction(enviCova); |
| 5029 | */ |
| 5030 | menu->addMenu(enviMenu); |
| 5031 | |
| 5032 | if ((int) idx < mol->asymm.size()){ |
| 5033 | a=menu->addAction(QString("List ENVIronment of %1").arg(mol->showatoms.at(idx).Label),this,SLOT(envi())); |
| 5034 | a->setData(idx); |
| 5035 | a=menu->addAction(QString("Grow ENVIronment of %1").arg(mol->showatoms.at(idx).Label),this,SLOT(growEnvi())); |
| 5036 | a->setData(idx); |
| 5037 | a=menu->addAction(QString("Show only ENVIronment of %1").arg(mol->showatoms.at(idx).Label),this,SLOT(showEnvi())); |
| 5038 | a->setData(idx); |
| 5039 | } |
| 5040 | menu->addSeparator(); |
| 5041 | int ssgr=0; |
| 5042 | int adpat=0; |
| 5043 | for (int seli=0; seli<mol->selectedatoms.size(); seli++){ |
| 5044 | if ((mol->showatoms.at(seli).symmGroup==0)&&(!mol->selectedatoms.at(seli).isIso))adpat++; |
| 5045 | } |
| 5046 | for (int seli=0; seli<mol->selectedatoms.size(); seli++){ |
| 5047 | if (mol->selectedatoms.at(seli).symmGroup>0) ssgr+=mol->selectedatoms.at(seli).symmGroup; |
| 5048 | else { |
| 5049 | ssgr=0; |
| 5050 | break; |
| 5051 | } |
| 5052 | } |
| 5053 | if (ssgr) adpat=0; |
| 5054 | if (ssgr){ |
| 5055 | a=menu->addAction(QString("Move selected atoms to selected sites"), |
| 5056 | chparent,SLOT(moveSymmMateSel())); |
| 5057 | //////// 28.03.12 |
| 5058 | if ((mol->showatoms.at(idx).part<0)){ |
| 5059 | a=menu->addAction(QString("Copy %1 here").arg(mol->showatoms.at(idx).Label.section("_",0,0)), |
| 5060 | chparent,SLOT(copySymmMate())); |
| 5061 | a->setData(idx); |
| 5062 | } |
| 5063 | //////// - |
| 5064 | }else{ |
| 5065 | if ((mol->showatoms.at(idx).symmGroup>0)){ |
| 5066 | a=menu->addAction(QString("Move %1 here").arg(mol->showatoms.at(idx).Label.section("_",0,0)), |
| 5067 | chparent,SLOT(moveSymmMate())); |
| 5068 | a->setData(idx); |
| 5069 | if ((mol->showatoms.at(idx).part<0)){ |
| 5070 | a=menu->addAction(QString("Copy %1 here").arg(mol->showatoms.at(idx).Label.section("_",0,0)), |
| 5071 | chparent,SLOT(copySymmMate())); |
| 5072 | a->setData(idx); |
| 5073 | } |
| 5074 | } |
| 5075 | } |
| 5076 | menu->addSeparator(); |
| 5077 | if ((nahdai<mol->asymm.size())&&(mol->knoepfe.at(idx).neighbors.size()==1)&&((mol->showatoms.at(idx).an==6)||(mol->showatoms.at(idx).an==5))) { |
| 5078 | a=menu->addAction(QString("Add dissordered %1 Hydrogen atoms").arg(((mol->showatoms.at(idx).an==5))?"methyl":"-NH3"),chparent,SLOT(addDissorderedMethyl())); |
| 5079 | a->setData(idx); |
| 5080 | a=menu->addAction(QString("Add ordered %1 Hydrogen atoms").arg(((mol->showatoms.at(idx).an==5))?"methyl":"-NH3+"),chparent,SLOT(addMethyl())); |
| 5081 | a->setData(idx); |
| 5082 | a=menu->addAction(QString("Add terminal %1 Hydrogen atoms").arg(((mol->showatoms.at(idx).an==5))?"=CH2 ":"=NH2+"),chparent,SLOT(addH93())); |
| 5083 | a->setData(idx); |
| 5084 | if (mol->showatoms.at(idx).an==5){ |
| 5085 | a=menu->addAction(QString("Add acetylenic C-H Hydrogen atom"),chparent,SLOT(addH163())); |
| 5086 | a->setData(idx); |
| 5087 | } |
| 5088 | if (mol->showatoms.at(idx).an==6){ |
| 5089 | a=menu->addAction(QString("Add %1 Hydrogen atoms").arg("-NH2 (non planar)"),chparent,SLOT(addHnonplanarAminR1())); |
| 5090 | a->setData(idx); |
| 5091 | } |
| 5092 | } |
| 5093 | if ((nahdai<mol->asymm.size())&&(mol->knoepfe.at(idx).neighbors.size()==1)&&(mol->showatoms.at(idx).an==7)){ |
| 5094 | a->setData(idx); |
| 5095 | a=menu->addAction(QString("Add hydroxyl Hydrogen atom to %1").arg(mol->showatoms.at(idx).Label.section("_",0,0)),chparent,SLOT(addHydroxyl())); |
| 5096 | a->setData(idx); |
| 5097 | } |
| 5098 | if ((nahdai<mol->asymm.size())&&(mol->knoepfe.at(idx).neighbors.size()==2)&&((mol->showatoms.at(idx).an==6)||(mol->showatoms.at(idx).an==5))) { |
| 5099 | a=menu->addAction(QString("Add %1 Hydrogen atoms").arg(((mol->showatoms.at(idx).an==5))?">CH2":">NH2+"),chparent,SLOT(addH23())); |
| 5100 | a->setData(idx); |
| 5101 | a=menu->addAction(QString("Add %1 Hydrogen atom").arg(((mol->showatoms.at(idx).an==5))?">CH":">NH (planar)"),chparent,SLOT(addH43())); |
| 5102 | a->setData(idx); |
| 5103 | //addHnonplanarAminR2(); |
| 5104 | if ((mol->showatoms.at(idx).an==6)){ |
| 5105 | a=menu->addAction(QString("Add %1 Hydrogen atom").arg(">NH (non planar)"),chparent,SLOT(addHnonplanarAminR2())); |
| 5106 | a->setData(idx); |
| 5107 | } |
| 5108 | } |
| 5109 | if ((idx < mol->asymm.size()) && (mol->asymm.at(idx).an>-1)) { |
| 5110 | a=menu->addAction(QString("Use %1 as new label for rename mode").arg(mol->showatoms.at(idx).Label.section("_",0,0)),chparent,SLOT(renameThisAtom())); |
| 5111 | a->setData(idx); |
| 5112 | } |
| 5113 | |
| 5114 | if(!mol->selectedatoms.isEmpty()){ |
| 5115 | menu->addAction(QString("Make selected atoms ANIS"),this,SLOT(addANIS())); |
| 5116 | } |
| 5117 | if ((adpat)) { |
| 5118 | if (mol->selectedatoms.isEmpty()){ |
| 5119 | a=menu->addAction(QIcon(theIconPath+"sina.svg"),QString("make %1 isotropic (ISOT)") |
| 5120 | .arg(mol->showatoms.at(idx).Label),chparent,SLOT(sina())); |
| 5121 | a->setData(idx); |
| 5122 | }else{ |
| 5123 | a=menu->addAction(QIcon(theIconPath+"sina.svg"),QString("make selected atoms isotropic (ISOT)"),chparent,SLOT(sina())); |
| 5124 | a->setData(-1); |
| 5125 | } |
| 5126 | } |
| 5127 | if ((idx<mol->asymm.size())&&(mol->asymm.at(idx).an>-1)){ |
| 5128 | QAction *a = menu->addAction("Draw voronoi polyeder of this atom",chparent,SLOT(makeVoro())); |
| 5129 | a->setData(idx); |
| 5130 | } |
| 5131 | if ((mol->showatoms.at(p).molindex!=mol->showatoms.at(idx).molindex)){ |
| 5132 | menu->addSeparator(); |
| 5133 | menu->addAction(QString("Inherit Labels from molecule around %1 to atoms around %2") |
| 5134 | .arg(mol->showatoms.at(p).Label) |
| 5135 | .arg(mol->showatoms.at(idx).Label) |
| 5136 | ,chparent,SLOT(inheritLabels())); |
| 5137 | ppp = pp; |
| 5138 | pp = p; |
| 5139 | p = idx; |
| 5140 | } |
| 5141 | menu->exec(menupoint); |
| 5142 | //delete enviMenu; |
| 5143 | //delete menu; |
| 5144 | } |
| 5145 | } |
| 5146 | |
| 5147 | |
| 5148 | void PlayOpenGL::mousePressEvent(QMouseEvent *event){ |
| 5149 | //printf("mousePressEvent mouxy %d %d \n",moux,mouy); |
| 5150 | if ((event->buttons() & Qt::RightButton)){ |
| 5151 | contextMenuEvent(event); |
| 5152 | return; |
| 5153 | } |
| 5154 | if (menu) menu->close(); |
| 5155 | if (rectangle){ |
| 5156 | rectangle=false; |
| 5157 | update(); |
| 5158 | } |
| 5159 | moux=event->pos().x(); |
| 5160 | mouy=event->pos().y(); |
| 5161 | |
| 5162 | p = qMin(p,mol->showatoms.size()-1); |
| 5163 | pp = qMin(pp,mol->showatoms.size()-1); |
| 5164 | ppp = qMin(ppp,mol->showatoms.size()-1); |
| 5165 | |
| 5166 | p = qMax(p,0); |
| 5167 | pp = qMax(pp,0); |
| 5168 | ppp = qMax(ppp,0); |
| 5169 | double nahda=pickradius,da=0; |
| 5170 | int nahdai=-1; |
| 5171 | for (int j=0; j<mol->showatoms.size();j++){ |
| 5172 | if (mol->showatoms.at(j).hidden) continue; |
| 5173 | if ((mol->showatoms.at(j).an==-1)&&(mol->showatoms.at(j).peakHeight<qcutoff)) continue; |
| 5174 | |
| 5175 | da=(((screenAtoms.at(j).x()-event->x())*( screenAtoms.at(j).x()-event->x()))+ |
| 5176 | ((screenAtoms.at(j).y()-event->y())*( screenAtoms.at(j).y()-event->y()))); |
| 5177 | nahdai=(da<nahda)?j:nahdai; |
| 5178 | nahda=qMin(nahda,da); |
| 5179 | } |
| 5180 | if (event->buttons() & Qt::LeftButton){ |
| 5181 | scrx0=moux; |
| 5182 | scry0=mouy; |
| 5183 | if ((event->buttons() & Qt::LeftButton) && (nahdai >= 0) && (nahdai < mol->showatoms.size())){ |
| 5184 | int index=nahdai; |
| 5185 | if (event->modifiers()==Qt::NoModifier) { |
| 5186 | double w=0,dw=0; |
| 5187 | if ((pp!=p)&&(pp!=index)&&(p!=index)) { |
| 5188 | V3 aa1=mol->showatoms.at(p).pos-mol->showatoms.at(pp).pos; |
| 5189 | V3 aa2=mol->showatoms.at(p).pos-mol->showatoms.at(index).pos; |
| 5190 | w=mol->winkel(aa1,aa2); |
| 5191 | if ((ppp!=p)&&(ppp!=pp)&&(ppp!=index)) |
| 5192 | dw=mol->dieder(mol->showatoms.at(pp).pos-mol->showatoms.at(ppp).pos, |
| 5193 | mol->showatoms.at(pp).pos-mol->showatoms.at(p).pos, |
| 5194 | mol->showatoms.at(p).pos-mol->showatoms.at(index).pos); |
| 5195 | } |
| 5196 | if (atomsClickable){ |
| 5197 | emit jumpit(index); |
| 5198 | /* printf("%s %d %d\n", |
| 5199 | mol->showatoms.at(index).Label.toStdString().c_str(), |
| 5200 | mol->showatoms.at(index).scod, |
| 5201 | mol->showatoms.at(index).an);*/ |
| 5202 | if (inRenameMode) return; |
| 5203 | if (!inRenameMode){ |
| 5204 | apair.clear(); |
| 5205 | if (event->modifiers()==Qt::NoModifier) { |
| 5206 | int isschon=-1; |
| 5207 | for (int i=0; i< mol->selectedatoms.size();i++){ |
| 5208 | isschon=(mol->selectedatoms.at(i).style==index)?index:isschon; |
| 5209 | } |
| 5210 | mol->selectedatoms.clear(); |
| 5211 | if (isschon==-1){ |
| 5212 | mol->selectedatoms.append(mol->showatoms[index]); |
| 5213 | mol->selectedatoms.last().style=index; |
| 5214 | } |
| 5215 | } |
| 5216 | if ((manualAx!=nullptr)&&(!manualAx->isChecked())&&(event->modifiers()==Qt::AltModifier)) { |
| 5217 | int pv1=pivot1cb->findText(mol->showatoms.at(p).Label); |
| 5218 | int pv2=pivot2cb->findText(mol->showatoms.at(index).Label); |
| 5219 | if ((pv1>-1)&&(pv2)){ |
| 5220 | emit pivot1Changed(pv1); |
| 5221 | emit pivot2Changed(pv2); |
| 5222 | altpivot=true; |
| 5223 | //printf("new axe %d %d\n",pv1,pv2); |
| 5224 | } |
| 5225 | |
| 5226 | } |
| 5227 | if (event->modifiers()==Qt::ShiftModifier) { |
| 5228 | int min=mol->showatoms.size(), max=-1; |
| 5229 | for (int i=0; i< mol->selectedatoms.size();i++){ |
| 5230 | min=qMin(mol->selectedatoms.at(i).style,min); |
| 5231 | max=qMax(mol->selectedatoms.at(i).style,max); |
| 5232 | } |
| 5233 | min=qMin((int)index,min); |
| 5234 | max=qMax((int)index,max); |
| 5235 | mol->selectedatoms.clear(); |
| 5236 | for (int i=min; i<=max; i++){ |
| 5237 | mol->selectedatoms.append(mol->showatoms[i]); |
| 5238 | mol->selectedatoms.last().style=i; |
| 5239 | } |
| 5240 | } |
| 5241 | if (event->modifiers()==Qt::ControlModifier) { |
| 5242 | if (mol->selectedatoms.contains(mol->showatoms[index])){ |
| 5243 | mol->selectedatoms.removeOne(mol->showatoms[index]); |
| 5244 | } else { |
| 5245 | mol->selectedatoms.append(mol->showatoms[index]); |
| 5246 | mol->selectedatoms.last().style=index; |
| 5247 | // 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(); |
| 5248 | } |
| 5249 | } |
| 5250 | // std::cout<<mol->selectedatoms.size()<<mol->selectedatoms.last().Label.toStdString()<<std::endl; |
| 5251 | emit selectionChanged(); |
| 5252 | updateBondActions(); |
| 5253 | update(); |
| 5254 | } |
| 5255 | // |
| 5256 | |
| 5257 | V3 hin; |
| 5258 | double dmsda=0; |
| 5259 | hin = Normalize(mol->showatoms.at(index).pos-mol->showatoms.at(p).pos); |
| 5260 | if ((mol->showatoms.at(index).an>-1) && (mol->showatoms.at(p).an)) |
| 5261 | dmsda = fabs(((hin*mol->showatoms.at(index).uc)*hin)- ((hin*mol->showatoms.at(p).uc)*hin)); |
| 5262 | // |
| 5263 | bool syok; |
| 5264 | QString symml; |
| 5265 | int syid=mol->showatoms.at(index).Label.section(QString::fromUtf8("»"),1).toInt(&syok); |
| 5266 | if (mol->usedSymmetry.size()&&syok) symml=mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid); |
| 5267 | syid=mol->showatoms.at(p).Label.section(QString::fromUtf8("»"),1).toInt(&syok); |
| 5268 | if ((mol->usedSymmetry.size())&&(syok)&&(!symml.contains(mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid)))) |
| 5269 | symml+=mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid); |
| 5270 | |
| 5271 | syid=mol->showatoms.at(pp).Label.section(QString::fromUtf8("»"),1).toInt(&syok); |
| 5272 | if ((mol->usedSymmetry.size())&&(syok)&&(!symml.contains(mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid)))) |
| 5273 | symml+=mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid); |
| 5274 | |
| 5275 | syid=mol->showatoms.at(ppp).Label.section(QString::fromUtf8("»"),1).toInt(&syok); |
| 5276 | if ((mol->usedSymmetry.size())&&(syok)&&(!symml.contains(mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid)))) |
| 5277 | symml+=mol->symmcode2human(mol->usedSymmetry.at(syid-1),syid); |
| 5278 | /*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", |
| 5279 | mol->showatoms.at(index).Label.toStdString().c_str(), |
| 5280 | mol->showatoms.at(index).ufiso_org.toStdString().c_str(), |
| 5281 | mol->showatoms.at(index).isIso, |
| 5282 | 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, |
| 5283 | 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, |
| 5284 | 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 |
| 5285 | );// */ |
| 5286 | |
| 5287 | if ((index!=p)&&(index!=pp)&&(mol->showatoms.at(index).Label[0]=='Q')){ |
| 5288 | /*printf("scod %d %f %f %f \n",mol->showatoms.at(index).scod, |
| 5289 | mol->showatoms.at(index).frac.x, |
| 5290 | mol->showatoms.at(index).frac.y, |
| 5291 | mol->showatoms.at(index).frac.z);// **/ |
| 5292 | emit bigmessage(QString("<hr><table><tr><td><b>%1</b></td><td align=\"right\"></td></tr><tr><td><b>%1--%2</b>" |
| 5293 | "</td><td align=\"right\">%5 Å</td></tr><tr><td><b>%1--%2--%3</b></td><td " |
| 5294 | "align=\"right\">%6°</td></tr><tr><td><b>%1--%2--%3--%4 </b></td><td " |
| 5295 | "align=\"right\">%7°</td></tr><tr><td><b>%1</b> Peak Height: </td><td " |
| 5296 | "align=\"right\">%8 eÅ<sup>-3</sup></td><td>[%9…%10]" |
| 5297 | "</td></tr></table>%11") |
| 5298 | .arg((mol->showatoms.at(index).Label)) //1 |
| 5299 | .arg((mol->showatoms.at(p).Label)) //3 |
| 5300 | .arg((mol->showatoms.at(pp).Label)) //5 //8 |
| 5301 | .arg((mol->showatoms.at(ppp).Label)) //9 |
| 5302 | .arg(sqrt(Distance(mol->showatoms.at(index).pos,mol->showatoms.at(p).pos)),8,'f',3) //4 |
| 5303 | .arg(w,8,'f',2) |
| 5304 | .arg(dw,8,'f',2) |
| 5305 | .arg(mol->showatoms.at(index).peakHeight,8,'f',2) |
| 5306 | .arg(mol->pmin,3,'f',2) |
| 5307 | .arg(mol->pmax,3,'f',2) |
| 5308 | .arg(symml) |
| 5309 | |
| 5310 | ); |
| 5311 | } |
| 5312 | else if ((index!=p)&&(index!=pp)&&(mol->showatoms.at(index).Label[0]=='L')&&(mol->showatoms.at(index).an==-42)){ |
| 5313 | emit bigmessage(QString("<hr><table><tr><td><b>%1</b></td><td align=\"right\"></td></tr><tr><td><b>%1--%2</b>" |
| 5314 | "</td><td align=\"right\">%5 Å</td></tr><tr><td><b>%1--%2--%3</b></td><td " |
| 5315 | "align=\"right\">%6°</td></tr><tr><td><b>%1--%2--%3--%4 </b></td><td " |
| 5316 | "align=\"right\">%7°</td></tr><tr><td><b>%1</b> a exp(-b x<sup>2</sup>)</td><td " |
| 5317 | "align=\"right\">a = %8 </td><td> b = %9 " |
| 5318 | "</td></tr></table>%11") |
| 5319 | .arg((mol->showatoms.at(index).Label)) //1 |
| 5320 | .arg((mol->showatoms.at(p).Label)) //3 |
| 5321 | .arg((mol->showatoms.at(pp).Label)) //5 //8 |
| 5322 | .arg((mol->showatoms.at(ppp).Label)) //9 |
| 5323 | .arg(sqrt(Distance(mol->showatoms.at(index).pos,mol->showatoms.at(p).pos)),8,'f',3) //4 |
| 5324 | .arg(w,8,'f',2) |
| 5325 | .arg(dw,8,'f',2) |
| 5326 | .arg(mol->showatoms.at(index).sof,8,'f',2) |
| 5327 | .arg(mol->showatoms.at(index).peakHeight,8,'f',2) |
| 5328 | .arg(symml) |
| 5329 | |
| 5330 | ); |
| 5331 | } |
| 5332 | else if ((index!=p)&&(index!=pp)){ |
| 5333 | emit bigmessage(QString("<br><hr><table><tr><td><b>%1</b> part: %8 residue: %9 %10 (fragment: %12)</td><td align=\"right\">" |
| 5334 | "</td></tr><tr><td><b>%1--%2</b></td><td align=\"right\">%5 Å</td><td> DMSDA: %13 Å<sup>2</sup></td></tr>" |
| 5335 | "<tr><td><b>%1--%2--%3</b></td><td align=\"right\">%6°</td><td> 1,3 Distance( DANG) %14 Å</td></tr><tr><td>" |
| 5336 | "<b>%1--%2--%3--%4 </b></td><td align=\"right\">%7°</td></tr></table>%11") |
| 5337 | .arg((mol->showatoms.at(index).Label)) //1 |
| 5338 | .arg((mol->showatoms.at(p).Label)) //2 |
| 5339 | .arg((mol->showatoms.at(pp).Label)) //3 |
| 5340 | .arg((mol->showatoms.at(ppp).Label)) //4 |
| 5341 | .arg(sqrt(Distance(mol->showatoms.at(index).pos,mol->showatoms.at(p).pos)),8,'f',3) //5 |
| 5342 | .arg(w,8,'f',2) //6 |
| 5343 | .arg(dw,8,'f',2) //7 |
| 5344 | .arg(mol->showatoms.at(index).part) |
| 5345 | .arg(mol->showatoms.at(index).resiNr) |
| 5346 | .arg(mol->showatoms.at(index).ResiClass) |
| 5347 | .arg(symml) |
| 5348 | .arg(mol->showatoms.at(index).molindex) |
| 5349 | .arg(dmsda,5,'e',2) |
| 5350 | .arg(sqrt(Distance(mol->showatoms.at(index).pos,mol->showatoms.at(pp).pos)),8,'f',3) |
| 5351 | ); |
| 5352 | } |
| 5353 | // ,QMessageBox::Ok); |
| 5354 | ppp = pp; |
| 5355 | pp = p; |
| 5356 | p = index; |
| 5357 | } |
| 5358 | |
| 5359 | }else if (event->modifiers()==Qt::ShiftModifier) { |
| 5360 | int min=mol->showatoms.size(), max=-1; |
| 5361 | for (int i=0; i< mol->selectedatoms.size();i++){ |
| 5362 | min=qMin(mol->selectedatoms.at(i).style,min); |
| 5363 | max=qMax(mol->selectedatoms.at(i).style,max); |
| 5364 | } |
| 5365 | min=qMin((int)index,min); |
| 5366 | max=qMax((int)index,max); |
| 5367 | mol->selectedatoms.clear(); |
| 5368 | for (int i=min; i<=max; i++){ |
| 5369 | mol->selectedatoms.append(mol->showatoms[i]); |
| 5370 | mol->selectedatoms.last().style=i; |
| 5371 | } |
| 5372 | } |
| 5373 | if (event->modifiers()==Qt::ControlModifier) { |
| 5374 | if (mol->selectedatoms.contains(mol->showatoms[index])){ |
| 5375 | mol->selectedatoms.removeOne(mol->showatoms[index]); |
| 5376 | } else { |
| 5377 | mol->selectedatoms.append(mol->showatoms[index]); |
| 5378 | mol->selectedatoms.last().style=index; |
| 5379 | } |
| 5380 | } |
| 5381 | updateBondActions(); |
| 5382 | makeSelectedAtoms(); |
| 5383 | updateSceenAtoms(); |
| 5384 | update(); |
| 5385 | } |
| 5386 | } |
| 5387 | if ((event->buttons() & Qt::MiddleButton) && (nahdai >= 0) && (nahdai < mol->showatoms.size()) && (parent()->objectName()=="The Main Window")){ |
| 5388 | int index=nahdai; |
| 5389 | rotze=((int)index<mol->showatoms.size())?index:-1; |
| 5390 | printf("rot center %d %d %d\n",rotze, mol->showatoms.size(),index); |
| 5391 | if (rotze>-1){ |
| 5392 | if (parent()->objectName()=="The Main Window") rCenter->show(); |
| 5393 | homeXY(); |
| 5394 | updateSceenAtoms(); |
| 5395 | //glGetDoublev(GL_MODELVIEW_MATRIX, MM); MM[12] = MM[13] = 0; glLoadMatrixd(MM); |
| 5396 | } |
| 5397 | update(); |
| 5398 | } |
| 5399 | update(); |
| 5400 | } |
| 5401 | |
| 5402 | void PlayOpenGL::along001(){ |
| 5403 | makeCurrent(); |
| 5404 | double va=viewAngle; |
| 5405 | setViewAngle(29.0); |
| 5406 | mvmat(0,0)=1.f; |
| 5407 | mvmat(0,1)=0.f; |
| 5408 | mvmat(0,2)=0.f; |
| 5409 | mvmat(1,0)=0.f; |
| 5410 | mvmat(1,1)=1.f; |
| 5411 | mvmat(1,2)=0.f; |
| 5412 | mvmat(2,0)=0.f; |
| 5413 | mvmat(2,1)=0.f; |
| 5414 | mvmat(2,2)=1.f; |
| 5415 | pmv = pmat*mvmat; |
| 5416 | nm = mvmat.normalMatrix(); |
| 5417 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 5418 | updateSceenAtoms(); |
| 5419 | update(); |
| 5420 | setViewAngle(va); |
| 5421 | } |
| 5422 | |
| 5423 | void PlayOpenGL::zoom(double speed){//!scale about speed @param speed scale factor |
| 5424 | double ll=1.0+speed*0.1; |
| 5425 | L*=ll; |
| 5426 | mvmat.scale(ll,ll,ll); |
| 5427 | pmv = pmat*mvmat; |
| 5428 | nm = mvmat.normalMatrix(); |
| 5429 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 5430 | updateSceenAtoms(); |
| 5431 | update(); |
| 5432 | } |
| 5433 | |
| 5434 | void PlayOpenGL::rotY(double speed){//!rotate around Y axis @param speed in degrees |
| 5435 | //glRotateL(-20.0*speed,0.0f,1.0f,0.0f); |
| 5436 | glRotateMat(mvmat,-20.0*speed,0,1,0); |
| 5437 | pmv = pmat*mvmat; |
| 5438 | nm = mvmat.normalMatrix(); |
| 5439 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 5440 | updateSceenAtoms(); |
| 5441 | update(); |
| 5442 | } |
| 5443 | |
| 5444 | void PlayOpenGL::gZoom(double speed){//!scale about speed @param speed scale factor |
| 5445 | //glScaled(1.0+speed*0.02,1.0+speed*0.02,1.0+speed*0.02); |
| 5446 | double ll=1.0+speed*0.02; |
| 5447 | L*=ll; |
| 5448 | mvmat.scale(ll,ll,ll); |
| 5449 | pmv = pmat*mvmat; |
| 5450 | nm = mvmat.normalMatrix(); |
| 5451 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 5452 | updateSceenAtoms(); |
| 5453 | update(); |
| 5454 | } |
| 5455 | |
| 5456 | void PlayOpenGL::rotZ(double speed){//!rotate around Z axis @param speed in degrees |
| 5457 | glRotateMat(mvmat,-20*speed,0,0,1); |
| 5458 | pmv = pmat*mvmat; |
| 5459 | nm = mvmat.normalMatrix(); |
| 5460 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 5461 | updateSceenAtoms(); |
| 5462 | update(); |
| 5463 | } |
| 5464 | |
| 5465 | void PlayOpenGL::moveY(double speed){//!translate the molecule in Y direction |
| 5466 | //glTranslateL(0.0,speed,0.0); |
| 5467 | pmat.translate(0,speed*viewAngle,0); |
| 5468 | pmv = pmat*mvmat; |
| 5469 | nm = mvmat.normalMatrix(); |
| 5470 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 5471 | updateSceenAtoms(); |
| 5472 | |
| 5473 | update(); |
| 5474 | } |
| 5475 | |
| 5476 | void PlayOpenGL::moveX(double speed){//!translate the molecule in X direction |
| 5477 | //glTranslateL(speed,0.0,0.0); |
| 5478 | pmat.translate(speed*viewAngle,0,0); |
| 5479 | pmv = pmat*mvmat; |
| 5480 | nm = mvmat.normalMatrix(); |
| 5481 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 5482 | updateSceenAtoms(); |
| 5483 | // QMessageBox::information(this,"Px move","xmoved",QMessageBox::Ok); |
| 5484 | update(); |
| 5485 | } |
| 5486 | |
| 5487 | void PlayOpenGL::rotX(double speed){//!rotate around X axis @param speed in degrees |
| 5488 | //glRotateL(-20.0*speed,1.0f,0.0f,0.0f); |
| 5489 | glRotateMat(mvmat,-20*speed,1,0,0); |
| 5490 | pmv = pmat*mvmat; |
| 5491 | nm = mvmat.normalMatrix(); |
| 5492 | eye = mvmat.inverted()*QVector4D(0,0,0,1); |
| 5493 | updateSceenAtoms(); |
| 5494 | update(); |
| 5495 | } |
| 5496 | |
| 5497 | |
| 5498 | void PlayOpenGL::paintGL(){ |
| 5499 | //if (parent()->objectName()!="The Main Window") printf("paintGL -> %d\n",context()->isValid()); |
| 5500 | GLenum err = GL_NO_ERROR; |
| 5501 | while((err = glGetError()) != GL_NO_ERROR){ |
| 5502 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 5503 | //printf("%s\n",(char*)gluErrorString(err)); |
| 5504 | } |
| 5505 | |
| 5506 | glClearColor(backGroundColor.redF(),backGroundColor.greenF(),backGroundColor.blueF(),backGroundColor.alphaF()); |
| 5507 | frame_cnt++; |
| 5508 | QVector3D org = QVector3D(sumse.x, sumse.y, sumse.z); |
| 5509 | if ((rotze>-1)&&(rotze<mol->showatoms.size())) org = QVector3D(mol->showatoms.at(rotze).pos.x, mol->showatoms.at(rotze).pos.y, mol->showatoms.at(rotze).pos.z); |
| 5510 | if ((centerSelection)&&(centerSelection->isChecked())){ |
| 5511 | if (mol->selectedatoms.isEmpty()) { |
| 5512 | org = QVector3D(sumse.x, sumse.y, sumse.z); |
| 5513 | } |
| 5514 | else { |
| 5515 | V3 sums=V3(0,0,0); |
| 5516 | for (int i = 0; i < mol->selectedatoms.size(); i++) sums += mol->selectedatoms[i].pos; |
| 5517 | sums *= 1.0 / mol->selectedatoms.size(); |
| 5518 | org = QVector3D(sums.x, sums.y, sums.z); |
| 5519 | } |
| 5520 | } |
| 5521 | V3 org3=V3(org.x(), org.y(), org.z()); |
| 5522 | altemitte=org3; |
| 5523 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
| 5524 | if (bg_program){ |
| 5525 | |
| 5526 | //if (parent()->objectName()!="The Main Window") printf("paintGL -> %d\n",__LINE__); |
| 5527 | if ( !bg_program->bind() ){ qWarning() << "Could not bind shader program to context"; return;} |
| 5528 | bg_vao.bind(); |
| 5529 | bg_program->setUniformValue("bgcolor", backGroundColor); |
| 5530 | bg_program->setUniformValue("bggradient", bggradient); |
| 5531 | glDisable(GL_DEPTH_TEST); |
| 5532 | glEnable(GL_BLEND); |
| 5533 | glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; |
| 5534 | glDisable(GL_CULL_FACE); |
| 5535 | glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); |
| 5536 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| 5537 | glEnable(GL_DEPTH_TEST); |
| 5538 | bg_vao.release(); |
| 5539 | bg_program->release(); |
| 5540 | }//* |
| 5541 | if (rectangle) renderRect(); |
| 5542 | if ((drawAtoms)&&(atom_program)){ |
| 5543 | GLenum err = GL_NO_ERROR; |
| 5544 | while((err = glGetError()) != GL_NO_ERROR) |
| 5545 | { |
| 5546 | printf("atom_program %s error %X\n", parent()->objectName().toStdString().c_str(),err); |
| 5547 | //printf("%s\n",(char*)gluErrorString(err)); |
| 5548 | } |
| 5549 | |
| 5550 | //if (parent()->objectName()!="The Main Window") printf("paintGL -> %d atom_index_size %d\n",__LINE__,atom_index_size); |
| 5551 | if ( !atom_program->bind() ){ qWarning() << "Could not bind shader program to context"; return;} |
| 5552 | float fiftypct =1.54; |
| 5553 | switch (mol->proba ) { |
| 5554 | case 10 :{ fiftypct = 0.76; break;} //Hauptachsen der Eliipsoide 10% Wahrscheinlichkeit |
| 5555 | case 30 :{ fiftypct = 1.19; break;} //Hauptachsen der Eliipsoide 30% Wahrscheinlichkeit |
| 5556 | case 50 :{ fiftypct = 1.54; break;} //Hauptachsen der Eliipsoide 50% Wahrscheinlichkeit |
| 5557 | case 70 :{ fiftypct = 1.91; break;} //Hauptachsen der Eliipsoide 70% Wahrscheinlichkeit |
| 5558 | case 90 :{ fiftypct = 2.50; break;} //Hauptachsen der Eliipsoide 90% Wahrscheinlichkeit |
| 5559 | default: ; |
| 5560 | } |
| 5561 | atom_vao.bind(); |
| 5562 | glEnable(GL_DEPTH_TEST); |
| 5563 | glEnable(GL_BLEND); |
| 5564 | glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; |
| 5565 | atom_program->setUniformValue("pmv", pmv); |
| 5566 | atom_program->setUniformValue("origin", org); |
| 5567 | atom_program->setUniformValue("normalMatrix", nm); |
| 5568 | atom_program->setUniformValue("lightPos", QVector3D(-100.0, 100.0, 800.0)); |
| 5569 | atom_program->setUniformValue("pmax", static_cast<GLfloat>(mol->pmax)); |
| 5570 | atom_program->setUniformValue("pmin", static_cast<GLfloat>(mol->pmin)); |
| 5571 | atom_program->setUniformValue("lmax", static_cast<GLfloat>(mol->lmax)); |
| 5572 | atom_program->setUniformValue("lmin", static_cast<GLfloat>(mol->lmin)); |
| 5573 | atom_program->setUniformValue("qcutoff", qcutoff); |
| 5574 | atom_program->setUniformValue("fiftypct", fiftypct); |
| 5575 | atom_program->setUniformValue("LOD", mol->LOD); |
| 5576 | atom_program->setUniformValue("eye", eye); |
| 5577 | atom_program->setUniformValue("adp", adp->isChecked()); |
| 5578 | atom_program->setUniformValue("bede", hideBeLo->isChecked()); |
| 5579 | atom_program->setUniformValue("hidePM1", shpm1->isChecked()); |
| 5580 | atom_program->setUniformValue("QPeakLegend", QPeakLegend->isChecked()); |
| 5581 | atom_program->setUniformValue("Qolor", mol->mQolor); |
| 5582 | atom_program->setUniformValue("highlightParts", highlightParts->isChecked()); |
| 5583 | atom_program->setUniformValue("highlightEquivalents", mol->highlightEquivalents); |
| 5584 | atom_program->setUniformValue("hideHydrogen", !hideHydrogen->isVisible()); |
| 5585 | atom_program->setUniformValue("bondradius", static_cast<float>(mol->bondStrength)); |
| 5586 | atom_program->setUniformValue("tubes", tubes->isChecked()); |
| 5587 | atom_program->setUniformValue("ballStick", ballStick->isChecked()); |
| 5588 | atom_program->setUniformValue("qpeakrad", static_cast<GLfloat>(mol->qPeakRad*2)); |
| 5589 | glDrawElements(GL_TRIANGLES, atom_index_size, GL_UNSIGNED_INT, nullptr); |
| 5590 | atom_program->release(); |
| 5591 | atom_vao.release(); |
| 5592 | |
| 5593 | err = GL_NO_ERROR; |
| 5594 | while((err = glGetError()) != GL_NO_ERROR) |
| 5595 | { |
| 5596 | printf("atom_program_released %s error %X %d\n", parent()->objectName().toStdString().c_str(),err, __LINE__); |
| 5597 | //printf("%s\n",(char*)gluErrorString(err)); |
| 5598 | } |
| 5599 | } |
| 5600 | if ((drawBonds)&&(bond_program)){ |
| 5601 | |
| 5602 | //if (parent()->objectName()!="The Main Window") printf("paintGL -> %d\n",__LINE__); |
| 5603 | if ( !bond_program->bind() ){ qWarning() << "2Could not bind shader program to context"; return;} |
| 5604 | bond_vao.bind(); |
| 5605 | glEnable(GL_DEPTH_TEST ); |
| 5606 | glEnable(GL_BLEND); |
| 5607 | glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; |
| 5608 | bond_program->setUniformValue("pmv", pmv); |
| 5609 | bond_program->setUniformValue("origin", org); |
| 5610 | bond_program->setUniformValue("normalMatrix",nm); |
| 5611 | bond_program->setUniformValue("radius", static_cast<float>(mol->bondStrength)); |
| 5612 | bond_program->setUniformValue("qradius", 0.1f*static_cast<float>(mol->q_bondWidth)); |
| 5613 | bond_program->setUniformValue("segments", qMin(mol->LOD,8)); |
| 5614 | bond_program->setUniformValue("hideHydrogen", !hideHydrogen->isVisible()); |
| 5615 | bond_program->setUniformValue("qPeakBonds",qPeakBonds->isChecked()); |
| 5616 | bond_program->setUniformValue("qcutoff", qcutoff); |
| 5617 | bond_program->setUniformValue("h_bonds", (h_bonds->isChecked())); |
| 5618 | bond_program->setUniformValue("highlightEquivalents", mol->highlightEquivalents); |
| 5619 | //printf("h_bonds %d\n",h_bonds->isChecked()); |
| 5620 | bond_program->setUniformValue("highlightParts", highlightParts->isChecked()); |
| 5621 | bond_program->setUniformValue("tubes", tubes->isChecked()); |
| 5622 | bond_program->setUniformValue("hidePM1", shpm1->isChecked()); |
| 5623 | bond_program->setUniformValue("ballStick", ballStick->isChecked()); |
| 5624 | bond_program->setUniformValue("uniColorBonds",(mol->bondColorStyle!=0)); |
| 5625 | bond_program->setUniformValue("uniColor",mol->bondColor); |
| 5626 | glDrawElements(GL_LINES, nbondx2, GL_UNSIGNED_INT, nullptr); |
| 5627 | bond_program->release(); |
| 5628 | bond_vao.release(); |
| 5629 | } |
| 5630 | //if (parent()->objectName()!="The Main Window") printf("paintGL -> %d\n",__LINE__); |
| 5631 | if (((mol->splitLbonds.size()+mol->splitRbonds.size())>0)&&(splitrot_program)){ |
| 5632 | if ( !splitrot_program->bind() ){ qWarning() << "2Could not bind shader program to context"; return;} |
| 5633 | splitrot_vao.bind(); |
| 5634 | glEnable(GL_DEPTH_TEST ); |
| 5635 | //glEnable(GL_BLEND); |
| 5636 | //printf("splitrot_program %d\n",mol->splitLbonds.size()+mol->splitRbonds.size()); |
| 5637 | //glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; |
| 5638 | splitrot_program->setUniformValue("pmv", pmv); |
| 5639 | splitrot_program->setUniformValue("origin", org); |
| 5640 | splitrot_program->setUniformValue("normalMatrix",nm); |
| 5641 | splitrot_program->setUniformValue("radius", static_cast<float>(mol->bondStrength*1.5f)); |
| 5642 | splitrot_program->setUniformValue("dirx", QVector3D(screenRotx.x,screenRotx.y,screenRotx.z)); |
| 5643 | splitrot_program->setUniformValue("diry", QVector3D(screenRoty.x,screenRoty.y,screenRoty.z)); |
| 5644 | splitrot_program->setUniformValue("SRorg", QVector3D(SRorg.x,SRorg.y,SRorg.z)); |
| 5645 | //printf("X>%f %f %f Y>%f %f %f\n", screenRotx.x, screenRotx.y, screenRotx.z, screenRoty.x, screenRoty.y, screenRoty.z); |
| 5646 | glDrawElements(GL_LINES, (mol->splitLbonds.size() + mol->splitRbonds.size())*2, GL_UNSIGNED_INT, nullptr); |
| 5647 | splitrot_program->release(); |
| 5648 | splitrot_vao.release(); |
| 5649 | } |
| 5650 | //if (parent()->objectName()!="The Main Window") |
| 5651 | //printf("paintGL -> %d %d %d %d\n",__LINE__,drawLabels,mol->showatoms.size(),screenAtoms.size()); |
| 5652 | if ((drawLabels)&&(mol->showatoms.size()<=screenAtoms.size())){ |
| 5653 | for (int i = 0; i < mol->showatoms.size(); i++){ |
| 5654 | if (mol->showatoms.at(i).hidden) continue; |
| 5655 | if ((mol->showatoms.at(i).an>=0)&&((mol->AtomStyle[mol->showatoms.at(i).an]&ATOM_STYLE_NOLABEL)!=0)) continue; |
| 5656 | if ((mol->showatoms.at(i).an==0)&&(!hideHydrogen->isVisible())) continue; |
| 5657 | if ((mol->showatoms.at(i).an==-42)&&(!hideBeLo->isChecked())) continue; |
| 5658 | if ((mol->showatoms.at(i).an==-1)&&(mol->showatoms.at(i).peakHeight<qcutoff)) continue; |
| 5659 | if (i<altLabels.size()){ |
| 5660 | renderText(screenAtoms.at(i),i); |
| 5661 | } |
| 5662 | } |
| 5663 | } |
| 5664 | if ((cont_program)&&(cont_vao.isCreated())&&(!cont.isEmpty())){ |
| 5665 | cont_vao.bind(); |
| 5666 | cont_program->bind(); |
| 5667 | glDisable( GL_DEPTH_TEST ); |
| 5668 | glEnable(GL_BLEND); |
| 5669 | glLineWidth(1.0); |
| 5670 | glEnable(GL_LINE_SMOOTH); |
| 5671 | //glDisable(GL_LIGHTING); |
| 5672 | cont_program->setUniformValue("pmv", pmv); |
| 5673 | cont_program->setUniformValue("origin", org); |
| 5674 | cont_program->setUniformValue("rainbow", rainbowPlot->isChecked()); |
| 5675 | cont_program->setUniformValue("contMax", static_cast<float>(contMax)); |
| 5676 | cont_program->setUniformValue("contMin", static_cast<float>(contMin)); |
| 5677 | glDrawArrays(GL_LINES,0,cont.size()); |
| 5678 | cont_program->release(); |
| 5679 | cont_vao.release(); |
| 5680 | } |
| 5681 | //if (parent()->objectName()!="The Main Window") printf("paintGL -> %d\n",__LINE__); |
| 5682 | ///maps? |
| 5683 | /// |
| 5684 | if ((map_program)&&((!fVertexes[0].isEmpty()||!fVertexes[1].isEmpty()))) {//(!habzutun)&& |
| 5685 | double max; |
| 5686 | int Pers=0; |
| 5687 | bool neutrons=false; |
| 5688 | map_vao.bind(); |
| 5689 | map_program->bind(); |
| 5690 | glEnable(GL_DEPTH_TEST ); |
| 5691 | glEnable(GL_BLEND); |
| 5692 | glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; |
| 5693 | glDisable(GL_CULL_FACE); |
| 5694 | err = GL_NO_ERROR; |
| 5695 | while((err = glGetError()) != GL_NO_ERROR) |
| 5696 | { |
| 5697 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 5698 | //printf("%s\n",(char*)gluErrorString(err)); |
| 5699 | } |
| 5700 | glLineWidth(linwidth); |
| 5701 | if (niceTrans->isChecked()){ |
| 5702 | QMatrix4x4 mm(mvmat); |
| 5703 | max= (fabs(mm(2,0))>fabs(mm(2,1)))?mm(2,0):mm(2,1); |
| 5704 | max=(fabs(max)<fabs(mm(2,2)))?mm(2,2):max; |
| 5705 | if ((max==mm(2,0))&&(max>0.0)) Pers=0; else |
| 5706 | if ((max==mm(2,0))&&(max<0.0)) Pers=1; else |
| 5707 | if ((max==mm(2,1))&&(max>0.0)) Pers=2; else |
| 5708 | if ((max==mm(2,1))&&(max<0.0)) Pers=3; else |
| 5709 | if ((max==mm(2,2))&&(max>0.0)) Pers=4; else |
| 5710 | if ((max==mm(2,2))&&(max<0.0)) Pers=5; |
| 5711 | }else Pers=0; |
| 5712 | if (fillMap->isChecked()) glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); |
| 5713 | else glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); |
| 5714 | map_program->setUniformValue("lightPos", QVector3D(100.0, 100.0, 100.0)); |
| 5715 | map_program->setUniformValue("pmv", pmv); |
| 5716 | map_program->setUniformValue("origin", org); |
| 5717 | err = GL_NO_ERROR; |
| 5718 | while((err = glGetError()) != GL_NO_ERROR) |
| 5719 | { |
| 5720 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 5721 | //printf("%s\n",(char*)gluErrorString(err)); |
| 5722 | } |
| 5723 | map_program->setUniformValue("normalMatrix",nm); |
| 5724 | map_program->setUniformValue("lintrans",static_cast<GLfloat>(lintrans)); |
| 5725 | map_program->setUniformValue("lighting",lighting->isChecked()); |
| 5726 | if (fofcact->isChecked()) { |
| 5727 | map_program->setUniformValue("Color", dipc); |
| 5728 | glDrawArrays(GL_TRIANGLES, offsets.at(0+4*Pers)/12, fVertexes[0+4*Pers].size()/3); |
| 5729 | map_program->setUniformValue("Color", dimc); |
| 5730 | glDrawArrays(GL_TRIANGLES, offsets.at(1+4*Pers)/12 , fVertexes[1+4*Pers].size()/3); |
| 5731 | } |
| 5732 | if (foact->isChecked()) { |
| 5733 | map_program->setUniformValue("Color", fopc); |
| 5734 | glDrawArrays(GL_TRIANGLES, offsets.at(2+4*Pers)/12, fVertexes[2+4*Pers].size()/3); |
| 5735 | if (neutrons){ |
| 5736 | map_program->setUniformValue("Color", fomc); |
| 5737 | glDrawArrays(GL_TRIANGLES, offsets.at(3+4*Pers)/12, fVertexes[3+4*Pers].size()/3); |
| 5738 | } |
| 5739 | } |
| 5740 | //glEnable(GL_LIGHTING); |
| 5741 | glDisable(GL_BLEND); |
| 5742 | glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); |
| 5743 | map_program->release(); |
| 5744 | map_vao.release(); |
| 5745 | } |
| 5746 | ///maps! |
| 5747 | err = GL_NO_ERROR; |
| 5748 | while((err = glGetError()) != GL_NO_ERROR) |
| 5749 | { |
| 5750 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 5751 | //printf("%s\n",(char*)gluErrorString(err)); |
| 5752 | } |
| 5753 | if (((!mol->selectedatoms.isEmpty())||(!mol->duplicateAtoms.isEmpty())||(inFocus!=-1))&&(satom_program)){ |
| 5754 | if (!satom_program->bind() ){qWarning() << "Could not bind shader program to context"; return;} |
| 5755 | slct_vao.bind(); |
| 5756 | glDisable(GL_DEPTH_TEST); |
| 5757 | glDisable(GL_BLEND); |
| 5758 | //printf("org %f %f %f \n",org.x(),org.y(),org.z()); |
| 5759 | satom_program->setUniformValue("pmv", pmv); |
| 5760 | satom_program->setUniformValue("origin", org); |
| 5761 | satom_program->setUniformValue("fcoord", org); |
| 5762 | satom_program->setUniformValue("normalMatrix",nm); |
| 5763 | satom_program->setUniformValue("selrad", |
| 5764 | ((mol->splitLbonds.size()+mol->splitRbonds.size())>0)?0.2f:0.35f); |
| 5765 | if (!mol->selectedatoms.isEmpty()) { |
| 5766 | satom_program->setUniformValue("Color", QColor(Qt::yellow)); |
| 5767 | satom_program->setUniformValue("inFocus", -1); |
| 5768 | glDrawArrays( GL_POINTS, 0, mol->selectedatoms.size()); |
| 5769 | } |
| 5770 | if (!mol->duplicateAtoms.isEmpty()) { |
| 5771 | satom_program->setUniformValue("Color", QColor("#cd33ff")); |
| 5772 | satom_program->setUniformValue("inFocus", -2); |
| 5773 | glDrawArrays( GL_POINTS, mol->selectedatoms.size(), mol->duplicateAtoms.size()); |
| 5774 | } |
| 5775 | if ((inFocus!=-1)&&(inFocus<mol->showatoms.size())) { |
| 5776 | satom_program->setUniformValue("fcoord", QVector3D(mol->showatoms.at(inFocus).pos.x, mol->showatoms.at(inFocus).pos.y, mol->showatoms.at(inFocus).pos.z)); |
| 5777 | satom_program->setUniformValue("origin", org); |
| 5778 | satom_program->setUniformValue("Color", QColor("#66cdff")); |
| 5779 | satom_program->setUniformValue("inFocus", inFocus); |
| 5780 | glDrawArrays( GL_POINTS, 0, 1); |
| 5781 | } |
| 5782 | satom_program->release(); |
| 5783 | slct_vao.release(); |
| 5784 | } |
| 5785 | err = GL_NO_ERROR; |
| 5786 | while((err = glGetError()) != GL_NO_ERROR) |
| 5787 | { |
| 5788 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 5789 | //printf("%s\n",(char*)gluErrorString(err)); |
| 5790 | } |
| 5791 | |
| 5792 | if ((!enviPositions.isEmpty())&&(envi_program)&&(envi_vao.isCreated())){//printf("-ronment\n"); |
| 5793 | glDisable( GL_DEPTH_TEST ); |
| 5794 | glEnable(GL_BLEND); |
| 5795 | glLineWidth(1.0); |
| 5796 | glEnable(GL_LINE_SMOOTH); |
| 5797 | //glDisable(GL_LIGHTING); |
| 5798 | envi_vao.bind(); |
| 5799 | envi_program->bind(); |
| 5800 | envi_program->setUniformValue("pmv", pmv); |
| 5801 | envi_program->setUniformValue("origin", org); |
| 5802 | envi_program->setUniformValue("enviBondColor", mol->enviBondColor); |
| 5803 | envi_program->setUniformValue("enviHBColor", mol->enviHBColor); |
| 5804 | envi_program->setUniformValue("enviDefaultColor", mol->enviDefaultColor); |
| 5805 | glDrawArrays(GL_LINES, 0, enviPositions.size()*2); |
| 5806 | //glEnable(GL_LIGHTING); |
| 5807 | glEnable( GL_DEPTH_TEST ); |
| 5808 | envi_program->release(); |
| 5809 | envi_vao.release(); |
| 5810 | for (int j=0; j < enviPositions.size(); j++ ){ |
| 5811 | QColor c = mol->enviDefaultColor; |
| 5812 | switch(enviKat.at(j)){ |
| 5813 | case 1: c = mol->enviBondColor; break; |
| 5814 | case 2: c = mol->enviHBColor; break; |
| 5815 | default: |
| 5816 | c = mol->enviDefaultColor; |
| 5817 | } |
| 5818 | renderText(enviPositions.at(j)-org3, labs.at(j), c, 0xffd3d3d3); |
| 5819 | V3 p=(enviPositions.at(j)+enviP0)*0.5-org3; |
| 5820 | renderText(p, QString::number(sqrt(Distance(enviP0,enviPositions.at(j))),'f',3), c, 0); |
| 5821 | } |
| 5822 | } |
| 5823 | //if (parent()->objectName()!="The Main Window") printf("paintGL -> %d\n",__LINE__); |
| 5824 | if ((uc_program)&&(togUnit->isChecked())&&(uc_vao.isCreated())){//printf("leg end\n"); |
| 5825 | if ( !uc_program->bind() ){ qWarning() << "Could not bind shader program to context"; return;} |
| 5826 | uc_vao.bind(); |
| 5827 | glDisable(GL_DEPTH_TEST ); |
| 5828 | glEnable(GL_BLEND); |
| 5829 | glLineWidth(1.0); |
| 5830 | glEnable(GL_LINE_SMOOTH); |
| 5831 | //glDisable(GL_LIGHTING); |
| 5832 | uc_program->setUniformValue("pmv", pmv); |
| 5833 | uc_program->setUniformValue("origin", org); |
| 5834 | uc_program->setUniformValue("cholesky", mol->cell.Cholesky); |
| 5835 | glDrawArrays(GL_POINTS, 0, 1); |
| 5836 | uc_program->release(); |
| 5837 | uc_vao.release(); |
| 5838 | if (drawLabels){ |
| 5839 | V3 aa(1,0,0); |
| 5840 | V3 bb(0,1,0); |
| 5841 | V3 cc(0,0,1); |
| 5842 | QColor c=Qt::red; |
| 5843 | mol->frac2kart(aa,aa); |
| 5844 | mol->frac2kart(bb,bb); |
| 5845 | mol->frac2kart(cc,cc); |
| 5846 | renderText(aa-org3, "a", c, 0u); |
| 5847 | c=Qt::green; |
| 5848 | renderText(bb-org3, "b", c, 0u); |
| 5849 | c=Qt::blue; |
| 5850 | renderText(cc-org3, "c", c, 0u); |
| 5851 | c=Qt::black; |
| 5852 | renderText(V3(0,0,0)-org3, "0", c, 0u); |
| 5853 | } |
| 5854 | } |
| 5855 | //if (parent()->objectName()!="The Main Window") printf("paintGL -> %d\n",__LINE__); |
| 5856 | err = GL_NO_ERROR; |
| 5857 | while((err = glGetError()) != GL_NO_ERROR) |
| 5858 | { |
| 5859 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 5860 | //printf("%s\n",(char*)gluErrorString(err)); |
| 5861 | } |
| 5862 | |
| 5863 | if ((atom_program)&&(atomLegend->isChecked())&&(latom_vao.isCreated())){//printf("leg end\n"); |
| 5864 | if ( !atom_program->bind() ){ qWarning() << "Could not bind shader program to context"; return;} |
| 5865 | latom_vao.bind(); |
| 5866 | double fktr = retinafktr * legend_sc; |
| 5867 | glViewport(0, 0, 415 * fktr, qMax(950 * fktr, 1.0)); |
| 5868 | QMatrix4x4 tm,tn; |
| 5869 | tm.setToIdentity(); |
| 5870 | tn.setToIdentity(); |
| 5871 | //tm.ortho(-3.075, 1.075, -7.1, 2.4 ,-10,10); |
| 5872 | tm.ortho(-3.075, 1.075, -7.1, 2.4 ,-10,10); |
| 5873 | glEnable(GL_DEPTH_TEST ); |
| 5874 | glEnable(GL_BLEND); |
| 5875 | glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; |
| 5876 | float fiftypct =1.54; |
| 5877 | switch (mol->proba ) { |
| 5878 | case 10 :{ fiftypct = 0.76; break;} //Hauptachsen der Eliipsoide 10% Wahrscheinlichkeit |
| 5879 | case 30 :{ fiftypct = 1.19; break;} //Hauptachsen der Eliipsoide 30% Wahrscheinlichkeit |
| 5880 | case 50 :{ fiftypct = 1.54; break;} //Hauptachsen der Eliipsoide 50% Wahrscheinlichkeit |
| 5881 | case 70 :{ fiftypct = 1.91; break;} //Hauptachsen der Eliipsoide 70% Wahrscheinlichkeit |
| 5882 | case 90 :{ fiftypct = 2.50; break;} //Hauptachsen der Eliipsoide 90% Wahrscheinlichkeit |
| 5883 | default: ; |
| 5884 | } |
| 5885 | atom_program->setUniformValue("normalMatrix", tn.normalMatrix()); |
| 5886 | atom_program->setUniformValue("pmv", tm); |
| 5887 | atom_program->setUniformValue("origin", QVector3D(0.000000, 0.000000, 0.00000));//QVector3D(-2.750000, -6.800000, 0.00000) |
| 5888 | atom_program->setUniformValue("pmax", static_cast<GLfloat>(mol->pmax)); |
| 5889 | atom_program->setUniformValue("pmin", static_cast<GLfloat>(mol->pmin)); |
| 5890 | atom_program->setUniformValue("lightPos", QVector3D(-100,100,800)); |
| 5891 | atom_program->setUniformValue("lmax", static_cast<GLfloat>(mol->lmax)); |
| 5892 | atom_program->setUniformValue("lmin", static_cast<GLfloat>(mol->lmin)); |
| 5893 | atom_program->setUniformValue("qcutoff", qcutoff); |
| 5894 | atom_program->setUniformValue("fiftypct", fiftypct); |
| 5895 | atom_program->setUniformValue("LOD", mol->LOD); |
| 5896 | atom_program->setUniformValue("eye", QVector4D(0.000000, 31.475019, 7.868755, 1.000000)); |
| 5897 | atom_program->setUniformValue("adp", adp->isChecked()); |
| 5898 | atom_program->setUniformValue("bede", hideBeLo->isChecked()); |
| 5899 | atom_program->setUniformValue("shpm1", shpm1->isChecked()); |
| 5900 | atom_program->setUniformValue("QPeakLegend", QPeakLegend->isChecked()); |
| 5901 | atom_program->setUniformValue("Qolor", mol->mQolor); |
| 5902 | atom_program->setUniformValue("highlightParts", highlightParts->isChecked()); |
| 5903 | atom_program->setUniformValue("hideHydrogen", !hideHydrogen->isVisible()); |
| 5904 | atom_program->setUniformValue("bondradius", static_cast<float>(mol->bondStrength)); |
| 5905 | atom_program->setUniformValue("tubes", tubes->isChecked()); |
| 5906 | atom_program->setUniformValue("ballStick", ballStick->isChecked()); |
| 5907 | atom_program->setUniformValue("qpeakrad", static_cast<GLfloat>(mol->qPeakRad*2)); |
| 5908 | glDrawElements(GL_TRIANGLES, latom_index_size, GL_UNSIGNED_INT, nullptr); |
| 5909 | atom_program->release(); |
| 5910 | latom_vao.release(); |
| 5911 | //tm.scale(1.1); |
| 5912 | for (int i=0; i<mol->legendAtoms.size(); i++){ |
| 5913 | //renderText(tm, 415, height()-10 ,mol->legendAtoms.at(i).pos, mol->legendAtoms.at(i).Label, labelColor,0xffff0000); |
| 5914 | if (mol->legendAtoms.at(i).hidden) continue; |
| 5915 | if ((mol->legendAtoms.at(i).an==0)&&!hideHydrogen->isVisible()) continue; |
| 5916 | renderText(QVector2D( |
| 5917 | 330*legend_sc + mol->legendAtoms.at(i).pos.x * 100 * legend_sc, |
| 5918 | -15*legend_sc + height() - (mol->legendAtoms.at(i).pos.y + 6.7) * 104 * legend_sc), |
| 5919 | mol->legendAtoms.at(i).Label, mol->legendAtoms.at(i).an, 24 * legend_sc); |
| 5920 | } |
| 5921 | glViewport(0, 0, width()*retinafktr, qMax(height()*retinafktr, 1.0)); |
| 5922 | } |
| 5923 | //if (parent()->objectName()!="The Main Window") printf("paintGL -> %d\n",__LINE__); |
| 5924 | |
| 5925 | if ((symm_program0)&&(symm_program1)&&(symm_program2)&&((axend>0)||(invend>0)||(planend>0)||(glend>0))){ |
| 5926 | //printf("symm ->%d \n",axend); |
| 5927 | glEnable(GL_BLEND); |
| 5928 | glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; |
| 5929 | glEnable(GL_DEPTH_TEST ); |
| 5930 | glDisable(GL_CULL_FACE); |
| 5931 | |
| 5932 | //glDisable(GL_DEPTH_TEST ); |
| 5933 | glEnable(GL_BLEND); |
| 5934 | glLineWidth(1.0); |
| 5935 | glEnable(GL_LINE_SMOOTH); |
| 5936 | //glEnable(GL_LIGHTING); |
| 5937 | GLfloat scv[18*4]; |
| 5938 | for (int i=0;i<18;i++) { |
| 5939 | scv[4*i]=mol->symmColors.at(i).redF(); |
| 5940 | scv[4*i+1]=mol->symmColors.at(i).greenF(); |
| 5941 | scv[4*i+2]=mol->symmColors.at(i).blueF(); |
| 5942 | scv[4*i+3]=mol->symmColors.at(i).alphaF(); |
| 5943 | } |
| 5944 | if ((symm_vao0.isCreated())&&axend){ |
| 5945 | symm_vao0.bind(); |
| 5946 | if ( !symm_program0->bind() ){ qWarning() << "Could not bind shader program to context"; return;} |
| 5947 | symm_program0->setUniformValueArray("Color",scv,18,4);//we have to this for color changes too |
| 5948 | symm_program0->setUniformValue("pmv", pmv); |
| 5949 | symm_program0->setUniformValue("origin", org); |
| 5950 | symm_program0->setUniformValue("normalMatrix", nm); |
| 5951 | symm_program0->setUniformValueArray("dontshowSymElement",mol->dontshowSel.toVector().data(),mol->dontshowSel.count()); |
| 5952 | symm_program0->setUniformValueArray("dontshowSymOperation",mol->dontshowSop.toVector().data(),mol->dontshowSop.count()); |
| 5953 | symm_program0->setUniformValue("dssesize", static_cast<int>(mol->dontshowSel.count())); |
| 5954 | symm_program0->setUniformValue("dssosize", static_cast<int>(mol->dontshowSop.count())); |
| 5955 | symm_program0->setUniformValue("axisThickness",axisThickness); |
| 5956 | glDrawArrays( GL_LINES, 0, axend/3); |
| 5957 | symm_program0->release(); |
| 5958 | symm_vao0.release(); |
| 5959 | } |
| 5960 | if ((symm_vao1.isCreated())&&invend){ |
| 5961 | symm_vao1.bind(); |
| 5962 | //printf("inv %d centers %d\n",invend,invend/5); |
| 5963 | if ( !symm_program1->bind() ){ qWarning() << "Could not bind shader program to context"; return;} |
| 5964 | symm_program1->setUniformValueArray("Color",scv,18,4); |
| 5965 | symm_program1->setUniformValue("pmv", pmv); |
| 5966 | symm_program1->setUniformValue("origin", org); |
| 5967 | symm_program1->setUniformValue("normalMatrix", nm); |
| 5968 | symm_program1->setUniformValueArray("dontshowSymElement",mol->dontshowSel.toVector().data(),mol->dontshowSel.count()); |
| 5969 | symm_program1->setUniformValueArray("dontshowSymOperation",mol->dontshowSop.toVector().data(),mol->dontshowSop.count()); |
| 5970 | symm_program1->setUniformValue("dssesize", static_cast<int>(mol->dontshowSel.count())); |
| 5971 | symm_program1->setUniformValue("dssosize", static_cast<int>(mol->dontshowSop.count()));; |
| 5972 | symm_program1->setUniformValue("InversionCenterRadius", InversionCenterRadius); |
| 5973 | glDrawArrays( GL_POINTS, 0, invend/5); |
| 5974 | symm_program1->release(); |
| 5975 | symm_vao1.release(); |
| 5976 | } |
| 5977 | if ((symm_vao2.isCreated())&&glend){ |
| 5978 | symm_vao2.bind(); |
| 5979 | glDisable(GL_DEPTH_TEST ); |
| 5980 | //printf("gl %d centers %d\n",glend,planend); |
| 5981 | if ( !symm_program2->bind() ){ qWarning() << "Could not bind shader program to context"; return;} |
| 5982 | symm_program2->setUniformValueArray("Color",scv,18,4); |
| 5983 | symm_program2->setUniformValue("pmv", pmv); |
| 5984 | symm_program2->setUniformValue("origin", org); |
| 5985 | symm_program2->setUniformValue("normalMatrix", nm); |
| 5986 | symm_program2->setUniformValueArray("dontshowSymElement",mol->dontshowSel.toVector().data(),mol->dontshowSel.count()); |
| 5987 | symm_program2->setUniformValueArray("dontshowSymOperation",mol->dontshowSop.toVector().data(),mol->dontshowSop.count()); |
| 5988 | symm_program2->setUniformValue("dssesize", static_cast<int>(mol->dontshowSel.count())); |
| 5989 | symm_program2->setUniformValue("dssosize", static_cast<int>(mol->dontshowSop.count()));; |
| 5990 | symm_program2->setUniformValue("planeTransparence", planeTransparence); |
| 5991 | symm_program2->setUniformValue("glideVectorThickness", glideVectorThickness); |
| 5992 | symm_program2->setUniformValue("planeFrameThinkness", planeFrameThinkness); |
| 5993 | |
| 5994 | glDrawArrays( GL_POINTS, 0, glend/17); |
| 5995 | symm_program2->release(); |
| 5996 | symm_vao2.release(); |
| 5997 | } |
| 5998 | } |
| 5999 | // if (parent()->objectName()!="The Main Window") printf("paintGL -> %d valid %d widget %d\n",__LINE__,context()->isValid(),context()->isWidgetType()); |
| 6000 | |
| 6001 | if ((voro_vao.isCreated())&&(voro_program)){ |
| 6002 | if ( !voro_program->bind() ){ qWarning() << "Could not bind shader program to context"; return;} |
| 6003 | voro_vao.bind(); |
| 6004 | glEnable(GL_BLEND); |
| 6005 | glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; |
| 6006 | glEnable(GL_DEPTH_TEST ); |
| 6007 | glDisable(GL_CULL_FACE); |
| 6008 | glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); |
| 6009 | voro_program->setUniformValue("pmv", pmv); |
| 6010 | voro_program->setUniformValue("origin", org); |
| 6011 | voro_program->setUniformValue("normalMatrix", nm); |
| 6012 | glDrawArrays( GL_POINTS, 0, vtriangles.size()); |
| 6013 | voro_program->release(); |
| 6014 | voro_vao.release(); |
| 6015 | } |
| 6016 | |
| 6017 | if ((!mol->selectedatoms.isEmpty())&&(mol->splitLbonds.isEmpty())){ |
| 6018 | for (int i=0; i<mol->selectedatoms.size(); i++){ |
| 6019 | if (mol->selectedatoms.at(i).hidden) continue; |
| 6020 | QColor c = selectedLabelColor ; |
| 6021 | QString label = mol->selectedatoms.at(i).Label; |
| 6022 | if (shortLabels->isChecked()) { |
| 6023 | label=label.section("_",0,0); |
| 6024 | label=label.section(QString::fromUtf8("»"),0,0); |
| 6025 | } |
| 6026 | renderText(mol->selectedatoms.at(i).pos-org3, label, c, selectedLabelBGColor.rgba()); |
| 6027 | } |
| 6028 | } |
| 6029 | err = GL_NO_ERROR; |
| 6030 | while((err = glGetError()) != GL_NO_ERROR) |
| 6031 | { |
| 6032 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 6033 | //printf("%s\n",(char*)gluErrorString(err)); |
| 6034 | } |
| 6035 | if ((inFocus!=-1)&&(inFocus<mol->showatoms.size())){ |
| 6036 | QString label = mol->showatoms.at(inFocus).Label; |
| 6037 | if (shortLabels->isChecked()) { |
| 6038 | label=label.section("_",0,0); |
| 6039 | label=label.section(QString::fromUtf8("»"),0,0); |
| 6040 | } |
| 6041 | renderText(screenAtoms.at(inFocus), label, mol->showatoms.at(inFocus).an); |
| 6042 | } |
| 6043 | err = GL_NO_ERROR; |
| 6044 | while((err = glGetError()) != GL_NO_ERROR) |
| 6045 | { |
| 6046 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 6047 | //printf("%s\n",(char*)gluErrorString(err)); |
| 6048 | } |
| 6049 | if (parent()->objectName()=="Edit Atom Parameters Dialog"){ |
| 6050 | QString label = mol->showatoms.at(0).Label; |
| 6051 | if (shortLabels->isChecked()) { |
| 6052 | label=label.section("_",0,0); |
| 6053 | label=label.section(QString::fromUtf8("»"),0,0); |
| 6054 | } |
| 6055 | renderText(screenAtoms.at(0), label, mol->showatoms.at(0).an); |
| 6056 | label = mol->showatoms.at(1).Label; |
| 6057 | if (shortLabels->isChecked()) { |
| 6058 | label=label.section("_",0,0); |
| 6059 | label=label.section(QString::fromUtf8("»"),0,0); |
| 6060 | } |
| 6061 | renderText(screenAtoms.at(1), label, mol->showatoms.at(1).an); |
| 6062 | } |
| 6063 | err = GL_NO_ERROR; |
| 6064 | while((err = glGetError()) != GL_NO_ERROR) |
| 6065 | { |
| 6066 | printf("%s paintGL error %X %d\n", parent()->objectName().toStdString().c_str(), err, __LINE__); |
| 6067 | //printf("%s\n",(char*)gluErrorString(err)); |
| 6068 | } |
| 6069 | |
| 6070 | if (burnGPU) update(); |
| 6071 | |
| 6072 | //printf("paintGL <-\n"); |
| 6073 | } |