Changeset 6a3c83


Ignore:
Timestamp:
Apr 6, 2012, 11:46:15 AM (13 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:
760c4c
Parents:
d25bec
git-author:
Frederik Heber <heber@…> (04/06/12 09:57:43)
git-committer:
Frederik Heber <heber@…> (04/06/12 11:46:15)
Message:

Cleaned observer structure in molecule.

  • FIX: Several OBSERVE were not needed, as update trigger was already contained in sub functions called in these routines.
  • Added NotificationType enumeration of channels: Atom insertion, atom removal, atom nr changes, and molecule name changes.
  • OBSERVE and NOTIFY used in the functions only where the direct change occurs.
Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    rd25bec r6a3c83  
    6767  last_atom(0)
    6868{
     69  // add specific channels
     70  Channels *OurChannel = new Channels;
     71  NotificationChannels.insert( std::make_pair( this, OurChannel) );
     72  for (size_t type = 0; type < (size_t)NotificationType_MAX; ++type)
     73    OurChannel->addChannel(type);
    6974
    7075  strcpy(name,World::getInstance().getDefaultName().c_str());
     
    107112void molecule::setName(const std::string _name){
    108113  OBSERVE;
     114  NOTIFY(MoleculeNameChanged);
    109115  cout << "Set name of molecule " << getId() << " to " << _name << endl;
    110116  strncpy(name,_name.c_str(),MAXSTRINGSIZE);
     
    114120  OBSERVE;
    115121  if(atomIdPool.reserveId(newNr)){
     122    NOTIFY(AtomNrChanged);
    116123    if (oldNr != -1)  // -1 is reserved and indicates no number
    117124      atomIdPool.releaseId(oldNr);
     
    172179{
    173180  OBSERVE;
     181  NOTIFY(AtomRemoved);
    174182  const_iterator iter = loc;
    175183  ++iter;
    176184  atom * const _atom = const_cast<atom *>(*loc);
    177185  atomIds.erase( _atom->getId() );
     186  {
     187    NOTIFY(AtomNrChanged);
     188    atomIdPool.releaseId(_atom->getNr());
     189    _atom->setNr(-1);
     190  }
    178191  formula-=_atom->getType();
    179192  _atom->removeFromMolecule();
     
    184197{
    185198  OBSERVE;
     199  NOTIFY(AtomRemoved);
    186200  const_iterator iter = find(key);
    187201  if (iter != end()){
    188202    ++iter;
    189203    atomIds.erase( key->getId() );
    190     atomIdPool.releaseId(key->getNr());
    191     key->setNr(-1);
     204    {
     205      NOTIFY(AtomNrChanged);
     206      atomIdPool.releaseId(key->getNr());
     207      key->setNr(-1);
     208    }
    192209    formula-=key->getType();
    193210    key->removeFromMolecule();
     
    199216{
    200217  OBSERVE;
     218  NOTIFY(AtomInserted);
    201219  std::pair<iterator,bool> res = atomIds.insert(key->getId());
    202220  if (res.second) { // push atom if went well
     221    NOTIFY(AtomNrChanged);
    203222    key->setNr(atomIdPool.getNextId());
    204223    setAtomName(key);
     
    232251bool molecule::AddAtom(atom *pointer)
    233252{
    234   OBSERVE;
    235253  if (pointer != NULL) {
    236254    insert(pointer);
     
    248266{
    249267  atom *retval = NULL;
    250   OBSERVE;
    251268  if (pointer != NULL) {
    252269    atom *walker = pointer->clone();
     
    298315//  Info info(__func__);
    299316  bool AllWentWell = true;    // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit
    300   OBSERVE;
    301317  double bondlength;  // bond length of the bond to be replaced/cut
    302318  double bondangle;  // bond angle of the bond to be replaced/cut
     
    656672bond * molecule::AddBond(atom *atom1, atom *atom2, int degree)
    657673{
    658   OBSERVE;
    659674  bond *Binder = NULL;
    660675
     
    748763{
    749764  ASSERT(pointer, "Null pointer passed to molecule::RemoveAtom().");
    750   OBSERVE;
    751765  RemoveBonds(pointer);
    752766  pointer->removeFromMolecule();
  • src/molecule.hpp

    rd25bec r6a3c83  
    9292  molecule();
    9393  virtual ~molecule();
     94
     95public:
     96
     97  /******* Notifications *******/
     98
     99  //!> enumeration of present notification types: only insertion/removal of atoms or molecules
     100  enum NotificationType {
     101    AtomInserted,
     102    AtomRemoved,
     103    AtomNrChanged,
     104    MoleculeNameChanged,
     105    NotificationType_MAX
     106  };
    94107
    95108public:
Note: See TracChangeset for help on using the changeset viewer.