Index: src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp
===================================================================
--- src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp	(revision a39d72c6d5edf5fa534720d234e4a54c6dcfc17a)
+++ src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp	(revision 8688ef11c8d02f39202bf756a4085f44860a00df)
@@ -57,4 +57,6 @@
 #include "WorldTime.hpp"
 
+#include "ObservedValue_wCallback.hpp"
+
 using namespace boost::assign;
 
@@ -80,30 +82,10 @@
   Observer(std::string("GLMoleculeObject_atom")+toString(_id)),
   atomref(getAtom(_id)),
-  AtomIndex(
-      atomref,
-      boost::bind(&GLMoleculeObject_atom::updateIndex, this),
-      "AtomIndex_"+toString(_id),
-      _id,
-      AtomIndexChannels),
-  AtomPosition(
-      atomref,
-      boost::bind(&GLMoleculeObject_atom::updatePosition, this),
-      "AtomPosition_"+toString(_id),
-      updatePosition(),
-      AtomPositionChannels),
-  AtomElement(
-      atomref,
-      boost::bind(&GLMoleculeObject_atom::updateElement, this),
-      "AtomElement"+toString(_id),
-      updateElement(),
-      AtomElementChannels),
-  AtomBonds(
-      atomref,
-      boost::bind(&GLMoleculeObject_atom::updateBonds, this),
-      "AtomBonds_"+toString(_id),
-      updateBonds(),
-      AtomBondsChannels),
+  ObservedValues(MAX_ObservedTypes),
+  subjectKilledCount(0),
   owner(NULL)
 {
+  initObservedValues(_id);
+
   setObjectId(_id);
   resetPosition();
@@ -154,9 +136,10 @@
 {
   deactivateObserver();
+  destroyObservedValues();
 }
 
 void GLMoleculeObject_atom::resetIndex()
 {
-  const atomId_t newId = AtomIndex.get();
+  const atomId_t newId = getAtomIndex();
   const size_t oldId = objectId();
   ASSERT( newId != oldId,
@@ -170,5 +153,5 @@
 void GLMoleculeObject_atom::resetPosition()
 {
-  const Vector Position = AtomPosition.get();
+  const Vector Position = getAtomPosition();
   LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
   setPosition(QVector3D(Position[0], Position[1], Position[2]));
@@ -179,5 +162,5 @@
   size_t elementno = 0;
   const element * const _type = World::getInstance().
-      getPeriode()->FindElement(AtomElement.get());
+      getPeriode()->FindElement(getAtomElement());
   if (_type != NULL) {
     elementno = _type->getAtomicNumber();
@@ -205,5 +188,5 @@
 void GLMoleculeObject_atom::resetBonds()
 {
-  ListOfBonds_t ListOfBonds_new = AtomBonds.get();
+  ListOfBonds_t ListOfBonds_new = getAtomBonds();
   std::sort(ListOfBonds_new.begin(), ListOfBonds_new.end());
   ListOfBonds_t BondsToAdd;
@@ -220,5 +203,5 @@
       iter != BondsToAdd.end();
       ++iter) {
-    const GLMoleculeObject_bond::SideOfBond side = (iter->first == AtomIndex.get()) ?
+    const GLMoleculeObject_bond::SideOfBond side = (iter->first == getAtomIndex()) ?
         GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
     emit BondsAdded(iter->first, iter->second, side);
@@ -259,6 +242,6 @@
 void GLMoleculeObject_atom::wasClicked()
 {
-  LOG(4, "INFO: GLMoleculeObject_atom: atom " << AtomIndex.get() << " has been clicked");
-  emit clicked(AtomIndex.get());
+  LOG(4, "INFO: GLMoleculeObject_atom: atom " << getAtomIndex() << " has been clicked");
+  emit clicked(getAtomIndex());
 }
 
@@ -283,5 +266,5 @@
 Vector GLMoleculeObject_atom::updatePosition() const
 {
-  const atom * const _atom = getAtom(AtomIndex.get());
+  const atom * const _atom = getAtom(getAtomIndex());
   if (_atom != NULL) {
     return _atom->getPosition();
@@ -293,5 +276,5 @@
 atomicNumber_t GLMoleculeObject_atom::updateElement() const
 {
-  const atom * const _atom = getAtom(AtomIndex.get());
+  const atom * const _atom = getAtom(getAtomIndex());
   if (_atom != NULL) {
     return _atom->getElementNo();
@@ -304,5 +287,5 @@
 {
   ListOfBonds_t ListOfBonds;
-  const atom * const _atom = getAtom(AtomIndex.get());
+  const atom * const _atom = getAtom(getAtomIndex());
   if (_atom != NULL) {
     // make sure position is up-to-date
@@ -315,5 +298,5 @@
           (*iter)->rightatom->getId()) );
   } else {
-    ELOG(2, "Atom with id "+toString(AtomIndex.get())+" is already gone.");
+    ELOG(2, "Atom with id "+toString(getAtomIndex())+" is already gone.");
   }
   return ListOfBonds;
@@ -328,4 +311,6 @@
 {
   deactivateObserver();
+
+  countsubjectKilled();
 }
 
@@ -357,2 +342,74 @@
     ASSERT(0, "GLMoleculeObject_atom::recieveNotification() - received notification from unexpected source.");
 }
+
+void GLMoleculeObject_atom::countsubjectKilled()
+{
+  ++subjectKilledCount;
+
+  if (subjectKilledCount > ObservedValues.size())
+    emit InstanceRemoved(getAtomIndex());
+}
+
+void GLMoleculeObject_atom::initObservedValues(const atomId_t _id)
+{
+  // fill ObservedValues
+  boost::function<void()> subjectKilled =
+      boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this);
+  ObservedValues[AtomIndex] = new ObservedValue_wCallback<atomId_t>(
+      atomref,
+      boost::bind(&GLMoleculeObject_atom::updateIndex, this),
+      "AtomIndex_"+toString(_id),
+      _id,
+      AtomIndexChannels,
+      subjectKilled);
+  ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector>(
+      atomref,
+      boost::bind(&GLMoleculeObject_atom::updatePosition, this),
+      "AtomPosition_"+toString(_id),
+      updatePosition(),
+      AtomPositionChannels,
+      subjectKilled);
+  ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t>(
+      atomref,
+      boost::bind(&GLMoleculeObject_atom::updateElement, this),
+      "AtomElement"+toString(_id),
+      updateElement(),
+      AtomElementChannels,
+      subjectKilled);
+  ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t>(
+      atomref,
+      boost::bind(&GLMoleculeObject_atom::updateBonds, this),
+      "AtomBonds_"+toString(_id),
+      updateBonds(),
+      AtomBondsChannels,
+      subjectKilled);
+}
+
+void GLMoleculeObject_atom::destroyObservedValues()
+{
+  delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex]);
+  delete boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[AtomPosition]);
+  delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[AtomElement]);
+  delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(ObservedValues[AtomBonds]);
+  ObservedValues.clear();
+}
+
+atomId_t GLMoleculeObject_atom::getAtomIndex() const
+{
+  return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex])->get();
+}
+
+Vector GLMoleculeObject_atom::getAtomPosition() const
+{
+  return boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[AtomPosition])->get();
+}
+
+atomicNumber_t GLMoleculeObject_atom::getAtomElement() const
+{
+  return boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[AtomElement])->get();
+}
+
+GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::getAtomBonds() const
+{
+  return boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(ObservedValues[AtomBonds])->get();
+}
