Changeset 16bd37 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:
099f67
Parents:
8688ef
git-author:
Frederik Heber <heber@…> (10/17/15 12:55:30)
git-committer:
Frederik Heber <heber@…> (02/12/16 23:15:05)
Message:

GLMoleculeObject_atom's ObservedValues is now all static.

  • this is equivalent to the changes to GLMoleculeObject_molecule.
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
2 edited

Legend:

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

    r8688ef r16bd37  
    8686  owner(NULL)
    8787{
    88   initObservedValues(_id);
     88  boost::function<void()> subjectKilled =
     89      boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this);
     90  initObservedValues(ObservedValues, _id, atomref, subjectKilled);
    8991
    9092  setObjectId(_id);
     
    136138{
    137139  deactivateObserver();
    138   destroyObservedValues();
     140  destroyObservedValues(ObservedValues);
    139141}
    140142
     
    259261}
    260262
    261 atomId_t GLMoleculeObject_atom::updateIndex() const
     263atomId_t GLMoleculeObject_atom::updateIndex()
    262264{
    263265  return const_cast<const World &>(World::getInstance()).lastChangedAtomId();
    264266}
    265267
    266 Vector GLMoleculeObject_atom::updatePosition() const
    267 {
    268   const atom * const _atom = getAtom(getAtomIndex());
     268Vector GLMoleculeObject_atom::updatePosition(
     269    const boost::function<const atomId_t ()> &_getAtomIndex)
     270{
     271  const atom * const _atom = getAtomConst(_getAtomIndex());
    269272  if (_atom != NULL) {
    270273    return _atom->getPosition();
     
    274277}
    275278
    276 atomicNumber_t GLMoleculeObject_atom::updateElement() const
    277 {
    278   const atom * const _atom = getAtom(getAtomIndex());
     279atomicNumber_t GLMoleculeObject_atom::updateElement(
     280    const boost::function<const atomId_t ()> &_getAtomIndex)
     281{
     282  const atom * const _atom = getAtomConst(_getAtomIndex());
    279283  if (_atom != NULL) {
    280284    return _atom->getElementNo();
     
    284288}
    285289
    286 GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::updateBonds() const
     290GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::updateBonds(
     291    const boost::function<const atomId_t ()> &_getAtomIndex)
    287292{
    288293  ListOfBonds_t ListOfBonds;
    289   const atom * const _atom = getAtom(getAtomIndex());
     294  const atom * const _atom = getAtomConst(_getAtomIndex());
    290295  if (_atom != NULL) {
    291     // make sure position is up-to-date
     296    // make sure bonds is up-to-date
    292297    const BondList ListBonds = _atom->getListOfBonds();
    293298    for (BondList::const_iterator iter = ListBonds.begin();
     
    298303          (*iter)->rightatom->getId()) );
    299304  } else {
    300     ELOG(2, "Atom with id "+toString(getAtomIndex())+" is already gone.");
     305    ELOG(2, "Atom with id "+toString(_getAtomIndex())+" is already gone.");
    301306  }
    302307  return ListOfBonds;
     
    351356}
    352357
    353 void GLMoleculeObject_atom::initObservedValues(const atomId_t _id)
    354 {
    355   // fill ObservedValues
    356   boost::function<void()> subjectKilled =
    357       boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this);
    358   ObservedValues[AtomIndex] = new ObservedValue_wCallback<atomId_t>(
    359       atomref,
    360       boost::bind(&GLMoleculeObject_atom::updateIndex, this),
    361       "AtomIndex_"+toString(_id),
    362       _id,
    363       AtomIndexChannels,
    364       subjectKilled);
    365   ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector>(
    366       atomref,
    367       boost::bind(&GLMoleculeObject_atom::updatePosition, this),
     358void GLMoleculeObject_atom::initObservedValues(
     359    std::vector<boost::any> &_ObservedValues,
     360    const atomId_t _id,
     361    const atom * const _atomref,
     362    const boost::function<void()> &_subjectKilled)
     363{
     364  /* This is an old note from when the code was still part of cstor's initializer body.
     365   * TODO: Probably does not apply anymore but has not yet been tested.
     366   *
     367   * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
     368   * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
     369   * the class has not been fully constructed yet. "This" itself seems to be working fine.
     370   */
     371
     372  ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
     373      "GLMoleculeObject_atom::initObservedValues() - given ObservedValues has not correct size.");
     374
     375  // fill ObservedValues: index first
     376  const boost::function<atomId_t ()> AtomIndexUpdater(
     377      boost::bind(&GLMoleculeObject_atom::updateIndex));
     378
     379  ObservedValue_wCallback<atomId_t> * const IndexObservable =
     380      new ObservedValue_wCallback<atomId_t>(
     381          _atomref,
     382          boost::bind(&GLMoleculeObject_atom::updateIndex),
     383          "AtomIndex_"+toString(_id),
     384          _id,
     385          AtomIndexChannels,
     386          _subjectKilled);
     387  _ObservedValues[AtomIndex] = IndexObservable;
     388
     389  const boost::function<const atomId_t ()> AtomIndexGetter =
     390      boost::bind(&ObservedValue_wCallback<atomId_t>::get,
     391          IndexObservable);
     392
     393  // fill ObservedValues: then all the other that need index
     394  const boost::function<Vector ()> AtomPositionUpdater(
     395      boost::bind(&GLMoleculeObject_atom::updatePosition, AtomIndexGetter));
     396  const boost::function<atomicNumber_t ()> AtomElementUpdater(
     397      boost::bind(&GLMoleculeObject_atom::updateElement, AtomIndexGetter));
     398  const boost::function<ListOfBonds_t ()> AtomBondsUpdater(
     399      boost::bind(&GLMoleculeObject_atom::updateBonds, AtomIndexGetter));
     400
     401  _ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector>(
     402      _atomref,
     403      AtomPositionUpdater,
    368404      "AtomPosition_"+toString(_id),
    369       updatePosition(),
     405      AtomPositionUpdater(),
    370406      AtomPositionChannels,
    371       subjectKilled);
    372   ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t>(
    373       atomref,
    374       boost::bind(&GLMoleculeObject_atom::updateElement, this),
     407      _subjectKilled);
     408  _ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t>(
     409      _atomref,
     410      AtomElementUpdater,
    375411      "AtomElement"+toString(_id),
    376       updateElement(),
     412      AtomElementUpdater(),
    377413      AtomElementChannels,
    378       subjectKilled);
    379   ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t>(
    380       atomref,
    381       boost::bind(&GLMoleculeObject_atom::updateBonds, this),
     414      _subjectKilled);
     415  _ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t>(
     416      _atomref,
     417      AtomBondsUpdater,
    382418      "AtomBonds_"+toString(_id),
    383       updateBonds(),
     419      AtomBondsUpdater(),
    384420      AtomBondsChannels,
    385       subjectKilled);
    386 }
    387 
    388 void GLMoleculeObject_atom::destroyObservedValues()
    389 {
    390   delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex]);
    391   delete boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[AtomPosition]);
    392   delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[AtomElement]);
    393   delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(ObservedValues[AtomBonds]);
    394   ObservedValues.clear();
     421      _subjectKilled);
     422}
     423
     424void GLMoleculeObject_atom::destroyObservedValues(
     425    std::vector<boost::any> &_ObservedValues)
     426{
     427  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]);
     431  _ObservedValues.clear();
    395432}
    396433
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp

    r8688ef r16bd37  
    7676  static atom * const getAtom(const atomId_t _id);
    7777
    78   atomId_t updateIndex() const;
    79   Vector updatePosition() const;
    80   atomicNumber_t updateElement() const;
    81   ListOfBonds_t updateBonds() const;
     78  static atomId_t updateIndex();
     79  static Vector updatePosition(
     80      const boost::function<const atomId_t ()> &_getAtomIndex);
     81  static atomicNumber_t updateElement(
     82      const boost::function<const atomId_t ()> &_getAtomIndex);
     83  static ListOfBonds_t updateBonds(
     84      const boost::function<const atomId_t ()> &_getAtomIndex);
    8285
    8386  void activateObserver();
     
    114117  /** Initializes all \a ObservedValues entries.
    115118   *
     119   * \param _ObservedValues vector of ObservedValue to be filled
    116120   * \param _id atom id
     121   * \param _atomref reference to atom
     122   * \param _subjectKilled ref to function to call on subjectKilled()
    117123   */
    118   void initObservedValues(const atomId_t _id);
     124  static void initObservedValues(
     125      std::vector<boost::any> &_ObservedValues,
     126      const atomId_t _id,
     127      const atom * const _atomref,
     128      const boost::function<void()> &_subjectKilled);
    119129
    120130  /** Destroys all \a ObservedValues entries.
    121131   *
     132   * \param _ObservedValues vector of ObservedValue to be destroyed
    122133   */
    123   void destroyObservedValues();
     134  static void destroyObservedValues(
     135      std::vector<boost::any> &_ObservedValues);
    124136
    125137  /** Getter to atom index contained in \a ObservedValues.
Note: See TracChangeset for help on using the changeset viewer.