Changeset 494478


Ignore:
Timestamp:
Feb 12, 2016, 11:15:24 PM (9 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
90821d
Parents:
65c323
git-author:
Frederik Heber <heber@…> (10/29/15 12:52:29)
git-committer:
Frederik Heber <heber@…> (02/12/16 23:15:24)
Message:

Extracted all ObservedValue functionality out of GLMoleculeObject_molecule.

  • see previous commit for explanations.
Location:
src/UIElements
Files:
13 edited
2 moved

Legend:

Unmodified
Added
Removed
  • src/UIElements/Makefile.am

    r65c323 r494478  
    147147  UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp \
    148148  UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp \
    149   UIElements/Views/Qt4/Qt3D/ObservedValue_UpdateAtoms.hpp \
    150   UIElements/Views/Qt4/Qt3D/ObservedValue_wCallback.hpp
     149  UIElements/Qt4/InstanceBoard/ObservedValue_UpdateAtoms.hpp \
     150  UIElements/Qt4/InstanceBoard/ObservedValue_wCallback.hpp
    151151
    152152QTUISOURCE = \
  • src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp

    r65c323 r494478  
    3838  ++(iter->second.second);
    3939  typename T::ptr _molecule(new T(obsvalues, board));
    40 
    41   return _molecule;
    42 }
    43 
    44 template <>
    45 typename QtObservedMolecule::ptr
    46 ObservedValuesContainer<QtObservedMolecule,moleculeId_t>::get(const moleculeId_t _id)
    47 {
    48   typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);
    49   ASSERT( iter != ObservedValues.end(),
    50       "ObservedValuesContainer::getObservedValues() - no observed values present for "
    51       +NameOfType+" "+toString(_id));
    52   const ObservedValues_t &obsvalues = iter->second.first;
    53   // increase refcount
    54   ++(iter->second.second);
    55   typename QtObservedMolecule::ptr _molecule(new QtObservedMolecule(obsvalues));
    5640
    5741  return _molecule;
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.cpp

    r65c323 r494478  
    4848#include "World.hpp"
    4949
    50 #include "UIElements/Views/Qt4/Qt3D/ObservedValue_wCallback.hpp"
     50#include "UIElements/Qt4/InstanceBoard/ObservedValue_wCallback.hpp"
    5151
    5252using namespace boost::assign;
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    r65c323 r494478  
    3636#include "QtObservedInstanceBoard.hpp"
    3737
    38 #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp"
    3938#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
     39#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
    4040
    4141#include "CodePatterns/MemDebug.hpp"
     
    134134            getMolecule(MoleculeById(_id));
    135135        if (_molecule != NULL) {
    136           ObservedValues_t ObservedValues(GLMoleculeObject_molecule::MAX_ObservedTypes);
     136          ObservedValues_t ObservedValues(QtObservedMolecule::MAX_ObservedTypes);
    137137          LOG(3, "DEBUG: InformationBoard initializes ObservedValues for molecule " << _id);
    138           GLMoleculeObject_molecule::initObservedValues(
     138          QtObservedMolecule::initObservedValues(
    139139              ObservedValues,
    140140              _id,
     
    327327  ++(iter->second);
    328328
    329   if (iter->second > GLMoleculeObject_molecule::MAX_ObservedTypes) {
     329  if (iter->second > QtObservedMolecule::MAX_ObservedTypes) {
    330330    ASSERT( moleculeObservedValues.getRefCount(_molid) == 0,
    331331        "QtObservedInstanceBoard::moleculecountsubjectKilled() - observed Values for molecule "
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp

    r65c323 r494478  
    101101  friend class GLWorldScene;
    102102  friend class GLMoleculeObject_bond;
    103   friend class GLMoleculeObject_molecule;
    104103  friend class QtObservedAtom;
     104  friend class QtObservedMolecule;
    105105
    106106  //!> indicating whether we are still signedOn to World or not
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.cpp

    r65c323 r494478  
    3636#include "QtObservedMolecule.hpp"
    3737
     38#include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
     39
    3840#include "CodePatterns/MemDebug.hpp"
     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
     54using namespace boost::assign;
     55
     56static const Observable::channels_t getAllObservedChannels()
     57{
     58  Observable::channels_t channels;
     59  channels +=
     60      molecule::AtomInserted,
     61      molecule::AtomRemoved,
     62      molecule::IndexChanged,
     63      molecule::MoleculeNameChanged,
     64      molecule::BoundingBoxChanged;
     65  return channels;
     66}
     67
     68// static instances
     69const Observable::channels_t QtObservedMolecule::BoundingBoxChannels(1, molecule::BoundingBoxChanged);
     70const Observable::channels_t QtObservedMolecule::IndexChannels(1, molecule::IndexChanged);
     71const Observable::channels_t QtObservedMolecule::NameChannels(1, molecule::MoleculeNameChanged);
    3972
    4073QtObservedMolecule::QtObservedMolecule(
    41     const ObservedValues_t &_obsvalues,
     74    const ObservedValues_t &_ObservedValues,
     75    QtObservedInstanceBoard &_board,
    4276    QWidget * _parent) :
    4377  QWidget(_parent),
    4478  Observer("QtObservedMolecule"),
    45   obsvalues(_obsvalues)
    46 {}
     79  subjectKilledCount(0),
     80  AllsignedOnChannels(getAllObservedChannels().size()),
     81  signedOffChannels(0),
     82  owner(NULL),
     83  board(_board),
     84  ObservedValues(_ObservedValues)
     85{
     86  activateObserver();
     87}
    4788
    4889QtObservedMolecule::~QtObservedMolecule()
    49 {}
     90{
     91  deactivateObserver();
     92}
     93
     94void QtObservedMolecule::deactivateObserver()
     95{
     96  if (owner != NULL) {
     97    Observable::channels_t channels = getAllObservedChannels();
     98    for (Observable::channels_t::const_iterator iter = channels.begin();
     99        iter != channels.end(); ++iter)
     100      owner->signOff(this, *iter);
     101    owner = NULL;
     102    signedOffChannels = AllsignedOnChannels;
     103  }
     104}
     105
     106void QtObservedMolecule::activateObserver()
     107{
     108  // sign on as observer (obtain non-const instance before)
     109  const molecule * const _molecule = getMolecule(getMolIndex());
     110  if (_molecule != NULL) {
     111    Observable::channels_t channels = getAllObservedChannels();
     112    owner = static_cast<const Observable *>(_molecule);
     113    for (Observable::channels_t::const_iterator iter = channels.begin();
     114        iter != channels.end(); ++iter)
     115      owner->signOn(this, *iter);
     116  } else
     117    signedOffChannels = AllsignedOnChannels;
     118}
    50119
    51120void QtObservedMolecule::update(Observable *publisher)
    52 {}
     121{
     122  ASSERT(0,
     123      "QtObservedMolecule::update() - general update from unexpected source.");
     124}
    53125
    54126void QtObservedMolecule::subjectKilled(Observable *publisher)
    55 {}
     127{
     128  ++signedOffChannels;
     129
     130  if (signedOffChannels == AllsignedOnChannels) {
     131    // remove owner: no more signOff needed
     132    owner = NULL;
     133
     134    board.moleculecountsubjectKilled(getMolIndex());
     135  }
     136}
    56137
    57138void QtObservedMolecule::recieveNotification(Observable *publisher, Notification_ptr notification)
    58 {}
     139{
     140  const molecule * const _molecule = getMolecule(getMolIndex());
     141  // when molecule is NULL we will soon get destroyed anyway
     142  if (_molecule == NULL)
     143    return;
     144  if (publisher == dynamic_cast<const Observable*>(_molecule)){
     145    // notification from atom
     146#ifdef LOG_OBSERVER
     147    observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
     148          << " received notification from molecule " << getMolIndex() << " for channel "
     149          << notification->getChannelNo() << ".";
     150#endif
     151    switch (notification->getChannelNo()) {
     152      case molecule::AtomInserted:
     153      {
     154        const atomId_t _id = _molecule->lastChangedAtomId();
     155        emit atomInserted(_id);
     156        break;
     157      }
     158      case molecule::AtomRemoved:
     159      {
     160        const atomId_t _id = _molecule->lastChangedAtomId();
     161        emit atomRemoved(_id);
     162        break;
     163      }
     164      case molecule::BoundingBoxChanged:
     165      {
     166  #ifdef LOG_OBSERVER
     167        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that bounding box has changed.";
     168  #endif
     169        emit tesselationhullChanged();
     170        emit boundingboxChanged();
     171        break;
     172      }
     173      case molecule::IndexChanged:
     174      {
     175  #ifdef LOG_OBSERVER
     176        const atomId_t _id = _molecule->lastChangedAtomId();
     177        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+"'s index has changed.";
     178  #endif
     179        emit indexChanged();
     180        break;
     181      }
     182      case molecule::MoleculeNameChanged:
     183      {
     184  #ifdef LOG_OBSERVER
     185        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that name has changed.";
     186  #endif
     187        emit nameChanged();
     188        break;
     189      }
     190      default:
     191        break;
     192    }
     193  }
     194}
     195
     196const molecule * const QtObservedMolecule::getMolecule(const moleculeId_t _id)
     197{
     198  const molecule * const mol = const_cast<const World &>(World::getInstance()).
     199      getMolecule(MoleculeById(_id));
     200  return mol;
     201}
     202
     203static molecule::BoundingBoxInfo initBoundingBox()
     204{
     205  molecule::BoundingBoxInfo info;
     206  info.position = zeroVec;
     207  info.radius = 0.;
     208  return info;
     209}
     210
     211void QtObservedMolecule::initObservedValues(
     212    ObservedValues_t &_ObservedValues,
     213    const moleculeId_t _molid,
     214    const molecule * const _molref,
     215    const boost::function<void(const moleculeId_t)> &_subjectKilled)
     216{
     217  /* This is an old note from when the code was still part of cstor's initializer body.
     218   * TODO: Probably does not apply anymore but has not yet been tested.
     219   *
     220   * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
     221   * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
     222   * the class has not been fully constructed yet. "This" itself seems to be working fine.
     223   */
     224
     225  ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
     226      "QtObservedMolecule::initObservedValues() - given ObservedValues has not correct size.");
     227
     228  // fill ObservedValues: index first
     229  const boost::function<moleculeId_t ()> MolIndexUpdater(
     230      boost::bind(&QtObservedMolecule::updateIndex));
     231
     232  ObservedValue_wCallback<moleculeId_t> * const IndexObservable =
     233      new ObservedValue_wCallback<moleculeId_t>(
     234        _molref,
     235        MolIndexUpdater,
     236        "MoleculeIndex_"+toString(_molid),
     237        _molid,
     238        IndexChannels,
     239        _subjectKilled);
     240  _ObservedValues[MolIndex] = IndexObservable;
     241
     242  const boost::function<const moleculeId_t ()> MolIndexGetter =
     243      boost::bind(&ObservedValue_wCallback<moleculeId_t>::get,
     244          IndexObservable);
     245
     246  // fill ObservedValues: then all the other that need index
     247  const boost::function<std::string ()> MolNameUpdater(
     248      boost::bind(&QtObservedMolecule::updateName, MolIndexGetter));
     249  const boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater(
     250      boost::bind(&QtObservedMolecule::updateBoundingBox, MolIndexGetter));
     251
     252  _ObservedValues[MolName] = new ObservedValue_wCallback<std::string, moleculeId_t>(
     253      _molref,
     254      MolNameUpdater,
     255      "MoleculeName_"+toString(_molid),
     256      MolNameUpdater(),
     257      NameChannels,
     258      _subjectKilled,
     259      MolIndexGetter);
     260  _ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t>(
     261      _molref,
     262      BoundingBoxUpdater,
     263      "MoleculeBoundingBox_"+toString(_molid),
     264      initBoundingBox(),
     265      BoundingBoxChannels,
     266      _subjectKilled,
     267      MolIndexGetter);
     268}
     269
     270void QtObservedMolecule::destroyObservedValues(
     271    std::vector<boost::any> &_ObservedValues)
     272{
     273  delete boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(_ObservedValues[MolIndex]);
     274  delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[MolName]);
     275  delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(_ObservedValues[BoundingBox]);
     276  _ObservedValues.clear();
     277}
     278
     279molecule::BoundingBoxInfo QtObservedMolecule::updateBoundingBox(
     280    const boost::function<const moleculeId_t ()> &_getMolIndex)
     281{
     282  const molecule * const mol = getMolecule(_getMolIndex());
     283  if (mol != NULL)
     284    return mol->getBoundingBox();
     285  else
     286    return molecule::BoundingBoxInfo();
     287}
     288
     289moleculeId_t QtObservedMolecule::updateIndex()
     290{
     291  return const_cast<const World &>(World::getInstance()).lastChangedMolId();
     292}
     293
     294std::string QtObservedMolecule::updateName(
     295    const boost::function<const moleculeId_t ()> &_getMolIndex)
     296{
     297  const molecule * const mol = getMolecule(_getMolIndex());
     298  if (mol != NULL)
     299    return mol->getName();
     300  else
     301    return std::string("");
     302}
     303
     304moleculeId_t QtObservedMolecule::getMolIndex() const
     305{
     306  return boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(ObservedValues[MolIndex])->get();
     307}
     308
     309std::string QtObservedMolecule::getMolName() const
     310{
     311  return boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[MolName])->get();
     312}
     313
     314molecule::BoundingBoxInfo QtObservedMolecule::getBoundingBox() const
     315{
     316  return boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(ObservedValues[BoundingBox])->get();
     317}
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp

    r65c323 r494478  
    1717#include <QtGui/QWidget>
    1818
     19#include <boost/function.hpp>
    1920#include <boost/shared_ptr.hpp>
    2021
     22#include "CodePatterns/Observer/Observable.hpp"
    2123#include "CodePatterns/Observer/Observer.hpp"
    2224
     25#include "molecule.hpp"
    2326#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
    2427#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
     
    4144  Q_OBJECT
    4245
     46public:
     47
     48  //!> typedef for instance wrapped in shared ptr
     49  typedef boost::shared_ptr<QtObservedMolecule> ptr;
     50
     51private:
    4352  //!> ObservedValuesContainer needs to access private cstor and dstor
    4453  friend class ObservedValuesContainer<QtObservedMolecule, moleculeId_t>;
     
    4655  friend class QtObservedInstanceBoard;
    4756
    48   //!> typedef for instance wrapped in shared ptr
    49   typedef boost::shared_ptr<QtObservedMolecule> ptr;
    50 
    5157  /** Cstor of QtObservedMolecule.
    5258   *
    53    * \param _obsvalues ref to set of observed values for this instance
     59   * \param _ObservedValues ref to set of observed values for this instance
     60   * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
    5461   * \param _parent Qt parent to automatically destroy when parent is destroyed
    5562   */
    5663  QtObservedMolecule(
    57       const ObservedValues_t &_obsvalues,
     64      const ObservedValues_t &_ObservedValues,
     65      QtObservedInstanceBoard &_board,
    5866      QWidget * _parent=0);
    5967
     
    7078  void recieveNotification(Observable *publisher, Notification_ptr notification);
    7179
     80  /** Getter to molecule index contained in \a ObservedValues.
     81   *
     82   * \return molecule's index
     83   */
     84  moleculeId_t getMolIndex() const;
     85
     86  /** Getter to molecule name contained in \a ObservedValues.
     87   *
     88   * \return molecule's name
     89   */
     90  std::string getMolName() const;
     91
     92  /** Getter to molecule's bounding box contained in \a ObservedValues.
     93   *
     94   * \return molecule's bounding box
     95   */
     96  molecule::BoundingBoxInfo getBoundingBox() const;
     97
     98  static const molecule * const getMolecule(const moleculeId_t _id);
     99
    72100signals:
    73 
    74 private slots:
    75 
     101  void indexChanged();
     102  void nameChanged();
     103  void tesselationhullChanged();
     104  void boundingboxChanged();
     105  void atomInserted(const atomId_t);
     106  void atomRemoved(const atomId_t);
    76107
    77108private:
     109
     110  void activateObserver();
     111  void deactivateObserver();
     112
     113private:
     114  static molecule::BoundingBoxInfo updateBoundingBox(
     115      const boost::function<const moleculeId_t ()> &_getMolIndex);
     116  static moleculeId_t updateIndex();
     117  static std::string updateName(
     118      const boost::function<const moleculeId_t ()> &_getMolIndex);
     119
     120  //!> list of channels when bounding box needs to update
     121  static const Observable::channels_t BoundingBoxChannels;
     122  //!> list of channels when the index needs to update
     123  static const Observable::channels_t IndexChannels;
     124  //!> list of channels when the name needs to update
     125  static const Observable::channels_t NameChannels;
     126
     127private:
     128  /** Observed Values **/
     129
     130  //!> enumeration of observed values to match with entries in ObservedValues
     131  enum ObservedTypes {
     132    //!> contains the current molecule index
     133    MolIndex,
     134    //!> contains the current molecule name
     135    MolName,
     136    //!> contains newest version of the bounding box on request
     137    BoundingBox,
     138    //!> gives the size of the enumeration
     139    MAX_ObservedTypes
     140  };
     141
     142  /** Initializes all \a _ObservedValues entries.
     143   *
     144   * \param _ObservedValues vector of ObservedValue to be filled
     145   * \param _moid molecule id
     146   * \param _molref reference to molecule
     147   * \param _subjectKilled ref to function to call on subjectKilled()
     148   */
     149  static void initObservedValues(
     150      ObservedValues_t &_ObservedValues,
     151      const moleculeId_t _molid,
     152      const molecule * const _molref,
     153      const boost::function<void(const moleculeId_t)> &_subjectKilled);
     154
     155  /** Destroys all \a ObservedValues entries.
     156   *
     157   * \param _ObservedValues vector of ObservedValue to be destroyed
     158   */
     159  static void destroyObservedValues(
     160      std::vector<boost::any> &_ObservedValues);
     161
     162  //!> counts how many ObservedValues have already been subjectKilled()
     163  mutable size_t subjectKilledCount;
     164
     165private:
     166
     167  //!> we get multiple subjectKilled(), count and call callback() only on last
     168  const unsigned int AllsignedOnChannels;
     169  unsigned int signedOffChannels;
     170
     171  //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
     172  const Observable *owner;
     173
     174private:
     175
     176  //!> reference to InstanceBoard for callbacks on subjectKilled()
     177  QtObservedInstanceBoard & board;
     178
    78179  //!> internal reference to ObservedValues held by QtObservedInstanceBoard
    79   const ObservedValues_t &obsvalues;
     180  ObservedValues_t ObservedValues;
    80181};
    81182
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp

    r65c323 r494478  
    9494  LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(newId)+".");
    9595  setObjectId(newId);
     96
     97  emit indexChanged(this, oldId, newId);
    9698}
    9799
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp

    r65c323 r494478  
    5656  void BondsAdded(const atomId_t _left, const atomId_t _right, const GLMoleculeObject_bond::SideOfBond side);
    5757  void BondsRemoved(const atomId_t _left, const atomId_t _right);
    58   void indexChanged(GLMoleculeObject_atom *ob, const atomId_t oldId, const atomId_t newId);
     58  void indexChanged(GLMoleculeObject_atom*, const atomId_t _oldid, const atomId_t _newid);
    5959
    6060private:
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp

    r65c323 r494478  
    3939#include <Qt3D/qglscenenode.h>
    4040
     41#include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
     42
    4143#include "CodePatterns/MemDebug.hpp"
    42 
    4344
    4445#include <cmath>
     
    5556#include "LinearAlgebra/Line.hpp"
    5657#include "LinearAlgebra/Vector.hpp"
    57 #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
     58#include "UIElements/Qt4/InstanceBoard/ObservedValue_wCallback.hpp"
    5859#include "World.hpp"
    59 
    60 #include "ObservedValue_wCallback.hpp"
    6160
    6261
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    r65c323 r494478  
    4040#include <Qt3D/qglbuilder.h>
    4141
     42#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp"
     43
    4244#include "CodePatterns/MemDebug.hpp"
    4345
     
    4749#include "CodePatterns/IteratorAdaptors.hpp"
    4850#include "CodePatterns/Log.hpp"
    49 #include "CodePatterns/Observer/Notification.hpp"
    50 #include "CodePatterns/Observer/ObserverLog.hpp"
    51 
    52 #include "Atom/atom.hpp"
    53 #include "molecule.hpp"
    54 #include "Descriptors/AtomIdDescriptor.hpp"
    55 #include "Descriptors/MoleculeIdDescriptor.hpp"
    56 #include "Element/element.hpp"
     51
    5752#include "LinearAlgebra/Vector.hpp"
    5853#include "LinkedCell/PointCloudAdaptor.hpp"
     
    6661#include "World.hpp"
    6762
    68 #include "ObservedValue_wCallback.hpp"
    69 #include "ObservedValue_UpdateAtoms.hpp"
    70 
    7163using namespace boost::assign;
    72 
    73 #include "GLMoleculeObject_atom.hpp"
    7464
    7565static Observable::channels_t getAllAtomicChangesChannels()
     
    8070}
    8171
    82 static Observable::channels_t getAllAtomicObservedChannels()
    83 {
    84   Observable::channels_t channels;
    85   channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
    86   return channels;
    87 }
    88 
    89 // static instances
    9072const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels());
    91 const Observable::channels_t GLMoleculeObject_molecule::BoundingBoxChannels(1, molecule::BoundingBoxChanged);
    92 const Observable::channels_t GLMoleculeObject_molecule::IndexChannels(1, molecule::IndexChanged);
    93 const Observable::channels_t GLMoleculeObject_molecule::NameChannels(1, molecule::MoleculeNameChanged);
    9473
    9574static QGLSceneNode *createMoleculeMesh(const QGeometryData &_geo)
     
    10483GLMoleculeObject_molecule::GLMoleculeObject_molecule(
    10584    QObject *parent,
    106     const moleculeId_t _molid,
    107     QtObservedInstanceBoard * _board,
    108     std::vector<boost::any> _ObservedValues) :
     85    QtObservedInstanceBoard &_board,
     86    QtObservedMolecule::ptr _ObservedMolecule) :
    10987  GLMoleculeObject((QGLSceneNode *)NULL, parent),
    110   Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)),
    11188  owner(NULL),
    112   molref(getMolecule(_molid)),
     89  molref(QtObservedMolecule::getMolecule(_ObservedMolecule->getMolIndex())),
    11390  /* We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
    11491   * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
    11592   * the class has not been fully constructed yet. "This" itself seems to be working fine.
    11693   */
    117   ObservedValues(_ObservedValues),
    118   subjectKilledCount(0),
    11994  TesselationHullUpdater(
    12095      boost::bind(&GLMoleculeObject_molecule::updateTesselationHull, this)
     
    12398      molref,
    12499      TesselationHullUpdater,
    125       "MoleculeTesselationHull_"+toString(_molid),
     100      "MoleculeTesselationHull_"+toString(_ObservedMolecule->getMolIndex()),
    126101      HullChannels),
    127102  hoverAtomId(-1),
    128   AllsignedOnChannels(getAllAtomicObservedChannels().size()),
    129   signedOnChannels(0),
    130   board(_board)
    131 {
    132   init(_molid);
     103  board(_board),
     104  ObservedMolecule(_ObservedMolecule)
     105{
     106  init(ObservedMolecule->getMolIndex());
    133107}
    134108
     
    136110    QGLSceneNode *mesh[],
    137111    QObject *parent,
    138     const moleculeId_t _molid,
    139     QtObservedInstanceBoard * _board,
    140     std::vector<boost::any> _ObservedValues) :
     112    QtObservedInstanceBoard &_board,
     113    QtObservedMolecule::ptr _ObservedMolecule) :
    141114  GLMoleculeObject(mesh, parent),
    142   Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)),
    143115  owner(NULL),
    144   molref(getMolecule(_molid)),
     116  molref(QtObservedMolecule::getMolecule(_ObservedMolecule->getMolIndex())),
    145117  /* We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
    146118   * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
    147119   * the class has not been fully constructed yet. "This" itself seems to be working fine.
    148120   */
    149   ObservedValues(_ObservedValues),
    150   subjectKilledCount(0),
    151121  TesselationHullUpdater(
    152122      boost::bind(&GLMoleculeObject_molecule::updateTesselationHull, this)
     
    155125      molref,
    156126      TesselationHullUpdater,
    157       "MoleculeTesselationHull_"+toString(_molid),
     127      "MoleculeTesselationHull_"+toString(_ObservedMolecule->getMolIndex()),
    158128      HullChannels),
    159129  hoverAtomId(-1),
    160   AllsignedOnChannels(getAllAtomicObservedChannels().size()),
    161   signedOnChannels(0),
    162   board(_board)
    163 {
    164   init(_molid);
     130  board(_board),
     131  ObservedMolecule(_ObservedMolecule)
     132{
     133  init(ObservedMolecule->getMolIndex());
    165134}
    166135
     
    175144  m_visible = false;
    176145
    177   activateObserver();
    178 
    179146  connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
    180147  connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
    181   connect (this, SIGNAL(TesselationHullChanged()), this, SLOT(resetTesselationHull()), Qt::QueuedConnection);
    182   connect (this, SIGNAL(BoundingBoxChanged()), this, SLOT(resetBoundingBox()), Qt::QueuedConnection);
    183   connect (this, SIGNAL(IdChanged()), this, SLOT(resetIndex()), Qt::QueuedConnection);
    184   connect (this, SIGNAL(AtomInserted(const atomId_t)), this, SLOT(atomInserted(const atomId_t)), Qt::QueuedConnection);
    185   connect (this, SIGNAL(AtomRemoved(const atomId_t)), this, SLOT(atomRemoved(const atomId_t)), Qt::QueuedConnection);
    186   if (board != NULL) {
    187     connect(board, SIGNAL(atomInserted(const atomId_t)),
    188         this, SLOT(atomInserted(const atomId_t)));
    189     connect(board, SIGNAL(atomRemoved(const atomId_t)),
    190         this, SLOT(atomRemoved(const atomId_t)));
    191   }
     148  connect (ObservedMolecule.get(), SIGNAL(tesselationhullChanged()), this, SLOT(resetTesselationHull()));
     149  connect (ObservedMolecule.get(), SIGNAL(boundingboxChanged()), this, SLOT(resetBoundingBox()));
     150  connect (ObservedMolecule.get(), SIGNAL(indexChanged()), this, SLOT(resetIndex()));
     151  connect (ObservedMolecule.get(), SIGNAL(atomInserted(const atomId_t)), this, SLOT(atomInserted(const atomId_t)));
     152  connect (ObservedMolecule.get(), SIGNAL(atomRemoved(const atomId_t)), this, SLOT(atomRemoved(const atomId_t)));
    192153
    193154  connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
     
    195156
    196157GLMoleculeObject_molecule::~GLMoleculeObject_molecule()
    197 {
    198   deactivateObserver();
    199   board->returnMoleculeObservedValues(getMolIndex(), ObservedValues);
    200 }
    201 
    202 void GLMoleculeObject_molecule::deactivateObserver()
    203 {
    204   if (owner != NULL) {
    205     Observable::channels_t channels = getAllAtomicObservedChannels();
    206     for (Observable::channels_t::const_iterator iter = channels.begin();
    207         iter != channels.end(); ++iter)
    208       owner->signOff(this, *iter);
    209     owner = NULL;
    210     signedOnChannels = 0;
    211   }
    212 }
    213 
    214 void GLMoleculeObject_molecule::activateObserver()
    215 {
    216   // sign on as observer (obtain non-const instance before)
    217   const molecule * const _molecule = getMolecule(getMolIndex());
    218   if (_molecule != NULL) {
    219     Observable::channels_t channels = getAllAtomicObservedChannels();
    220     owner = static_cast<const Observable *>(_molecule);
    221     for (Observable::channels_t::const_iterator iter = channels.begin();
    222         iter != channels.end(); ++iter)
    223       owner->signOn(this, *iter);
    224   } else {
    225     ELOG(1, "GLMoleculeObject_molecule() - added null object for not present mol id " << getMolIndex());
    226   }
    227 
    228 }
     158{}
    229159
    230160void GLMoleculeObject_molecule::addAtomBonds(
     
    249179  QGeometryData geo;
    250180
    251   const molecule * const molref = getMolecule(getMolIndex());
     181  const molecule * const molref =
     182      QtObservedMolecule::getMolecule(ObservedMolecule->getMolIndex());
    252183  if (molref == NULL) {
    253     ELOG(1, "Could not createMoleculeMesh, molecule with id " << getMolIndex() << " already gone.");
     184    ELOG(1, "Could not createMoleculeMesh, molecule with id "
     185        << ObservedMolecule->getMolIndex() << " already gone.");
    254186    return geo;
    255187  }
     
    273205    // Tesselate the points.
    274206    Tesselation T;
    275     PointCloudAdaptor<molecule> cloud(const_cast<molecule *>(molref), getMolName());
     207    PointCloudAdaptor<molecule> cloud(
     208        const_cast<molecule *>(molref),
     209        ObservedMolecule->getMolName());
    276210    T(cloud, minradius);
    277211
     
    320254}
    321255
    322 molecule::BoundingBoxInfo GLMoleculeObject_molecule::initBoundingBox()
    323 {
    324   molecule::BoundingBoxInfo info;
    325   info.position = zeroVec;
    326   info.radius = 0.;
    327   return info;
    328 }
    329 
    330 molecule::BoundingBoxInfo GLMoleculeObject_molecule::updateBoundingBox(
    331     const boost::function<const moleculeId_t ()> &_getMolIndex)
    332 {
    333   const molecule * const mol = getMolecule(_getMolIndex());
    334   return mol->getBoundingBox();
    335 }
    336 
    337 moleculeId_t GLMoleculeObject_molecule::updateIndex()
    338 {
    339   return const_cast<const World &>(World::getInstance()).lastChangedMolId();
    340 }
    341 
    342 std::string GLMoleculeObject_molecule::updateName(
    343     const boost::function<const moleculeId_t ()> &_getMolIndex)
    344 {
    345   const molecule * const mol = getMolecule(_getMolIndex());
    346   return mol->getName();
    347 }
    348 
    349256void GLMoleculeObject_molecule::resetTesselationHull()
    350257{
     
    356263void GLMoleculeObject_molecule::resetBoundingBox()
    357264{
    358   molecule::BoundingBoxInfo info = getBoundingBox();
     265  molecule::BoundingBoxInfo info = ObservedMolecule->getBoundingBox();
    359266  setPosition(QVector3D(info.position[0], info.position[1], info.position[2]));
    360267  setScale(info.radius + 0.3); // getBoundingSphere() only sees atoms as points, so make the box a bit bigger
     
    363270void GLMoleculeObject_molecule::resetIndex()
    364271{
    365   const atomId_t newId = getMolIndex();
     272  const atomId_t newId = ObservedMolecule->getMolIndex();
    366273  const size_t oldId = objectId();
    367274  ASSERT( newId != oldId,
     
    371278
    372279  emit indexChanged(this, oldId, newId);
    373 }
    374 
    375 void GLMoleculeObject_molecule::resetName()
    376 {
    377280}
    378281
     
    418321}
    419322
    420 void GLMoleculeObject_molecule::update(Observable *publisher)
    421 {
    422   ASSERT(0,
    423       "GLMoleculeObject_molecule::update() - general update from unexpected source.");
    424 }
    425 
    426 void GLMoleculeObject_molecule::subjectKilled(Observable *publisher)
    427 {
    428   ++signedOnChannels;
    429 
    430   if (signedOnChannels == AllsignedOnChannels) {
    431     // remove owner: no more signOff needed
    432     owner = NULL;
    433 
    434     board->moleculecountsubjectKilled(getMolIndex());
    435   }
    436 }
    437 
    438 void GLMoleculeObject_molecule::recieveNotification(Observable *publisher, Notification_ptr notification)
    439 {
    440   const molecule * const _molecule = getMolecule(getMolIndex());
    441   // when molecule is NULL we will soon get destroyed anyway
    442   if (_molecule == NULL)
    443     return;
    444   if (publisher == dynamic_cast<const Observable*>(_molecule)){
    445     // notification from atom
    446 #ifdef LOG_OBSERVER
    447     observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
    448           << " received notification from molecule " << getMolIndex() << " for channel "
    449           << notification->getChannelNo() << ".";
    450 #endif
    451     switch (notification->getChannelNo()) {
    452       case molecule::AtomInserted:
    453       case molecule::AtomRemoved:
    454       case molecule::AtomMoved:
    455       {
    456   #ifdef LOG_OBSERVER
    457         observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted.";
    458   #endif
    459         emit TesselationHullChanged();
    460         emit BoundingBoxChanged();
    461         break;
    462       }
    463       case molecule::IndexChanged:
    464       {
    465   #ifdef LOG_OBSERVER
    466         const atomId_t _id = _molecule->lastChangedAtomId();
    467         observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+"'s index has changed.";
    468   #endif
    469         emit IdChanged();
    470         break;
    471       }
    472       default:
    473         break;
    474     }
    475   }
    476 }
    477323
    478324void GLMoleculeObject_molecule::initialize(QGLView *view, QGLPainter *painter)
     
    573419          GLMoleculeObject::meshSphere,
    574420          this,
    575           board->getObservedAtom(_id));
     421          board.getObservedAtom(_id));
    576422  ASSERT( atomObject != NULL,
    577423      "GLMoleculeObject_molecule::atomInserted - could not create atom object for "+toString(_id));
     
    582428
    583429  qRegisterMetaType<atomId_t>("atomId_t");
    584   qRegisterMetaType<bond::ptr>("bond::ptr");
    585430  qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
    586431  connect (atomObject, SIGNAL(clicked(atomId_t)), this, SIGNAL(atomClicked(atomId_t)));
     
    645490    if (moleculeObject == this){
    646491      // Propagate signal.
    647       emit hoverChanged(getMolIndex(), 0);
     492      emit hoverChanged(ObservedMolecule->getMolIndex(), 0);
    648493    }
    649494  }
     
    748593void GLMoleculeObject_molecule::wasClicked()
    749594{
    750   LOG(4, "INFO: GLMoleculeObject_molecule: atom " << getMolIndex() << " has been clicked");
    751   emit moleculeClicked(getMolIndex());
     595  LOG(4, "INFO: GLMoleculeObject_molecule: atom "
     596      << ObservedMolecule->getMolIndex() << " has been clicked");
     597  emit moleculeClicked(ObservedMolecule->getMolIndex());
    752598}
    753599
     
    777623}
    778624
    779 const molecule * const GLMoleculeObject_molecule::getMolecule(const moleculeId_t _id)
    780 {
    781   const molecule * const mol = const_cast<const World &>(World::getInstance()).
    782       getMolecule(MoleculeById(_id));
    783   return mol;
    784 }
    785 
    786 void GLMoleculeObject_molecule::initObservedValues(
    787     std::vector<boost::any> &_ObservedValues,
    788     const moleculeId_t _molid,
    789     const molecule * const _molref,
    790     const boost::function<void(const moleculeId_t)> &_subjectKilled)
    791 {
    792   /* This is an old note from when the code was still part of cstor's initializer body.
    793    * TODO: Probably does not apply anymore but has not yet been tested.
    794    *
    795    * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
    796    * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
    797    * the class has not been fully constructed yet. "This" itself seems to be working fine.
    798    */
    799 
    800   ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
    801       "GLMoleculeObject_molecule::initObservedValues() - given ObservedValues has not correct size.");
    802 
    803   // fill ObservedValues: index first
    804   const boost::function<moleculeId_t ()> MolIndexUpdater(
    805       boost::bind(&GLMoleculeObject_molecule::updateIndex));
    806 
    807   ObservedValue_wCallback<moleculeId_t> * const IndexObservable =
    808       new ObservedValue_wCallback<moleculeId_t>(
    809         _molref,
    810         MolIndexUpdater,
    811         "MoleculeIndex_"+toString(_molid),
    812         _molid,
    813         IndexChannels,
    814         _subjectKilled);
    815   _ObservedValues[MolIndex] = IndexObservable;
    816 
    817   const boost::function<const moleculeId_t ()> MolIndexGetter =
    818       boost::bind(&ObservedValue_wCallback<moleculeId_t>::get,
    819           IndexObservable);
    820 
    821   // fill ObservedValues: then all the other that need index
    822   const boost::function<std::string ()> MolNameUpdater(
    823       boost::bind(&GLMoleculeObject_molecule::updateName, MolIndexGetter));
    824   const boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater(
    825       boost::bind(&GLMoleculeObject_molecule::updateBoundingBox, MolIndexGetter));
    826 
    827   _ObservedValues[MolName] = new ObservedValue_wCallback<std::string, moleculeId_t>(
    828       _molref,
    829       MolNameUpdater,
    830       "MoleculeName_"+toString(_molid),
    831       MolNameUpdater(),
    832       NameChannels,
    833       _subjectKilled,
    834       MolIndexGetter);
    835   _ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t>(
    836       _molref,
    837       BoundingBoxUpdater,
    838       "MoleculeBoundingBox_"+toString(_molid),
    839       initBoundingBox(),
    840       BoundingBoxChannels,
    841       _subjectKilled,
    842       MolIndexGetter);
    843 }
    844 
    845 void GLMoleculeObject_molecule::destroyObservedValues(
    846     std::vector<boost::any> &_ObservedValues)
    847 {
    848   delete boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(_ObservedValues[MolIndex]);
    849   delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[MolName]);
    850   delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(_ObservedValues[BoundingBox]);
    851   _ObservedValues.clear();
    852 }
    853 
    854 moleculeId_t GLMoleculeObject_molecule::getMolIndex() const
    855 {
    856   return boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(ObservedValues[MolIndex])->get();
    857 }
    858 
    859 std::string GLMoleculeObject_molecule::getMolName() const
    860 {
    861   return boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[MolName])->get();
    862 }
    863 
    864 molecule::BoundingBoxInfo GLMoleculeObject_molecule::getBoundingBox() const
    865 {
    866   return boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(ObservedValues[BoundingBox])->get();
    867 }
    868625
    869626GLMoleculeObject_molecule::atoms_t GLMoleculeObject_molecule::getPresentAtoms() const
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp

    r65c323 r494478  
    1818#include <Qt3D/qgeometrydata.h>
    1919
    20 #include <vector>
    21 #include <boost/any.hpp>
     20#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
     21
     22#include <map>
     23
    2224#include <boost/function.hpp>
    2325
    2426#include "CodePatterns/Cacheable.hpp"
    25 #include "CodePatterns/Observer/Observer.hpp"
    26 #include "CodePatterns/ObservedValue.hpp"
     27#include "CodePatterns/Observer/Observable.hpp"
    2728
    2829#include "GLMoleculeObject_bond.hpp"
    2930
    30 #include "molecule.hpp"
     31#include "types.hpp"
    3132
    3233class atom;
    3334class bond;
     35class molecule;
    3436class GLMoleculeObject_atom;
    3537class GLWorldScene;
    3638class QtObservedInstanceBoard;
    3739
    38 class GLMoleculeObject_molecule : public GLMoleculeObject, public Observer
     40class GLMoleculeObject_molecule : public GLMoleculeObject
    3941{
    4042  Q_OBJECT
     
    4244  GLMoleculeObject_molecule(
    4345      QObject *parent,
    44       const moleculeId_t molid,
    45       QtObservedInstanceBoard * _board,
    46       std::vector<boost::any> _ObservedValues);
     46      QtObservedInstanceBoard &_board,
     47      QtObservedMolecule::ptr _ObservedMolecule);
    4748  GLMoleculeObject_molecule(
    4849      QGLSceneNode *mesh[],
    4950      QObject *parent,
    50       const moleculeId_t molid,
    51       QtObservedInstanceBoard * _board,
    52       std::vector<boost::any> _ObservedValues);
     51      QtObservedInstanceBoard &_board,
     52      QtObservedMolecule::ptr _ObservedMolecule);
    5353  virtual ~GLMoleculeObject_molecule();
    54 
    55   // Observer functions
    56   void update(Observable *publisher);
    57   void subjectKilled(Observable *publisher);
    58   void recieveNotification(Observable *publisher, Notification_ptr notification);
    5954
    6055  void initialize(QGLView *view, QGLPainter *painter);
     
    7671  void atomClicked(atomId_t no);
    7772  void moleculeClicked(moleculeId_t no);
    78   void TesselationHullChanged();
    79   void BoundingBoxChanged();
    8073  void IsSelectedChanged();
    81   void AtomInserted(const atomId_t _id);
    82   void AtomRemoved(const atomId_t _id);
    83   void IdChanged();
    8474
    8575private slots:
     
    9787  void setVisible(bool value);
    9888
    99   void activateObserver();
    100   void deactivateObserver();
    101 
    10289  void resetTesselationHull();
    10390  void resetBoundingBox();
    10491  void resetIndex();
    105   void resetName();
    10692
    10793  void AtomSelected(const atomId_t _id);
     
    11197
    11298private:
    113   static const molecule * const getMolecule(const moleculeId_t _id);
    114 
    115   void init(const moleculeId_t _molid);
    116 
    117 private:
    11899  void addAtomBonds(
    119100      const bond::ptr &_bond,
     
    121102      );
    122103
     104  void init(const moleculeId_t _molid);
     105
    123106  //!> typedef for the internal set of atoms
    124107  typedef std::set<atomId_t> atoms_t;
    125 
    126   static molecule::BoundingBoxInfo initBoundingBox();
    127 
    128   QGeometryData updateTesselationHull() const;
    129   static molecule::BoundingBoxInfo updateBoundingBox(
    130       const boost::function<const moleculeId_t ()> &_getMolIndex);
    131   static moleculeId_t updateIndex();
    132   static std::string updateName(
    133       const boost::function<const moleculeId_t ()> &_getMolIndex);
    134108
    135109  /** Getter to contained atoms contained in \a ObservedValues.
     
    139113  atoms_t getPresentAtoms() const;
    140114
     115private:
     116
    141117  //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
    142118  const Observable * owner;
    143119
    144   //!> internal variable for caching molecule ref in cstor
    145   const molecule * const molref;
     120  QGeometryData updateTesselationHull() const;
    146121
    147122  //!> list of channels when tesselation hull needs to update
    148123  static const Observable::channels_t HullChannels;
    149   //!> list of channels when bounding box needs to update
    150   static const Observable::channels_t BoundingBoxChannels;
    151   //!> list of channels when the index needs to update
    152   static const Observable::channels_t IndexChannels;
    153   //!> list of channels when the name needs to update
    154   static const Observable::channels_t NameChannels;
    155124
    156 private:
    157   friend class QtObservedInstanceBoard;
    158   /** Observed Values **/
    159 
    160   //!> enumeration of observed values to match with entries in ObservedValues
    161   enum ObservedTypes {
    162     //!> contains the current molecule index
    163     MolIndex,
    164     //!> contains the current molecule name
    165     MolName,
    166     //!> contains newest version of the bounding box on request
    167     BoundingBox,
    168     //!> gives the size of the enumeration
    169     MAX_ObservedTypes
    170   };
    171 
    172   //!> vector with all observed values
    173   std::vector<boost::any> ObservedValues;
    174 
    175   /** Initializes all \a _ObservedValues entries.
    176    *
    177    * \param _ObservedValues vector of ObservedValue to be filled
    178    * \param _moid molecule id
    179    * \param _molref reference to molecule
    180    * \param _subjectKilled ref to function to call on subjectKilled()
    181    */
    182   static void initObservedValues(
    183       std::vector<boost::any> &_ObservedValues,
    184       const moleculeId_t _molid,
    185       const molecule * const _molref,
    186       const boost::function<void(const moleculeId_t)> &_subjectKilled);
    187 
    188   /** Destroys all \a ObservedValues entries.
    189    *
    190    * \param _ObservedValues vector of ObservedValue to be destroyed
    191    */
    192   static void destroyObservedValues(
    193       std::vector<boost::any> &_ObservedValues);
    194 
    195   /** Getter to molecule index contained in \a ObservedValues.
    196    *
    197    * \return molecule's index
    198    */
    199   moleculeId_t getMolIndex() const;
    200 
    201   /** Getter to molecule name contained in \a ObservedValues.
    202    *
    203    * \return molecule's name
    204    */
    205   std::string getMolName() const;
    206 
    207   /** Getter to molecule's bounding box contained in \a ObservedValues.
    208    *
    209    * \return molecule's bounding box
    210    */
    211   molecule::BoundingBoxInfo getBoundingBox() const;
    212 
    213   //!> counts how many ObservedValues have already been subjectKilled()
    214   mutable size_t subjectKilledCount;
    215 
    216 private:
     125  //!> internal variable for caching molecule ref in cstor
     126  const molecule * const molref;
    217127
    218128  boost::function<QGeometryData ()> TesselationHullUpdater;
     
    231141  atomId_t hoverAtomId;
    232142
    233   //!> we get multiple subjectKilled(), count and call callback() only on last
    234   const unsigned int AllsignedOnChannels;
    235   unsigned int signedOnChannels;
     143  QtObservedInstanceBoard &board;
    236144
    237   QtObservedInstanceBoard * board;
     145  QtObservedMolecule::ptr ObservedMolecule;
    238146};
    239147
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    r65c323 r494478  
    166166  MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid);
    167167  if (moliter != MoleculesinSceneMap.end()) {
    168     // pass signal through
    169     GLMoleculeObject_molecule *molObject = moliter->second;
    170     QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    171                               "atomInserted",       // member name (no parameters here)
    172                               Qt::QueuedConnection,     // connection type
    173                               Q_ARG(const atomId_t, _atomid));     // parameters
     168    // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
    174169  } else {
    175170    // store signal for when it is instantiated
     
    194189  MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid);
    195190  if (moliter != MoleculesinSceneMap.end()) {
    196     // pass signal through
    197     GLMoleculeObject_molecule *molObject = moliter->second;
    198     QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    199                               "atomRemoved",       // member name (no parameters here)
    200                               Qt::QueuedConnection,     // connection type
    201                               Q_ARG(const atomId_t, _atomid));     // parameters
     191    // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
    202192  } else {
    203193    // store signal for when it is instantiated
     
    238228          GLMoleculeObject::meshEmpty,
    239229          this,
    240           _id,
    241           board,
    242           board->getMoleculeObservedValues(_id));
     230          *board,
     231          board->getObservedMolecule(_id));
    243232  ASSERT( molObject != NULL,
    244233      "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(_id));
Note: See TracChangeset for help on using the changeset viewer.