1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * GLWorldView.cpp
|
---|
10 | *
|
---|
11 | * Created on: Aug 1, 2010
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "GLWorldView.hpp"
|
---|
21 |
|
---|
22 | #include <Qt/qevent.h>
|
---|
23 | #include <Qt/qaction.h>
|
---|
24 | #include <QtGui/QToolBar>
|
---|
25 | #include <Qt/qtimer.h>
|
---|
26 | #include <Qt3D/qglbuilder.h>
|
---|
27 | #include <Qt3D/qglscenenode.h>
|
---|
28 | #include <Qt3D/qglsphere.h>
|
---|
29 | #include <Qt3D/qglcylinder.h>
|
---|
30 | #include <Qt3D/qglcube.h>
|
---|
31 |
|
---|
32 | #include "GLWorldScene.hpp"
|
---|
33 |
|
---|
34 | #include "CodePatterns/MemDebug.hpp"
|
---|
35 |
|
---|
36 | #include "Atom/AtomObserver.hpp"
|
---|
37 | #include "Atom/atom_observable.hpp"
|
---|
38 | #include "CodePatterns/Log.hpp"
|
---|
39 | #include "CodePatterns/Observer/Notification.hpp"
|
---|
40 | #include "World.hpp"
|
---|
41 | #include "Box.hpp"
|
---|
42 |
|
---|
43 | GLWorldView::GLWorldView(QWidget *parent)
|
---|
44 | : QGLView(parent), Observer("GLWorldView"), worldscene(NULL), changesPresent(false), needsRedraw(false)
|
---|
45 | {
|
---|
46 | worldscene = new GLWorldScene(this);
|
---|
47 |
|
---|
48 | setOption(QGLView::ObjectPicking, true);
|
---|
49 | setOption(QGLView::CameraNavigation, false);
|
---|
50 | setCameraControlMode(Rotate);
|
---|
51 |
|
---|
52 | createDomainBox();
|
---|
53 | createDreiBein();
|
---|
54 | //changeMaterials(false);
|
---|
55 |
|
---|
56 | connect(worldscene, SIGNAL(changeOccured()), this, SLOT(changeSignalled()));
|
---|
57 | connect(worldscene, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
58 | connect(this, SIGNAL(atomInserted(const atom *)), worldscene, SLOT(atomInserted(const atom *)));
|
---|
59 | connect(this, SIGNAL(atomRemoved(const atom *)), worldscene, SLOT(atomRemoved(const atom *)));
|
---|
60 | connect(this, SIGNAL(worldSelectionChanged()), worldscene, SLOT(worldSelectionChanged()));
|
---|
61 | connect(this, SIGNAL(moleculeRemoved(const molecule *)), worldscene, SLOT(moleculeRemoved(const molecule *)));
|
---|
62 | //connect(this, SIGNAL(changed()), this, SLOT(updateGL()));
|
---|
63 | connect(this, SIGNAL(changed()), this, SLOT(sceneChangeSignalled()));
|
---|
64 |
|
---|
65 | // sign on to changes in the world
|
---|
66 | World::getInstance().signOn(this);
|
---|
67 | World::getInstance().signOn(this, World::AtomInserted);
|
---|
68 | World::getInstance().signOn(this, World::AtomRemoved);
|
---|
69 | World::getInstance().signOn(this, World::MoleculeInserted);
|
---|
70 | World::getInstance().signOn(this, World::MoleculeRemoved);
|
---|
71 | World::getInstance().signOn(this, World::SelectionChanged);
|
---|
72 | AtomObserver::getInstance().signOn(this, AtomObservable::PositionChanged);
|
---|
73 |
|
---|
74 | redrawTimer = new QTimer(this);
|
---|
75 | }
|
---|
76 |
|
---|
77 | GLWorldView::~GLWorldView()
|
---|
78 | {
|
---|
79 | World::getInstance().signOff(this);
|
---|
80 | World::getInstance().signOff(this, World::AtomInserted);
|
---|
81 | World::getInstance().signOff(this, World::AtomRemoved);
|
---|
82 | World::getInstance().signOff(this, World::MoleculeInserted);
|
---|
83 | World::getInstance().signOff(this, World::MoleculeRemoved);
|
---|
84 | World::getInstance().signOff(this, World::SelectionChanged);
|
---|
85 | AtomObserver::getInstance().signOff(this, AtomObservable::PositionChanged);
|
---|
86 | delete worldscene;
|
---|
87 |
|
---|
88 | delete(domainBoxMaterial);
|
---|
89 | for (int i=0;i<3;i++)
|
---|
90 | delete(dreiBeinMaterial[i]);
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Add some widget specific actions to the toolbar:
|
---|
96 | * - camera rotation/translation mode
|
---|
97 | * - camera fit to domain
|
---|
98 | */
|
---|
99 | void GLWorldView::addToolBarActions(QToolBar *toolbar)
|
---|
100 | {
|
---|
101 | toolbar->addSeparator();
|
---|
102 | QAction *transAction = new QAction(QIcon::fromTheme("forward"), tr("camera translation mode"), this);
|
---|
103 | connect(transAction, SIGNAL(triggered()), this, SLOT(setCameraControlModeTranslation()));
|
---|
104 | toolbar->addAction(transAction);
|
---|
105 | QAction *rotAction = new QAction(QIcon::fromTheme("object-rotate-left"), tr("camera rotation mode"), this);
|
---|
106 | connect(rotAction, SIGNAL(triggered()), this, SLOT(setCameraControlModeRotation()));
|
---|
107 | toolbar->addAction(rotAction);
|
---|
108 | QAction *fitAction = new QAction(QIcon::fromTheme("zoom-best-fit"), tr("camera fit to domain"), this);
|
---|
109 | connect(fitAction, SIGNAL(triggered()), this, SLOT(fitCameraToDomain()));
|
---|
110 | toolbar->addAction(fitAction);
|
---|
111 | }
|
---|
112 |
|
---|
113 | void GLWorldView::createDomainBox()
|
---|
114 | {
|
---|
115 | domainBoxMaterial = new QGLMaterial;
|
---|
116 | domainBoxMaterial->setAmbientColor(QColor(0,0,0,255));
|
---|
117 | domainBoxMaterial->setDiffuseColor(QColor(0,0,0,255));
|
---|
118 | domainBoxMaterial->setEmittedLight(QColor(150,160,200,255));
|
---|
119 |
|
---|
120 |
|
---|
121 | QGLMaterial *material = new QGLMaterial;
|
---|
122 | material->setAmbientColor(QColor(50,60,100,255));
|
---|
123 | material->setDiffuseColor(QColor(150,160,200,180));
|
---|
124 |
|
---|
125 | QGLBuilder builder;
|
---|
126 | builder << QGL::Faceted;
|
---|
127 | builder << QGLCube(-1.0); // "inverted" => inside faces are used as front.
|
---|
128 | meshDomainBox = builder.finalizedSceneNode();
|
---|
129 | QMatrix4x4 mat;
|
---|
130 | mat.translate(0.5f, 0.5f, 0.5f);
|
---|
131 | meshDomainBox->setLocalTransform(mat);
|
---|
132 | meshDomainBox->setMaterial(material);
|
---|
133 | }
|
---|
134 |
|
---|
135 | void GLWorldView::createDreiBein()
|
---|
136 | {
|
---|
137 | // Create 3 color for the 3 axes.
|
---|
138 | dreiBeinMaterial[0] = new QGLMaterial;
|
---|
139 | dreiBeinMaterial[0]->setColor(QColor(255,50,50,255));
|
---|
140 | dreiBeinMaterial[1] = new QGLMaterial;
|
---|
141 | dreiBeinMaterial[1]->setColor(QColor(50,255,50,255));
|
---|
142 | dreiBeinMaterial[2] = new QGLMaterial;
|
---|
143 | dreiBeinMaterial[2]->setColor(QColor(50,50,255,255));
|
---|
144 |
|
---|
145 | // Create the basic meshes (cylinder and cone).
|
---|
146 | QGLBuilder builderCyl;
|
---|
147 | builderCyl << QGLCylinder(.15,.15,1.0,16);
|
---|
148 | QGLSceneNode *cyl = builderCyl.finalizedSceneNode();
|
---|
149 |
|
---|
150 | QGLBuilder builderCone;
|
---|
151 | builderCone << QGLCylinder(0,.4,0.4,16);
|
---|
152 | QGLSceneNode *cone = builderCone.finalizedSceneNode();
|
---|
153 | {
|
---|
154 | QMatrix4x4 mat;
|
---|
155 | mat.translate(0.0f, 0.0f, 1.0f);
|
---|
156 | cone->setLocalTransform(mat);
|
---|
157 | }
|
---|
158 |
|
---|
159 | // Create a scene node from the 3 axes.
|
---|
160 | meshDreiBein = new QGLSceneNode(this);
|
---|
161 |
|
---|
162 | // X-direction
|
---|
163 | QGLSceneNode *node = new QGLSceneNode(meshDreiBein);
|
---|
164 | node->setMaterial(dreiBeinMaterial[0]);
|
---|
165 | node->addNode(cyl);
|
---|
166 | node->addNode(cone);
|
---|
167 | {
|
---|
168 | QMatrix4x4 mat;
|
---|
169 | mat.rotate(90, 0.0f, 1.0f, 0.0f);
|
---|
170 | node->setLocalTransform(mat);
|
---|
171 | }
|
---|
172 |
|
---|
173 | // Y-direction
|
---|
174 | node = new QGLSceneNode(meshDreiBein);
|
---|
175 | node->setMaterial(dreiBeinMaterial[1]);
|
---|
176 | node->addNode(cyl);
|
---|
177 | node->addNode(cone);
|
---|
178 | {
|
---|
179 | QMatrix4x4 mat;
|
---|
180 | mat.rotate(-90, 1.0f, 0.0f, 0.0f);
|
---|
181 | node->setLocalTransform(mat);
|
---|
182 | }
|
---|
183 |
|
---|
184 | // Z-direction
|
---|
185 | node = new QGLSceneNode(meshDreiBein);
|
---|
186 | node->setMaterial(dreiBeinMaterial[2]);
|
---|
187 | node->addNode(cyl);
|
---|
188 | node->addNode(cone);
|
---|
189 | }
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Update operation which can be invoked by the observable (which should be the
|
---|
193 | * change tracker here).
|
---|
194 | */
|
---|
195 | void GLWorldView::update(Observable *publisher)
|
---|
196 | {
|
---|
197 | emit changed();
|
---|
198 | }
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * The observable can tell when it dies.
|
---|
202 | */
|
---|
203 | void GLWorldView::subjectKilled(Observable *publisher) {}
|
---|
204 |
|
---|
205 | /** Listen to specific changes to the world.
|
---|
206 | *
|
---|
207 | * @param publisher ref to observable.
|
---|
208 | * @param notification type of notification
|
---|
209 | */
|
---|
210 | void GLWorldView::recieveNotification(Observable *publisher, Notification_ptr notification)
|
---|
211 | {
|
---|
212 | if (static_cast<World *>(publisher) == World::getPointer()) {
|
---|
213 | switch (notification->getChannelNo()) {
|
---|
214 | case World::AtomInserted:
|
---|
215 | {
|
---|
216 | const atom *_atom = World::getInstance().lastChanged<atom>();
|
---|
217 | #ifdef LOG_OBSERVER
|
---|
218 | observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has been inserted.";
|
---|
219 | #endif
|
---|
220 | emit atomInserted(_atom);
|
---|
221 | break;
|
---|
222 | }
|
---|
223 | case World::AtomRemoved:
|
---|
224 | {
|
---|
225 | const atom *_atom = World::getInstance().lastChanged<atom>();
|
---|
226 | #ifdef LOG_OBSERVER
|
---|
227 | observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has been removed.";
|
---|
228 | #endif
|
---|
229 | emit atomRemoved(_atom);
|
---|
230 | break;
|
---|
231 | }
|
---|
232 | case World::SelectionChanged:
|
---|
233 | {
|
---|
234 | #ifdef LOG_OBSERVER
|
---|
235 | observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that selection has changed.";
|
---|
236 | #endif
|
---|
237 | emit worldSelectionChanged();
|
---|
238 | break;
|
---|
239 | }
|
---|
240 | case World::MoleculeInserted:
|
---|
241 | {
|
---|
242 | const molecule *_molecule = World::getInstance().lastChanged<molecule>();
|
---|
243 | #ifdef LOG_OBSERVER
|
---|
244 | observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that molecule "+toString(_molecule->getId())+" has been removed.";
|
---|
245 | #endif
|
---|
246 | emit moleculeInserted(_molecule);
|
---|
247 | break;
|
---|
248 | }
|
---|
249 | case World::MoleculeRemoved:
|
---|
250 | {
|
---|
251 | const molecule *_molecule = World::getInstance().lastChanged<molecule>();
|
---|
252 | #ifdef LOG_OBSERVER
|
---|
253 | observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that molecule "+toString(_molecule->getId())+" has been removed.";
|
---|
254 | #endif
|
---|
255 | emit moleculeRemoved(_molecule);
|
---|
256 | break;
|
---|
257 | }
|
---|
258 | default:
|
---|
259 | ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here.");
|
---|
260 | break;
|
---|
261 | }
|
---|
262 | } else if (dynamic_cast<AtomObservable *>(publisher) != NULL) {
|
---|
263 | switch (notification->getChannelNo()) {
|
---|
264 | case AtomObservable::PositionChanged:
|
---|
265 | {
|
---|
266 | const atom *_atom = dynamic_cast<const atom *>(publisher);
|
---|
267 | #ifdef LOG_OBSERVER
|
---|
268 | observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has changed its position.";
|
---|
269 | #endif
|
---|
270 | emit changed();
|
---|
271 | break;
|
---|
272 | }
|
---|
273 | default:
|
---|
274 | ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here.");
|
---|
275 | break;
|
---|
276 | }
|
---|
277 | } else
|
---|
278 | ASSERT(0, "GLWorldView::recieveNotification() - received notification from unknown source.");
|
---|
279 | }
|
---|
280 |
|
---|
281 | void GLWorldView::checkChanges()
|
---|
282 | {
|
---|
283 | updateGL();
|
---|
284 | needsRedraw = false;
|
---|
285 | }
|
---|
286 |
|
---|
287 | void GLWorldView::sceneChangeSignalled()
|
---|
288 | {
|
---|
289 | if (!needsRedraw){
|
---|
290 | redrawTimer->singleShot(0, this, SLOT(checkChanges()));
|
---|
291 | needsRedraw = true;
|
---|
292 | redrawTimer->start();
|
---|
293 | }
|
---|
294 | }
|
---|
295 |
|
---|
296 | void GLWorldView::initializeGL(QGLPainter *painter)
|
---|
297 | {
|
---|
298 | worldscene->initialize(this, painter);
|
---|
299 | changesPresent = false;
|
---|
300 | }
|
---|
301 |
|
---|
302 | void GLWorldView::paintGL(QGLPainter *painter)
|
---|
303 | {
|
---|
304 | if (changesPresent) {
|
---|
305 | initializeGL(painter);
|
---|
306 | changesPresent = false;
|
---|
307 | }
|
---|
308 | worldscene->draw(painter);
|
---|
309 |
|
---|
310 | drawDreiBein(painter);
|
---|
311 |
|
---|
312 | // Domain box has to be last because of its transparency.
|
---|
313 | drawDomainBox(painter);
|
---|
314 | }
|
---|
315 |
|
---|
316 | void GLWorldView::keyPressEvent(QKeyEvent *e)
|
---|
317 | {
|
---|
318 | if (e->key() == Qt::Key_Tab) {
|
---|
319 | // The Tab key turns the ShowPicking option on and off,
|
---|
320 | // which helps show what the pick buffer looks like.
|
---|
321 | setOption(QGLView::ShowPicking, ((options() & QGLView::ShowPicking) == 0));
|
---|
322 | updateGL();
|
---|
323 | }
|
---|
324 | QGLView::keyPressEvent(e);
|
---|
325 | }
|
---|
326 |
|
---|
327 | void GLWorldView::changeSignalled()
|
---|
328 | {
|
---|
329 | changesPresent = true;
|
---|
330 | }
|
---|
331 |
|
---|
332 |
|
---|
333 | /**
|
---|
334 | * Set the current camera control mode.
|
---|
335 | */
|
---|
336 | void GLWorldView::setCameraControlMode(GLWorldView::CameraControlModeType mode)
|
---|
337 | {
|
---|
338 | cameraControlMode = mode;
|
---|
339 | }
|
---|
340 |
|
---|
341 | void GLWorldView::setCameraControlModeRotation()
|
---|
342 | {
|
---|
343 | setCameraControlMode(Rotate);
|
---|
344 | }
|
---|
345 |
|
---|
346 | void GLWorldView::setCameraControlModeTranslation()
|
---|
347 | {
|
---|
348 | setCameraControlMode(Translate);
|
---|
349 | }
|
---|
350 |
|
---|
351 | /**
|
---|
352 | * Returns the current camera control mode.
|
---|
353 | * This needs to be invertable (rotation - translation), if the shift key is pressed.
|
---|
354 | */
|
---|
355 | GLWorldView::CameraControlModeType GLWorldView::getCameraControlMode(bool inverted)
|
---|
356 | {
|
---|
357 | if (inverted){
|
---|
358 | if (cameraControlMode == Rotate)
|
---|
359 | return Translate;
|
---|
360 | if (cameraControlMode == Translate)
|
---|
361 | return Rotate;
|
---|
362 | return Rotate;
|
---|
363 | }else
|
---|
364 | return cameraControlMode;
|
---|
365 | }
|
---|
366 |
|
---|
367 | /**
|
---|
368 | * Set the camera so it can oversee the whole domain.
|
---|
369 | */
|
---|
370 | void GLWorldView::fitCameraToDomain()
|
---|
371 | {
|
---|
372 | // Move the camera focus point to the center of the domain box.
|
---|
373 | Vector v = World::getInstance().getDomain().translateIn(Vector(0.5, 0.5, 0.5));
|
---|
374 | camera()->setCenter(QVector3D(v[0], v[1], v[2]));
|
---|
375 |
|
---|
376 | // Guess some eye distance.
|
---|
377 | double dist = v.Norm() * 3;
|
---|
378 | camera()->setEye(QVector3D(v[0], v[1], v[2] + dist));
|
---|
379 | camera()->setUpVector(QVector3D(0, 1, 0));
|
---|
380 | }
|
---|
381 |
|
---|
382 | void GLWorldView::mousePressEvent(QMouseEvent *event)
|
---|
383 | {
|
---|
384 | QGLView::mousePressEvent(event);
|
---|
385 |
|
---|
386 | // Reset the saved mouse position.
|
---|
387 | lastMousePos = event->posF();
|
---|
388 | }
|
---|
389 |
|
---|
390 | /**
|
---|
391 | * Handle a mouse move event.
|
---|
392 | * This is used to control the camera (rotation and translation) when the left button is being pressed.
|
---|
393 | */
|
---|
394 | void GLWorldView::mouseMoveEvent(QMouseEvent *event)
|
---|
395 | {
|
---|
396 | if (event->buttons() & Qt::LeftButton){
|
---|
397 | // Find the mouse distance since the last event.
|
---|
398 | QPointF d = event->posF() - lastMousePos;
|
---|
399 | lastMousePos = event->posF();
|
---|
400 |
|
---|
401 | // Rotate or translate? (inverted by shift key)
|
---|
402 | CameraControlModeType mode = getCameraControlMode(event->modifiers() & Qt::ShiftModifier);
|
---|
403 |
|
---|
404 | if (mode == Rotate){
|
---|
405 | // Rotate the camera.
|
---|
406 | d *= 0.3;
|
---|
407 | camera()->tiltPanRollCenter(- d.y(), - d.x(), 0);
|
---|
408 | }else if (mode == Translate){
|
---|
409 | // Translate the camera.
|
---|
410 | d *= 0.02;
|
---|
411 | camera()->translateCenter(- d.x(), d.y(), 0);
|
---|
412 | camera()->translateEye(- d.x(), d.y(), 0);
|
---|
413 | }
|
---|
414 | }else{
|
---|
415 | // Without this Qt would not test for hover events (i.e. mouse over an atom).
|
---|
416 | QGLView::mouseMoveEvent(event);
|
---|
417 | }
|
---|
418 | }
|
---|
419 |
|
---|
420 | /**
|
---|
421 | * When the mouse wheel is used, zoom in or out.
|
---|
422 | */
|
---|
423 | void GLWorldView::wheelEvent(QWheelEvent *event)
|
---|
424 | {
|
---|
425 | // Find the distance between the eye and focus point.
|
---|
426 | QVector3D d = camera()->eye() - camera()->center();
|
---|
427 |
|
---|
428 | // Scale the distance.
|
---|
429 | if (event->delta() < 0)
|
---|
430 | d *= 1.2;
|
---|
431 | else if (event->delta() > 0)
|
---|
432 | d /= 1.2;
|
---|
433 |
|
---|
434 | // Set new eye position.
|
---|
435 | camera()->setEye(camera()->center() + d);
|
---|
436 | }
|
---|
437 |
|
---|
438 | /**
|
---|
439 | * Draw a transparent cube representing the domain.
|
---|
440 | */
|
---|
441 | void GLWorldView::drawDomainBox(QGLPainter *painter) const
|
---|
442 | {
|
---|
443 | // Apply the domain matrix.
|
---|
444 | RealSpaceMatrix m = World::getInstance().getDomain().getM();
|
---|
445 | painter->modelViewMatrix().push();
|
---|
446 | painter->modelViewMatrix() *= QMatrix4x4(m.at(0,0), m.at(0,1), m.at(0,2), 0.0,
|
---|
447 | m.at(1,0), m.at(1,1), m.at(1,2), 0.0,
|
---|
448 | m.at(2,0), m.at(2,1), m.at(2,2), 0.0,
|
---|
449 | 0.0, 0.0, 0.0, 1.0);
|
---|
450 |
|
---|
451 | // Draw the transparent cube.
|
---|
452 | glCullFace(GL_BACK);
|
---|
453 | glEnable(GL_CULL_FACE);
|
---|
454 | glEnable(GL_BLEND);
|
---|
455 | glDepthMask(0);
|
---|
456 | //glDisable(GL_DEPTH_TEST);
|
---|
457 | meshDomainBox->draw(painter);
|
---|
458 | //glEnable(GL_DEPTH_TEST);
|
---|
459 | glDepthMask(1);
|
---|
460 | glDisable(GL_BLEND);
|
---|
461 | glDisable(GL_CULL_FACE);
|
---|
462 |
|
---|
463 | // Draw the outlines.
|
---|
464 | painter->setFaceMaterial(QGL::AllFaces, domainBoxMaterial);
|
---|
465 | //glEnable(GL_LINE_SMOOTH);
|
---|
466 | QVector3DArray array;
|
---|
467 | array.append(0, 0, 0); array.append(1, 0, 0);
|
---|
468 | array.append(1, 0, 0); array.append(1, 1, 0);
|
---|
469 | array.append(1, 1, 0); array.append(0, 1, 0);
|
---|
470 | array.append(0, 1, 0); array.append(0, 0, 0);
|
---|
471 |
|
---|
472 | array.append(0, 0, 1); array.append(1, 0, 1);
|
---|
473 | array.append(1, 0, 1); array.append(1, 1, 1);
|
---|
474 | array.append(1, 1, 1); array.append(0, 1, 1);
|
---|
475 | array.append(0, 1, 1); array.append(0, 0, 1);
|
---|
476 |
|
---|
477 | array.append(0, 0, 0); array.append(0, 0, 1);
|
---|
478 | array.append(1, 0, 0); array.append(1, 0, 1);
|
---|
479 | array.append(0, 1, 0); array.append(0, 1, 1);
|
---|
480 | array.append(1, 1, 0); array.append(1, 1, 1);
|
---|
481 | painter->clearAttributes();
|
---|
482 | painter->setVertexAttribute(QGL::Position, array);
|
---|
483 | painter->draw(QGL::Lines, 24);
|
---|
484 |
|
---|
485 | painter->modelViewMatrix().pop();
|
---|
486 | }
|
---|
487 |
|
---|
488 | void GLWorldView::drawDreiBein(QGLPainter *painter)
|
---|
489 | {
|
---|
490 | painter->modelViewMatrix().push();
|
---|
491 | painter->modelViewMatrix().translate(camera()->center());
|
---|
492 | painter->setFaceMaterial(QGL::FrontFaces, NULL);
|
---|
493 | meshDreiBein->draw(painter);
|
---|
494 | painter->modelViewMatrix().pop();
|
---|
495 | }
|
---|
496 |
|
---|
497 |
|
---|
498 | //#include <GL/glu.h>
|
---|
499 | //#include <QtGui/qslider.h>
|
---|
500 | //#include <QtGui/qevent.h>
|
---|
501 | //
|
---|
502 | //#include "ui_dialoglight.h"
|
---|
503 | //
|
---|
504 | //#include "CodePatterns/MemDebug.hpp"
|
---|
505 | //
|
---|
506 | //#include <iostream>
|
---|
507 | //#include <boost/shared_ptr.hpp>
|
---|
508 | //
|
---|
509 | //#include "LinearAlgebra/Line.hpp"
|
---|
510 | //#include "Atom/atom.hpp"
|
---|
511 | //#include "Bond/bond.hpp"
|
---|
512 | //#include "Element/element.hpp"
|
---|
513 | //#include "molecule.hpp"
|
---|
514 | //#include "Element/periodentafel.hpp"
|
---|
515 | //#include "World.hpp"
|
---|
516 | //
|
---|
517 | //#if defined(Q_CC_MSVC)
|
---|
518 | //#pragma warning(disable:4305) // init: truncation from const double to float
|
---|
519 | //#endif
|
---|
520 | //
|
---|
521 | //
|
---|
522 | //GLMoleculeView::GLMoleculeView(QWidget *parent) :
|
---|
523 | // QGLWidget(parent), Observer("GLMoleculeView"), X(Vector(1,0,0)), Y(Vector(0,1,0)), Z(Vector(0,0,1))
|
---|
524 | //{
|
---|
525 | // xRot = yRot = zRot = 0.0; // default object rotation
|
---|
526 | // scale = 5.; // default object scale
|
---|
527 | // object = 0;
|
---|
528 | // LightPosition[0] = 0.0f;
|
---|
529 | // LightPosition[1] = 2.0f;
|
---|
530 | // LightPosition[2] = 2.0f;
|
---|
531 | // LightPosition[3] = 0.0f;
|
---|
532 | // LightDiffuse[0] = 0.5f;
|
---|
533 | // LightDiffuse[1] = 0.5f;
|
---|
534 | // LightDiffuse[2] = 0.5f;
|
---|
535 | // LightDiffuse[3] = 0.0f;
|
---|
536 | // LightAmbient[0] = 0.0f;
|
---|
537 | // LightAmbient[1] = 0.0f;
|
---|
538 | // LightAmbient[2] = 0.0f;
|
---|
539 | // LightAmbient[3] = 0.0f;
|
---|
540 | //
|
---|
541 | // SelectionColor[0] = 0;
|
---|
542 | // SelectionColor[1] = 128;
|
---|
543 | // SelectionColor[2] = 128;
|
---|
544 | //
|
---|
545 | // MultiViewEnabled = true;
|
---|
546 | //
|
---|
547 | // isSignaller = false;
|
---|
548 | //
|
---|
549 | // World::getInstance().signOn(this);
|
---|
550 | //}
|
---|
551 | //
|
---|
552 | ///** Destructor of GLMoleculeView.
|
---|
553 | // * Free's the CallList.
|
---|
554 | // */
|
---|
555 | //GLMoleculeView::~GLMoleculeView()
|
---|
556 | //{
|
---|
557 | // makeCurrent();
|
---|
558 | // glDeleteLists( object, 1 );
|
---|
559 | //
|
---|
560 | // World::getInstance().signOff(this);
|
---|
561 | //}
|
---|
562 | //
|
---|
563 | ///** Paints the conents of the OpenGL window.
|
---|
564 | // * Clears the GL buffers, enables lighting and depth.
|
---|
565 | // * Window is either quartered (if GLMoleculeView::MultiViewEnabled) and xy, xz, yz planar views
|
---|
566 | // * are added. Uses the CallList, constructed during InitializeGL().
|
---|
567 | // */
|
---|
568 | //void GLMoleculeView::paintGL()
|
---|
569 | //{
|
---|
570 | // Vector spot;
|
---|
571 | //
|
---|
572 | // glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
573 | // glShadeModel(GL_SMOOTH); // Enable Smooth Shading
|
---|
574 | // glEnable(GL_LIGHTING); // Enable Light One
|
---|
575 | // glEnable(GL_DEPTH_TEST); // Enables Depth Testing
|
---|
576 | // glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
|
---|
577 | // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
|
---|
578 | //
|
---|
579 | // // 3d viewport
|
---|
580 | // if (MultiViewEnabled)
|
---|
581 | // glViewport( 0, 0, (GLint)width/2, (GLint)height/2 );
|
---|
582 | // else
|
---|
583 | // glViewport( 0, 0, (GLint)width, (GLint)height );
|
---|
584 | // glMatrixMode( GL_PROJECTION );
|
---|
585 | // glLoadIdentity();
|
---|
586 | // glFrustum( -1.0, 1.0, -1.0, 1.0, 1.0, 50.0 );
|
---|
587 | // glMatrixMode( GL_MODELVIEW );
|
---|
588 | // glLoadIdentity();
|
---|
589 | //
|
---|
590 | // // calculate point of view and direction
|
---|
591 | // glTranslated(position[0],position[1],position[2]);
|
---|
592 | // glTranslated(0.0, 0.0, -scale);
|
---|
593 | // glRotated(xRot, 1.0, 0.0, 0.0);
|
---|
594 | // glRotated(yRot, 0.0, 1.0, 0.0);
|
---|
595 | // glRotated(zRot, 0.0, 0.0, 1.0);
|
---|
596 | //
|
---|
597 | // // render scene
|
---|
598 | // glCallList(object);
|
---|
599 | //
|
---|
600 | // // enable light
|
---|
601 | // glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
|
---|
602 | // glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
|
---|
603 | // glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light
|
---|
604 | // glEnable(GL_LIGHT1); // Enable Light One
|
---|
605 | //
|
---|
606 | // if (MultiViewEnabled) {
|
---|
607 | // // xy view port
|
---|
608 | // glViewport( (GLint)width/2, 0, (GLint)width/2, (GLint)height/2 );
|
---|
609 | // glMatrixMode( GL_PROJECTION );
|
---|
610 | // glLoadIdentity();
|
---|
611 | // glScalef(1./scale, 1./scale,1./scale);
|
---|
612 | // glOrtho(0, width/2, 0, height/2, 0,0);
|
---|
613 | // glMatrixMode( GL_MODELVIEW );
|
---|
614 | // glLoadIdentity();
|
---|
615 | //
|
---|
616 | // // calculate point of view and direction
|
---|
617 | // view = position;
|
---|
618 | // spot = Vector(0.,0.,scale);
|
---|
619 | // top = Vector(0.,1.,0.);
|
---|
620 | // gluLookAt(
|
---|
621 | // spot[0], spot[1], spot[2],
|
---|
622 | // view[0], view[1], view[2],
|
---|
623 | // top[0], top[1], top[2]);
|
---|
624 | //
|
---|
625 | // // enable light
|
---|
626 | // glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
|
---|
627 | // glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
|
---|
628 | // glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light
|
---|
629 | // glEnable(GL_LIGHT1); // Enable Light One
|
---|
630 | //
|
---|
631 | // // render scene
|
---|
632 | // glCallList(object);
|
---|
633 | //
|
---|
634 | // // xz viewport
|
---|
635 | // glViewport( 0, (GLint)height/2, (GLint)width/2, (GLint)height/2 );
|
---|
636 | // glMatrixMode( GL_PROJECTION );
|
---|
637 | // glLoadIdentity();
|
---|
638 | // glScalef(1./scale, 1./scale,1./scale);
|
---|
639 | // glOrtho(0, width/2, 0, height/2, 0,0);
|
---|
640 | // glMatrixMode( GL_MODELVIEW );
|
---|
641 | // glLoadIdentity();
|
---|
642 | //
|
---|
643 | // // calculate point of view and direction
|
---|
644 | // view = position;
|
---|
645 | // spot = Vector(0.,scale,0.);
|
---|
646 | // top = Vector(1.,0.,0.);
|
---|
647 | // gluLookAt(
|
---|
648 | // spot[0], spot[1], spot[2],
|
---|
649 | // view[0], view[1], view[2],
|
---|
650 | // top[0], top[1], top[2]);
|
---|
651 | //
|
---|
652 | // // enable light
|
---|
653 | // glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
|
---|
654 | // glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
|
---|
655 | // glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light
|
---|
656 | // glEnable(GL_LIGHT1); // Enable Light One
|
---|
657 | //
|
---|
658 | // // render scene
|
---|
659 | // glCallList(object);
|
---|
660 | //
|
---|
661 | // //yz viewport
|
---|
662 | // glViewport( (GLint)width/2, (GLint)height/2, (GLint)width/2, (GLint)height/2 );
|
---|
663 | // glMatrixMode( GL_PROJECTION );
|
---|
664 | // glLoadIdentity();
|
---|
665 | // glScalef(1./scale, 1./scale,1./scale);
|
---|
666 | // glOrtho(0, width/2, 0, height/2, 0,0);
|
---|
667 | // glMatrixMode( GL_MODELVIEW );
|
---|
668 | // glLoadIdentity();
|
---|
669 | //
|
---|
670 | // // calculate point of view and direction
|
---|
671 | // view= position;
|
---|
672 | // spot = Vector(scale,0.,0.);
|
---|
673 | // top = Vector(0.,1.,0.);
|
---|
674 | // gluLookAt(
|
---|
675 | // spot[0], spot[1], spot[2],
|
---|
676 | // view[0], view[1], view[2],
|
---|
677 | // top[0], top[1], top[2]);
|
---|
678 | //
|
---|
679 | // // enable light
|
---|
680 | // glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
|
---|
681 | // glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
|
---|
682 | // glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light
|
---|
683 | // glEnable(GL_LIGHT1); // Enable Light One
|
---|
684 | //
|
---|
685 | // // render scene
|
---|
686 | // glCallList(object);
|
---|
687 | // }
|
---|
688 | // //CoordinatesBar->setText( QString ("X: %1, Y: %2, Z: %3").arg(position[0]).arg(position[1]).arg(position[2]) );
|
---|
689 | //}
|
---|
690 | //
|
---|
691 | ////void polarView{GLdouble distance, GLdouble twist,
|
---|
692 | //// GLdouble elevation, GLdouble azimuth)
|
---|
693 | ////{
|
---|
694 | //// glTranslated(0.0, 0.0, -distance);
|
---|
695 | //// glRotated(-twist, 0.0, 0.0, 1.0);
|
---|
696 | //// glRotated(-elevation, 1.0, 0.0, 0.0);
|
---|
697 | //// glRotated(azimuth, 0.0, 0.0, 1.0);
|
---|
698 | ////}
|
---|
699 | //
|
---|
700 | ///** Make a sphere.
|
---|
701 | // * \param x position
|
---|
702 | // * \param radius radius
|
---|
703 | // * \param color[3] color rgb values
|
---|
704 | // */
|
---|
705 | //void GLMoleculeView::makeSphere(const Vector &x, double radius, const unsigned char color[3])
|
---|
706 | //{
|
---|
707 | // float blueMaterial[] = { 255./(float)color[0], 255./(float)color[1], 255./(float)color[2], 1 }; // need to recast from [0,255] with integers into [0,1] with floats
|
---|
708 | // GLUquadricObj* q = gluNewQuadric ();
|
---|
709 | // gluQuadricOrientation(q, GLU_OUTSIDE);
|
---|
710 | //
|
---|
711 | // std::cout << "Setting sphere at " << x << " with color r"
|
---|
712 | // << (int)color[0] << ",g" << (int)color[1] << ",b" << (int)color[2] << "." << endl;
|
---|
713 | //
|
---|
714 | // glPushMatrix();
|
---|
715 | // glTranslatef( x[0], x[1], x[2]);
|
---|
716 | //// glRotatef( xRot, 1.0, 0.0, 0.0);
|
---|
717 | //// glRotatef( yRot, 0.0, 1.0, 0.0);
|
---|
718 | //// glRotatef( zRot, 0.0, 0.0, 1.0);
|
---|
719 | // glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blueMaterial);
|
---|
720 | // gluSphere (q, (GLdouble)radius, 10, 10);
|
---|
721 | // glPopMatrix();
|
---|
722 | //}
|
---|
723 | //
|
---|
724 | ///** Make a cylinder.
|
---|
725 | // * \param x origin
|
---|
726 | // * \param y direction
|
---|
727 | // * \param radius thickness
|
---|
728 | // * \param height length
|
---|
729 | // * \color[3] color rgb values
|
---|
730 | // */
|
---|
731 | //void GLMoleculeView::makeCylinder(const Vector &x, const Vector &y, double radius, double height, const unsigned char color[3])
|
---|
732 | //{
|
---|
733 | // float blueMaterial[] = { 255./(float)color[0], 255./(float)color[1], 255./(float)color[2], 1 };
|
---|
734 | // GLUquadricObj* q = gluNewQuadric ();
|
---|
735 | // gluQuadricOrientation(q, GLU_OUTSIDE);
|
---|
736 | // Vector a,b;
|
---|
737 | // Vector OtherAxis;
|
---|
738 | // double alpha;
|
---|
739 | // a = x - y;
|
---|
740 | // // construct rotation axis
|
---|
741 | // b = a;
|
---|
742 | // b.VectorProduct(Z);
|
---|
743 | // Line axis(zeroVec, b);
|
---|
744 | // // calculate rotation angle
|
---|
745 | // alpha = a.Angle(Z);
|
---|
746 | // // construct other axis to check right-hand rule
|
---|
747 | // OtherAxis = b;
|
---|
748 | // OtherAxis.VectorProduct(Z);
|
---|
749 | // // assure right-hand rule for the rotation
|
---|
750 | // if (a.ScalarProduct(OtherAxis) < MYEPSILON)
|
---|
751 | // alpha = M_PI-alpha;
|
---|
752 | // // check
|
---|
753 | // Vector a_rotated = axis.rotateVector(a, alpha);
|
---|
754 | // std::cout << "Setting cylinder from "// << x << " to " << y
|
---|
755 | // << a << " to " << a_rotated << " around " << b << " by " << alpha/M_PI*180. << ", respectively, "
|
---|
756 | // << " with color r"
|
---|
757 | // << (int)color[0] << ",g" << (int)color[1] << ",b" << (int)color[2] << "." << endl;
|
---|
758 | //
|
---|
759 | // glPushMatrix();
|
---|
760 | // glTranslatef( x[0], x[1], x[2]);
|
---|
761 | // glRotatef( alpha/M_PI*180., b[0], b[1], b[2]);
|
---|
762 | // glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blueMaterial);
|
---|
763 | // gluCylinder (q, (GLdouble)radius, (GLdouble)radius, (GLdouble)height, 10, 10);
|
---|
764 | // glPopMatrix();
|
---|
765 | //}
|
---|
766 | //
|
---|
767 | ///** Defines the display CallList.
|
---|
768 | // * Goes through all molecules and their atoms and adds spheres for atoms and cylinders
|
---|
769 | // * for bonds. Heeds GLMoleculeView::SelectedAtom and GLMoleculeView::SelectedMolecule.
|
---|
770 | // */
|
---|
771 | //void GLMoleculeView::initializeGL()
|
---|
772 | //{
|
---|
773 | // double x[3] = {-1, 0, -10};
|
---|
774 | // unsigned char white[3] = {255,255,255};
|
---|
775 | // Vector Position, OtherPosition;
|
---|
776 | // QSize window = size();
|
---|
777 | // width = window.width();
|
---|
778 | // height = window.height();
|
---|
779 | // std::cout << "Setting width to " << width << " and height to " << height << std::endl;
|
---|
780 | // GLfloat shininess[] = { 0.0 };
|
---|
781 | // GLfloat specular[] = { 0, 0, 0, 1 };
|
---|
782 | // glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Let OpenGL clear to black
|
---|
783 | // object = glGenLists(1);
|
---|
784 | // glNewList( object, GL_COMPILE );
|
---|
785 | // glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
|
---|
786 | // glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
|
---|
787 | //
|
---|
788 | // const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
|
---|
789 | //
|
---|
790 | // if (molecules.size() > 0) {
|
---|
791 | // for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
|
---|
792 | // Runner != molecules.end();
|
---|
793 | // Runner++) {
|
---|
794 | // for (molecule::const_iterator atomiter = (*Runner)->begin();
|
---|
795 | // atomiter != (*Runner)->end();
|
---|
796 | // ++atomiter) {
|
---|
797 | // // create atom
|
---|
798 | // const element *ptr = (*atomiter)->getType();
|
---|
799 | // boost::shared_ptr<Vector> MolCenter((*Runner)->DetermineCenterOfGravity());
|
---|
800 | // Position = (*atomiter)->getPosition() - *MolCenter;
|
---|
801 | // const unsigned char* color = NULL;
|
---|
802 | // if ((World::getInstance().isSelected(*atomiter)) || (World::getInstance().isSelected((*Runner))))
|
---|
803 | // color = SelectionColor;
|
---|
804 | // else
|
---|
805 | // color = ptr->getColor();
|
---|
806 | // makeSphere(Position, ptr->getVanDerWaalsRadius()*0.25, color);
|
---|
807 | //
|
---|
808 | // // create bonds
|
---|
809 | // const BondList &bonds = (*atomiter)->getListOfBonds();
|
---|
810 | // for (BondList::const_iterator bonditer = bonds.begin();
|
---|
811 | // bonditer != bonds.end();
|
---|
812 | // ++bonditer) {
|
---|
813 | // if ((*bonditer)->leftatom->getId() == (*atomiter)->getId()) {
|
---|
814 | // Position = (*bonditer)->leftatom->getPosition() - *MolCenter;
|
---|
815 | // OtherPosition = (*bonditer)->rightatom->getPosition() - *MolCenter;
|
---|
816 | // const double distance = sqrt(Position.DistanceSquared(OtherPosition))/2.;
|
---|
817 | // const unsigned char *color1 = (*bonditer)->leftatom->getType()->getColor();
|
---|
818 | // const unsigned char *color2 = (*bonditer)->rightatom->getType()->getColor();
|
---|
819 | // makeCylinder(Position, OtherPosition, 0.1, distance, color1);
|
---|
820 | // makeCylinder(OtherPosition, Position, 0.1, distance, color2);
|
---|
821 | // }
|
---|
822 | // }
|
---|
823 | // }
|
---|
824 | // }
|
---|
825 | // } else {
|
---|
826 | // makeSphere( x,1, white);
|
---|
827 | // }
|
---|
828 | // glEndList();
|
---|
829 | //}
|
---|
830 | //
|
---|
831 | //
|
---|
832 | ///* ================================== SLOTS ============================== */
|
---|
833 | //
|
---|
834 | ///** Initializes some public variables.
|
---|
835 | // * \param *ptr pointer to QLabel statusbar
|
---|
836 | // */
|
---|
837 | //void GLMoleculeView::init(QLabel *ptr)
|
---|
838 | //{
|
---|
839 | // StatusBar = ptr;
|
---|
840 | //}
|
---|
841 | //
|
---|
842 | ///** Initializes the viewport statusbar.
|
---|
843 | // * \param *ptr pointer to QLabel for showing view pointcoordinates.
|
---|
844 | // */
|
---|
845 | //void GLMoleculeView::initCoordinates(QLabel *ptr)
|
---|
846 | //{
|
---|
847 | // CoordinatesBar = ptr;
|
---|
848 | //}
|
---|
849 | //
|
---|
850 | ///** Slot to be called when to initialize GLMoleculeView::MolData.
|
---|
851 | // */
|
---|
852 | //void GLMoleculeView::createView( )
|
---|
853 | //{
|
---|
854 | // initializeGL();
|
---|
855 | // updateGL();
|
---|
856 | //}
|
---|
857 | //
|
---|
858 | ///** Slot of window is resized.
|
---|
859 | // * Copies new width and height to GLMoleculeView::width and GLMoleculeView::height and calls updateGL().
|
---|
860 | // * \param w new width of window
|
---|
861 | // * \param h new height of window
|
---|
862 | // */
|
---|
863 | //void GLMoleculeView::resizeGL( int w, int h )
|
---|
864 | //{
|
---|
865 | // width = w;
|
---|
866 | // height = h;
|
---|
867 | // updateGL();
|
---|
868 | //}
|
---|
869 | //
|
---|
870 | ///** Sets x rotation angle.
|
---|
871 | // * sets GLMoleculeView::xRot and calls updateGL().
|
---|
872 | // * \param degrees new rotation angle in degrees
|
---|
873 | // */
|
---|
874 | //void GLMoleculeView::setXRotation( int degrees )
|
---|
875 | //{
|
---|
876 | // xRot = (GLfloat)(degrees % 360);
|
---|
877 | // updateGL();
|
---|
878 | //}
|
---|
879 | //
|
---|
880 | //
|
---|
881 | ///** Sets y rotation angle.
|
---|
882 | // * sets GLMoleculeView::yRot and calls updateGL().
|
---|
883 | // * \param degrees new rotation angle in degrees
|
---|
884 | // */
|
---|
885 | //void GLMoleculeView::setYRotation( int degrees )
|
---|
886 | //{
|
---|
887 | // yRot = (GLfloat)(degrees % 360);
|
---|
888 | // updateGL();
|
---|
889 | //}
|
---|
890 | //
|
---|
891 | //
|
---|
892 | ///** Sets z rotation angle.
|
---|
893 | // * sets GLMoleculeView::zRot and calls updateGL().
|
---|
894 | // * \param degrees new rotation angle in degrees
|
---|
895 | // */
|
---|
896 | //void GLMoleculeView::setZRotation( int degrees )
|
---|
897 | //{
|
---|
898 | // zRot = (GLfloat)(degrees % 360);
|
---|
899 | // updateGL();
|
---|
900 | //}
|
---|
901 | //
|
---|
902 | ///** Sets the scale of the scene.
|
---|
903 | // * sets GLMoleculeView::scale and calls updateGL().
|
---|
904 | // * \param distance distance divided by 100 is the new scale
|
---|
905 | // */
|
---|
906 | //void GLMoleculeView::setScale( int distance )
|
---|
907 | //{
|
---|
908 | // scale = (GLfloat)(distance / 100.);
|
---|
909 | // updateGL();
|
---|
910 | //}
|
---|
911 | //
|
---|
912 | ///** Update the ambient light.
|
---|
913 | // * \param light[4] light strength per axis and position (w)
|
---|
914 | // */
|
---|
915 | //void GLMoleculeView::setLightAmbient( int *light )
|
---|
916 | //{
|
---|
917 | // for(int i=0;i<4;i++)
|
---|
918 | // LightAmbient[i] = light[i];
|
---|
919 | // updateGL();
|
---|
920 | //}
|
---|
921 | //
|
---|
922 | ///** Update the diffuse light.
|
---|
923 | // * \param light[4] light strength per axis and position (w)
|
---|
924 | // */
|
---|
925 | //void GLMoleculeView::setLightDiffuse( int *light )
|
---|
926 | //{
|
---|
927 | // for(int i=0;i<4;i++)
|
---|
928 | // LightDiffuse[i] = light[i];
|
---|
929 | // updateGL();
|
---|
930 | //}
|
---|
931 | //
|
---|
932 | ///** Update the position of light.
|
---|
933 | // * \param light[4] light strength per axis and position (w)
|
---|
934 | // */
|
---|
935 | //void GLMoleculeView::setLightPosition( int *light )
|
---|
936 | //{
|
---|
937 | // for(int i=0;i<4;i++)
|
---|
938 | // LightPosition[i] = light[i];
|
---|
939 | // updateGL();
|
---|
940 | //}
|
---|
941 | //
|
---|
942 | ///** Toggles the boolean GLMoleculeView::MultiViewEnabled.
|
---|
943 | // * Flips the boolean and calls updateGL().
|
---|
944 | // */
|
---|
945 | //void GLMoleculeView::toggleMultiViewEnabled ( )
|
---|
946 | //{
|
---|
947 | // MultiViewEnabled = !MultiViewEnabled;
|
---|
948 | // cout << "Setting MultiView to " << MultiViewEnabled << "." << endl;
|
---|
949 | // updateGL();
|
---|
950 | //}
|
---|
951 | //
|
---|
952 | ///** Launch a dialog to configure the lights.
|
---|
953 | // */
|
---|
954 | //void GLMoleculeView::createDialogLight()
|
---|
955 | //{
|
---|
956 | //// Ui_DialogLight *Lights = new Ui_DialogLight();
|
---|
957 | //// if (Lights == NULL)
|
---|
958 | //// return;
|
---|
959 | //// // Set up the dynamic dialog here
|
---|
960 | //// QLineEdit *Field = NULL;
|
---|
961 | //// Field = Lights->findChild<QLineEdit *>("LightPositionX");
|
---|
962 | //// if (Field) Field->setText( QString("%1").arg(LightPosition[0]) );
|
---|
963 | //// Field = Lights->findChild<QLineEdit *>("LightPositionY");
|
---|
964 | //// if (Field) Field->setText( QString("%1").arg(LightPosition[1]) );
|
---|
965 | //// Field = Lights->findChild<QLineEdit *>("LightPositionZ");
|
---|
966 | //// if (Field) Field->setText( QString("%1").arg(LightPosition[2]) );
|
---|
967 | //// Field = Lights->findChild<QLineEdit *>("LightPositionW");
|
---|
968 | //// if (Field) Field->setText( QString("%1").arg(LightPosition[3]) );
|
---|
969 | ////
|
---|
970 | //// Field = Lights->findChild<QLineEdit *>("LightDiffuseX");
|
---|
971 | //// if (Field) Field->setText( QString("%1").arg(LightDiffuse[0]) );
|
---|
972 | //// Field = Lights->findChild<QLineEdit *>("LightDiffuseY");
|
---|
973 | //// if (Field) Field->setText( QString("%1").arg(LightDiffuse[1]) );
|
---|
974 | //// Field = Lights->findChild<QLineEdit *>("LightDiffuseZ");
|
---|
975 | //// if (Field) Field->setText( QString("%1").arg(LightDiffuse[2]) );
|
---|
976 | //// Field = Lights->findChild<QLineEdit *>("LightDiffuseW");
|
---|
977 | //// if (Field) Field->setText( QString("%1").arg(LightDiffuse[3]) );
|
---|
978 | ////
|
---|
979 | //// Field = Lights->findChild<QLineEdit *>("LightAmbientX");
|
---|
980 | //// if (Field) Field->setText( QString("%1").arg(LightAmbient[0]) );
|
---|
981 | //// Field = Lights->findChild<QLineEdit *>("LightAmbientY");
|
---|
982 | //// if (Field) Field->setText( QString("%1").arg(LightAmbient[1]) );
|
---|
983 | //// Field = Lights->findChild<QLineEdit *>("LightAmbientZ");
|
---|
984 | //// if (Field) Field->setText( QString("%1").arg(LightAmbient[2]) );
|
---|
985 | //// Field = Lights->findChild<QLineEdit *>("LightAmbientW");
|
---|
986 | //// if (Field) Field->setText( QString("%1").arg(LightAmbient[3]) );
|
---|
987 | ////
|
---|
988 | //// if ( Lights->exec() ) {
|
---|
989 | //// //cout << "User accepted.\n";
|
---|
990 | //// // The user accepted, act accordingly
|
---|
991 | //// Field = Lights->findChild<QLineEdit *>("LightPositionX");
|
---|
992 | //// if (Field) LightPosition[0] = Field->text().toDouble();
|
---|
993 | //// Field = Lights->findChild<QLineEdit *>("LightPositionY");
|
---|
994 | //// if (Field) LightPosition[1] = Field->text().toDouble();
|
---|
995 | //// Field = Lights->findChild<QLineEdit *>("LightPositionZ");
|
---|
996 | //// if (Field) LightPosition[2] = Field->text().toDouble();
|
---|
997 | //// Field = Lights->findChild<QLineEdit *>("LightPositionW");
|
---|
998 | //// if (Field) LightPosition[3] = Field->text().toDouble();
|
---|
999 | ////
|
---|
1000 | //// Field = Lights->findChild<QLineEdit *>("LightDiffuseX");
|
---|
1001 | //// if (Field) LightDiffuse[0] = Field->text().toDouble();
|
---|
1002 | //// Field = Lights->findChild<QLineEdit *>("LightDiffuseY");
|
---|
1003 | //// if (Field) LightDiffuse[1] = Field->text().toDouble();
|
---|
1004 | //// Field = Lights->findChild<QLineEdit *>("LightDiffuseZ");
|
---|
1005 | //// if (Field) LightDiffuse[2] = Field->text().toDouble();
|
---|
1006 | //// Field = Lights->findChild<QLineEdit *>("LightDiffuseW");
|
---|
1007 | //// if (Field) LightDiffuse[3] = Field->text().toDouble();
|
---|
1008 | ////
|
---|
1009 | //// Field = Lights->findChild<QLineEdit *>("LightAmbientX");
|
---|
1010 | //// if (Field) LightAmbient[0] = Field->text().toDouble();
|
---|
1011 | //// Field = Lights->findChild<QLineEdit *>("LightAmbientY");
|
---|
1012 | //// if (Field) LightAmbient[1] = Field->text().toDouble();
|
---|
1013 | //// Field = Lights->findChild<QLineEdit *>("LightAmbientZ");
|
---|
1014 | //// if (Field) LightAmbient[2] = Field->text().toDouble();
|
---|
1015 | //// Field = Lights->findChild<QLineEdit *>("LightAmbientW");
|
---|
1016 | //// if (Field) LightAmbient[3] = Field->text().toDouble();
|
---|
1017 | //// updateGL();
|
---|
1018 | //// } else {
|
---|
1019 | //// //cout << "User reclined.\n";
|
---|
1020 | //// }
|
---|
1021 | //// delete(Lights);
|
---|
1022 | //}
|
---|
1023 | //
|
---|
1024 | ///** Slot for event of pressed mouse button.
|
---|
1025 | // * Switch discerns between buttons and stores position of event in GLMoleculeView::LeftButtonPos,
|
---|
1026 | // * GLMoleculeView::MiddleButtonPos or GLMoleculeView::RightButtonPos.
|
---|
1027 | // * \param *event structure containing information of the event
|
---|
1028 | // */
|
---|
1029 | //void GLMoleculeView::mousePressEvent(QMouseEvent *event)
|
---|
1030 | //{
|
---|
1031 | // std::cout << "MousePressEvent." << endl;
|
---|
1032 | // QPoint *pos = NULL;
|
---|
1033 | // switch (event->button()) { // get the right array
|
---|
1034 | // case Qt::LeftButton:
|
---|
1035 | // pos = &LeftButtonPos;
|
---|
1036 | // std::cout << "Left Button" << endl;
|
---|
1037 | // break;
|
---|
1038 | // case Qt::MidButton:
|
---|
1039 | // pos = &MiddleButtonPos;
|
---|
1040 | // std::cout << "Middle Button" << endl;
|
---|
1041 | // break;
|
---|
1042 | // case Qt::RightButton:
|
---|
1043 | // pos = &RightButtonPos;
|
---|
1044 | // std::cout << "Right Button" << endl;
|
---|
1045 | // break;
|
---|
1046 | // default:
|
---|
1047 | // break;
|
---|
1048 | // }
|
---|
1049 | // if (pos) { // store the position
|
---|
1050 | // pos->setX(event->pos().x());
|
---|
1051 | // pos->setY(event->pos().y());
|
---|
1052 | // std::cout << "Stored src position is (" << pos->x() << "," << pos->y() << ")." << endl;
|
---|
1053 | // } else {
|
---|
1054 | // std::cout << "pos is NULL." << endl;
|
---|
1055 | // }
|
---|
1056 | //}
|
---|
1057 | //
|
---|
1058 | ///** Slot for event of pressed mouse button.
|
---|
1059 | // * Switch discerns between buttons:
|
---|
1060 | // * -# Left Button: Rotates the view of the GLMoleculeView, relative to GLMoleculeView::LeftButtonPos.
|
---|
1061 | // * -# Middle Button: nothing
|
---|
1062 | // * -# Right Button: Shifts the selected molecule or atom, relative to GLMoleculeView::RightButtonPos.
|
---|
1063 | // * \param *event structure containing information of the event
|
---|
1064 | // */
|
---|
1065 | //void GLMoleculeView::mouseReleaseEvent(QMouseEvent *event)
|
---|
1066 | //{
|
---|
1067 | // std::cout << "MouseReleaseEvent." << endl;
|
---|
1068 | // QPoint *srcpos = NULL;
|
---|
1069 | // QPoint destpos = event->pos();
|
---|
1070 | // int Width = (MultiViewEnabled) ? width/2 : width;
|
---|
1071 | // int Height = (MultiViewEnabled) ? height/2 : height;
|
---|
1072 | // std::cout << "Received dest position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
|
---|
1073 | // switch (event->button()) { // get the right array
|
---|
1074 | // case Qt::LeftButton: // LeftButton rotates the view
|
---|
1075 | // srcpos = &LeftButtonPos;
|
---|
1076 | // std::cout << "Left Button" << endl;
|
---|
1077 | // if (srcpos) { // subtract the position and act
|
---|
1078 | // std::cout << "Stored src position is (" << srcpos->x() << "," << srcpos->y() << ")." << endl;
|
---|
1079 | // destpos -= *srcpos;
|
---|
1080 | // std::cout << "Resulting diff position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
|
---|
1081 | // std::cout << "Width and Height are " << Width << "," << Height << "." << endl;
|
---|
1082 | //
|
---|
1083 | // int pos = (int)floor((double)srcpos->x()/(double)Width) + ((int)floor((double)srcpos->y()/(double)Height))*2;
|
---|
1084 | // if ((MultiViewEnabled) && (pos != 2)) { // means four regions, and we are in a shifting one
|
---|
1085 | // // switch between three regions
|
---|
1086 | // // decide into which of the four screens the initial click has been made
|
---|
1087 | // std::cout << "Position is " << pos << "." << endl;
|
---|
1088 | // switch(pos) {
|
---|
1089 | // case 0: // lower left = xz
|
---|
1090 | // position[0] += -destpos.y()/100.;
|
---|
1091 | // position[2] += destpos.x()/100.;
|
---|
1092 | // break;
|
---|
1093 | // case 1: // lower right = yz
|
---|
1094 | // position[1] += -destpos.y()/100.;
|
---|
1095 | // position[2] += -destpos.x()/100.;
|
---|
1096 | // break;
|
---|
1097 | // case 2: // upper left = projected
|
---|
1098 | // std::cout << "This is impossible: Shifting in the projected region, we should rotate!." << endl;
|
---|
1099 | // break;
|
---|
1100 | // case 3: // upper right = xy
|
---|
1101 | // position[0] += destpos.x()/100.;
|
---|
1102 | // position[1] += -destpos.y()/100.;
|
---|
1103 | // break;
|
---|
1104 | // default:
|
---|
1105 | // std::cout << "click was not in any of the four regions." << endl;
|
---|
1106 | // break;
|
---|
1107 | // }
|
---|
1108 | // updateGL();
|
---|
1109 | // } else { // we are in rotation region
|
---|
1110 | // QWidget *Parent = parentWidget();
|
---|
1111 | // QSlider *sliderX = Parent->findChild<QSlider *>("sliderX");
|
---|
1112 | // QSlider *sliderY = Parent->findChild<QSlider *>("sliderY");
|
---|
1113 | // std::cout << sliderX << " and " << sliderY << endl;
|
---|
1114 | // if (sliderX) {
|
---|
1115 | // int xrange = sliderX->maximum() - sliderX->minimum();
|
---|
1116 | // double xValue = ((destpos.x() + Width) % Width);
|
---|
1117 | // xValue *= (double)xrange/(double)Width;
|
---|
1118 | // xValue += sliderX->value();
|
---|
1119 | // int xvalue = (int) xValue % xrange;
|
---|
1120 | // std::cout << "Setting x to " << xvalue << " within range " << xrange << "." << endl;
|
---|
1121 | // setXRotation(xvalue);
|
---|
1122 | // sliderX->setValue(xvalue);
|
---|
1123 | // } else {
|
---|
1124 | // std::cout << "sliderX is NULL." << endl;
|
---|
1125 | // }
|
---|
1126 | // if (sliderY) {
|
---|
1127 | // int yrange = sliderY->maximum() - sliderY->minimum();
|
---|
1128 | // double yValue = ((destpos.y() + Height) % Height);
|
---|
1129 | // yValue *= (double)yrange/(double)Height;
|
---|
1130 | // yValue += sliderY->value();
|
---|
1131 | // int yvalue = (int) yValue % yrange;
|
---|
1132 | // std::cout << "Setting y to " << yvalue << " within range " << yrange << "." << endl;
|
---|
1133 | // setYRotation(yvalue);
|
---|
1134 | // sliderY->setValue(yvalue);
|
---|
1135 | // } else {
|
---|
1136 | // std::cout << "sliderY is NULL." << endl;
|
---|
1137 | // }
|
---|
1138 | // }
|
---|
1139 | // } else {
|
---|
1140 | // std::cout << "srcpos is NULL." << endl;
|
---|
1141 | // }
|
---|
1142 | // break;
|
---|
1143 | //
|
---|
1144 | // case Qt::MidButton: // MiddleButton has no function so far
|
---|
1145 | // srcpos = &MiddleButtonPos;
|
---|
1146 | // std::cout << "Middle Button" << endl;
|
---|
1147 | // if (srcpos) { // subtract the position and act
|
---|
1148 | // QWidget *Parent = parentWidget();
|
---|
1149 | // QSlider *sliderZ = Parent->findChild<QSlider *>("sliderZ");
|
---|
1150 | // QSlider *sliderScale = Parent->findChild<QSlider *>("sliderScale");
|
---|
1151 | // std::cout << sliderZ << " and " << sliderScale << endl;
|
---|
1152 | // std::cout << "Stored src position is (" << srcpos->x() << "," << srcpos->y() << ")." << endl;
|
---|
1153 | // destpos -= *srcpos;
|
---|
1154 | // std::cout << "Resulting diff position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
|
---|
1155 | // std::cout << "Width and Height are " << Width << "," << Height << "." << endl;
|
---|
1156 | // if (sliderZ) {
|
---|
1157 | // int xrange = sliderZ->maximum() - sliderZ->minimum();
|
---|
1158 | // double xValue = ((destpos.x() + Width) % Width);
|
---|
1159 | // xValue *= (double)xrange/(double)Width;
|
---|
1160 | // xValue += sliderZ->value();
|
---|
1161 | // int xvalue = (int) xValue % xrange;
|
---|
1162 | // std::cout << "Setting x to " << xvalue << " within range " << xrange << "." << endl;
|
---|
1163 | // setZRotation(xvalue);
|
---|
1164 | // sliderZ->setValue(xvalue);
|
---|
1165 | // } else {
|
---|
1166 | // std::cout << "sliderZ is NULL." << endl;
|
---|
1167 | // }
|
---|
1168 | // if (sliderScale) {
|
---|
1169 | // int yrange = sliderScale->maximum() - sliderScale->minimum();
|
---|
1170 | // double yValue = ((destpos.y() + Height) % Height);
|
---|
1171 | // yValue *= (double)yrange/(double)Height;
|
---|
1172 | // yValue += sliderScale->value();
|
---|
1173 | // int yvalue = (int) yValue % yrange;
|
---|
1174 | // std::cout << "Setting y to " << yvalue << " within range " << yrange << "." << endl;
|
---|
1175 | // setScale(yvalue);
|
---|
1176 | // sliderScale->setValue(yvalue);
|
---|
1177 | // } else {
|
---|
1178 | // std::cout << "sliderScale is NULL." << endl;
|
---|
1179 | // }
|
---|
1180 | // } else {
|
---|
1181 | // std::cout << "srcpos is NULL." << endl;
|
---|
1182 | // }
|
---|
1183 | // break;
|
---|
1184 | // break;
|
---|
1185 | //
|
---|
1186 | // case Qt::RightButton: // RightButton moves eitstdher the selected molecule or atom
|
---|
1187 | // srcpos = &RightButtonPos;
|
---|
1188 | // std::cout << "Right Button" << endl;
|
---|
1189 | // if (srcpos) { // subtract the position and act
|
---|
1190 | // std::cout << "Stored src position is (" << srcpos->x() << "," << srcpos->y() << ")." << endl;
|
---|
1191 | // destpos -= *srcpos;
|
---|
1192 | // std::cout << "Resulting diff position is (" << destpos.x() << "," << destpos.y() << ")." << endl;
|
---|
1193 | // std::cout << "Width and Height are " << Width << "," << Height << "." << endl;
|
---|
1194 | // if (MultiViewEnabled) {
|
---|
1195 | // // which vector to change
|
---|
1196 | // Vector SelectedPosition;
|
---|
1197 | // const std::vector<atom*> &SelectedAtoms = World::getInstance().getSelectedAtoms();
|
---|
1198 | // const std::vector<molecule*> &SelectedMolecules = World::getInstance().getSelectedMolecules();
|
---|
1199 | // if (SelectedMolecules.size()) {
|
---|
1200 | // if (SelectedAtoms.size())
|
---|
1201 | // SelectedPosition = (*SelectedAtoms.begin())->getPosition();
|
---|
1202 | // else
|
---|
1203 | // SelectedPosition = (*(*SelectedMolecules.begin())->begin())->getPosition();
|
---|
1204 | // }
|
---|
1205 | // // decide into which of the four screens the initial click has been made
|
---|
1206 | // int pos = (int)floor((double)srcpos->x()/(double)Width) + ((int)floor((double)srcpos->y()/(double)Height))*2;
|
---|
1207 | // if (!SelectedPosition.IsZero()) {
|
---|
1208 | // std::cout << "Position is " << pos << "." << endl;
|
---|
1209 | // switch(pos) {
|
---|
1210 | // case 0: // lower left = xz
|
---|
1211 | // SelectedPosition[0] += -destpos.y()/100.;
|
---|
1212 | // SelectedPosition[2] += destpos.x()/100.;
|
---|
1213 | // break;
|
---|
1214 | // case 1: // lower right = yz
|
---|
1215 | // SelectedPosition[1] += -destpos.y()/100.;
|
---|
1216 | // SelectedPosition[2] += -destpos.x()/100.;
|
---|
1217 | // break;
|
---|
1218 | // case 2: // upper left = projected
|
---|
1219 | // SelectedPosition[0] += destpos.x()/100.;
|
---|
1220 | // SelectedPosition[1] += destpos.y()/100.;
|
---|
1221 | // SelectedPosition[2] += destpos.y()/100.;
|
---|
1222 | // break;
|
---|
1223 | // case 3: // upper right = xy
|
---|
1224 | // SelectedPosition[0] += destpos.x()/100.;
|
---|
1225 | // SelectedPosition[1] += -destpos.y()/100.;
|
---|
1226 | // break;
|
---|
1227 | // default:
|
---|
1228 | // std::cout << "click was not in any of the four regions." << endl;
|
---|
1229 | // break;
|
---|
1230 | // }
|
---|
1231 | // } else {
|
---|
1232 | // std::cout << "Nothing selected." << endl;
|
---|
1233 | // }
|
---|
1234 | // // update Tables
|
---|
1235 | // if (SelectedMolecules.size()) {
|
---|
1236 | // isSignaller = true;
|
---|
1237 | // if (SelectedAtoms.size())
|
---|
1238 | // emit notifyAtomChanged( (*SelectedMolecules.begin()), (*SelectedAtoms.begin()), AtomPosition);
|
---|
1239 | // else
|
---|
1240 | // emit notifyMoleculeChanged( (*SelectedMolecules.begin()), MoleculePosition );
|
---|
1241 | // }
|
---|
1242 | // // update graphic
|
---|
1243 | // initializeGL();
|
---|
1244 | // updateGL();
|
---|
1245 | // } else {
|
---|
1246 | // cout << "MultiView is not enabled." << endl;
|
---|
1247 | // }
|
---|
1248 | // } else {
|
---|
1249 | // cout << "srcpos is NULL." << endl;
|
---|
1250 | // }
|
---|
1251 | // break;
|
---|
1252 | //
|
---|
1253 | // default:
|
---|
1254 | // break;
|
---|
1255 | // }
|
---|
1256 | //}
|
---|
1257 | //
|
---|
1258 | ///* ======================================== SLOTS ================================ */
|
---|
1259 | //
|
---|
1260 | ///** Hear announcement of selected molecule.
|
---|
1261 | // * \param *mol pointer to selected molecule
|
---|
1262 | // */
|
---|
1263 | //void GLMoleculeView::hearMoleculeSelected(molecule *mol)
|
---|
1264 | //{
|
---|
1265 | // if (isSignaller) { // if we emitted the signal, return
|
---|
1266 | // isSignaller = false;
|
---|
1267 | // return;
|
---|
1268 | // }
|
---|
1269 | // initializeGL();
|
---|
1270 | // updateGL();
|
---|
1271 | //};
|
---|
1272 | //
|
---|
1273 | ///** Hear announcement of selected atom.
|
---|
1274 | // * \param *mol pointer to molecule containing atom
|
---|
1275 | // * \param *Walker pointer to selected atom
|
---|
1276 | // */
|
---|
1277 | //void GLMoleculeView::hearAtomSelected(molecule *mol, atom *Walker)
|
---|
1278 | //{
|
---|
1279 | // if (isSignaller) { // if we emitted the signal, return
|
---|
1280 | // isSignaller = false;
|
---|
1281 | // return;
|
---|
1282 | // }
|
---|
1283 | // initializeGL();
|
---|
1284 | // updateGL();
|
---|
1285 | //};
|
---|
1286 | //
|
---|
1287 | ///** Hear announcement of changed molecule.
|
---|
1288 | // * \param *mol pointer to changed molecule
|
---|
1289 | // * \param type of change
|
---|
1290 | // */
|
---|
1291 | //void GLMoleculeView::hearMoleculeChanged(molecule *mol, enum ChangesinMolecule type)
|
---|
1292 | //{
|
---|
1293 | // if (isSignaller) { // if we emitted the signal, return
|
---|
1294 | // isSignaller = false;
|
---|
1295 | // return;
|
---|
1296 | // }
|
---|
1297 | // initializeGL();
|
---|
1298 | // updateGL();
|
---|
1299 | //};
|
---|
1300 | //
|
---|
1301 | ///** Hear announcement of changed atom.
|
---|
1302 | // * \param *mol pointer to molecule containing atom
|
---|
1303 | // * \param *Walker pointer to changed atom
|
---|
1304 | // * \param type type of change
|
---|
1305 | // */
|
---|
1306 | //void GLMoleculeView::hearAtomChanged(molecule *mol, atom *Walker, enum ChangesinAtom type)
|
---|
1307 | //{
|
---|
1308 | // if (isSignaller) { // if we emitted the signal, return
|
---|
1309 | // isSignaller = false;
|
---|
1310 | // return;
|
---|
1311 | // }
|
---|
1312 | // initializeGL();
|
---|
1313 | // updateGL();
|
---|
1314 | //};
|
---|
1315 | //
|
---|
1316 | ///** Hear announcement of changed element.
|
---|
1317 | // * \param *Runner pointer to changed element
|
---|
1318 | // * \param type of change
|
---|
1319 | // */
|
---|
1320 | //void GLMoleculeView::hearElementChanged(element *Runner, enum ChangesinElement type)
|
---|
1321 | //{
|
---|
1322 | // if (isSignaller) { // if we emitted the signal, return
|
---|
1323 | // isSignaller = false;
|
---|
1324 | // return;
|
---|
1325 | // }
|
---|
1326 | // switch(type) {
|
---|
1327 | // default:
|
---|
1328 | // case ElementName:
|
---|
1329 | // case ElementSymbol:
|
---|
1330 | // case ElementMass:
|
---|
1331 | // case ElementValence:
|
---|
1332 | // case ElementZ:
|
---|
1333 | // break;
|
---|
1334 | // case ElementCovalent:
|
---|
1335 | // case ElementVanderWaals:
|
---|
1336 | // initializeGL();
|
---|
1337 | // updateGL();
|
---|
1338 | // break;
|
---|
1339 | // }
|
---|
1340 | //};
|
---|
1341 | //
|
---|
1342 | ///** Hear announcement of added molecule.
|
---|
1343 | // * \param *mol pointer to added molecule
|
---|
1344 | // */
|
---|
1345 | //void GLMoleculeView::hearMoleculeAdded(molecule *mol)
|
---|
1346 | //{
|
---|
1347 | // if (isSignaller) { // if we emitted the signal, return
|
---|
1348 | // isSignaller = false;
|
---|
1349 | // return;
|
---|
1350 | // }
|
---|
1351 | // initializeGL();
|
---|
1352 | // updateGL();
|
---|
1353 | //};
|
---|
1354 | //
|
---|
1355 | ///** Hear announcement of added atom.
|
---|
1356 | // * \param *mol pointer to molecule containing atom
|
---|
1357 | // * \param *Walker pointer to added atom
|
---|
1358 | // */
|
---|
1359 | //void GLMoleculeView::hearAtomAdded(molecule *mol, atom *Walker)
|
---|
1360 | //{
|
---|
1361 | // if (isSignaller) { // if we emitted the signal, return
|
---|
1362 | // isSignaller = false;
|
---|
1363 | // return;
|
---|
1364 | // }
|
---|
1365 | // initializeGL();
|
---|
1366 | // updateGL();
|
---|
1367 | //};
|
---|
1368 | //
|
---|
1369 | ///** Hear announcement of removed molecule.
|
---|
1370 | // * \param *mol pointer to removed molecule
|
---|
1371 | // */
|
---|
1372 | //void GLMoleculeView::hearMoleculeRemoved(molecule *mol)
|
---|
1373 | //{
|
---|
1374 | // if (isSignaller) { // if we emitted the signal, return
|
---|
1375 | // isSignaller = false;
|
---|
1376 | // return;
|
---|
1377 | // }
|
---|
1378 | // initializeGL();
|
---|
1379 | // updateGL();
|
---|
1380 | //};
|
---|
1381 | //
|
---|
1382 | ///** Hear announcement of removed atom.
|
---|
1383 | // * \param *mol pointer to molecule containing atom
|
---|
1384 | // * \param *Walker pointer to removed atom
|
---|
1385 | // */
|
---|
1386 | //void GLMoleculeView::hearAtomRemoved(molecule *mol, atom *Walker)
|
---|
1387 | //{
|
---|
1388 | // if (isSignaller) { // if we emitted the signal, return
|
---|
1389 | // isSignaller = false;
|
---|
1390 | // return;
|
---|
1391 | // }
|
---|
1392 | // initializeGL();
|
---|
1393 | // updateGL();
|
---|
1394 | //};
|
---|
1395 | //
|
---|
1396 | //void GLMoleculeView::update(Observable *publisher)
|
---|
1397 | //{
|
---|
1398 | // initializeGL();
|
---|
1399 | // updateGL();
|
---|
1400 | //}
|
---|
1401 | //
|
---|
1402 | ///**
|
---|
1403 | // * This method is called when a special named change
|
---|
1404 | // * of the Observable occured
|
---|
1405 | // */
|
---|
1406 | //void GLMoleculeView::recieveNotification(Observable *publisher, Notification_ptr notification)
|
---|
1407 | //{
|
---|
1408 | // initializeGL();
|
---|
1409 | // updateGL();
|
---|
1410 | //}
|
---|
1411 | //
|
---|
1412 | ///**
|
---|
1413 | // * This method is called when the observed object is destroyed.
|
---|
1414 | // */
|
---|
1415 | //void GLMoleculeView::subjectKilled(Observable *publisher)
|
---|
1416 | //{
|
---|
1417 | //
|
---|
1418 | //}
|
---|
1419 | //
|
---|
1420 | //
|
---|
1421 | //// new stuff
|
---|
1422 | //
|
---|
1423 | ///** Returns the ref to the Material for element No \a from the map.
|
---|
1424 | // *
|
---|
1425 | // * \note We create a new one if the element is missing.
|
---|
1426 | // *
|
---|
1427 | // * @param no element no
|
---|
1428 | // * @return ref to QGLMaterial
|
---|
1429 | // */
|
---|
1430 | //QGLMaterial* GLMoleculeView::getMaterial(size_t no)
|
---|
1431 | //{
|
---|
1432 | // if (ElementNoMaterialMap.find(no) != ElementNoMaterialMap.end()){
|
---|
1433 | // // get present one
|
---|
1434 | //
|
---|
1435 | // } else {
|
---|
1436 | // ASSERT( (no >= 0) && (no < MAX_ELEMENTS),
|
---|
1437 | // "GLMoleculeView::getMaterial() - Element no "+toString(no)+" is invalid.");
|
---|
1438 | // // create new one
|
---|
1439 | // LOG(1, "Creating new material for element "+toString(no)+".");
|
---|
1440 | // QGLMaterial *newmaterial = new QGLMaterial(this);
|
---|
1441 | // periodentafel *periode = World::getInstance().getPeriode();
|
---|
1442 | // element *desiredelement = periode->FindElement(no);
|
---|
1443 | // ASSERT(desiredelement != NULL,
|
---|
1444 | // "GLMoleculeView::getMaterial() - desired element "+toString(no)+" not present in periodentafel.");
|
---|
1445 | // const unsigned char* color = desiredelement->getColor();
|
---|
1446 | // newmaterial->setAmbientColor( QColor(color[0], color[1], color[2]) );
|
---|
1447 | // newmaterial->setSpecularColor( QColor(60, 60, 60) );
|
---|
1448 | // newmaterial->setShininess( QColor(128) );
|
---|
1449 | // ElementNoMaterialMap.insert( no, newmaterial);
|
---|
1450 | // }
|
---|
1451 | //}
|
---|
1452 | //
|
---|
1453 | //QGLSceneNode* GLMoleculeView::getAtom(size_t no)
|
---|
1454 | //{
|
---|
1455 | // // first some sensibility checks
|
---|
1456 | // ASSERT(World::getInstance().getAtom(AtomById(no)) != NULL,
|
---|
1457 | // "GLMoleculeView::getAtom() - desired atom "
|
---|
1458 | // +toString(no)+" not present in the World.");
|
---|
1459 | // ASSERT(AtomsinSceneMap.find(no) != AtomsinSceneMap.end(),
|
---|
1460 | // "GLMoleculeView::getAtom() - desired atom "
|
---|
1461 | // +toString(no)+" not present in the AtomsinSceneMap.");
|
---|
1462 | //
|
---|
1463 | // return AtomsinSceneMap[no];
|
---|
1464 | //}
|
---|
1465 | //
|
---|
1466 | //QGLSceneNode* GLMoleculeView::getBond(size_t leftno, size_t rightno)
|
---|
1467 | //{
|
---|
1468 | // // first some sensibility checks
|
---|
1469 | // ASSERT(World::getInstance().getAtom(AtomById(leftno)) != NULL,
|
---|
1470 | // "GLMoleculeView::getAtom() - desired atom "
|
---|
1471 | // +toString(leftno)+" of bond not present in the World.");
|
---|
1472 | // ASSERT(World::getInstance().getAtom(AtomById(rightno)) != NULL,
|
---|
1473 | // "GLMoleculeView::getAtom() - desired atom "
|
---|
1474 | // +toString(rightno)+" of bond not present in the World.");
|
---|
1475 | // ASSERT(AtomsinSceneMap.find(leftno) != AtomsinSceneMap.end(),
|
---|
1476 | // "GLMoleculeView::getAtom() - desired atom "
|
---|
1477 | // +toString(leftno)+" of bond not present in the AtomsinSceneMap.");
|
---|
1478 | // ASSERT(AtomsinSceneMap.find(rightno) != AtomsinSceneMap.end(),
|
---|
1479 | // "GLMoleculeView::getAtom() - desired atom "
|
---|
1480 | // +toString(rightno)+" of bond not present in the AtomsinSceneMap.");
|
---|
1481 | // ASSERT(leftno == rightno,
|
---|
1482 | // "GLMoleculeView::getAtom() - bond must not be between the same atom: "
|
---|
1483 | // +toString(leftno)+" == "+toString(rightno)+".");
|
---|
1484 | //
|
---|
1485 | // // then return with smaller index first
|
---|
1486 | // if (leftno > rightno)
|
---|
1487 | // return AtomsinSceneMap[ make_pair(rightno, leftno) ];
|
---|
1488 | // else
|
---|
1489 | // return AtomsinSceneMap[ make_pair(leftno, rightno) ];
|
---|
1490 | //}
|
---|
1491 | //
|
---|