| [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 | * QtObservedMolecule.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 "QtObservedMolecule.hpp" | 
|---|
|  | 37 |  | 
|---|
| [494478] | 38 | #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp" | 
|---|
|  | 39 |  | 
|---|
| [0070aa] | 40 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| [494478] | 41 | #include "CodePatterns/Assert.hpp" | 
|---|
|  | 42 | #include "CodePatterns/Log.hpp" | 
|---|
|  | 43 |  | 
|---|
|  | 44 | #include <boost/assign.hpp> | 
|---|
|  | 45 | #include <boost/bind.hpp> | 
|---|
|  | 46 |  | 
|---|
|  | 47 | #include "UIElements/Qt4/InstanceBoard/ObservedValue_wCallback.hpp" | 
|---|
|  | 48 |  | 
|---|
|  | 49 | #include "Atom/atom.hpp" | 
|---|
|  | 50 | #include "Descriptors/MoleculeIdDescriptor.hpp" | 
|---|
|  | 51 | #include "World.hpp" | 
|---|
|  | 52 |  | 
|---|
|  | 53 | using namespace boost::assign; | 
|---|
|  | 54 |  | 
|---|
|  | 55 | static const Observable::channels_t getAllObservedChannels() | 
|---|
|  | 56 | { | 
|---|
|  | 57 | Observable::channels_t channels; | 
|---|
|  | 58 | channels += | 
|---|
|  | 59 | molecule::AtomInserted, | 
|---|
| [5a9e34] | 60 | molecule::AtomMoved, | 
|---|
| [494478] | 61 | molecule::AtomRemoved, | 
|---|
| [1b6415a] | 62 | molecule::FormulaChanged, | 
|---|
| [494478] | 63 | molecule::IndexChanged, | 
|---|
|  | 64 | molecule::MoleculeNameChanged, | 
|---|
| [9e9100] | 65 | molecule::BoundingBoxChanged, | 
|---|
|  | 66 | molecule::SelectionChanged; | 
|---|
| [494478] | 67 | return channels; | 
|---|
|  | 68 | } | 
|---|
|  | 69 |  | 
|---|
| [1b6415a] | 70 | static const Observable::channels_t getAllAtomCountChannels() | 
|---|
|  | 71 | { | 
|---|
|  | 72 | Observable::channels_t channels; | 
|---|
|  | 73 | channels += | 
|---|
|  | 74 | molecule::AtomInserted, | 
|---|
|  | 75 | molecule::AtomRemoved; | 
|---|
|  | 76 | return channels; | 
|---|
|  | 77 | } | 
|---|
|  | 78 |  | 
|---|
| [5a9e34] | 79 | static const Observable::channels_t getAllCenterChannels() | 
|---|
|  | 80 | { | 
|---|
|  | 81 | Observable::channels_t channels; | 
|---|
|  | 82 | channels += | 
|---|
|  | 83 | molecule::AtomInserted, | 
|---|
|  | 84 | molecule::AtomMoved, | 
|---|
|  | 85 | molecule::AtomRemoved; | 
|---|
|  | 86 | return channels; | 
|---|
|  | 87 | } | 
|---|
|  | 88 |  | 
|---|
| [494478] | 89 | // static instances | 
|---|
| [1b6415a] | 90 | const Observable::channels_t QtObservedMolecule::AtomCountChannels(getAllAtomCountChannels()); | 
|---|
| [5a9e34] | 91 | const Observable::channels_t QtObservedMolecule::BondCountChannels(getAllAtomCountChannels()); | 
|---|
| [494478] | 92 | const Observable::channels_t QtObservedMolecule::BoundingBoxChannels(1, molecule::BoundingBoxChanged); | 
|---|
| [1b6415a] | 93 | const Observable::channels_t QtObservedMolecule::FormulaStringChannels(1, molecule::FormulaChanged); | 
|---|
| [5a9e34] | 94 | const Observable::channels_t QtObservedMolecule::CenterChannels(getAllCenterChannels()); | 
|---|
| [494478] | 95 | const Observable::channels_t QtObservedMolecule::IndexChannels(1, molecule::IndexChanged); | 
|---|
|  | 96 | const Observable::channels_t QtObservedMolecule::NameChannels(1, molecule::MoleculeNameChanged); | 
|---|
| [5a9e34] | 97 | const Observable::channels_t QtObservedMolecule::NonHydrogenCountChannels(1, molecule::FormulaChanged); | 
|---|
| [9e9100] | 98 | const Observable::channels_t QtObservedMolecule::SelectedChannels(1, molecule::SelectionChanged); | 
|---|
| [0070aa] | 99 |  | 
|---|
| [98c35c] | 100 | QtObservedMolecule::QtObservedMolecule( | 
|---|
| [62a0ee] | 101 | const moleculeId_t _id, | 
|---|
|  | 102 | const molecule * const _mol, | 
|---|
| [494478] | 103 | QtObservedInstanceBoard &_board, | 
|---|
| [98c35c] | 104 | QWidget * _parent) : | 
|---|
| [0070aa] | 105 | QWidget(_parent), | 
|---|
| [98c35c] | 106 | Observer("QtObservedMolecule"), | 
|---|
| [494478] | 107 | subjectKilledCount(0), | 
|---|
|  | 108 | AllsignedOnChannels(getAllObservedChannels().size()), | 
|---|
|  | 109 | signedOffChannels(0), | 
|---|
|  | 110 | owner(NULL), | 
|---|
| [08a7ecc] | 111 | index(static_cast<const ObservedValue_Index_t>(const_cast<const QtObservedMolecule * const>(this))), | 
|---|
| [494478] | 112 | board(_board), | 
|---|
| [04c3a3] | 113 | BoardIsGone(false), | 
|---|
| [62a0ee] | 114 | ObservedValues(QtObservedMolecule::MAX_ObservedTypes) | 
|---|
| [494478] | 115 | { | 
|---|
| [d48a16] | 116 | boost::function<void ()> moleculeSubjectKilled( | 
|---|
| [62a0ee] | 117 | boost::bind(&QtObservedMolecule::countValuesSubjectKilled, | 
|---|
|  | 118 | boost::ref(*this), | 
|---|
| [bf6245] | 119 | boost::bind(&QtObservedMolecule::getIndex, boost::ref(*this)))); | 
|---|
| [62a0ee] | 120 | initObservedValues(ObservedValues, _id, _mol, moleculeSubjectKilled); | 
|---|
|  | 121 |  | 
|---|
| [68418e] | 122 | // activating Observer is done by ObservedValueContainer when it's prepared | 
|---|
| [494478] | 123 | } | 
|---|
| [0070aa] | 124 |  | 
|---|
|  | 125 | QtObservedMolecule::~QtObservedMolecule() | 
|---|
| [494478] | 126 | { | 
|---|
| [bf6245] | 127 | boost::any_cast<ObservedValue_wCallback<moleculeId_t, ObservedValue_Index_t> *>(ObservedValues[MolIndex])->noteCallBackIsGone(); | 
|---|
|  | 128 | boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(ObservedValues[AtomCount])->noteCallBackIsGone(); | 
|---|
|  | 129 | boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(ObservedValues[BondCount])->noteCallBackIsGone(); | 
|---|
|  | 130 | boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, ObservedValue_Index_t> *>(ObservedValues[BoundingBox])->noteCallBackIsGone(); | 
|---|
|  | 131 | boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(ObservedValues[FormulaString])->noteCallBackIsGone(); | 
|---|
|  | 132 | boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[MolCenter])->noteCallBackIsGone(); | 
|---|
|  | 133 | boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(ObservedValues[MolName])->noteCallBackIsGone(); | 
|---|
|  | 134 | boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(ObservedValues[NonHydrogenCount])->noteCallBackIsGone(); | 
|---|
|  | 135 | boost::any_cast<ObservedValue_wCallback<bool, ObservedValue_Index_t> *>(ObservedValues[MolSelected])->noteCallBackIsGone(); | 
|---|
| [04c3a3] | 136 |  | 
|---|
| [494478] | 137 | deactivateObserver(); | 
|---|
| [c44763] | 138 |  | 
|---|
|  | 139 | destroyObservedValues(ObservedValues); | 
|---|
| [494478] | 140 | } | 
|---|
|  | 141 |  | 
|---|
|  | 142 | void QtObservedMolecule::deactivateObserver() | 
|---|
|  | 143 | { | 
|---|
|  | 144 | if (owner != NULL) { | 
|---|
|  | 145 | Observable::channels_t channels = getAllObservedChannels(); | 
|---|
|  | 146 | for (Observable::channels_t::const_iterator iter = channels.begin(); | 
|---|
|  | 147 | iter != channels.end(); ++iter) | 
|---|
|  | 148 | owner->signOff(this, *iter); | 
|---|
|  | 149 | owner = NULL; | 
|---|
|  | 150 | signedOffChannels = AllsignedOnChannels; | 
|---|
| [04c3a3] | 151 | if (!BoardIsGone) | 
|---|
| [59eabc] | 152 | board.markObservedMoleculeAsDisconnected(getIndex()); | 
|---|
| [494478] | 153 | } | 
|---|
|  | 154 | } | 
|---|
|  | 155 |  | 
|---|
|  | 156 | void QtObservedMolecule::activateObserver() | 
|---|
|  | 157 | { | 
|---|
|  | 158 | // sign on as observer (obtain non-const instance before) | 
|---|
|  | 159 | const molecule * const _molecule = getMolecule(getMolIndex()); | 
|---|
|  | 160 | if (_molecule != NULL) { | 
|---|
|  | 161 | Observable::channels_t channels = getAllObservedChannels(); | 
|---|
|  | 162 | owner = static_cast<const Observable *>(_molecule); | 
|---|
|  | 163 | for (Observable::channels_t::const_iterator iter = channels.begin(); | 
|---|
|  | 164 | iter != channels.end(); ++iter) | 
|---|
|  | 165 | owner->signOn(this, *iter); | 
|---|
| [04c3a3] | 166 | if (!BoardIsGone) | 
|---|
| [59eabc] | 167 | board.markObservedMoleculeAsConnected(getIndex()); | 
|---|
| [494478] | 168 | } else | 
|---|
|  | 169 | signedOffChannels = AllsignedOnChannels; | 
|---|
|  | 170 | } | 
|---|
| [98c35c] | 171 |  | 
|---|
|  | 172 | void QtObservedMolecule::update(Observable *publisher) | 
|---|
| [494478] | 173 | { | 
|---|
|  | 174 | ASSERT(0, | 
|---|
|  | 175 | "QtObservedMolecule::update() - general update from unexpected source."); | 
|---|
|  | 176 | } | 
|---|
| [98c35c] | 177 |  | 
|---|
|  | 178 | void QtObservedMolecule::subjectKilled(Observable *publisher) | 
|---|
| [494478] | 179 | { | 
|---|
|  | 180 | ++signedOffChannels; | 
|---|
|  | 181 |  | 
|---|
| [bf6245] | 182 | checkForRemoval(getIndex()); | 
|---|
| [62a0ee] | 183 | } | 
|---|
|  | 184 |  | 
|---|
| [bf6245] | 185 | void QtObservedMolecule::countValuesSubjectKilled(ObservedValue_Index_t _id) | 
|---|
| [62a0ee] | 186 | { | 
|---|
| [bf6245] | 187 | ASSERT( _id == getIndex(), | 
|---|
|  | 188 | "QtObservedAtom::countValuesSubjectKilled() - molecule "+toString(getIndex()) | 
|---|
| [62a0ee] | 189 | +" received countValuesSubjectKilled for molecule id "+toString(_id)+"."); | 
|---|
|  | 190 |  | 
|---|
|  | 191 | ++subjectKilledCount; | 
|---|
|  | 192 |  | 
|---|
| [bf6245] | 193 | checkForRemoval(_id); | 
|---|
| [62a0ee] | 194 | } | 
|---|
|  | 195 |  | 
|---|
| [bf6245] | 196 | void QtObservedMolecule::checkForRemoval(ObservedValue_Index_t _id) | 
|---|
| [62a0ee] | 197 | { | 
|---|
|  | 198 | if ((signedOffChannels == AllsignedOnChannels) && (subjectKilledCount == MAX_ObservedTypes)) { | 
|---|
| [494478] | 199 | // remove owner: no more signOff needed | 
|---|
|  | 200 | owner = NULL; | 
|---|
|  | 201 |  | 
|---|
| [5a9e34] | 202 | emit moleculeRemoved(); | 
|---|
| [4e6ffe] | 203 |  | 
|---|
|  | 204 | if (!BoardIsGone) { | 
|---|
| [bf6245] | 205 | board.markObservedMoleculeAsDisconnected(_id); | 
|---|
|  | 206 | board.markObservedMoleculeForErase(_id); | 
|---|
| [4e6ffe] | 207 | } | 
|---|
| [494478] | 208 | } | 
|---|
|  | 209 | } | 
|---|
| [98c35c] | 210 |  | 
|---|
|  | 211 | void QtObservedMolecule::recieveNotification(Observable *publisher, Notification_ptr notification) | 
|---|
| [494478] | 212 | { | 
|---|
|  | 213 | const molecule * const _molecule = getMolecule(getMolIndex()); | 
|---|
|  | 214 | // when molecule is NULL we will soon get destroyed anyway | 
|---|
|  | 215 | if (_molecule == NULL) | 
|---|
|  | 216 | return; | 
|---|
|  | 217 | if (publisher == dynamic_cast<const Observable*>(_molecule)){ | 
|---|
|  | 218 | // notification from atom | 
|---|
|  | 219 | #ifdef LOG_OBSERVER | 
|---|
|  | 220 | observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this)) | 
|---|
|  | 221 | << " received notification from molecule " << getMolIndex() << " for channel " | 
|---|
|  | 222 | << notification->getChannelNo() << "."; | 
|---|
|  | 223 | #endif | 
|---|
|  | 224 | switch (notification->getChannelNo()) { | 
|---|
|  | 225 | case molecule::AtomInserted: | 
|---|
|  | 226 | { | 
|---|
|  | 227 | const atomId_t _id = _molecule->lastChangedAtomId(); | 
|---|
| [1b07b1] | 228 | QtObservedAtom::ptr _atom = board.getObservedAtom(_id); | 
|---|
| [1b6415a] | 229 | emit atomcountChanged(); | 
|---|
| [96e145] | 230 | emit atomInserted(_atom, this); | 
|---|
| [5a9e34] | 231 | emit bondcountChanged(); | 
|---|
|  | 232 | emit boundingboxChanged(); | 
|---|
|  | 233 | emit centerChanged(); | 
|---|
|  | 234 | emit tesselationhullChanged(); | 
|---|
|  | 235 | break; | 
|---|
|  | 236 | } | 
|---|
|  | 237 | case molecule::AtomMoved: | 
|---|
|  | 238 | { | 
|---|
|  | 239 | emit boundingboxChanged(); | 
|---|
|  | 240 | emit centerChanged(); | 
|---|
|  | 241 | emit tesselationhullChanged(); | 
|---|
| [494478] | 242 | break; | 
|---|
|  | 243 | } | 
|---|
|  | 244 | case molecule::AtomRemoved: | 
|---|
|  | 245 | { | 
|---|
|  | 246 | const atomId_t _id = _molecule->lastChangedAtomId(); | 
|---|
| [f91ef6] | 247 | QtObservedAtom::ptr _atom = board.getObservedAtom(_id); | 
|---|
| [1b6415a] | 248 | emit atomcountChanged(); | 
|---|
| [f91ef6] | 249 | emit atomRemoved(_atom->getIndex(), this); | 
|---|
| [5a9e34] | 250 | emit bondcountChanged(); | 
|---|
|  | 251 | emit boundingboxChanged(); | 
|---|
|  | 252 | emit centerChanged(); | 
|---|
|  | 253 | emit tesselationhullChanged(); | 
|---|
| [494478] | 254 | break; | 
|---|
|  | 255 | } | 
|---|
|  | 256 | case molecule::BoundingBoxChanged: | 
|---|
|  | 257 | { | 
|---|
|  | 258 | #ifdef LOG_OBSERVER | 
|---|
|  | 259 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that bounding box has changed."; | 
|---|
|  | 260 | #endif | 
|---|
|  | 261 | emit tesselationhullChanged(); | 
|---|
|  | 262 | emit boundingboxChanged(); | 
|---|
|  | 263 | break; | 
|---|
|  | 264 | } | 
|---|
| [1b6415a] | 265 | case molecule::FormulaChanged: | 
|---|
|  | 266 | { | 
|---|
|  | 267 | emit formulaChanged(); | 
|---|
| [5a9e34] | 268 | emit nononhydrogenChanged(); | 
|---|
| [1b6415a] | 269 | break; | 
|---|
|  | 270 | } | 
|---|
| [494478] | 271 | case molecule::IndexChanged: | 
|---|
|  | 272 | { | 
|---|
|  | 273 | #ifdef LOG_OBSERVER | 
|---|
|  | 274 | const atomId_t _id = _molecule->lastChangedAtomId(); | 
|---|
|  | 275 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+"'s index has changed."; | 
|---|
|  | 276 | #endif | 
|---|
| [522c45] | 277 | emit indexChanged(); | 
|---|
| [494478] | 278 | break; | 
|---|
|  | 279 | } | 
|---|
|  | 280 | case molecule::MoleculeNameChanged: | 
|---|
|  | 281 | { | 
|---|
|  | 282 | #ifdef LOG_OBSERVER | 
|---|
|  | 283 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that name has changed."; | 
|---|
|  | 284 | #endif | 
|---|
|  | 285 | emit nameChanged(); | 
|---|
|  | 286 | break; | 
|---|
|  | 287 | } | 
|---|
| [9e9100] | 288 | case molecule::SelectionChanged: | 
|---|
|  | 289 | { | 
|---|
|  | 290 | #ifdef LOG_OBSERVER | 
|---|
|  | 291 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that selected has changed."; | 
|---|
|  | 292 | #endif | 
|---|
|  | 293 | emit selectedChanged(); | 
|---|
|  | 294 | break; | 
|---|
|  | 295 | } | 
|---|
| [494478] | 296 | default: | 
|---|
|  | 297 | break; | 
|---|
|  | 298 | } | 
|---|
|  | 299 | } | 
|---|
|  | 300 | } | 
|---|
|  | 301 |  | 
|---|
|  | 302 | const molecule * const QtObservedMolecule::getMolecule(const moleculeId_t _id) | 
|---|
|  | 303 | { | 
|---|
|  | 304 | const molecule * const mol = const_cast<const World &>(World::getInstance()). | 
|---|
|  | 305 | getMolecule(MoleculeById(_id)); | 
|---|
|  | 306 | return mol; | 
|---|
|  | 307 | } | 
|---|
|  | 308 |  | 
|---|
|  | 309 | static molecule::BoundingBoxInfo initBoundingBox() | 
|---|
|  | 310 | { | 
|---|
|  | 311 | molecule::BoundingBoxInfo info; | 
|---|
|  | 312 | info.position = zeroVec; | 
|---|
|  | 313 | info.radius = 0.; | 
|---|
|  | 314 | return info; | 
|---|
|  | 315 | } | 
|---|
|  | 316 |  | 
|---|
|  | 317 | void QtObservedMolecule::initObservedValues( | 
|---|
|  | 318 | ObservedValues_t &_ObservedValues, | 
|---|
|  | 319 | const moleculeId_t _molid, | 
|---|
|  | 320 | const molecule * const _molref, | 
|---|
| [d48a16] | 321 | const boost::function<void()> &_subjectKilled) | 
|---|
| [494478] | 322 | { | 
|---|
|  | 323 | ASSERT( _ObservedValues.size() == MAX_ObservedTypes, | 
|---|
|  | 324 | "QtObservedMolecule::initObservedValues() - given ObservedValues has not correct size."); | 
|---|
|  | 325 |  | 
|---|
|  | 326 | // fill ObservedValues: then all the other that need index | 
|---|
| [bf6245] | 327 | const boost::function<moleculeId_t ()> MolIndexUpdater( | 
|---|
|  | 328 | boost::bind(&QtObservedMolecule::updateIndex, boost::cref(*_molref))); | 
|---|
| [1b6415a] | 329 | const boost::function<int ()> AtomCountUpdater( | 
|---|
| [f35f7e] | 330 | boost::bind(&QtObservedMolecule::updateAtomCount, boost::cref(*_molref))); | 
|---|
| [5a9e34] | 331 | const boost::function<int ()> BondCountUpdater( | 
|---|
| [f35f7e] | 332 | boost::bind(&QtObservedMolecule::updateBondCount, boost::cref(*_molref))); | 
|---|
| [5a9e34] | 333 | const boost::function<Vector ()> MolCenterUpdater( | 
|---|
| [f35f7e] | 334 | boost::bind(&QtObservedMolecule::updateCenter, boost::cref(*_molref))); | 
|---|
| [1b6415a] | 335 | const boost::function<std::string ()> MolFormulaUpdater( | 
|---|
| [f35f7e] | 336 | boost::bind(&QtObservedMolecule::updateFormulaString, boost::cref(*_molref))); | 
|---|
| [494478] | 337 | const boost::function<std::string ()> MolNameUpdater( | 
|---|
| [f35f7e] | 338 | boost::bind(&QtObservedMolecule::updateName, boost::cref(*_molref))); | 
|---|
| [5a9e34] | 339 | const boost::function<int ()> NonHydrogenCountUpdater( | 
|---|
| [f35f7e] | 340 | boost::bind(&QtObservedMolecule::updateNonHydrogenCount, boost::cref(*_molref))); | 
|---|
| [494478] | 341 | const boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater( | 
|---|
| [f35f7e] | 342 | boost::bind(&QtObservedMolecule::updateBoundingBox, boost::cref(*_molref))); | 
|---|
| [9e9100] | 343 | const boost::function<bool ()> SelectedUpdater( | 
|---|
| [f35f7e] | 344 | boost::bind(&QtObservedMolecule::updateSelected, boost::cref(*_molref))); | 
|---|
| [494478] | 345 |  | 
|---|
| [bf6245] | 346 | _ObservedValues[MolIndex] = new ObservedValue_wCallback<moleculeId_t, ObservedValue_Index_t>( | 
|---|
|  | 347 | _molref, | 
|---|
|  | 348 | MolIndexUpdater, | 
|---|
|  | 349 | "MoleculeIndex_"+toString(_molid), | 
|---|
|  | 350 | _molid, | 
|---|
|  | 351 | IndexChannels, | 
|---|
| [d48a16] | 352 | _subjectKilled); | 
|---|
| [bf6245] | 353 | _ObservedValues[AtomCount] = new ObservedValue_wCallback<int, ObservedValue_Index_t>( | 
|---|
| [494478] | 354 | _molref, | 
|---|
| [1b6415a] | 355 | AtomCountUpdater, | 
|---|
|  | 356 | "MoleculeAtomCount_"+toString(_molid), | 
|---|
|  | 357 | AtomCountUpdater(), | 
|---|
|  | 358 | AtomCountChannels, | 
|---|
| [d48a16] | 359 | _subjectKilled); | 
|---|
| [bf6245] | 360 | _ObservedValues[BondCount] = new ObservedValue_wCallback<int, ObservedValue_Index_t>( | 
|---|
| [5a9e34] | 361 | _molref, | 
|---|
|  | 362 | BondCountUpdater, | 
|---|
|  | 363 | "MoleculeBondCount_"+toString(_molid), | 
|---|
|  | 364 | BondCountUpdater(), | 
|---|
|  | 365 | BondCountChannels, | 
|---|
| [d48a16] | 366 | _subjectKilled); | 
|---|
| [bf6245] | 367 | _ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo, ObservedValue_Index_t>( | 
|---|
| [494478] | 368 | _molref, | 
|---|
|  | 369 | BoundingBoxUpdater, | 
|---|
|  | 370 | "MoleculeBoundingBox_"+toString(_molid), | 
|---|
|  | 371 | initBoundingBox(), | 
|---|
|  | 372 | BoundingBoxChannels, | 
|---|
| [d48a16] | 373 | _subjectKilled); | 
|---|
| [bf6245] | 374 | _ObservedValues[FormulaString] = new ObservedValue_wCallback<std::string, ObservedValue_Index_t>( | 
|---|
| [1b6415a] | 375 | _molref, | 
|---|
|  | 376 | MolFormulaUpdater, | 
|---|
|  | 377 | "MoleculeFormula_"+toString(_molid), | 
|---|
|  | 378 | MolFormulaUpdater(), | 
|---|
|  | 379 | FormulaStringChannels, | 
|---|
| [d48a16] | 380 | _subjectKilled); | 
|---|
| [bf6245] | 381 | _ObservedValues[MolCenter] = new ObservedValue_wCallback<Vector, ObservedValue_Index_t>( | 
|---|
| [5a9e34] | 382 | _molref, | 
|---|
|  | 383 | MolCenterUpdater, | 
|---|
|  | 384 | "MoleculeCenter_"+toString(_molid), | 
|---|
|  | 385 | MolCenterUpdater(), | 
|---|
|  | 386 | CenterChannels, | 
|---|
| [d48a16] | 387 | _subjectKilled); | 
|---|
| [bf6245] | 388 | _ObservedValues[MolName] = new ObservedValue_wCallback<std::string, ObservedValue_Index_t>( | 
|---|
| [1b6415a] | 389 | _molref, | 
|---|
|  | 390 | MolNameUpdater, | 
|---|
|  | 391 | "MoleculeName_"+toString(_molid), | 
|---|
|  | 392 | MolNameUpdater(), | 
|---|
|  | 393 | NameChannels, | 
|---|
| [d48a16] | 394 | _subjectKilled); | 
|---|
| [bf6245] | 395 | _ObservedValues[NonHydrogenCount] = new ObservedValue_wCallback<int, ObservedValue_Index_t>( | 
|---|
| [5a9e34] | 396 | _molref, | 
|---|
|  | 397 | NonHydrogenCountUpdater, | 
|---|
|  | 398 | "MoleculeNonHydrogenCount_"+toString(_molid), | 
|---|
|  | 399 | NonHydrogenCountUpdater(), | 
|---|
|  | 400 | NonHydrogenCountChannels, | 
|---|
| [d48a16] | 401 | _subjectKilled); | 
|---|
| [bf6245] | 402 | _ObservedValues[MolSelected] = new ObservedValue_wCallback<bool, ObservedValue_Index_t>( | 
|---|
| [9e9100] | 403 | _molref, | 
|---|
|  | 404 | SelectedUpdater, | 
|---|
|  | 405 | "MoleculeSelected_"+toString(_molid), | 
|---|
|  | 406 | SelectedUpdater(), | 
|---|
|  | 407 | SelectedChannels, | 
|---|
| [d48a16] | 408 | _subjectKilled); | 
|---|
| [494478] | 409 | } | 
|---|
|  | 410 |  | 
|---|
|  | 411 | void QtObservedMolecule::destroyObservedValues( | 
|---|
|  | 412 | std::vector<boost::any> &_ObservedValues) | 
|---|
|  | 413 | { | 
|---|
| [bf6245] | 414 | delete boost::any_cast<ObservedValue_wCallback<moleculeId_t, ObservedValue_Index_t> *>(_ObservedValues[MolIndex]); | 
|---|
|  | 415 | delete boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(_ObservedValues[AtomCount]); | 
|---|
|  | 416 | delete boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(_ObservedValues[BondCount]); | 
|---|
|  | 417 | delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, ObservedValue_Index_t> *>(_ObservedValues[BoundingBox]); | 
|---|
|  | 418 | delete boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(_ObservedValues[FormulaString]); | 
|---|
|  | 419 | delete boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(_ObservedValues[MolCenter]); | 
|---|
|  | 420 | delete boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(_ObservedValues[MolName]); | 
|---|
|  | 421 | delete boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(_ObservedValues[NonHydrogenCount]); | 
|---|
|  | 422 | delete boost::any_cast<ObservedValue_wCallback<bool, ObservedValue_Index_t> *>(_ObservedValues[MolSelected]); | 
|---|
| [494478] | 423 | _ObservedValues.clear(); | 
|---|
|  | 424 | } | 
|---|
|  | 425 |  | 
|---|
| [f35f7e] | 426 | #ifdef HAVE_INLINE | 
|---|
|  | 427 | inline | 
|---|
|  | 428 | #endif | 
|---|
|  | 429 | int QtObservedMolecule::updateAtomCount(const molecule &mol) | 
|---|
| [1b6415a] | 430 | { | 
|---|
| [f35f7e] | 431 | return mol.getAtomCount(); | 
|---|
| [1b6415a] | 432 | } | 
|---|
|  | 433 |  | 
|---|
| [f35f7e] | 434 | #ifdef HAVE_INLINE | 
|---|
|  | 435 | inline | 
|---|
|  | 436 | #endif | 
|---|
|  | 437 | int QtObservedMolecule::updateBondCount(const molecule &mol) | 
|---|
| [5a9e34] | 438 | { | 
|---|
| [f35f7e] | 439 | return mol.getBondCount(); | 
|---|
| [5a9e34] | 440 | } | 
|---|
|  | 441 |  | 
|---|
| [f35f7e] | 442 | #ifdef HAVE_INLINE | 
|---|
|  | 443 | inline | 
|---|
|  | 444 | #endif | 
|---|
|  | 445 | molecule::BoundingBoxInfo QtObservedMolecule::updateBoundingBox(const molecule &mol) | 
|---|
| [494478] | 446 | { | 
|---|
| [f35f7e] | 447 | return mol.getBoundingBox(); | 
|---|
| [494478] | 448 | } | 
|---|
|  | 449 |  | 
|---|
| [f35f7e] | 450 | #ifdef HAVE_INLINE | 
|---|
|  | 451 | inline | 
|---|
|  | 452 | #endif | 
|---|
|  | 453 | std::string QtObservedMolecule::updateFormulaString(const molecule &mol) | 
|---|
| [1b6415a] | 454 | { | 
|---|
| [f35f7e] | 455 | return mol.getFormula().toString(); | 
|---|
| [1b6415a] | 456 | } | 
|---|
|  | 457 |  | 
|---|
| [f35f7e] | 458 | #ifdef HAVE_INLINE | 
|---|
|  | 459 | inline | 
|---|
|  | 460 | #endif | 
|---|
|  | 461 | Vector QtObservedMolecule::updateCenter(const molecule &mol) | 
|---|
| [5a9e34] | 462 | { | 
|---|
| [f35f7e] | 463 | return mol.DetermineCenterOfAll(); | 
|---|
| [5a9e34] | 464 | } | 
|---|
|  | 465 |  | 
|---|
| [f35f7e] | 466 | #ifdef HAVE_INLINE | 
|---|
|  | 467 | inline | 
|---|
|  | 468 | #endif | 
|---|
|  | 469 | moleculeId_t QtObservedMolecule::updateIndex(const molecule &mol) | 
|---|
| [494478] | 470 | { | 
|---|
| [f35f7e] | 471 | return mol.getId(); | 
|---|
| [494478] | 472 | } | 
|---|
|  | 473 |  | 
|---|
| [f35f7e] | 474 | #ifdef HAVE_INLINE | 
|---|
|  | 475 | inline | 
|---|
|  | 476 | #endif | 
|---|
|  | 477 | std::string QtObservedMolecule::updateName(const molecule &mol) | 
|---|
| [494478] | 478 | { | 
|---|
| [f35f7e] | 479 | return mol.getName(); | 
|---|
| [494478] | 480 | } | 
|---|
|  | 481 |  | 
|---|
| [f35f7e] | 482 | #ifdef HAVE_INLINE | 
|---|
|  | 483 | inline | 
|---|
|  | 484 | #endif | 
|---|
|  | 485 | int QtObservedMolecule::updateNonHydrogenCount(const molecule &mol) | 
|---|
| [5a9e34] | 486 | { | 
|---|
| [f35f7e] | 487 | return mol.getNoNonHydrogen(); | 
|---|
| [5a9e34] | 488 | } | 
|---|
|  | 489 |  | 
|---|
| [f35f7e] | 490 | #ifdef HAVE_INLINE | 
|---|
|  | 491 | inline | 
|---|
|  | 492 | #endif | 
|---|
|  | 493 | bool QtObservedMolecule::updateSelected(const molecule &mol) | 
|---|
| [9e9100] | 494 | { | 
|---|
| [f35f7e] | 495 | return mol.getSelected(); | 
|---|
| [9e9100] | 496 | } | 
|---|
|  | 497 |  | 
|---|
| [59eabc] | 498 | ObservedValue_Index_t QtObservedMolecule::getIndex() const | 
|---|
|  | 499 | { | 
|---|
| [2560f1] | 500 | ASSERT( index != NULL, | 
|---|
| [59eabc] | 501 | "QtObservedMolecule::getIndex() - index is NULL"); | 
|---|
| [2560f1] | 502 | return index; | 
|---|
| [59eabc] | 503 | } | 
|---|
|  | 504 |  | 
|---|
| [3b9aa1] | 505 | const int& QtObservedMolecule::getAtomCount() const | 
|---|
| [1b6415a] | 506 | { | 
|---|
| [bf6245] | 507 | return boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(ObservedValues[AtomCount])->get(); | 
|---|
| [1b6415a] | 508 | } | 
|---|
|  | 509 |  | 
|---|
| [3b9aa1] | 510 | const int& QtObservedMolecule::getBondCount() const | 
|---|
| [5a9e34] | 511 | { | 
|---|
| [bf6245] | 512 | return boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(ObservedValues[BondCount])->get(); | 
|---|
| [5a9e34] | 513 | } | 
|---|
|  | 514 |  | 
|---|
| [3b9aa1] | 515 | const std::string& QtObservedMolecule::getMolFormula() const | 
|---|
| [1b6415a] | 516 | { | 
|---|
| [bf6245] | 517 | return boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(ObservedValues[FormulaString])->get(); | 
|---|
| [1b6415a] | 518 | } | 
|---|
|  | 519 |  | 
|---|
| [3b9aa1] | 520 | const Vector& QtObservedMolecule::getMolCenter() const | 
|---|
| [5a9e34] | 521 | { | 
|---|
| [bf6245] | 522 | return boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[MolCenter])->get(); | 
|---|
| [5a9e34] | 523 | } | 
|---|
|  | 524 |  | 
|---|
| [3b9aa1] | 525 | const moleculeId_t& QtObservedMolecule::getMolIndex() const | 
|---|
| [494478] | 526 | { | 
|---|
| [bf6245] | 527 | return boost::any_cast<ObservedValue_wCallback<moleculeId_t, ObservedValue_Index_t> *>(ObservedValues[MolIndex])->get(); | 
|---|
| [494478] | 528 | } | 
|---|
|  | 529 |  | 
|---|
| [3b9aa1] | 530 | const std::string& QtObservedMolecule::getMolName() const | 
|---|
| [494478] | 531 | { | 
|---|
| [bf6245] | 532 | return boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(ObservedValues[MolName])->get(); | 
|---|
| [494478] | 533 | } | 
|---|
|  | 534 |  | 
|---|
| [3b9aa1] | 535 | const int& QtObservedMolecule::getNonHydrogenCount() const | 
|---|
| [5a9e34] | 536 | { | 
|---|
| [bf6245] | 537 | return boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(ObservedValues[NonHydrogenCount])->get(); | 
|---|
| [5a9e34] | 538 | } | 
|---|
|  | 539 |  | 
|---|
| [3b9aa1] | 540 | const molecule::BoundingBoxInfo& QtObservedMolecule::getBoundingBox() const | 
|---|
| [494478] | 541 | { | 
|---|
| [bf6245] | 542 | return boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, ObservedValue_Index_t> *>(ObservedValues[BoundingBox])->get(); | 
|---|
| [494478] | 543 | } | 
|---|
| [9e9100] | 544 |  | 
|---|
|  | 545 | const bool& QtObservedMolecule::getMolSelected() const | 
|---|
|  | 546 | { | 
|---|
| [bf6245] | 547 | return boost::any_cast<ObservedValue_wCallback<bool, ObservedValue_Index_t> *>(ObservedValues[MolSelected])->get(); | 
|---|
| [9e9100] | 548 | } | 
|---|