| [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
 | 
|---|
| [273c8a] | 84 | QtObservedAtom::MoleculeChangedChannels(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),
 | 
|---|
| [08a7ecc] | 103 |   index(static_cast<const ObservedValue_Index_t>(const_cast<const QtObservedAtom * const>(this))),
 | 
|---|
| [65c323] | 104 |   board(_board),
 | 
|---|
| [04c3a3] | 105 |   BoardIsGone(false),
 | 
|---|
| [62a0ee] | 106 |   ObservedValues(QtObservedAtom::MAX_ObservedTypes)
 | 
|---|
| [65c323] | 107 | {
 | 
|---|
| [d48a16] | 108 |   boost::function<void ()> atomSubjectKilled(
 | 
|---|
| [62a0ee] | 109 |       boost::bind(&QtObservedAtom::countValuesSubjectKilled,
 | 
|---|
 | 110 |           boost::ref(*this),
 | 
|---|
| [ee3fb8] | 111 |           boost::bind(&QtObservedAtom::getIndex, boost::ref(*this))));
 | 
|---|
| [62a0ee] | 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 | {
 | 
|---|
| [ee3fb8] | 119 |   boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(ObservedValues[AtomIndex])->noteCallBackIsGone();
 | 
|---|
 | 120 |   boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, ObservedValue_Index_t> *>(ObservedValues[AtomBonds])->noteCallBackIsGone();
 | 
|---|
 | 121 |   boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(ObservedValues[AtomElement])->noteCallBackIsGone();
 | 
|---|
| [273c8a] | 122 |   boost::any_cast<ObservedValue_wCallback<QtObservedMolecule*, ObservedValue_Index_t> *>(ObservedValues[MoleculeRef])->noteCallBackIsGone();
 | 
|---|
| [ee3fb8] | 123 |   boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(ObservedValues[AtomName])->noteCallBackIsGone();
 | 
|---|
 | 124 |   boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[AtomPosition])->noteCallBackIsGone();
 | 
|---|
 | 125 |   boost::any_cast<ObservedValue_wCallback<bool, ObservedValue_Index_t> *>(ObservedValues[AtomSelected])->noteCallBackIsGone();
 | 
|---|
| [04c3a3] | 126 | 
 | 
|---|
| [65c323] | 127 |   deactivateObserver();
 | 
|---|
| [c44763] | 128 | 
 | 
|---|
 | 129 |   destroyObservedValues(ObservedValues);
 | 
|---|
| [65c323] | 130 | }
 | 
|---|
 | 131 | 
 | 
|---|
 | 132 | const atom * const QtObservedAtom::getAtomConst(const atomId_t _id)
 | 
|---|
 | 133 | {
 | 
|---|
 | 134 |   const atom * const _atom = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 135 |       getAtom(AtomById(_id));
 | 
|---|
 | 136 |   return _atom;
 | 
|---|
 | 137 | }
 | 
|---|
 | 138 | 
 | 
|---|
 | 139 | atom * const QtObservedAtom::getAtom(const atomId_t _id)
 | 
|---|
 | 140 | {
 | 
|---|
 | 141 |   atom * const _atom = World::getInstance().getAtom(AtomById(_id));
 | 
|---|
 | 142 |   return _atom;
 | 
|---|
 | 143 | }
 | 
|---|
 | 144 | 
 | 
|---|
| [f35f7e] | 145 | #ifdef HAVE_INLINE
 | 
|---|
 | 146 | inline
 | 
|---|
 | 147 | #endif
 | 
|---|
 | 148 | atomId_t QtObservedAtom::updateIndex(const atom &_atomref)
 | 
|---|
| [65c323] | 149 | {
 | 
|---|
| [f35f7e] | 150 |   return _atomref.getId();
 | 
|---|
| [65c323] | 151 | }
 | 
|---|
 | 152 | 
 | 
|---|
| [fe493f] | 153 | QtObservedAtom::ListOfBonds_t QtObservedAtom::updateBonds(
 | 
|---|
| [f35f7e] | 154 |     const atom &_atom)
 | 
|---|
| [65c323] | 155 | {
 | 
|---|
| [fe493f] | 156 |   ListOfBonds_t ListOfBonds;
 | 
|---|
| [f35f7e] | 157 |   // make sure bonds is up-to-date
 | 
|---|
 | 158 |   const BondList ListBonds = _atom.getListOfBonds();
 | 
|---|
 | 159 |   for (BondList::const_iterator iter = ListBonds.begin();
 | 
|---|
 | 160 |       iter != ListBonds.end();
 | 
|---|
 | 161 |       ++iter)
 | 
|---|
 | 162 |     ListOfBonds.insert( ListOfBonds.end(), std::make_pair(
 | 
|---|
 | 163 |         (*iter)->leftatom->getId(),
 | 
|---|
 | 164 |         (*iter)->rightatom->getId()) );
 | 
|---|
| [fe493f] | 165 |   return ListOfBonds;
 | 
|---|
| [65c323] | 166 | }
 | 
|---|
 | 167 | 
 | 
|---|
| [f35f7e] | 168 | #ifdef HAVE_INLINE
 | 
|---|
 | 169 | inline
 | 
|---|
 | 170 | #endif
 | 
|---|
| [65c323] | 171 | atomicNumber_t QtObservedAtom::updateElement(
 | 
|---|
| [f35f7e] | 172 |     const atom &_atom)
 | 
|---|
| [65c323] | 173 | {
 | 
|---|
| [f35f7e] | 174 |   return _atom.getElementNo();
 | 
|---|
| [65c323] | 175 | }
 | 
|---|
 | 176 | 
 | 
|---|
| [f35f7e] | 177 | #ifdef HAVE_INLINE
 | 
|---|
 | 178 | inline
 | 
|---|
 | 179 | #endif
 | 
|---|
| [273c8a] | 180 | QtObservedMolecule* QtObservedAtom::updateMoleculeRef(
 | 
|---|
| [f35f7e] | 181 |     const atom &_atom)
 | 
|---|
| [fe493f] | 182 | {
 | 
|---|
| [f35f7e] | 183 |   if (_atom.getMolecule() != NULL) {
 | 
|---|
 | 184 |     const moleculeId_t molid = _atom.getMolecule()->getId();
 | 
|---|
| [273c8a] | 185 |     const QtObservedMolecule::ptr mol = board.getObservedMolecule(molid);
 | 
|---|
 | 186 |     ASSERT(mol,
 | 
|---|
 | 187 |         "QtObservedAtom::updateMoleculeRef() - could not update the ref, "
 | 
|---|
 | 188 |         +toString(molid)+" unknown to Instance board?");
 | 
|---|
 | 189 |     return mol.get();
 | 
|---|
| [fe493f] | 190 |   } else {
 | 
|---|
| [273c8a] | 191 |     return (QtObservedMolecule*)NULL;
 | 
|---|
| [fe493f] | 192 |   }
 | 
|---|
 | 193 | }
 | 
|---|
 | 194 | 
 | 
|---|
| [f35f7e] | 195 | #ifdef HAVE_INLINE
 | 
|---|
 | 196 | inline
 | 
|---|
 | 197 | #endif
 | 
|---|
| [fe493f] | 198 | std::string QtObservedAtom::updateName(
 | 
|---|
| [f35f7e] | 199 |     const atom &_atom)
 | 
|---|
| [65c323] | 200 | {
 | 
|---|
| [f35f7e] | 201 |   return _atom.getName();
 | 
|---|
| [fe493f] | 202 | }
 | 
|---|
 | 203 | 
 | 
|---|
| [f35f7e] | 204 | #ifdef HAVE_INLINE
 | 
|---|
 | 205 | inline
 | 
|---|
 | 206 | #endif
 | 
|---|
| [fe493f] | 207 | Vector QtObservedAtom::updatePosition(
 | 
|---|
| [f35f7e] | 208 |     const atom &_atom)
 | 
|---|
| [fe493f] | 209 | {
 | 
|---|
| [f35f7e] | 210 |   return _atom.getPosition();
 | 
|---|
| [65c323] | 211 | }
 | 
|---|
| [98c35c] | 212 | 
 | 
|---|
| [f35f7e] | 213 | #ifdef HAVE_INLINE
 | 
|---|
 | 214 | inline
 | 
|---|
 | 215 | #endif
 | 
|---|
| [9e9100] | 216 | bool QtObservedAtom::updateSelected(
 | 
|---|
| [f35f7e] | 217 |     const atom &_atom)
 | 
|---|
| [9e9100] | 218 | {
 | 
|---|
| [f35f7e] | 219 |   return _atom.getSelected();
 | 
|---|
| [9e9100] | 220 | }
 | 
|---|
 | 221 | 
 | 
|---|
| [98c35c] | 222 | void QtObservedAtom::update(Observable *publisher)
 | 
|---|
| [65c323] | 223 | {
 | 
|---|
 | 224 |   ASSERT(0, "QtObservedAtom::update() - we are not signed on for global updates.");
 | 
|---|
 | 225 | }
 | 
|---|
| [98c35c] | 226 | 
 | 
|---|
 | 227 | void QtObservedAtom::subjectKilled(Observable *publisher)
 | 
|---|
| [65c323] | 228 | {
 | 
|---|
 | 229 |   ++signedOffChannels;
 | 
|---|
 | 230 | 
 | 
|---|
| [ee3fb8] | 231 |   checkForRemoval(getIndex());
 | 
|---|
| [62a0ee] | 232 | }
 | 
|---|
 | 233 | 
 | 
|---|
| [ee3fb8] | 234 | void QtObservedAtom::countValuesSubjectKilled(ObservedValue_Index_t _id)
 | 
|---|
| [62a0ee] | 235 | {
 | 
|---|
| [ee3fb8] | 236 |   ASSERT( _id == getIndex(),
 | 
|---|
 | 237 |       "QtObservedAtom::countValuesSubjectKilled() - atom "+toString(getIndex())
 | 
|---|
| [62a0ee] | 238 |       +" received countValuesSubjectKilled for atom id "+toString(_id)+".");
 | 
|---|
 | 239 | 
 | 
|---|
 | 240 |   ++subjectKilledCount;
 | 
|---|
 | 241 | 
 | 
|---|
| [ee3fb8] | 242 |   checkForRemoval(_id);
 | 
|---|
| [62a0ee] | 243 | }
 | 
|---|
 | 244 | 
 | 
|---|
 | 245 | #ifdef HAVE_INLINE
 | 
|---|
 | 246 | inline
 | 
|---|
 | 247 | #endif
 | 
|---|
| [ee3fb8] | 248 | void QtObservedAtom::checkForRemoval(ObservedValue_Index_t _id)
 | 
|---|
| [62a0ee] | 249 | {
 | 
|---|
 | 250 |   if ((signedOffChannels == AllsignedOnChannels) && (subjectKilledCount == MAX_ObservedTypes)) {
 | 
|---|
| [65c323] | 251 |     // remove owner: no more signOff needed
 | 
|---|
 | 252 |     owner = NULL;
 | 
|---|
 | 253 | 
 | 
|---|
| [fe493f] | 254 |     emit atomRemoved();
 | 
|---|
| [4e6ffe] | 255 | 
 | 
|---|
 | 256 |     if (!BoardIsGone) {
 | 
|---|
| [ee3fb8] | 257 |       board.markObservedAtomAsDisconnected(_id);
 | 
|---|
 | 258 |       board.markObservedAtomForErase(_id);
 | 
|---|
| [4e6ffe] | 259 |     }
 | 
|---|
| [65c323] | 260 |   }
 | 
|---|
 | 261 | }
 | 
|---|
| [98c35c] | 262 | 
 | 
|---|
 | 263 | void QtObservedAtom::recieveNotification(Observable *publisher, Notification_ptr notification)
 | 
|---|
| [65c323] | 264 | {
 | 
|---|
 | 265 |   // ObservedValues have been updated before, hence convert updates to Qt's signals
 | 
|---|
 | 266 |   switch (notification->getChannelNo()) {
 | 
|---|
 | 267 |     case AtomObservable::IndexChanged:
 | 
|---|
| [1c0961] | 268 |     {
 | 
|---|
| [522c45] | 269 |       emit indexChanged();
 | 
|---|
| [65c323] | 270 |       break;
 | 
|---|
| [1c0961] | 271 |     }
 | 
|---|
| [fe493f] | 272 |     case AtomObservable::BondsAdded:
 | 
|---|
 | 273 |     case AtomObservable::BondsRemoved:
 | 
|---|
 | 274 |       emit bondsChanged();
 | 
|---|
| [65c323] | 275 |       break;
 | 
|---|
 | 276 |     case AtomObservable::ElementChanged:
 | 
|---|
 | 277 |       emit elementChanged();
 | 
|---|
 | 278 |       break;
 | 
|---|
| [fe493f] | 279 |     case AtomObservable::MoleculeChanged:
 | 
|---|
| [1187c5] | 280 |       emit moleculeChanged();
 | 
|---|
| [fe493f] | 281 |       break;
 | 
|---|
 | 282 |     case AtomObservable::NameChanged:
 | 
|---|
 | 283 |       emit nameChanged();
 | 
|---|
 | 284 |       break;
 | 
|---|
 | 285 |     case AtomObservable::PositionChanged:
 | 
|---|
 | 286 |       emit positionChanged();
 | 
|---|
| [65c323] | 287 |       break;
 | 
|---|
| [9e9100] | 288 |     case AtomObservable::SelectionChanged:
 | 
|---|
 | 289 |       emit selectedChanged();
 | 
|---|
 | 290 |       break;
 | 
|---|
| [65c323] | 291 |     default:
 | 
|---|
 | 292 |       ASSERT(0, "QtObservedAtom::recieveNotification() - we are not signed on to channel "
 | 
|---|
 | 293 |           +toString(notification->getChannelNo())+" of the atom.");
 | 
|---|
 | 294 |       break;
 | 
|---|
 | 295 |   }
 | 
|---|
 | 296 | }
 | 
|---|
 | 297 | 
 | 
|---|
 | 298 | void QtObservedAtom::activateObserver()
 | 
|---|
 | 299 | {
 | 
|---|
 | 300 |   atom * atomref = getAtom(getAtomIndex());
 | 
|---|
 | 301 |   if (atomref != NULL) {
 | 
|---|
 | 302 |     Observable::channels_t channels = getAllObservedChannels();
 | 
|---|
 | 303 |     owner = static_cast<const Observable *>(atomref);
 | 
|---|
 | 304 |     for (Observable::channels_t::const_iterator iter = channels.begin();
 | 
|---|
 | 305 |         iter != channels.end(); ++iter)
 | 
|---|
 | 306 |       owner->signOn(this, *iter);
 | 
|---|
| [04c3a3] | 307 |     if (!BoardIsGone)
 | 
|---|
| [59eabc] | 308 |       board.markObservedAtomAsConnected(getIndex());
 | 
|---|
| [65c323] | 309 |   } else
 | 
|---|
| [04c3a3] | 310 |     signedOffChannels = AllsignedOnChannels;
 | 
|---|
| [65c323] | 311 | }
 | 
|---|
 | 312 | 
 | 
|---|
 | 313 | void QtObservedAtom::deactivateObserver()
 | 
|---|
 | 314 | {
 | 
|---|
 | 315 |   // sign Off
 | 
|---|
 | 316 |   if (owner != NULL) {
 | 
|---|
 | 317 |     Observable::channels_t channels = getAllObservedChannels();
 | 
|---|
 | 318 |     for (Observable::channels_t::const_iterator iter = channels.begin();
 | 
|---|
 | 319 |         iter != channels.end(); ++iter)
 | 
|---|
 | 320 |       owner->signOff(this, *iter);
 | 
|---|
 | 321 |     owner = NULL;
 | 
|---|
 | 322 |     signedOffChannels = AllsignedOnChannels;
 | 
|---|
| [04c3a3] | 323 |     if (!BoardIsGone)
 | 
|---|
| [59eabc] | 324 |       board.markObservedAtomAsDisconnected(getIndex());
 | 
|---|
| [65c323] | 325 |   }
 | 
|---|
 | 326 | }
 | 
|---|
 | 327 | 
 | 
|---|
 | 328 | void QtObservedAtom::initObservedValues(
 | 
|---|
 | 329 |     ObservedValues_t &_ObservedValues,
 | 
|---|
 | 330 |     const atomId_t _id,
 | 
|---|
 | 331 |     const atom * const _atomref,
 | 
|---|
| [d48a16] | 332 |     const boost::function<void()> &_subjectKilled)
 | 
|---|
| [65c323] | 333 | {
 | 
|---|
 | 334 |   ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
 | 
|---|
 | 335 |       "QtObservedAtom::initObservedValues() - given ObservedValues has not correct size.");
 | 
|---|
 | 336 | 
 | 
|---|
 | 337 |   // fill ObservedValues: then all the other that need index
 | 
|---|
| [ee3fb8] | 338 |   const boost::function<atomId_t ()> AtomIndexUpdater(
 | 
|---|
 | 339 |       boost::bind(&QtObservedAtom::updateIndex, boost::cref(*_atomref)));
 | 
|---|
| [65c323] | 340 |   const boost::function<ListOfBonds_t ()> AtomBondsUpdater(
 | 
|---|
| [f35f7e] | 341 |       boost::bind(&QtObservedAtom::updateBonds, boost::cref(*_atomref)));
 | 
|---|
| [fe493f] | 342 |   const boost::function<atomicNumber_t ()> AtomElementUpdater(
 | 
|---|
| [f35f7e] | 343 |       boost::bind(&QtObservedAtom::updateElement, boost::cref(*_atomref)));
 | 
|---|
| [fe493f] | 344 |   const boost::function<std::string ()> AtomNameUpdater(
 | 
|---|
| [f35f7e] | 345 |       boost::bind(&QtObservedAtom::updateName, boost::cref(*_atomref)));
 | 
|---|
| [fe493f] | 346 |   const boost::function<Vector ()> AtomPositionUpdater(
 | 
|---|
| [f35f7e] | 347 |       boost::bind(&QtObservedAtom::updatePosition, boost::cref(*_atomref)));
 | 
|---|
| [9e9100] | 348 |   const boost::function<bool ()> AtomSelectedUpdater(
 | 
|---|
| [f35f7e] | 349 |       boost::bind(&QtObservedAtom::updateSelected, boost::cref(*_atomref)));
 | 
|---|
| [273c8a] | 350 |   const boost::function<QtObservedMolecule* ()> MoleculeRefUpdater(
 | 
|---|
 | 351 |       boost::bind(&QtObservedAtom::updateMoleculeRef, this, boost::cref(*_atomref)));
 | 
|---|
| [65c323] | 352 | 
 | 
|---|
| [ee3fb8] | 353 |   _ObservedValues[AtomIndex] = new ObservedValue_wCallback<atomId_t, ObservedValue_Index_t>(
 | 
|---|
 | 354 |       _atomref,
 | 
|---|
 | 355 |       AtomIndexUpdater,
 | 
|---|
 | 356 |       "AtomIndex_"+toString(_id),
 | 
|---|
 | 357 |       _id,
 | 
|---|
 | 358 |       AtomIndexChannels,
 | 
|---|
| [d48a16] | 359 |       _subjectKilled);
 | 
|---|
| [ee3fb8] | 360 |   _ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t, ObservedValue_Index_t>(
 | 
|---|
| [65c323] | 361 |       _atomref,
 | 
|---|
| [fe493f] | 362 |       AtomBondsUpdater,
 | 
|---|
 | 363 |       "AtomBonds_"+toString(_id),
 | 
|---|
 | 364 |       AtomBondsUpdater(),
 | 
|---|
 | 365 |       AtomBondsChannels,
 | 
|---|
| [d48a16] | 366 |       _subjectKilled);
 | 
|---|
| [ee3fb8] | 367 |   _ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t>(
 | 
|---|
| [65c323] | 368 |       _atomref,
 | 
|---|
 | 369 |       AtomElementUpdater,
 | 
|---|
 | 370 |       "AtomElement"+toString(_id),
 | 
|---|
 | 371 |       AtomElementUpdater(),
 | 
|---|
 | 372 |       AtomElementChannels,
 | 
|---|
| [d48a16] | 373 |       _subjectKilled);
 | 
|---|
| [ee3fb8] | 374 |   _ObservedValues[AtomName] = new ObservedValue_wCallback<std::string, ObservedValue_Index_t>(
 | 
|---|
| [fe493f] | 375 |       _atomref,
 | 
|---|
 | 376 |       AtomNameUpdater,
 | 
|---|
 | 377 |       "AtomName"+toString(_id),
 | 
|---|
 | 378 |       AtomNameUpdater(),
 | 
|---|
 | 379 |       AtomNameChannels,
 | 
|---|
| [d48a16] | 380 |       _subjectKilled);
 | 
|---|
| [ee3fb8] | 381 |   _ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector, ObservedValue_Index_t>(
 | 
|---|
| [fe493f] | 382 |       _atomref,
 | 
|---|
 | 383 |       AtomPositionUpdater,
 | 
|---|
 | 384 |       "AtomPosition_"+toString(_id),
 | 
|---|
 | 385 |       AtomPositionUpdater(),
 | 
|---|
 | 386 |       AtomPositionChannels,
 | 
|---|
| [d48a16] | 387 |       _subjectKilled);
 | 
|---|
| [ee3fb8] | 388 |   _ObservedValues[AtomSelected] = new ObservedValue_wCallback<bool, ObservedValue_Index_t>(
 | 
|---|
| [9e9100] | 389 |       _atomref,
 | 
|---|
 | 390 |       AtomSelectedUpdater,
 | 
|---|
 | 391 |       "AtomSelected_"+toString(_id),
 | 
|---|
 | 392 |       AtomSelectedUpdater(),
 | 
|---|
 | 393 |       AtomSelectedChannels,
 | 
|---|
| [d48a16] | 394 |       _subjectKilled);
 | 
|---|
| [273c8a] | 395 |   _ObservedValues[MoleculeRef] = new ObservedValue_wCallback<QtObservedMolecule*, ObservedValue_Index_t>(
 | 
|---|
 | 396 |       _atomref,
 | 
|---|
 | 397 |       MoleculeRefUpdater,
 | 
|---|
 | 398 |       "AtomMoleculeIndex"+toString(_id),
 | 
|---|
 | 399 |       MoleculeRefUpdater(),
 | 
|---|
 | 400 |       MoleculeChangedChannels,
 | 
|---|
 | 401 |       _subjectKilled);
 | 
|---|
| [65c323] | 402 | }
 | 
|---|
 | 403 | 
 | 
|---|
 | 404 | void QtObservedAtom::destroyObservedValues(
 | 
|---|
 | 405 |     std::vector<boost::any> &_ObservedValues)
 | 
|---|
 | 406 | {
 | 
|---|
| [ee3fb8] | 407 |   delete boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(_ObservedValues[AtomIndex]);
 | 
|---|
 | 408 |   delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, ObservedValue_Index_t> *>(_ObservedValues[AtomBonds]);
 | 
|---|
 | 409 |   delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(_ObservedValues[AtomElement]);
 | 
|---|
 | 410 |   delete boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(_ObservedValues[AtomName]);
 | 
|---|
 | 411 |   delete boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(_ObservedValues[AtomPosition]);
 | 
|---|
 | 412 |   delete boost::any_cast<ObservedValue_wCallback<bool, ObservedValue_Index_t> *>(_ObservedValues[AtomSelected]);
 | 
|---|
| [273c8a] | 413 |   delete boost::any_cast<ObservedValue_wCallback<QtObservedMolecule*, ObservedValue_Index_t> *>(_ObservedValues[MoleculeRef]);
 | 
|---|
| [65c323] | 414 |   _ObservedValues.clear();
 | 
|---|
 | 415 | }
 | 
|---|
 | 416 | 
 | 
|---|
| [59eabc] | 417 | ObservedValue_Index_t QtObservedAtom::getIndex() const
 | 
|---|
 | 418 | {
 | 
|---|
| [498c678] | 419 |   ASSERT( index != NULL,
 | 
|---|
| [59eabc] | 420 |       "QtObservedAtom::getIndex() - index is NULL");
 | 
|---|
| [498c678] | 421 |   return index;
 | 
|---|
| [59eabc] | 422 | }
 | 
|---|
 | 423 | 
 | 
|---|
| [3b9aa1] | 424 | const atomId_t& QtObservedAtom::getAtomIndex() const
 | 
|---|
| [65c323] | 425 | {
 | 
|---|
| [ee3fb8] | 426 |   return boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(ObservedValues[AtomIndex])->get();
 | 
|---|
| [65c323] | 427 | }
 | 
|---|
 | 428 | 
 | 
|---|
| [3b9aa1] | 429 | const QtObservedAtom::ListOfBonds_t& QtObservedAtom::getAtomBonds() const
 | 
|---|
| [65c323] | 430 | {
 | 
|---|
| [ee3fb8] | 431 |   return boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, ObservedValue_Index_t> *>(ObservedValues[AtomBonds])->get();
 | 
|---|
| [65c323] | 432 | }
 | 
|---|
 | 433 | 
 | 
|---|
| [3b9aa1] | 434 | const atomicNumber_t& QtObservedAtom::getAtomElement() const
 | 
|---|
| [65c323] | 435 | {
 | 
|---|
| [ee3fb8] | 436 |   return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(ObservedValues[AtomElement])->get();
 | 
|---|
| [65c323] | 437 | }
 | 
|---|
 | 438 | 
 | 
|---|
| [3b9aa1] | 439 | const std::string& QtObservedAtom::getAtomName() const
 | 
|---|
| [fe493f] | 440 | {
 | 
|---|
| [ee3fb8] | 441 |   return boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(ObservedValues[AtomName])->get();
 | 
|---|
| [fe493f] | 442 | }
 | 
|---|
 | 443 | 
 | 
|---|
| [3b9aa1] | 444 | const Vector& QtObservedAtom::getAtomPosition() const
 | 
|---|
| [fe493f] | 445 | {
 | 
|---|
| [ee3fb8] | 446 |   return boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[AtomPosition])->get();
 | 
|---|
| [65c323] | 447 | }
 | 
|---|
| [9e9100] | 448 | 
 | 
|---|
 | 449 | const bool QtObservedAtom::getAtomSelected() const
 | 
|---|
 | 450 | {
 | 
|---|
| [ee3fb8] | 451 |   return boost::any_cast<ObservedValue_wCallback<bool, ObservedValue_Index_t> *>(ObservedValues[AtomSelected])->get();
 | 
|---|
| [9e9100] | 452 | }
 | 
|---|
| [273c8a] | 453 | 
 | 
|---|
 | 454 | const QtObservedMolecule* const QtObservedAtom::getMoleculeRef() const
 | 
|---|
 | 455 | {
 | 
|---|
 | 456 |   return boost::any_cast<ObservedValue_wCallback<QtObservedMolecule*, ObservedValue_Index_t> *>(ObservedValues[MoleculeRef])->get();
 | 
|---|
 | 457 | }
 | 
|---|