source: src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp@ 59f1bc

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 59f1bc was 59f1bc, checked in by Frederik Heber <heber@…>, 9 years ago

All ..Inserted/..Removed signals now go through GLWorldScene.

  • this should enforce synchronicity of the signals. If we mix direct and queued connections, then this cannot be ensured.
  • the idea is that GLWorldScene gets all Inserted/Removed signals for atoms and molecules from the QtObservedInstanceBoard. It connects to each QtObservedMolecule and thus can call the GLMoleculeObject_molecule's atomInserted, atomRemoved functions in sequence.
  • removed RemovalMolecules, no longer needed.
  • we now enforce with mutexes that instantation of molecule and MissedStateMap do not interfere, i.e. it is always perfectly clear whether to push a signal into the Map or whether to call the function of the present GLMolObj_mol.
  • FIX: MoleculesInScene_mutex has not been used properly, now is.
  • DOCU: Updated construct qt-gu documentation with the new concept.
  • Property mode set to 100644
File size: 20.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
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/>.
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>
40#include <Qt3D/qglbuilder.h>
41
42#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp"
43
44#include "CodePatterns/MemDebug.hpp"
45
46#include <boost/assign.hpp>
47
48#include "CodePatterns/Assert.hpp"
49#include "CodePatterns/IteratorAdaptors.hpp"
50#include "CodePatterns/Log.hpp"
51
52#include "LinearAlgebra/Vector.hpp"
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"
59#include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
60#include "Atom/TesselPoint.hpp"
61#include "World.hpp"
62
63using namespace boost::assign;
64
65static Observable::channels_t getAllAtomicChangesChannels()
66{
67 Observable::channels_t channels;
68 channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
69 return channels;
70}
71
72const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels());
73
74static QGLSceneNode *createMoleculeMesh(const QGeometryData &_geo)
75{
76 // Build a mesh from the geometry.
77 QGLBuilder builder;
78 builder.addTriangles(_geo);
79 QGLSceneNode *mesh = builder.finalizedSceneNode();
80 return mesh;
81}
82
83GLMoleculeObject_molecule::GLMoleculeObject_molecule(
84 QObject *parent,
85 QtObservedInstanceBoard &_board,
86 QtObservedMolecule::ptr &_ObservedMolecule) :
87 GLMoleculeObject((QGLSceneNode *)NULL, parent),
88 owner(NULL),
89 molref(QtObservedMolecule::getMolecule(_ObservedMolecule->getMolIndex())),
90 hoverAtomId(-1),
91 board(_board),
92 ObservedMolecule(_ObservedMolecule)
93{
94 init(ObservedMolecule->getMolIndex());
95}
96
97GLMoleculeObject_molecule::GLMoleculeObject_molecule(
98 QGLSceneNode *mesh[],
99 QObject *parent,
100 QtObservedInstanceBoard &_board,
101 QtObservedMolecule::ptr &_ObservedMolecule) :
102 GLMoleculeObject(mesh, parent),
103 owner(NULL),
104 molref(QtObservedMolecule::getMolecule(_ObservedMolecule->getMolIndex())),
105 hoverAtomId(-1),
106 board(_board),
107 ObservedMolecule(_ObservedMolecule)
108{
109 init(ObservedMolecule->getMolIndex());
110}
111
112void GLMoleculeObject_molecule::init(const moleculeId_t _molid)
113{
114 setObjectId(_molid);
115 setMaterial(getMaterial(1));
116
117 m_selected = const_cast<const World &>(World::getInstance()).isMoleculeSelected(_molid);
118
119 // initially, atoms and bonds should be visible
120 m_visible = false;
121
122 connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
123 connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
124 connect (ObservedMolecule.get(), SIGNAL(tesselationhullChanged()), this, SLOT(resetTesselationHull()));
125 connect (ObservedMolecule.get(), SIGNAL(boundingboxChanged()), this, SLOT(resetBoundingBox()));
126 connect (ObservedMolecule.get(), SIGNAL(indexChanged(const moleculeId_t, const moleculeId_t)),
127 this, SLOT(resetIndex(const moleculeId_t, const moleculeId_t)));
128 /// these are channeled through GLWorldScene instead to ensure synchronicity
129// connect (ObservedMolecule.get(), SIGNAL(atomInserted(QtObservedAtom::ptr)),
130// this, SLOT(atomInserted(QtObservedAtom::ptr)) );
131// connect (ObservedMolecule.get(), SIGNAL(atomRemoved(const atomId_t)),
132// this, SLOT(atomRemoved(const atomId_t)) );
133 connect (ObservedMolecule.get(), SIGNAL(selectedChanged()), this, SLOT(resetSelected()));
134
135 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
136}
137
138GLMoleculeObject_molecule::~GLMoleculeObject_molecule()
139{}
140
141void GLMoleculeObject_molecule::addAtomBonds(
142 const bond::ptr &_bond,
143 const GLMoleculeObject_bond::SideOfBond _side
144 )
145{
146 bool bond_present = false;
147 const BondIds ids = getBondIds(_bond, _side);
148 // check whether bond is not present already
149 bond_present = BondsinSceneMap.count(ids);
150 if (!bond_present)
151 bondInserted(ids.first, ids.second, _side);
152 else {
153 BondsinSceneMap[ids]->resetPosition();
154 BondsinSceneMap[ids]->resetWidth();
155 }
156}
157
158QGeometryData GLMoleculeObject_molecule::updateTesselationHull() const
159{
160 QGeometryData geo;
161
162 const molecule * const molref =
163 QtObservedMolecule::getMolecule(ObservedMolecule->getMolIndex());
164 if (molref == NULL) {
165 ELOG(1, "Could not createMoleculeMesh, molecule with id "
166 << ObservedMolecule->getMolIndex() << " already gone.");
167 return geo;
168 }
169 double minradius = 2.; // TODO: set to maximum bond length value
170 LOG(3, "DEBUG: Molecule fits into sphere of radius " << minradius);
171 // check minimum bond radius in molecule
172 double minlength = std::numeric_limits<double>::max();
173 for (molecule::const_iterator iter = molref->begin();
174 iter != molref->end(); ++iter) {
175 const BondList &ListOfBonds = (*iter)->getListOfBonds();
176 for (BondList::const_iterator bonditer = ListOfBonds.begin();
177 bonditer != ListOfBonds.end(); ++bonditer) {
178 const double bond_distance = (*bonditer)->GetDistance();
179 minlength = std::min(bond_distance, minlength);
180 }
181 }
182 minradius = std::max( std::max(minradius, minlength), 1.);
183
184 // we need at least three points for tesselation
185 if (getPresentAtoms().size() >= 3) {
186 // Tesselate the points.
187 Tesselation T;
188 PointCloudAdaptor<molecule> cloud(
189 const_cast<molecule *>(molref),
190 ObservedMolecule->getMolName());
191 T(cloud, minradius);
192
193 // Fill the points into a Qt geometry.
194 LinkedCell_deprecated LinkedList(cloud, minradius);
195 std::map<int, int> indices;
196 std::map<int, Vector> normals;
197 int index = 0;
198 for (PointMap::const_iterator piter = T.PointsOnBoundary.begin();
199 piter != T.PointsOnBoundary.end(); ++piter) {
200 const Vector &point = piter->second->getPosition();
201 // add data to the primitive
202 geo.appendVertex(QVector3D(point[0], point[1], point[2]));
203 Vector normalvector;
204 for (LineMap::const_iterator lineiter = piter->second->lines.begin();
205 lineiter != piter->second->lines.end(); ++lineiter)
206 for (TriangleMap::const_iterator triangleiter = lineiter->second->triangles.begin();
207 triangleiter != lineiter->second->triangles.end(); ++triangleiter)
208 normalvector +=
209 triangleiter->second->NormalVector;
210 normalvector.Normalize();
211 geo.appendNormal(QVector3D(normalvector[0], normalvector[1], normalvector[2]));
212 geo.appendColor(QColor(1, 1, 1, 1));
213 geo.appendTexCoord(QVector2D(0, 0));
214 indices.insert( std::make_pair( piter->second->getNr(), index++));
215 }
216
217 // Fill the tesselated triangles into the geometry.
218 for (TriangleMap::const_iterator runner = T.TrianglesOnBoundary.begin();
219 runner != T.TrianglesOnBoundary.end(); runner++) {
220 int v[3];
221 for (size_t i=0; i<3; ++i)
222 v[i] = runner->second->endpoints[i]->getNr();
223
224 // Sort the vertices so the triangle is clockwise (relative to the normal vector).
225 Vector cross = T.PointsOnBoundary[v[1]]->getPosition() - T.PointsOnBoundary[v[0]]->getPosition();
226 cross.VectorProduct(T.PointsOnBoundary[v[2]]->getPosition() - T.PointsOnBoundary[v[0]]->getPosition());
227 if (cross.ScalarProduct(runner->second->NormalVector) > 0)
228 geo.appendIndices(indices[v[0]], indices[v[1]], indices[v[2]]);
229 else
230 geo.appendIndices(indices[v[0]], indices[v[2]], indices[v[1]]);
231 }
232 }
233
234 return geo;
235}
236
237void GLMoleculeObject_molecule::resetTesselationHull()
238{
239 if (owner != NULL) {
240 TesselationHull = updateTesselationHull();
241 updateMesh(createMoleculeMesh(TesselationHull));
242 }
243}
244
245void GLMoleculeObject_molecule::resetBoundingBox()
246{
247 molecule::BoundingBoxInfo info = ObservedMolecule->getBoundingBox();
248 setPosition(QVector3D(info.position[0], info.position[1], info.position[2]));
249 setScale(info.radius + 0.3); // getBoundingSphere() only sees atoms as points, so make the box a bit bigger
250}
251
252void GLMoleculeObject_molecule::resetIndex(const moleculeId_t, const moleculeId_t)
253{
254 const atomId_t newId = ObservedMolecule->getMolIndex();
255 const size_t oldId = objectId();
256 ASSERT( newId != oldId,
257 "GLMoleculeObject_molecule::resetIndex() - index "+toString(newId)+" did not change.");
258 LOG(4, "INFO: GLMoleculeObject_molecule: new index is "+toString(newId)+".");
259 setObjectId(newId);
260
261 emit indexChanged(this, oldId, newId);
262}
263
264void GLMoleculeObject_molecule::resetSelected()
265{
266 const bool new_selected = ObservedMolecule->getMolSelected();
267 m_selected = new_selected;
268
269 emit changed();
270}
271
272void GLMoleculeObject_molecule::initialize(QGLView *view, QGLPainter *painter)
273{
274 // Initialize all of the mesh objects that we have as children.
275 if (m_visible) {
276 GLMoleculeObject::initialize(view, painter);
277 } else {
278 foreach (QObject *obj, children()) {
279 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
280 if (meshobj)
281 meshobj->initialize(view, painter);
282 }
283 }
284}
285
286void GLMoleculeObject_molecule::draw(QGLPainter *painter, const QVector4D &cameraPlane)
287{
288 // draw either molecule's mesh or all atoms and bonds
289 if (m_visible) {
290 resetTesselationHull();
291
292 painter->modelViewMatrix().push();
293
294 // Apply the material and effect to the painter.
295 QGLMaterial *material;
296 if (m_hovering)
297 material = m_hoverMaterial;
298 else if (m_selected)
299 material = m_selectionMaterial;
300 else
301 material = m_material;
302
303 ASSERT(material, "GLMoleculeObject::draw: chosen material is NULL");
304
305 painter->setColor(material->diffuseColor());
306 painter->setFaceMaterial(QGL::AllFaces, material);
307 if (m_effect)
308 painter->setUserEffect(m_effect);
309 else
310 painter->setStandardEffect(QGL::LitMaterial);
311
312 // Mark the object for object picking purposes.
313 int prevObjectId = painter->objectPickId();
314 if (m_objectId != -1)
315 painter->setObjectPickId(m_objectId);
316
317 m_mesh[0]->draw(painter);
318
319 // Turn off the user effect, if present.
320 if (m_effect)
321 painter->setStandardEffect(QGL::LitMaterial);
322
323 // Revert to the previous object identifier.
324 painter->setObjectPickId(prevObjectId);
325
326 // Restore the modelview matrix.
327 painter->modelViewMatrix().pop();
328
329 // GLMoleculeObject::draw(painter, cameraPlane);
330 } else {
331 // Draw all of the mesh objects that we have as children.
332 foreach (QObject *obj, children()) {
333 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
334 if (meshobj)
335 meshobj->draw(painter, cameraPlane);
336 }
337
338 // update bounding box prior to selection
339 resetBoundingBox();
340
341 painter->modelViewMatrix().push();
342 painter->modelViewMatrix().translate(m_position);
343 if (m_rotationAngle != 0.0f)
344 painter->modelViewMatrix().rotate(m_rotationAngle, m_rotationVector);
345 if ((m_scaleX != 1.0f) || (m_scaleY != 1.0f) || (m_scaleZ != 1.0f))
346 painter->modelViewMatrix().scale(m_scaleX, m_scaleY, m_scaleZ);
347
348 // Draw a box around the mesh, if selected.
349 if (m_selected)
350 drawSelectionBox(painter);
351
352 // Restore the modelview matrix.
353 painter->modelViewMatrix().pop();
354 }
355}
356
357/** Adds an atom of this molecule to the scene.
358 *
359 * @param _atom atom to add
360 */
361void GLMoleculeObject_molecule::atomInserted(QtObservedAtom::ptr _atom)
362{
363 const atomId_t atomid = _atom->getAtomIndex();
364 LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomInserted for atom "+toString(atomid)+".");
365
366 if (_atom) {
367 GLMoleculeObject_atom *atomObject =
368 new GLMoleculeObject_atom(
369 GLMoleculeObject::meshSphere,
370 this,
371 _atom);
372 ASSERT( atomObject != NULL,
373 "GLMoleculeObject_molecule::atomInserted - could not create atom object for "+toString(atomid));
374 AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid);
375 ASSERT(iter == AtomsinSceneMap.end(),
376 "GLMoleculeObject_molecule::atomInserted - same atom with id "+toString(atomid)+" added again.");
377 AtomsinSceneMap.insert( make_pair(atomid, atomObject) );
378
379 qRegisterMetaType<atomId_t>("atomId_t");
380 qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
381 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SIGNAL(atomClicked(atomId_t)));
382 connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
383 connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
384 connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
385 // connect (atomObject, SIGNAL(bondsChanged()), this, SLOT(bondInserted(const atomId_t, const atomId_t, const GLMoleculeObject_bond::SideOfBond)));
386 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)));
387 connect (atomObject, SIGNAL(BondsRemoved(const atomId_t, const atomId_t)), this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
388 connect (atomObject, SIGNAL(indexChanged(GLMoleculeObject_atom*, const atomId_t, const atomId_t)), this, SLOT(changeAtomId(GLMoleculeObject_atom*, const atomId_t, const atomId_t)));
389
390 if (m_objectId == -1)
391 setObjectId(atomid);
392
393 emit changed();
394 emit changeOccured();
395 }
396}
397
398/** Removes an atom of this molecule from the scene.
399 *
400 * We just the id as the atom might have already been destroyed.
401 *
402 * @param _id id of atom to remove
403 */
404void GLMoleculeObject_molecule::atomRemoved(const atomId_t _id)
405{
406 LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomRemoved for atom "+toString(_id)+".");
407 // bonds are removed by signal coming from ~bond
408
409 if ((unsigned int)m_objectId == _id)
410 setObjectId(-1);
411
412 // remove atoms
413 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
414 ASSERT(iter != AtomsinSceneMap.end(),
415 "GLMoleculeObject_molecule::atomRemoved() - atom "+toString(_id)+" not on display.");
416 GLMoleculeObject_atom *atomObject = iter->second;
417 AtomsinSceneMap.erase(iter);
418 atomObject->disconnect();
419 delete atomObject;
420
421 emit changed();
422 emit changeOccured();
423}
424
425void GLMoleculeObject_molecule::hoverChangedSignalled(GLMoleculeObject *ob)
426{
427 // Find the atom, ob corresponds to.
428 hoverAtomId = -1;
429 GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
430 if (atomObject){
431 for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
432 if (iter->second == atomObject)
433 hoverAtomId = iter->first;
434 }
435
436 // Propagate signal.
437 emit hoverChanged(hoverAtomId);
438 } else {
439 // Find the atom, ob corresponds to.
440 GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob);
441 if (moleculeObject == this){
442 // Propagate signal.
443 emit hoverChanged(ObservedMolecule->getMolIndex(), 0);
444 }
445 }
446}
447
448
449/** Helper function to get bond ids in the correct order for BondNodeMap.
450 *
451 * \return pair of ids in correct order.
452 */
453GLMoleculeObject_molecule::BondIds GLMoleculeObject_molecule::getBondIds(
454 const bond::ptr _bond,
455 const enum GLMoleculeObject_bond::SideOfBond _side)
456{
457 BondIds ids;
458 switch (_side) {
459 case GLMoleculeObject_bond::left:
460 ids = std::make_pair(_bond->leftatom->getId(), _bond->rightatom->getId());
461 break;
462 case GLMoleculeObject_bond::right:
463 ids = std::make_pair(_bond->rightatom->getId(), _bond->leftatom->getId());
464 break;
465 }
466 return ids;
467}
468
469/** Adds a bond to the scene.
470 *
471 * @param _bond bond to add
472 * @param side which side of the bond (left or right)
473 */
474void GLMoleculeObject_molecule::bondInserted(
475 const atomId_t _left, const atomId_t _right,
476 const enum GLMoleculeObject_bond::SideOfBond _side)
477{
478 LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(_left)
479 +toString(_right)+".");
480 //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
481
482 const BondIds ids( std::make_pair(_left, _right) );
483 BondNodeMap::iterator iter = BondsinSceneMap.find(ids);
484 if (iter == BondsinSceneMap.end()) {
485 GLMoleculeObject_bond * bondObject =
486 new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, ids, _side);
487 connect (
488 bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)),
489 this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
490 connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
491 BondsinSceneMap.insert( make_pair(ids, bondObject) );
492 // BondIdsinSceneMap.insert( Leftids );
493 } else {
494 iter->second->resetPosition();
495 iter->second->resetWidth();
496 }
497 emit changed();
498 emit changeOccured();
499}
500
501/** Removes a bond from the scene.
502 *
503 * @param _bond bond to remove
504 */
505void GLMoleculeObject_molecule::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
506{
507 LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+".");
508 {
509 // left bond
510 const BondIds Leftids( make_pair(leftnr, rightnr) );
511 BondNodeMap::iterator leftiter = BondsinSceneMap.find( Leftids );
512 ASSERT(leftiter != BondsinSceneMap.end(),
513 "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
514 +toString(rightnr)+" not on display.");
515 GLMoleculeObject_bond *bondObject = leftiter->second;
516 bondObject->disconnect();
517 BondsinSceneMap.erase(leftiter);
518 delete bondObject; // is done by signal from bond itself
519 //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
520 }
521
522 emit changed();
523 emit changeOccured();
524}
525
526void GLMoleculeObject_molecule::setVisible(bool value)
527{
528 // first update the mesh if we are going to be visible now
529 if (value)
530 updateTesselationHull();
531 // then emit onward
532 GLMoleculeObject::setVisible(value);
533
534 emit changed();
535 emit changeOccured();
536}
537
538std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t)
539{
540 ost << t.first << "," << t.second;
541 return ost;
542}
543
544void GLMoleculeObject_molecule::wasClicked()
545{
546 LOG(4, "INFO: GLMoleculeObject_molecule: atom "
547 << ObservedMolecule->getMolIndex() << " has been clicked");
548 emit moleculeClicked(ObservedMolecule->getMolIndex());
549}
550
551void GLMoleculeObject_molecule::changeAtomId(
552 GLMoleculeObject_atom *ob,
553 const atomId_t oldId,
554 const atomId_t newId)
555{
556 LOG(3, "INFO: GLMoleculeObject_molecule - change atom id " << oldId << " to " << newId << ".");
557
558 // Remove from map.
559 AtomNodeMap::iterator iter = AtomsinSceneMap.find(oldId);
560 ASSERT(iter != AtomsinSceneMap.end(),
561 "GLMoleculeObject_molecule::changeAtomId() - atom with old id "+toString(oldId)+" not on display.");
562 ASSERT(iter->second == ob,
563 "GLMoleculeObject_molecule::changeAtomId() - atom with id "
564 +toString(oldId)+" does not match with object in AtomsinSceneMap.");
565 AtomsinSceneMap.erase(iter);
566
567 // Reinsert with new id.
568 {
569 AtomNodeMap::iterator iter = AtomsinSceneMap.find(newId);
570 ASSERT(iter == AtomsinSceneMap.end(),
571 "GLMoleculeObject_molecule::changeAtomId() - atom with new id "+toString(newId)+" already known.");
572 }
573 AtomsinSceneMap.insert( make_pair(newId, ob) );
574}
575
576
577GLMoleculeObject_molecule::atoms_t GLMoleculeObject_molecule::getPresentAtoms() const
578{
579 atoms_t returnAtomIds;
580 returnAtomIds.insert(
581 MapKeyConstIterator<AtomNodeMap::const_iterator>(const_cast<const AtomNodeMap &>(AtomsinSceneMap).begin()),
582 MapKeyConstIterator<AtomNodeMap::const_iterator>(const_cast<const AtomNodeMap &>(AtomsinSceneMap).end()));
583 return returnAtomIds;
584}
Note: See TracBrowser for help on using the repository browser.