[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_bond.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_bond.hpp"
|
---|
| 37 |
|
---|
| 38 | #include <Qt3D/qglmaterial.h>
|
---|
| 39 | #include <Qt3D/qglscenenode.h>
|
---|
| 40 |
|
---|
| 41 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 42 |
|
---|
[856d05] | 43 |
|
---|
[907636] | 44 | #include <cmath>
|
---|
| 45 |
|
---|
| 46 | #include "CodePatterns/Assert.hpp"
|
---|
[57a770] | 47 | #include "CodePatterns/Log.hpp"
|
---|
[2ad1ec] | 48 | #include "CodePatterns/Observer/Notification.hpp"
|
---|
[856d05] | 49 | #include "CodePatterns/Observer/ObserverLog.hpp"
|
---|
[c60665] | 50 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
[6f0841] | 51 | #include "Atom/atom.hpp"
|
---|
[907636] | 52 | #include "Bond/bond.hpp"
|
---|
[3bdb6d] | 53 | #include "Element/element.hpp"
|
---|
[907636] | 54 | #include "Helpers/defs.hpp"
|
---|
| 55 | #include "LinearAlgebra/Line.hpp"
|
---|
| 56 | #include "LinearAlgebra/Vector.hpp"
|
---|
[2f7988] | 57 | #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
|
---|
[c60665] | 58 | #include "World.hpp"
|
---|
[907636] | 59 |
|
---|
[7c7c4a] | 60 | #include "ObservedValue_wCallback.hpp"
|
---|
| 61 |
|
---|
[009e2e2] | 62 |
|
---|
| 63 | // static entities
|
---|
| 64 | const Observable::channels_t
|
---|
[099f67] | 65 | GLMoleculeObject_bond::IndexChannels(1, AtomObservable::IndexChanged);
|
---|
| 66 | const Observable::channels_t
|
---|
[009e2e2] | 67 | GLMoleculeObject_bond::BondPositionChannels(1, AtomObservable::PositionChanged);
|
---|
| 68 | const Observable::channels_t
|
---|
| 69 | GLMoleculeObject_bond::BondDegreeChannels(1, BondObservable::DegreeChanged);
|
---|
| 70 | const Observable::channels_t
|
---|
| 71 | GLMoleculeObject_bond::BondElementChannels(1, AtomObservable::ElementChanged);
|
---|
| 72 |
|
---|
[8d5fbf1] | 73 | static GLMoleculeObject_bond::bondIds_t getBondIdsForIds(
|
---|
| 74 | const boost::function<const atomId_t()> &_left,
|
---|
| 75 | const boost::function<const atomId_t()> &_right)
|
---|
| 76 | {
|
---|
| 77 | return std::make_pair(_left(), _right());
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[009e2e2] | 80 | GLMoleculeObject_bond::GLMoleculeObject_bond(
|
---|
| 81 | QGLSceneNode *mesh[],
|
---|
| 82 | QObject *parent,
|
---|
| 83 | const bondIds_t bondIds,
|
---|
| 84 | const enum SideOfBond side) :
|
---|
[bca99d] | 85 | GLMoleculeObject(mesh, parent),
|
---|
[2ad1ec] | 86 | Observer(std::string("GLMoleculeObject_bond")
|
---|
[009e2e2] | 87 | +toString(bondIds.first)
|
---|
[2ad1ec] | 88 | +std::string("-")
|
---|
[009e2e2] | 89 | +toString(bondIds.second)),
|
---|
[099f67] | 90 | leftowner(getAtomConst(bondIds.first)),
|
---|
| 91 | rightowner(getAtomConst(bondIds.second)),
|
---|
| 92 | bondowner(getAtomConst(bondIds.first)->getBond(getAtomConst(bondIds.second)).get()),
|
---|
[c60665] | 93 | BondSide(side),
|
---|
[7c7c4a] | 94 | ObservedValues(MAX_ObservedTypes),
|
---|
| 95 | subjectKilledCount(0),
|
---|
[c60665] | 96 | leftobservable_enabled(false),
|
---|
[8d5fbf1] | 97 | rightobservable_enabled(false),
|
---|
| 98 | board_subjectKilled(
|
---|
| 99 | boost::bind(
|
---|
| 100 | static_cast<void (GLMoleculeObject_bond::*) ()>(
|
---|
| 101 | &GLMoleculeObject_bond::countsubjectKilled),
|
---|
| 102 | this))
|
---|
[907636] | 103 | {
|
---|
[026bef] | 104 | boost::function<void(const atomId_t &)> leftsubjectKilled =
|
---|
| 105 | boost::bind(
|
---|
| 106 | static_cast<void (GLMoleculeObject_bond::*) (const atomId_t &)>(
|
---|
| 107 | &GLMoleculeObject_bond::countsubjectKilled),
|
---|
| 108 | this, _1);
|
---|
| 109 | boost::function<void(const atomId_t &)> rightsubjectKilled =
|
---|
| 110 | boost::bind(
|
---|
| 111 | static_cast<void (GLMoleculeObject_bond::*) (const atomId_t &)>(
|
---|
| 112 | &GLMoleculeObject_bond::countsubjectKilled)
|
---|
| 113 | , this, _1);
|
---|
| 114 | boost::function<void(const bondIds_t &)> bondsubjectKilled =
|
---|
| 115 | boost::bind(
|
---|
| 116 | static_cast<void (GLMoleculeObject_bond::*) (const bondIds_t &)>(
|
---|
| 117 | &GLMoleculeObject_bond::countsubjectKilled)
|
---|
| 118 | , this, _1);
|
---|
| 119 | initObservedValues(
|
---|
| 120 | ObservedValues,
|
---|
| 121 | bondIds.first,
|
---|
| 122 | bondIds.second,
|
---|
| 123 | leftowner,
|
---|
| 124 | rightowner,
|
---|
| 125 | bondowner,
|
---|
| 126 | leftsubjectKilled,
|
---|
| 127 | rightsubjectKilled,
|
---|
| 128 | bondsubjectKilled);
|
---|
| 129 |
|
---|
| 130 | init();
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | GLMoleculeObject_bond::GLMoleculeObject_bond(
|
---|
| 134 | QGLSceneNode *mesh[],
|
---|
| 135 | QObject *parent,
|
---|
| 136 | const bondIds_t bondIds,
|
---|
| 137 | const enum SideOfBond side,
|
---|
[8d5fbf1] | 138 | std::vector<boost::any> &_ObservedValues,
|
---|
| 139 | const boost::function<void (const bondIds_t)> &_subjectKilled) :
|
---|
[026bef] | 140 | GLMoleculeObject(mesh, parent),
|
---|
| 141 | Observer(std::string("GLMoleculeObject_bond")
|
---|
| 142 | +toString(bondIds.first)
|
---|
| 143 | +std::string("-")
|
---|
| 144 | +toString(bondIds.second)),
|
---|
| 145 | leftowner(getAtomConst(bondIds.first)),
|
---|
| 146 | rightowner(getAtomConst(bondIds.second)),
|
---|
| 147 | bondowner(getAtomConst(bondIds.first)->getBond(getAtomConst(bondIds.second)).get()),
|
---|
| 148 | BondSide(side),
|
---|
| 149 | ObservedValues(_ObservedValues),
|
---|
| 150 | subjectKilledCount(0),
|
---|
| 151 | leftobservable_enabled(false),
|
---|
[8d5fbf1] | 152 | rightobservable_enabled(false),
|
---|
| 153 | board_subjectKilled(_subjectKilled)
|
---|
[026bef] | 154 | {
|
---|
| 155 | init();
|
---|
| 156 | }
|
---|
[7c7c4a] | 157 |
|
---|
[026bef] | 158 | void GLMoleculeObject_bond::init()
|
---|
| 159 | {
|
---|
[2ad1ec] | 160 | // sign on as observer (obtain non-const instance before)
|
---|
[7e2adc] | 161 | bondowner->signOn(this, BondObservable::BondRemoved);
|
---|
| 162 | bondowner->signOn(this, BondObservable::DegreeChanged);
|
---|
[c60665] | 163 | bond_enabled = true;
|
---|
[7e2adc] | 164 | leftowner->signOn(this, AtomObservable::PositionChanged);
|
---|
| 165 | leftowner->signOn(this, AtomObservable::ElementChanged);
|
---|
[c60665] | 166 | leftobservable_enabled = true;
|
---|
[7e2adc] | 167 | rightowner->signOn(this, AtomObservable::PositionChanged);
|
---|
| 168 | rightowner->signOn(this, AtomObservable::ElementChanged);
|
---|
[c60665] | 169 | rightobservable_enabled = true;
|
---|
[2ad1ec] | 170 |
|
---|
[009e2e2] | 171 | resetElement();
|
---|
[343a4b] | 172 | resetPosition();
|
---|
[4b62d3] | 173 | resetWidth();
|
---|
[009e2e2] | 174 |
|
---|
| 175 | connect(this, SIGNAL(elementChanged()), this, SLOT(resetElement()), Qt::QueuedConnection);
|
---|
| 176 | connect(this, SIGNAL(positionChanged()), this, SLOT(resetPosition()), Qt::QueuedConnection);
|
---|
| 177 | connect(this, SIGNAL(degreeChanged()), this, SLOT(resetWidth()), Qt::QueuedConnection);
|
---|
[907636] | 178 | }
|
---|
[2ad1ec] | 179 |
|
---|
| 180 | GLMoleculeObject_bond::~GLMoleculeObject_bond()
|
---|
[c60665] | 181 | {
|
---|
[009e2e2] | 182 | LOG(3, "DEBUG: Destroying GLMoleculeObject_bond to bond [" <<
|
---|
[099f67] | 183 | getleftIndex() << "," << getrightIndex() << "] and side " << BondSide << ".");
|
---|
[c60665] | 184 | // signOff() if not already done
|
---|
| 185 | removeChannels();
|
---|
[099f67] | 186 | destroyObservedValues(ObservedValues);
|
---|
[c60665] | 187 | }
|
---|
| 188 |
|
---|
[7e2adc] | 189 | void GLMoleculeObject_bond::removeChannels()
|
---|
[c60665] | 190 | {
|
---|
| 191 | // at this point both atoms should still be alive, hence we may safely sign off
|
---|
| 192 | // from the AtomObservable itself
|
---|
[7e2adc] | 193 | if (bond_enabled) {
|
---|
| 194 | if (bondowner != NULL) {
|
---|
| 195 | bondowner->signOff(this, BondObservable::BondRemoved);
|
---|
| 196 | bondowner->signOff(this, BondObservable::DegreeChanged);
|
---|
[c60665] | 197 | }
|
---|
[7e2adc] | 198 | bond_enabled = false;
|
---|
[c60665] | 199 | }
|
---|
| 200 | if (leftobservable_enabled) {
|
---|
[7e2adc] | 201 | if (leftowner != NULL) {
|
---|
| 202 | leftowner->signOff(this, AtomObservable::PositionChanged);
|
---|
| 203 | leftowner->signOff(this, AtomObservable::ElementChanged);
|
---|
[c60665] | 204 | }
|
---|
| 205 | leftobservable_enabled = false;
|
---|
| 206 | }
|
---|
| 207 | if (rightobservable_enabled) {
|
---|
[7e2adc] | 208 | if (rightowner != NULL) {
|
---|
| 209 | rightowner->signOff(this, AtomObservable::PositionChanged);
|
---|
| 210 | rightowner->signOff(this, AtomObservable::ElementChanged);
|
---|
[c60665] | 211 | }
|
---|
| 212 | rightobservable_enabled = false;
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 |
|
---|
[2ad1ec] | 216 | void GLMoleculeObject_bond::update(Observable *publisher)
|
---|
| 217 | {
|
---|
[009e2e2] | 218 | ASSERT(0, "GLMoleculeObject_bond::update() - we are not signed on for any global updates.");
|
---|
[2ad1ec] | 219 | }
|
---|
| 220 |
|
---|
| 221 | void GLMoleculeObject_bond::subjectKilled(Observable *publisher)
|
---|
| 222 | {
|
---|
[7e2adc] | 223 | // we signOff from all other sources
|
---|
[c60665] | 224 | removeChannels();
|
---|
[7c7c4a] | 225 | // check whether we should be removed
|
---|
[8d5fbf1] | 226 | board_subjectKilled(std::make_pair(getleftIndex(), getrightIndex()));
|
---|
[2ad1ec] | 227 | }
|
---|
| 228 |
|
---|
| 229 | void GLMoleculeObject_bond::recieveNotification(Observable *publisher, Notification_ptr notification)
|
---|
| 230 | {
|
---|
| 231 | #ifdef LOG_OBSERVER
|
---|
[7e2adc] | 232 | if (publisher == static_cast<const Observable *>(bondowner)) {
|
---|
[70db8f] | 233 | observerLog().addMessage() << "++ Update of Observer "
|
---|
| 234 | << observerLog().getName(static_cast<Observer*>(this))
|
---|
| 235 | << " received notification from bond for channel "
|
---|
| 236 | << notification->getChannelNo() << ".";
|
---|
[7e2adc] | 237 | } else if (publisher == static_cast<const Observable * const>(leftowner)) {
|
---|
[70db8f] | 238 | observerLog().addMessage() << "++ Update of Observer "
|
---|
| 239 | << observerLog().getName(static_cast<Observer*>(this))
|
---|
[099f67] | 240 | << " received notification from leftatom " << getleftIndex() << " for channel "
|
---|
[70db8f] | 241 | << notification->getChannelNo() << ".";
|
---|
[7e2adc] | 242 | } else if (publisher == static_cast<const Observable * const>(rightowner)) {
|
---|
[70db8f] | 243 | observerLog().addMessage() << "++ Update of Observer "
|
---|
| 244 | << observerLog().getName(static_cast<Observer*>(this))
|
---|
[099f67] | 245 | << " received notification from rightatom " << getrightIndex() << " for channel "
|
---|
[70db8f] | 246 | << notification->getChannelNo() << ".";
|
---|
[7e2adc] | 247 | }
|
---|
[2ad1ec] | 248 | #endif
|
---|
[7e2adc] | 249 | if (publisher == static_cast<const Observable *>(bondowner)){
|
---|
[1f693d] | 250 | switch (notification->getChannelNo()) {
|
---|
| 251 | case BondObservable::BondRemoved:
|
---|
[c60665] | 252 | // removeMe();
|
---|
[1f693d] | 253 | break;
|
---|
[4b62d3] | 254 | case BondObservable::DegreeChanged:
|
---|
[009e2e2] | 255 | emit degreeChanged();
|
---|
[4b62d3] | 256 | break;
|
---|
| 257 | default:
|
---|
| 258 | ASSERT(0, "GLMoleculeObject_bond::recieveNotification() - unknown signal.");
|
---|
| 259 | break;
|
---|
[1f693d] | 260 | }
|
---|
[70db8f] | 261 | } else {
|
---|
[343a4b] | 262 | // from an atom
|
---|
| 263 | switch (notification->getChannelNo()) {
|
---|
[70db8f] | 264 | case AtomObservable::PositionChanged:
|
---|
| 265 | LOG(2, "INFO: Received notification of PositionChanged.");
|
---|
[009e2e2] | 266 | emit positionChanged();
|
---|
[70db8f] | 267 | break;
|
---|
| 268 | case AtomObservable::ElementChanged:
|
---|
| 269 | LOG(2, "INFO: Received notification of ElementChanged.");
|
---|
[009e2e2] | 270 | emit elementChanged();
|
---|
[70db8f] | 271 | break;
|
---|
| 272 | default:
|
---|
| 273 | break;
|
---|
| 274 | }
|
---|
[343a4b] | 275 | }
|
---|
[4b62d3] | 276 | }
|
---|
| 277 |
|
---|
[099f67] | 278 | atomId_t GLMoleculeObject_bond::updateIndex()
|
---|
[4b62d3] | 279 | {
|
---|
[099f67] | 280 | return const_cast<const World &>(World::getInstance()).lastChangedAtomId();
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | Vector GLMoleculeObject_bond::updateLeftPosition(
|
---|
| 284 | const boost::function<const atomId_t ()> &_getLeftAtomIndex)
|
---|
| 285 | {
|
---|
| 286 | const atom * const _atom = getAtomConst(_getLeftAtomIndex());
|
---|
[009e2e2] | 287 | return _atom->getPosition();
|
---|
[343a4b] | 288 | }
|
---|
| 289 |
|
---|
[099f67] | 290 | Vector GLMoleculeObject_bond::updateRightPosition(
|
---|
| 291 | const boost::function<const atomId_t ()> &_getRightAtomIndex)
|
---|
[009e2e2] | 292 | {
|
---|
[099f67] | 293 | const atom * const _atom = getAtomConst(_getRightAtomIndex());
|
---|
[009e2e2] | 294 | return _atom->getPosition();
|
---|
| 295 | }
|
---|
| 296 |
|
---|
[099f67] | 297 | atomicNumber_t GLMoleculeObject_bond::updateLeftElement(
|
---|
| 298 | const boost::function<const atomId_t ()> &_getLeftAtomIndex)
|
---|
[009e2e2] | 299 | {
|
---|
[099f67] | 300 | const atom * const _atom = getAtomConst(_getLeftAtomIndex());
|
---|
[009e2e2] | 301 | return _atom->getElementNo();
|
---|
| 302 | }
|
---|
| 303 |
|
---|
[099f67] | 304 | atomicNumber_t GLMoleculeObject_bond::updateRightElement(
|
---|
| 305 | const boost::function<const atomId_t ()> &_getRightAtomIndex)
|
---|
[009e2e2] | 306 | {
|
---|
[099f67] | 307 | const atom * const _atom = getAtomConst(_getRightAtomIndex());
|
---|
[009e2e2] | 308 | return _atom->getElementNo();
|
---|
| 309 | }
|
---|
| 310 |
|
---|
[099f67] | 311 | int GLMoleculeObject_bond::updateDegree(
|
---|
| 312 | const boost::function<const atomId_t ()> &_getLeftAtomIndex,
|
---|
| 313 | const boost::function<const atomId_t ()> &_getRightAtomIndex)
|
---|
[343a4b] | 314 | {
|
---|
[f01769] | 315 | const atom * const _leftatom = const_cast<const World &>(World::getInstance()).
|
---|
[099f67] | 316 | getAtom(AtomById(_getLeftAtomIndex()));
|
---|
[f01769] | 317 | const atom * const _rightatom = const_cast<const World &>(World::getInstance()).
|
---|
[099f67] | 318 | getAtom(AtomById(_getRightAtomIndex()));
|
---|
[009e2e2] | 319 | if ((_leftatom != NULL) && (_rightatom != NULL)) {
|
---|
| 320 | bond::ptr _bond = _leftatom->getBond(_rightatom);
|
---|
| 321 | return _bond->getDegree();
|
---|
| 322 | } else {
|
---|
| 323 | return 1;
|
---|
[2ad1ec] | 324 | }
|
---|
[009e2e2] | 325 | }
|
---|
| 326 |
|
---|
| 327 | void GLMoleculeObject_bond::resetElement()
|
---|
| 328 | {
|
---|
[7c7c4a] | 329 | size_t elementno = getrightElement();
|
---|
[009e2e2] | 330 | QGLMaterial *elementmaterial = getMaterial(elementno);
|
---|
| 331 | setMaterial(elementmaterial);
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 | void GLMoleculeObject_bond::resetWidth()
|
---|
| 335 | {
|
---|
[7c7c4a] | 336 | const double factor = 1.0f+.5f*(getDegree()-1);
|
---|
[009e2e2] | 337 | LOG(2, "DEBUG: GLMoleculeObject_bond::resetWidth() - setting bond's width to " << factor << ".");
|
---|
| 338 | setScaleX(factor);
|
---|
| 339 | setScaleY(factor);
|
---|
| 340 |
|
---|
| 341 | emit changed();
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | void GLMoleculeObject_bond::resetPosition()
|
---|
| 345 | {
|
---|
[7c7c4a] | 346 | Vector Position = getleftPosition();
|
---|
| 347 | Vector OtherPosition = getrightPosition();
|
---|
[fbb1f1] | 348 | const double distance =
|
---|
| 349 | Position.distance(OtherPosition)/2.;
|
---|
| 350 | setScaleZ(distance);
|
---|
[343a4b] | 351 |
|
---|
| 352 | // calculate position
|
---|
[37e910] | 353 | Vector Z(unitVec[2]); // cylinder are initially aligned along the Z axis
|
---|
[343a4b] | 354 | Vector zeroVec(0.,0.,0.);
|
---|
| 355 | Vector a,b;
|
---|
| 356 | Vector OtherAxis;
|
---|
| 357 | double alpha;
|
---|
| 358 | a = Position - OtherPosition;
|
---|
| 359 | // construct rotation axis
|
---|
| 360 | b = a;
|
---|
| 361 | b.VectorProduct(Z);
|
---|
| 362 | Line axis(zeroVec, b);
|
---|
| 363 | // calculate rotation angle
|
---|
| 364 | alpha = a.Angle(Z);
|
---|
| 365 | // construct other axis to check right-hand rule
|
---|
| 366 | OtherAxis = b;
|
---|
| 367 | OtherAxis.VectorProduct(Z);
|
---|
| 368 | // assure right-hand rule for the rotation
|
---|
| 369 | if (a.ScalarProduct(OtherAxis) < MYEPSILON)
|
---|
| 370 | alpha = M_PI-alpha;
|
---|
| 371 | // check
|
---|
| 372 | Vector a_rotated = axis.rotateVector(a, alpha);
|
---|
| 373 | LOG(3, "INFO: Created cylinder from "// << Position << " to " << OtherPosition
|
---|
| 374 | << a << " to " << a_rotated << " around " << b << " by " << alpha/M_PI*180. << ", respectively.");
|
---|
| 375 |
|
---|
[37e910] | 376 | // set position (cylinder offset is in its barymetric center)
|
---|
| 377 | Vector OneFourth(Position - 0.75 * a);
|
---|
| 378 | setPosition(QVector3D(OneFourth[0], OneFourth[1], OneFourth[2]));
|
---|
[343a4b] | 379 | setRotationVector(QVector3D(b[0], b[1], b[2]));
|
---|
| 380 | setRotationAngle(alpha/M_PI*180.);
|
---|
[009e2e2] | 381 |
|
---|
| 382 | emit changed();
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | atom * const GLMoleculeObject_bond::getAtom(const atomId_t _id)
|
---|
| 386 | {
|
---|
| 387 | atom * const _atom = World::getInstance().getAtom(AtomById(_id));
|
---|
| 388 | return _atom;
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 | const atom * const GLMoleculeObject_bond::getAtomConst(const atomId_t _id)
|
---|
| 392 | {
|
---|
| 393 | const atom * const _atom = const_cast<const World &>(World::getInstance()).
|
---|
| 394 | getAtom(AtomById(_id));
|
---|
| 395 | return _atom;
|
---|
[2ad1ec] | 396 | }
|
---|
[7c7c4a] | 397 |
|
---|
| 398 | void GLMoleculeObject_bond::countsubjectKilled()
|
---|
| 399 | {
|
---|
| 400 | ++subjectKilledCount;
|
---|
| 401 |
|
---|
| 402 | if (subjectKilledCount > ObservedValues.size())
|
---|
[099f67] | 403 | emit BondRemoved(getleftIndex(), getrightIndex());
|
---|
[7c7c4a] | 404 | }
|
---|
| 405 |
|
---|
[099f67] | 406 | void GLMoleculeObject_bond::initObservedValues(
|
---|
| 407 | std::vector<boost::any> &_ObservedValues,
|
---|
| 408 | const atomId_t _leftatomId,
|
---|
| 409 | const atomId_t _rightatomId,
|
---|
| 410 | const Observable * const _leftowner,
|
---|
| 411 | const Observable * const _rightowner,
|
---|
| 412 | const Observable * const _bondowner,
|
---|
[026bef] | 413 | const boost::function<void(const atomId_t &)> &_leftsubjectKilled,
|
---|
| 414 | const boost::function<void(const atomId_t &)> &_rightsubjectKilled,
|
---|
| 415 | const boost::function<void(const bondIds_t &)> &_bondsubjectKilled)
|
---|
[7c7c4a] | 416 | {
|
---|
[099f67] | 417 | /* This is an old note from when the code was still part of cstor's initializer body.
|
---|
| 418 | * TODO: Probably does not apply anymore but has not yet been tested.
|
---|
| 419 | *
|
---|
| 420 | * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
|
---|
| 421 | * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
|
---|
| 422 | * the class has not been fully constructed yet. "This" itself seems to be working fine.
|
---|
| 423 | */
|
---|
| 424 |
|
---|
| 425 | ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
|
---|
| 426 | "GLMoleculeObject_bond::initObservedValues() - given ObservedValues has not correct size.");
|
---|
| 427 |
|
---|
| 428 | // fill ObservedValues: index first
|
---|
| 429 | // Note that we only need one as the function just checks on the last changed id
|
---|
| 430 | // and ids cannot be changed simultaneously
|
---|
| 431 | const boost::function<atomId_t ()> AtomIndexUpdater(
|
---|
| 432 | boost::bind(&GLMoleculeObject_bond::updateIndex));
|
---|
| 433 |
|
---|
| 434 | ObservedValue_wCallback<atomId_t> * const LeftIndexObservable =
|
---|
| 435 | new ObservedValue_wCallback<atomId_t>(
|
---|
| 436 | _leftowner,
|
---|
| 437 | AtomIndexUpdater,
|
---|
| 438 | "Bonds_LeftAtomIndex_"+toString(_leftatomId),
|
---|
| 439 | _leftatomId,
|
---|
| 440 | IndexChannels,
|
---|
[026bef] | 441 | _leftsubjectKilled);
|
---|
[099f67] | 442 | _ObservedValues[leftIndex] = LeftIndexObservable;
|
---|
| 443 | ObservedValue_wCallback<atomId_t> * const RightIndexObservable =
|
---|
| 444 | new ObservedValue_wCallback<atomId_t>(
|
---|
| 445 | _rightowner,
|
---|
| 446 | AtomIndexUpdater,
|
---|
| 447 | "Bonds_RightAtomIndex_"+toString(_rightatomId),
|
---|
| 448 | _rightatomId,
|
---|
| 449 | IndexChannels,
|
---|
[026bef] | 450 | _rightsubjectKilled);
|
---|
[099f67] | 451 | _ObservedValues[rightIndex] = RightIndexObservable;
|
---|
| 452 |
|
---|
| 453 | const boost::function<const atomId_t ()> LeftIndexGetter =
|
---|
| 454 | boost::bind(&ObservedValue_wCallback<atomId_t>::get,
|
---|
| 455 | LeftIndexObservable);
|
---|
| 456 | const boost::function<const atomId_t ()> RightIndexGetter =
|
---|
| 457 | boost::bind(&ObservedValue_wCallback<atomId_t>::get,
|
---|
| 458 | RightIndexObservable);
|
---|
| 459 |
|
---|
| 460 | // fill ObservedValues: then all the other that need index
|
---|
| 461 | const boost::function<Vector ()> LeftPositionUpdater(
|
---|
| 462 | boost::bind(&GLMoleculeObject_bond::updateLeftPosition, LeftIndexGetter));
|
---|
| 463 | const boost::function<Vector ()> RightPositionUpdater(
|
---|
| 464 | boost::bind(&GLMoleculeObject_bond::updateRightPosition, RightIndexGetter));
|
---|
| 465 | const boost::function<atomicNumber_t ()> LeftElementUpdater(
|
---|
| 466 | boost::bind(&GLMoleculeObject_bond::updateLeftElement, LeftIndexGetter));
|
---|
| 467 | const boost::function<atomicNumber_t ()> RightElementUpdater(
|
---|
| 468 | boost::bind(&GLMoleculeObject_bond::updateRightElement, RightIndexGetter));
|
---|
| 469 | const boost::function<int ()> DegreeUpdater(
|
---|
| 470 | boost::bind(&GLMoleculeObject_bond::updateDegree, LeftIndexGetter, RightIndexGetter));
|
---|
[026bef] | 471 | const boost::function<bondIds_t ()> BondIdGetter(
|
---|
| 472 | boost::bind(&getBondIdsForIds, LeftIndexGetter, RightIndexGetter));
|
---|
[099f67] | 473 |
|
---|
[026bef] | 474 | _ObservedValues[leftPosition] = new ObservedValue_wCallback<Vector, atomId_t>(
|
---|
[099f67] | 475 | _leftowner,
|
---|
| 476 | LeftPositionUpdater,
|
---|
| 477 | "BondleftPosition_"+toString(_leftatomId),
|
---|
| 478 | LeftPositionUpdater(),
|
---|
[7c7c4a] | 479 | BondPositionChannels,
|
---|
[026bef] | 480 | _leftsubjectKilled,
|
---|
| 481 | LeftIndexGetter);
|
---|
| 482 | _ObservedValues[rightPosition] = new ObservedValue_wCallback<Vector, atomId_t>(
|
---|
[099f67] | 483 | _rightowner,
|
---|
| 484 | RightPositionUpdater,
|
---|
| 485 | "BondrightPosition_"+toString(_rightatomId),
|
---|
| 486 | RightPositionUpdater(),
|
---|
[7c7c4a] | 487 | BondPositionChannels,
|
---|
[026bef] | 488 | _rightsubjectKilled,
|
---|
| 489 | RightIndexGetter);
|
---|
| 490 | _ObservedValues[leftElement] = new ObservedValue_wCallback<atomicNumber_t, atomId_t>(
|
---|
[099f67] | 491 | _leftowner,
|
---|
| 492 | LeftElementUpdater,
|
---|
| 493 | "BondleftElement"+toString(_leftatomId),
|
---|
| 494 | LeftElementUpdater(),
|
---|
[7c7c4a] | 495 | BondElementChannels,
|
---|
[026bef] | 496 | _leftsubjectKilled,
|
---|
| 497 | LeftIndexGetter);
|
---|
| 498 | _ObservedValues[rightElement] = new ObservedValue_wCallback<atomicNumber_t, atomId_t>(
|
---|
[099f67] | 499 | _rightowner,
|
---|
| 500 | RightElementUpdater,
|
---|
| 501 | "BondrightElement"+toString(_rightatomId),
|
---|
| 502 | RightElementUpdater(),
|
---|
[7c7c4a] | 503 | BondElementChannels,
|
---|
[026bef] | 504 | _rightsubjectKilled,
|
---|
| 505 | RightIndexGetter);
|
---|
| 506 | _ObservedValues[Degree] = new ObservedValue_wCallback<int, bondIds_t>(
|
---|
[099f67] | 507 | _bondowner,
|
---|
| 508 | DegreeUpdater,
|
---|
| 509 | "BondDegree"+toString(_leftatomId)+"_"+toString(_rightatomId),
|
---|
| 510 | DegreeUpdater(),
|
---|
[7c7c4a] | 511 | BondDegreeChannels,
|
---|
[026bef] | 512 | _bondsubjectKilled,
|
---|
| 513 | BondIdGetter);
|
---|
[099f67] | 514 | }
|
---|
| 515 |
|
---|
| 516 | void GLMoleculeObject_bond::destroyObservedValues(
|
---|
| 517 | std::vector<boost::any> &_ObservedValues)
|
---|
| 518 | {
|
---|
| 519 | delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[leftIndex]);
|
---|
| 520 | delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[rightIndex]);
|
---|
[026bef] | 521 | delete boost::any_cast<ObservedValue_wCallback<Vector,atomId_t> *>(_ObservedValues[leftPosition]);
|
---|
| 522 | delete boost::any_cast<ObservedValue_wCallback<Vector,atomId_t> *>(_ObservedValues[rightPosition]);
|
---|
| 523 | delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t,atomId_t> *>(_ObservedValues[leftElement]);
|
---|
| 524 | delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t,atomId_t> *>(_ObservedValues[rightElement]);
|
---|
| 525 | delete boost::any_cast<ObservedValue_wCallback<int, bondIds_t> *>(_ObservedValues[Degree]);
|
---|
[099f67] | 526 | _ObservedValues.clear();
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | atomId_t GLMoleculeObject_bond::getleftIndex() const
|
---|
| 530 | {
|
---|
| 531 | return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[leftIndex])->get();
|
---|
[7c7c4a] | 532 | }
|
---|
| 533 |
|
---|
[099f67] | 534 | atomId_t GLMoleculeObject_bond::getrightIndex() const
|
---|
[7c7c4a] | 535 | {
|
---|
[099f67] | 536 | return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[rightIndex])->get();
|
---|
[7c7c4a] | 537 | }
|
---|
| 538 |
|
---|
| 539 | Vector GLMoleculeObject_bond::getleftPosition() const
|
---|
| 540 | {
|
---|
[026bef] | 541 | return boost::any_cast<ObservedValue_wCallback<Vector,atomId_t> *>(ObservedValues[leftPosition])->get();
|
---|
[7c7c4a] | 542 | }
|
---|
| 543 |
|
---|
| 544 | Vector GLMoleculeObject_bond::getrightPosition() const
|
---|
| 545 | {
|
---|
[026bef] | 546 | return boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(ObservedValues[rightPosition])->get();
|
---|
[7c7c4a] | 547 | }
|
---|
| 548 |
|
---|
| 549 | atomicNumber_t GLMoleculeObject_bond::getleftElement() const
|
---|
| 550 | {
|
---|
[026bef] | 551 | return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(ObservedValues[leftElement])->get();
|
---|
[7c7c4a] | 552 | }
|
---|
| 553 |
|
---|
| 554 | atomicNumber_t GLMoleculeObject_bond::getrightElement() const
|
---|
| 555 | {
|
---|
[026bef] | 556 | return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(ObservedValues[rightElement])->get();
|
---|
[7c7c4a] | 557 | }
|
---|
| 558 |
|
---|
| 559 | int GLMoleculeObject_bond::getDegree() const
|
---|
| 560 | {
|
---|
[026bef] | 561 | return boost::any_cast<ObservedValue_wCallback<int, bondIds_t> *>(ObservedValues[Degree])->get();
|
---|
[7c7c4a] | 562 | }
|
---|