[c67518] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[5aaa43] | 5 | * Copyright (C) 2013 Frederik Heber. All rights reserved.
|
---|
[94d5ac6] | 6 | *
|
---|
| 7 | *
|
---|
| 8 | * This file is part of MoleCuilder.
|
---|
| 9 | *
|
---|
| 10 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[c67518] | 22 | */
|
---|
| 23 |
|
---|
| 24 | /*
|
---|
| 25 | * GLMoleculeObject_molecule.cpp
|
---|
| 26 | *
|
---|
| 27 | * Created on: Mar 30, 2012
|
---|
| 28 | * Author: ankele
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | // include config.h
|
---|
| 33 | #ifdef HAVE_CONFIG_H
|
---|
| 34 | #include <config.h>
|
---|
| 35 | #endif
|
---|
| 36 |
|
---|
| 37 | #include "GLMoleculeObject_molecule.hpp"
|
---|
| 38 |
|
---|
| 39 | #include <Qt3D/qglscenenode.h>
|
---|
[34e7fdb] | 40 | #include <Qt3D/qglbuilder.h>
|
---|
[c67518] | 41 |
|
---|
| 42 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 43 |
|
---|
[6c16a0] | 44 | #include <boost/assign.hpp>
|
---|
| 45 |
|
---|
[c67518] | 46 | #include "CodePatterns/Assert.hpp"
|
---|
[8d5fbf1] | 47 | #include "CodePatterns/IteratorAdaptors.hpp"
|
---|
[c67518] | 48 | #include "CodePatterns/Log.hpp"
|
---|
| 49 | #include "CodePatterns/Observer/Notification.hpp"
|
---|
[856d05] | 50 | #include "CodePatterns/Observer/ObserverLog.hpp"
|
---|
[c67518] | 51 |
|
---|
| 52 | #include "Atom/atom.hpp"
|
---|
| 53 | #include "molecule.hpp"
|
---|
| 54 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
[704d59] | 55 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
[c67518] | 56 | #include "Element/element.hpp"
|
---|
| 57 | #include "LinearAlgebra/Vector.hpp"
|
---|
[34e7fdb] | 58 | #include "LinkedCell/PointCloudAdaptor.hpp"
|
---|
| 59 | #include "LinkedCell/linkedcell.hpp"
|
---|
| 60 | #include "Tesselation/tesselation.hpp"
|
---|
| 61 | #include "Tesselation/BoundaryLineSet.hpp"
|
---|
| 62 | #include "Tesselation/BoundaryTriangleSet.hpp"
|
---|
| 63 | #include "Tesselation/CandidateForTesselation.hpp"
|
---|
[2f7988] | 64 | #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
|
---|
[34e7fdb] | 65 | #include "Atom/TesselPoint.hpp"
|
---|
[c67518] | 66 | #include "World.hpp"
|
---|
| 67 |
|
---|
[7c7c4a] | 68 | #include "ObservedValue_wCallback.hpp"
|
---|
[8688ef] | 69 | #include "ObservedValue_UpdateAtoms.hpp"
|
---|
[7c7c4a] | 70 |
|
---|
[6c16a0] | 71 | using namespace boost::assign;
|
---|
| 72 |
|
---|
[8c001a] | 73 | #include "GLMoleculeObject_atom.hpp"
|
---|
| 74 |
|
---|
[8d5fbf1] | 75 | static Observable::channels_t getAllAtomicChangesChannels()
|
---|
[34e7fdb] | 76 | {
|
---|
[6c16a0] | 77 | Observable::channels_t channels;
|
---|
[8d5fbf1] | 78 | channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
|
---|
[6c16a0] | 79 | return channels;
|
---|
| 80 | }
|
---|
[34e7fdb] | 81 |
|
---|
[8d5fbf1] | 82 | static Observable::channels_t getAllAtomicObservedChannels()
|
---|
[6c16a0] | 83 | {
|
---|
| 84 | Observable::channels_t channels;
|
---|
| 85 | channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
|
---|
| 86 | return channels;
|
---|
| 87 | }
|
---|
[34e7fdb] | 88 |
|
---|
[6c16a0] | 89 | // static instances
|
---|
| 90 | const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels());
|
---|
[e39e7a] | 91 | const Observable::channels_t GLMoleculeObject_molecule::BoundingBoxChannels(1, molecule::BoundingBoxChanged);
|
---|
[6c16a0] | 92 | const Observable::channels_t GLMoleculeObject_molecule::IndexChannels(1, molecule::IndexChanged);
|
---|
[5b61e5] | 93 | const Observable::channels_t GLMoleculeObject_molecule::NameChannels(1, molecule::MoleculeNameChanged);
|
---|
[34e7fdb] | 94 |
|
---|
[6c16a0] | 95 | static QGLSceneNode *createMoleculeMesh(const QGeometryData &_geo)
|
---|
| 96 | {
|
---|
[34e7fdb] | 97 | // Build a mesh from the geometry.
|
---|
| 98 | QGLBuilder builder;
|
---|
[6c16a0] | 99 | builder.addTriangles(_geo);
|
---|
[34e7fdb] | 100 | QGLSceneNode *mesh = builder.finalizedSceneNode();
|
---|
| 101 | return mesh;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[8d5fbf1] | 104 | GLMoleculeObject_molecule::GLMoleculeObject_molecule(
|
---|
| 105 | QObject *parent,
|
---|
| 106 | const moleculeId_t _molid,
|
---|
[2f7988] | 107 | QtObservedInstanceBoard * _board,
|
---|
[8d5fbf1] | 108 | std::vector<boost::any> _ObservedValues) :
|
---|
[6c16a0] | 109 | GLMoleculeObject((QGLSceneNode *)NULL, parent),
|
---|
| 110 | Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)),
|
---|
| 111 | owner(NULL),
|
---|
| 112 | molref(getMolecule(_molid)),
|
---|
| 113 | /* We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
|
---|
| 114 | * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
|
---|
| 115 | * the class has not been fully constructed yet. "This" itself seems to be working fine.
|
---|
| 116 | */
|
---|
[8d5fbf1] | 117 | ObservedValues(_ObservedValues),
|
---|
[8688ef] | 118 | subjectKilledCount(0),
|
---|
[6c16a0] | 119 | TesselationHullUpdater(
|
---|
| 120 | boost::bind(&GLMoleculeObject_molecule::updateTesselationHull, this)
|
---|
| 121 | ),
|
---|
| 122 | TesselationHull(
|
---|
| 123 | molref,
|
---|
| 124 | TesselationHullUpdater,
|
---|
| 125 | "MoleculeTesselationHull_"+toString(_molid),
|
---|
| 126 | HullChannels),
|
---|
[8d5fbf1] | 127 | hoverAtomId(-1),
|
---|
| 128 | AllsignedOnChannels(getAllAtomicObservedChannels().size()),
|
---|
| 129 | signedOnChannels(0),
|
---|
| 130 | board(_board)
|
---|
[34e7fdb] | 131 | {
|
---|
[8d5fbf1] | 132 | init(_molid);
|
---|
[34e7fdb] | 133 | }
|
---|
| 134 |
|
---|
[026bef] | 135 | GLMoleculeObject_molecule::GLMoleculeObject_molecule(
|
---|
| 136 | QGLSceneNode *mesh[],
|
---|
| 137 | QObject *parent,
|
---|
[8d5fbf1] | 138 | const moleculeId_t _molid,
|
---|
[2f7988] | 139 | QtObservedInstanceBoard * _board,
|
---|
[8d5fbf1] | 140 | std::vector<boost::any> _ObservedValues) :
|
---|
[bca99d] | 141 | GLMoleculeObject(mesh, parent),
|
---|
[6c16a0] | 142 | Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)),
|
---|
| 143 | owner(NULL),
|
---|
| 144 | molref(getMolecule(_molid)),
|
---|
| 145 | /* We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
|
---|
| 146 | * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
|
---|
| 147 | * the class has not been fully constructed yet. "This" itself seems to be working fine.
|
---|
| 148 | */
|
---|
[8d5fbf1] | 149 | ObservedValues(_ObservedValues),
|
---|
[8688ef] | 150 | subjectKilledCount(0),
|
---|
[6c16a0] | 151 | TesselationHullUpdater(
|
---|
| 152 | boost::bind(&GLMoleculeObject_molecule::updateTesselationHull, this)
|
---|
| 153 | ),
|
---|
| 154 | TesselationHull(
|
---|
| 155 | molref,
|
---|
| 156 | TesselationHullUpdater,
|
---|
| 157 | "MoleculeTesselationHull_"+toString(_molid),
|
---|
| 158 | HullChannels),
|
---|
[8d5fbf1] | 159 | hoverAtomId(-1),
|
---|
| 160 | AllsignedOnChannels(getAllAtomicObservedChannels().size()),
|
---|
| 161 | signedOnChannels(0),
|
---|
| 162 | board(_board)
|
---|
[c67518] | 163 | {
|
---|
[8d5fbf1] | 164 | init(_molid);
|
---|
| 165 | }
|
---|
[7c7c4a] | 166 |
|
---|
[8d5fbf1] | 167 | void GLMoleculeObject_molecule::init(const moleculeId_t _molid)
|
---|
| 168 | {
|
---|
[6c16a0] | 169 | setObjectId(_molid);
|
---|
[3b229e] | 170 | setMaterial(getMaterial(1));
|
---|
[8c001a] | 171 |
|
---|
[a39d72] | 172 | m_selected = const_cast<const World &>(World::getInstance()).isMoleculeSelected(_molid);
|
---|
| 173 |
|
---|
[739ee9] | 174 | // initially, atoms and bonds should be visible
|
---|
| 175 | m_visible = false;
|
---|
| 176 |
|
---|
[8d5fbf1] | 177 | activateObserver();
|
---|
| 178 |
|
---|
[2b596f] | 179 | connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
|
---|
| 180 | connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
|
---|
[6c16a0] | 181 | connect (this, SIGNAL(TesselationHullChanged()), this, SLOT(resetTesselationHull()), Qt::QueuedConnection);
|
---|
| 182 | connect (this, SIGNAL(BoundingBoxChanged()), this, SLOT(resetBoundingBox()), Qt::QueuedConnection);
|
---|
| 183 | connect (this, SIGNAL(IdChanged()), this, SLOT(resetIndex()), Qt::QueuedConnection);
|
---|
| 184 | connect (this, SIGNAL(AtomInserted(const atomId_t)), this, SLOT(atomInserted(const atomId_t)), Qt::QueuedConnection);
|
---|
| 185 | connect (this, SIGNAL(AtomRemoved(const atomId_t)), this, SLOT(atomRemoved(const atomId_t)), Qt::QueuedConnection);
|
---|
[0f7ffe] | 186 | if (board != NULL) {
|
---|
| 187 | connect(board, SIGNAL(atomInserted(const atomId_t)),
|
---|
| 188 | this, SLOT(atomInserted(const atomId_t)));
|
---|
| 189 | connect(board, SIGNAL(atomRemoved(const atomId_t)),
|
---|
| 190 | this, SLOT(atomRemoved(const atomId_t)));
|
---|
| 191 | }
|
---|
[9a7ef9] | 192 |
|
---|
| 193 | connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
|
---|
[c67518] | 194 | }
|
---|
| 195 |
|
---|
| 196 | GLMoleculeObject_molecule::~GLMoleculeObject_molecule()
|
---|
| 197 | {
|
---|
[6c16a0] | 198 | deactivateObserver();
|
---|
[8d5fbf1] | 199 | board->returnMoleculeObservedValues(getMolIndex(), ObservedValues);
|
---|
[6c16a0] | 200 | }
|
---|
| 201 |
|
---|
| 202 | void GLMoleculeObject_molecule::deactivateObserver()
|
---|
| 203 | {
|
---|
| 204 | if (owner != NULL) {
|
---|
[8d5fbf1] | 205 | Observable::channels_t channels = getAllAtomicObservedChannels();
|
---|
| 206 | for (Observable::channels_t::const_iterator iter = channels.begin();
|
---|
| 207 | iter != channels.end(); ++iter)
|
---|
| 208 | owner->signOff(this, *iter);
|
---|
[6c16a0] | 209 | owner = NULL;
|
---|
[8d5fbf1] | 210 | signedOnChannels = 0;
|
---|
[34e7fdb] | 211 | }
|
---|
[c67518] | 212 | }
|
---|
| 213 |
|
---|
[73b13c] | 214 | void GLMoleculeObject_molecule::activateObserver()
|
---|
| 215 | {
|
---|
| 216 | // sign on as observer (obtain non-const instance before)
|
---|
[7c7c4a] | 217 | const molecule * const _molecule = getMolecule(getMolIndex());
|
---|
[73b13c] | 218 | if (_molecule != NULL) {
|
---|
[8d5fbf1] | 219 | Observable::channels_t channels = getAllAtomicObservedChannels();
|
---|
[6c16a0] | 220 | owner = static_cast<const Observable *>(_molecule);
|
---|
[8d5fbf1] | 221 | for (Observable::channels_t::const_iterator iter = channels.begin();
|
---|
| 222 | iter != channels.end(); ++iter)
|
---|
| 223 | owner->signOn(this, *iter);
|
---|
[73b13c] | 224 | } else {
|
---|
[7c7c4a] | 225 | ELOG(1, "GLMoleculeObject_molecule() - added null object for not present mol id " << getMolIndex());
|
---|
[73b13c] | 226 | }
|
---|
[6c16a0] | 227 |
|
---|
[73b13c] | 228 | }
|
---|
| 229 |
|
---|
[8c001a] | 230 | void GLMoleculeObject_molecule::addAtomBonds(
|
---|
| 231 | const bond::ptr &_bond,
|
---|
| 232 | const GLMoleculeObject_bond::SideOfBond _side
|
---|
| 233 | )
|
---|
| 234 | {
|
---|
| 235 | bool bond_present = false;
|
---|
| 236 | const BondIds ids = getBondIds(_bond, _side);
|
---|
| 237 | // check whether bond is not present already
|
---|
| 238 | bond_present = BondsinSceneMap.count(ids);
|
---|
| 239 | if (!bond_present)
|
---|
[6c16a0] | 240 | bondInserted(ids.first, ids.second, _side);
|
---|
[8c001a] | 241 | else {
|
---|
| 242 | BondsinSceneMap[ids]->resetPosition();
|
---|
| 243 | BondsinSceneMap[ids]->resetWidth();
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 |
|
---|
[6c16a0] | 247 | QGeometryData GLMoleculeObject_molecule::updateTesselationHull() const
|
---|
| 248 | {
|
---|
| 249 | QGeometryData geo;
|
---|
| 250 |
|
---|
[7c7c4a] | 251 | const molecule * const molref = getMolecule(getMolIndex());
|
---|
[6c16a0] | 252 | if (molref == NULL) {
|
---|
[7c7c4a] | 253 | ELOG(1, "Could not createMoleculeMesh, molecule with id " << getMolIndex() << " already gone.");
|
---|
[6c16a0] | 254 | return geo;
|
---|
| 255 | }
|
---|
| 256 | double minradius = 2.; // TODO: set to maximum bond length value
|
---|
| 257 | LOG(3, "DEBUG: Molecule fits into sphere of radius " << minradius);
|
---|
| 258 | // check minimum bond radius in molecule
|
---|
| 259 | double minlength = std::numeric_limits<double>::max();
|
---|
| 260 | for (molecule::const_iterator iter = molref->begin();
|
---|
| 261 | iter != molref->end(); ++iter) {
|
---|
| 262 | const BondList &ListOfBonds = (*iter)->getListOfBonds();
|
---|
| 263 | for (BondList::const_iterator bonditer = ListOfBonds.begin();
|
---|
| 264 | bonditer != ListOfBonds.end(); ++bonditer) {
|
---|
| 265 | const double bond_distance = (*bonditer)->GetDistance();
|
---|
| 266 | minlength = std::min(bond_distance, minlength);
|
---|
| 267 | }
|
---|
| 268 | }
|
---|
| 269 | minradius = std::max( std::max(minradius, minlength), 1.);
|
---|
| 270 |
|
---|
| 271 | // we need at least three points for tesselation
|
---|
[7c7c4a] | 272 | if (getPresentAtoms().size() >= 3) {
|
---|
[6c16a0] | 273 | // Tesselate the points.
|
---|
| 274 | Tesselation T;
|
---|
[7c7c4a] | 275 | PointCloudAdaptor<molecule> cloud(const_cast<molecule *>(molref), getMolName());
|
---|
[6c16a0] | 276 | T(cloud, minradius);
|
---|
| 277 |
|
---|
| 278 | // Fill the points into a Qt geometry.
|
---|
| 279 | LinkedCell_deprecated LinkedList(cloud, minradius);
|
---|
| 280 | std::map<int, int> indices;
|
---|
| 281 | std::map<int, Vector> normals;
|
---|
| 282 | int index = 0;
|
---|
| 283 | for (PointMap::const_iterator piter = T.PointsOnBoundary.begin();
|
---|
| 284 | piter != T.PointsOnBoundary.end(); ++piter) {
|
---|
| 285 | const Vector &point = piter->second->getPosition();
|
---|
| 286 | // add data to the primitive
|
---|
| 287 | geo.appendVertex(QVector3D(point[0], point[1], point[2]));
|
---|
| 288 | Vector normalvector;
|
---|
| 289 | for (LineMap::const_iterator lineiter = piter->second->lines.begin();
|
---|
| 290 | lineiter != piter->second->lines.end(); ++lineiter)
|
---|
| 291 | for (TriangleMap::const_iterator triangleiter = lineiter->second->triangles.begin();
|
---|
| 292 | triangleiter != lineiter->second->triangles.end(); ++triangleiter)
|
---|
| 293 | normalvector +=
|
---|
| 294 | triangleiter->second->NormalVector;
|
---|
| 295 | normalvector.Normalize();
|
---|
| 296 | geo.appendNormal(QVector3D(normalvector[0], normalvector[1], normalvector[2]));
|
---|
| 297 | geo.appendColor(QColor(1, 1, 1, 1));
|
---|
| 298 | geo.appendTexCoord(QVector2D(0, 0));
|
---|
| 299 | indices.insert( std::make_pair( piter->second->getNr(), index++));
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | // Fill the tesselated triangles into the geometry.
|
---|
| 303 | for (TriangleMap::const_iterator runner = T.TrianglesOnBoundary.begin();
|
---|
| 304 | runner != T.TrianglesOnBoundary.end(); runner++) {
|
---|
| 305 | int v[3];
|
---|
| 306 | for (size_t i=0; i<3; ++i)
|
---|
| 307 | v[i] = runner->second->endpoints[i]->getNr();
|
---|
| 308 |
|
---|
| 309 | // Sort the vertices so the triangle is clockwise (relative to the normal vector).
|
---|
| 310 | Vector cross = T.PointsOnBoundary[v[1]]->getPosition() - T.PointsOnBoundary[v[0]]->getPosition();
|
---|
| 311 | cross.VectorProduct(T.PointsOnBoundary[v[2]]->getPosition() - T.PointsOnBoundary[v[0]]->getPosition());
|
---|
| 312 | if (cross.ScalarProduct(runner->second->NormalVector) > 0)
|
---|
| 313 | geo.appendIndices(indices[v[0]], indices[v[1]], indices[v[2]]);
|
---|
| 314 | else
|
---|
| 315 | geo.appendIndices(indices[v[0]], indices[v[2]], indices[v[1]]);
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | return geo;
|
---|
| 320 | }
|
---|
| 321 |
|
---|
[8688ef] | 322 | molecule::BoundingBoxInfo GLMoleculeObject_molecule::initBoundingBox()
|
---|
[6c16a0] | 323 | {
|
---|
[e39e7a] | 324 | molecule::BoundingBoxInfo info;
|
---|
[6fe4f7] | 325 | info.position = zeroVec;
|
---|
| 326 | info.radius = 0.;
|
---|
| 327 | return info;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
[8688ef] | 330 | molecule::BoundingBoxInfo GLMoleculeObject_molecule::updateBoundingBox(
|
---|
| 331 | const boost::function<const moleculeId_t ()> &_getMolIndex)
|
---|
[6fe4f7] | 332 | {
|
---|
[8688ef] | 333 | const molecule * const mol = getMolecule(_getMolIndex());
|
---|
| 334 | return mol->getBoundingBox();
|
---|
[6c16a0] | 335 | }
|
---|
| 336 |
|
---|
[8688ef] | 337 | moleculeId_t GLMoleculeObject_molecule::updateIndex()
|
---|
[d6203a] | 338 | {
|
---|
[54bdaa] | 339 | return const_cast<const World &>(World::getInstance()).lastChangedMolId();
|
---|
[6c16a0] | 340 | }
|
---|
| 341 |
|
---|
[8688ef] | 342 | std::string GLMoleculeObject_molecule::updateName(
|
---|
| 343 | const boost::function<const moleculeId_t ()> &_getMolIndex)
|
---|
[5b61e5] | 344 | {
|
---|
[8688ef] | 345 | const molecule * const mol = getMolecule(_getMolIndex());
|
---|
[5b61e5] | 346 | return mol->getName();
|
---|
| 347 | }
|
---|
| 348 |
|
---|
[6c16a0] | 349 | void GLMoleculeObject_molecule::resetTesselationHull()
|
---|
| 350 | {
|
---|
[0f7ffe] | 351 | // only when Observable still lives so far, we may check on Cacheable::isValid
|
---|
| 352 | if ((owner != NULL) && (!TesselationHull.isValid()))
|
---|
[6c16a0] | 353 | updateMesh(createMoleculeMesh(*TesselationHull));
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | void GLMoleculeObject_molecule::resetBoundingBox()
|
---|
| 357 | {
|
---|
[7c7c4a] | 358 | molecule::BoundingBoxInfo info = getBoundingBox();
|
---|
[6c16a0] | 359 | setPosition(QVector3D(info.position[0], info.position[1], info.position[2]));
|
---|
| 360 | setScale(info.radius + 0.3); // getBoundingSphere() only sees atoms as points, so make the box a bit bigger
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | void GLMoleculeObject_molecule::resetIndex()
|
---|
| 364 | {
|
---|
[7c7c4a] | 365 | const atomId_t newId = getMolIndex();
|
---|
[6c16a0] | 366 | const size_t oldId = objectId();
|
---|
| 367 | ASSERT( newId != oldId,
|
---|
| 368 | "GLMoleculeObject_molecule::resetIndex() - index "+toString(newId)+" did not change.");
|
---|
| 369 | LOG(4, "INFO: GLMoleculeObject_molecule: new index is "+toString(newId)+".");
|
---|
| 370 | setObjectId(newId);
|
---|
| 371 |
|
---|
| 372 | emit indexChanged(this, oldId, newId);
|
---|
[d6203a] | 373 | }
|
---|
| 374 |
|
---|
[5b61e5] | 375 | void GLMoleculeObject_molecule::resetName()
|
---|
| 376 | {
|
---|
| 377 | }
|
---|
| 378 |
|
---|
[015f8c] | 379 | void GLMoleculeObject_molecule::AtomSelected(const atomId_t _id)
|
---|
| 380 | {
|
---|
| 381 | AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
|
---|
[a39d72] | 382 | if (iter != AtomsinSceneMap.end())
|
---|
| 383 | QMetaObject::invokeMethod(iter->second, // pointer to a QObject
|
---|
[015f8c] | 384 | "Selected", // member name (no parameters here)
|
---|
| 385 | Qt::QueuedConnection); // connection type
|
---|
[a39d72] | 386 | else
|
---|
| 387 | ELOG(2, "GLMoleculeObject_molecule::AtomSelected() - atom "
|
---|
| 388 | << _id << " unknown to GLMoleculeObject_molecule.");
|
---|
[015f8c] | 389 | }
|
---|
| 390 |
|
---|
| 391 | void GLMoleculeObject_molecule::AtomUnselected(const atomId_t _id)
|
---|
| 392 | {
|
---|
| 393 | AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
|
---|
[a39d72] | 394 | if (iter != AtomsinSceneMap.end())
|
---|
| 395 | QMetaObject::invokeMethod(iter->second, // pointer to a QObject
|
---|
[015f8c] | 396 | "Unselected", // member name (no parameters here)
|
---|
| 397 | Qt::QueuedConnection); // connection type
|
---|
[a39d72] | 398 | else ELOG(2, "GLMoleculeObject_molecule::AtomUnselected() - atom "
|
---|
| 399 | << _id << " unknown to GLMoleculeObject_molecule.");
|
---|
[015f8c] | 400 | }
|
---|
| 401 |
|
---|
| 402 | void GLMoleculeObject_molecule::Selected()
|
---|
| 403 | {
|
---|
| 404 | ASSERT( !m_selected,
|
---|
| 405 | "GLMoleculeObject_molecule::Selected() - 3D rep of molecule is already selected.");
|
---|
| 406 | m_selected = true;
|
---|
| 407 |
|
---|
| 408 | emit changed();
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | void GLMoleculeObject_molecule::Unselected()
|
---|
| 412 | {
|
---|
| 413 | ASSERT( m_selected,
|
---|
| 414 | "GLMoleculeObject_molecule::Unselected() - 3D rep of molecule is already unselected.");
|
---|
| 415 | m_selected = false;
|
---|
| 416 |
|
---|
| 417 | emit changed();
|
---|
| 418 | }
|
---|
| 419 |
|
---|
[c67518] | 420 | void GLMoleculeObject_molecule::update(Observable *publisher)
|
---|
| 421 | {
|
---|
[92ee41] | 422 | ASSERT(0,
|
---|
| 423 | "GLMoleculeObject_molecule::update() - general update from unexpected source.");
|
---|
[c67518] | 424 | }
|
---|
| 425 |
|
---|
| 426 | void GLMoleculeObject_molecule::subjectKilled(Observable *publisher)
|
---|
[34e7fdb] | 427 | {
|
---|
[8d5fbf1] | 428 | ++signedOnChannels;
|
---|
[7c7c4a] | 429 |
|
---|
[8d5fbf1] | 430 | if (signedOnChannels == AllsignedOnChannels) {
|
---|
| 431 | // remove owner: no more signOff needed
|
---|
| 432 | owner = NULL;
|
---|
| 433 |
|
---|
| 434 | board->moleculecountsubjectKilled(getMolIndex());
|
---|
| 435 | }
|
---|
[34e7fdb] | 436 | }
|
---|
[c67518] | 437 |
|
---|
| 438 | void GLMoleculeObject_molecule::recieveNotification(Observable *publisher, Notification_ptr notification)
|
---|
| 439 | {
|
---|
[7c7c4a] | 440 | const molecule * const _molecule = getMolecule(getMolIndex());
|
---|
[cc2976] | 441 | // when molecule is NULL we will soon get destroyed anyway
|
---|
| 442 | if (_molecule == NULL)
|
---|
| 443 | return;
|
---|
[c67518] | 444 | if (publisher == dynamic_cast<const Observable*>(_molecule)){
|
---|
[8d5fbf1] | 445 | // notification from atom
|
---|
[c67518] | 446 | #ifdef LOG_OBSERVER
|
---|
[708277] | 447 | observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
|
---|
[7c7c4a] | 448 | << " received notification from molecule " << getMolIndex() << " for channel "
|
---|
[c67518] | 449 | << notification->getChannelNo() << ".";
|
---|
| 450 | #endif
|
---|
[8c001a] | 451 | switch (notification->getChannelNo()) {
|
---|
| 452 | case molecule::AtomInserted:
|
---|
[8d5fbf1] | 453 | case molecule::AtomRemoved:
|
---|
[7b5984] | 454 | case molecule::AtomMoved:
|
---|
| 455 | {
|
---|
| 456 | #ifdef LOG_OBSERVER
|
---|
| 457 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted.";
|
---|
| 458 | #endif
|
---|
[6c16a0] | 459 | emit TesselationHullChanged();
|
---|
| 460 | emit BoundingBoxChanged();
|
---|
| 461 | break;
|
---|
| 462 | }
|
---|
| 463 | case molecule::IndexChanged:
|
---|
| 464 | {
|
---|
| 465 | #ifdef LOG_OBSERVER
|
---|
[54bdaa] | 466 | const atomId_t _id = _molecule->lastChangedAtomId();
|
---|
[6c16a0] | 467 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+"'s index has changed.";
|
---|
| 468 | #endif
|
---|
| 469 | emit IdChanged();
|
---|
[7b5984] | 470 | break;
|
---|
| 471 | }
|
---|
[8c001a] | 472 | default:
|
---|
| 473 | break;
|
---|
| 474 | }
|
---|
[a39d72] | 475 | }
|
---|
[c67518] | 476 | }
|
---|
| 477 |
|
---|
[8c001a] | 478 | void GLMoleculeObject_molecule::initialize(QGLView *view, QGLPainter *painter)
|
---|
| 479 | {
|
---|
| 480 | // Initialize all of the mesh objects that we have as children.
|
---|
[2b596f] | 481 | if (m_visible) {
|
---|
| 482 | GLMoleculeObject::initialize(view, painter);
|
---|
| 483 | } else {
|
---|
[8c001a] | 484 | foreach (QObject *obj, children()) {
|
---|
| 485 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
| 486 | if (meshobj)
|
---|
| 487 | meshobj->initialize(view, painter);
|
---|
| 488 | }
|
---|
[2b596f] | 489 | }
|
---|
[8c001a] | 490 | }
|
---|
| 491 |
|
---|
| 492 | void GLMoleculeObject_molecule::draw(QGLPainter *painter, const QVector4D &cameraPlane)
|
---|
| 493 | {
|
---|
[739ee9] | 494 | // draw either molecule's mesh or all atoms and bonds
|
---|
| 495 | if (m_visible) {
|
---|
[6c16a0] | 496 | resetTesselationHull();
|
---|
[7b5984] | 497 |
|
---|
[34e7fdb] | 498 | painter->modelViewMatrix().push();
|
---|
| 499 |
|
---|
| 500 | // Apply the material and effect to the painter.
|
---|
| 501 | QGLMaterial *material;
|
---|
| 502 | if (m_hovering)
|
---|
| 503 | material = m_hoverMaterial;
|
---|
| 504 | else if (m_selected)
|
---|
| 505 | material = m_selectionMaterial;
|
---|
| 506 | else
|
---|
| 507 | material = m_material;
|
---|
| 508 |
|
---|
| 509 | ASSERT(material, "GLMoleculeObject::draw: chosen material is NULL");
|
---|
| 510 |
|
---|
| 511 | painter->setColor(material->diffuseColor());
|
---|
| 512 | painter->setFaceMaterial(QGL::AllFaces, material);
|
---|
| 513 | if (m_effect)
|
---|
| 514 | painter->setUserEffect(m_effect);
|
---|
| 515 | else
|
---|
| 516 | painter->setStandardEffect(QGL::LitMaterial);
|
---|
| 517 |
|
---|
| 518 | // Mark the object for object picking purposes.
|
---|
| 519 | int prevObjectId = painter->objectPickId();
|
---|
| 520 | if (m_objectId != -1)
|
---|
| 521 | painter->setObjectPickId(m_objectId);
|
---|
| 522 |
|
---|
| 523 | m_mesh[0]->draw(painter);
|
---|
| 524 |
|
---|
| 525 | // Turn off the user effect, if present.
|
---|
| 526 | if (m_effect)
|
---|
| 527 | painter->setStandardEffect(QGL::LitMaterial);
|
---|
| 528 |
|
---|
| 529 | // Revert to the previous object identifier.
|
---|
| 530 | painter->setObjectPickId(prevObjectId);
|
---|
| 531 |
|
---|
| 532 | // Restore the modelview matrix.
|
---|
| 533 | painter->modelViewMatrix().pop();
|
---|
| 534 |
|
---|
| 535 | // GLMoleculeObject::draw(painter, cameraPlane);
|
---|
[739ee9] | 536 | } else {
|
---|
| 537 | // Draw all of the mesh objects that we have as children.
|
---|
| 538 | foreach (QObject *obj, children()) {
|
---|
| 539 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
| 540 | if (meshobj)
|
---|
| 541 | meshobj->draw(painter, cameraPlane);
|
---|
| 542 | }
|
---|
[2b596f] | 543 |
|
---|
| 544 | // update bounding box prior to selection
|
---|
[6c16a0] | 545 | resetBoundingBox();
|
---|
[2b596f] | 546 |
|
---|
| 547 | painter->modelViewMatrix().push();
|
---|
| 548 | painter->modelViewMatrix().translate(m_position);
|
---|
| 549 | if (m_rotationAngle != 0.0f)
|
---|
| 550 | painter->modelViewMatrix().rotate(m_rotationAngle, m_rotationVector);
|
---|
[f47efd4] | 551 | if ((m_scaleX != 1.0f) || (m_scaleY != 1.0f) || (m_scaleZ != 1.0f))
|
---|
| 552 | painter->modelViewMatrix().scale(m_scaleX, m_scaleY, m_scaleZ);
|
---|
[2b596f] | 553 |
|
---|
| 554 | // Draw a box around the mesh, if selected.
|
---|
| 555 | if (m_selected)
|
---|
| 556 | drawSelectionBox(painter);
|
---|
| 557 |
|
---|
| 558 | // Restore the modelview matrix.
|
---|
| 559 | painter->modelViewMatrix().pop();
|
---|
[739ee9] | 560 | }
|
---|
[8c001a] | 561 | }
|
---|
| 562 |
|
---|
| 563 | /** Adds an atom of this molecule to the scene.
|
---|
| 564 | *
|
---|
| 565 | * @param _atom atom to add
|
---|
| 566 | */
|
---|
[2f76d2] | 567 | void GLMoleculeObject_molecule::atomInserted(const atomId_t _id)
|
---|
[8c001a] | 568 | {
|
---|
[9c259e] | 569 | LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomInserted for atom "+toString(_id)+".");
|
---|
| 570 |
|
---|
[8d5fbf1] | 571 | GLMoleculeObject_atom *atomObject =
|
---|
| 572 | new GLMoleculeObject_atom(
|
---|
| 573 | GLMoleculeObject::meshSphere,
|
---|
| 574 | this,
|
---|
| 575 | _id,
|
---|
| 576 | board,
|
---|
| 577 | board->getAtomObservedValues(_id));
|
---|
[8923ad8] | 578 | ASSERT( atomObject != NULL,
|
---|
| 579 | "GLMoleculeObject_molecule::atomInserted - could not create atom object for "+toString(_id));
|
---|
| 580 | AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
|
---|
| 581 | ASSERT(iter == AtomsinSceneMap.end(),
|
---|
| 582 | "GLMoleculeObject_molecule::atomInserted - same atom with id "+toString(_id)+" added again.");
|
---|
| 583 | AtomsinSceneMap.insert( make_pair(_id, atomObject) );
|
---|
| 584 |
|
---|
| 585 | qRegisterMetaType<atomId_t>("atomId_t");
|
---|
| 586 | qRegisterMetaType<bond::ptr>("bond::ptr");
|
---|
| 587 | qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
|
---|
| 588 | connect (atomObject, SIGNAL(clicked(atomId_t)), this, SIGNAL(atomClicked(atomId_t)));
|
---|
| 589 | connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
| 590 | connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
|
---|
| 591 | connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
|
---|
[f714763] | 592 | // connect (atomObject, SIGNAL(bondsChanged()), this, SLOT(bondInserted(const atomId_t, const atomId_t, const GLMoleculeObject_bond::SideOfBond)));
|
---|
[015f8c] | 593 | connect (atomObject, SIGNAL(BondsAdded(const atomId_t, const atomId_t, const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const atomId_t, const atomId_t, const GLMoleculeObject_bond::SideOfBond)));
|
---|
[6c16a0] | 594 | connect (atomObject, SIGNAL(BondsRemoved(const atomId_t, const atomId_t)), this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
|
---|
| 595 | connect (atomObject, SIGNAL(indexChanged(GLMoleculeObject_atom*, const atomId_t, const atomId_t)), this, SLOT(changeAtomId(GLMoleculeObject_atom*, const atomId_t, const atomId_t)));
|
---|
[8923ad8] | 596 |
|
---|
| 597 | if (m_objectId == -1)
|
---|
| 598 | setObjectId(_id);
|
---|
[8c001a] | 599 |
|
---|
[8d5fbf1] | 600 | emit changed();
|
---|
[8c001a] | 601 | emit changeOccured();
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | /** Removes an atom of this molecule from the scene.
|
---|
| 605 | *
|
---|
| 606 | * We just the id as the atom might have already been destroyed.
|
---|
| 607 | *
|
---|
| 608 | * @param _id id of atom to remove
|
---|
| 609 | */
|
---|
[2f76d2] | 610 | void GLMoleculeObject_molecule::atomRemoved(const atomId_t _id)
|
---|
[8c001a] | 611 | {
|
---|
[9c259e] | 612 | LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomRemoved for atom "+toString(_id)+".");
|
---|
[8c001a] | 613 | // bonds are removed by signal coming from ~bond
|
---|
[2b596f] | 614 |
|
---|
[704d59] | 615 | if ((unsigned int)m_objectId == _id)
|
---|
[2b596f] | 616 | setObjectId(-1);
|
---|
| 617 |
|
---|
[8c001a] | 618 | // remove atoms
|
---|
| 619 | AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
|
---|
| 620 | ASSERT(iter != AtomsinSceneMap.end(),
|
---|
[73b13c] | 621 | "GLMoleculeObject_molecule::atomRemoved() - atom "+toString(_id)+" not on display.");
|
---|
[8c001a] | 622 | GLMoleculeObject_atom *atomObject = iter->second;
|
---|
| 623 | AtomsinSceneMap.erase(iter);
|
---|
[704d59] | 624 | atomObject->disconnect();
|
---|
[8c001a] | 625 | delete atomObject;
|
---|
| 626 |
|
---|
[8d5fbf1] | 627 | emit changed();
|
---|
[8c001a] | 628 | emit changeOccured();
|
---|
| 629 | }
|
---|
| 630 |
|
---|
| 631 | void GLMoleculeObject_molecule::hoverChangedSignalled(GLMoleculeObject *ob)
|
---|
| 632 | {
|
---|
| 633 | // Find the atom, ob corresponds to.
|
---|
[704d59] | 634 | hoverAtomId = -1;
|
---|
[8c001a] | 635 | GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
|
---|
| 636 | if (atomObject){
|
---|
| 637 | for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
|
---|
| 638 | if (iter->second == atomObject)
|
---|
[704d59] | 639 | hoverAtomId = iter->first;
|
---|
[8c001a] | 640 | }
|
---|
| 641 |
|
---|
[2b596f] | 642 | // Propagate signal.
|
---|
[704d59] | 643 | emit hoverChanged(hoverAtomId);
|
---|
[2b596f] | 644 | } else {
|
---|
| 645 | // Find the atom, ob corresponds to.
|
---|
| 646 | GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob);
|
---|
| 647 | if (moleculeObject == this){
|
---|
| 648 | // Propagate signal.
|
---|
[7c7c4a] | 649 | emit hoverChanged(getMolIndex(), 0);
|
---|
[2b596f] | 650 | }
|
---|
| 651 | }
|
---|
[8c001a] | 652 | }
|
---|
| 653 |
|
---|
| 654 |
|
---|
| 655 | /** Helper function to get bond ids in the correct order for BondNodeMap.
|
---|
| 656 | *
|
---|
| 657 | * \return pair of ids in correct order.
|
---|
| 658 | */
|
---|
| 659 | GLMoleculeObject_molecule::BondIds GLMoleculeObject_molecule::getBondIds(
|
---|
| 660 | const bond::ptr _bond,
|
---|
| 661 | const enum GLMoleculeObject_bond::SideOfBond _side)
|
---|
| 662 | {
|
---|
| 663 | BondIds ids;
|
---|
| 664 | switch (_side) {
|
---|
| 665 | case GLMoleculeObject_bond::left:
|
---|
| 666 | ids = std::make_pair(_bond->leftatom->getId(), _bond->rightatom->getId());
|
---|
| 667 | break;
|
---|
| 668 | case GLMoleculeObject_bond::right:
|
---|
| 669 | ids = std::make_pair(_bond->rightatom->getId(), _bond->leftatom->getId());
|
---|
| 670 | break;
|
---|
| 671 | }
|
---|
| 672 | return ids;
|
---|
| 673 | }
|
---|
| 674 |
|
---|
| 675 | /** Adds a bond to the scene.
|
---|
| 676 | *
|
---|
| 677 | * @param _bond bond to add
|
---|
| 678 | * @param side which side of the bond (left or right)
|
---|
| 679 | */
|
---|
[6c16a0] | 680 | void GLMoleculeObject_molecule::bondInserted(
|
---|
| 681 | const atomId_t _left, const atomId_t _right,
|
---|
| 682 | const enum GLMoleculeObject_bond::SideOfBond _side)
|
---|
[8c001a] | 683 | {
|
---|
[6c16a0] | 684 | LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(_left)
|
---|
| 685 | +toString(_right)+".");
|
---|
[8c001a] | 686 | //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
|
---|
| 687 |
|
---|
[6c16a0] | 688 | const BondIds ids( std::make_pair(_left, _right) );
|
---|
[8c001a] | 689 | BondNodeMap::iterator iter = BondsinSceneMap.find(ids);
|
---|
| 690 | if (iter == BondsinSceneMap.end()) {
|
---|
| 691 | GLMoleculeObject_bond * bondObject =
|
---|
[009e2e2] | 692 | new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, ids, _side);
|
---|
[8c001a] | 693 | connect (
|
---|
| 694 | bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)),
|
---|
| 695 | this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
|
---|
| 696 | connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
| 697 | BondsinSceneMap.insert( make_pair(ids, bondObject) );
|
---|
| 698 | // BondIdsinSceneMap.insert( Leftids );
|
---|
| 699 | } else {
|
---|
| 700 | iter->second->resetPosition();
|
---|
| 701 | iter->second->resetWidth();
|
---|
| 702 | }
|
---|
[8d5fbf1] | 703 | emit changed();
|
---|
[8c001a] | 704 | emit changeOccured();
|
---|
| 705 | }
|
---|
| 706 |
|
---|
| 707 | /** Removes a bond from the scene.
|
---|
| 708 | *
|
---|
| 709 | * @param _bond bond to remove
|
---|
| 710 | */
|
---|
| 711 | void GLMoleculeObject_molecule::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
|
---|
| 712 | {
|
---|
| 713 | LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+".");
|
---|
| 714 | {
|
---|
| 715 | // left bond
|
---|
| 716 | const BondIds Leftids( make_pair(leftnr, rightnr) );
|
---|
| 717 | BondNodeMap::iterator leftiter = BondsinSceneMap.find( Leftids );
|
---|
| 718 | ASSERT(leftiter != BondsinSceneMap.end(),
|
---|
| 719 | "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
|
---|
| 720 | +toString(rightnr)+" not on display.");
|
---|
| 721 | GLMoleculeObject_bond *bondObject = leftiter->second;
|
---|
| 722 | bondObject->disconnect();
|
---|
| 723 | BondsinSceneMap.erase(leftiter);
|
---|
| 724 | delete bondObject; // is done by signal from bond itself
|
---|
| 725 | //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
|
---|
| 726 | }
|
---|
| 727 |
|
---|
[8d5fbf1] | 728 | emit changed();
|
---|
[8c001a] | 729 | emit changeOccured();
|
---|
| 730 | }
|
---|
| 731 |
|
---|
[34e7fdb] | 732 | void GLMoleculeObject_molecule::setVisible(bool value)
|
---|
| 733 | {
|
---|
| 734 | // first update the mesh if we are going to be visible now
|
---|
| 735 | if (value)
|
---|
[7b5984] | 736 | updateTesselationHull();
|
---|
[34e7fdb] | 737 | // then emit onward
|
---|
| 738 | GLMoleculeObject::setVisible(value);
|
---|
[8d5fbf1] | 739 |
|
---|
| 740 | emit changed();
|
---|
| 741 | emit changeOccured();
|
---|
[34e7fdb] | 742 | }
|
---|
| 743 |
|
---|
[8c001a] | 744 | std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t)
|
---|
| 745 | {
|
---|
| 746 | ost << t.first << "," << t.second;
|
---|
| 747 | return ost;
|
---|
| 748 | }
|
---|
[34e7fdb] | 749 |
|
---|
[9a7ef9] | 750 | void GLMoleculeObject_molecule::wasClicked()
|
---|
| 751 | {
|
---|
[7c7c4a] | 752 | LOG(4, "INFO: GLMoleculeObject_molecule: atom " << getMolIndex() << " has been clicked");
|
---|
| 753 | emit moleculeClicked(getMolIndex());
|
---|
[9a7ef9] | 754 | }
|
---|
[8d3ee6] | 755 |
|
---|
[6c16a0] | 756 | void GLMoleculeObject_molecule::changeAtomId(
|
---|
| 757 | GLMoleculeObject_atom *ob,
|
---|
| 758 | const atomId_t oldId,
|
---|
| 759 | const atomId_t newId)
|
---|
[8d3ee6] | 760 | {
|
---|
| 761 | LOG(3, "INFO: GLMoleculeObject_molecule - change atom id " << oldId << " to " << newId << ".");
|
---|
| 762 |
|
---|
| 763 | // Remove from map.
|
---|
| 764 | AtomNodeMap::iterator iter = AtomsinSceneMap.find(oldId);
|
---|
| 765 | ASSERT(iter != AtomsinSceneMap.end(),
|
---|
| 766 | "GLMoleculeObject_molecule::changeAtomId() - atom with old id "+toString(oldId)+" not on display.");
|
---|
| 767 | ASSERT(iter->second == ob,
|
---|
| 768 | "GLMoleculeObject_molecule::changeAtomId() - atom with id "
|
---|
| 769 | +toString(oldId)+" does not match with object in AtomsinSceneMap.");
|
---|
| 770 | AtomsinSceneMap.erase(iter);
|
---|
| 771 |
|
---|
| 772 | // Reinsert with new id.
|
---|
| 773 | {
|
---|
| 774 | AtomNodeMap::iterator iter = AtomsinSceneMap.find(newId);
|
---|
| 775 | ASSERT(iter == AtomsinSceneMap.end(),
|
---|
| 776 | "GLMoleculeObject_molecule::changeAtomId() - atom with new id "+toString(newId)+" already known.");
|
---|
| 777 | }
|
---|
| 778 | AtomsinSceneMap.insert( make_pair(newId, ob) );
|
---|
| 779 | }
|
---|
[6c16a0] | 780 |
|
---|
| 781 | const molecule * const GLMoleculeObject_molecule::getMolecule(const moleculeId_t _id)
|
---|
| 782 | {
|
---|
| 783 | const molecule * const mol = const_cast<const World &>(World::getInstance()).
|
---|
| 784 | getMolecule(MoleculeById(_id));
|
---|
| 785 | return mol;
|
---|
| 786 | }
|
---|
[7c7c4a] | 787 |
|
---|
[8688ef] | 788 | void GLMoleculeObject_molecule::initObservedValues(
|
---|
| 789 | std::vector<boost::any> &_ObservedValues,
|
---|
| 790 | const moleculeId_t _molid,
|
---|
| 791 | const molecule * const _molref,
|
---|
[026bef] | 792 | const boost::function<void(const moleculeId_t)> &_subjectKilled)
|
---|
[7c7c4a] | 793 | {
|
---|
[8688ef] | 794 | /* This is an old note from when the code was still part of cstor's initializer body.
|
---|
| 795 | * TODO: Probably does not apply anymore but has not yet been tested.
|
---|
| 796 | *
|
---|
| 797 | * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
|
---|
| 798 | * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
|
---|
| 799 | * the class has not been fully constructed yet. "This" itself seems to be working fine.
|
---|
| 800 | */
|
---|
| 801 |
|
---|
| 802 | ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
|
---|
| 803 | "GLMoleculeObject_molecule::initObservedValues() - given ObservedValues has not correct size.");
|
---|
| 804 |
|
---|
| 805 | // fill ObservedValues: index first
|
---|
| 806 | const boost::function<moleculeId_t ()> MolIndexUpdater(
|
---|
| 807 | boost::bind(&GLMoleculeObject_molecule::updateIndex));
|
---|
| 808 |
|
---|
| 809 | ObservedValue_wCallback<moleculeId_t> * const IndexObservable =
|
---|
| 810 | new ObservedValue_wCallback<moleculeId_t>(
|
---|
| 811 | _molref,
|
---|
| 812 | MolIndexUpdater,
|
---|
| 813 | "MoleculeIndex_"+toString(_molid),
|
---|
| 814 | _molid,
|
---|
| 815 | IndexChannels,
|
---|
| 816 | _subjectKilled);
|
---|
| 817 | _ObservedValues[MolIndex] = IndexObservable;
|
---|
| 818 |
|
---|
| 819 | const boost::function<const moleculeId_t ()> MolIndexGetter =
|
---|
| 820 | boost::bind(&ObservedValue_wCallback<moleculeId_t>::get,
|
---|
| 821 | IndexObservable);
|
---|
| 822 |
|
---|
| 823 | // fill ObservedValues: then all the other that need index
|
---|
| 824 | const boost::function<std::string ()> MolNameUpdater(
|
---|
| 825 | boost::bind(&GLMoleculeObject_molecule::updateName, MolIndexGetter));
|
---|
| 826 | const boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater(
|
---|
| 827 | boost::bind(&GLMoleculeObject_molecule::updateBoundingBox, MolIndexGetter));
|
---|
| 828 |
|
---|
[026bef] | 829 | _ObservedValues[MolName] = new ObservedValue_wCallback<std::string, moleculeId_t>(
|
---|
[8688ef] | 830 | _molref,
|
---|
[7c7c4a] | 831 | MolNameUpdater,
|
---|
| 832 | "MoleculeName_"+toString(_molid),
|
---|
[8688ef] | 833 | MolNameUpdater(),
|
---|
[7c7c4a] | 834 | NameChannels,
|
---|
[026bef] | 835 | _subjectKilled,
|
---|
| 836 | MolIndexGetter);
|
---|
| 837 | _ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t>(
|
---|
[8688ef] | 838 | _molref,
|
---|
[7c7c4a] | 839 | BoundingBoxUpdater,
|
---|
| 840 | "MoleculeBoundingBox_"+toString(_molid),
|
---|
| 841 | initBoundingBox(),
|
---|
| 842 | BoundingBoxChannels,
|
---|
[026bef] | 843 | _subjectKilled,
|
---|
| 844 | MolIndexGetter);
|
---|
[7c7c4a] | 845 | }
|
---|
| 846 |
|
---|
[8688ef] | 847 | void GLMoleculeObject_molecule::destroyObservedValues(
|
---|
| 848 | std::vector<boost::any> &_ObservedValues)
|
---|
[7c7c4a] | 849 | {
|
---|
[8688ef] | 850 | delete boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(_ObservedValues[MolIndex]);
|
---|
[026bef] | 851 | delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[MolName]);
|
---|
| 852 | delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(_ObservedValues[BoundingBox]);
|
---|
[8688ef] | 853 | _ObservedValues.clear();
|
---|
[7c7c4a] | 854 | }
|
---|
| 855 |
|
---|
| 856 | moleculeId_t GLMoleculeObject_molecule::getMolIndex() const
|
---|
| 857 | {
|
---|
| 858 | return boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(ObservedValues[MolIndex])->get();
|
---|
| 859 | }
|
---|
| 860 |
|
---|
| 861 | std::string GLMoleculeObject_molecule::getMolName() const
|
---|
| 862 | {
|
---|
[026bef] | 863 | return boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[MolName])->get();
|
---|
[7c7c4a] | 864 | }
|
---|
| 865 |
|
---|
| 866 | molecule::BoundingBoxInfo GLMoleculeObject_molecule::getBoundingBox() const
|
---|
| 867 | {
|
---|
[026bef] | 868 | return boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(ObservedValues[BoundingBox])->get();
|
---|
[7c7c4a] | 869 | }
|
---|
| 870 |
|
---|
| 871 | GLMoleculeObject_molecule::atoms_t GLMoleculeObject_molecule::getPresentAtoms() const
|
---|
| 872 | {
|
---|
[8d5fbf1] | 873 | atoms_t returnAtomIds;
|
---|
| 874 | returnAtomIds.insert(
|
---|
| 875 | MapKeyConstIterator<AtomNodeMap::const_iterator>(const_cast<const AtomNodeMap &>(AtomsinSceneMap).begin()),
|
---|
| 876 | MapKeyConstIterator<AtomNodeMap::const_iterator>(const_cast<const AtomNodeMap &>(AtomsinSceneMap).end()));
|
---|
| 877 | return returnAtomIds;
|
---|
[7c7c4a] | 878 | }
|
---|