[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 |
|
---|
[494478] | 42 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp"
|
---|
| 43 |
|
---|
[c67518] | 44 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 45 |
|
---|
[6c16a0] | 46 | #include <boost/assign.hpp>
|
---|
| 47 |
|
---|
[c67518] | 48 | #include "CodePatterns/Assert.hpp"
|
---|
[8d5fbf1] | 49 | #include "CodePatterns/IteratorAdaptors.hpp"
|
---|
[c67518] | 50 | #include "CodePatterns/Log.hpp"
|
---|
[494478] | 51 |
|
---|
[c67518] | 52 | #include "LinearAlgebra/Vector.hpp"
|
---|
[34e7fdb] | 53 | #include "LinkedCell/PointCloudAdaptor.hpp"
|
---|
| 54 | #include "LinkedCell/linkedcell.hpp"
|
---|
| 55 | #include "Tesselation/tesselation.hpp"
|
---|
| 56 | #include "Tesselation/BoundaryLineSet.hpp"
|
---|
| 57 | #include "Tesselation/BoundaryTriangleSet.hpp"
|
---|
| 58 | #include "Tesselation/CandidateForTesselation.hpp"
|
---|
[2f7988] | 59 | #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
|
---|
[34e7fdb] | 60 | #include "Atom/TesselPoint.hpp"
|
---|
[c67518] | 61 | #include "World.hpp"
|
---|
| 62 |
|
---|
[6c16a0] | 63 | using namespace boost::assign;
|
---|
| 64 |
|
---|
[8d5fbf1] | 65 | static Observable::channels_t getAllAtomicChangesChannels()
|
---|
[34e7fdb] | 66 | {
|
---|
[6c16a0] | 67 | Observable::channels_t channels;
|
---|
[8d5fbf1] | 68 | channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
|
---|
[6c16a0] | 69 | return channels;
|
---|
| 70 | }
|
---|
[34e7fdb] | 71 |
|
---|
[6c16a0] | 72 | const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels());
|
---|
[34e7fdb] | 73 |
|
---|
[6c16a0] | 74 | static QGLSceneNode *createMoleculeMesh(const QGeometryData &_geo)
|
---|
| 75 | {
|
---|
[34e7fdb] | 76 | // Build a mesh from the geometry.
|
---|
| 77 | QGLBuilder builder;
|
---|
[6c16a0] | 78 | builder.addTriangles(_geo);
|
---|
[34e7fdb] | 79 | QGLSceneNode *mesh = builder.finalizedSceneNode();
|
---|
| 80 | return mesh;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[8d5fbf1] | 83 | GLMoleculeObject_molecule::GLMoleculeObject_molecule(
|
---|
| 84 | QObject *parent,
|
---|
[494478] | 85 | QtObservedInstanceBoard &_board,
|
---|
[1b07b1] | 86 | QtObservedMolecule::ptr &_ObservedMolecule) :
|
---|
[6c16a0] | 87 | GLMoleculeObject((QGLSceneNode *)NULL, parent),
|
---|
| 88 | owner(NULL),
|
---|
[8d5fbf1] | 89 | hoverAtomId(-1),
|
---|
[494478] | 90 | board(_board),
|
---|
| 91 | ObservedMolecule(_ObservedMolecule)
|
---|
[34e7fdb] | 92 | {
|
---|
[96f14a] | 93 | init();
|
---|
[34e7fdb] | 94 | }
|
---|
| 95 |
|
---|
[026bef] | 96 | GLMoleculeObject_molecule::GLMoleculeObject_molecule(
|
---|
| 97 | QGLSceneNode *mesh[],
|
---|
| 98 | QObject *parent,
|
---|
[494478] | 99 | QtObservedInstanceBoard &_board,
|
---|
[1b07b1] | 100 | QtObservedMolecule::ptr &_ObservedMolecule) :
|
---|
[bca99d] | 101 | GLMoleculeObject(mesh, parent),
|
---|
[6c16a0] | 102 | owner(NULL),
|
---|
[8d5fbf1] | 103 | hoverAtomId(-1),
|
---|
[494478] | 104 | board(_board),
|
---|
| 105 | ObservedMolecule(_ObservedMolecule)
|
---|
[c67518] | 106 | {
|
---|
[96f14a] | 107 | init();
|
---|
[8d5fbf1] | 108 | }
|
---|
[7c7c4a] | 109 |
|
---|
[96f14a] | 110 | void GLMoleculeObject_molecule::init()
|
---|
[8d5fbf1] | 111 | {
|
---|
[96f14a] | 112 | setObjectId(ObservedMolecule->getMolIndex());
|
---|
[3b229e] | 113 | setMaterial(getMaterial(1));
|
---|
[8c001a] | 114 |
|
---|
[96f14a] | 115 | m_selected = ObservedMolecule->getMolSelected();
|
---|
[a39d72] | 116 |
|
---|
[739ee9] | 117 | // initially, atoms and bonds should be visible
|
---|
| 118 | m_visible = false;
|
---|
| 119 |
|
---|
[2b596f] | 120 | connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
|
---|
| 121 | connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
|
---|
[494478] | 122 | connect (ObservedMolecule.get(), SIGNAL(tesselationhullChanged()), this, SLOT(resetTesselationHull()));
|
---|
| 123 | connect (ObservedMolecule.get(), SIGNAL(boundingboxChanged()), this, SLOT(resetBoundingBox()));
|
---|
[1c0961] | 124 | connect (ObservedMolecule.get(), SIGNAL(indexChanged(const moleculeId_t, const moleculeId_t)),
|
---|
| 125 | this, SLOT(resetIndex(const moleculeId_t, const moleculeId_t)));
|
---|
[59f1bc] | 126 | /// these are channeled through GLWorldScene instead to ensure synchronicity
|
---|
| 127 | // connect (ObservedMolecule.get(), SIGNAL(atomInserted(QtObservedAtom::ptr)),
|
---|
| 128 | // this, SLOT(atomInserted(QtObservedAtom::ptr)) );
|
---|
| 129 | // connect (ObservedMolecule.get(), SIGNAL(atomRemoved(const atomId_t)),
|
---|
| 130 | // this, SLOT(atomRemoved(const atomId_t)) );
|
---|
[5cd3a33] | 131 | connect (ObservedMolecule.get(), SIGNAL(selectedChanged()), this, SLOT(resetSelected()));
|
---|
[9a7ef9] | 132 |
|
---|
| 133 | connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
|
---|
[c67518] | 134 | }
|
---|
| 135 |
|
---|
| 136 | GLMoleculeObject_molecule::~GLMoleculeObject_molecule()
|
---|
[494478] | 137 | {}
|
---|
[73b13c] | 138 |
|
---|
[6c16a0] | 139 | QGeometryData GLMoleculeObject_molecule::updateTesselationHull() const
|
---|
| 140 | {
|
---|
| 141 | QGeometryData geo;
|
---|
| 142 |
|
---|
[494478] | 143 | const molecule * const molref =
|
---|
| 144 | QtObservedMolecule::getMolecule(ObservedMolecule->getMolIndex());
|
---|
[6c16a0] | 145 | if (molref == NULL) {
|
---|
[494478] | 146 | ELOG(1, "Could not createMoleculeMesh, molecule with id "
|
---|
| 147 | << ObservedMolecule->getMolIndex() << " already gone.");
|
---|
[6c16a0] | 148 | return geo;
|
---|
| 149 | }
|
---|
| 150 | double minradius = 2.; // TODO: set to maximum bond length value
|
---|
| 151 | LOG(3, "DEBUG: Molecule fits into sphere of radius " << minradius);
|
---|
| 152 | // check minimum bond radius in molecule
|
---|
| 153 | double minlength = std::numeric_limits<double>::max();
|
---|
| 154 | for (molecule::const_iterator iter = molref->begin();
|
---|
| 155 | iter != molref->end(); ++iter) {
|
---|
| 156 | const BondList &ListOfBonds = (*iter)->getListOfBonds();
|
---|
| 157 | for (BondList::const_iterator bonditer = ListOfBonds.begin();
|
---|
| 158 | bonditer != ListOfBonds.end(); ++bonditer) {
|
---|
| 159 | const double bond_distance = (*bonditer)->GetDistance();
|
---|
| 160 | minlength = std::min(bond_distance, minlength);
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 | minradius = std::max( std::max(minradius, minlength), 1.);
|
---|
| 164 |
|
---|
| 165 | // we need at least three points for tesselation
|
---|
[76c238] | 166 | if (AtomsinSceneMap.size() >= 3) {
|
---|
[6c16a0] | 167 | // Tesselate the points.
|
---|
| 168 | Tesselation T;
|
---|
[494478] | 169 | PointCloudAdaptor<molecule> cloud(
|
---|
| 170 | const_cast<molecule *>(molref),
|
---|
| 171 | ObservedMolecule->getMolName());
|
---|
[6c16a0] | 172 | T(cloud, minradius);
|
---|
| 173 |
|
---|
| 174 | // Fill the points into a Qt geometry.
|
---|
| 175 | LinkedCell_deprecated LinkedList(cloud, minradius);
|
---|
| 176 | std::map<int, int> indices;
|
---|
| 177 | std::map<int, Vector> normals;
|
---|
| 178 | int index = 0;
|
---|
| 179 | for (PointMap::const_iterator piter = T.PointsOnBoundary.begin();
|
---|
| 180 | piter != T.PointsOnBoundary.end(); ++piter) {
|
---|
| 181 | const Vector &point = piter->second->getPosition();
|
---|
| 182 | // add data to the primitive
|
---|
| 183 | geo.appendVertex(QVector3D(point[0], point[1], point[2]));
|
---|
| 184 | Vector normalvector;
|
---|
| 185 | for (LineMap::const_iterator lineiter = piter->second->lines.begin();
|
---|
| 186 | lineiter != piter->second->lines.end(); ++lineiter)
|
---|
| 187 | for (TriangleMap::const_iterator triangleiter = lineiter->second->triangles.begin();
|
---|
| 188 | triangleiter != lineiter->second->triangles.end(); ++triangleiter)
|
---|
| 189 | normalvector +=
|
---|
| 190 | triangleiter->second->NormalVector;
|
---|
| 191 | normalvector.Normalize();
|
---|
| 192 | geo.appendNormal(QVector3D(normalvector[0], normalvector[1], normalvector[2]));
|
---|
| 193 | geo.appendColor(QColor(1, 1, 1, 1));
|
---|
| 194 | geo.appendTexCoord(QVector2D(0, 0));
|
---|
| 195 | indices.insert( std::make_pair( piter->second->getNr(), index++));
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | // Fill the tesselated triangles into the geometry.
|
---|
| 199 | for (TriangleMap::const_iterator runner = T.TrianglesOnBoundary.begin();
|
---|
| 200 | runner != T.TrianglesOnBoundary.end(); runner++) {
|
---|
| 201 | int v[3];
|
---|
| 202 | for (size_t i=0; i<3; ++i)
|
---|
| 203 | v[i] = runner->second->endpoints[i]->getNr();
|
---|
| 204 |
|
---|
| 205 | // Sort the vertices so the triangle is clockwise (relative to the normal vector).
|
---|
| 206 | Vector cross = T.PointsOnBoundary[v[1]]->getPosition() - T.PointsOnBoundary[v[0]]->getPosition();
|
---|
| 207 | cross.VectorProduct(T.PointsOnBoundary[v[2]]->getPosition() - T.PointsOnBoundary[v[0]]->getPosition());
|
---|
| 208 | if (cross.ScalarProduct(runner->second->NormalVector) > 0)
|
---|
| 209 | geo.appendIndices(indices[v[0]], indices[v[1]], indices[v[2]]);
|
---|
| 210 | else
|
---|
| 211 | geo.appendIndices(indices[v[0]], indices[v[2]], indices[v[1]]);
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | return geo;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | void GLMoleculeObject_molecule::resetTesselationHull()
|
---|
| 219 | {
|
---|
[3fe318] | 220 | if (owner != NULL) {
|
---|
| 221 | TesselationHull = updateTesselationHull();
|
---|
| 222 | updateMesh(createMoleculeMesh(TesselationHull));
|
---|
| 223 | }
|
---|
[6c16a0] | 224 | }
|
---|
| 225 |
|
---|
| 226 | void GLMoleculeObject_molecule::resetBoundingBox()
|
---|
| 227 | {
|
---|
[494478] | 228 | molecule::BoundingBoxInfo info = ObservedMolecule->getBoundingBox();
|
---|
[6c16a0] | 229 | setPosition(QVector3D(info.position[0], info.position[1], info.position[2]));
|
---|
| 230 | setScale(info.radius + 0.3); // getBoundingSphere() only sees atoms as points, so make the box a bit bigger
|
---|
| 231 | }
|
---|
| 232 |
|
---|
[1c0961] | 233 | void GLMoleculeObject_molecule::resetIndex(const moleculeId_t, const moleculeId_t)
|
---|
[6c16a0] | 234 | {
|
---|
[494478] | 235 | const atomId_t newId = ObservedMolecule->getMolIndex();
|
---|
[6c16a0] | 236 | const size_t oldId = objectId();
|
---|
| 237 | ASSERT( newId != oldId,
|
---|
| 238 | "GLMoleculeObject_molecule::resetIndex() - index "+toString(newId)+" did not change.");
|
---|
| 239 | LOG(4, "INFO: GLMoleculeObject_molecule: new index is "+toString(newId)+".");
|
---|
| 240 | setObjectId(newId);
|
---|
[d6203a] | 241 | }
|
---|
| 242 |
|
---|
[5cd3a33] | 243 | void GLMoleculeObject_molecule::resetSelected()
|
---|
[015f8c] | 244 | {
|
---|
[5cd3a33] | 245 | const bool new_selected = ObservedMolecule->getMolSelected();
|
---|
| 246 | m_selected = new_selected;
|
---|
[015f8c] | 247 |
|
---|
| 248 | emit changed();
|
---|
| 249 | }
|
---|
| 250 |
|
---|
[8c001a] | 251 | void GLMoleculeObject_molecule::initialize(QGLView *view, QGLPainter *painter)
|
---|
| 252 | {
|
---|
| 253 | // Initialize all of the mesh objects that we have as children.
|
---|
[2b596f] | 254 | if (m_visible) {
|
---|
| 255 | GLMoleculeObject::initialize(view, painter);
|
---|
| 256 | } else {
|
---|
[8c001a] | 257 | foreach (QObject *obj, children()) {
|
---|
| 258 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
| 259 | if (meshobj)
|
---|
| 260 | meshobj->initialize(view, painter);
|
---|
| 261 | }
|
---|
[2b596f] | 262 | }
|
---|
[8c001a] | 263 | }
|
---|
| 264 |
|
---|
| 265 | void GLMoleculeObject_molecule::draw(QGLPainter *painter, const QVector4D &cameraPlane)
|
---|
| 266 | {
|
---|
[739ee9] | 267 | // draw either molecule's mesh or all atoms and bonds
|
---|
| 268 | if (m_visible) {
|
---|
[6c16a0] | 269 | resetTesselationHull();
|
---|
[7b5984] | 270 |
|
---|
[34e7fdb] | 271 | painter->modelViewMatrix().push();
|
---|
| 272 |
|
---|
| 273 | // Apply the material and effect to the painter.
|
---|
| 274 | QGLMaterial *material;
|
---|
| 275 | if (m_hovering)
|
---|
| 276 | material = m_hoverMaterial;
|
---|
| 277 | else if (m_selected)
|
---|
| 278 | material = m_selectionMaterial;
|
---|
| 279 | else
|
---|
| 280 | material = m_material;
|
---|
| 281 |
|
---|
| 282 | ASSERT(material, "GLMoleculeObject::draw: chosen material is NULL");
|
---|
| 283 |
|
---|
| 284 | painter->setColor(material->diffuseColor());
|
---|
| 285 | painter->setFaceMaterial(QGL::AllFaces, material);
|
---|
| 286 | if (m_effect)
|
---|
| 287 | painter->setUserEffect(m_effect);
|
---|
| 288 | else
|
---|
| 289 | painter->setStandardEffect(QGL::LitMaterial);
|
---|
| 290 |
|
---|
| 291 | // Mark the object for object picking purposes.
|
---|
| 292 | int prevObjectId = painter->objectPickId();
|
---|
| 293 | if (m_objectId != -1)
|
---|
| 294 | painter->setObjectPickId(m_objectId);
|
---|
| 295 |
|
---|
| 296 | m_mesh[0]->draw(painter);
|
---|
| 297 |
|
---|
| 298 | // Turn off the user effect, if present.
|
---|
| 299 | if (m_effect)
|
---|
| 300 | painter->setStandardEffect(QGL::LitMaterial);
|
---|
| 301 |
|
---|
| 302 | // Revert to the previous object identifier.
|
---|
| 303 | painter->setObjectPickId(prevObjectId);
|
---|
| 304 |
|
---|
| 305 | // Restore the modelview matrix.
|
---|
| 306 | painter->modelViewMatrix().pop();
|
---|
| 307 |
|
---|
| 308 | // GLMoleculeObject::draw(painter, cameraPlane);
|
---|
[739ee9] | 309 | } else {
|
---|
| 310 | // Draw all of the mesh objects that we have as children.
|
---|
| 311 | foreach (QObject *obj, children()) {
|
---|
| 312 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
| 313 | if (meshobj)
|
---|
| 314 | meshobj->draw(painter, cameraPlane);
|
---|
| 315 | }
|
---|
[2b596f] | 316 |
|
---|
| 317 | // update bounding box prior to selection
|
---|
[6c16a0] | 318 | resetBoundingBox();
|
---|
[2b596f] | 319 |
|
---|
| 320 | painter->modelViewMatrix().push();
|
---|
| 321 | painter->modelViewMatrix().translate(m_position);
|
---|
| 322 | if (m_rotationAngle != 0.0f)
|
---|
| 323 | painter->modelViewMatrix().rotate(m_rotationAngle, m_rotationVector);
|
---|
[f47efd4] | 324 | if ((m_scaleX != 1.0f) || (m_scaleY != 1.0f) || (m_scaleZ != 1.0f))
|
---|
| 325 | painter->modelViewMatrix().scale(m_scaleX, m_scaleY, m_scaleZ);
|
---|
[2b596f] | 326 |
|
---|
| 327 | // Draw a box around the mesh, if selected.
|
---|
| 328 | if (m_selected)
|
---|
| 329 | drawSelectionBox(painter);
|
---|
| 330 |
|
---|
| 331 | // Restore the modelview matrix.
|
---|
| 332 | painter->modelViewMatrix().pop();
|
---|
[739ee9] | 333 | }
|
---|
[8c001a] | 334 | }
|
---|
| 335 |
|
---|
| 336 | /** Adds an atom of this molecule to the scene.
|
---|
| 337 | *
|
---|
| 338 | * @param _atom atom to add
|
---|
| 339 | */
|
---|
[1b07b1] | 340 | void GLMoleculeObject_molecule::atomInserted(QtObservedAtom::ptr _atom)
|
---|
[8c001a] | 341 | {
|
---|
[76c238] | 342 | const ObservedValue_Index_t atomid = _atom->getIndex();
|
---|
| 343 | LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomInserted for atom "
|
---|
| 344 | << _atom->getAtomIndex());
|
---|
[9c259e] | 345 |
|
---|
[7ded1c] | 346 | if (_atom) {
|
---|
| 347 | GLMoleculeObject_atom *atomObject =
|
---|
| 348 | new GLMoleculeObject_atom(
|
---|
| 349 | GLMoleculeObject::meshSphere,
|
---|
| 350 | this,
|
---|
| 351 | _atom);
|
---|
| 352 | ASSERT( atomObject != NULL,
|
---|
[76c238] | 353 | "GLMoleculeObject_molecule::atomInserted - could not create atom object for "
|
---|
| 354 | +toString(_atom->getAtomIndex()));
|
---|
[1b07b1] | 355 | AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid);
|
---|
[7ded1c] | 356 | ASSERT(iter == AtomsinSceneMap.end(),
|
---|
[76c238] | 357 | "GLMoleculeObject_molecule::atomInserted - same atom with id "
|
---|
| 358 | +toString(_atom->getAtomIndex())+" added again.");
|
---|
[1b07b1] | 359 | AtomsinSceneMap.insert( make_pair(atomid, atomObject) );
|
---|
[7ded1c] | 360 |
|
---|
| 361 | qRegisterMetaType<atomId_t>("atomId_t");
|
---|
| 362 | qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
|
---|
| 363 | connect (atomObject, SIGNAL(clicked(atomId_t)), this, SIGNAL(atomClicked(atomId_t)));
|
---|
| 364 | connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
| 365 | connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
|
---|
| 366 | connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
|
---|
| 367 |
|
---|
| 368 | if (m_objectId == -1)
|
---|
[76c238] | 369 | setObjectId(_atom->getAtomIndex());
|
---|
[7ded1c] | 370 |
|
---|
| 371 | emit changed();
|
---|
| 372 | emit changeOccured();
|
---|
| 373 | }
|
---|
[8c001a] | 374 | }
|
---|
| 375 |
|
---|
| 376 | /** Removes an atom of this molecule from the scene.
|
---|
| 377 | *
|
---|
| 378 | * We just the id as the atom might have already been destroyed.
|
---|
| 379 | *
|
---|
| 380 | * @param _id id of atom to remove
|
---|
| 381 | */
|
---|
[76c238] | 382 | void GLMoleculeObject_molecule::atomRemoved(ObservedValue_Index_t _id)
|
---|
[8c001a] | 383 | {
|
---|
[9c259e] | 384 | LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomRemoved for atom "+toString(_id)+".");
|
---|
[8c001a] | 385 | // bonds are removed by signal coming from ~bond
|
---|
[2b596f] | 386 |
|
---|
[8c001a] | 387 | // remove atoms
|
---|
| 388 | AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
|
---|
| 389 | ASSERT(iter != AtomsinSceneMap.end(),
|
---|
[73b13c] | 390 | "GLMoleculeObject_molecule::atomRemoved() - atom "+toString(_id)+" not on display.");
|
---|
[8c001a] | 391 | GLMoleculeObject_atom *atomObject = iter->second;
|
---|
| 392 | AtomsinSceneMap.erase(iter);
|
---|
[704d59] | 393 | atomObject->disconnect();
|
---|
[8c001a] | 394 | delete atomObject;
|
---|
| 395 |
|
---|
[8d5fbf1] | 396 | emit changed();
|
---|
[8c001a] | 397 | emit changeOccured();
|
---|
[640cbd] | 398 |
|
---|
| 399 | if (AtomsinSceneMap.empty())
|
---|
| 400 | emit moleculeEmptied(ObservedMolecule);
|
---|
[8c001a] | 401 | }
|
---|
| 402 |
|
---|
| 403 | void GLMoleculeObject_molecule::hoverChangedSignalled(GLMoleculeObject *ob)
|
---|
| 404 | {
|
---|
| 405 | // Find the atom, ob corresponds to.
|
---|
[704d59] | 406 | hoverAtomId = -1;
|
---|
[8c001a] | 407 | GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
|
---|
| 408 | if (atomObject){
|
---|
| 409 | for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
|
---|
| 410 | if (iter->second == atomObject)
|
---|
[76c238] | 411 | hoverAtomId = iter->second->objectId();
|
---|
[8c001a] | 412 | }
|
---|
| 413 |
|
---|
[2b596f] | 414 | // Propagate signal.
|
---|
[704d59] | 415 | emit hoverChanged(hoverAtomId);
|
---|
[2b596f] | 416 | } else {
|
---|
| 417 | // Find the atom, ob corresponds to.
|
---|
| 418 | GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob);
|
---|
| 419 | if (moleculeObject == this){
|
---|
| 420 | // Propagate signal.
|
---|
[494478] | 421 | emit hoverChanged(ObservedMolecule->getMolIndex(), 0);
|
---|
[2b596f] | 422 | }
|
---|
| 423 | }
|
---|
[8c001a] | 424 | }
|
---|
| 425 |
|
---|
| 426 | /** Adds a bond to the scene.
|
---|
| 427 | *
|
---|
| 428 | * @param _bond bond to add
|
---|
| 429 | */
|
---|
[6c16a0] | 430 | void GLMoleculeObject_molecule::bondInserted(
|
---|
[96f14a] | 431 | QtObservedBond::ptr _bond)
|
---|
[8c001a] | 432 | {
|
---|
[96f14a] | 433 | static const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides =
|
---|
| 434 | boost::assign::list_of<GLMoleculeObject_bond::SideOfBond>
|
---|
| 435 | (GLMoleculeObject_bond::left)
|
---|
| 436 | (GLMoleculeObject_bond::right);
|
---|
| 437 | LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bonds " << _bond->getBondIndex());
|
---|
[8c001a] | 438 | //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
|
---|
| 439 |
|
---|
[96f14a] | 440 | const ObservedValue_Index_t bondid = _bond->getIndex();
|
---|
| 441 | const std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =
|
---|
| 442 | BondsinSceneMap.equal_range(bondid);
|
---|
| 443 | if (iters.first == iters.second) {
|
---|
| 444 | for (size_t i=0;i<2;++i) {
|
---|
| 445 | GLMoleculeObject_bond * bondObject =
|
---|
| 446 | new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, _bond, bondsides[i]);
|
---|
| 447 | connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
| 448 | BondsinSceneMap.insert( std::make_pair(bondid, bondObject) );
|
---|
| 449 | }
|
---|
[8c001a] | 450 | } else {
|
---|
[96f14a] | 451 | for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {
|
---|
| 452 | iter->second->resetPosition();
|
---|
| 453 | iter->second->resetWidth();
|
---|
| 454 | }
|
---|
[8c001a] | 455 | }
|
---|
[8d5fbf1] | 456 | emit changed();
|
---|
[8c001a] | 457 | emit changeOccured();
|
---|
| 458 | }
|
---|
| 459 |
|
---|
| 460 | /** Removes a bond from the scene.
|
---|
| 461 | *
|
---|
| 462 | * @param _bond bond to remove
|
---|
| 463 | */
|
---|
[96f14a] | 464 | void GLMoleculeObject_molecule::bondRemoved(ObservedValue_Index_t _id)
|
---|
[8c001a] | 465 | {
|
---|
[96f14a] | 466 | LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond to id " << _id);
|
---|
[8c001a] | 467 | {
|
---|
| 468 | // left bond
|
---|
[96f14a] | 469 | const std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =
|
---|
| 470 | BondsinSceneMap.equal_range(_id);
|
---|
| 471 | for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {
|
---|
| 472 | GLMoleculeObject_bond *bondObject = iter->second;
|
---|
| 473 | bondObject->disconnect();
|
---|
| 474 | delete bondObject; // is done by signal from bond itself
|
---|
| 475 | //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
|
---|
| 476 | }
|
---|
| 477 | BondsinSceneMap.erase(_id);
|
---|
[8c001a] | 478 | }
|
---|
| 479 |
|
---|
[8d5fbf1] | 480 | emit changed();
|
---|
[8c001a] | 481 | emit changeOccured();
|
---|
| 482 | }
|
---|
| 483 |
|
---|
[34e7fdb] | 484 | void GLMoleculeObject_molecule::setVisible(bool value)
|
---|
| 485 | {
|
---|
| 486 | // first update the mesh if we are going to be visible now
|
---|
| 487 | if (value)
|
---|
[7b5984] | 488 | updateTesselationHull();
|
---|
[34e7fdb] | 489 | // then emit onward
|
---|
| 490 | GLMoleculeObject::setVisible(value);
|
---|
[8d5fbf1] | 491 |
|
---|
| 492 | emit changed();
|
---|
| 493 | emit changeOccured();
|
---|
[34e7fdb] | 494 | }
|
---|
| 495 |
|
---|
[8c001a] | 496 | std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t)
|
---|
| 497 | {
|
---|
| 498 | ost << t.first << "," << t.second;
|
---|
| 499 | return ost;
|
---|
| 500 | }
|
---|
[34e7fdb] | 501 |
|
---|
[9a7ef9] | 502 | void GLMoleculeObject_molecule::wasClicked()
|
---|
| 503 | {
|
---|
[494478] | 504 | LOG(4, "INFO: GLMoleculeObject_molecule: atom "
|
---|
| 505 | << ObservedMolecule->getMolIndex() << " has been clicked");
|
---|
| 506 | emit moleculeClicked(ObservedMolecule->getMolIndex());
|
---|
[9a7ef9] | 507 | }
|
---|