Changeset 4a328f for src/Atom


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:
5d8f4f
Parents:
7f1865d
git-author:
Frederik Heber <heber@…> (12/28/15 15:09:49)
git-committer:
Frederik Heber <heber@…> (02/11/16 08:06:49)
Message:

FIX: AtomObserver was not up-to-date with respect to atom's channels.

Location:
src/Atom
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Atom/AtomObserver.cpp

    r7f1865d r4a328f  
    5353  Observable::insertNotificationChannel( std::make_pair(static_cast<Observable *>(this), OurChannel) );
    5454  OurChannel->addChannel(AtomObservable::PositionChanged);
     55  OurChannel->addChannel(AtomObservable::VelocityChanged);
     56  OurChannel->addChannel(AtomObservable::ForceChanged);
     57  OurChannel->addChannel(AtomObservable::MoleculeChanged);
     58  OurChannel->addChannel(AtomObservable::NameChanged);
    5559  OurChannel->addChannel(AtomObservable::ElementChanged);
     60  OurChannel->addChannel(AtomObservable::IndexChanged);
     61  OurChannel->addChannel(AtomObservable::PropertyChanged);
     62  OurChannel->addChannel(AtomObservable::BondsAdded);
     63  OurChannel->addChannel(AtomObservable::BondsRemoved);
    5664  OurChannel->addChannel(AtomObservable::TrajectoryChanged);
     65  OurChannel->addChannel(AtomObservable::SelectionChanged);
    5766}
    5867
     
    7079{
    7180  res->signOn(this, AtomObservable::PositionChanged);
     81  res->signOn(this, AtomObservable::VelocityChanged);
     82  res->signOn(this, AtomObservable::ForceChanged);
     83  res->signOn(this, AtomObservable::MoleculeChanged);
     84  res->signOn(this, AtomObservable::NameChanged);
    7285  res->signOn(this, AtomObservable::ElementChanged);
     86  res->signOn(this, AtomObservable::IndexChanged);
     87  res->signOn(this, AtomObservable::PropertyChanged);
     88  res->signOn(this, AtomObservable::BondsAdded);
     89  res->signOn(this, AtomObservable::BondsRemoved);
    7390  res->signOn(this, AtomObservable::TrajectoryChanged);
     91  res->signOn(this, AtomObservable::SelectionChanged);
    7492}
    7593
     
    8199{
    82100  res->signOff(this, AtomObservable::PositionChanged);
     101  res->signOff(this, AtomObservable::VelocityChanged);
     102  res->signOff(this, AtomObservable::ForceChanged);
     103  res->signOff(this, AtomObservable::MoleculeChanged);
     104  res->signOff(this, AtomObservable::NameChanged);
    83105  res->signOff(this, AtomObservable::ElementChanged);
     106  res->signOff(this, AtomObservable::IndexChanged);
     107  res->signOff(this, AtomObservable::PropertyChanged);
     108  res->signOff(this, AtomObservable::BondsAdded);
     109  res->signOff(this, AtomObservable::BondsRemoved);
    84110  res->signOff(this, AtomObservable::TrajectoryChanged);
     111  res->signOff(this, AtomObservable::SelectionChanged);
    85112}
    86113
  • src/Atom/unittests/AtomObserverUnitTest.cpp

    r7f1865d r4a328f  
    6868  // observer checks that we don't receive general updates ...
    6969  observer = new UpdateCountObserver;
    70   // but only specific notifications in observer1 and observer2
    71   observer1 = new NotificationObserver(
    72       AtomObserver::getInstance().getChannel(AtomObservable::PositionChanged)
    73       );
    74   observer2 = new NotificationObserver(
    75       AtomObserver::getInstance().getChannel(AtomObservable::ElementChanged)
    76       );
     70  AtomObserver::getInstance().signOn(observer);
    7771
    78   AtomObserver::getInstance().signOn(observer);
    79   AtomObserver::getInstance().signOn(observer1, AtomObservable::PositionChanged);
    80   AtomObserver::getInstance().signOn(observer2, AtomObservable::ElementChanged);
     72  // but only specific notifications in others observers
     73  for (int i=0;i<AtomObservable::NotificationType_MAX; ++i) {
     74    specific_observers.push_back(new NotificationObserver(
     75          AtomObserver::getInstance().getChannel((enum AtomObservable::NotificationType)i)
     76          ));
     77    AtomObserver::getInstance().signOn(
     78        specific_observers.back(), (enum AtomObservable::NotificationType)i);
     79  }
     80
    8181
    8282  for(int i=0;i<ATOM_COUNT;++i){
     
    8989{
    9090  AtomObserver::getInstance().signOff(observer);
    91   AtomObserver::getInstance().signOff(observer1, AtomObservable::PositionChanged);
    92   AtomObserver::getInstance().signOff(observer2, AtomObservable::ElementChanged);
     91  for (int i=0;i<AtomObservable::NotificationType_MAX; ++i) {
     92    AtomObserver::getInstance().signOff(specific_observers[i], (enum AtomObservable::NotificationType)i);
     93    delete specific_observers[i];
     94  }
     95  specific_observers.clear();
    9396
    9497  delete observer;
    95   delete observer1;
    96   delete observer2;
    9798
    9899  World::purgeInstance();
     
    107108  // check for zero update
    108109  CPPUNIT_ASSERT_EQUAL( (int)0, observer->updates );
    109   CPPUNIT_ASSERT_EQUAL( false, observer1->wasNotified );
    110   CPPUNIT_ASSERT_EQUAL( false, observer2->wasNotified );
     110  for (int i=0;i<AtomObservable::NotificationType_MAX; ++i) {
     111
     112    CPPUNIT_ASSERT_EQUAL( false, specific_observers[i]->wasNotified );
     113  }
    111114}
    112115
     
    120123
    121124  // check for update
    122   CPPUNIT_ASSERT_EQUAL( true, observer1->wasNotified );
    123   CPPUNIT_ASSERT_EQUAL( false, observer2->wasNotified );
     125  for (int i=0;i<AtomObservable::NotificationType_MAX; ++i) {
     126    CPPUNIT_ASSERT_EQUAL( (enum AtomObservable::NotificationType)i == AtomObservable::PositionChanged,
     127        specific_observers[i]->wasNotified );
     128  }
    124129  CPPUNIT_ASSERT_EQUAL( (int)0, observer->updates );
    125130}
     
    134139
    135140  // check for update
    136   CPPUNIT_ASSERT_EQUAL( false, observer1->wasNotified );
    137   CPPUNIT_ASSERT_EQUAL( true, observer2->wasNotified );
     141  for (int i=0;i<AtomObservable::NotificationType_MAX; ++i) {
     142    CPPUNIT_ASSERT_EQUAL( (enum AtomObservable::NotificationType)i == AtomObservable::ElementChanged,
     143        specific_observers[i]->wasNotified );
     144  }
    138145  CPPUNIT_ASSERT_EQUAL( (int)0, observer->updates );
    139146}
  • src/Atom/unittests/AtomObserverUnitTest.hpp

    r7f1865d r4a328f  
    1616
    1717#include <cppunit/extensions/HelperMacros.h>
     18
     19#include <vector>
    1820
    1921#include "types.hpp"
     
    4850
    4951  UpdateCountObserver *observer;
    50   NotificationObserver *observer1;
    51   NotificationObserver *observer2;
     52  std::vector<NotificationObserver *> specific_observers;
    5253};
    5354
Note: See TracChangeset for help on using the changeset viewer.