source: src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp@ 5cd3a33

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 5cd3a33 was 5cd3a33, checked in by Frederik Heber <heber@…>, 9 years ago

Removed QtSelectionUsage in GLWorldView and related.

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