Changeset 9ef76a


Ignore:
Timestamp:
Feb 19, 2010, 11:49:54 AM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
01d28a
Parents:
5d4edf
Message:

Added a mechanism that allows the world to track changes done by the manipulators

Location:
molecuilder/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/Actions/ManipulateAtomsProcess.cpp

    r5d4edf r9ef76a  
    2323
    2424void ManipulateAtomsProcess::call(){
    25   World* world = World::get();
     25  World::get()->doManipulate(this);
     26}
     27
     28void ManipulateAtomsProcess::undo(){
     29
     30}
     31
     32bool ManipulateAtomsProcess::canUndo(){
     33  return false;
     34}
     35
     36void ManipulateAtomsProcess::doManipulate(World *world){
    2637  setMaxSteps(world->numAtoms());
    2738  start();
     
    3344  stop();
    3445}
    35 
    36 void ManipulateAtomsProcess::undo(){
    37 
    38 }
    39 
    40 bool ManipulateAtomsProcess::canUndo(){
    41   return false;
    42 }
  • molecuilder/src/Actions/ManipulateAtomsProcess.hpp

    r5d4edf r9ef76a  
    2121  virtual void undo();
    2222  virtual bool canUndo();
     23
     24  virtual void doManipulate(World *);
    2325private:
    2426  AtomDescriptor descr;
  • molecuilder/src/World.cpp

    r5d4edf r9ef76a  
    3737  return molecules_deprecated->ListOfMolecules.size();
    3838}
     39
     40/******************** Methods to change World state *********************/
    3941
    4042molecule* World::createMolecule(){
     
    5355}
    5456
     57/********************* Internal Change methods for double Callback and Observer mechanism ********/
     58
     59void World::doManipulate(ManipulateAtomsProcess *proc){
     60  proc->signOn(this);
     61  {
     62    OBSERVE;
     63    proc->doManipulate(this);
     64  }
     65  proc->signOff(this);
     66}
     67
    5568/******************************* Iterators ********************************/
    5669
  • molecuilder/src/World.hpp

    r5d4edf r9ef76a  
    8080  AtomList::iterator atomEnd();
    8181
     82  /******* Internal manipulation routines for double callback and Observer mechanism ******/
     83  void doManipulate(ManipulateAtomsProcess *);
     84
    8285private:
    8386  periodentafel *periode;
  • molecuilder/src/unittests/manipulateAtomsTest.cpp

    r5d4edf r9ef76a  
    4949};
    5050
     51class countObserver : public Observer{
     52public:
     53  countObserver() :
     54    count(0)
     55    {}
     56  virtual ~countObserver(){}
     57
     58  void update(Observable *){
     59    count++;
     60  }
     61
     62  void subjectKilled(Observable *)
     63  {}
     64
     65  int count;
     66};
    5167
    5268// set up and tear down
     
    131147}
    132148
     149void manipulateAtomsTest::testObserver(){
     150  countObserver *obs = new countObserver();
     151  World::get()->signOn(obs);
     152  ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
     153  proc->call();
     154
     155  CPPUNIT_ASSERT_EQUAL(1,obs->count);
     156  World::get()->signOff(obs);
     157  delete obs;
     158}
     159
    133160/********************************************** Main routine **************************************/
    134161
  • molecuilder/src/unittests/manipulateAtomsTest.hpp

    r5d4edf r9ef76a  
    2020  CPPUNIT_TEST ( testManipulateSimple );
    2121  CPPUNIT_TEST ( testManipulateExcluded );
     22  CPPUNIT_TEST ( testObserver );
    2223  CPPUNIT_TEST_SUITE_END();
    2324
     
    2829  void testManipulateSimple();
    2930  void testManipulateExcluded();
     31  void testObserver();
    3032
    3133private:
Note: See TracChangeset for help on using the changeset viewer.