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