[907636] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 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/>.
|
---|
[907636] | 22 | */
|
---|
| 23 |
|
---|
| 24 | /*
|
---|
| 25 | * GLMoleculeObject_atom.cpp
|
---|
| 26 | *
|
---|
| 27 | * Created on: Aug 17, 2011
|
---|
| 28 | * Author: heber
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | // include config.h
|
---|
| 32 | #ifdef HAVE_CONFIG_H
|
---|
| 33 | #include <config.h>
|
---|
| 34 | #endif
|
---|
| 35 |
|
---|
| 36 | #include "GLMoleculeObject_atom.hpp"
|
---|
| 37 |
|
---|
| 38 | #include <Qt3D/qglscenenode.h>
|
---|
| 39 |
|
---|
| 40 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 41 |
|
---|
| 42 | #include "CodePatterns/Assert.hpp"
|
---|
[7188b1] | 43 | #include "CodePatterns/Log.hpp"
|
---|
[02ce36] | 44 | #include "CodePatterns/Observer/Notification.hpp"
|
---|
[907636] | 45 |
|
---|
[534374] | 46 | #include <algorithm>
|
---|
| 47 | #include <boost/assign.hpp>
|
---|
| 48 |
|
---|
[2ad1ec] | 49 | #include "Atom/atom.hpp"
|
---|
| 50 | #include "Bond/bond.hpp"
|
---|
[7188b1] | 51 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
[3bdb6d] | 52 | #include "Element/element.hpp"
|
---|
[534374] | 53 | #include "Element/periodentafel.hpp"
|
---|
[907636] | 54 | #include "LinearAlgebra/Vector.hpp"
|
---|
[2ad1ec] | 55 | #include "GLMoleculeObject_bond.hpp"
|
---|
[7188b1] | 56 | #include "World.hpp"
|
---|
[89b992] | 57 | #include "WorldTime.hpp"
|
---|
[907636] | 58 |
|
---|
[7c7c4a] | 59 | #include "ObservedValue_wCallback.hpp"
|
---|
| 60 |
|
---|
[534374] | 61 | using namespace boost::assign;
|
---|
| 62 |
|
---|
| 63 | static const Observable::channels_t getAtomBondsChannels()
|
---|
| 64 | {
|
---|
| 65 | Observable::channels_t channels;
|
---|
| 66 | channels += AtomObservable::BondsAdded, AtomObservable::BondsRemoved;
|
---|
| 67 | return channels;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | // static entities
|
---|
| 71 | const Observable::channels_t
|
---|
| 72 | GLMoleculeObject_atom::AtomIndexChannels(1, AtomObservable::IndexChanged);
|
---|
| 73 | const Observable::channels_t
|
---|
| 74 | GLMoleculeObject_atom::AtomPositionChannels(1, AtomObservable::PositionChanged);
|
---|
| 75 | const Observable::channels_t
|
---|
| 76 | GLMoleculeObject_atom::AtomElementChannels(1, AtomObservable::ElementChanged);
|
---|
| 77 | const Observable::channels_t
|
---|
| 78 | GLMoleculeObject_atom::AtomBondsChannels(getAtomBondsChannels());
|
---|
| 79 |
|
---|
[917659] | 80 | GLMoleculeObject_atom::GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atomId_t _id) :
|
---|
[bca99d] | 81 | GLMoleculeObject(mesh, parent),
|
---|
[917659] | 82 | Observer(std::string("GLMoleculeObject_atom")+toString(_id)),
|
---|
[534374] | 83 | atomref(getAtom(_id)),
|
---|
[7c7c4a] | 84 | ObservedValues(MAX_ObservedTypes),
|
---|
| 85 | subjectKilledCount(0),
|
---|
[534374] | 86 | owner(NULL)
|
---|
[7188b1] | 87 | {
|
---|
[16bd37] | 88 | boost::function<void()> subjectKilled =
|
---|
| 89 | boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this);
|
---|
| 90 | initObservedValues(ObservedValues, _id, atomref, subjectKilled);
|
---|
[7c7c4a] | 91 |
|
---|
[534374] | 92 | setObjectId(_id);
|
---|
| 93 | resetPosition();
|
---|
| 94 | resetElement();
|
---|
[7188b1] | 95 |
|
---|
[a39d72] | 96 | m_selected = const_cast<const World &>(World::getInstance()).isAtomSelected(_id);
|
---|
| 97 |
|
---|
[534374] | 98 | // sign On
|
---|
| 99 | activateObserver();
|
---|
[7188b1] | 100 |
|
---|
[534374] | 101 | // atomref is only used for caching the ref, it must be used elswhere
|
---|
| 102 | const_cast<atom *&>(atomref) = NULL;
|
---|
[7188b1] | 103 |
|
---|
| 104 | connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
|
---|
[534374] | 105 | connect( this, SIGNAL(idChanged()), this, SLOT(resetIndex()), Qt::QueuedConnection);
|
---|
| 106 | connect( this, SIGNAL(elementChanged()), this, SLOT(resetElement()), Qt::QueuedConnection);
|
---|
| 107 | connect( this, SIGNAL(positionChanged()), this, SLOT(resetPosition()), Qt::QueuedConnection);
|
---|
| 108 | connect( this, SIGNAL(bondsChanged()), this, SLOT(resetPosition()), Qt::QueuedConnection);
|
---|
[7188b1] | 109 | }
|
---|
| 110 |
|
---|
[534374] | 111 | void GLMoleculeObject_atom::activateObserver()
|
---|
[9c18e4] | 112 | {
|
---|
[534374] | 113 | if (atomref != NULL) {
|
---|
| 114 | owner = static_cast<const Observable *>(atomref);
|
---|
| 115 | owner->signOn(this, AtomObservable::IndexChanged);
|
---|
| 116 | owner->signOn(this, AtomObservable::PositionChanged);
|
---|
| 117 | owner->signOn(this, AtomObservable::ElementChanged);
|
---|
| 118 | owner->signOn(this, AtomObservable::BondsAdded);
|
---|
| 119 | owner->signOn(this, AtomObservable::BondsRemoved);
|
---|
[c736fe] | 120 | }
|
---|
[9c18e4] | 121 | }
|
---|
| 122 |
|
---|
[534374] | 123 |
|
---|
| 124 | void GLMoleculeObject_atom::deactivateObserver()
|
---|
[7188b1] | 125 | {
|
---|
[534374] | 126 | // sign Off
|
---|
| 127 | if (owner != NULL) {
|
---|
| 128 | owner->signOff(this, AtomObservable::IndexChanged);
|
---|
| 129 | owner->signOff(this, AtomObservable::PositionChanged);
|
---|
| 130 | owner->signOff(this, AtomObservable::ElementChanged);
|
---|
| 131 | owner->signOff(this, AtomObservable::BondsAdded);
|
---|
| 132 | owner->signOff(this, AtomObservable::BondsRemoved);
|
---|
| 133 | owner = NULL;
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | GLMoleculeObject_atom::~GLMoleculeObject_atom()
|
---|
| 138 | {
|
---|
| 139 | deactivateObserver();
|
---|
[16bd37] | 140 | destroyObservedValues(ObservedValues);
|
---|
[534374] | 141 | }
|
---|
| 142 |
|
---|
| 143 | void GLMoleculeObject_atom::resetIndex()
|
---|
| 144 | {
|
---|
[7c7c4a] | 145 | const atomId_t newId = getAtomIndex();
|
---|
[534374] | 146 | const size_t oldId = objectId();
|
---|
| 147 | ASSERT( newId != oldId,
|
---|
| 148 | "GLMoleculeObject_atom::updateIndex() - index "+toString(newId)+" did not change.");
|
---|
| 149 | LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(newId)+".");
|
---|
| 150 | setObjectId(newId);
|
---|
| 151 |
|
---|
| 152 | emit indexChanged(this, oldId, newId);
|
---|
[7188b1] | 153 | }
|
---|
| 154 |
|
---|
| 155 | void GLMoleculeObject_atom::resetPosition()
|
---|
[907636] | 156 | {
|
---|
[7c7c4a] | 157 | const Vector Position = getAtomPosition();
|
---|
[534374] | 158 | LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
|
---|
| 159 | setPosition(QVector3D(Position[0], Position[1], Position[2]));
|
---|
[7188b1] | 160 | }
|
---|
| 161 |
|
---|
| 162 | void GLMoleculeObject_atom::resetElement()
|
---|
| 163 | {
|
---|
| 164 | size_t elementno = 0;
|
---|
[534374] | 165 | const element * const _type = World::getInstance().
|
---|
[7c7c4a] | 166 | getPeriode()->FindElement(getAtomElement());
|
---|
[c60665] | 167 | if (_type != NULL) {
|
---|
| 168 | elementno = _type->getAtomicNumber();
|
---|
| 169 | } else { // if no element yet, set to hydrogen
|
---|
| 170 | elementno = 1;
|
---|
| 171 | }
|
---|
| 172 | LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
|
---|
| 173 |
|
---|
| 174 | // set materials
|
---|
| 175 | QGLMaterial *elementmaterial = getMaterial(elementno);
|
---|
| 176 | ASSERT(elementmaterial != NULL,
|
---|
| 177 | "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
|
---|
| 178 | setMaterial(elementmaterial);
|
---|
| 179 |
|
---|
| 180 | // set scale
|
---|
| 181 | double radius = 0.;
|
---|
| 182 | if (_type != NULL) {
|
---|
| 183 | radius = _type->getVanDerWaalsRadius();
|
---|
| 184 | } else {
|
---|
| 185 | radius = 0.5;
|
---|
| 186 | }
|
---|
| 187 | setScale( radius / 4. );
|
---|
[534374] | 188 | }
|
---|
[f115cc] | 189 |
|
---|
[534374] | 190 | void GLMoleculeObject_atom::resetBonds()
|
---|
| 191 | {
|
---|
[7c7c4a] | 192 | ListOfBonds_t ListOfBonds_new = getAtomBonds();
|
---|
[534374] | 193 | std::sort(ListOfBonds_new.begin(), ListOfBonds_new.end());
|
---|
| 194 | ListOfBonds_t BondsToAdd;
|
---|
| 195 | std::set_difference(
|
---|
| 196 | ListOfBonds_new.begin(), ListOfBonds_new.end(),
|
---|
| 197 | ListOfBonds.begin(), ListOfBonds.end(),
|
---|
| 198 | std::back_inserter(BondsToAdd));
|
---|
| 199 | ListOfBonds_t BondsToRemove;
|
---|
| 200 | std::set_difference(
|
---|
| 201 | ListOfBonds.begin(), ListOfBonds.end(),
|
---|
| 202 | ListOfBonds_new.begin(), ListOfBonds_new.end(),
|
---|
| 203 | std::back_inserter(BondsToRemove));
|
---|
| 204 | for (ListOfBonds_t::const_iterator iter = BondsToAdd.begin();
|
---|
| 205 | iter != BondsToAdd.end();
|
---|
| 206 | ++iter) {
|
---|
[7c7c4a] | 207 | const GLMoleculeObject_bond::SideOfBond side = (iter->first == getAtomIndex()) ?
|
---|
[534374] | 208 | GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
|
---|
| 209 | emit BondsAdded(iter->first, iter->second, side);
|
---|
| 210 | }
|
---|
| 211 | for (ListOfBonds_t::const_iterator iter = BondsToRemove.begin();
|
---|
| 212 | iter != BondsToRemove.end();
|
---|
| 213 | ++iter) {
|
---|
| 214 | emit BondsRemoved(iter->first, iter->second);
|
---|
| 215 | }
|
---|
| 216 | ListOfBonds = ListOfBonds_new;
|
---|
[7188b1] | 217 | }
|
---|
| 218 |
|
---|
[015f8c] | 219 | void GLMoleculeObject_atom::Selected()
|
---|
| 220 | {
|
---|
| 221 | ASSERT( !m_selected,
|
---|
| 222 | "GLMoleculeObject_atom::Selected() - 3D rep of atom is already selected.");
|
---|
| 223 | m_selected = true;
|
---|
| 224 |
|
---|
| 225 | emit changed();
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | void GLMoleculeObject_atom::Unselected()
|
---|
[7188b1] | 229 | {
|
---|
[015f8c] | 230 | ASSERT( m_selected,
|
---|
| 231 | "GLMoleculeObject_atom::Unselected() - 3D rep of atom is already unselected.");
|
---|
| 232 | m_selected = false;
|
---|
| 233 |
|
---|
| 234 | emit changed();
|
---|
[534374] | 235 | }
|
---|
[30cd0d] | 236 |
|
---|
[015f8c] | 237 |
|
---|
[534374] | 238 | void GLMoleculeObject_atom::draw(QGLPainter *painter, const QVector4D &cameraPlane)
|
---|
| 239 | {
|
---|
| 240 | // call old hook to do the actual paining
|
---|
| 241 | GLMoleculeObject::draw(painter, cameraPlane);
|
---|
[7188b1] | 242 | }
|
---|
| 243 |
|
---|
[534374] | 244 | void GLMoleculeObject_atom::wasClicked()
|
---|
[7188b1] | 245 | {
|
---|
[7c7c4a] | 246 | LOG(4, "INFO: GLMoleculeObject_atom: atom " << getAtomIndex() << " has been clicked");
|
---|
| 247 | emit clicked(getAtomIndex());
|
---|
[534374] | 248 | }
|
---|
[907636] | 249 |
|
---|
[534374] | 250 | const atom * const GLMoleculeObject_atom::getAtomConst(const atomId_t _id)
|
---|
| 251 | {
|
---|
| 252 | const atom * const _atom = const_cast<const World &>(World::getInstance()).
|
---|
| 253 | getAtom(AtomById(_id));
|
---|
| 254 | return _atom;
|
---|
| 255 | }
|
---|
[907636] | 256 |
|
---|
[534374] | 257 | atom * const GLMoleculeObject_atom::getAtom(const atomId_t _id)
|
---|
| 258 | {
|
---|
| 259 | atom * const _atom = World::getInstance().getAtom(AtomById(_id));
|
---|
| 260 | return _atom;
|
---|
| 261 | }
|
---|
[d53902] | 262 |
|
---|
[16bd37] | 263 | atomId_t GLMoleculeObject_atom::updateIndex()
|
---|
[534374] | 264 | {
|
---|
[54bdaa] | 265 | return const_cast<const World &>(World::getInstance()).lastChangedAtomId();
|
---|
[7188b1] | 266 | }
|
---|
[907636] | 267 |
|
---|
[16bd37] | 268 | Vector GLMoleculeObject_atom::updatePosition(
|
---|
| 269 | const boost::function<const atomId_t ()> &_getAtomIndex)
|
---|
[f115cc] | 270 | {
|
---|
[16bd37] | 271 | const atom * const _atom = getAtomConst(_getAtomIndex());
|
---|
[534374] | 272 | if (_atom != NULL) {
|
---|
| 273 | return _atom->getPosition();
|
---|
| 274 | } else {
|
---|
| 275 | return zeroVec;
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
[f115cc] | 278 |
|
---|
[16bd37] | 279 | atomicNumber_t GLMoleculeObject_atom::updateElement(
|
---|
| 280 | const boost::function<const atomId_t ()> &_getAtomIndex)
|
---|
[534374] | 281 | {
|
---|
[16bd37] | 282 | const atom * const _atom = getAtomConst(_getAtomIndex());
|
---|
[534374] | 283 | if (_atom != NULL) {
|
---|
| 284 | return _atom->getElementNo();
|
---|
| 285 | } else {
|
---|
| 286 | return (atomicNumber_t)-1;
|
---|
| 287 | }
|
---|
| 288 | }
|
---|
| 289 |
|
---|
[16bd37] | 290 | GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::updateBonds(
|
---|
| 291 | const boost::function<const atomId_t ()> &_getAtomIndex)
|
---|
[534374] | 292 | {
|
---|
| 293 | ListOfBonds_t ListOfBonds;
|
---|
[16bd37] | 294 | const atom * const _atom = getAtomConst(_getAtomIndex());
|
---|
[534374] | 295 | if (_atom != NULL) {
|
---|
[16bd37] | 296 | // make sure bonds is up-to-date
|
---|
[534374] | 297 | const BondList ListBonds = _atom->getListOfBonds();
|
---|
| 298 | for (BondList::const_iterator iter = ListBonds.begin();
|
---|
| 299 | iter != ListBonds.end();
|
---|
| 300 | ++iter)
|
---|
| 301 | ListOfBonds.insert( ListOfBonds.end(), std::make_pair(
|
---|
| 302 | (*iter)->leftatom->getId(),
|
---|
| 303 | (*iter)->rightatom->getId()) );
|
---|
| 304 | } else {
|
---|
[16bd37] | 305 | ELOG(2, "Atom with id "+toString(_getAtomIndex())+" is already gone.");
|
---|
[534374] | 306 | }
|
---|
| 307 | return ListOfBonds;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | void GLMoleculeObject_atom::update(Observable *publisher)
|
---|
| 311 | {
|
---|
| 312 | ASSERT(0, "GLMoleculeObject_atom::update() - we are not signed on for global updates.");
|
---|
[f115cc] | 313 | }
|
---|
| 314 |
|
---|
[7188b1] | 315 | void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
|
---|
[c736fe] | 316 | {
|
---|
[534374] | 317 | deactivateObserver();
|
---|
[7c7c4a] | 318 |
|
---|
| 319 | countsubjectKilled();
|
---|
[c736fe] | 320 | }
|
---|
[06ebf5] | 321 |
|
---|
[7188b1] | 322 | void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
|
---|
| 323 | {
|
---|
[534374] | 324 | // ObservedValues have been updated before, hence convert updates to Qt's signals
|
---|
| 325 | atom * const _atom = dynamic_cast<atom *>(publisher);
|
---|
| 326 | if (_atom != NULL) {
|
---|
[d53902] | 327 | switch (notification->getChannelNo()) {
|
---|
| 328 | case AtomObservable::IndexChanged:
|
---|
[534374] | 329 | emit idChanged();
|
---|
[d53902] | 330 | break;
|
---|
| 331 | case AtomObservable::PositionChanged:
|
---|
[534374] | 332 | emit positionChanged();
|
---|
| 333 | break;
|
---|
| 334 | case AtomObservable::ElementChanged:
|
---|
| 335 | emit elementChanged();
|
---|
[d53902] | 336 | break;
|
---|
| 337 | case AtomObservable::BondsAdded:
|
---|
[534374] | 338 | case AtomObservable::BondsRemoved:
|
---|
| 339 | emit bondsChanged();
|
---|
[917659] | 340 | break;
|
---|
[d53902] | 341 | default:
|
---|
[534374] | 342 | ASSERT(0, "GLMoleculeObject_atom::recieveNotification() - we are not signed on to channel "
|
---|
| 343 | +toString(notification->getChannelNo())+" of the atom.");
|
---|
[d53902] | 344 | break;
|
---|
| 345 | }
|
---|
[015f8c] | 346 | } else
|
---|
| 347 | ASSERT(0, "GLMoleculeObject_atom::recieveNotification() - received notification from unexpected source.");
|
---|
[06ebf5] | 348 | }
|
---|
[7c7c4a] | 349 |
|
---|
| 350 | void GLMoleculeObject_atom::countsubjectKilled()
|
---|
| 351 | {
|
---|
| 352 | ++subjectKilledCount;
|
---|
| 353 |
|
---|
| 354 | if (subjectKilledCount > ObservedValues.size())
|
---|
| 355 | emit InstanceRemoved(getAtomIndex());
|
---|
| 356 | }
|
---|
| 357 |
|
---|
[16bd37] | 358 | void GLMoleculeObject_atom::initObservedValues(
|
---|
| 359 | std::vector<boost::any> &_ObservedValues,
|
---|
| 360 | const atomId_t _id,
|
---|
| 361 | const atom * const _atomref,
|
---|
| 362 | const boost::function<void()> &_subjectKilled)
|
---|
[7c7c4a] | 363 | {
|
---|
[16bd37] | 364 | /* This is an old note from when the code was still part of cstor's initializer body.
|
---|
| 365 | * TODO: Probably does not apply anymore but has not yet been tested.
|
---|
| 366 | *
|
---|
| 367 | * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
|
---|
| 368 | * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
|
---|
| 369 | * the class has not been fully constructed yet. "This" itself seems to be working fine.
|
---|
| 370 | */
|
---|
| 371 |
|
---|
| 372 | ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
|
---|
| 373 | "GLMoleculeObject_atom::initObservedValues() - given ObservedValues has not correct size.");
|
---|
| 374 |
|
---|
| 375 | // fill ObservedValues: index first
|
---|
| 376 | const boost::function<atomId_t ()> AtomIndexUpdater(
|
---|
| 377 | boost::bind(&GLMoleculeObject_atom::updateIndex));
|
---|
| 378 |
|
---|
| 379 | ObservedValue_wCallback<atomId_t> * const IndexObservable =
|
---|
| 380 | new ObservedValue_wCallback<atomId_t>(
|
---|
| 381 | _atomref,
|
---|
| 382 | boost::bind(&GLMoleculeObject_atom::updateIndex),
|
---|
| 383 | "AtomIndex_"+toString(_id),
|
---|
| 384 | _id,
|
---|
| 385 | AtomIndexChannels,
|
---|
| 386 | _subjectKilled);
|
---|
| 387 | _ObservedValues[AtomIndex] = IndexObservable;
|
---|
| 388 |
|
---|
| 389 | const boost::function<const atomId_t ()> AtomIndexGetter =
|
---|
| 390 | boost::bind(&ObservedValue_wCallback<atomId_t>::get,
|
---|
| 391 | IndexObservable);
|
---|
| 392 |
|
---|
| 393 | // fill ObservedValues: then all the other that need index
|
---|
| 394 | const boost::function<Vector ()> AtomPositionUpdater(
|
---|
| 395 | boost::bind(&GLMoleculeObject_atom::updatePosition, AtomIndexGetter));
|
---|
| 396 | const boost::function<atomicNumber_t ()> AtomElementUpdater(
|
---|
| 397 | boost::bind(&GLMoleculeObject_atom::updateElement, AtomIndexGetter));
|
---|
| 398 | const boost::function<ListOfBonds_t ()> AtomBondsUpdater(
|
---|
| 399 | boost::bind(&GLMoleculeObject_atom::updateBonds, AtomIndexGetter));
|
---|
| 400 |
|
---|
| 401 | _ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector>(
|
---|
| 402 | _atomref,
|
---|
| 403 | AtomPositionUpdater,
|
---|
[7c7c4a] | 404 | "AtomPosition_"+toString(_id),
|
---|
[16bd37] | 405 | AtomPositionUpdater(),
|
---|
[7c7c4a] | 406 | AtomPositionChannels,
|
---|
[16bd37] | 407 | _subjectKilled);
|
---|
| 408 | _ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t>(
|
---|
| 409 | _atomref,
|
---|
| 410 | AtomElementUpdater,
|
---|
[7c7c4a] | 411 | "AtomElement"+toString(_id),
|
---|
[16bd37] | 412 | AtomElementUpdater(),
|
---|
[7c7c4a] | 413 | AtomElementChannels,
|
---|
[16bd37] | 414 | _subjectKilled);
|
---|
| 415 | _ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t>(
|
---|
| 416 | _atomref,
|
---|
| 417 | AtomBondsUpdater,
|
---|
[7c7c4a] | 418 | "AtomBonds_"+toString(_id),
|
---|
[16bd37] | 419 | AtomBondsUpdater(),
|
---|
[7c7c4a] | 420 | AtomBondsChannels,
|
---|
[16bd37] | 421 | _subjectKilled);
|
---|
[7c7c4a] | 422 | }
|
---|
| 423 |
|
---|
[16bd37] | 424 | void GLMoleculeObject_atom::destroyObservedValues(
|
---|
| 425 | std::vector<boost::any> &_ObservedValues)
|
---|
[7c7c4a] | 426 | {
|
---|
[16bd37] | 427 | delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[AtomIndex]);
|
---|
| 428 | delete boost::any_cast<ObservedValue_wCallback<Vector> *>(_ObservedValues[AtomPosition]);
|
---|
| 429 | delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(_ObservedValues[AtomElement]);
|
---|
| 430 | delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(_ObservedValues[AtomBonds]);
|
---|
| 431 | _ObservedValues.clear();
|
---|
[7c7c4a] | 432 | }
|
---|
| 433 |
|
---|
| 434 | atomId_t GLMoleculeObject_atom::getAtomIndex() const
|
---|
| 435 | {
|
---|
| 436 | return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex])->get();
|
---|
| 437 | }
|
---|
| 438 |
|
---|
| 439 | Vector GLMoleculeObject_atom::getAtomPosition() const
|
---|
| 440 | {
|
---|
| 441 | return boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[AtomPosition])->get();
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | atomicNumber_t GLMoleculeObject_atom::getAtomElement() const
|
---|
| 445 | {
|
---|
| 446 | return boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[AtomElement])->get();
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::getAtomBonds() const
|
---|
| 450 | {
|
---|
| 451 | return boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(ObservedValues[AtomBonds])->get();
|
---|
| 452 | }
|
---|