source: src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp@ 8281cc

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 8281cc was 1c0961, checked in by Frederik Heber <heber@…>, 9 years ago

FIX: indexChanged from QtObserved... transmit both old and new id.

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