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