1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * GLMoleculeScene.cpp
|
---|
10 | *
|
---|
11 | * This is based on the Qt3D example "teaservice", specifically sceneobject.cpp.
|
---|
12 | *
|
---|
13 | * Created on: Aug 17, 2011
|
---|
14 | * Author: heber
|
---|
15 | */
|
---|
16 |
|
---|
17 | // include config.h
|
---|
18 | #ifdef HAVE_CONFIG_H
|
---|
19 | #include <config.h>
|
---|
20 | #endif
|
---|
21 |
|
---|
22 | #include "GLMoleculeScene.hpp"
|
---|
23 |
|
---|
24 | #include "GLMoleculeObject.hpp"
|
---|
25 | #include "GLMoleculeObject_atom.hpp"
|
---|
26 | #include "GLMoleculeObject_bond.hpp"
|
---|
27 |
|
---|
28 | #include "CodePatterns/MemDebug.hpp"
|
---|
29 |
|
---|
30 | #include "atom.hpp"
|
---|
31 | #include "Bond/bond.hpp"
|
---|
32 | #include "molecule.hpp"
|
---|
33 |
|
---|
34 |
|
---|
35 | GLMoleculeScene::GLMoleculeScene(QObject *parent, molecule *_mol) :
|
---|
36 | QObject(parent), mol(_mol)
|
---|
37 | {
|
---|
38 | for (molecule::const_iterator atomiter = mol->begin();
|
---|
39 | atomiter != mol->end();
|
---|
40 | ++atomiter) {
|
---|
41 | // create atom objects in scene
|
---|
42 | GLMoleculeObject_atom *atomObject= new GLMoleculeObject_atom(this, *atomiter);
|
---|
43 | AtomsinMoleculeMap.insert( make_pair((*atomiter)->getId(), atomObject) );
|
---|
44 | connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
|
---|
45 | connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(hoverChanged()));
|
---|
46 |
|
---|
47 | // create its bonds
|
---|
48 | const BondList &bonds = (*atomiter)->getListOfBonds();
|
---|
49 | for (BondList::const_iterator bonditer = bonds.begin();
|
---|
50 | bonditer != bonds.end();
|
---|
51 | ++bonditer) {
|
---|
52 | if ((*bonditer)->leftatom->getId() == (*atomiter)->getId()) {
|
---|
53 | // create bond objects in scene
|
---|
54 | const double distance =
|
---|
55 | (*bonditer)->leftatom->getPosition().distance((*bonditer)->rightatom->getPosition())/2.;
|
---|
56 | GLMoleculeObject_bond *bondObject= new GLMoleculeObject_bond(this, *bonditer, distance, GLMoleculeObject_bond::left);
|
---|
57 | BondsinMoleculeMap.insert( make_pair(
|
---|
58 | make_pair(
|
---|
59 | (*bonditer)->leftatom->getId(),
|
---|
60 | (*bonditer)->rightatom->getId()
|
---|
61 | ),
|
---|
62 | bondObject) );
|
---|
63 | bondObject= new GLMoleculeObject_bond(this, *bonditer, distance, GLMoleculeObject_bond::right);
|
---|
64 | BondsinMoleculeMap.insert( make_pair(
|
---|
65 | make_pair(
|
---|
66 | (*bonditer)->rightatom->getId(),
|
---|
67 | (*bonditer)->leftatom->getId()
|
---|
68 | ),
|
---|
69 | bondObject) );
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | GLMoleculeScene::~GLMoleculeScene()
|
---|
76 | {
|
---|
77 | // remove all elements
|
---|
78 | GLMoleculeObject::cleanMaterialMap();
|
---|
79 | }
|
---|
80 |
|
---|
81 | void GLMoleculeScene::initialize(QGLView *view, QGLPainter *painter)
|
---|
82 | {
|
---|
83 | // Initialize all of the mesh objects that we have as children.
|
---|
84 | foreach (QObject *obj, children()) {
|
---|
85 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
86 | if (meshobj)
|
---|
87 | meshobj->initialize(view, painter);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | void GLMoleculeScene::draw(QGLPainter *painter)
|
---|
92 | {
|
---|
93 | // Draw all of the mesh objects that we have as children.
|
---|
94 | foreach (QObject *obj, children()) {
|
---|
95 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
96 | if (meshobj)
|
---|
97 | meshobj->draw(painter);
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | void GLMoleculeScene::atomClicked(atomId_t no)
|
---|
102 | {
|
---|
103 | qDebug("GLMoleculeScene: atom %d has been clicked inside molecule %d", no, mol->getId());
|
---|
104 | emit clicked(no, mol->getId());
|
---|
105 | }
|
---|