Changeset f1b5ca for src/UIElements


Ignore:
Timestamp:
Apr 20, 2016, 11:07:46 PM (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:
7f185f9
Parents:
785d89
git-author:
Frederik Heber <heber@…> (04/12/16 08:51:06)
git-committer:
Frederik Heber <heber@…> (04/20/16 23:07:46)
Message:

Only GLWorldScene creates stuff, GLMoleculeObject_.. are just visual reps.

Location:
src/UIElements/Views/Qt4/Qt3D
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    r785d89 rf1b5ca  
    4343
    4444#include "CodePatterns/MemDebug.hpp"
    45 
    46 #include <boost/assign.hpp>
    4745
    4846#include "CodePatterns/Assert.hpp"
     
    6159#include "World.hpp"
    6260
    63 using namespace boost::assign;
    64 
    65 static Observable::channels_t getAllAtomicChangesChannels()
    66 {
    67   Observable::channels_t channels;
    68   channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
    69   return channels;
    70 }
    71 
    72 const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels());
    73 
    7461static QGLSceneNode *createMoleculeMesh(const QGeometryData &_geo)
    7562{
     
    8370GLMoleculeObject_molecule::GLMoleculeObject_molecule(
    8471    QObject *parent,
    85     QtObservedInstanceBoard &_board,
    8672    QtObservedMolecule::ptr &_ObservedMolecule) :
    8773  GLMoleculeObject((QGLSceneNode *)NULL, parent),
    88   owner(NULL),
    8974  hoverAtomId(-1),
    90   board(_board),
    9175  ObservedMolecule(_ObservedMolecule)
    9276{
     
    9781    QGLSceneNode *mesh[],
    9882    QObject *parent,
    99     QtObservedInstanceBoard &_board,
    10083    QtObservedMolecule::ptr &_ObservedMolecule) :
    10184  GLMoleculeObject(mesh, parent),
    102   owner(NULL),
    10385  hoverAtomId(-1),
    104   board(_board),
    10586  ObservedMolecule(_ObservedMolecule)
    10687{
     
    11899  m_visible = false;
    119100
    120   connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
    121   connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
    122101  connect (ObservedMolecule.get(), SIGNAL(tesselationhullChanged()), this, SLOT(resetTesselationHull()));
    123102  connect (ObservedMolecule.get(), SIGNAL(boundingboxChanged()), this, SLOT(resetBoundingBox()));
     
    130109//      this, SLOT(atomRemoved(const atomId_t)) );
    131110  connect (ObservedMolecule.get(), SIGNAL(selectedChanged()), this, SLOT(resetSelected()));
    132 
    133   connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
    134111}
    135112
     
    152129  // check minimum bond radius in molecule
    153130  double minlength = std::numeric_limits<double>::max();
     131  size_t NoAtoms = 0;
    154132  for (molecule::const_iterator iter = molref->begin();
    155133      iter != molref->end(); ++iter) {
     
    160138      minlength = std::min(bond_distance, minlength);
    161139    }
     140    ++NoAtoms;
    162141  }
    163142  minradius = std::max( std::max(minradius, minlength), 1.);
    164143
    165144  // we need at least three points for tesselation
    166   if (AtomsinSceneMap.size() >= 3) {
     145  if (NoAtoms >= 3) {
    167146    // Tesselate the points.
    168147    Tesselation T;
     
    218197void GLMoleculeObject_molecule::resetTesselationHull()
    219198{
    220   if (owner != NULL) {
    221     TesselationHull = updateTesselationHull();
    222     updateMesh(createMoleculeMesh(TesselationHull));
    223   }
     199  TesselationHull = updateTesselationHull();
     200  updateMesh(createMoleculeMesh(TesselationHull));
    224201}
    225202
     
    334311}
    335312
    336 /** Adds an atom of this molecule to the scene.
    337  *
    338  * @param _atom atom to add
    339  */
    340 void GLMoleculeObject_molecule::atomInserted(QtObservedAtom::ptr _atom)
    341 {
    342   const ObservedValue_Index_t atomid = _atom->getIndex();
    343   LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomInserted for atom "
    344       << _atom->getAtomIndex());
    345 
    346   if (_atom) {
    347     GLMoleculeObject_atom *atomObject =
    348         new GLMoleculeObject_atom(
    349             GLMoleculeObject::meshSphere,
    350             this,
    351             _atom);
    352     ASSERT( atomObject != NULL,
    353         "GLMoleculeObject_molecule::atomInserted - could not create atom object for "
    354         +toString(_atom->getAtomIndex()));
    355     AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid);
    356     ASSERT(iter == AtomsinSceneMap.end(),
    357         "GLMoleculeObject_molecule::atomInserted - same atom with id "
    358         +toString(_atom->getAtomIndex())+" added again.");
    359     AtomsinSceneMap.insert( make_pair(atomid, atomObject) );
    360 
    361     qRegisterMetaType<atomId_t>("atomId_t");
    362     qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
    363     connect (atomObject, SIGNAL(clicked(atomId_t)), this, SIGNAL(atomClicked(atomId_t)));
    364     connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
    365     connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
    366     connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
    367 
    368     if (m_objectId  == -1)
    369       setObjectId(_atom->getAtomIndex());
    370 
    371     emit changed();
    372     emit changeOccured();
    373   }
    374 }
    375 
    376 /** Removes an atom of this molecule from the scene.
    377  *
    378  * We just the id as the atom might have already been destroyed.
    379  *
    380  * @param _id id of atom to remove
    381  */
    382 void GLMoleculeObject_molecule::atomRemoved(ObservedValue_Index_t _id)
    383 {
    384   LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomRemoved for atom "+toString(_id)+".");
    385   // bonds are removed by signal coming from ~bond
    386 
    387   // remove atoms
    388   AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
    389   ASSERT(iter != AtomsinSceneMap.end(),
    390       "GLMoleculeObject_molecule::atomRemoved() - atom "+toString(_id)+" not on display.");
    391   GLMoleculeObject_atom *atomObject = iter->second;
    392   AtomsinSceneMap.erase(iter);
    393   atomObject->disconnect();
    394   delete atomObject;
    395 
    396   emit changed();
    397   emit changeOccured();
    398 
    399   if (AtomsinSceneMap.empty())
    400     emit moleculeEmptied(ObservedMolecule);
    401 }
    402 
    403 void GLMoleculeObject_molecule::hoverChangedSignalled(GLMoleculeObject *ob)
    404 {
    405   // Find the atom, ob corresponds to.
    406   hoverAtomId = -1;
    407   GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
    408   if (atomObject){
    409     for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
    410       if (iter->second == atomObject)
    411         hoverAtomId = iter->second->objectId();
    412     }
    413 
    414     // Propagate signal.
    415     emit hoverChanged(hoverAtomId);
    416   } else {
    417     // Find the atom, ob corresponds to.
    418     GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob);
    419     if (moleculeObject == this){
    420       // Propagate signal.
    421       emit hoverChanged(ObservedMolecule->getMolIndex(), 0);
    422     }
    423   }
    424 }
    425 
    426 /** Adds a bond to the scene.
    427  *
    428  * @param _bond bond to add
    429  */
    430 void GLMoleculeObject_molecule::bondInserted(
    431     QtObservedBond::ptr _bond)
    432 {
    433   static const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides =
    434       boost::assign::list_of<GLMoleculeObject_bond::SideOfBond>
    435           (GLMoleculeObject_bond::left)
    436           (GLMoleculeObject_bond::right);
    437   LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bonds " << _bond->getBondIndex());
    438   //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
    439 
    440   const ObservedValue_Index_t bondid = _bond->getIndex();
    441   const std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =
    442       BondsinSceneMap.equal_range(bondid);
    443   if (iters.first == iters.second) {
    444     for (size_t i=0;i<2;++i) {
    445       GLMoleculeObject_bond * bondObject =
    446           new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, _bond, bondsides[i]);
    447       connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
    448       BondsinSceneMap.insert( std::make_pair(bondid, bondObject) );
    449     }
    450   } else {
    451     for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {
    452       iter->second->resetPosition();
    453       iter->second->resetWidth();
    454     }
    455   }
    456   emit changed();
    457   emit changeOccured();
    458 }
    459 
    460 /** Removes a bond from the scene.
    461  *
    462  * @param _bond bond to remove
    463  */
    464 void GLMoleculeObject_molecule::bondRemoved(ObservedValue_Index_t _id)
    465 {
    466   LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond to id " << _id);
    467   {
    468     // left bond
    469     const std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =
    470         BondsinSceneMap.equal_range(_id);
    471     for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {
    472       GLMoleculeObject_bond *bondObject = iter->second;
    473       bondObject->disconnect();
    474       delete bondObject; // is done by signal from bond itself
    475       //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
    476     }
    477     BondsinSceneMap.erase(_id);
    478   }
    479 
    480   emit changed();
    481   emit changeOccured();
    482 }
    483 
    484313void GLMoleculeObject_molecule::setVisible(bool value)
    485314{
     
    499328  return ost;
    500329}
    501 
    502 void GLMoleculeObject_molecule::wasClicked()
    503 {
    504   LOG(4, "INFO: GLMoleculeObject_molecule: atom "
    505       << ObservedMolecule->getMolIndex() << " has been clicked");
    506   emit moleculeClicked(ObservedMolecule->getMolIndex());
    507 }
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp

    r785d89 rf1b5ca  
    4141  GLMoleculeObject_molecule(
    4242      QObject *parent,
    43       QtObservedInstanceBoard &_board,
    4443      QtObservedMolecule::ptr &_ObservedMolecule);
    4544  GLMoleculeObject_molecule(
    4645      QGLSceneNode *mesh[],
    4746      QObject *parent,
    48       QtObservedInstanceBoard &_board,
    4947      QtObservedMolecule::ptr &_ObservedMolecule);
    5048  virtual ~GLMoleculeObject_molecule();
     
    5957  void changed();
    6058  void changeOccured();
    61   void hoverChanged(const atomId_t);
    62   void hoverChanged(const moleculeId_t, int);
    63   void atomClicked(atomId_t);
    64   void moleculeClicked(moleculeId_t);
    65   void moleculeEmptied(QtObservedMolecule::ptr);
    66   void IsSelectedChanged();
    6759
    6860private slots:
    6961  //!> grant GLWorldScene access to private slots
    7062  friend class GLWorldScene;
    71 
    72   void wasClicked();
    73   void atomInserted(QtObservedAtom::ptr _atom);
    74   void atomRemoved(ObservedValue_Index_t _id);
    75   void bondInserted(QtObservedBond::ptr _bond);
    76   void bondRemoved(ObservedValue_Index_t _id);
    77   void hoverChangedSignalled(GLMoleculeObject *ob);
    7863
    7964  void setVisible(bool value);
     
    9075private:
    9176
    92   //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
    93   const Observable * owner;
    94 
    9577  QGeometryData updateTesselationHull() const;
    96 
    97   //!> list of channels when tesselation hull needs to update
    98   static const Observable::channels_t HullChannels;
    9978
    10079  //!> contains current version of the tesselation hull on request
    10180  QGeometryData TesselationHull;
    10281
    103   typedef std::map< ObservedValue_Index_t, GLMoleculeObject_atom* > AtomNodeMap;
    104   typedef std::multimap< ObservedValue_Index_t, GLMoleculeObject_bond* > BondNodeMap;
    105   AtomNodeMap AtomsinSceneMap;
    106   BondNodeMap BondsinSceneMap;
    10782
    10883  atomId_t hoverAtomId;
    109 
    110   QtObservedInstanceBoard &board;
    11184
    11285  QtObservedMolecule::ptr ObservedMolecule;
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    r785d89 rf1b5ca  
    5454
    5555#include "CodePatterns/Log.hpp"
     56
     57#include <boost/assign.hpp>
    5658
    5759#include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
     
    7981  board(_board)
    8082{
     83  qRegisterMetaType<atomId_t>("atomId_t");
     84  qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
     85
    8186  int sphereDetails[] = {5, 3, 2, 0};
    8287  int cylinderDetails[] = {16, 8, 6, 3};
     
    9499  }
    95100  connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
    96       this, SLOT(moleculeSignOn(QtObservedMolecule::ptr)), Qt::DirectConnection);
     101      this, SLOT(moleculeInserted(QtObservedMolecule::ptr)));
    97102  connect(board, SIGNAL(moleculeRemoved(ObservedValue_Index_t)),
    98       this, SLOT(moleculeSignOff(ObservedValue_Index_t)), Qt::DirectConnection);
     103      this, SLOT(moleculeRemoved(ObservedValue_Index_t)));
    99104  connect(board, SIGNAL(atomInserted(QtObservedAtom::ptr)),
    100105      this, SLOT(atomInserted(QtObservedAtom::ptr)));
     
    105110  connect(board, SIGNAL(bondRemoved(ObservedValue_Index_t)),
    106111      this, SLOT(bondRemoved(ObservedValue_Index_t)));
    107   connect(this, SIGNAL(insertMolecule(QtObservedMolecule::ptr)),
    108       this, SLOT(moleculeInserted(QtObservedMolecule::ptr)) );
    109   connect(this, SIGNAL(removeMolecule(QtObservedMolecule*)),
    110       this, SLOT(moleculeRemoved(QtObservedMolecule*)) );
    111112
    112113//  connect(this, SIGNAL(updated()), this, SLOT(update()));
     
    143144}
    144145
     146/** Adds an atom to the scene.
     147 *
     148 * @param _atom atom to add
     149 */
     150void GLWorldScene::atomInserted(QtObservedAtom::ptr _atom)
     151{
     152  LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "
     153      << _atom->getAtomIndex());
     154
     155  GLMoleculeObject_atom *atomObject =
     156      new GLMoleculeObject_atom(
     157          GLMoleculeObject::meshSphere,
     158          this, /* parent is GLWorldScene */
     159          _atom);
     160  ASSERT( atomObject != NULL,
     161      "GLWorldScene::atomInserted - could not create atom object for "
     162      +toString(_atom->getAtomIndex()));
     163  const ObservedValue_Index_t atomid = _atom->getIndex();
     164  AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid);
     165  ASSERT(iter == AtomsinSceneMap.end(),
     166      "GLWorldScene::atomInserted - same atom with id "
     167      +toString(_atom->getAtomIndex())+" added again.");
     168  AtomsinSceneMap.insert( make_pair(atomid, atomObject) );
     169
     170  connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
     171  connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
     172  connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
     173  connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
     174
     175  emit changed();
     176  emit changeOccured();
     177}
     178
     179/** Removes an atom.
     180 *
     181 * @param _atomid index of the atom that is removed
     182 */
     183void GLWorldScene::atomRemoved(ObservedValue_Index_t _atomid)
     184{
     185  LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
     186  // bonds are removed by signal coming from ~bond
     187
     188  // remove atoms
     189  AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atomid);
     190  ASSERT(iter != AtomsinSceneMap.end(),
     191      "GLWorldScene::atomRemoved() - atom "+toString(_atomid)+" not on display.");
     192  GLMoleculeObject_atom *atomObject = iter->second;
     193  AtomsinSceneMap.erase(iter);
     194  delete atomObject;
     195
     196  emit changed();
     197  emit changeOccured();
     198}
     199
     200/** Adds a bond to the scene.
     201 *
     202 * @param _bond bond to add
     203 */
     204void GLWorldScene::bondInserted(QtObservedBond::ptr _bond)
     205{
     206  static const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides =
     207      boost::assign::list_of<GLMoleculeObject_bond::SideOfBond>
     208          (GLMoleculeObject_bond::left)
     209          (GLMoleculeObject_bond::right);
     210  LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bonds " << _bond->getBondIndex());
     211  //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
     212
     213  const ObservedValue_Index_t bondid = _bond->getIndex();
     214  BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
     215  ASSERT( iter == BondsinSceneMap.end(),
     216      "GLWorldScene::bondInserted() - bond "+toString(bondid)+" is already known.");
     217  for (size_t i=0;i<2;++i) {
     218    GLMoleculeObject_bond * bondObject =
     219        new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, _bond, bondsides[i]);
     220    connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
     221    BondsinSceneMap.insert( std::make_pair(bondid, bondObject) );
     222  }
     223
     224  emit changed();
     225  emit changeOccured();
     226}
     227
     228/** Removes a bond.
     229 *
     230 * @param _bondid id of bond to remove
     231 */
     232void GLWorldScene::bondRemoved(ObservedValue_Index_t _bondid)
     233{
     234  LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond to id " << _bondid);
     235
     236  // left bond
     237  BondNodeMap::iterator iter = BondsinSceneMap.find(_bondid);
     238  ASSERT( iter != BondsinSceneMap.end(),
     239      "GLWorldScene::bondRemoved() - could not find bond to id "+toString(_bondid));
     240  GLMoleculeObject_bond *bondObject = iter->second;
     241  delete bondObject; // is done by signal from bond itself
     242  //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
     243  BondsinSceneMap.erase(iter);
     244
     245  emit changed();
     246  emit changeOccured();
     247}
     248
     249void GLWorldScene::hoverChangedSignalled(GLMoleculeObject *ob)
     250{
     251  // Find the atom, ob corresponds to.
     252  hoverAtomId = -1;
     253  GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
     254  if (atomObject){
     255    for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
     256      if (iter->second == atomObject)
     257        hoverAtomId = iter->second->objectId();
     258    }
     259
     260    // Propagate signal.
     261    emit hoverChanged(hoverAtomId);
     262  } else {
     263    // Find the atom, ob corresponds to.
     264    GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob);
     265    if (moleculeObject){
     266      // Propagate signal.
     267      emit hoverChanged(moleculeObject->objectId(), 0);
     268    }
     269  }
     270}
     271
    145272void GLWorldScene::moleculeClicked(moleculeId_t no)
    146273{
     
    157284}
    158285
    159 /** Prepares insertion of a general atom.
    160  *
    161  * This is called before the insertion into a molecule and thus before the
    162  * insertion into the scene.
    163  *
    164  * @param _atom atom to insert
    165  */
    166 void GLWorldScene::atomInserted(QtObservedAtom::ptr _atom)
    167 {
    168   const ObservedValue_Index_t atomid = _atom->getIndex();
    169   ASSERT( QtObservedAtomMap.find(atomid) == QtObservedAtomMap.end(),
    170       "GLWorldScene::AtomInserted() - atom with id "+toString(_atom->getAtomIndex())
    171       +" is already present in QtObservedAtomMap.");
    172   QtObservedAtomMap[atomid] = _atom;
    173 }
    174 
    175 /** Removes an general atom.
    176  *
    177  * This is called when the atom has been removed from the molecule.
    178  *
    179  * @param _atom atom to remove
    180  */
    181 void GLWorldScene::atomRemoved(ObservedValue_Index_t _atomid)
    182 {
    183   const QtObservedAtomMap_t::iterator eraseiter = QtObservedAtomMap.find(_atomid);
    184   ASSERT( eraseiter != QtObservedAtomMap.end(),
    185       "GLWorldScene::AtomRemoved() - atom with id "+toString(_atomid)
    186       +" is not present in QtObservedAtomMap.");
    187   QtObservedAtomMap.erase(eraseiter);
    188 }
    189 
    190 /** Prepares insertion of a bond.
    191  *
    192  * This is called before the insertion into a molecule and thus before the
    193  * insertion into the scene.
    194  *
    195  * @param _bond bond to insert
    196  */
    197 void GLWorldScene::bondInserted(QtObservedBond::ptr _bond)
    198 {
    199   const ObservedValue_Index_t bondid = _bond->getIndex();
    200   ASSERT( QtObservedBondMap.find(bondid) == QtObservedBondMap.end(),
    201       "GLWorldScene::BondInserted() - bond with id "+toString(_bond->getBondIndex())
    202       +" is already present in QtObservedBondMap.");
    203   QtObservedBondMap[bondid] = _bond;
    204 
    205   // assign to its molecule if present
    206   const moleculeId_t molid = _bond->getMoleculeIndex();
    207   if (molid != (moleculeId_t)-1) {
    208     QtObservedMolecule::ptr mol = board->getObservedMolecule(molid);
    209     emit moleculesBondInserted(_bond, mol.get());
    210   } else {
    211     // watch bond till it has a molecule
    212     connect( _bond.get(), SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),
    213         this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));
    214   }
    215 }
    216 
    217 /** Handle change of molecule from initial none.
    218  *
    219  */
    220 void GLWorldScene::bondsMoleculeChanged(moleculeId_t _oldid, moleculeId_t _newid)
    221 {
    222   ASSERT( _oldid == (moleculeId_t)-1,
    223       "GLWorldScene::bondsMoleculeChanged() - got true index change from "
    224       +toString(_oldid)+" to "+toString(_newid)+" and not just added to mol.");
    225   QtObservedBond* bondref = static_cast<QtObservedBond*>(sender());
    226 
    227   // disconnect from further molecule changes
    228   disconnect( bondref, SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),
    229       this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));
    230 
    231   // add it to its molecule
    232   QtObservedMolecule::ptr mol = board->getObservedMolecule(_newid);
    233   emit moleculesBondInserted(bondref->getRef(), mol.get());
    234 }
    235 
    236 
    237 /** Removes an general bond.
    238  *
    239  * This is called when the bond has been removed from the molecule.
    240  *
    241  * @param _bond bond to remove
    242  */
    243 void GLWorldScene::bondRemoved(ObservedValue_Index_t _bondid)
    244 {
    245   const QtObservedBondMap_t::iterator eraseiter = QtObservedBondMap.find(_bondid);
    246   ASSERT( eraseiter != QtObservedBondMap.end(),
    247       "GLWorldScene::BondRemoved() - bond with id "+toString(_bondid)
    248       +" is not present in QtObservedBondMap.");
    249   QtObservedBond::ptr bondref = eraseiter->second;
    250 
    251   // tell its assigned molecule if present
    252   const moleculeId_t molid = bondref->getMoleculeIndex();
    253   if (molid != (moleculeId_t)-1) {
    254     QtObservedMolecule::ptr mol = board->getObservedMolecule(molid);
    255     emit moleculesBondRemoved(_bondid, mol.get());
    256   } else {
    257     // it might have still been waiting for a molecule assignment
    258     disconnect( bondref.get(), SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),
    259         this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));
    260   }
    261   QtObservedBondMap.erase(eraseiter);
    262 }
    263 
    264 /** Inserts an atom into the scene when molecule is present.
    265  *
    266  * @param _atom atom to insert
    267  */
    268 void GLWorldScene::moleculesAtomInserted(QtObservedAtom::ptr _atom, QtObservedMolecule * _mol)
    269 {
    270   const ObservedValue_Index_t atomid = _atom->getIndex();
    271   // this ASSERT cannot work: The same molecule may get reassigned to a different
    272   // molecule, when e.g. the time step changes (which triggers an update-molecules).
    273   // The GUI is slow and may lack behind and thus get  to execute the event
    274   // moleculeAtomInserted when the change has been already been done.
    275 //  ASSERT( (atommol == NULL) || (_mol == atommol),
    276 //      "GLWorldScene::moleculesAtomInserted() - atom "+toString(atomid)
    277 //      +" claims to belong to QtObservedMolecule "+toString(atommol)
    278 //      +" but signal came from QtObservedMolecule "+toString(_mol)+".");
    279   LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom " << _atom->getAtomIndex());
    280   const ObservedValue_Index_t molid = _mol->getIndex();
    281 
    282   // check of molecule is already present
    283   boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    284   const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
    285   if (moliter != MoleculesinSceneMap.end()) {
    286     const RemovedMoleculesMap_t::iterator emptyiter = EmptyMolecules.find(_mol);
    287     if (emptyiter != EmptyMolecules.end())
    288       EmptyMolecules.erase(emptyiter);
    289     // check that it is the right molecule
    290     QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;
    291     if (checkmol.get() == _mol) {
    292       LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomInserted for atom "
    293           << _atom->getAtomIndex());
    294       QMetaObject::invokeMethod(moliter->second,        // pointer to a QObject
    295                                 "atomInserted",       // member name (no parameters here)
    296                                 Qt::QueuedConnection,     // connection type
    297                                 Q_ARG(QtObservedAtom::ptr, _atom));     // parameters
    298     } else {
    299       // relay atomRemoved to GLMoleculeObject_molecule in RemovedMolecules
    300 //      LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomInserted for atom "+toString(_atomid)
    301 //          +" to molecule in RemovedMolecules.");
    302 //      const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(molid);
    303 //      ASSERT( removedmoliter != RemovedMolecules.end(),
    304 //          "GLWorldScene::moleculesAtomInserted() - signal from old mol "
    305 //          +toString(molid)+", but not present in RemovedMolecules");
    306 //      QMetaObject::invokeMethod(removedmoliter->second,        // pointer to a QObject
    307 //                                "atomInserted ",       // member name (no parameters here)
    308 //                                Qt::QueuedConnection,     // connection type
    309 //                                Q_ARG(QtObservedAtom::ptr, _atom));     // parameters
    310       ASSERT( 0,
    311           "GLWorldScene::moleculesAtomInserted() - would need to send atomInserted to already removed molecule.");
    312     }
    313   } else {
    314     const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
    315     if (removedmoliter != RemovedMolecules.end()) {
    316       ASSERT( 0,
    317           "GLWorldScene::moleculesAtomInserted() - would need to send atomInserted to already removed molecule.");
    318     } else {
    319       boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    320       // only record missed state for molecule if (still) present but not instantiated
    321       if (QtObservedMoleculeMap.count(molid)) {
    322         // store signal for when it is instantiated
    323         if (MoleculeMissedStateMap.count(molid) == 0)
    324           MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );
    325         MoleculeMissedStateMap[molid].insert( std::make_pair(atomid, atomInsertedState) );
    326         ASSERT( QtObservedAtomMap[atomid] == _atom,
    327             "GLWorldScene::moleculesAtomInserted() - atom "+toString(atomid)
    328             +" inserted in molecule "+toString(_mol->getMolIndex())
    329             +" which does not match atom in QtObservedAtomMap.");
    330         LOG(3, "INFO: GLWorldScene: Placing atomInserted for atom " << _atom->getAtomIndex()
    331              << " and molecule " << _mol->getMolIndex() << " into missed state map.");
    332       }
    333     }
    334   }
    335 }
    336 
    337 /** Removes an atom into the scene before molecule is present.
    338  *
    339  * @param _atomid atom to remove
    340  */
    341 void GLWorldScene::moleculesAtomRemoved(ObservedValue_Index_t _atomid, QtObservedMolecule * _mol)
    342 {
    343   LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
    344 
    345   const ObservedValue_Index_t molid = _mol->getIndex();
    346   // check of molecule is already present
    347   boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    348   const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
    349   if (moliter != MoleculesinSceneMap.end()) {
    350     const QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;
    351     if (checkmol.get() == _mol) {
    352       LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomRemoved for atom "+toString(_atomid)+".");
    353       QMetaObject::invokeMethod(moliter->second,        // pointer to a QObject
    354                                 "atomRemoved",       // member name (no parameters here)
    355                                 Qt::QueuedConnection,     // connection type
    356                                 Q_ARG(ObservedValue_Index_t, _atomid));     // parameters
    357     } else {
    358       // relay atomRemoved to GLMoleculeObject_molecule in RemovedMolecules
    359       LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomRemoved for atom "+toString(_atomid)
    360           +" to molecule in RemovedMolecules.");
    361       const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
    362       ASSERT( removedmoliter != RemovedMolecules.end(),
    363           "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "
    364           +toString(molid)+", but not present in RemovedMolecules");
    365 #ifndef NDEBUG
    366       const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;
    367 #endif
    368       ASSERT( othercheckmol.get() == _mol,
    369           "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "
    370           +toString(molid)+", but different one "+toString(othercheckmol)
    371           +" present in RemovedMolecules.");
    372       QMetaObject::invokeMethod(removedmoliter->second,        // pointer to a QObject
    373                                 "atomRemoved",       // member name (no parameters here)
    374                                 Qt::QueuedConnection,     // connection type
    375                                 Q_ARG(ObservedValue_Index_t, _atomid));     // parameters
    376     }
    377   } else {
    378     const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
    379     if (removedmoliter != RemovedMolecules.end()) {
    380       ASSERT( removedmoliter != RemovedMolecules.end(),
    381           "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "
    382           +toString(molid)+", but not present in RemovedMolecules");
    383 #ifndef NDEBUG
    384       const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;
    385 #endif
    386       ASSERT( othercheckmol.get() == _mol,
    387           "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "
    388           +toString(molid)+", but different one "+toString(othercheckmol)
    389           +" present in RemovedMolecules.");
    390       QMetaObject::invokeMethod(removedmoliter->second,        // pointer to a QObject
    391                                 "atomRemoved",       // member name (no parameters here)
    392                                 Qt::QueuedConnection,     // connection type
    393                                 Q_ARG(ObservedValue_Index_t, _atomid));     // parameters
    394     } else {
    395       boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    396       // only record missed state for molecule if (still) present but not instantiated
    397       if (QtObservedMoleculeMap.count(molid)) {
    398         // store signal for when it is instantiated
    399         if (MoleculeMissedStateMap.count(molid) == 0)
    400           MoleculeMissedStateMap.insert( std::make_pair(molid, StateChangeMap_t()) );
    401         MoleculeMissedStateMap[molid].insert( std::make_pair(_atomid, atomRemovedState) );
    402         LOG(3, "INFO: GLWorldScene: Placing atomRemoved for atom " << _atomid
    403              << " and molecule " << molid << " into missed state map.");
    404       }
    405     }
    406   }
    407 }
    408 
    409 /** Inserts an bond into the scene when molecule is present.
    410  *
    411  * @param _bond bond to insert
    412  */
    413 void GLWorldScene::moleculesBondInserted(QtObservedBond::ptr _bond, QtObservedMolecule * _mol)
    414 {
    415   const ObservedValue_Index_t bondid = _bond->getIndex();
    416   LOG(3, "INFO: GLWorldScene: Received signal bondInserted for bond " << _bond->getBondIndex());
    417   const ObservedValue_Index_t molid = _mol->getIndex();
    418 
    419   // check of molecule is already present
    420   boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    421   const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
    422   if (moliter != MoleculesinSceneMap.end()) {
    423     // check that it is the right molecule
    424     QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;
    425     ASSERT( checkmol.get() == _mol,
    426         "GLWorldScene::moleculesBondInserted() - claimed and present molecule differ.");
    427     LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondInserted for bond "
    428         << _bond->getBondIndex());
    429     QMetaObject::invokeMethod(moliter->second,        // pointer to a QObject
    430                               "bondInserted",       // member name (no parameters here)
    431                               Qt::QueuedConnection,     // connection type
    432                               Q_ARG(QtObservedBond::ptr, _bond));     // parameters
    433   } else {
    434 #ifndef NDEBUG
    435     const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
    436     ASSERT( removedmoliter != RemovedMolecules.end(),
    437           "GLWorldScene::moleculesBondInserted() - would need to send bondInserted to already removed molecule.");
    438 #endif
    439     boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    440     // only record missed state for molecule if (still) present but not instantiated
    441     if (QtObservedMoleculeMap.count(molid)) {
    442       // store signal for when it is instantiated
    443       if (MoleculeMissedStateMap.count(molid) == 0)
    444         MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );
    445       MoleculeMissedStateMap[molid].insert( std::make_pair(bondid, bondInsertedState) );
    446       ASSERT( QtObservedBondMap[bondid] == _bond,
    447           "GLWorldScene::moleculesBondInserted() - bond "+toString(bondid)
    448           +" inserted in molecule "+toString(_mol->getMolIndex())
    449           +" which does not match bond in QtObservedBondMap.");
    450       LOG(3, "INFO: GLWorldScene: Placing bondInserted for bond " << _bond->getBondIndex()
    451            << " and molecule " << _mol->getMolIndex() << " into missed state map.");
    452     }
    453   }
    454 }
    455 
    456 /** Removes an bond into the scene before molecule is present.
    457  *
    458  * @param _bondid bond to remove
    459  */
    460 void GLWorldScene::moleculesBondRemoved(ObservedValue_Index_t _bondid, QtObservedMolecule * _mol)
    461 {
    462   LOG(3, "INFO: GLWorldScene: Received signal bondRemoved for bond "+toString(_bondid)+".");
    463 
    464   const ObservedValue_Index_t molid = _mol->getIndex();
    465   // check of molecule is already present
    466   boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    467   const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
    468   if (moliter != MoleculesinSceneMap.end()) {
    469     const QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;
    470     if (checkmol.get() == _mol) {
    471       LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondRemoved for bond "+toString(_bondid)+".");
    472       QMetaObject::invokeMethod(moliter->second,        // pointer to a QObject
    473                                 "bondRemoved",       // member name (no parameters here)
    474                                 Qt::QueuedConnection,     // connection type
    475                                 Q_ARG(ObservedValue_Index_t, _bondid));     // parameters
    476     } else {
    477       // relay bondRemoved to GLMoleculeObject_molecule in RemovedMolecules
    478       LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondRemoved for bond "+toString(_bondid)
    479           +" to molecule in RemovedMolecules.");
    480       const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
    481       ASSERT( removedmoliter != RemovedMolecules.end(),
    482           "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
    483           +toString(molid)+", but not present in RemovedMolecules");
    484 #ifndef NDEBUG
    485       const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;
    486       ASSERT( othercheckmol.get() == _mol,
    487           "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
    488           +toString(molid)+", but different one "+toString(othercheckmol)
    489           +" present in RemovedMolecules.");
    490 #endif
    491       QMetaObject::invokeMethod(removedmoliter->second,        // pointer to a QObject
    492                                 "bondRemoved",       // member name (no parameters here)
    493                                 Qt::QueuedConnection,     // connection type
    494                                 Q_ARG(ObservedValue_Index_t, _bondid));     // parameters
    495     }
    496   } else {
    497     const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
    498     if (removedmoliter != RemovedMolecules.end()) {
    499       ASSERT( removedmoliter != RemovedMolecules.end(),
    500           "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
    501           +toString(molid)+", but not present in RemovedMolecules");
    502 #ifndef NDEBUG
    503       const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;
    504       ASSERT( othercheckmol.get() == _mol,
    505           "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
    506           +toString(molid)+", but different one "+toString(othercheckmol)
    507           +" present in RemovedMolecules.");
    508 #endif
    509       QMetaObject::invokeMethod(removedmoliter->second,        // pointer to a QObject
    510                                 "bondRemoved",       // member name (no parameters here)
    511                                 Qt::QueuedConnection,     // connection type
    512                                 Q_ARG(ObservedValue_Index_t, _bondid));     // parameters
    513     } else {
    514       boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    515       // only record missed state for molecule if (still) present but not instantiated
    516       if (QtObservedMoleculeMap.count(molid)) {
    517         // store signal for when it is instantiated
    518         if (MoleculeMissedStateMap.count(molid) == 0)
    519           MoleculeMissedStateMap.insert( std::make_pair(molid, StateChangeMap_t()) );
    520         MoleculeMissedStateMap[molid].insert( std::make_pair(_bondid, bondRemovedState) );
    521         LOG(3, "INFO: GLWorldScene: Placing bondRemoved for bond " << _bondid
    522              << " and molecule " << molid << " into missed state map.");
    523       }
    524     }
    525   }
    526 }
    527 
    528 void GLWorldScene::moleculeSignOn(QtObservedMolecule::ptr _mol)
    529 {
    530   // sign on to QtObservedMolecule to get atomInserted/..Removed signals from same
    531   // source as GLMoleculeObject_molecule would
    532   connect(_mol.get(), SIGNAL(atomInserted(QtObservedAtom::ptr, QtObservedMolecule *)),
    533       this, SLOT(moleculesAtomInserted(QtObservedAtom::ptr, QtObservedMolecule *)) );
    534   connect(_mol.get(), SIGNAL(atomRemoved(ObservedValue_Index_t, QtObservedMolecule *)),
    535       this, SLOT(moleculesAtomRemoved(ObservedValue_Index_t, QtObservedMolecule *)) );
    536   const ObservedValue_Index_t molid = _mol->getIndex();
    537   ASSERT( QtObservedMoleculeMap.find(molid) == QtObservedMoleculeMap.end(),
    538       "GLWorldScene::moleculeSignOn() - molecule with id "+toString(_mol->getMolIndex())
    539       +" is already present in QtObservedMoleculeMap.");
    540   QtObservedMoleculeMap[molid] = _mol;
    541 
    542   LOG(3, "INFO: GLWorldScene: Received signal moleculeSignOn for molecule " << _mol->getMolIndex());
    543 
    544   emit insertMolecule(_mol);
    545 }
    546 
    547 void GLWorldScene::moleculeSignOff(ObservedValue_Index_t _id)
    548 {
    549   const QtObservedMoleculeMap_t::iterator eraseiter = QtObservedMoleculeMap.find(_id);
    550   ASSERT( eraseiter != QtObservedMoleculeMap.end(),
    551       "GLWorldScene::moleculeSignOff() - cannot find id "+toString(_id)+" in map.");
    552   QtObservedMolecule * mol = eraseiter->second.get();
    553   QtObservedMoleculeMap.erase(eraseiter);
    554 
    555   LOG(3, "INFO: GLWorldScene: Received signal moleculeSignOff for molecule " << mol->getMolIndex());
    556 
    557   emit removeMolecule(mol);
    558 }
    559 
    560286/** Inserts a molecule into the scene.
    561287 *
     
    564290void GLWorldScene::moleculeInserted(QtObservedMolecule::ptr _mol)
    565291{
    566   ASSERT (_mol,
    567       "GLWorldScene::moleculeInserted() - received shared_ptr for molecule is empty?");
    568292  const ObservedValue_Index_t molid = _mol->getIndex();
    569293  LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "
    570294      << _mol->getMolIndex());
    571 
    572   boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    573295
    574296  MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid);
     
    583305          GLMoleculeObject::meshEmpty,
    584306          this,
    585           *board,
    586307          _mol);
    587308  ASSERT( molObject != NULL,
     
    596317      +" already present in scene.");
    597318
    598   // now handle all state changes that came up before the instantiation
    599   if (MoleculeMissedStateMap.count(molid) != 0) {
    600 //      ASSERT( !MoleculeMissedStateMap[molid].empty(),
    601 //          "GLWorldScene::moleculeInserted() - we have an empty state change map for molecule with id "
    602 //          +toString(molid));
    603     boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    604     for (StateChangeMap_t::iterator iter = MoleculeMissedStateMap[molid].begin();
    605         !MoleculeMissedStateMap[molid].empty();
    606         iter = MoleculeMissedStateMap[molid].begin()) {
    607       std::pair<StateChangeMap_t::iterator, StateChangeMap_t::iterator> rangeiter =
    608           MoleculeMissedStateMap[molid].equal_range(iter->first);
    609       const size_t StateCounts = std::distance(rangeiter.first, rangeiter.second);
    610       if (StateCounts > 1) {
    611         // more than one state change, have to combine
    612         typedef std::map<StateChangeType, size_t> StateChangeAmounts_t;
    613         StateChangeAmounts_t StateChangeAmounts;
    614         for (StateChangeMap_t::const_iterator stateiter = rangeiter.first;
    615             stateiter != rangeiter.second; ++stateiter)
    616           ++StateChangeAmounts[stateiter->second];
    617         // is it an atom?
    618         if ((StateChangeAmounts[atomInsertedState] + StateChangeAmounts[atomRemovedState]) != 0) {
    619           ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
    620               "GLWorldScene::moleculeInserted() - more atomRemoved states "
    621               +toString(StateChangeAmounts[atomRemovedState])+" than atomInserted "
    622               +toString(StateChangeAmounts[atomInsertedState])+" for atom "+toString(iter->first));
    623           if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
    624             LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
    625             QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    626                                       "atomInserted",       // member name (no parameters here)
    627                                       Qt::QueuedConnection,     // connection type
    628                                       Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first]));     // parameters
    629           } else {
    630             LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
    631           }
    632         }
    633         // or is it a bond?
    634         if ((StateChangeAmounts[bondInsertedState] + StateChangeAmounts[bondInsertedState]) != 0) {
    635           ASSERT( StateChangeAmounts[bondInsertedState] >= StateChangeAmounts[bondRemovedState],
    636               "GLWorldScene::moleculeInserted() - more bondRemoved states "
    637               +toString(StateChangeAmounts[bondRemovedState])+" than bondInserted "
    638               +toString(StateChangeAmounts[bondInsertedState])+" for bond "+toString(iter->first));
    639           if (StateChangeAmounts[bondInsertedState] > StateChangeAmounts[bondRemovedState]) {
    640             LOG(1, "INFO: invoking bondInserted for bond " << iter->first);
    641             QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    642                                       "bondInserted",       // member name (no parameters here)
    643                                       Qt::QueuedConnection,     // connection type
    644                                       Q_ARG(QtObservedBond::ptr, QtObservedBondMap[iter->first]));     // parameters
    645           } else {
    646             LOG(1, "INFO: Bond " << iter->first << " has been inserted and removed already.");
    647           }
    648         }
    649         ASSERT( (StateChangeAmounts[bondInsertedState] + StateChangeAmounts[bondInsertedState]
    650             + StateChangeAmounts[atomInsertedState] + StateChangeAmounts[atomRemovedState]) != 0,
    651             "GLWorldScene::moleculeInserted() - state with no changes for "+toString(iter->first));
    652         // removed all state changes for this atom/bond
    653         MoleculeMissedStateMap[molid].erase(rangeiter.first, rangeiter.second);
    654       } else {
    655         // can only be an insertion
    656         switch (rangeiter.first->second) {
    657           case atomRemovedState:
    658             ASSERT( 0,
    659                 "GLWorldScene::moleculeInserted() - atomRemoved state without atomInserted for atom "
    660                 +toString(iter->first));
    661             break;
    662           case atomInsertedState:
    663           {
    664             LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
    665             QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    666                                       "atomInserted",       // member name (no parameters here)
    667                                       Qt::QueuedConnection,     // connection type
    668                                       Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first]));     // parameters
    669             break;
    670           }
    671           case bondRemovedState:
    672             ASSERT( 0,
    673                 "GLWorldScene::moleculeInserted() - bondRemoved state without bondInserted for bond "
    674                 +toString(iter->first));
    675             break;
    676           case bondInsertedState:
    677           {
    678             LOG(1, "INFO: invoking bondInserted for bond " << iter->first);
    679             QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    680                                       "bondInserted",       // member name (no parameters here)
    681                                       Qt::QueuedConnection,     // connection type
    682                                       Q_ARG(QtObservedBond::ptr, QtObservedBondMap[iter->first]));     // parameters
    683             break;
    684           }
    685           default:
    686             ASSERT( 0,
    687                 "GLWorldScene::moleculeInserted() - there are unknown change states.");
    688             break;
    689         }
    690         // removed state changes for this atom/bond
    691         MoleculeMissedStateMap[molid].erase(iter);
    692       }
    693     }
    694   }
    695 
    696319  connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
    697320  connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
    698   connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
    699   connect (molObject, SIGNAL(moleculeClicked(moleculeId_t)), this, SLOT(moleculeClicked(moleculeId_t)));
    700   connect (molObject, SIGNAL(moleculeEmptied(QtObservedMolecule::ptr)), this, SLOT(moleculeEmpty(QtObservedMolecule::ptr)));
    701   connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
    702   connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
    703   connect (molObject, SIGNAL(hoverChanged(const atomId_t)), this, SIGNAL(hoverChanged(const atomId_t)));
    704   connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
    705   connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
    706 
    707   emit changed();
    708   emit changeOccured();
    709 
    710   // remove state change map for the molecule
    711   {
    712     boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    713     MoleculeMissedStateMap.erase(molid);
    714   }
     321
     322  emit changed();
     323  emit changeOccured();
    715324}
    716325
    717326/** Removes a molecule from the scene.
    718327 *
    719  * @param _mol QtObservedMolecule instance of molecule to remove
    720  */
    721 void GLWorldScene::moleculeRemoved(QtObservedMolecule* _mol)
    722 {
    723   const ObservedValue_Index_t molid = _mol->getIndex();
    724   LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(molid)+".");
    725 
    726   boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    727 
    728   MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(molid);
     328 * @param _molid index of the molecule to remove
     329 */
     330void GLWorldScene::moleculeRemoved(ObservedValue_Index_t _molid)
     331{
     332  LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molid)+".");
     333
     334  MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
    729335  ASSERT ( iter != MoleculesinSceneMap.end(),
    730       "GLWorldScene::moleculeRemoved() - to be removed molecule "+toString(_mol->getMolIndex())
     336      "GLWorldScene::moleculeRemoved() - to be removed molecule "+toString(_molid)
    731337      +" is already gone.");
    732338  // check if it's already empty
    733   const RemovedMoleculesMap_t::iterator emptyiter = EmptyMolecules.find(_mol);
    734   if (emptyiter != EmptyMolecules.end()) {
    735     LOG(1, "DEBUG: Removing empty GLMoleculeObject_molecule to id " << _mol->getMolIndex()
    736         << " from scene.");
    737     // it's already empty, remove it
    738     ASSERT( emptyiter->second == iter->second,
    739         "GLWorldScene::moleculeRemoved() - empty molecule "
    740         +toString(emptyiter->second)+" and removed molecule "
    741         +toString(iter->second)+" don't match.");
    742     LOG(1, "DEBUG: Deleting already empty GLMoleculeObject_molecule to id " << _mol->getMolIndex());
    743     GLMoleculeObject_molecule *molObject = emptyiter->second;
    744     EmptyMolecules.erase(emptyiter);
    745     molObject->disconnect();
    746     delete molObject;
    747 
    748     emit changed();
    749     emit changeOccured();
    750   } else {
    751     // otherwise note it as removal candidate
    752     RemovedMolecules.insert( std::make_pair(_mol, iter->second) );
    753   }
     339  GLMoleculeObject_molecule *molObject = iter->second;
     340  delete molObject;
    754341  MoleculesinSceneMap.erase(iter);
    755342
    756   // remove any possible state changes left
    757   {
    758     boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    759     MoleculeMissedStateMap.erase(molid);
    760   }
    761 }
    762 
    763 void GLWorldScene::moleculeEmpty(QtObservedMolecule::ptr _mol)
    764 {
    765   LOG(3, "INFO: GLWorldScene: Received signal moleculeEmpty for molecule "
    766       +toString(_mol->getMolIndex())+".");
    767 
    768   boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    769 
    770   const ObservedValue_Index_t molid = _mol->getIndex();
    771   MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(molid);
    772   if ( iter == MoleculesinSceneMap.end()) {
    773     RemovedMoleculesMap_t::iterator removeiter = RemovedMolecules.find(_mol.get());
    774     ASSERT ( removeiter != RemovedMolecules.end(),
    775         "GLWorldScene::moleculeEmpty() - to be removed molecule "+toString(_mol->getMolIndex())
    776         +" is neither in MoleculesinSceneMap, nor in RemovedMolecules.");
    777     // it's noted for removal already, remove it
    778     LOG(1, "DEBUG: Deleting empty GLMoleculeObject_molecule to id " << _mol->getMolIndex());
    779     GLMoleculeObject_molecule *molObject = removeiter->second;
    780     RemovedMolecules.erase(removeiter);
    781     molObject->disconnect();
    782     delete molObject;
    783 
    784     emit changed();
    785     emit changeOccured();
    786   } else {
    787     // otherwise just note it as empty
    788     EmptyMolecules.insert( std::make_pair(_mol.get(), iter->second) );
    789   }
    790 
    791 //  // remove any possible state changes left
    792 //  {
    793 //    boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    794 //    MoleculeMissedStateMap.erase(molid);
    795 //  }
     343  emit changed();
     344  emit changeOccured();
    796345}
    797346
    798347void GLWorldScene::moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible)
    799348{
    800   boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    801349  MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
    802350  ASSERT( iter != MoleculesinSceneMap.end(),
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    r785d89 rf1b5ca  
    1919
    2020#include <iosfwd>
    21 
    22 #include <boost/thread/recursive_mutex.hpp>
    2321
    2422#include "Bond/bond.hpp"
     
    8583  void hoverChanged(const atomId_t);
    8684  void hoverChanged(const moleculeId_t, int);
    87   void insertMolecule(QtObservedMolecule::ptr);
    88   void removeMolecule(QtObservedMolecule*);
    8985
    9086private slots:
    9187  void atomClicked(atomId_t no);
    92   void moleculeClicked(moleculeId_t no);
    93   void moleculeRemoved(QtObservedMolecule* _mol);
    94   void moleculeEmpty(QtObservedMolecule::ptr _mol);
    95   void moleculeInserted(QtObservedMolecule::ptr);
    96   void moleculeSignOn(QtObservedMolecule::ptr);
    97   void moleculeSignOff(ObservedValue_Index_t _id);
    98   void moleculesAtomRemoved(ObservedValue_Index_t _atomid, QtObservedMolecule * _mol);
    99   void moleculesAtomInserted(QtObservedAtom::ptr, QtObservedMolecule *_mol);
    100   void moleculesBondRemoved(ObservedValue_Index_t _bondid, QtObservedMolecule * _mol);
    101   void moleculesBondInserted(QtObservedBond::ptr, QtObservedMolecule *_mol);
    10288  void atomRemoved(ObservedValue_Index_t _atomid);
    10389  void atomInserted(QtObservedAtom::ptr);
    10490  void bondRemoved(ObservedValue_Index_t _bondid);
    10591  void bondInserted(QtObservedBond::ptr);
    106   void bondsMoleculeChanged(moleculeId_t _oldid, moleculeId_t _newid);
     92  void moleculeClicked(moleculeId_t no);
     93  void moleculeRemoved(ObservedValue_Index_t _molid);
     94  void moleculeInserted(QtObservedMolecule::ptr);
    10795  void setSelectionModeAtom();
    10896  void setSelectionModeMolecule();
     
    11199//  void update();
    112100  void moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible);
     101  void hoverChangedSignalled(GLMoleculeObject *ob);
    113102
    114103public:
     
    117106private:
    118107
     108  //!> id of atom hovered over
     109  atomId_t hoverAtomId;
     110
    119111  typedef std::map< ObservedValue_Index_t , GLMoleculeObject_molecule* > MoleculeNodeMap;
     112  typedef std::map< ObservedValue_Index_t, GLMoleculeObject_atom* > AtomNodeMap;
     113  typedef std::map< ObservedValue_Index_t, GLMoleculeObject_bond* > BondNodeMap;
    120114  typedef std::map< std::string , GLMoleculeObject_shape* > ShapeNodeMap;
     115
     116  AtomNodeMap AtomsinSceneMap;
     117  BondNodeMap BondsinSceneMap;
    121118  MoleculeNodeMap MoleculesinSceneMap;
    122119  ShapeNodeMap ShapesinSceneMap;
    123   //!> flag to indicate whether state map is currently worked on
    124   boost::recursive_mutex MoleculeinSceneMap_mutex;
    125 
    126   //!> enumeration of all possible changes molecule might have missed before instantiation
    127   enum StateChangeType {
    128     atomInsertedState,
    129     atomRemovedState,
    130     bondInsertedState,
    131     bondRemovedState,
    132     MAX_StateChangeType
    133   };
    134   typedef std::map< ObservedValue_Index_t, QtObservedAtom::ptr> QtObservedAtomMap_t;
    135   typedef std::map< ObservedValue_Index_t, QtObservedBond::ptr> QtObservedBondMap_t;
    136   typedef std::map< ObservedValue_Index_t, QtObservedMolecule::ptr> QtObservedMoleculeMap_t;
    137   typedef std::multimap< ObservedValue_Index_t, StateChangeType> StateChangeMap_t;
    138   typedef std::map< ObservedValue_Index_t, StateChangeMap_t> MissedStateMap_t;
    139   //!> map of all missed state changes
    140   MissedStateMap_t MoleculeMissedStateMap;
    141   //!> map to contain all QtObservedAtom that have not been instantiated so far
    142   QtObservedAtomMap_t QtObservedAtomMap;
    143   //!> map to contain all QtObservedBond that have not been instantiated so far
    144   QtObservedBondMap_t QtObservedBondMap;
    145   //!> map to contain all QtObservedMolecule that have not been instantiated so far
    146   QtObservedMoleculeMap_t QtObservedMoleculeMap;
    147 
    148   //!> map to get from QtObservedMolecule to the visual representant
    149   typedef std::map< QtObservedMolecule* , GLMoleculeObject_molecule* > RemovedMoleculesMap_t;
    150   //!> set of all currently removed molecules
    151   RemovedMoleculesMap_t RemovedMolecules;
    152   //!> set of all currently empty molecules (about to be removed)
    153   RemovedMoleculesMap_t EmptyMolecules;
    154 
    155   //!> flag to indicate whether state map is currently worked on
    156   boost::recursive_mutex MoleculeMissedStateMap_mutex;
    157120
    158121  SelectionModeType selectionMode;
Note: See TracChangeset for help on using the changeset viewer.