Ignore:
Timestamp:
Feb 12, 2016, 11:15:06 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:
15c8a9
Parents:
099f67
git-author:
Frederik Heber <heber@…> (01/25/16 11:01:10)
git-committer:
Frederik Heber <heber@…> (02/12/16 23:15:06)
Message:

Changed GLMoleculeObject_...:countSubjectKilled() to taking id parameter.

  • this is a precursor for when the ObservedValues reside with QtInstanceInformationBoard.
  • enhanced ObservedValue_wCallback to take a bound getIndex function().
  • additionally, we route internally to ObservedValue::get() and this gets us out of the painful situation where we need to supply an index getter to the ObservedValue that monitors the index (and hence must be present already to bind to its get function).
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp

    r099f67 r026bef  
    7878GLMoleculeObject_atom::AtomBondsChannels(getAtomBondsChannels());
    7979
    80 GLMoleculeObject_atom::GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atomId_t _id) :
     80GLMoleculeObject_atom::GLMoleculeObject_atom(
     81    QGLSceneNode *mesh[],
     82    QObject *parent,
     83    const atomId_t _id) :
    8184  GLMoleculeObject(mesh, parent),
    8285  Observer(std::string("GLMoleculeObject_atom")+toString(_id)),
     
    8689  owner(NULL)
    8790{
    88   boost::function<void()> subjectKilled =
    89       boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this);
     91  boost::function<void(const atomId_t)> subjectKilled =
     92      boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this, _id);
    9093  initObservedValues(ObservedValues, _id, atomref, subjectKilled);
    9194
     95  init(_id);
     96}
     97
     98GLMoleculeObject_atom::GLMoleculeObject_atom(
     99    QGLSceneNode *mesh[],
     100    QObject *parent,
     101    const atomId_t _id,
     102    std::vector<boost::any> _ObservedValues) :
     103  GLMoleculeObject(mesh, parent),
     104  Observer(std::string("GLMoleculeObject_atom")+toString(_id)),
     105  atomref(getAtom(_id)),
     106  ObservedValues(_ObservedValues),
     107  subjectKilledCount(0),
     108  owner(NULL)
     109{
     110  init(_id);
     111}
     112
     113void GLMoleculeObject_atom::init(const atomId_t _id)
     114{
    92115  setObjectId(_id);
    93116  resetPosition();
     
    317340  deactivateObserver();
    318341
    319   countsubjectKilled();
     342  countsubjectKilled(getAtomIndex());
    320343}
    321344
     
    348371}
    349372
    350 void GLMoleculeObject_atom::countsubjectKilled()
     373void GLMoleculeObject_atom::countsubjectKilled(const atomId_t)
    351374{
    352375  ++subjectKilledCount;
     
    360383    const atomId_t _id,
    361384    const atom * const _atomref,
    362     const boost::function<void()> &_subjectKilled)
     385    const boost::function<void(const atomId_t)> &_subjectKilled)
    363386{
    364387  /* This is an old note from when the code was still part of cstor's initializer body.
     
    399422      boost::bind(&GLMoleculeObject_atom::updateBonds, AtomIndexGetter));
    400423
    401   _ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector>(
     424  _ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector, atomId_t>(
    402425      _atomref,
    403426      AtomPositionUpdater,
     
    405428      AtomPositionUpdater(),
    406429      AtomPositionChannels,
    407       _subjectKilled);
    408   _ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t>(
     430      _subjectKilled,
     431      AtomIndexGetter);
     432  _ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t, atomId_t>(
    409433      _atomref,
    410434      AtomElementUpdater,
     
    412436      AtomElementUpdater(),
    413437      AtomElementChannels,
    414       _subjectKilled);
    415   _ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t>(
     438      _subjectKilled,
     439      AtomIndexGetter);
     440  _ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t, atomId_t>(
    416441      _atomref,
    417442      AtomBondsUpdater,
     
    419444      AtomBondsUpdater(),
    420445      AtomBondsChannels,
    421       _subjectKilled);
     446      _subjectKilled,
     447      AtomIndexGetter);
    422448}
    423449
     
    426452{
    427453  delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[AtomIndex]);
    428   delete boost::any_cast<ObservedValue_wCallback<Vector> *>(_ObservedValues[AtomPosition]);
    429   delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(_ObservedValues[AtomElement]);
    430   delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(_ObservedValues[AtomBonds]);
     454  delete boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(_ObservedValues[AtomPosition]);
     455  delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(_ObservedValues[AtomElement]);
     456  delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, atomId_t> *>(_ObservedValues[AtomBonds]);
    431457  _ObservedValues.clear();
    432458}
     
    439465Vector GLMoleculeObject_atom::getAtomPosition() const
    440466{
    441   return boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[AtomPosition])->get();
     467  return boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(ObservedValues[AtomPosition])->get();
    442468}
    443469
    444470atomicNumber_t GLMoleculeObject_atom::getAtomElement() const
    445471{
    446   return boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[AtomElement])->get();
     472  return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(ObservedValues[AtomElement])->get();
    447473}
    448474
    449475GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::getAtomBonds() const
    450476{
    451   return boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(ObservedValues[AtomBonds])->get();
    452 }
     477  return boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, atomId_t> *>(ObservedValues[AtomBonds])->get();
     478}
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp

    r099f67 r026bef  
    3434  Q_OBJECT
    3535public:
    36   GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atomId_t id);
     36  GLMoleculeObject_atom(
     37      QGLSceneNode *mesh[],
     38      QObject *parent,
     39      const atomId_t id
     40      );
     41  GLMoleculeObject_atom(
     42      QGLSceneNode *mesh[],
     43      QObject *parent,
     44      const atomId_t id,
     45      std::vector<boost::any> _ObservedValues
     46      );
    3747  virtual ~GLMoleculeObject_atom();
    3848
     
    8696  void activateObserver();
    8797  void deactivateObserver();
     98
     99  void init(const atomId_t _id);
    88100
    89101private:
     
    126138      const atomId_t _id,
    127139      const atom * const _atomref,
    128       const boost::function<void()> &_subjectKilled);
     140      const boost::function<void(const atomId_t)> &_subjectKilled);
    129141
    130142  /** Destroys all \a ObservedValues entries.
     
    165177   * monitored Observable. Only then can we safely remove the instance.
    166178   *
    167    */
    168   void countsubjectKilled();
     179   * \param _atomid id of atom who signalled subjectKilled()
     180   */
     181  void countsubjectKilled(const atomId_t _atomid);
    169182
    170183  //!> counts how many ObservedValues have already been subjectKilled()
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp

    r099f67 r026bef  
    8989  rightobservable_enabled(false)
    9090{
    91   boost::function<void()> subjectKilled =
    92       boost::bind(&GLMoleculeObject_bond::countsubjectKilled, this);
    93   initObservedValues(ObservedValues, bondIds.first, bondIds.second, leftowner, rightowner, bondowner, subjectKilled);
    94 
     91  boost::function<void(const atomId_t &)> leftsubjectKilled =
     92      boost::bind(
     93          static_cast<void (GLMoleculeObject_bond::*) (const atomId_t &)>(
     94              &GLMoleculeObject_bond::countsubjectKilled),
     95          this, _1);
     96  boost::function<void(const atomId_t &)> rightsubjectKilled =
     97      boost::bind(
     98          static_cast<void (GLMoleculeObject_bond::*) (const atomId_t &)>(
     99              &GLMoleculeObject_bond::countsubjectKilled)
     100              , this, _1);
     101  boost::function<void(const bondIds_t &)> bondsubjectKilled =
     102      boost::bind(
     103          static_cast<void (GLMoleculeObject_bond::*) (const bondIds_t &)>(
     104              &GLMoleculeObject_bond::countsubjectKilled)
     105              , this, _1);
     106  initObservedValues(
     107      ObservedValues,
     108      bondIds.first,
     109      bondIds.second,
     110      leftowner,
     111      rightowner,
     112      bondowner,
     113      leftsubjectKilled,
     114      rightsubjectKilled,
     115      bondsubjectKilled);
     116
     117  init();
     118}
     119
     120GLMoleculeObject_bond::GLMoleculeObject_bond(
     121    QGLSceneNode *mesh[],
     122    QObject *parent,
     123    const bondIds_t bondIds,
     124    const enum SideOfBond side,
     125    std::vector<boost::any> &_ObservedValues) :
     126  GLMoleculeObject(mesh, parent),
     127  Observer(std::string("GLMoleculeObject_bond")
     128      +toString(bondIds.first)
     129      +std::string("-")
     130      +toString(bondIds.second)),
     131  leftowner(getAtomConst(bondIds.first)),
     132  rightowner(getAtomConst(bondIds.second)),
     133  bondowner(getAtomConst(bondIds.first)->getBond(getAtomConst(bondIds.second)).get()),
     134  BondSide(side),
     135  ObservedValues(_ObservedValues),
     136  subjectKilledCount(0),
     137  leftobservable_enabled(false),
     138  rightobservable_enabled(false)
     139{
     140  init();
     141}
     142
     143void GLMoleculeObject_bond::init()
     144{
    95145  // sign on as observer (obtain non-const instance before)
    96146  bondowner->signOn(this, BondObservable::BondRemoved);
     
    159209  removeChannels();
    160210  // check whether we should be removed
    161   countsubjectKilled();
     211  countsubjectKilled(std::make_pair(getleftIndex(), getrightIndex()));
    162212}
    163213
     
    339389}
    340390
     391static GLMoleculeObject_bond::bondIds_t getBondIdsForIds(
     392    const boost::function<const atomId_t ()> _left,
     393    const boost::function<const atomId_t ()> _right)
     394{
     395  return std::make_pair( _left(), _right());
     396}
     397
    341398void GLMoleculeObject_bond::initObservedValues(
    342399    std::vector<boost::any> &_ObservedValues,
     
    346403    const Observable * const _rightowner,
    347404    const Observable * const _bondowner,
    348     const boost::function<void()> &_subjectKilled)
     405    const boost::function<void(const atomId_t &)> &_leftsubjectKilled,
     406    const boost::function<void(const atomId_t &)> &_rightsubjectKilled,
     407    const boost::function<void(const bondIds_t &)> &_bondsubjectKilled)
    349408{
    350409  /* This is an old note from when the code was still part of cstor's initializer body.
     
    372431        _leftatomId,
    373432        IndexChannels,
    374         _subjectKilled);
     433        _leftsubjectKilled);
    375434  _ObservedValues[leftIndex] = LeftIndexObservable;
    376435  ObservedValue_wCallback<atomId_t> * const RightIndexObservable =
     
    381440        _rightatomId,
    382441        IndexChannels,
    383         _subjectKilled);
     442        _rightsubjectKilled);
    384443  _ObservedValues[rightIndex] = RightIndexObservable;
    385444
     
    402461  const boost::function<int ()> DegreeUpdater(
    403462      boost::bind(&GLMoleculeObject_bond::updateDegree, LeftIndexGetter, RightIndexGetter));
    404 
    405   _ObservedValues[leftPosition] = new ObservedValue_wCallback<Vector>(
     463  const boost::function<bondIds_t ()> BondIdGetter(
     464      boost::bind(&getBondIdsForIds, LeftIndexGetter, RightIndexGetter));
     465
     466  _ObservedValues[leftPosition] = new ObservedValue_wCallback<Vector, atomId_t>(
    406467      _leftowner,
    407468      LeftPositionUpdater,
     
    409470      LeftPositionUpdater(),
    410471      BondPositionChannels,
    411       _subjectKilled);
    412   _ObservedValues[rightPosition] = new ObservedValue_wCallback<Vector>(
     472      _leftsubjectKilled,
     473      LeftIndexGetter);
     474  _ObservedValues[rightPosition] = new ObservedValue_wCallback<Vector, atomId_t>(
    413475      _rightowner,
    414476      RightPositionUpdater,
     
    416478      RightPositionUpdater(),
    417479      BondPositionChannels,
    418       _subjectKilled);
    419   _ObservedValues[leftElement] = new ObservedValue_wCallback<atomicNumber_t>(
     480      _rightsubjectKilled,
     481      RightIndexGetter);
     482  _ObservedValues[leftElement] = new ObservedValue_wCallback<atomicNumber_t, atomId_t>(
    420483      _leftowner,
    421484      LeftElementUpdater,
     
    423486      LeftElementUpdater(),
    424487      BondElementChannels,
    425       _subjectKilled);
    426   _ObservedValues[rightElement] = new ObservedValue_wCallback<atomicNumber_t>(
     488      _leftsubjectKilled,
     489      LeftIndexGetter);
     490  _ObservedValues[rightElement] = new ObservedValue_wCallback<atomicNumber_t, atomId_t>(
    427491      _rightowner,
    428492      RightElementUpdater,
     
    430494      RightElementUpdater(),
    431495      BondElementChannels,
    432       _subjectKilled);
    433   _ObservedValues[Degree] = new ObservedValue_wCallback<int>(
     496      _rightsubjectKilled,
     497      RightIndexGetter);
     498  _ObservedValues[Degree] = new ObservedValue_wCallback<int, bondIds_t>(
    434499      _bondowner,
    435500      DegreeUpdater,
     
    437502      DegreeUpdater(),
    438503      BondDegreeChannels,
    439       _subjectKilled);
     504      _bondsubjectKilled,
     505      BondIdGetter);
    440506}
    441507
     
    445511  delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[leftIndex]);
    446512  delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[rightIndex]);
    447   delete boost::any_cast<ObservedValue_wCallback<Vector> *>(_ObservedValues[leftPosition]);
    448   delete boost::any_cast<ObservedValue_wCallback<Vector> *>(_ObservedValues[rightPosition]);
    449   delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(_ObservedValues[leftElement]);
    450   delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(_ObservedValues[rightElement]);
    451   delete boost::any_cast<ObservedValue_wCallback<int> *>(_ObservedValues[Degree]);
     513  delete boost::any_cast<ObservedValue_wCallback<Vector,atomId_t> *>(_ObservedValues[leftPosition]);
     514  delete boost::any_cast<ObservedValue_wCallback<Vector,atomId_t> *>(_ObservedValues[rightPosition]);
     515  delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t,atomId_t> *>(_ObservedValues[leftElement]);
     516  delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t,atomId_t> *>(_ObservedValues[rightElement]);
     517  delete boost::any_cast<ObservedValue_wCallback<int, bondIds_t> *>(_ObservedValues[Degree]);
    452518  _ObservedValues.clear();
    453519}
     
    465531Vector GLMoleculeObject_bond::getleftPosition() const
    466532{
    467   return boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[leftPosition])->get();
     533  return boost::any_cast<ObservedValue_wCallback<Vector,atomId_t> *>(ObservedValues[leftPosition])->get();
    468534}
    469535
    470536Vector GLMoleculeObject_bond::getrightPosition() const
    471537{
    472   return boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[rightPosition])->get();
     538  return boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(ObservedValues[rightPosition])->get();
    473539}
    474540
    475541atomicNumber_t GLMoleculeObject_bond::getleftElement() const
    476542{
    477   return boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[leftElement])->get();
     543  return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(ObservedValues[leftElement])->get();
    478544}
    479545
    480546atomicNumber_t GLMoleculeObject_bond::getrightElement() const
    481547{
    482   return boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[rightElement])->get();
     548  return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(ObservedValues[rightElement])->get();
    483549}
    484550
    485551int GLMoleculeObject_bond::getDegree() const
    486552{
    487   return boost::any_cast<ObservedValue_wCallback<int> *>(ObservedValues[Degree])->get();
    488 }
     553  return boost::any_cast<ObservedValue_wCallback<int, bondIds_t> *>(ObservedValues[Degree])->get();
     554}
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp

    r099f67 r026bef  
    3939  typedef std::pair<atomId_t, atomId_t> bondIds_t;
    4040
    41   GLMoleculeObject_bond(QGLSceneNode *mesh[], QObject *parent, const bondIds_t bondIds, const enum SideOfBond side);
     41  GLMoleculeObject_bond(
     42      QGLSceneNode *mesh[],
     43      QObject *parent,
     44      const bondIds_t bondIds,
     45      const enum SideOfBond side);
     46  GLMoleculeObject_bond(
     47      QGLSceneNode *mesh[],
     48      QObject *parent,
     49      const bondIds_t bondIds,
     50      const enum SideOfBond side,
     51      std::vector<boost::any> &_ObservedValues);
    4252  virtual ~GLMoleculeObject_bond();
    4353
     
    7383
    7484private:
     85
     86  void init();
     87
    7588  void removeChannels();
    7689
     
    136149   * \param _rightowner reference to right atom
    137150   * \param _bondowner reference to bond
    138    * \param _subjectKilled ref to function to call on subjectKilled()
     151   * \param _leftsubjectKilled ref to function to call on subjectKilled() for left atom
     152   * \param _rightsubjectKilled ref to function to call on subjectKilled() for right atom
     153   * \param _bondsubjectKilled ref to function to call on subjectKilled() for bond
    139154   */
    140155  static void initObservedValues(
     
    145160      const Observable * const _rightowner,
    146161      const Observable * const _bondowner,
    147       const boost::function<void()> &_subjectKilled);
     162      const boost::function<void(const atomId_t &)> &_leftsubjectKilled,
     163      const boost::function<void(const atomId_t &)> &_rightsubjectKilled,
     164      const boost::function<void(const bondIds_t &)> &_bondsubjectKilled);
    148165
    149166  /** Destroys all \a ObservedValues entries.
     
    202219   * monitored Observable. Only then can we safely remove the instance.
    203220   *
    204    */
     221   * \param _bondIds bond ids whose bond has called subjectKilled()
     222   */
     223  void countsubjectKilled(
     224      const bondIds_t &_bondIds)
     225  {
     226    countsubjectKilled();
     227  }
     228
     229  void countsubjectKilled(
     230      const atomId_t &_atomid)
     231  {
     232    countsubjectKilled();
     233  }
     234
    205235  void countsubjectKilled();
    206236
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    r099f67 r026bef  
    122122  hoverAtomId(-1)
    123123{
    124   boost::function<void()> subjectKilled =
    125       boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this);
     124  boost::function<void(const moleculeId_t)> subjectKilled =
     125      boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this, _molid);
    126126  initObservedValues(ObservedValues, _molid, molref, subjectKilled);
    127127
     
    138138  connect (this, SIGNAL(TesselationHullChanged()), this, SLOT(resetTesselationHull()), Qt::QueuedConnection);
    139139  connect (this, SIGNAL(BoundingBoxChanged()), this, SLOT(resetBoundingBox()), Qt::QueuedConnection);
    140   connect (this, SIGNAL(IsSelectedChanged()), this, SLOT(resetIsSelected()), Qt::QueuedConnection);
    141140  connect (this, SIGNAL(IdChanged()), this, SLOT(resetIndex()), Qt::QueuedConnection);
    142141  connect (this, SIGNAL(AtomInserted(const atomId_t)), this, SLOT(atomInserted(const atomId_t)), Qt::QueuedConnection);
     
    148147}
    149148
    150 GLMoleculeObject_molecule::GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const moleculeId_t _molid) :
     149GLMoleculeObject_molecule::GLMoleculeObject_molecule(
     150    QGLSceneNode *mesh[],
     151    QObject *parent,
     152    const moleculeId_t _molid) :
    151153  GLMoleculeObject(mesh, parent),
    152154  Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)),
     
    169171  hoverAtomId(-1)
    170172{
    171   boost::function<void()> subjectKilled =
    172       boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this);
     173  boost::function<void(const moleculeId_t)> subjectKilled =
     174      boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this, _molid);
    173175  initObservedValues(ObservedValues, _molid, molref, subjectKilled);
    174176
     
    480482  owner = NULL;
    481483
    482   countsubjectKilled();
     484  countsubjectKilled(getMolIndex());
    483485}
    484486
     
    844846}
    845847
    846 void GLMoleculeObject_molecule::countsubjectKilled()
     848void GLMoleculeObject_molecule::countsubjectKilled(const moleculeId_t)
    847849{
    848850  ++subjectKilledCount;
     
    856858    const moleculeId_t _molid,
    857859    const molecule * const _molref,
    858     const boost::function<void()> &_subjectKilled)
     860    const boost::function<void(const moleculeId_t)> &_subjectKilled)
    859861{
    860862  /* This is an old note from when the code was still part of cstor's initializer body.
     
    893895      boost::bind(&GLMoleculeObject_molecule::updateBoundingBox, MolIndexGetter));
    894896
    895   _ObservedValues[MolName] = new ObservedValue_wCallback<std::string>(
     897  _ObservedValues[MolName] = new ObservedValue_wCallback<std::string, moleculeId_t>(
    896898      _molref,
    897899      MolNameUpdater,
     
    899901      MolNameUpdater(),
    900902      NameChannels,
    901       _subjectKilled);
    902   _ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo>(
     903      _subjectKilled,
     904      MolIndexGetter);
     905  _ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t>(
    903906      _molref,
    904907      BoundingBoxUpdater,
     
    906909      initBoundingBox(),
    907910      BoundingBoxChannels,
    908       _subjectKilled);
     911      _subjectKilled,
     912      MolIndexGetter);
    909913  _ObservedValues[PresentAtoms] = new ObservedValue_UpdateAtoms(
    910914      _molref,
     
    919923{
    920924  delete boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(_ObservedValues[MolIndex]);
    921   delete boost::any_cast<ObservedValue_wCallback<std::string> *>(_ObservedValues[MolName]);
    922   delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo> *>(_ObservedValues[BoundingBox]);
     925  delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[MolName]);
     926  delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(_ObservedValues[BoundingBox]);
    923927  delete boost::any_cast<ObservedValue_UpdateAtoms *>(_ObservedValues[PresentAtoms]);
    924928  _ObservedValues.clear();
     
    932936std::string GLMoleculeObject_molecule::getMolName() const
    933937{
    934   return boost::any_cast<ObservedValue_wCallback<std::string> *>(ObservedValues[MolName])->get();
     938  return boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[MolName])->get();
    935939}
    936940
    937941molecule::BoundingBoxInfo GLMoleculeObject_molecule::getBoundingBox() const
    938942{
    939   return boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo> *>(ObservedValues[BoundingBox])->get();
     943  return boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(ObservedValues[BoundingBox])->get();
    940944}
    941945
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp

    r099f67 r026bef  
    3939  Q_OBJECT
    4040public:
    41   GLMoleculeObject_molecule(QObject *parent, const moleculeId_t molid);
    42   GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const moleculeId_t molid);
     41  GLMoleculeObject_molecule(
     42      QObject *parent,
     43      const moleculeId_t molid);
     44  GLMoleculeObject_molecule(
     45      QGLSceneNode *mesh[],
     46      QObject *parent,
     47      const moleculeId_t molid);
    4348  virtual ~GLMoleculeObject_molecule();
    4449
     
    172177      const moleculeId_t _molid,
    173178      const molecule * const _molref,
    174       const boost::function<void()> &_subjectKilled);
     179      const boost::function<void(const moleculeId_t)> &_subjectKilled);
    175180
    176181  /** Destroys all \a ObservedValues entries.
     
    211216   * monitored Observable. Only then can we safely remove the instance.
    212217   *
    213    */
    214   void countsubjectKilled();
     218   * \param _molid molecule id who signalled subjectKilled()
     219   */
     220  void countsubjectKilled(const moleculeId_t _molid);
    215221
    216222  //!> counts how many ObservedValues have already been subjectKilled()
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    r099f67 r026bef  
    9090    GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
    9191  }
    92   connect(this, SIGNAL(moleculePreparedInserted(const moleculeId_t)), this, SLOT(moleculeInserted(const moleculeId_t)));
    9392
    9493//  connect(this, SIGNAL(updated()), this, SLOT(update()));
     
    220219}
    221220
    222 /** Prepres insertion of a molecule into the scene.
    223  *
    224  * This function takes up the insertion information, i.e. a molecule has been
    225  * inserted and its id, and takes some immediate action (writing id into a map).
    226  * But the request is then transmitted indirectly (i.e. not necessarily being
    227  * processed in the same thread). Hence, we first take the request via a direction
    228  * connection in the thread where the actual World::createMolecule() was called.
    229  * However, the creation of the visual representation must occur in the thread
    230  * who also contains GLWorldScene and GLWorldView and all further parents.
    231  *
    232  * That's the reason why we split here into moleculePrepareInserted and
    233  * moleculeInserted.
     221/** Inserts a molecule into the scene.
    234222 *
    235223 * @param _mol molecule to insert
    236224 */
    237 void GLWorldScene::moleculePrepareInserted(const moleculeId_t _id)
    238 {
    239   LOG(3, "INFO: GLWorldScene: Received signal moleculePrepareInserted for molecule "+toString(_id)+".");
     225void GLWorldScene::moleculeInserted(const moleculeId_t _id)
     226{
     227  LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "+toString(_id)+".");
    240228
    241229  boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
     
    244232  ASSERT( iter == MoleculesinSceneMap.end(),
    245233      "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" already present.");
    246 
    247   emit moleculePreparedInserted(_id);
    248 }
    249 
    250 /** Inserts a molecule into the scene.
    251  *
    252  * \sa moleculePrepareInserted()
    253  *
    254  * @param _mol molecule to insert
    255  */
    256 void GLWorldScene::moleculeInserted(const moleculeId_t _id)
    257 {
    258   boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    259234
    260235  // check whether molecule is still present
     
    271246  LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << _id);
    272247  GLMoleculeObject_molecule *molObject =
    273       new GLMoleculeObject_molecule(GLMoleculeObject::meshEmpty, this, _id);
     248      new GLMoleculeObject_molecule(
     249          GLMoleculeObject::meshEmpty, this, _id);
    274250  ASSERT( molObject != NULL,
    275251      "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(_id));
     
    347323  connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
    348324  connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
    349   connect (molObject, SIGNAL(InstanceRemoved(const moleculeId_t)), this, SLOT(moleculeRemoved(const moleculeId_t)));
    350325
    351326  emit changed();
     
    355330/** Removes a molecule from the scene.
    356331 *
    357  * * \sa moleculePrepareRemoved()
    358  *
    359332 * @param _id id of molecule to remove
    360333 */
    361334void GLWorldScene::moleculeRemoved(const moleculeId_t _id)
    362335{
    363   LOG(3, "INFO: GLWorldScene: Received signal moleculePrepareRemoved for molecule "+toString(_id)+".");
     336  LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_id)+".");
    364337
    365338  boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    r099f67 r026bef  
    8282  void hoverChanged(const atomId_t);
    8383  void hoverChanged(const moleculeId_t, int);
    84   void moleculePreparedInserted(const moleculeId_t _id);
    8584
    8685private slots:
    8786  void atomClicked(atomId_t no);
    8887  void moleculeClicked(moleculeId_t no);
    89   void moleculePrepareInserted(const moleculeId_t _id);
    9088  void moleculeRemoved(const moleculeId_t _id);
    9189  void moleculeInserted(const moleculeId_t _id);
  • src/UIElements/Views/Qt4/Qt3D/GLWorldView.cpp

    r099f67 r026bef  
    9090  connect(worldscene, SIGNAL(hoverChanged(const atomId_t)), this, SLOT(sceneHoverSignalled(const atomId_t)));
    9191  connect(worldscene, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SLOT(sceneHoverSignalled(const moleculeId_t, int)));
    92   connect(this, SIGNAL(atomRemoved(const moleculeId_t, const atomId_t)), worldscene, SLOT(atomRemoved(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
    93   connect(this, SIGNAL(atomInserted(const moleculeId_t, const atomId_t)), worldscene, SLOT(atomInserted(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
    94   connect(this, SIGNAL(moleculeInserted(const moleculeId_t)), worldscene, SLOT(moleculePrepareInserted(const moleculeId_t)), Qt::DirectConnection);
    9592  //connect(this, SIGNAL(changed()), this, SLOT(updateGL()));
    9693  connect(this, SIGNAL(changed()), this, SLOT(sceneChangeSignalled()));
  • src/UIElements/Views/Qt4/Qt3D/ObservedValue_UpdateAtoms.hpp

    r099f67 r026bef  
    3434 *
    3535 */
    36 class ObservedValue_UpdateAtoms : public ObservedValue_wCallback< std::set<atomId_t> >
     36class ObservedValue_UpdateAtoms : public ObservedValue_wCallback< std::set<atomId_t>, moleculeId_t >
    3737{
    3838  typedef std::set<atomId_t> atoms_t;
     
    4343    const std::string &_name,
    4444    const Observable::channels_t &_channels,
    45     const boost::function<void()> &_callback,
     45    const boost::function<void(moleculeId_t)> &_callback,
    4646    const boost::function<const moleculeId_t ()> &_getMolIndex
    4747    ) :
    48       ObservedValue_wCallback<atoms_t>(
     48      ObservedValue_wCallback<atoms_t, moleculeId_t>(
    4949          _owner,
    5050          boost::bind(&ObservedValue_UpdateAtoms::updateAtoms,
     
    5252              atoms_t(),
    5353              _channels,
    54               _callback),
     54              _callback,
     55              _getMolIndex),
    5556      getMolIndex(_getMolIndex)
    5657    {}
  • src/UIElements/Views/Qt4/Qt3D/ObservedValue_wCallback.hpp

    r099f67 r026bef  
    1818#include "CodePatterns/Observer/Observable.hpp"
    1919
     20#include <string>
     21
     22#include <boost/bind.hpp>
     23#include <boost/function.hpp>
     24
    2025/** We derive from ObservedValue in order to tell owning instance about
    2126 * subjectKilled() having been called.
    2227 */
    23 template <class T>
     28template <class T, class id=T>
    2429class ObservedValue_wCallback : public ObservedValue<T>
    2530{
     
    3136      const T &_initialvalue,
    3237      const Observable::channels_t &_channels,
    33       const boost::function<void()> &_callback) :
     38      const boost::function<void(const id)> &_callback,
     39      const boost::function<const id()> &_getId) :
    3440        ObservedValue<T>(_owner, _recalcMethod, _name, _initialvalue, _channels),
    35         callback(_callback)
     41        callback(_callback),
     42        getId(_getId)
    3643  {}
    3744  virtual ~ObservedValue_wCallback()
     
    4249  {
    4350    ObservedValue<T>::subjectKilled(publisher);
    44     callback();
     51    callback(getId());
    4552  }
    4653
    4754private:
    4855  //!> callback function to tell other entity about subjectKilled
    49   const boost::function<void()> callback;
     56  const boost::function<void(const id)> callback;
     57  const boost::function<const id()> getId;
     58};
     59
     60/** Specialization of ObservedValue_wCallback for the index ObservedValue.
     61 *
     62 * The index serves as the unique identifier for the object instance whose
     63 * properties are monitored in ObservedValue. Hence, how to give a subjectKilled()
     64 * with an external getId() function? For the index the ObservedValue::get() is
     65 * the getId() we need to call! Hence, we may simply connect these internally
     66 * in this partial template specialization.
     67 *
     68 * Because atomicNumber_t, atomId_t and moleculeId_t are not unique types but
     69 * -- at the writing of this class -- just typedefs, we have to resort to the
     70 * trick with two constructors, one taking an external getId(), the other
     71 * routing the getId() internally by binding to ObservedValue<T>::get().
     72 */
     73template <class T>
     74class ObservedValue_wCallback<T,T> : public ObservedValue<T>
     75{
     76public:
     77  ObservedValue_wCallback(
     78      const Observable * const _owner,
     79      const boost::function<T()> &_recalcMethod,
     80      const std::string &_name,
     81      const T &_initialvalue,
     82      const Observable::channels_t &_channels,
     83      const boost::function<void(const T)> &_callback,
     84      const boost::function<const T()> &_getId) :
     85        ObservedValue<T>(_owner, _recalcMethod, _name, _initialvalue, _channels),
     86        callback(_callback),
     87        getId(_getId)
     88  {}
     89  ObservedValue_wCallback(
     90      const Observable * const _owner,
     91      const boost::function<T()> &_recalcMethod,
     92      const std::string &_name,
     93      const T &_initialvalue,
     94      const Observable::channels_t &_channels,
     95      const boost::function<void(const T)> &_callback) :
     96        ObservedValue<T>(_owner, _recalcMethod, _name, _initialvalue, _channels),
     97        callback(_callback),
     98        getId(boost::bind(&ObservedValue<T>::get, this))
     99  {}
     100  virtual ~ObservedValue_wCallback()
     101  {}
     102
     103protected:
     104  virtual void subjectKilled(Observable *publisher)
     105  {
     106    ObservedValue<T>::subjectKilled(publisher);
     107    callback(getId());
     108  }
     109
     110private:
     111  //!> callback function to tell other entity about subjectKilled
     112  const boost::function<void(const T)> callback;
     113  const boost::function<const T()> getId;
    50114};
    51115
Note: See TracChangeset for help on using the changeset viewer.