[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 | #include "UIElements/Qt4/InstanceBoard/ObservedValue_UpdateAtoms.hpp"
|
---|
| 49 |
|
---|
| 50 | #include "Atom/atom.hpp"
|
---|
| 51 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
| 52 | #include "World.hpp"
|
---|
| 53 |
|
---|
| 54 | using namespace boost::assign;
|
---|
| 55 |
|
---|
| 56 | static const Observable::channels_t getAllObservedChannels()
|
---|
| 57 | {
|
---|
| 58 | Observable::channels_t channels;
|
---|
| 59 | channels +=
|
---|
| 60 | molecule::AtomInserted,
|
---|
[5a9e34] | 61 | molecule::AtomMoved,
|
---|
[494478] | 62 | molecule::AtomRemoved,
|
---|
[1b6415a] | 63 | molecule::FormulaChanged,
|
---|
[494478] | 64 | molecule::IndexChanged,
|
---|
| 65 | molecule::MoleculeNameChanged,
|
---|
[9e9100] | 66 | molecule::BoundingBoxChanged,
|
---|
| 67 | molecule::SelectionChanged;
|
---|
[494478] | 68 | return channels;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[1b6415a] | 71 | static const Observable::channels_t getAllAtomCountChannels()
|
---|
| 72 | {
|
---|
| 73 | Observable::channels_t channels;
|
---|
| 74 | channels +=
|
---|
| 75 | molecule::AtomInserted,
|
---|
| 76 | molecule::AtomRemoved;
|
---|
| 77 | return channels;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[5a9e34] | 80 | static const Observable::channels_t getAllCenterChannels()
|
---|
| 81 | {
|
---|
| 82 | Observable::channels_t channels;
|
---|
| 83 | channels +=
|
---|
| 84 | molecule::AtomInserted,
|
---|
| 85 | molecule::AtomMoved,
|
---|
| 86 | molecule::AtomRemoved;
|
---|
| 87 | return channels;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[494478] | 90 | // static instances
|
---|
[1b6415a] | 91 | const Observable::channels_t QtObservedMolecule::AtomCountChannels(getAllAtomCountChannels());
|
---|
[5a9e34] | 92 | const Observable::channels_t QtObservedMolecule::BondCountChannels(getAllAtomCountChannels());
|
---|
[494478] | 93 | const Observable::channels_t QtObservedMolecule::BoundingBoxChannels(1, molecule::BoundingBoxChanged);
|
---|
[1b6415a] | 94 | const Observable::channels_t QtObservedMolecule::FormulaStringChannels(1, molecule::FormulaChanged);
|
---|
[5a9e34] | 95 | const Observable::channels_t QtObservedMolecule::CenterChannels(getAllCenterChannels());
|
---|
[494478] | 96 | const Observable::channels_t QtObservedMolecule::IndexChannels(1, molecule::IndexChanged);
|
---|
| 97 | const Observable::channels_t QtObservedMolecule::NameChannels(1, molecule::MoleculeNameChanged);
|
---|
[5a9e34] | 98 | const Observable::channels_t QtObservedMolecule::NonHydrogenCountChannels(1, molecule::FormulaChanged);
|
---|
[9e9100] | 99 | const Observable::channels_t QtObservedMolecule::SelectedChannels(1, molecule::SelectionChanged);
|
---|
[0070aa] | 100 |
|
---|
[98c35c] | 101 | QtObservedMolecule::QtObservedMolecule(
|
---|
[62a0ee] | 102 | const moleculeId_t _id,
|
---|
| 103 | const molecule * const _mol,
|
---|
[494478] | 104 | QtObservedInstanceBoard &_board,
|
---|
[98c35c] | 105 | QWidget * _parent) :
|
---|
[0070aa] | 106 | QWidget(_parent),
|
---|
[98c35c] | 107 | Observer("QtObservedMolecule"),
|
---|
[494478] | 108 | subjectKilledCount(0),
|
---|
| 109 | AllsignedOnChannels(getAllObservedChannels().size()),
|
---|
| 110 | signedOffChannels(0),
|
---|
| 111 | owner(NULL),
|
---|
[1c0961] | 112 | oldId(_id),
|
---|
[494478] | 113 | board(_board),
|
---|
[04c3a3] | 114 | BoardIsGone(false),
|
---|
[62a0ee] | 115 | ObservedValues(QtObservedMolecule::MAX_ObservedTypes)
|
---|
[494478] | 116 | {
|
---|
[62a0ee] | 117 | boost::function<void (const atomId_t)> moleculeSubjectKilled(
|
---|
| 118 | boost::bind(&QtObservedMolecule::countValuesSubjectKilled,
|
---|
| 119 | boost::ref(*this),
|
---|
| 120 | _1));
|
---|
| 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 | {
|
---|
[04c3a3] | 128 | boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(ObservedValues[MolIndex])->noteCallBackIsGone();
|
---|
| 129 | boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(ObservedValues[AtomCount])->noteCallBackIsGone();
|
---|
| 130 | boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(ObservedValues[BondCount])->noteCallBackIsGone();
|
---|
| 131 | boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(ObservedValues[BoundingBox])->noteCallBackIsGone();
|
---|
| 132 | boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[FormulaString])->noteCallBackIsGone();
|
---|
| 133 | boost::any_cast<ObservedValue_wCallback<Vector, moleculeId_t> *>(ObservedValues[MolCenter])->noteCallBackIsGone();
|
---|
| 134 | boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[MolName])->noteCallBackIsGone();
|
---|
| 135 | boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(ObservedValues[NonHydrogenCount])->noteCallBackIsGone();
|
---|
[9e9100] | 136 | boost::any_cast<ObservedValue_wCallback<bool, moleculeId_t> *>(ObservedValues[MolSelected])->noteCallBackIsGone();
|
---|
[04c3a3] | 137 |
|
---|
[494478] | 138 | deactivateObserver();
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | void QtObservedMolecule::deactivateObserver()
|
---|
| 142 | {
|
---|
| 143 | if (owner != NULL) {
|
---|
| 144 | Observable::channels_t channels = getAllObservedChannels();
|
---|
| 145 | for (Observable::channels_t::const_iterator iter = channels.begin();
|
---|
| 146 | iter != channels.end(); ++iter)
|
---|
| 147 | owner->signOff(this, *iter);
|
---|
| 148 | owner = NULL;
|
---|
| 149 | signedOffChannels = AllsignedOnChannels;
|
---|
[04c3a3] | 150 | if (!BoardIsGone)
|
---|
| 151 | board.markObservedMoleculeAsDisconnected(getMolIndex());
|
---|
[494478] | 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | void QtObservedMolecule::activateObserver()
|
---|
| 156 | {
|
---|
| 157 | // sign on as observer (obtain non-const instance before)
|
---|
| 158 | const molecule * const _molecule = getMolecule(getMolIndex());
|
---|
| 159 | if (_molecule != NULL) {
|
---|
| 160 | Observable::channels_t channels = getAllObservedChannels();
|
---|
| 161 | owner = static_cast<const Observable *>(_molecule);
|
---|
| 162 | for (Observable::channels_t::const_iterator iter = channels.begin();
|
---|
| 163 | iter != channels.end(); ++iter)
|
---|
| 164 | owner->signOn(this, *iter);
|
---|
[04c3a3] | 165 | if (!BoardIsGone)
|
---|
| 166 | board.markObservedMoleculeAsConnected(getMolIndex());
|
---|
[494478] | 167 | } else
|
---|
| 168 | signedOffChannels = AllsignedOnChannels;
|
---|
| 169 | }
|
---|
[98c35c] | 170 |
|
---|
| 171 | void QtObservedMolecule::update(Observable *publisher)
|
---|
[494478] | 172 | {
|
---|
| 173 | ASSERT(0,
|
---|
| 174 | "QtObservedMolecule::update() - general update from unexpected source.");
|
---|
| 175 | }
|
---|
[98c35c] | 176 |
|
---|
| 177 | void QtObservedMolecule::subjectKilled(Observable *publisher)
|
---|
[494478] | 178 | {
|
---|
| 179 | ++signedOffChannels;
|
---|
| 180 |
|
---|
[62a0ee] | 181 | checkForRemoval();
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | void QtObservedMolecule::countValuesSubjectKilled(const moleculeId_t _id)
|
---|
| 185 | {
|
---|
| 186 | ASSERT( _id == getMolIndex(),
|
---|
| 187 | "QtObservedAtom::countValuesSubjectKilled() - molecule "+toString(getMolIndex())
|
---|
| 188 | +" received countValuesSubjectKilled for molecule id "+toString(_id)+".");
|
---|
| 189 |
|
---|
| 190 | ++subjectKilledCount;
|
---|
| 191 |
|
---|
| 192 | checkForRemoval();
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | void QtObservedMolecule::checkForRemoval()
|
---|
| 196 | {
|
---|
| 197 | if ((signedOffChannels == AllsignedOnChannels) && (subjectKilledCount == MAX_ObservedTypes)) {
|
---|
[494478] | 198 | // remove owner: no more signOff needed
|
---|
| 199 | owner = NULL;
|
---|
| 200 |
|
---|
[5a9e34] | 201 | emit moleculeRemoved();
|
---|
[4e6ffe] | 202 |
|
---|
| 203 | if (!BoardIsGone) {
|
---|
| 204 | board.markObservedMoleculeAsDisconnected(getMolIndex());
|
---|
| 205 | board.markObservedMoleculeForErase(getMolIndex());
|
---|
| 206 | }
|
---|
[494478] | 207 | }
|
---|
| 208 | }
|
---|
[98c35c] | 209 |
|
---|
| 210 | void QtObservedMolecule::recieveNotification(Observable *publisher, Notification_ptr notification)
|
---|
[494478] | 211 | {
|
---|
| 212 | const molecule * const _molecule = getMolecule(getMolIndex());
|
---|
| 213 | // when molecule is NULL we will soon get destroyed anyway
|
---|
| 214 | if (_molecule == NULL)
|
---|
| 215 | return;
|
---|
| 216 | if (publisher == dynamic_cast<const Observable*>(_molecule)){
|
---|
| 217 | // notification from atom
|
---|
| 218 | #ifdef LOG_OBSERVER
|
---|
| 219 | observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
|
---|
| 220 | << " received notification from molecule " << getMolIndex() << " for channel "
|
---|
| 221 | << notification->getChannelNo() << ".";
|
---|
| 222 | #endif
|
---|
| 223 | switch (notification->getChannelNo()) {
|
---|
| 224 | case molecule::AtomInserted:
|
---|
| 225 | {
|
---|
| 226 | const atomId_t _id = _molecule->lastChangedAtomId();
|
---|
[1b07b1] | 227 | QtObservedAtom::ptr _atom = board.getObservedAtom(_id);
|
---|
[1b6415a] | 228 | emit atomcountChanged();
|
---|
[1b07b1] | 229 | emit atomInserted(_atom);
|
---|
[5a9e34] | 230 | emit bondcountChanged();
|
---|
| 231 | emit boundingboxChanged();
|
---|
| 232 | emit centerChanged();
|
---|
| 233 | emit tesselationhullChanged();
|
---|
| 234 | break;
|
---|
| 235 | }
|
---|
| 236 | case molecule::AtomMoved:
|
---|
| 237 | {
|
---|
| 238 | emit boundingboxChanged();
|
---|
| 239 | emit centerChanged();
|
---|
| 240 | emit tesselationhullChanged();
|
---|
[494478] | 241 | break;
|
---|
| 242 | }
|
---|
| 243 | case molecule::AtomRemoved:
|
---|
| 244 | {
|
---|
| 245 | const atomId_t _id = _molecule->lastChangedAtomId();
|
---|
[1b6415a] | 246 | emit atomcountChanged();
|
---|
[494478] | 247 | emit atomRemoved(_id);
|
---|
[5a9e34] | 248 | emit bondcountChanged();
|
---|
| 249 | emit boundingboxChanged();
|
---|
| 250 | emit centerChanged();
|
---|
| 251 | emit tesselationhullChanged();
|
---|
[494478] | 252 | break;
|
---|
| 253 | }
|
---|
| 254 | case molecule::BoundingBoxChanged:
|
---|
| 255 | {
|
---|
| 256 | #ifdef LOG_OBSERVER
|
---|
| 257 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that bounding box has changed.";
|
---|
| 258 | #endif
|
---|
| 259 | emit tesselationhullChanged();
|
---|
| 260 | emit boundingboxChanged();
|
---|
| 261 | break;
|
---|
| 262 | }
|
---|
[1b6415a] | 263 | case molecule::FormulaChanged:
|
---|
| 264 | {
|
---|
| 265 | emit formulaChanged();
|
---|
[5a9e34] | 266 | emit nononhydrogenChanged();
|
---|
[1b6415a] | 267 | break;
|
---|
| 268 | }
|
---|
[494478] | 269 | case molecule::IndexChanged:
|
---|
| 270 | {
|
---|
| 271 | #ifdef LOG_OBSERVER
|
---|
| 272 | const atomId_t _id = _molecule->lastChangedAtomId();
|
---|
| 273 | observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+"'s index has changed.";
|
---|
| 274 | #endif
|
---|
[1c0961] | 275 | const moleculeId_t newId = getMolIndex();
|
---|
| 276 | emit indexChanged(oldId, newId);
|
---|
| 277 | oldId = newId;
|
---|
[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,
|
---|
| 321 | const boost::function<void(const moleculeId_t)> &_subjectKilled)
|
---|
| 322 | {
|
---|
| 323 | /* This is an old note from when the code was still part of cstor's initializer body.
|
---|
| 324 | * TODO: Probably does not apply anymore but has not yet been tested.
|
---|
| 325 | *
|
---|
| 326 | * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
|
---|
| 327 | * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
|
---|
| 328 | * the class has not been fully constructed yet. "This" itself seems to be working fine.
|
---|
| 329 | */
|
---|
| 330 |
|
---|
| 331 | ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
|
---|
| 332 | "QtObservedMolecule::initObservedValues() - given ObservedValues has not correct size.");
|
---|
| 333 |
|
---|
| 334 | // fill ObservedValues: index first
|
---|
| 335 | const boost::function<moleculeId_t ()> MolIndexUpdater(
|
---|
| 336 | boost::bind(&QtObservedMolecule::updateIndex));
|
---|
| 337 |
|
---|
| 338 | ObservedValue_wCallback<moleculeId_t> * const IndexObservable =
|
---|
| 339 | new ObservedValue_wCallback<moleculeId_t>(
|
---|
| 340 | _molref,
|
---|
| 341 | MolIndexUpdater,
|
---|
| 342 | "MoleculeIndex_"+toString(_molid),
|
---|
| 343 | _molid,
|
---|
| 344 | IndexChannels,
|
---|
| 345 | _subjectKilled);
|
---|
| 346 | _ObservedValues[MolIndex] = IndexObservable;
|
---|
| 347 |
|
---|
| 348 | const boost::function<const moleculeId_t ()> MolIndexGetter =
|
---|
| 349 | boost::bind(&ObservedValue_wCallback<moleculeId_t>::get,
|
---|
| 350 | IndexObservable);
|
---|
| 351 |
|
---|
| 352 | // fill ObservedValues: then all the other that need index
|
---|
[1b6415a] | 353 | const boost::function<int ()> AtomCountUpdater(
|
---|
| 354 | boost::bind(&QtObservedMolecule::updateAtomCount, MolIndexGetter));
|
---|
[5a9e34] | 355 | const boost::function<int ()> BondCountUpdater(
|
---|
| 356 | boost::bind(&QtObservedMolecule::updateBondCount, MolIndexGetter));
|
---|
| 357 | const boost::function<Vector ()> MolCenterUpdater(
|
---|
| 358 | boost::bind(&QtObservedMolecule::updateCenter, MolIndexGetter));
|
---|
[1b6415a] | 359 | const boost::function<std::string ()> MolFormulaUpdater(
|
---|
| 360 | boost::bind(&QtObservedMolecule::updateFormulaString, MolIndexGetter));
|
---|
[494478] | 361 | const boost::function<std::string ()> MolNameUpdater(
|
---|
| 362 | boost::bind(&QtObservedMolecule::updateName, MolIndexGetter));
|
---|
[5a9e34] | 363 | const boost::function<int ()> NonHydrogenCountUpdater(
|
---|
| 364 | boost::bind(&QtObservedMolecule::updateNonHydrogenCount, MolIndexGetter));
|
---|
[494478] | 365 | const boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater(
|
---|
| 366 | boost::bind(&QtObservedMolecule::updateBoundingBox, MolIndexGetter));
|
---|
[9e9100] | 367 | const boost::function<bool ()> SelectedUpdater(
|
---|
| 368 | boost::bind(&QtObservedMolecule::updateSelected, MolIndexGetter));
|
---|
[494478] | 369 |
|
---|
[1b6415a] | 370 | _ObservedValues[AtomCount] = new ObservedValue_wCallback<int, moleculeId_t>(
|
---|
[494478] | 371 | _molref,
|
---|
[1b6415a] | 372 | AtomCountUpdater,
|
---|
| 373 | "MoleculeAtomCount_"+toString(_molid),
|
---|
| 374 | AtomCountUpdater(),
|
---|
| 375 | AtomCountChannels,
|
---|
[494478] | 376 | _subjectKilled,
|
---|
| 377 | MolIndexGetter);
|
---|
[5a9e34] | 378 | _ObservedValues[BondCount] = new ObservedValue_wCallback<int, moleculeId_t>(
|
---|
| 379 | _molref,
|
---|
| 380 | BondCountUpdater,
|
---|
| 381 | "MoleculeBondCount_"+toString(_molid),
|
---|
| 382 | BondCountUpdater(),
|
---|
| 383 | BondCountChannels,
|
---|
| 384 | _subjectKilled,
|
---|
| 385 | MolIndexGetter);
|
---|
[494478] | 386 | _ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t>(
|
---|
| 387 | _molref,
|
---|
| 388 | BoundingBoxUpdater,
|
---|
| 389 | "MoleculeBoundingBox_"+toString(_molid),
|
---|
| 390 | initBoundingBox(),
|
---|
| 391 | BoundingBoxChannels,
|
---|
| 392 | _subjectKilled,
|
---|
| 393 | MolIndexGetter);
|
---|
[1b6415a] | 394 | _ObservedValues[FormulaString] = new ObservedValue_wCallback<std::string, moleculeId_t>(
|
---|
| 395 | _molref,
|
---|
| 396 | MolFormulaUpdater,
|
---|
| 397 | "MoleculeFormula_"+toString(_molid),
|
---|
| 398 | MolFormulaUpdater(),
|
---|
| 399 | FormulaStringChannels,
|
---|
| 400 | _subjectKilled,
|
---|
| 401 | MolIndexGetter);
|
---|
[5a9e34] | 402 | _ObservedValues[MolCenter] = new ObservedValue_wCallback<Vector, moleculeId_t>(
|
---|
| 403 | _molref,
|
---|
| 404 | MolCenterUpdater,
|
---|
| 405 | "MoleculeCenter_"+toString(_molid),
|
---|
| 406 | MolCenterUpdater(),
|
---|
| 407 | CenterChannels,
|
---|
| 408 | _subjectKilled,
|
---|
| 409 | MolIndexGetter);
|
---|
[1b6415a] | 410 | _ObservedValues[MolName] = new ObservedValue_wCallback<std::string, moleculeId_t>(
|
---|
| 411 | _molref,
|
---|
| 412 | MolNameUpdater,
|
---|
| 413 | "MoleculeName_"+toString(_molid),
|
---|
| 414 | MolNameUpdater(),
|
---|
| 415 | NameChannels,
|
---|
| 416 | _subjectKilled,
|
---|
| 417 | MolIndexGetter);
|
---|
[5a9e34] | 418 | _ObservedValues[NonHydrogenCount] = new ObservedValue_wCallback<int, moleculeId_t>(
|
---|
| 419 | _molref,
|
---|
| 420 | NonHydrogenCountUpdater,
|
---|
| 421 | "MoleculeNonHydrogenCount_"+toString(_molid),
|
---|
| 422 | NonHydrogenCountUpdater(),
|
---|
| 423 | NonHydrogenCountChannels,
|
---|
| 424 | _subjectKilled,
|
---|
| 425 | MolIndexGetter);
|
---|
[9e9100] | 426 | _ObservedValues[MolSelected] = new ObservedValue_wCallback<bool, moleculeId_t>(
|
---|
| 427 | _molref,
|
---|
| 428 | SelectedUpdater,
|
---|
| 429 | "MoleculeSelected_"+toString(_molid),
|
---|
| 430 | SelectedUpdater(),
|
---|
| 431 | SelectedChannels,
|
---|
| 432 | _subjectKilled,
|
---|
| 433 | MolIndexGetter);
|
---|
[494478] | 434 | }
|
---|
| 435 |
|
---|
| 436 | void QtObservedMolecule::destroyObservedValues(
|
---|
| 437 | std::vector<boost::any> &_ObservedValues)
|
---|
| 438 | {
|
---|
| 439 | delete boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(_ObservedValues[MolIndex]);
|
---|
[1b6415a] | 440 | delete boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(_ObservedValues[AtomCount]);
|
---|
[5a9e34] | 441 | delete boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(_ObservedValues[BondCount]);
|
---|
[04c3a3] | 442 | delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(_ObservedValues[BoundingBox]);
|
---|
[1b6415a] | 443 | delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[FormulaString]);
|
---|
[5a9e34] | 444 | delete boost::any_cast<ObservedValue_wCallback<Vector, moleculeId_t> *>(_ObservedValues[MolCenter]);
|
---|
[1b6415a] | 445 | delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[MolName]);
|
---|
[5a9e34] | 446 | delete boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(_ObservedValues[NonHydrogenCount]);
|
---|
[9e9100] | 447 | delete boost::any_cast<ObservedValue_wCallback<bool, moleculeId_t> *>(_ObservedValues[MolSelected]);
|
---|
[494478] | 448 | _ObservedValues.clear();
|
---|
| 449 | }
|
---|
| 450 |
|
---|
[1b6415a] | 451 | int QtObservedMolecule::updateAtomCount(
|
---|
| 452 | const boost::function<const moleculeId_t ()> &_getMolIndex)
|
---|
| 453 | {
|
---|
| 454 | const molecule * const mol = getMolecule(_getMolIndex());
|
---|
| 455 | if (mol != NULL)
|
---|
| 456 | return mol->getAtomCount();
|
---|
| 457 | else
|
---|
| 458 | return (int)0;
|
---|
| 459 | }
|
---|
| 460 |
|
---|
[5a9e34] | 461 | int QtObservedMolecule::updateBondCount(
|
---|
| 462 | const boost::function<const moleculeId_t ()> &_getMolIndex)
|
---|
| 463 | {
|
---|
| 464 | const molecule * const mol = getMolecule(_getMolIndex());
|
---|
| 465 | if (mol != NULL)
|
---|
| 466 | return mol->getBondCount();
|
---|
| 467 | else
|
---|
| 468 | return (int)0;
|
---|
| 469 | }
|
---|
| 470 |
|
---|
[494478] | 471 | molecule::BoundingBoxInfo QtObservedMolecule::updateBoundingBox(
|
---|
| 472 | const boost::function<const moleculeId_t ()> &_getMolIndex)
|
---|
| 473 | {
|
---|
| 474 | const molecule * const mol = getMolecule(_getMolIndex());
|
---|
| 475 | if (mol != NULL)
|
---|
| 476 | return mol->getBoundingBox();
|
---|
| 477 | else
|
---|
| 478 | return molecule::BoundingBoxInfo();
|
---|
| 479 | }
|
---|
| 480 |
|
---|
[1b6415a] | 481 | std::string QtObservedMolecule::updateFormulaString(
|
---|
| 482 | const boost::function<const moleculeId_t ()> &_getMolIndex)
|
---|
| 483 | {
|
---|
| 484 | const molecule * const mol = getMolecule(_getMolIndex());
|
---|
| 485 | if (mol != NULL)
|
---|
| 486 | return mol->getFormula().toString();
|
---|
| 487 | else
|
---|
| 488 | return std::string("");
|
---|
| 489 | }
|
---|
| 490 |
|
---|
[5a9e34] | 491 | Vector QtObservedMolecule::updateCenter(
|
---|
| 492 | const boost::function<const moleculeId_t ()> &_getMolIndex)
|
---|
| 493 | {
|
---|
| 494 | const molecule * const mol = getMolecule(_getMolIndex());
|
---|
| 495 | if (mol != NULL)
|
---|
| 496 | return mol->DetermineCenterOfAll();
|
---|
| 497 | else
|
---|
| 498 | return zeroVec;
|
---|
| 499 | }
|
---|
| 500 |
|
---|
[494478] | 501 | moleculeId_t QtObservedMolecule::updateIndex()
|
---|
| 502 | {
|
---|
| 503 | return const_cast<const World &>(World::getInstance()).lastChangedMolId();
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | std::string QtObservedMolecule::updateName(
|
---|
| 507 | const boost::function<const moleculeId_t ()> &_getMolIndex)
|
---|
| 508 | {
|
---|
| 509 | const molecule * const mol = getMolecule(_getMolIndex());
|
---|
| 510 | if (mol != NULL)
|
---|
| 511 | return mol->getName();
|
---|
| 512 | else
|
---|
| 513 | return std::string("");
|
---|
| 514 | }
|
---|
| 515 |
|
---|
[5a9e34] | 516 | int QtObservedMolecule::updateNonHydrogenCount(
|
---|
| 517 | const boost::function<const moleculeId_t ()> &_getMolIndex)
|
---|
| 518 | {
|
---|
| 519 | const molecule * const mol = getMolecule(_getMolIndex());
|
---|
| 520 | if (mol != NULL)
|
---|
| 521 | return mol->getNoNonHydrogen();
|
---|
| 522 | else
|
---|
| 523 | return (int)0;
|
---|
| 524 | }
|
---|
| 525 |
|
---|
[9e9100] | 526 | bool QtObservedMolecule::updateSelected(
|
---|
| 527 | const boost::function<const moleculeId_t ()> &_getMolIndex)
|
---|
| 528 | {
|
---|
| 529 | const molecule * const mol = getMolecule(_getMolIndex());
|
---|
| 530 | if (mol != NULL)
|
---|
| 531 | return mol->getSelected();
|
---|
| 532 | else
|
---|
| 533 | return false;
|
---|
| 534 | }
|
---|
| 535 |
|
---|
[3b9aa1] | 536 | const int& QtObservedMolecule::getAtomCount() const
|
---|
[1b6415a] | 537 | {
|
---|
| 538 | return boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(ObservedValues[AtomCount])->get();
|
---|
| 539 | }
|
---|
| 540 |
|
---|
[3b9aa1] | 541 | const int& QtObservedMolecule::getBondCount() const
|
---|
[5a9e34] | 542 | {
|
---|
| 543 | return boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(ObservedValues[BondCount])->get();
|
---|
| 544 | }
|
---|
| 545 |
|
---|
[3b9aa1] | 546 | const std::string& QtObservedMolecule::getMolFormula() const
|
---|
[1b6415a] | 547 | {
|
---|
| 548 | return boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[FormulaString])->get();
|
---|
| 549 | }
|
---|
| 550 |
|
---|
[3b9aa1] | 551 | const Vector& QtObservedMolecule::getMolCenter() const
|
---|
[5a9e34] | 552 | {
|
---|
| 553 | return boost::any_cast<ObservedValue_wCallback<Vector, moleculeId_t> *>(ObservedValues[MolCenter])->get();
|
---|
| 554 | }
|
---|
| 555 |
|
---|
[3b9aa1] | 556 | const moleculeId_t& QtObservedMolecule::getMolIndex() const
|
---|
[494478] | 557 | {
|
---|
| 558 | return boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(ObservedValues[MolIndex])->get();
|
---|
| 559 | }
|
---|
| 560 |
|
---|
[3b9aa1] | 561 | const std::string& QtObservedMolecule::getMolName() const
|
---|
[494478] | 562 | {
|
---|
| 563 | return boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[MolName])->get();
|
---|
| 564 | }
|
---|
| 565 |
|
---|
[3b9aa1] | 566 | const int& QtObservedMolecule::getNonHydrogenCount() const
|
---|
[5a9e34] | 567 | {
|
---|
| 568 | return boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(ObservedValues[NonHydrogenCount])->get();
|
---|
| 569 | }
|
---|
| 570 |
|
---|
[3b9aa1] | 571 | const molecule::BoundingBoxInfo& QtObservedMolecule::getBoundingBox() const
|
---|
[494478] | 572 | {
|
---|
| 573 | return boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(ObservedValues[BoundingBox])->get();
|
---|
| 574 | }
|
---|
[9e9100] | 575 |
|
---|
| 576 | const bool& QtObservedMolecule::getMolSelected() const
|
---|
| 577 | {
|
---|
| 578 | return boost::any_cast<ObservedValue_wCallback<bool, moleculeId_t> *>(ObservedValues[MolSelected])->get();
|
---|
| 579 | }
|
---|