1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * This file is part of MoleCuilder.
|
---|
8 | *
|
---|
9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * GLMoleculeObject_molecule.cpp
|
---|
25 | *
|
---|
26 | * Created on: Mar 30, 2012
|
---|
27 | * Author: ankele
|
---|
28 | */
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 | // include config.h
|
---|
35 | #ifdef HAVE_CONFIG_H
|
---|
36 | #include <config.h>
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #include "GLMoleculeObject_molecule.hpp"
|
---|
40 |
|
---|
41 | #include <Qt3D/qglscenenode.h>
|
---|
42 |
|
---|
43 | #include "CodePatterns/MemDebug.hpp"
|
---|
44 |
|
---|
45 | #include "CodePatterns/Assert.hpp"
|
---|
46 | #include "CodePatterns/Log.hpp"
|
---|
47 | #include "CodePatterns/Observer/Notification.hpp"
|
---|
48 | #include "CodePatterns/Observer/ObserverLog.hpp"
|
---|
49 |
|
---|
50 | #include "Atom/atom.hpp"
|
---|
51 | #include "molecule.hpp"
|
---|
52 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
53 | #include "Element/element.hpp"
|
---|
54 | #include "LinearAlgebra/Vector.hpp"
|
---|
55 | #include "World.hpp"
|
---|
56 |
|
---|
57 | GLMoleculeObject_molecule::GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const molecule *molref) :
|
---|
58 | GLMoleculeObject(mesh, parent),
|
---|
59 | Observer(std::string("GLMoleculeObject_molecule")+toString(molref->getId())),
|
---|
60 | _molecule(molref)
|
---|
61 | {
|
---|
62 | // sign on as observer (obtain non-const instance before)
|
---|
63 | /*molref->signOn(this, AtomObservable::IndexChanged);
|
---|
64 | molref->signOn(this, AtomObservable::PositionChanged);
|
---|
65 | molref->signOn(this, AtomObservable::ElementChanged);
|
---|
66 | molref->signOn(this, AtomObservable::BondsAdded);*/
|
---|
67 | setMaterial(getMaterial(1));
|
---|
68 | World::getInstance().signOn(this, World::SelectionChanged);
|
---|
69 | updateBoundingBox();
|
---|
70 | }
|
---|
71 |
|
---|
72 | GLMoleculeObject_molecule::~GLMoleculeObject_molecule()
|
---|
73 | {
|
---|
74 | /*_atom->signOff(this, AtomObservable::IndexChanged);
|
---|
75 | _atom->signOff(this, AtomObservable::PositionChanged);
|
---|
76 | _atom->signOff(this, AtomObservable::ElementChanged);
|
---|
77 | _atom->signOff(this, AtomObservable::BondsAdded);*/
|
---|
78 | World::getInstance().signOff(this, World::SelectionChanged);
|
---|
79 | }
|
---|
80 |
|
---|
81 | void GLMoleculeObject_molecule::updateBoundingBox()
|
---|
82 | {
|
---|
83 | Shape shape = _molecule->getBoundingShape();
|
---|
84 | Vector v = shape.getCenter();
|
---|
85 | setPosition(QVector3D(v[0], v[1], v[2]));
|
---|
86 | setScale(shape.getRadius() + 0.3); // getBoundingShape() only sees atoms as points, so make the box a bit bigger
|
---|
87 | }
|
---|
88 |
|
---|
89 | void GLMoleculeObject_molecule::update(Observable *publisher)
|
---|
90 | {
|
---|
91 | #ifdef LOG_OBSERVER
|
---|
92 | observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(this) << " from atom "+toString(_atom->getId())+".";
|
---|
93 | #endif
|
---|
94 | }
|
---|
95 |
|
---|
96 | void GLMoleculeObject_molecule::subjectKilled(Observable *publisher)
|
---|
97 | {}
|
---|
98 |
|
---|
99 | void GLMoleculeObject_molecule::recieveNotification(Observable *publisher, Notification_ptr notification)
|
---|
100 | {
|
---|
101 | if (publisher == dynamic_cast<const Observable*>(_molecule)){
|
---|
102 | // notofication from atom
|
---|
103 | #ifdef LOG_OBSERVER
|
---|
104 | observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)
|
---|
105 | << " received notification from molecule " << _molecule->getId() << " for channel "
|
---|
106 | << notification->getChannelNo() << ".";
|
---|
107 | #endif
|
---|
108 | }else{
|
---|
109 | // notification from world
|
---|
110 | #ifdef LOG_OBSERVER
|
---|
111 | observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)
|
---|
112 | << " received notification from world for channel "
|
---|
113 | << notification->getChannelNo() << ".";
|
---|
114 | #endif
|
---|
115 | switch (notification->getChannelNo()) {
|
---|
116 | case World::SelectionChanged:
|
---|
117 | setSelected(World::getInstance().isSelected(_molecule));
|
---|
118 | break;
|
---|
119 | default:
|
---|
120 | break;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|