Changeset f35f7e for src/UIElements


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.
Location:
src/UIElements/Qt4/InstanceBoard
Files:
4 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>(
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp

    rd845bd rf35f7e  
    151151
    152152private:
    153   static atomId_t updateIndex();
    154   static ListOfBonds_t updateBonds(
    155       const boost::function<const atomId_t ()> &_getAtomIndex);
    156   static atomicNumber_t updateElement(
    157       const boost::function<const atomId_t ()> &_getAtomIndex);
    158   QtObservedMolecule* updateMoleculeIndex(
    159       const boost::function<const atomId_t ()> &_getAtomIndex);
    160   static std::string updateName(
    161       const boost::function<const atomId_t ()> &_getAtomIndex);
    162   static Vector updatePosition(
    163       const boost::function<const atomId_t ()> &_getAtomIndex);
    164   static bool updateSelected(
    165       const boost::function<const atomId_t ()> &_getAtomIndex);
     153  static atomId_t updateIndex(const atom &_atomref);
     154  static ListOfBonds_t updateBonds(const atom &_atom);
     155  static atomicNumber_t updateElement(const atom &_atom);
     156  QtObservedMolecule* updateMoleculeIndex(const atom &_atom);
     157  static std::string updateName(const atom &_atom);
     158  static Vector updatePosition(const atom &_atom);
     159  static bool updateSelected(const atom &_atom);
    166160
    167161  //!> enumeration of observed values to match with entries in ObservedValues
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.cpp

    rd845bd rf35f7e  
    336336  // fill ObservedValues: index first
    337337  const boost::function<moleculeId_t ()> MolIndexUpdater(
    338       boost::bind(&QtObservedMolecule::updateIndex));
     338      boost::bind(&QtObservedMolecule::updateIndex, boost::cref(*_molref)));
    339339
    340340  ObservedValue_wCallback<moleculeId_t> * const IndexObservable =
     
    354354  // fill ObservedValues: then all the other that need index
    355355  const boost::function<int ()> AtomCountUpdater(
    356       boost::bind(&QtObservedMolecule::updateAtomCount, MolIndexGetter));
     356      boost::bind(&QtObservedMolecule::updateAtomCount, boost::cref(*_molref)));
    357357  const boost::function<int ()> BondCountUpdater(
    358       boost::bind(&QtObservedMolecule::updateBondCount, MolIndexGetter));
     358      boost::bind(&QtObservedMolecule::updateBondCount, boost::cref(*_molref)));
    359359  const boost::function<Vector ()> MolCenterUpdater(
    360       boost::bind(&QtObservedMolecule::updateCenter, MolIndexGetter));
     360      boost::bind(&QtObservedMolecule::updateCenter, boost::cref(*_molref)));
    361361  const boost::function<std::string ()> MolFormulaUpdater(
    362       boost::bind(&QtObservedMolecule::updateFormulaString, MolIndexGetter));
     362      boost::bind(&QtObservedMolecule::updateFormulaString, boost::cref(*_molref)));
    363363  const boost::function<std::string ()> MolNameUpdater(
    364       boost::bind(&QtObservedMolecule::updateName, MolIndexGetter));
     364      boost::bind(&QtObservedMolecule::updateName, boost::cref(*_molref)));
    365365  const boost::function<int ()> NonHydrogenCountUpdater(
    366       boost::bind(&QtObservedMolecule::updateNonHydrogenCount, MolIndexGetter));
     366      boost::bind(&QtObservedMolecule::updateNonHydrogenCount, boost::cref(*_molref)));
    367367  const boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater(
    368       boost::bind(&QtObservedMolecule::updateBoundingBox, MolIndexGetter));
     368      boost::bind(&QtObservedMolecule::updateBoundingBox, boost::cref(*_molref)));
    369369  const boost::function<bool ()> SelectedUpdater(
    370       boost::bind(&QtObservedMolecule::updateSelected, MolIndexGetter));
     370      boost::bind(&QtObservedMolecule::updateSelected, boost::cref(*_molref)));
    371371
    372372  _ObservedValues[AtomCount] = new ObservedValue_wCallback<int, moleculeId_t>(
     
    451451}
    452452
    453 int QtObservedMolecule::updateAtomCount(
    454     const boost::function<const moleculeId_t ()> &_getMolIndex)
    455 {
    456   const molecule * const mol = getMolecule(_getMolIndex());
    457   if (mol != NULL)
    458     return mol->getAtomCount();
    459   else
    460     return (int)0;
    461 }
    462 
    463 int QtObservedMolecule::updateBondCount(
    464     const boost::function<const moleculeId_t ()> &_getMolIndex)
    465 {
    466   const molecule * const mol = getMolecule(_getMolIndex());
    467   if (mol != NULL)
    468     return mol->getBondCount();
    469   else
    470     return (int)0;
    471 }
    472 
    473 molecule::BoundingBoxInfo QtObservedMolecule::updateBoundingBox(
    474     const boost::function<const moleculeId_t ()> &_getMolIndex)
    475 {
    476   const molecule * const mol = getMolecule(_getMolIndex());
    477   if (mol != NULL)
    478     return mol->getBoundingBox();
    479   else
    480     return molecule::BoundingBoxInfo();
    481 }
    482 
    483 std::string QtObservedMolecule::updateFormulaString(
    484     const boost::function<const moleculeId_t ()> &_getMolIndex)
    485 {
    486   const molecule * const mol = getMolecule(_getMolIndex());
    487   if (mol != NULL)
    488     return mol->getFormula().toString();
    489   else
    490     return std::string("");
    491 }
    492 
    493 Vector QtObservedMolecule::updateCenter(
    494     const boost::function<const moleculeId_t ()> &_getMolIndex)
    495 {
    496   const molecule * const mol = getMolecule(_getMolIndex());
    497   if (mol != NULL)
    498     return mol->DetermineCenterOfAll();
    499   else
    500     return zeroVec;
    501 }
    502 
    503 moleculeId_t QtObservedMolecule::updateIndex()
    504 {
    505   return const_cast<const World &>(World::getInstance()).lastChangedMolId();
    506 }
    507 
    508 std::string QtObservedMolecule::updateName(
    509     const boost::function<const moleculeId_t ()> &_getMolIndex)
    510 {
    511   const molecule * const mol = getMolecule(_getMolIndex());
    512   if (mol != NULL)
    513     return mol->getName();
    514   else
    515     return std::string("");
    516 }
    517 
    518 int QtObservedMolecule::updateNonHydrogenCount(
    519     const boost::function<const moleculeId_t ()> &_getMolIndex)
    520 {
    521   const molecule * const mol = getMolecule(_getMolIndex());
    522   if (mol != NULL)
    523     return mol->getNoNonHydrogen();
    524   else
    525     return (int)0;
    526 }
    527 
    528 bool QtObservedMolecule::updateSelected(
    529     const boost::function<const moleculeId_t ()> &_getMolIndex)
    530 {
    531   const molecule * const mol = getMolecule(_getMolIndex());
    532   if (mol != NULL)
    533     return mol->getSelected();
    534   else
    535     return false;
     453#ifdef HAVE_INLINE
     454inline
     455#endif
     456int QtObservedMolecule::updateAtomCount(const molecule &mol)
     457{
     458  return mol.getAtomCount();
     459}
     460
     461#ifdef HAVE_INLINE
     462inline
     463#endif
     464int QtObservedMolecule::updateBondCount(const molecule &mol)
     465{
     466  return mol.getBondCount();
     467}
     468
     469#ifdef HAVE_INLINE
     470inline
     471#endif
     472molecule::BoundingBoxInfo QtObservedMolecule::updateBoundingBox(const molecule &mol)
     473{
     474  return mol.getBoundingBox();
     475}
     476
     477#ifdef HAVE_INLINE
     478inline
     479#endif
     480std::string QtObservedMolecule::updateFormulaString(const molecule &mol)
     481{
     482  return mol.getFormula().toString();
     483}
     484
     485#ifdef HAVE_INLINE
     486inline
     487#endif
     488Vector QtObservedMolecule::updateCenter(const molecule &mol)
     489{
     490  return mol.DetermineCenterOfAll();
     491}
     492
     493#ifdef HAVE_INLINE
     494inline
     495#endif
     496moleculeId_t QtObservedMolecule::updateIndex(const molecule &mol)
     497{
     498  return mol.getId();
     499}
     500
     501#ifdef HAVE_INLINE
     502inline
     503#endif
     504std::string QtObservedMolecule::updateName(const molecule &mol)
     505{
     506  return mol.getName();
     507}
     508
     509#ifdef HAVE_INLINE
     510inline
     511#endif
     512int QtObservedMolecule::updateNonHydrogenCount(const molecule &mol)
     513{
     514  return mol.getNoNonHydrogen();
     515}
     516
     517#ifdef HAVE_INLINE
     518inline
     519#endif
     520bool QtObservedMolecule::updateSelected(const molecule &mol)
     521{
     522  return mol.getSelected();
    536523}
    537524
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp

    rd845bd rf35f7e  
    160160
    161161private:
    162   static int updateAtomCount(
    163       const boost::function<const moleculeId_t ()> &_getMolIndex);
    164   static int updateBondCount(
    165       const boost::function<const moleculeId_t ()> &_getMolIndex);
    166   static molecule::BoundingBoxInfo updateBoundingBox(
    167       const boost::function<const moleculeId_t ()> &_getMolIndex);
    168   static std::string updateFormulaString(
    169       const boost::function<const moleculeId_t ()> &_getMolIndex);
    170   static Vector updateCenter(
    171       const boost::function<const moleculeId_t ()> &_getMolIndex);
    172   static moleculeId_t updateIndex();
    173   static std::string updateName(
    174       const boost::function<const moleculeId_t ()> &_getMolIndex);
    175   static int updateNonHydrogenCount(
    176       const boost::function<const moleculeId_t ()> &_getMolIndex);
    177   static bool updateSelected(
    178       const boost::function<const moleculeId_t ()> &_getMolIndex);
     162  static int updateAtomCount(const molecule &mol);
     163  static int updateBondCount(const molecule &mol);
     164  static molecule::BoundingBoxInfo updateBoundingBox(const molecule &mol);
     165  static std::string updateFormulaString(const molecule &mol);
     166  static Vector updateCenter(const molecule &mol);
     167  static moleculeId_t updateIndex(const molecule &mol);
     168  static std::string updateName(const molecule &mol);
     169  static int updateNonHydrogenCount(const molecule &mol);
     170  static bool updateSelected(const molecule &mol);
    179171
    180172  //!> list of channels when atom count needs to update
Note: See TracChangeset for help on using the changeset viewer.