[0070aa] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2015 Frederik Heber. All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * QtObservedAtom.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Oct 28, 2015
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | // include config.h
|
---|
| 32 | #ifdef HAVE_CONFIG_H
|
---|
| 33 | #include <config.h>
|
---|
| 34 | #endif
|
---|
| 35 |
|
---|
| 36 | #include "QtObservedAtom.hpp"
|
---|
| 37 |
|
---|
[65c323] | 38 | #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
|
---|
| 39 |
|
---|
[0070aa] | 40 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 41 |
|
---|
[65c323] | 42 | #include <boost/assign.hpp>
|
---|
| 43 |
|
---|
| 44 | #include "Atom/atom.hpp"
|
---|
| 45 | #include "Bond/bond.hpp"
|
---|
| 46 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
| 47 | #include "Element/element.hpp"
|
---|
| 48 | #include "World.hpp"
|
---|
| 49 |
|
---|
[494478] | 50 | #include "UIElements/Qt4/InstanceBoard/ObservedValue_wCallback.hpp"
|
---|
[65c323] | 51 |
|
---|
| 52 | using namespace boost::assign;
|
---|
| 53 |
|
---|
| 54 | static const Observable::channels_t getAtomBondsChannels()
|
---|
| 55 | {
|
---|
| 56 | Observable::channels_t channels;
|
---|
| 57 | channels += AtomObservable::BondsAdded, AtomObservable::BondsRemoved;
|
---|
| 58 | return channels;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | static const Observable::channels_t getAllObservedChannels()
|
---|
| 62 | {
|
---|
| 63 | Observable::channels_t channels;
|
---|
| 64 | channels +=
|
---|
| 65 | AtomObservable::IndexChanged,
|
---|
| 66 | AtomObservable::BondsAdded,
|
---|
[fe493f] | 67 | AtomObservable::BondsRemoved,
|
---|
| 68 | AtomObservable::MoleculeChanged,
|
---|
| 69 | AtomObservable::NameChanged,
|
---|
| 70 | AtomObservable::ElementChanged,
|
---|
[9e9100] | 71 | AtomObservable::PositionChanged,
|
---|
| 72 | AtomObservable::SelectionChanged;
|
---|
[65c323] | 73 | return channels;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | // static entities
|
---|
| 77 | const Observable::channels_t
|
---|
| 78 | QtObservedAtom::AtomIndexChannels(1, AtomObservable::IndexChanged);
|
---|
| 79 | const Observable::channels_t
|
---|
[fe493f] | 80 | QtObservedAtom::AtomBondsChannels(getAtomBondsChannels());
|
---|
[65c323] | 81 | const Observable::channels_t
|
---|
| 82 | QtObservedAtom::AtomElementChannels(1, AtomObservable::ElementChanged);
|
---|
| 83 | const Observable::channels_t
|
---|
[1187c5] | 84 | QtObservedAtom::AtomMoleculeChannels(1, AtomObservable::MoleculeChanged);
|
---|
[fe493f] | 85 | const Observable::channels_t
|
---|
| 86 | QtObservedAtom::AtomNameChannels(1, AtomObservable::NameChanged);
|
---|
| 87 | const Observable::channels_t
|
---|
| 88 | QtObservedAtom::AtomPositionChannels(1, AtomObservable::PositionChanged);
|
---|
[9e9100] | 89 | const Observable::channels_t
|
---|
| 90 | QtObservedAtom::AtomSelectedChannels(1, AtomObservable::SelectionChanged);
|
---|
[65c323] | 91 |
|
---|
[98c35c] | 92 | QtObservedAtom::QtObservedAtom(
|
---|
[62a0ee] | 93 | const atomId_t _id,
|
---|
| 94 | const atom * const _atom,
|
---|
[65c323] | 95 | QtObservedInstanceBoard &_board,
|
---|
[98c35c] | 96 | QWidget * _parent) :
|
---|
[0070aa] | 97 | QWidget(_parent),
|
---|
[98c35c] | 98 | Observer("QtObservedAtom"),
|
---|
[65c323] | 99 | subjectKilledCount(0),
|
---|
| 100 | AllsignedOnChannels(getAllObservedChannels().size()),
|
---|
| 101 | signedOffChannels(0),
|
---|
| 102 | owner(NULL),
|
---|
[1c0961] | 103 | oldId(_id),
|
---|
[65c323] | 104 | board(_board),
|
---|
[04c3a3] | 105 | BoardIsGone(false),
|
---|
[62a0ee] | 106 | ObservedValues(QtObservedAtom::MAX_ObservedTypes)
|
---|
[65c323] | 107 | {
|
---|
[62a0ee] | 108 | boost::function<void (const atomId_t)> atomSubjectKilled(
|
---|
| 109 | boost::bind(&QtObservedAtom::countValuesSubjectKilled,
|
---|
| 110 | boost::ref(*this),
|
---|
| 111 | _1));
|
---|
| 112 | initObservedValues( ObservedValues, _id, _atom, atomSubjectKilled);
|
---|
| 113 |
|
---|
| 114 | // activating Observer is done by ObservedValueContainer when it's inserted
|
---|
[65c323] | 115 | }
|
---|
[0070aa] | 116 |
|
---|
| 117 | QtObservedAtom::~QtObservedAtom()
|
---|
[65c323] | 118 | {
|
---|
[04c3a3] | 119 | boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex])->noteCallBackIsGone();
|
---|
| 120 | boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, atomId_t> *>(ObservedValues[AtomBonds])->noteCallBackIsGone();
|
---|
| 121 | boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(ObservedValues[AtomElement])->noteCallBackIsGone();
|
---|
[1187c5] | 122 | boost::any_cast<ObservedValue_wCallback<QtObservedMolecule*, atomId_t> *>(ObservedValues[AtomMolecule])->noteCallBackIsGone();
|
---|
[04c3a3] | 123 | boost::any_cast<ObservedValue_wCallback<std::string, atomId_t> *>(ObservedValues[AtomName])->noteCallBackIsGone();
|
---|
| 124 | boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(ObservedValues[AtomPosition])->noteCallBackIsGone();
|
---|
[9e9100] | 125 | boost::any_cast<ObservedValue_wCallback<bool, atomId_t> *>(ObservedValues[AtomSelected])->noteCallBackIsGone();
|
---|
[04c3a3] | 126 |
|
---|
[65c323] | 127 | deactivateObserver();
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | const atom * const QtObservedAtom::getAtomConst(const atomId_t _id)
|
---|
| 131 | {
|
---|
| 132 | const atom * const _atom = const_cast<const World &>(World::getInstance()).
|
---|
| 133 | getAtom(AtomById(_id));
|
---|
| 134 | return _atom;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | atom * const QtObservedAtom::getAtom(const atomId_t _id)
|
---|
| 138 | {
|
---|
| 139 | atom * const _atom = World::getInstance().getAtom(AtomById(_id));
|
---|
| 140 | return _atom;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | atomId_t QtObservedAtom::updateIndex()
|
---|
| 144 | {
|
---|
| 145 | return const_cast<const World &>(World::getInstance()).lastChangedAtomId();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[fe493f] | 148 | QtObservedAtom::ListOfBonds_t QtObservedAtom::updateBonds(
|
---|
[65c323] | 149 | const boost::function<const atomId_t ()> &_getAtomIndex)
|
---|
| 150 | {
|
---|
[fe493f] | 151 | ListOfBonds_t ListOfBonds;
|
---|
[65c323] | 152 | const atom * const _atom = getAtomConst(_getAtomIndex());
|
---|
| 153 | if (_atom != NULL) {
|
---|
[fe493f] | 154 | // make sure bonds is up-to-date
|
---|
| 155 | const BondList ListBonds = _atom->getListOfBonds();
|
---|
| 156 | for (BondList::const_iterator iter = ListBonds.begin();
|
---|
| 157 | iter != ListBonds.end();
|
---|
| 158 | ++iter)
|
---|
| 159 | ListOfBonds.insert( ListOfBonds.end(), std::make_pair(
|
---|
| 160 | (*iter)->leftatom->getId(),
|
---|
| 161 | (*iter)->rightatom->getId()) );
|
---|
[65c323] | 162 | }
|
---|
[fe493f] | 163 | return ListOfBonds;
|
---|
[65c323] | 164 | }
|
---|
| 165 |
|
---|
| 166 | atomicNumber_t QtObservedAtom::updateElement(
|
---|
| 167 | const boost::function<const atomId_t ()> &_getAtomIndex)
|
---|
| 168 | {
|
---|
| 169 | const atom * const _atom = getAtomConst(_getAtomIndex());
|
---|
| 170 | if (_atom != NULL) {
|
---|
| 171 | return _atom->getElementNo();
|
---|
| 172 | } else {
|
---|
| 173 | return (atomicNumber_t)-1;
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[1187c5] | 177 | QtObservedMolecule* QtObservedAtom::updateMoleculeIndex(
|
---|
[fe493f] | 178 | const boost::function<const atomId_t ()> &_getAtomIndex)
|
---|
| 179 | {
|
---|
| 180 | const atom * const _atom = getAtomConst(_getAtomIndex());
|
---|
| 181 | if ((_atom != NULL) && (_atom->getMolecule() != NULL)) {
|
---|
[1187c5] | 182 | const moleculeId_t molid = _atom->getMolecule()->getId();
|
---|
| 183 | QtObservedMolecule* mol = board.getObservedMolecule(molid).get();
|
---|
| 184 | if (mol != NULL)
|
---|
| 185 | return mol;
|
---|
| 186 | else
|
---|
| 187 | return (QtObservedMolecule*)NULL;
|
---|
[fe493f] | 188 | } else {
|
---|
[1187c5] | 189 | return (QtObservedMolecule*)NULL;
|
---|
[fe493f] | 190 | }
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | std::string QtObservedAtom::updateName(
|
---|
[65c323] | 194 | const boost::function<const atomId_t ()> &_getAtomIndex)
|
---|
| 195 | {
|
---|
| 196 | const atom * const _atom = getAtomConst(_getAtomIndex());
|
---|
| 197 | if (_atom != NULL) {
|
---|
[fe493f] | 198 | return _atom->getName();
|
---|
| 199 | } else {
|
---|
| 200 | return std::string("");
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | Vector QtObservedAtom::updatePosition(
|
---|
| 205 | const boost::function<const atomId_t ()> &_getAtomIndex)
|
---|
| 206 | {
|
---|
| 207 | const atom * const _atom = getAtomConst(_getAtomIndex());
|
---|
| 208 | if (_atom != NULL) {
|
---|
| 209 | return _atom->getPosition();
|
---|
| 210 | } else {
|
---|
| 211 | return zeroVec;
|
---|
[65c323] | 212 | }
|
---|
| 213 | }
|
---|
[98c35c] | 214 |
|
---|
[9e9100] | 215 | bool QtObservedAtom::updateSelected(
|
---|
| 216 | const boost::function<const atomId_t ()> &_getAtomIndex)
|
---|
| 217 | {
|
---|
| 218 | const atom * const _atom = getAtomConst(_getAtomIndex());
|
---|
| 219 | if (_atom != NULL) {
|
---|
| 220 | return _atom->getSelected();
|
---|
| 221 | } else {
|
---|
| 222 | return false;
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[98c35c] | 226 | void QtObservedAtom::update(Observable *publisher)
|
---|
[65c323] | 227 | {
|
---|
| 228 | ASSERT(0, "QtObservedAtom::update() - we are not signed on for global updates.");
|
---|
| 229 | }
|
---|
[98c35c] | 230 |
|
---|
| 231 | void QtObservedAtom::subjectKilled(Observable *publisher)
|
---|
[65c323] | 232 | {
|
---|
| 233 | ++signedOffChannels;
|
---|
| 234 |
|
---|
[62a0ee] | 235 | checkForRemoval();
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | void QtObservedAtom::countValuesSubjectKilled(const atomId_t _id)
|
---|
| 239 | {
|
---|
| 240 | ASSERT( _id == getAtomIndex(),
|
---|
| 241 | "QtObservedAtom::countValuesSubjectKilled() - atom "+toString(getAtomIndex())
|
---|
| 242 | +" received countValuesSubjectKilled for atom id "+toString(_id)+".");
|
---|
| 243 |
|
---|
| 244 | ++subjectKilledCount;
|
---|
| 245 |
|
---|
| 246 | checkForRemoval();
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | #ifdef HAVE_INLINE
|
---|
| 250 | inline
|
---|
| 251 | #endif
|
---|
| 252 | void QtObservedAtom::checkForRemoval()
|
---|
| 253 | {
|
---|
| 254 | if ((signedOffChannels == AllsignedOnChannels) && (subjectKilledCount == MAX_ObservedTypes)) {
|
---|
[65c323] | 255 | // remove owner: no more signOff needed
|
---|
| 256 | owner = NULL;
|
---|
| 257 |
|
---|
[fe493f] | 258 | emit atomRemoved();
|
---|
[4e6ffe] | 259 |
|
---|
| 260 | if (!BoardIsGone) {
|
---|
| 261 | board.markObservedAtomAsDisconnected(getAtomIndex());
|
---|
| 262 | board.markObservedAtomForErase(getAtomIndex());
|
---|
| 263 | }
|
---|
[65c323] | 264 | }
|
---|
| 265 | }
|
---|
[98c35c] | 266 |
|
---|
| 267 | void QtObservedAtom::recieveNotification(Observable *publisher, Notification_ptr notification)
|
---|
[65c323] | 268 | {
|
---|
| 269 | // ObservedValues have been updated before, hence convert updates to Qt's signals
|
---|
| 270 | switch (notification->getChannelNo()) {
|
---|
| 271 | case AtomObservable::IndexChanged:
|
---|
[1c0961] | 272 | {
|
---|
| 273 | const atomId_t newId = getAtomIndex();
|
---|
| 274 | emit indexChanged(oldId, newId);
|
---|
| 275 | oldId = newId;
|
---|
[65c323] | 276 | break;
|
---|
[1c0961] | 277 | }
|
---|
[fe493f] | 278 | case AtomObservable::BondsAdded:
|
---|
| 279 | case AtomObservable::BondsRemoved:
|
---|
| 280 | emit bondsChanged();
|
---|
[65c323] | 281 | break;
|
---|
| 282 | case AtomObservable::ElementChanged:
|
---|
| 283 | emit elementChanged();
|
---|
| 284 | break;
|
---|
[fe493f] | 285 | case AtomObservable::MoleculeChanged:
|
---|
[1187c5] | 286 | emit moleculeChanged();
|
---|
[fe493f] | 287 | break;
|
---|
| 288 | case AtomObservable::NameChanged:
|
---|
| 289 | emit nameChanged();
|
---|
| 290 | break;
|
---|
| 291 | case AtomObservable::PositionChanged:
|
---|
| 292 | emit positionChanged();
|
---|
[65c323] | 293 | break;
|
---|
[9e9100] | 294 | case AtomObservable::SelectionChanged:
|
---|
| 295 | emit selectedChanged();
|
---|
| 296 | break;
|
---|
[65c323] | 297 | default:
|
---|
| 298 | ASSERT(0, "QtObservedAtom::recieveNotification() - we are not signed on to channel "
|
---|
| 299 | +toString(notification->getChannelNo())+" of the atom.");
|
---|
| 300 | break;
|
---|
| 301 | }
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | void QtObservedAtom::activateObserver()
|
---|
| 305 | {
|
---|
| 306 | atom * atomref = getAtom(getAtomIndex());
|
---|
| 307 | if (atomref != NULL) {
|
---|
| 308 | Observable::channels_t channels = getAllObservedChannels();
|
---|
| 309 | owner = static_cast<const Observable *>(atomref);
|
---|
| 310 | for (Observable::channels_t::const_iterator iter = channels.begin();
|
---|
| 311 | iter != channels.end(); ++iter)
|
---|
| 312 | owner->signOn(this, *iter);
|
---|
[04c3a3] | 313 | if (!BoardIsGone)
|
---|
| 314 | board.markObservedAtomAsConnected(getAtomIndex());
|
---|
[65c323] | 315 | } else
|
---|
[04c3a3] | 316 | signedOffChannels = AllsignedOnChannels;
|
---|
[65c323] | 317 | }
|
---|
| 318 |
|
---|
| 319 | void QtObservedAtom::deactivateObserver()
|
---|
| 320 | {
|
---|
| 321 | // sign Off
|
---|
| 322 | if (owner != NULL) {
|
---|
| 323 | Observable::channels_t channels = getAllObservedChannels();
|
---|
| 324 | for (Observable::channels_t::const_iterator iter = channels.begin();
|
---|
| 325 | iter != channels.end(); ++iter)
|
---|
| 326 | owner->signOff(this, *iter);
|
---|
| 327 | owner = NULL;
|
---|
| 328 | signedOffChannels = AllsignedOnChannels;
|
---|
[04c3a3] | 329 | if (!BoardIsGone)
|
---|
| 330 | board.markObservedAtomAsDisconnected(getAtomIndex());
|
---|
[65c323] | 331 | }
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 | void QtObservedAtom::initObservedValues(
|
---|
| 335 | ObservedValues_t &_ObservedValues,
|
---|
| 336 | const atomId_t _id,
|
---|
| 337 | const atom * const _atomref,
|
---|
| 338 | const boost::function<void(const atomId_t)> &_subjectKilled)
|
---|
| 339 | {
|
---|
| 340 | /* This is an old note from when the code was still part of cstor's initializer body.
|
---|
| 341 | * TODO: Probably does not apply anymore but has not yet been tested.
|
---|
| 342 | *
|
---|
| 343 | * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
|
---|
| 344 | * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
|
---|
| 345 | * the class has not been fully constructed yet. "This" itself seems to be working fine.
|
---|
| 346 | */
|
---|
| 347 |
|
---|
| 348 | ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
|
---|
| 349 | "QtObservedAtom::initObservedValues() - given ObservedValues has not correct size.");
|
---|
| 350 |
|
---|
| 351 | // fill ObservedValues: index first
|
---|
| 352 | const boost::function<atomId_t ()> AtomIndexUpdater(
|
---|
| 353 | boost::bind(&QtObservedAtom::updateIndex));
|
---|
| 354 |
|
---|
| 355 | ObservedValue_wCallback<atomId_t> * const IndexObservable =
|
---|
| 356 | new ObservedValue_wCallback<atomId_t>(
|
---|
| 357 | _atomref,
|
---|
| 358 | boost::bind(&QtObservedAtom::updateIndex),
|
---|
| 359 | "AtomIndex_"+toString(_id),
|
---|
| 360 | _id,
|
---|
| 361 | AtomIndexChannels,
|
---|
| 362 | _subjectKilled);
|
---|
| 363 | _ObservedValues[AtomIndex] = IndexObservable;
|
---|
| 364 |
|
---|
| 365 | const boost::function<const atomId_t ()> AtomIndexGetter =
|
---|
| 366 | boost::bind(&ObservedValue_wCallback<atomId_t>::get,
|
---|
| 367 | IndexObservable);
|
---|
| 368 |
|
---|
| 369 | // fill ObservedValues: then all the other that need index
|
---|
| 370 | const boost::function<ListOfBonds_t ()> AtomBondsUpdater(
|
---|
| 371 | boost::bind(&QtObservedAtom::updateBonds, AtomIndexGetter));
|
---|
[fe493f] | 372 | const boost::function<atomicNumber_t ()> AtomElementUpdater(
|
---|
| 373 | boost::bind(&QtObservedAtom::updateElement, AtomIndexGetter));
|
---|
[1187c5] | 374 | const boost::function<QtObservedMolecule* ()> AtomMoleculeUpdater(
|
---|
| 375 | boost::bind(&QtObservedAtom::updateMoleculeIndex, this, AtomIndexGetter));
|
---|
[fe493f] | 376 | const boost::function<std::string ()> AtomNameUpdater(
|
---|
| 377 | boost::bind(&QtObservedAtom::updateName, AtomIndexGetter));
|
---|
| 378 | const boost::function<Vector ()> AtomPositionUpdater(
|
---|
| 379 | boost::bind(&QtObservedAtom::updatePosition, AtomIndexGetter));
|
---|
[9e9100] | 380 | const boost::function<bool ()> AtomSelectedUpdater(
|
---|
| 381 | boost::bind(&QtObservedAtom::updateSelected, AtomIndexGetter));
|
---|
[65c323] | 382 |
|
---|
[fe493f] | 383 | _ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t, atomId_t>(
|
---|
[65c323] | 384 | _atomref,
|
---|
[fe493f] | 385 | AtomBondsUpdater,
|
---|
| 386 | "AtomBonds_"+toString(_id),
|
---|
| 387 | AtomBondsUpdater(),
|
---|
| 388 | AtomBondsChannels,
|
---|
[65c323] | 389 | _subjectKilled,
|
---|
| 390 | AtomIndexGetter);
|
---|
| 391 | _ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t, atomId_t>(
|
---|
| 392 | _atomref,
|
---|
| 393 | AtomElementUpdater,
|
---|
| 394 | "AtomElement"+toString(_id),
|
---|
| 395 | AtomElementUpdater(),
|
---|
| 396 | AtomElementChannels,
|
---|
| 397 | _subjectKilled,
|
---|
| 398 | AtomIndexGetter);
|
---|
[1187c5] | 399 | _ObservedValues[AtomMolecule] = new ObservedValue_wCallback<QtObservedMolecule*, atomId_t>(
|
---|
[65c323] | 400 | _atomref,
|
---|
[1187c5] | 401 | AtomMoleculeUpdater,
|
---|
| 402 | "AtomMolecule"+toString(_id),
|
---|
| 403 | AtomMoleculeUpdater(),
|
---|
| 404 | AtomMoleculeChannels,
|
---|
[fe493f] | 405 | _subjectKilled,
|
---|
| 406 | AtomIndexGetter);
|
---|
| 407 | _ObservedValues[AtomName] = new ObservedValue_wCallback<std::string, atomId_t>(
|
---|
| 408 | _atomref,
|
---|
| 409 | AtomNameUpdater,
|
---|
| 410 | "AtomName"+toString(_id),
|
---|
| 411 | AtomNameUpdater(),
|
---|
| 412 | AtomNameChannels,
|
---|
| 413 | _subjectKilled,
|
---|
| 414 | AtomIndexGetter);
|
---|
| 415 | _ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector, atomId_t>(
|
---|
| 416 | _atomref,
|
---|
| 417 | AtomPositionUpdater,
|
---|
| 418 | "AtomPosition_"+toString(_id),
|
---|
| 419 | AtomPositionUpdater(),
|
---|
| 420 | AtomPositionChannels,
|
---|
[65c323] | 421 | _subjectKilled,
|
---|
| 422 | AtomIndexGetter);
|
---|
[9e9100] | 423 | _ObservedValues[AtomSelected] = new ObservedValue_wCallback<bool, atomId_t>(
|
---|
| 424 | _atomref,
|
---|
| 425 | AtomSelectedUpdater,
|
---|
| 426 | "AtomSelected_"+toString(_id),
|
---|
| 427 | AtomSelectedUpdater(),
|
---|
| 428 | AtomSelectedChannels,
|
---|
| 429 | _subjectKilled,
|
---|
| 430 | AtomIndexGetter);
|
---|
[65c323] | 431 | }
|
---|
| 432 |
|
---|
| 433 | void QtObservedAtom::destroyObservedValues(
|
---|
| 434 | std::vector<boost::any> &_ObservedValues)
|
---|
| 435 | {
|
---|
| 436 | delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[AtomIndex]);
|
---|
| 437 | delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, atomId_t> *>(_ObservedValues[AtomBonds]);
|
---|
[fe493f] | 438 | delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(_ObservedValues[AtomElement]);
|
---|
[1187c5] | 439 | delete boost::any_cast<ObservedValue_wCallback<QtObservedMolecule*, atomId_t> *>(_ObservedValues[AtomMolecule]);
|
---|
[fe493f] | 440 | delete boost::any_cast<ObservedValue_wCallback<std::string, atomId_t> *>(_ObservedValues[AtomName]);
|
---|
| 441 | delete boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(_ObservedValues[AtomPosition]);
|
---|
[9e9100] | 442 | delete boost::any_cast<ObservedValue_wCallback<bool, atomId_t> *>(_ObservedValues[AtomSelected]);
|
---|
[65c323] | 443 | _ObservedValues.clear();
|
---|
| 444 | }
|
---|
| 445 |
|
---|
[3b9aa1] | 446 | const atomId_t& QtObservedAtom::getAtomIndex() const
|
---|
[65c323] | 447 | {
|
---|
| 448 | return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex])->get();
|
---|
| 449 | }
|
---|
| 450 |
|
---|
[3b9aa1] | 451 | const QtObservedAtom::ListOfBonds_t& QtObservedAtom::getAtomBonds() const
|
---|
[65c323] | 452 | {
|
---|
[fe493f] | 453 | return boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, atomId_t> *>(ObservedValues[AtomBonds])->get();
|
---|
[65c323] | 454 | }
|
---|
| 455 |
|
---|
[3b9aa1] | 456 | const atomicNumber_t& QtObservedAtom::getAtomElement() const
|
---|
[65c323] | 457 | {
|
---|
| 458 | return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(ObservedValues[AtomElement])->get();
|
---|
| 459 | }
|
---|
| 460 |
|
---|
[1187c5] | 461 | QtObservedMolecule* const QtObservedAtom::getAtomMolecule() const
|
---|
[65c323] | 462 | {
|
---|
[1187c5] | 463 | return boost::any_cast<ObservedValue_wCallback<QtObservedMolecule*, atomId_t> *>(ObservedValues[AtomMolecule])->get();
|
---|
[fe493f] | 464 | }
|
---|
| 465 |
|
---|
[3b9aa1] | 466 | const std::string& QtObservedAtom::getAtomName() const
|
---|
[fe493f] | 467 | {
|
---|
| 468 | return boost::any_cast<ObservedValue_wCallback<std::string, atomId_t> *>(ObservedValues[AtomName])->get();
|
---|
| 469 | }
|
---|
| 470 |
|
---|
[3b9aa1] | 471 | const Vector& QtObservedAtom::getAtomPosition() const
|
---|
[fe493f] | 472 | {
|
---|
| 473 | return boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(ObservedValues[AtomPosition])->get();
|
---|
[65c323] | 474 | }
|
---|
[9e9100] | 475 |
|
---|
| 476 | const bool QtObservedAtom::getAtomSelected() const
|
---|
| 477 | {
|
---|
| 478 | return boost::any_cast<ObservedValue_wCallback<bool, atomId_t> *>(ObservedValues[AtomSelected])->get();
|
---|
| 479 | }
|
---|