Changeset 7f1865d


Ignore:
Timestamp:
Feb 11, 2016, 8:06:49 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:
4a328f
Parents:
b71881
git-author:
Frederik Heber <heber@…> (12/28/15 06:28:10)
git-committer:
Frederik Heber <heber@…> (02/11/16 08:06:49)
Message:

Added template functions to (un)set vector of instances in a row.

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/World.cpp

    rb71881 r7f1865d  
    601601/************************** Selection of Atoms and molecules ******************/
    602602
     603// translate type's selection member functions to overloaded with specific type
     604
     605template <class T>
     606void World::selectVectorOfInstances(const typename T::iterator _begin, const typename T::iterator _end)
     607{
     608  std::for_each(_begin,_end,
     609      boost::bind(&World::selectInstance<typename T::value_type::second_type>,
     610          boost::bind(_take<typename T::value_type::second_type,typename T::value_type>::get, _1)));
     611}
     612
     613template <class T>
     614void World::unselectVectorOfInstances(const typename  T::iterator _begin, const typename T::iterator _end)
     615{
     616  std::for_each(_begin,_end,
     617      boost::bind(&World::unselectInstance<typename T::value_type::second_type>,
     618          boost::bind(_take<typename T::value_type::second_type,typename T::value_type>::get, _1)));
     619}
     620
    603621// Atoms
    604622
     
    606624  OBSERVE;
    607625  NOTIFY(SelectionChanged);
     626  unselectVectorOfInstances<AtomSet>(selectedAtoms.begin(), selectedAtoms.end());
    608627  selectedAtoms.clear();
    609628}
     
    618637  invertedSelection.erase(iter, invertedSelection.end());
    619638  // apply new selection
     639  unselectVectorOfInstances<AtomSet>(selectedAtoms.begin(), selectedAtoms.end());
    620640  selectedAtoms.clear();
    621641  void (World::*selector)(const atom*) = &World::selectAtom; // needed for type resolution of overloaded function
     
    630650  boost::function<void (const atomId_t)> IdSelector =
    631651      boost::bind(static_cast<void (World::*)(const atomId_t)>(&World::selectAtom), this, _1);
     652  unselectVectorOfInstances<AtomSet>(selectedAtoms.begin(), selectedAtoms.end());
    632653  selectedAtoms.clear();
    633654  std::for_each(atomids.begin(),atomids.end(), IdSelector);
     
    644665      atomids.begin());
    645666  selectedAtoms_Stack.push( atomids );
     667  unselectVectorOfInstances<AtomSet>(selectedAtoms.begin(), selectedAtoms.end());
    646668  selectedAtoms.clear();
    647669}
     
    652674  // atom * is unchanged in this function, but we do store entity as changeable
    653675  ASSERT(_atom,"Invalid pointer in selection of atom");
    654   selectedAtoms[_atom->getId()]=const_cast<atom *>(_atom);
     676  selectAtom(_atom->getId());
    655677}
    656678
     
    660682  ASSERT(atoms.count(id),"Atom Id selected that was not in the world");
    661683  selectedAtoms[id]=atoms[id];
     684  atoms[id]->select();
    662685}
    663686
     
    699722  NOTIFY(SelectionChanged);
    700723  ASSERT(atoms.count(id),"Atom Id unselected that was not in the world");
     724  atoms[id]->unselect();
    701725  selectedAtoms.erase(id);
    702726}
     
    736760
    737761bool World::isSelected(const atom *_atom) const {
    738   return isAtomSelected(_atom->getId());
     762  const bool status = isAtomSelected(_atom->getId());
     763   ASSERT( status == _atom->selected,
     764      "World::isSelected() - mismatch between selection state in atom "+
     765      toString(_atom->getId())+" and World.");
     766  return status;
    739767}
    740768
     
    778806  OBSERVE;
    779807  NOTIFY(SelectionChanged);
     808  unselectVectorOfInstances<MoleculeSet>(selectedMolecules.begin(), selectedMolecules.end());
    780809  selectedMolecules.clear();
    781810}
     
    791820  invertedSelection.erase(iter, invertedSelection.end());
    792821  // apply new selection
     822  unselectVectorOfInstances<MoleculeSet>(selectedMolecules.begin(), selectedMolecules.end());
    793823  selectedMolecules.clear();
    794824  void (World::*selector)(const molecule*) = &World::selectMolecule; // needed for type resolution of overloaded function
     
    803833  boost::function<void (const moleculeId_t)> IdSelector =
    804834      boost::bind(static_cast<void (World::*)(const moleculeId_t)>(&World::selectMolecule), this, _1);
     835  unselectVectorOfInstances<MoleculeSet>(selectedMolecules.begin(), selectedMolecules.end());
    805836  selectedMolecules.clear();
    806837  std::for_each(moleculeids.begin(),moleculeids.end(), IdSelector);
     
    819850      moleculeids.begin());
    820851  selectedMolecules_Stack.push( moleculeids );
     852  unselectVectorOfInstances<MoleculeSet>(selectedMolecules.begin(), selectedMolecules.end());
    821853  selectedMolecules.clear();
    822854}
     
    827859  // molecule * is unchanged in this function, but we do store entity as changeable
    828860  ASSERT(_mol,"Invalid pointer to molecule in selection");
    829   selectedMolecules[_mol->getId()]=const_cast<molecule *>(_mol);
     861  selectMolecule(_mol->getId());
    830862}
    831863
     
    834866  NOTIFY(SelectionChanged);
    835867  ASSERT(molecules.count(id),"Molecule Id selected that was not in the world");
     868  molecules[id]->select();
    836869  selectedMolecules[id]=molecules[id];
    837870}
     
    875908  NOTIFY(SelectionChanged);
    876909  ASSERT(molecules.count(id),"No such molecule with ID in unselection");
     910  molecules[id]->unselect();
    877911  selectedMolecules.erase(id);
    878912}
     
    913947
    914948bool World::isSelected(const molecule *_mol) const {
    915   return isMoleculeSelected(_mol->getId());
     949  const bool status = isMoleculeSelected(_mol->getId());
     950  ASSERT( status == _mol->selected,
     951      "World::isSelected() - mismatch in selection status between mol "+
     952      toString(_mol->getId())+" and World.");
     953  return status;
    916954}
    917955
  • src/World.hpp

    rb71881 r7f1865d  
    536536
    537537private:
     538  /** Helper to access atom::select() and molecule::select() only by type.
     539   *
     540   */
     541  template <class T>
     542  static void selectInstance(T _instance)
     543  { _instance->select(); }
     544
     545  /** Helper to access atom::unselect() and molecule::unselect() only by type.
     546   *
     547   */
     548  template <class T>
     549  static void unselectInstance(T _instance)
     550  { _instance->unselect(); }
     551
     552  /** Forward declaration of a helper function for selecting a vector of instances.
     553   *
     554   * \note only implemented inside World.
     555   *
     556   */
     557  template <class T>
     558  void selectVectorOfInstances(const typename T::iterator _begin, const typename T::iterator _end);
     559
     560  /** Forward declaration of a helper function for unselecting a vector of instances.
     561   *
     562   * \note only implemented inside World.
     563   *
     564   */
     565  template <class T>
     566  void unselectVectorOfInstances(const typename T::iterator _begin, const typename T::iterator _end);
     567
     568private:
    538569
    539570  friend const atom *detail::lastChanged<atom>();
Note: See TracChangeset for help on using the changeset viewer.