Changeset 099f67 for src/UIElements


Ignore:
Timestamp:
Feb 12, 2016, 11:15:05 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:
026bef
Parents:
16bd37
git-author:
Frederik Heber <heber@…> (10/17/15 13:28:19)
git-committer:
Frederik Heber <heber@…> (02/12/16 23:15:05)
Message:

GLMoleculeObject_bond's ObservedValues is now all static.

  • again, the same change as with .._molecule and .._atom.
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
2 edited

Legend:

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

    r16bd37 r099f67  
    6262// static entities
    6363const Observable::channels_t
     64GLMoleculeObject_bond::IndexChannels(1, AtomObservable::IndexChanged);
     65const Observable::channels_t
    6466GLMoleculeObject_bond::BondPositionChannels(1, AtomObservable::PositionChanged);
    6567const Observable::channels_t
     
    7880      +std::string("-")
    7981      +toString(bondIds.second)),
    80   leftatomId(bondIds.first),
    81   rightatomId(bondIds.second),
    82   leftowner(getAtom(leftatomId)),
    83   rightowner(getAtom(rightatomId)),
    84   bondowner(getAtom(leftatomId)->getBond(getAtom(rightatomId)).get()),
     82  leftowner(getAtomConst(bondIds.first)),
     83  rightowner(getAtomConst(bondIds.second)),
     84  bondowner(getAtomConst(bondIds.first)->getBond(getAtomConst(bondIds.second)).get()),
    8585  BondSide(side),
    8686  ObservedValues(MAX_ObservedTypes),
     
    8989  rightobservable_enabled(false)
    9090{
    91   initObservedValues();
     91  boost::function<void()> subjectKilled =
     92      boost::bind(&GLMoleculeObject_bond::countsubjectKilled, this);
     93  initObservedValues(ObservedValues, bondIds.first, bondIds.second, leftowner, rightowner, bondowner, subjectKilled);
    9294
    9395  // sign on as observer (obtain non-const instance before)
     
    114116{
    115117  LOG(3, "DEBUG: Destroying  GLMoleculeObject_bond to bond [" <<
    116       leftatomId << "," << rightatomId << "] and side " << BondSide << ".");
     118      getleftIndex() << "," << getrightIndex() << "] and side " << BondSide << ".");
    117119  // signOff() if not already done
    118120  removeChannels();
    119   destroyObservedValues();
     121  destroyObservedValues(ObservedValues);
    120122}
    121123
     
    171173    observerLog().addMessage() << "++ Update of Observer "
    172174        << observerLog().getName(static_cast<Observer*>(this))
    173         << " received notification from leftatom " << leftatomId << " for channel "
     175        << " received notification from leftatom " << getleftIndex() << " for channel "
    174176        << notification->getChannelNo() << ".";
    175177  } else if (publisher == static_cast<const Observable * const>(rightowner)) {
    176178    observerLog().addMessage() << "++ Update of Observer "
    177179        << observerLog().getName(static_cast<Observer*>(this))
    178         << " received notification from rightatom " << rightatomId << " for channel "
     180        << " received notification from rightatom " << getrightIndex() << " for channel "
    179181        << notification->getChannelNo() << ".";
    180182  }
     
    209211}
    210212
    211 Vector GLMoleculeObject_bond::updateLeftPosition() const
    212 {
    213   const atom * const _atom = getAtomConst(leftatomId);
     213atomId_t GLMoleculeObject_bond::updateIndex()
     214{
     215  return const_cast<const World &>(World::getInstance()).lastChangedAtomId();
     216}
     217
     218Vector GLMoleculeObject_bond::updateLeftPosition(
     219    const boost::function<const atomId_t ()> &_getLeftAtomIndex)
     220{
     221  const atom * const _atom = getAtomConst(_getLeftAtomIndex());
    214222  return _atom->getPosition();
    215223}
    216224
    217 Vector GLMoleculeObject_bond::updateRightPosition() const
    218 {
    219   const atom * const _atom = getAtomConst(rightatomId);
     225Vector GLMoleculeObject_bond::updateRightPosition(
     226    const boost::function<const atomId_t ()> &_getRightAtomIndex)
     227{
     228  const atom * const _atom = getAtomConst(_getRightAtomIndex());
    220229  return _atom->getPosition();
    221230}
    222231
    223 atomicNumber_t GLMoleculeObject_bond::updateLeftElement() const
    224 {
    225   const atom * const _atom = getAtomConst(leftatomId);
     232atomicNumber_t GLMoleculeObject_bond::updateLeftElement(
     233    const boost::function<const atomId_t ()> &_getLeftAtomIndex)
     234{
     235  const atom * const _atom = getAtomConst(_getLeftAtomIndex());
    226236  return _atom->getElementNo();
    227237}
    228238
    229 atomicNumber_t GLMoleculeObject_bond::updateRightElement() const
    230 {
    231   const atom * const _atom = getAtomConst(rightatomId);
     239atomicNumber_t GLMoleculeObject_bond::updateRightElement(
     240    const boost::function<const atomId_t ()> &_getRightAtomIndex)
     241{
     242  const atom * const _atom = getAtomConst(_getRightAtomIndex());
    232243  return _atom->getElementNo();
    233244}
    234245
    235 int GLMoleculeObject_bond::updateDegree() const
     246int GLMoleculeObject_bond::updateDegree(
     247    const boost::function<const atomId_t ()> &_getLeftAtomIndex,
     248    const boost::function<const atomId_t ()> &_getRightAtomIndex)
    236249{
    237250  const atom * const _leftatom = const_cast<const World &>(World::getInstance()).
    238       getAtom(AtomById(leftatomId));
     251      getAtom(AtomById(_getLeftAtomIndex()));
    239252  const atom * const _rightatom = const_cast<const World &>(World::getInstance()).
    240       getAtom(AtomById(rightatomId));
     253      getAtom(AtomById(_getRightAtomIndex()));
    241254  if ((_leftatom != NULL) && (_rightatom != NULL)) {
    242255    bond::ptr _bond = _leftatom->getBond(_rightatom);
     
    323336
    324337  if (subjectKilledCount > ObservedValues.size())
    325     emit BondRemoved(leftatomId, rightatomId);
    326 }
    327 
    328 void GLMoleculeObject_bond::initObservedValues()
    329 {
    330   // fill ObservedValues
    331   boost::function<void()> subjectKilled =
    332       boost::bind(&GLMoleculeObject_bond::countsubjectKilled, this);
    333   ObservedValues[leftPosition] = new ObservedValue_wCallback<Vector>(
    334       leftowner,
    335       boost::bind(&GLMoleculeObject_bond::updateLeftPosition, this),
    336       "BondleftPosition_"+toString(leftatomId),
    337       updateLeftPosition(),
     338    emit BondRemoved(getleftIndex(), getrightIndex());
     339}
     340
     341void GLMoleculeObject_bond::initObservedValues(
     342    std::vector<boost::any> &_ObservedValues,
     343    const atomId_t _leftatomId,
     344    const atomId_t _rightatomId,
     345    const Observable * const _leftowner,
     346    const Observable * const _rightowner,
     347    const Observable * const _bondowner,
     348    const boost::function<void()> &_subjectKilled)
     349{
     350  /* This is an old note from when the code was still part of cstor's initializer body.
     351   * TODO: Probably does not apply anymore but has not yet been tested.
     352   *
     353   * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
     354   * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
     355   * the class has not been fully constructed yet. "This" itself seems to be working fine.
     356   */
     357
     358  ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
     359      "GLMoleculeObject_bond::initObservedValues() - given ObservedValues has not correct size.");
     360
     361  // fill ObservedValues: index first
     362  // Note that we only need one as the function just checks on the last changed id
     363  // and ids cannot be changed simultaneously
     364  const boost::function<atomId_t ()> AtomIndexUpdater(
     365      boost::bind(&GLMoleculeObject_bond::updateIndex));
     366
     367  ObservedValue_wCallback<atomId_t> * const LeftIndexObservable =
     368      new ObservedValue_wCallback<atomId_t>(
     369        _leftowner,
     370        AtomIndexUpdater,
     371        "Bonds_LeftAtomIndex_"+toString(_leftatomId),
     372        _leftatomId,
     373        IndexChannels,
     374        _subjectKilled);
     375  _ObservedValues[leftIndex] = LeftIndexObservable;
     376  ObservedValue_wCallback<atomId_t> * const RightIndexObservable =
     377      new ObservedValue_wCallback<atomId_t>(
     378        _rightowner,
     379        AtomIndexUpdater,
     380        "Bonds_RightAtomIndex_"+toString(_rightatomId),
     381        _rightatomId,
     382        IndexChannels,
     383        _subjectKilled);
     384  _ObservedValues[rightIndex] = RightIndexObservable;
     385
     386  const boost::function<const atomId_t ()> LeftIndexGetter =
     387      boost::bind(&ObservedValue_wCallback<atomId_t>::get,
     388          LeftIndexObservable);
     389  const boost::function<const atomId_t ()> RightIndexGetter =
     390      boost::bind(&ObservedValue_wCallback<atomId_t>::get,
     391          RightIndexObservable);
     392
     393  // fill ObservedValues: then all the other that need index
     394  const boost::function<Vector ()> LeftPositionUpdater(
     395      boost::bind(&GLMoleculeObject_bond::updateLeftPosition, LeftIndexGetter));
     396  const boost::function<Vector ()> RightPositionUpdater(
     397      boost::bind(&GLMoleculeObject_bond::updateRightPosition, RightIndexGetter));
     398  const boost::function<atomicNumber_t ()> LeftElementUpdater(
     399      boost::bind(&GLMoleculeObject_bond::updateLeftElement, LeftIndexGetter));
     400  const boost::function<atomicNumber_t ()> RightElementUpdater(
     401      boost::bind(&GLMoleculeObject_bond::updateRightElement, RightIndexGetter));
     402  const boost::function<int ()> DegreeUpdater(
     403      boost::bind(&GLMoleculeObject_bond::updateDegree, LeftIndexGetter, RightIndexGetter));
     404
     405  _ObservedValues[leftPosition] = new ObservedValue_wCallback<Vector>(
     406      _leftowner,
     407      LeftPositionUpdater,
     408      "BondleftPosition_"+toString(_leftatomId),
     409      LeftPositionUpdater(),
    338410      BondPositionChannels,
    339       subjectKilled);
    340   ObservedValues[rightPosition] = new ObservedValue_wCallback<Vector>(
    341       rightowner,
    342       boost::bind(&GLMoleculeObject_bond::updateRightPosition, this),
    343       "BondrightPosition_"+toString(rightatomId),
    344       updateRightPosition(),
     411      _subjectKilled);
     412  _ObservedValues[rightPosition] = new ObservedValue_wCallback<Vector>(
     413      _rightowner,
     414      RightPositionUpdater,
     415      "BondrightPosition_"+toString(_rightatomId),
     416      RightPositionUpdater(),
    345417      BondPositionChannels,
    346       subjectKilled);
    347   ObservedValues[leftElement] = new ObservedValue_wCallback<atomicNumber_t>(
    348       leftowner,
    349       boost::bind(&GLMoleculeObject_bond::updateLeftElement, this),
    350       "BondleftElement"+toString(leftatomId),
    351       updateLeftElement(),
     418      _subjectKilled);
     419  _ObservedValues[leftElement] = new ObservedValue_wCallback<atomicNumber_t>(
     420      _leftowner,
     421      LeftElementUpdater,
     422      "BondleftElement"+toString(_leftatomId),
     423      LeftElementUpdater(),
    352424      BondElementChannels,
    353       subjectKilled);
    354   ObservedValues[rightElement] = new ObservedValue_wCallback<atomicNumber_t>(
    355       rightowner,
    356       boost::bind(&GLMoleculeObject_bond::updateRightElement, this),
    357       "BondrightElement"+toString(rightatomId),
    358       updateRightElement(),
     425      _subjectKilled);
     426  _ObservedValues[rightElement] = new ObservedValue_wCallback<atomicNumber_t>(
     427      _rightowner,
     428      RightElementUpdater,
     429      "BondrightElement"+toString(_rightatomId),
     430      RightElementUpdater(),
    359431      BondElementChannels,
    360       subjectKilled);
    361   ObservedValues[Degree] = new ObservedValue_wCallback<int>(
    362       bondowner,
    363       boost::bind(&GLMoleculeObject_bond::updateDegree, this),
    364       "BondDegree"+toString(leftatomId)+"_"+toString(rightatomId),
    365       updateDegree(),
     432      _subjectKilled);
     433  _ObservedValues[Degree] = new ObservedValue_wCallback<int>(
     434      _bondowner,
     435      DegreeUpdater,
     436      "BondDegree"+toString(_leftatomId)+"_"+toString(_rightatomId),
     437      DegreeUpdater(),
    366438      BondDegreeChannels,
    367       subjectKilled);
    368 }
    369 
    370 void GLMoleculeObject_bond::destroyObservedValues()
    371 {
    372   delete boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[leftPosition]);
    373   delete boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[rightPosition]);
    374   delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[leftElement]);
    375   delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[rightElement]);
    376   delete boost::any_cast<ObservedValue_wCallback<int> *>(ObservedValues[Degree]);
    377   ObservedValues.clear();
     439      _subjectKilled);
     440}
     441
     442void GLMoleculeObject_bond::destroyObservedValues(
     443    std::vector<boost::any> &_ObservedValues)
     444{
     445  delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[leftIndex]);
     446  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]);
     452  _ObservedValues.clear();
     453}
     454
     455atomId_t GLMoleculeObject_bond::getleftIndex() const
     456{
     457  return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[leftIndex])->get();
     458}
     459
     460atomId_t GLMoleculeObject_bond::getrightIndex() const
     461{
     462  return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[rightIndex])->get();
    378463}
    379464
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp

    r16bd37 r099f67  
    7575  void removeChannels();
    7676
    77   Vector updateLeftPosition() const;
    78   Vector updateRightPosition() const;
    79   atomicNumber_t updateLeftElement() const;
    80   atomicNumber_t updateRightElement() const;
    81   int updateDegree() const;
     77  static atomId_t updateIndex();
     78  static Vector updateLeftPosition(
     79      const boost::function<const atomId_t ()> &_getLeftAtomIndex);
     80  static Vector updateRightPosition(
     81      const boost::function<const atomId_t ()> &_getRightAtomIndex);
     82  static atomicNumber_t updateLeftElement(
     83      const boost::function<const atomId_t ()> &_getLeftAtomIndex);
     84  static atomicNumber_t updateRightElement(
     85      const boost::function<const atomId_t ()> &_getRightAtomIndex);
     86  static int updateDegree(
     87      const boost::function<const atomId_t ()> &_getLeftAtomIndex,
     88      const boost::function<const atomId_t ()> &_getRightAtomIndex);
    8289
    8390  static const atom * const getAtomConst(const atomId_t _id);
     
    8592
    8693private:
    87   //!> id of left bond partner for safely emitting BondRemoved signal
    88   const atomId_t leftatomId;
    89   //!> id of right bond partner for safely emitting BondRemoved signal
    90   const atomId_t rightatomId;
    91 
    9294  //!> contains ref to Observable of left atom
    9395  const Observable * const leftowner;
     
    105107  //!> enumeration of observed values to match with entries in ObservedValues
    106108  enum ObservedTypes {
     109    //!> contains the id of the left atom
     110    leftIndex,
     111    //!> contains the id of the right atom
     112    rightIndex,
    107113    //!> contains the position of the left atom
    108114    leftPosition,
     
    124130  /** Initializes all \a ObservedValues entries.
    125131   *
    126    */
    127   void initObservedValues();
     132   * \param _ObservedValues vector of ObservedValue to be filled
     133   * \param _leftatomId left atom id
     134   * \param _rightatomId right atom id
     135   * \param _leftowner reference to left atom
     136   * \param _rightowner reference to right atom
     137   * \param _bondowner reference to bond
     138   * \param _subjectKilled ref to function to call on subjectKilled()
     139   */
     140  static void initObservedValues(
     141      std::vector<boost::any> &_ObservedValues,
     142      const atomId_t _leftatomId,
     143      const atomId_t _rightatomId,
     144      const Observable * const _leftowner,
     145      const Observable * const _rightowner,
     146      const Observable * const _bondowner,
     147      const boost::function<void()> &_subjectKilled);
    128148
    129149  /** Destroys all \a ObservedValues entries.
    130150   *
    131    */
    132   void destroyObservedValues();
     151   * \param _ObservedValues vector of ObservedValue to be destroyed
     152   */
     153  static void destroyObservedValues(
     154      std::vector<boost::any> &_ObservedValues);
     155
     156  /** Getter to left atom's id contained in \a ObservedValues.
     157   *
     158   * \return left atom's id
     159   */
     160  atomId_t getleftIndex() const;
     161
     162  /** Getter to right atom's id contained in \a ObservedValues.
     163   *
     164   * \return right atom's id
     165   */
     166  atomId_t getrightIndex() const;
    133167
    134168  /** Getter to left atom's position contained in \a ObservedValues.
     
    183217  bool bond_enabled;
    184218
     219  //!> list of channels when id needs to update
     220  static const Observable::channels_t IndexChannels;
    185221  //!> list of channels when position needs to update
    186222  static const Observable::channels_t BondPositionChannels;
Note: See TracChangeset for help on using the changeset viewer.