Ignore:
Timestamp:
Mar 14, 2016, 9:53:43 AM (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:
7f1c00
Parents:
d845bd
git-author:
Frederik Heber <heber@…> (03/14/16 09:51:32)
git-committer:
Frederik Heber <heber@…> (03/14/16 09:53:43)
Message:

All QtObserved..::update..() now use the atom or molecule ref instead of index getter.

  • the update() is called instantly by the Observable. Hence, the ref is still fully valid and always more recent than the index that needs updating. Also, it is way faster, as no lookup in the World is required and function may even get inlined.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.cpp

    rd845bd rf35f7e  
    143143}
    144144
    145 atomId_t QtObservedAtom::updateIndex()
    146 {
    147   return const_cast<const World &>(World::getInstance()).lastChangedAtomId();
     145#ifdef HAVE_INLINE
     146inline
     147#endif
     148atomId_t QtObservedAtom::updateIndex(const atom &_atomref)
     149{
     150  return _atomref.getId();
    148151}
    149152
    150153QtObservedAtom::ListOfBonds_t QtObservedAtom::updateBonds(
    151     const boost::function<const atomId_t ()> &_getAtomIndex)
     154    const atom &_atom)
    152155{
    153156  ListOfBonds_t ListOfBonds;
    154   const atom * const _atom = getAtomConst(_getAtomIndex());
    155   if (_atom != NULL) {
    156     // make sure bonds is up-to-date
    157     const BondList ListBonds = _atom->getListOfBonds();
    158     for (BondList::const_iterator iter = ListBonds.begin();
    159         iter != ListBonds.end();
    160         ++iter)
    161       ListOfBonds.insert( ListOfBonds.end(), std::make_pair(
    162           (*iter)->leftatom->getId(),
    163           (*iter)->rightatom->getId()) );
    164   }
     157  // make sure bonds is up-to-date
     158  const BondList ListBonds = _atom.getListOfBonds();
     159  for (BondList::const_iterator iter = ListBonds.begin();
     160      iter != ListBonds.end();
     161      ++iter)
     162    ListOfBonds.insert( ListOfBonds.end(), std::make_pair(
     163        (*iter)->leftatom->getId(),
     164        (*iter)->rightatom->getId()) );
    165165  return ListOfBonds;
    166166}
    167167
     168#ifdef HAVE_INLINE
     169inline
     170#endif
    168171atomicNumber_t QtObservedAtom::updateElement(
    169     const boost::function<const atomId_t ()> &_getAtomIndex)
    170 {
    171   const atom * const _atom = getAtomConst(_getAtomIndex());
    172   if (_atom != NULL) {
    173     return _atom->getElementNo();
    174   } else {
    175     return (atomicNumber_t)-1;
    176   }
    177 }
    178 
     172    const atom &_atom)
     173{
     174  return _atom.getElementNo();
     175}
     176
     177#ifdef HAVE_INLINE
     178inline
     179#endif
    179180QtObservedMolecule* QtObservedAtom::updateMoleculeIndex(
    180     const boost::function<const atomId_t ()> &_getAtomIndex)
    181 {
    182   const atom * const _atom = getAtomConst(_getAtomIndex());
    183   if ((_atom != NULL) && (_atom->getMolecule() != NULL)) {
    184     const moleculeId_t molid = _atom->getMolecule()->getId();
     181    const atom &_atom)
     182{
     183  if (_atom.getMolecule() != NULL) {
     184    const moleculeId_t molid = _atom.getMolecule()->getId();
    185185      QtObservedMolecule* mol = board.getObservedMolecule(molid).get();
    186186      if (mol != NULL)
     
    193193}
    194194
     195#ifdef HAVE_INLINE
     196inline
     197#endif
    195198std::string QtObservedAtom::updateName(
    196     const boost::function<const atomId_t ()> &_getAtomIndex)
    197 {
    198   const atom * const _atom = getAtomConst(_getAtomIndex());
    199   if (_atom != NULL) {
    200     return _atom->getName();
    201   } else {
    202     return std::string("");
    203   }
    204 }
    205 
     199    const atom &_atom)
     200{
     201  return _atom.getName();
     202}
     203
     204#ifdef HAVE_INLINE
     205inline
     206#endif
    206207Vector QtObservedAtom::updatePosition(
    207     const boost::function<const atomId_t ()> &_getAtomIndex)
    208 {
    209   const atom * const _atom = getAtomConst(_getAtomIndex());
    210   if (_atom != NULL) {
    211     return _atom->getPosition();
    212   } else {
    213     return zeroVec;
    214   }
    215 }
    216 
     208    const atom &_atom)
     209{
     210  return _atom.getPosition();
     211}
     212
     213#ifdef HAVE_INLINE
     214inline
     215#endif
    217216bool QtObservedAtom::updateSelected(
    218     const boost::function<const atomId_t ()> &_getAtomIndex)
    219 {
    220   const atom * const _atom = getAtomConst(_getAtomIndex());
    221   if (_atom != NULL) {
    222     return _atom->getSelected();
    223   } else {
    224     return false;
    225   }
     217    const atom &_atom)
     218{
     219  return _atom.getSelected();
    226220}
    227221
     
    353347  // fill ObservedValues: index first
    354348  const boost::function<atomId_t ()> AtomIndexUpdater(
    355       boost::bind(&QtObservedAtom::updateIndex));
     349      boost::bind(&QtObservedAtom::updateIndex, boost::cref(*_atomref)));
    356350
    357351  ObservedValue_wCallback<atomId_t> * const IndexObservable =
    358352      new ObservedValue_wCallback<atomId_t>(
    359353          _atomref,
    360           boost::bind(&QtObservedAtom::updateIndex),
     354          AtomIndexUpdater,
    361355          "AtomIndex_"+toString(_id),
    362356          _id,
     
    371365  // fill ObservedValues: then all the other that need index
    372366  const boost::function<ListOfBonds_t ()> AtomBondsUpdater(
    373       boost::bind(&QtObservedAtom::updateBonds, AtomIndexGetter));
     367      boost::bind(&QtObservedAtom::updateBonds, boost::cref(*_atomref)));
    374368  const boost::function<atomicNumber_t ()> AtomElementUpdater(
    375       boost::bind(&QtObservedAtom::updateElement, AtomIndexGetter));
     369      boost::bind(&QtObservedAtom::updateElement, boost::cref(*_atomref)));
    376370  const boost::function<QtObservedMolecule* ()> AtomMoleculeUpdater(
    377       boost::bind(&QtObservedAtom::updateMoleculeIndex, this, AtomIndexGetter));
     371      boost::bind(&QtObservedAtom::updateMoleculeIndex, this, boost::cref(*_atomref)));
    378372  const boost::function<std::string ()> AtomNameUpdater(
    379       boost::bind(&QtObservedAtom::updateName, AtomIndexGetter));
     373      boost::bind(&QtObservedAtom::updateName, boost::cref(*_atomref)));
    380374  const boost::function<Vector ()> AtomPositionUpdater(
    381       boost::bind(&QtObservedAtom::updatePosition, AtomIndexGetter));
     375      boost::bind(&QtObservedAtom::updatePosition, boost::cref(*_atomref)));
    382376  const boost::function<bool ()> AtomSelectedUpdater(
    383       boost::bind(&QtObservedAtom::updateSelected, AtomIndexGetter));
     377      boost::bind(&QtObservedAtom::updateSelected, boost::cref(*_atomref)));
    384378
    385379  _ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t, atomId_t>(
Note: See TracChangeset for help on using the changeset viewer.