Changeset 7188b1


Ignore:
Timestamp:
Oct 6, 2011, 4:06:10 PM (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:
db7e6d
Parents:
e638f9
git-author:
Frederik Heber <heber@…> (09/01/11 13:49:14)
git-committer:
Frederik Heber <heber@…> (10/06/11 16:06:10)
Message:

Introduced atom_observables and GLWorldView observes World, GLMoleculeObject_atom observes its atom.

Observer changes:

  • new Channels pattern required from CodePatterns 1.1.5 and that Observable signing on and off is now with const instance possible.
  • class atom is now observable, encapsulated in class AtomObservable:
    • enums have notification types
    • we use NotificationChannels of Observable to emit these distinct types.
  • atominfo, particleinfo, bondedparticleinfo all have OBSERVE and NOTIFY(..) in their setter functions (thx encapsulation).
  • class GLMoleculeObject_atom signs on to atom to changes to position, element, and index.
  • World equally has notifications for atom (new,remove) and molecules (new, remove).
  • GLWorldView now observes World for these changes.

Other changes:

  • removed additional hierarchy level for GLWidget of molecules (i.e. GLMoleculeScene removed and incorporated into GLWorldScene).
Files:
2 added
2 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • configure.ac

    re638f9 r7188b1  
    126126#AC_MSG_NOTICE(["GLU_CFLAGS: $GLU_CFLAGS, GLU_CXXFLAGS: $GLU_CXXFLAGS, GLU_LDFLAGS: $GLU_LDFLAGS, GLU_LIBS: $GLU_LIBS"])
    127127
    128 # CodePatterns library (needs operator<<(.., range<>) )
    129 AM_PATH_CODEPATTERNS([1.0.13], $have_debug,,[AC_MSG_ERROR([Missing CodePatterns library, please specify PKG_CONFIG_PATH or use --with-codepatterns...])])
     128# CodePatterns library (needs Observer::Channels )
     129AM_PATH_CODEPATTERNS([1.1.5], $have_debug,,[AC_MSG_ERROR([Missing CodePatterns library, please specify PKG_CONFIG_PATH or use --with-codepatterns...])])
    130130
    131131# Checks for header files.
  • src/Makefile.am

    re638f9 r7188b1  
    2525  atom_graphnode.cpp \
    2626  atom_graphnodeinfo.cpp \
     27  atom_observable.cpp \
    2728  atom_particleinfo.cpp
    2829ATOMHEADER = \
     
    3334  atom_graphnode.hpp \
    3435  atom_graphnodeinfo.hpp \
     36  atom_observable.hpp \
    3537  atom_particleinfo.hpp \
    3638  AtomicInfo.hpp \
  • src/UIElements/Makefile.am

    re638f9 r7188b1  
    195195        UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp \
    196196        UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp \
    197         UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp \
    198         UIElements/Views/Qt4/Qt3D/GLMoleculeScene.cpp
     197        UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp
    199198#  UIElements/Views/Qt4/dialoglight.cpp
    200199             
     
    226225        UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp \
    227226        UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp \
    228         UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp \
    229         UIElements/Views/Qt4/Qt3D/GLMoleculeScene.hpp
     227        UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp
    230228
    231229#QTUIUI_HEADER = \
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp

    re638f9 r7188b1  
    3535
    3636   //!> Allow it to call cleanMaterialMap()
    37    friend class GLMoleculeScene;
     37   friend class GLWorldScene;
    3838public:
    3939   explicit GLMoleculeObject(QGLSceneNode *GLMoleculeObject, QObject *parent=0);
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp

    re638f9 r7188b1  
    2727
    2828#include "CodePatterns/Assert.hpp"
     29#include "CodePatterns/Log.hpp"
    2930
     31#include "Descriptors/AtomIdDescriptor.hpp"
    3032#include "element.hpp"
    3133#include "LinearAlgebra/Vector.hpp"
    32 
     34#include "World.hpp"
    3335
    3436static QGLSceneNode * createAtom(QObject *parent)
     
    4244
    4345GLMoleculeObject_atom::GLMoleculeObject_atom(QObject *parent, const atom *atomref) :
    44   GLMoleculeObject(createAtom(parent), parent), _atom(atomref)
     46  GLMoleculeObject(createAtom(parent), parent), Observer("GLMoleculeObject_atom"), _atom(atomref)
     47{
     48  // sign on as observer (obtain non-const instance before)
     49  atomref->signOn(this, atomref->getChannel(AtomObservable::IndexChanged));
     50  atomref->signOn(this, atomref->getChannel(AtomObservable::PositionChanged));
     51  atomref->signOn(this, atomref->getChannel(AtomObservable::ElementChanged));
     52
     53  // set the object's id
     54  resetProperties();
     55
     56  std::cout << "Created sphere for atom " << _atom->getId() << "." << endl;
     57
     58  connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
     59}
     60
     61void GLMoleculeObject_atom::update(Observable *publisher)
     62{
     63  LOG(0, "GLMoleculeObject_atom::update() - called fro atom "+toString(_atom->getId())+".");
     64  resetProperties();
     65}
     66
     67void GLMoleculeObject_atom::resetPosition()
    4568{
    4669  const Vector Position = _atom->getPosition();
    47   const size_t elementno = _atom->getType()->getNumber();
     70  LOG(1, "GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
     71  setPosition(QVector3D(Position[0], Position[1], Position[2]));
     72}
     73
     74void GLMoleculeObject_atom::resetElement()
     75{
     76  size_t elementno = 0;
     77  if (_atom->getType() != NULL) {
     78    elementno = _atom->getType()->getNumber();
     79  } else { // if no element yet, set to hydrogen
     80    elementno = 1;
     81  }
     82  LOG(1, "GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
    4883
    4984  // set materials
     
    5792  setHoverMaterial(hovermaterial);
    5893
     94  // set scale
     95  double radius = 0.;
     96  if (_atom->getType() != NULL) {
     97    radius = _atom->getType()->getVanDerWaalsRadius();
     98  } else {
     99    radius = 0.5;
     100  }
     101  setScale( radius );
     102}
     103
     104void GLMoleculeObject_atom::resetIndex()
     105{
     106  const size_t atomno = _atom->getId();
     107  LOG(1, "GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomno)+".");
     108  setObjectId(atomno);
     109}
     110
     111void GLMoleculeObject_atom::resetProperties()
     112{
    59113  // set position
    60   setPosition(QVector3D(Position[0], Position[1], Position[2]));
     114  resetPosition();
    61115
    62   // set scale
    63   setScale( _atom->getType()->getVanDerWaalsRadius());
     116  // set element
     117  resetElement();
    64118
    65119  // set the object's id
    66   setObjectId(_atom->getId());
     120  resetIndex();
     121}
    67122
    68   std::cout << "Created sphere at " << Position << " with elementno " << elementno << "." << endl;
     123void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
     124{}
    69125
    70   connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
     126void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
     127{
     128  LOG(0, "GLMoleculeObject_atom::recieveNotification() - notification type "
     129      +toString(notification->getChannelNo())+".");
     130  switch (notification->getChannelNo()) {
     131    case AtomObservable::ElementChanged:
     132      resetElement();
     133      break;
     134    case AtomObservable::IndexChanged:
     135      resetIndex();
     136      break;
     137    case AtomObservable::PositionChanged:
     138      resetPosition();
     139      break;
     140    default:
     141      //setProperties();
     142      break;
     143  }
    71144}
    72145
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp

    re638f9 r7188b1  
    1616#include "GLMoleculeObject.hpp"
    1717
     18#include "CodePatterns/Observer.hpp"
     19
    1820#include "atom.hpp"
    1921
    20 class GLMoleculeObject_atom : public GLMoleculeObject
     22class GLMoleculeObject_atom : public GLMoleculeObject, public Observer
    2123{
    2224  Q_OBJECT
    2325public:
    2426  GLMoleculeObject_atom(QObject *parent, const atom *atomref);
    25   ~GLMoleculeObject_atom() {}
     27  virtual ~GLMoleculeObject_atom() {}
     28
     29  // Observer functions
     30  void update(Observable *publisher);
     31  void subjectKilled(Observable *publisher);
     32  void recieveNotification(Observable *publisher, Notification_ptr notification);
    2633
    2734private slots:
     
    3239
    3340private:
     41  void resetPosition();
     42  void resetElement();
     43  void resetIndex();
     44  void resetProperties();
     45
    3446  const atom *_atom;
    3547};
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp

    re638f9 r7188b1  
    5858      Position = _bond->leftatom->getPosition();
    5959      OtherPosition = _bond->rightatom->getPosition();
    60       elementno = _bond->leftatom->getType()->getNumber();
     60      if (_bond->leftatom->getType() != NULL) {
     61        elementno = _bond->leftatom->getType()->getNumber();
     62      } else { // if not element yet set, set to hydrogen
     63        elementno = 1;
     64      }
    6165      break;
    6266    case right:
    6367      Position = _bond->rightatom->getPosition();
    6468      OtherPosition = _bond->leftatom->getPosition();
    65       elementno = _bond->rightatom->getType()->getNumber();
     69      if (_bond->rightatom->getType() != NULL) {
     70        elementno = _bond->rightatom->getType()->getNumber();
     71      } else { // if not element yet set, set to hydrogen
     72        elementno = 1;
     73      }
     74
    6675      break;
    6776    default:
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp

    re638f9 r7188b1  
    2525
    2626  GLMoleculeObject_bond(QObject *parent, const bond *bondref, double distance, enum SideOfBond side);
    27   ~GLMoleculeObject_bond() {}
     27  virtual ~GLMoleculeObject_bond() {}
    2828
    2929
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    re638f9 r7188b1  
    2222#include "GLWorldScene.hpp"
    2323
    24 #include "GLMoleculeScene.hpp"
    2524#include "GLMoleculeObject.hpp"
     25#include "GLMoleculeObject_atom.hpp"
     26#include "GLMoleculeObject_bond.hpp"
    2627
    2728#include "CodePatterns/MemDebug.hpp"
    2829
     30#include "CodePatterns/Log.hpp"
     31
    2932#include "atom.hpp"
     33#include "Bond/bond.hpp"
    3034#include "molecule.hpp"
    3135#include "World.hpp"
     
    4145
    4246GLWorldScene::~GLWorldScene()
    43 {}
     47{
     48  // remove all elements
     49  GLMoleculeObject::cleanMaterialMap();
     50}
    4451
    4552/** Initialise the WorldScene with molecules and atoms from World.
     
    5562        Runner++) {
    5663      // create molecule
    57       GLMoleculeScene * const molObject = new GLMoleculeScene(this, *Runner);
    58       MoleculeSceneList.push_back(molObject);
    59       connect (molObject, SIGNAL(clicked(atomId_t, moleculeId_t)), this, SLOT(molClicked(atomId_t, moleculeId_t)));
    60       connect (molObject, SIGNAL(hoverChanged()), this, SIGNAL(changed()));
     64      for (molecule::const_iterator atomiter = (*Runner)->begin();
     65          atomiter != (*Runner)->end();
     66          ++atomiter) {
     67        // create atom objects in scene
     68        atomInserted(*atomiter);
     69
     70        // create its bonds
     71        const BondList &bonds = (*atomiter)->getListOfBonds();
     72        for (BondList::const_iterator bonditer = bonds.begin();
     73            bonditer != bonds.end();
     74            ++bonditer) {
     75          if ((*bonditer)->leftatom->getId() == (*atomiter)->getId()) {
     76            // create bond objects in scene
     77            bondInserted(*bonditer);
     78          }
     79        }
     80      }
    6181    }
    6282  }
    6383}
    6484
     85/** Adds an atom to the scene.
     86 *
     87 * @param _atom atom to add
     88 */
     89void GLWorldScene::atomInserted(const atom *_atom)
     90{
     91  LOG(0, "GLWorldScene: Received signal atomInserted for atom "+toString(_atom->getId())+".");
     92  GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(this, _atom);
     93  AtomNodeMap::iterator iter = AtomsinMoleculeMap.find(_atom->getId());
     94  ASSERT(iter == AtomsinMoleculeMap.end(),
     95      "GLWorldScene::atomAdded() - same atom "+_atom->getName()+" added again.");
     96  AtomsinMoleculeMap.insert( make_pair(_atom->getId(), atomObject) );
     97  connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
     98  connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(hoverChanged()));
     99  emit changed();
     100}
     101
     102/** Removes an atom from the scene.
     103 *
     104 * @param _atom atom to remove
     105 */
     106void GLWorldScene::atomRemoved(const atom *_atom)
     107{
     108  LOG(0, "GLWorldScene: Received signal atomRemoved for atom "+toString(_atom->getId())+".");
     109  // remove all its bonds
     110  const BondList& bondlist = _atom->getListOfBonds();
     111  for (BondList::const_iterator iter = bondlist.begin(); iter != bondlist.end(); ++iter) {
     112    bondRemoved(*iter);
     113  }
     114  // remove atoms
     115  AtomNodeMap::iterator iter = AtomsinMoleculeMap.find(_atom->getId());
     116  ASSERT(iter != AtomsinMoleculeMap.end(),
     117      "GLWorldScene::atomRemoved() - atom "+_atom->getName()+" not on display.");
     118  GLMoleculeObject_atom *atomObject = iter->second;
     119  atomObject->disconnect();
     120  AtomsinMoleculeMap.erase(iter);
     121  delete atomObject;
     122  emit changed();
     123}
     124
     125/** Adds an bond to the scene.
     126 *
     127 * @param _bond bond to add
     128 */
     129void GLWorldScene::bondInserted(const bond *_bond)
     130{
     131  const double distance =
     132      _bond->leftatom->getPosition().distance(_bond->rightatom->getPosition())/2.;
     133  {
     134    // left bond
     135    const BondIds Leftids( make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()) );
     136    BondNodeMap::iterator iter = BondsinMoleculeMap.find(Leftids);
     137    ASSERT(iter == BondsinMoleculeMap.end(),
     138        "GLWorldScene::bondAdded() - same left-sided bond "+toString(*_bond)+" added again.");
     139    GLMoleculeObject_bond *bondObject =
     140        new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::left);
     141    BondsinMoleculeMap.insert( make_pair(Leftids, bondObject) );
     142  }
     143  {
     144    // right bond
     145    const BondIds Rightids( make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()) );
     146    BondNodeMap::iterator iter = BondsinMoleculeMap.find(Rightids);
     147    ASSERT(iter == BondsinMoleculeMap.end(),
     148        "GLWorldScene::bondAdded() - same right-sided bond "+toString(*_bond)+" added again.");
     149    GLMoleculeObject_bond *bondObject =
     150        new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::right);
     151    BondsinMoleculeMap.insert( make_pair(Rightids, bondObject) );
     152  }
     153  emit changed();
     154}
     155
     156/** Removes an bond from the scene.
     157 *
     158 * @param _bond bond to remove
     159 */
     160void GLWorldScene::bondRemoved(const bond *_bond)
     161{
     162  {
     163    // left bond
     164    const BondIds Leftids( make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()) );
     165    BondNodeMap::iterator leftiter = BondsinMoleculeMap.find( Leftids );
     166    ASSERT(leftiter != BondsinMoleculeMap.end(),
     167        "GLWorldScene::bondRemoved() - bond "+toString(*_bond)+" not on display.");
     168    GLMoleculeObject_bond *bondObject = leftiter->second;
     169    BondsinMoleculeMap.erase(leftiter);
     170    delete bondObject;
     171  }
     172  {
     173    // right bond
     174    const BondIds Rightids( make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()) );
     175    BondNodeMap::iterator rightiter = BondsinMoleculeMap.find( Rightids );
     176    ASSERT(rightiter != BondsinMoleculeMap.end(),
     177        "GLWorldScene::bondRemoved() - bond "+toString(*_bond)+" not on display.");
     178    GLMoleculeObject_bond *bondObject = rightiter->second;
     179    BondsinMoleculeMap.erase(rightiter);
     180    delete bondObject;
     181  }
     182  emit changed();
     183}
     184
    65185void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
    66186{
    67   for (List_MoleculeScene::const_iterator iter = MoleculeSceneList.begin();
    68       iter != MoleculeSceneList.end();
    69       ++iter) {
    70     (*iter)->initialize(view, painter);
    71   }
    72 }
    73 
     187  // Initialize all of the mesh objects that we have as children.
     188   foreach (QObject *obj, children()) {
     189     GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
     190       if (meshobj)
     191         meshobj->initialize(view, painter);
     192   }
     193}
    74194
    75195void GLWorldScene::draw(QGLPainter *painter) const
    76196{
    77   for (List_MoleculeScene::const_iterator iter = MoleculeSceneList.begin();
    78       iter != MoleculeSceneList.end();
    79       ++iter) {
    80     (*iter)->draw(painter);
    81   }
    82 }
    83 
    84 void GLWorldScene::molClicked(atomId_t atom_no, moleculeId_t mol_no)
    85 {
    86    qDebug("WorldScene: atom %d of molecule %d has been clicked", atom_no, mol_no);
    87 }
    88 
     197   // Draw all of the mesh objects that we have as children.
     198   foreach (QObject *obj, children()) {
     199     GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
     200       if (meshobj)
     201         meshobj->draw(painter);
     202   }
     203}
     204
     205void GLWorldScene::atomClicked(atomId_t no)
     206{
     207   qDebug("GLWorldScene: atom %d has been clicked.", no);
     208   emit clicked(no);
     209}
     210
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    re638f9 r7188b1  
    1818#include <Qt/qobject.h>
    1919
    20 #include "atom.hpp"
    2120#include "molecule.hpp"
     21
     22class atom;
    2223
    2324class QGLPainter;
     
    2829class GLMoleculeObject_atom;
    2930class GLMoleculeObject_bond;
    30 class GLMoleculeScene;
    3131
    3232/** This class contains a list of all molecules in the world.
     
    5353signals:
    5454  void changed();
     55  void pressed();
     56  void released();
     57  void clicked();
     58  void clicked(atomId_t);
     59  void doubleClicked();
     60  void hoverChanged();
    5561
    5662private slots:
    57   void molClicked(atomId_t atom_no, moleculeId_t mol_no);
     63  void atomClicked(atomId_t no);
     64  void atomInserted(const atom *_atom);
     65  void atomRemoved(const atom *_atom);
     66  void bondInserted(const bond *_bond);
     67  void bondRemoved(const bond *_bond);
    5868
    5969private:
    6070  void init();
    6171
    62   typedef std::list< GLMoleculeScene * > List_MoleculeScene;
    63 
    64   List_MoleculeScene MoleculeSceneList;
     72  typedef std::pair< size_t, size_t> BondIds;
     73  typedef std::map< size_t, GLMoleculeObject_atom* > AtomNodeMap;
     74  typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap;
     75  AtomNodeMap AtomsinMoleculeMap;
     76  BondNodeMap BondsinMoleculeMap;
    6577};
    6678
  • src/UIElements/Views/Qt4/Qt3D/GLWorldView.cpp

    re638f9 r7188b1  
    2626#include "CodePatterns/MemDebug.hpp"
    2727
     28#include "CodePatterns/Log.hpp"
     29
     30#include "World.hpp"
     31
    2832GLWorldView::GLWorldView(QWidget *parent)
    29    : QGLView(parent), worldscene(NULL)
     33   : QGLView(parent), Observer("GLWorldView"), worldscene(NULL)
    3034{
    3135   worldscene = new GLWorldScene(this);
     
    3438
    3539   connect(worldscene, SIGNAL(changed()), this, SLOT(updateGL()));
     40   connect(this, SIGNAL(atomInserted(const atom *)), worldscene, SLOT(atomInserted(const atom *)));
     41   connect(this, SIGNAL(atomRemoved(const atom *)), worldscene, SLOT(atomRemoved(const atom *)));
     42   connect(this, SIGNAL(changed()), this, SLOT(updateGL()));
     43
     44   // sign on to changes in the world
     45   World::getInstance().signOn(this);
     46   World::getInstance().signOn(this, World::getInstance().getChannel(World::AtomInserted));
     47   World::getInstance().signOn(this, World::getInstance().getChannel(World::AtomRemoved));
    3648}
    3749
     
    4153}
    4254
     55/**
     56 * Update operation which can be invoked by the observable (which should be the
     57 * change tracker here).
     58 */
     59void GLWorldView::update(Observable *publisher)
     60{
     61  emit changed();
     62}
     63
     64/**
     65 * The observable can tell when it dies.
     66 */
     67void GLWorldView::subjectKilled(Observable *publisher) {}
     68
     69/** Listen to specific changes to the world.
     70 *
     71 * @param publisher ref to observable.
     72 * @param notification type of notification
     73 */
     74void GLWorldView::recieveNotification(Observable *publisher, Notification_ptr notification)
     75{
     76  switch (notification->getChannelNo()) {
     77    case World::AtomInserted:
     78    {
     79      const atom *_atom = World::getInstance().lastChanged<atom>();
     80      LOG(0, "GLWorldView: Received notification that atom "+toString(_atom->getId())+" has been inserted.");
     81      emit atomInserted(_atom);
     82      break;
     83    }
     84    case World::AtomRemoved:
     85    {
     86      const atom *_atom = World::getInstance().lastChanged<atom>();
     87      LOG(0, "GLWorldView: Received notification that atom "+toString(_atom->getId())+" has been removed.");
     88      emit atomRemoved(_atom);
     89      break;
     90    }
     91    default:
     92      ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here.");
     93      break;
     94  }
     95}
    4396
    4497void GLWorldView::initializeGL(QGLPainter *painter)
  • src/UIElements/Views/Qt4/Qt3D/GLWorldView.hpp

    re638f9 r7188b1  
    1616#include "qglview.h"
    1717
     18#include "CodePatterns/Observer.hpp"
     19
     20#include "World.hpp"
     21
    1822class QKeyEvent;
    1923class GLWorldScene;
     
    2428 *
    2529 */
    26 class GLWorldView : public QGLView
     30class GLWorldView : public QGLView, public Observer
    2731{
    2832  Q_OBJECT
     
    3135  virtual ~GLWorldView();
    3236
     37  // Observer functions
     38  void update(Observable *publisher);
     39  void subjectKilled(Observable *publisher);
     40  void recieveNotification(Observable *publisher, Notification_ptr notification);
     41
    3342public slots:
     43
     44signals:
     45  void changed();
     46  void atomInserted(const atom *_atom);
     47  void atomRemoved(const atom *_atom);
     48  void moleculeInserted(const molecule *_mol);
     49  void moleculeRemoved(const molecule *_mol);
    3450
    3551protected:
  • src/World.cpp

    re638f9 r7188b1  
    5252const unsigned int MAX_FRAGMENTATION_SKIPS=100;
    5353
     54/******************************* Notifications ************************/
     55
     56
     57atom* World::_lastchangedatom = NULL;
     58molecule* World::_lastchangedmol = NULL;
     59
    5460/******************************* getter and setter ************************/
    5561periodentafel *&World::getPeriode()
     
    173179  molecules[mol->getId()] = mol;
    174180  mol->signOn(this);
     181  _lastchangedmol = mol;
     182  NOTIFY(MoleculeInserted);
    175183  return mol;
    176184}
     
    186194  molecule *mol = molecules[id];
    187195  ASSERT(mol,"Molecule id that was meant to be destroyed did not exist");
     196  _lastchangedmol = mol;
     197  NOTIFY(MoleculeRemoved);
    188198  DeleteMolecule(mol);
    189199  molecules.erase(id);
     
    199209  // store the atom by ID
    200210  atoms[res->getId()] = res;
     211  _lastchangedatom = res;
     212  NOTIFY(AtomInserted);
    201213  return res;
    202214}
     
    222234  atom *atom = atoms[id];
    223235  ASSERT(atom,"Atom ID that was meant to be destroyed did not exist");
     236  _lastchangedatom = atom;
     237  NOTIFY(AtomRemoved);
    224238  DeleteAtom(atom);
    225239  atoms.erase(id);
     
    778792  cell_size->setM(domain);
    779793  defaultName = "none";
     794  NotificationChannels = new Channels(this);
     795  for (size_t type = 0; type < (size_t)NotificationType_MAX; ++type)
     796    NotificationChannels->addChannel(type);
    780797  molecules_deprecated->signOn(this);
    781798}
     
    796813  }
    797814  atoms.clear();
     815
     816  // empty notifications
     817  delete NotificationChannels;
     818
    798819  delete BG;
    799820  delete periode;
  • src/World.hpp

    re638f9 r7188b1  
    5555/********************************************** Class World *******************************/
    5656
     57namespace detail {
     58  template <class T> const T* lastChanged()
     59  {
     60    ASSERT(0, "detail::lastChanged() - only specializations may be used.");
     61    return NULL;
     62  }
     63}
     64
    5765class World : public Singleton<World>, public Observable
    5866{
     
    8492  typedef ATOMSET(std::vector) AtomComposite;
    8593
    86   /***** getter and setter *****/
     94    /******* Notifications *******/
     95
     96  //!> enumeration of present notification types
     97  enum NotificationType {
     98    AtomInserted,
     99    AtomRemoved,
     100    AtomChanged,
     101    MoleculeInserted,
     102    MoleculeRemoved,
     103    MoleculeChanged,
     104    NotificationType_MAX
     105  };
     106
     107  //>! access to last changed element (atom or molecule)
     108  template <class T> const T* lastChanged() const
     109  { return detail::lastChanged<T>(); }
     110
     111    /***** getter and setter *****/
    87112  // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
    88113  /**
     
    106131   */
    107132  config *&getConfig();
     133
     134  /** Returns a notification_ptr for a specific type.
     135   *
     136   * @param type request type
     137   * @return reference to instance
     138   */
     139  Notification_ptr getNotification(enum NotificationType type) const;
    108140
    109141  /**
     
    385417  void defragMoleculeIdPool();
    386418
     419  friend const atom *detail::lastChanged<atom>();
     420  friend const molecule *detail::lastChanged<molecule>();
     421  static atom *_lastchangedatom;
     422  static molecule*_lastchangedmol;
     423
    387424  BondGraph *BG;
    388425  periodentafel *periode;
     
    442479};
    443480
     481/** Externalized stuff as member functions cannot be specialized without
     482 *  specializing the class, too.
     483 */
     484namespace detail {
     485  template <>       inline  const atom* lastChanged<atom>() { return World::_lastchangedatom; }
     486  template <>       inline  const molecule* lastChanged<molecule>() { return World::_lastchangedmol; }
     487}
     488
     489
    444490#endif /* WORLD_HPP_ */
  • src/atom_atominfo.cpp

    re638f9 r7188b1  
    121121void AtomInfo::set(size_t i, const double value)
    122122{
     123  OBSERVE;
     124  NOTIFY(AtomObservable::PositionChanged);
    123125  ASSERT(AtomicPosition.size() > WorldTime::getTime(),
    124126      "AtomInfo::set() - Access out of range: "
     
    146148}
    147149
    148 void AtomInfo::setType(const element* _type) {
     150void AtomInfo::setType(const element* _type)
     151{
     152  OBSERVE;
     153  NOTIFY(AtomObservable::ElementChanged);
    149154  AtomicElement = _type;
    150155}
    151156
    152 void AtomInfo::setType(const int Z) {
     157void AtomInfo::setType(const int Z)
     158{
     159  OBSERVE;
     160  NOTIFY(AtomObservable::ElementChanged);
    153161  const element *elem = World::getInstance().getPeriode()->FindElement(Z);
    154162  setType(elem);
     
    187195void AtomInfo::setAtomicVelocity(const Vector &_newvelocity)
    188196{
     197  OBSERVE;
     198  NOTIFY(AtomObservable::VelocityChanged);
    189199  ASSERT(WorldTime::getTime() < AtomicVelocity.size(),
    190200      "AtomInfo::setAtomicVelocity() - Access out of range: "
     
    196206void AtomInfo::setAtomicVelocityAtStep(const unsigned int _step, const Vector &_newvelocity)
    197207{
     208  OBSERVE;
     209  if (WorldTime::getTime() == _step)
     210    NOTIFY(AtomObservable::VelocityChanged);
    198211  const unsigned int size = AtomicVelocity.size();
    199212  ASSERT(_step <= size,
     
    229242void AtomInfo::setAtomicForce(const Vector &_newforce)
    230243{
     244  OBSERVE;
     245  NOTIFY(AtomObservable::VelocityChanged);
    231246  ASSERT(WorldTime::getTime() < AtomicForce.size(),
    232247      "AtomInfo::setAtomicForce() - Access out of range: "
     
    238253void AtomInfo::setAtomicForceAtStep(const unsigned int _step, const Vector &_newforce)
    239254{
     255  OBSERVE;
     256  if (WorldTime::getTime() == _step)
     257    NOTIFY(AtomObservable::VelocityChanged);
    240258  const unsigned int size = AtomicForce.size();
    241259  ASSERT(_step <= size,
     
    258276void AtomInfo::setFixedIon(const bool _fixedion)
    259277{
     278  OBSERVE;
     279  NOTIFY(AtomObservable::PropertyChanged);
    260280  FixedIon = _fixedion;
    261281}
     
    263283void AtomInfo::setPosition(const Vector& _vector)
    264284{
     285  OBSERVE;
     286  NOTIFY(AtomObservable::PositionChanged);
    265287  ASSERT(WorldTime::getTime() < AtomicPosition.size(),
    266288      "AtomInfo::setPosition() - Access out of range: "
     
    273295void AtomInfo::setPositionAtStep(unsigned int _step, const Vector& _vector)
    274296{
     297  OBSERVE;
     298  if (WorldTime::getTime() == _step)
     299    NOTIFY(AtomObservable::PositionChanged);
    275300  const unsigned int size = AtomicPosition.size();
    276301  ASSERT(_step <= size,
     
    289314const VectorInterface& AtomInfo::operator+=(const Vector& b)
    290315{
     316  OBSERVE;
     317  NOTIFY(AtomObservable::PositionChanged);
    291318  ASSERT(WorldTime::getTime() < AtomicPosition.size(),
    292319      "AtomInfo::operator+=() - Access out of range: "
     
    299326const VectorInterface& AtomInfo::operator-=(const Vector& b)
    300327{
     328  OBSERVE;
     329  NOTIFY(AtomObservable::PositionChanged);
    301330  ASSERT(WorldTime::getTime() < AtomicPosition.size(),
    302331      "AtomInfo::operator-=() - Access out of range: "
     
    367396VectorInterface &AtomInfo::operator=(const Vector& _vector)
    368397{
     398  OBSERVE;
     399  NOTIFY(AtomObservable::PositionChanged);
    369400  ASSERT(WorldTime::getTime() < AtomicPosition.size(),
    370401      "AtomInfo::operator=() - Access out of range: "
     
    377408void AtomInfo::ScaleAll(const double *factor)
    378409{
     410  OBSERVE;
     411  NOTIFY(AtomObservable::PositionChanged);
    379412  ASSERT(WorldTime::getTime() < AtomicPosition.size(),
    380413      "AtomInfo::ScaleAll() - Access out of range: "
     
    386419void AtomInfo::ScaleAll(const Vector &factor)
    387420{
     421  OBSERVE;
     422  NOTIFY(AtomObservable::PositionChanged);
    388423  ASSERT(WorldTime::getTime() < AtomicPosition.size(),
    389424      "AtomInfo::ScaleAll() - Access out of range: "
     
    395430void AtomInfo::Scale(const double factor)
    396431{
     432  OBSERVE;
     433  NOTIFY(AtomObservable::PositionChanged);
    397434  ASSERT(WorldTime::getTime() < AtomicPosition.size(),
    398435      "AtomInfo::Scale() - Access out of range: "
     
    404441void AtomInfo::Zero()
    405442{
     443  OBSERVE;
     444  NOTIFY(AtomObservable::PositionChanged);
    406445  ASSERT(WorldTime::getTime() < AtomicPosition.size(),
    407446      "AtomInfo::Zero() - Access out of range: "
     
    413452void AtomInfo::One(const double one)
    414453{
     454  OBSERVE;
     455  NOTIFY(AtomObservable::PositionChanged);
    415456  ASSERT(WorldTime::getTime() < AtomicPosition.size(),
    416457      "AtomInfo::One() - Access out of range: "
     
    422463void AtomInfo::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors)
    423464{
     465  OBSERVE;
     466  NOTIFY(AtomObservable::PositionChanged);
    424467  ASSERT(WorldTime::getTime() < AtomicPosition.size(),
    425468      "AtomInfo::LinearCombinationOfVectors() - Access out of range: "
     
    432475 *  returns the kinetic energy of this atom at a given time step
    433476 */
    434 double AtomInfo::getKineticEnergy(const unsigned int _step) const{
     477double AtomInfo::getKineticEnergy(const unsigned int _step) const
     478{
    435479  ASSERT(_step < AtomicPosition.size(),
    436480      "AtomInfo::getKineticEnergy() - Access out of range: "
     
    440484}
    441485
    442 Vector AtomInfo::getMomentum(const unsigned int _step) const{
     486Vector AtomInfo::getMomentum(const unsigned int _step) const
     487{
    443488  ASSERT(_step < AtomicPosition.size(),
    444489      "AtomInfo::getMomentum() - Access out of range: "
     
    475520  if (dest == src)  // self assignment check
    476521    return;
     522
     523  if (WorldTime::getTime() == dest){
     524    NOTIFY(AtomObservable::PositionChanged);
     525    NOTIFY(AtomObservable::VelocityChanged);
     526    NOTIFY(AtomObservable::ForceChanged);
     527  }
    477528
    478529  ASSERT(dest < AtomicPosition.size(),
  • src/atom_atominfo.hpp

    re638f9 r7188b1  
    2121#include <vector>
    2222
     23#include "atom_observable.hpp"
     24
    2325#include "LinearAlgebra/Vector.hpp"
    2426#include "LinearAlgebra/VectorInterface.hpp"
     
    3335/********************************************** declarations *******************************/
    3436
    35 class AtomInfo : public VectorInterface {
     37class AtomInfo : public VectorInterface, public virtual AtomObservable {
    3638
    3739public:
  • src/atom_bondedparticleinfo.cpp

    re638f9 r7188b1  
    5656BondList& BondedParticleInfo::getListOfBonds()
    5757{
     58  // todo: here we actually need a container on whose destruction notifiy is emitted, i.e.
     59  // similar or simply an ObservedContainer.
     60  OBSERVE;
     61  NOTIFY(AtomObservable::BondsChanged);
    5862  const unsigned int size = ListOfBonds.size();
    5963  ASSERT(WorldTime::getTime() <= size,
  • src/atom_bondedparticleinfo.hpp

    re638f9 r7188b1  
    1919#endif
    2020
     21#include "atom_observable.hpp"
     22
    2123#include <list>
    2224
     
    3032/********************************************** declarations *******************************/
    3133
    32 class BondedParticleInfo {
     34class BondedParticleInfo  : public virtual AtomObservable {
    3335  friend class BondedParticle;
    3436public:
  • src/atom_particleinfo.cpp

    re638f9 r7188b1  
    4747
    4848void ParticleInfo::setName(const string& _name){
     49  OBSERVE;
     50  NOTIFY(AtomObservable::NameChanged);
    4951  name = _name;
    5052}
     
    6365void ParticleInfo::setNr(const int newnr)
    6466{
     67  OBSERVE;
     68  NOTIFY(AtomObservable::PropertyChanged);
    6569  Nr = newnr;
    6670}
  • src/atom_particleinfo.hpp

    re638f9 r7188b1  
    1818#endif
    1919
     20#include "atom_observable.hpp"
     21
    2022#include <iosfwd>
    2123#include <string>
     
    2628/********************************************** declarations *******************************/
    2729
    28 class ParticleInfo {
     30class ParticleInfo : public virtual AtomObservable {
    2931public:
    3032  ParticleInfo();
Note: See TracChangeset for help on using the changeset viewer.