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