Changeset 8c001a for src


Ignore:
Timestamp:
Jan 10, 2015, 5:14:21 PM (10 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:
739ee9
Parents:
7b38d3
git-author:
Frederik Heber <heber@…> (11/05/14 19:19:42)
git-committer:
Frederik Heber <heber@…> (01/10/15 17:14:21)
Message:

GLMoleculeObject_atoms and .._bonds are now children of .._molecule.

  • GLMoleculeObject::initialize() is now virtual.
  • .._molecule is now draw()ing its children, i.e. initialize() of .._molecule calls in turn those of .._atom and .._bond. Similarly with draw.
  • molecule has a lastchangedatom member variable now.
  • FIX: molecule::getBoundingSphere() did not check for no atoms.
Location:
src
Files:
12 edited

Legend:

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

    r7b38d3 r8c001a  
    6262QGLMaterial *GLMoleculeObject::m_selectionBoxMaterial = NULL;
    6363
     64QGLSceneNode *GLMoleculeObject::meshEmpty[GLMoleculeObject::DETAILTYPES_MAX];
     65QGLSceneNode *GLMoleculeObject::meshSphere[GLMoleculeObject::DETAILTYPES_MAX];
     66QGLSceneNode *GLMoleculeObject::meshCylinder[GLMoleculeObject::DETAILTYPES_MAX];
    6467
    6568double GLMoleculeObject::detailMinDistance[GLMoleculeObject::DETAILTYPES_MAX] = {0, 15, 30, 42};
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp

    r7b38d3 r8c001a  
    7575
    7676   void initStaticMaterials();
    77    void initialize(QGLView *view, QGLPainter *painter);
     77   virtual void initialize(QGLView *view, QGLPainter *painter);
    7878   virtual void draw(QGLPainter *painter, const QVector4D &cameraPlane);
    7979   void drawSelectionBox(QGLPainter *painter);
     
    9999public:
    100100   enum{DETAIL_HIGHEST, DETAIL_HIGH, DETAIL_MEDIUM, DETAIL_LOW, DETAILTYPES_MAX} DetailType;
     101
     102   static QGLSceneNode *meshEmpty[DETAILTYPES_MAX];
     103   static QGLSceneNode *meshSphere[DETAILTYPES_MAX];
     104   static QGLSceneNode *meshCylinder[DETAILTYPES_MAX];
    101105
    102106protected:
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp

    r7b38d3 r8c001a  
    4545
    4646private:
    47   //!> grant GLWorldScene acess to reset functions
    48   friend class GLWorldScene;
     47  //!> grant GLMoleculeObject_molecule acess to reset functions
     48  friend class GLMoleculeObject_molecule;
    4949
    5050  void resetPosition();
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp

    r7b38d3 r8c001a  
    4343
    4444private:
    45   //!> grant WorldScene access to reset functions
    46   friend class GLWorldScene;
     45  //!> grant GLMoleculeObject_molecule acess to reset functions
     46  friend class GLMoleculeObject_molecule;
    4747
    4848  /** Recalculates the position of the cylinder representing the bond.
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    r7b38d3 r8c001a  
    5656#include "World.hpp"
    5757
     58#include "GLMoleculeObject_atom.hpp"
     59
    5860GLMoleculeObject_molecule::GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const molecule *molref) :
    5961  GLMoleculeObject(mesh, parent),
    6062  Observer(std::string("GLMoleculeObject_molecule")+toString(molref->getId())),
    61   _molecule(molref)
     63  _molecule(molref),
     64  hoverAtom(NULL)
    6265{
    6366  // sign on as observer (obtain non-const instance before)
     67  _molecule->signOn(this, molecule::AtomInserted);
     68  _molecule->signOn(this, molecule::AtomRemoved);
    6469  /*molref->signOn(this, AtomObservable::IndexChanged);
    6570  molref->signOn(this, AtomObservable::PositionChanged);
     
    6974  World::getInstance().signOn(this, World::SelectionChanged);
    7075  updateBoundingBox();
     76
     77  init();
    7178}
    7279
    7380GLMoleculeObject_molecule::~GLMoleculeObject_molecule()
    7481{
     82  _molecule->signOff(this, molecule::AtomInserted);
     83  _molecule->signOff(this, molecule::AtomRemoved);
    7584  /*_atom->signOff(this, AtomObservable::IndexChanged);
    7685  _atom->signOff(this, AtomObservable::PositionChanged);
     
    7887  _atom->signOff(this, AtomObservable::BondsAdded);*/
    7988  World::getInstance().signOff(this, World::SelectionChanged);
     89}
     90
     91/** Initialise the WorldScene with molecules and atoms from World.
     92 *
     93 */
     94void GLMoleculeObject_molecule::init()
     95{
     96  if (_molecule->begin() != _molecule->end()) {
     97    for (molecule::const_iterator atomiter = _molecule->begin();
     98        atomiter != _molecule->end();
     99        atomiter++) {
     100      // create atom objects in scene
     101      atomInserted((*atomiter)->getId());
     102
     103      // create bond objects in scene
     104      const BondList &bondlist = (*atomiter)->getListOfBonds();
     105      for (BondList::const_iterator bonditer = bondlist.begin();
     106          bonditer != bondlist.end();
     107          ++bonditer) {
     108        const bond::ptr _bond = *bonditer;
     109        const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == *atomiter) ?
     110            GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
     111        bondInserted(_bond, side);
     112      }
     113    }
     114  }
     115}
     116
     117void GLMoleculeObject_molecule::addAtomBonds(
     118    const bond::ptr &_bond,
     119    const GLMoleculeObject_bond::SideOfBond _side
     120    )
     121{
     122  bool bond_present = false;
     123  const BondIds ids = getBondIds(_bond, _side);
     124  // check whether bond is not present already
     125  bond_present = BondsinSceneMap.count(ids);
     126  if (!bond_present)
     127    bondInserted(_bond, _side);
     128  else {
     129    BondsinSceneMap[ids]->resetPosition();
     130    BondsinSceneMap[ids]->resetWidth();
     131  }
     132}
     133
     134void GLMoleculeObject_molecule::addAtomBonds(
     135    const atom *_atom)
     136{
     137  const bool atom_present = AtomsinSceneMap.count(_atom->getId());
     138  const BondList &bondlist = _atom->getListOfBonds();
     139  for (BondList::const_iterator bonditer = bondlist.begin();
     140      (bonditer != bondlist.end()) && atom_present;
     141      ++bonditer) {
     142    const bond::ptr _bond = *bonditer;
     143    // check if OtherAtom's sphere is already present
     144    const atom *OtherAtom = _bond->GetOtherAtom(_atom);
     145    const bool otheratom_present = AtomsinSceneMap.count(OtherAtom->getId());
     146    if (otheratom_present && atom_present) {
     147      const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ?
     148          GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
     149      const GLMoleculeObject_bond::SideOfBond otherside = (_bond->leftatom == _atom) ?
     150          GLMoleculeObject_bond::right : GLMoleculeObject_bond::left;
     151      addAtomBonds(_bond, side);
     152      addAtomBonds(_bond, otherside);
     153    }
     154  }
     155}
     156
     157void GLMoleculeObject_molecule::reinit()
     158{
     159  if (_molecule->getAtomCount() > 0) {
     160    for (molecule::const_iterator atomiter = _molecule->begin();
     161        atomiter != _molecule->end();
     162        atomiter++) {
     163      // check whether atom already exists
     164      const atomId_t atomid = (*atomiter)->getId();
     165      const bool atom_present = AtomsinSceneMap.count(atomid);
     166      if (!atom_present)
     167        atomInserted((*atomiter)->getId());
     168      else
     169        AtomsinSceneMap[atomid]->resetPosition();
     170
     171
     172      // create bond objects in scene
     173      addAtomBonds(*atomiter);
     174    }
     175  }
    80176}
    81177
     
    108204          << notification->getChannelNo() << ".";
    109205#endif
     206    switch (notification->getChannelNo()) {
     207      case molecule::AtomInserted:
     208      {
     209        const atomId_t _id = _molecule->lastChanged()->getId();
     210  #ifdef LOG_OBSERVER
     211        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted.";
     212  #endif
     213        atomInserted(_id);
     214        break;
     215      }
     216      case World::AtomRemoved:
     217      {
     218        const atomId_t _id = _molecule->lastChanged()->getId();
     219  #ifdef LOG_OBSERVER
     220        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been removed.";
     221  #endif
     222        atomRemoved(_id);
     223        break;
     224      }
     225      default:
     226        break;
     227    }
    110228  }else{
    111229    // notification from world
     
    125243}
    126244
     245void GLMoleculeObject_molecule::initialize(QGLView *view, QGLPainter *painter)
     246{
     247  // Initialize all of the mesh objects that we have as children.
     248//  GLMoleculeObject::initialize(view, painter);
     249   foreach (QObject *obj, children()) {
     250     GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
     251       if (meshobj)
     252         meshobj->initialize(view, painter);
     253   }
     254}
     255
     256void GLMoleculeObject_molecule::draw(QGLPainter *painter, const QVector4D &cameraPlane)
     257{
     258   // Draw all of the mesh objects that we have as children.
     259  GLMoleculeObject::draw(painter, cameraPlane);
     260   foreach (QObject *obj, children()) {
     261     GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
     262       if (meshobj)
     263         meshobj->draw(painter, cameraPlane);
     264   }
     265}
     266
     267/** Adds an atom of this molecule to the scene.
     268 *
     269 * @param _atom atom to add
     270 */
     271void GLMoleculeObject_molecule::atomInserted(const atomicNumber_t _id)
     272{
     273  LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_id)+".");
     274  GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(GLMoleculeObject::meshSphere, this, _id);
     275  AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
     276  ASSERT(iter == AtomsinSceneMap.end(),
     277      "GLWorldScene::atomAdded() - same atom with id "+toString(_id)+" added again.");
     278  AtomsinSceneMap.insert( make_pair(_id, atomObject) );
     279
     280  qRegisterMetaType<atomId_t>("atomId_t");
     281  qRegisterMetaType<bond::ptr>("bond::ptr");
     282  qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
     283  connect (atomObject, SIGNAL(clicked(atomId_t)), this, SIGNAL(atomClicked(atomId_t)));
     284  connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
     285  connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
     286  connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
     287  connect (atomObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
     288  connect (atomObject, SIGNAL(BondsInserted(const bond::ptr , const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond::ptr , const GLMoleculeObject_bond::SideOfBond)));
     289  connect (atomObject, SIGNAL(indexChanged(GLMoleculeObject_atom*, int, int)), this, SIGNAL(changeAtomId(GLMoleculeObject_atom*, int, int)));
     290
     291  updateBoundingBox();
     292
     293  //bondsChanged(_atom);
     294  emit changeOccured();
     295}
     296
     297/** Removes an atom of this molecule from the scene.
     298 *
     299 * We just the id as the atom might have already been destroyed.
     300 *
     301 * @param _id id of atom to remove
     302 */
     303void GLMoleculeObject_molecule::atomRemoved(const atomicNumber_t _id)
     304{
     305  LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_id)+".");
     306  // bonds are removed by signal coming from ~bond
     307  // remove atoms
     308  AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
     309  ASSERT(iter != AtomsinSceneMap.end(),
     310      "GLWorldScene::atomRemoved() - atom "+toString(_id)+" not on display.");
     311  GLMoleculeObject_atom *atomObject = iter->second;
     312  atomObject->disconnect();
     313  AtomsinSceneMap.erase(iter);
     314  delete atomObject;
     315
     316  updateBoundingBox();
     317
     318  emit changeOccured();
     319}
     320
     321void GLMoleculeObject_molecule::hoverChangedSignalled(GLMoleculeObject *ob)
     322{
     323  // Find the atom, ob corresponds to.
     324  hoverAtom = NULL;
     325  GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
     326  if (atomObject){
     327    for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
     328      if (iter->second == atomObject)
     329        hoverAtom = World::getInstance().getAtom(AtomById(iter->first));
     330    }
     331  }
     332
     333  // Propagate signal.
     334  emit hoverChanged(hoverAtom);
     335}
     336
     337
     338/** Helper function to get bond ids in the correct order for BondNodeMap.
     339 *
     340 * \return pair of ids in correct order.
     341 */
     342GLMoleculeObject_molecule::BondIds GLMoleculeObject_molecule::getBondIds(
     343    const bond::ptr _bond,
     344    const enum GLMoleculeObject_bond::SideOfBond _side)
     345{
     346  BondIds ids;
     347  switch (_side) {
     348    case GLMoleculeObject_bond::left:
     349      ids = std::make_pair(_bond->leftatom->getId(), _bond->rightatom->getId());
     350      break;
     351    case GLMoleculeObject_bond::right:
     352      ids = std::make_pair(_bond->rightatom->getId(), _bond->leftatom->getId());
     353      break;
     354  }
     355  return ids;
     356}
     357
     358/** Adds a bond to the scene.
     359 *
     360 * @param _bond bond to add
     361 * @param side which side of the bond (left or right)
     362 */
     363void GLMoleculeObject_molecule::bondInserted(const bond::ptr _bond, const enum GLMoleculeObject_bond::SideOfBond _side)
     364{
     365  LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
     366  //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
     367
     368  const BondIds ids = getBondIds(_bond, _side);
     369  BondNodeMap::iterator iter = BondsinSceneMap.find(ids);
     370  if (iter == BondsinSceneMap.end()) {
     371    GLMoleculeObject_bond * bondObject =
     372        new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, _bond, _side);
     373    connect (
     374        bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)),
     375        this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
     376    connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
     377    BondsinSceneMap.insert( make_pair(ids, bondObject) );
     378  //    BondIdsinSceneMap.insert( Leftids );
     379  } else {
     380    iter->second->resetPosition();
     381    iter->second->resetWidth();
     382  }
     383  emit changeOccured();
     384}
     385
     386/** Removes a bond from the scene.
     387 *
     388 * @param _bond bond to remove
     389 */
     390void GLMoleculeObject_molecule::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
     391{
     392  LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+".");
     393  {
     394    // left bond
     395    const BondIds Leftids( make_pair(leftnr, rightnr) );
     396    BondNodeMap::iterator leftiter = BondsinSceneMap.find( Leftids );
     397    ASSERT(leftiter != BondsinSceneMap.end(),
     398        "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
     399        +toString(rightnr)+" not on display.");
     400    GLMoleculeObject_bond *bondObject = leftiter->second;
     401    bondObject->disconnect();
     402    BondsinSceneMap.erase(leftiter);
     403    delete bondObject; // is done by signal from bond itself
     404    //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
     405  }
     406
     407  emit changeOccured();
     408}
     409
     410std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t)
     411{
     412  ost << t.first << "," << t.second;
     413  return ost;
     414}
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp

    r7b38d3 r8c001a  
    2222class atom;
    2323class bond;
     24class GLMoleculeObject_atom;
     25class GLWorldScene;
    2426class molecule;
    2527
     
    3840  void recieveNotification(Observable *publisher, Notification_ptr notification);
    3941
     42  void initialize(QGLView *view, QGLPainter *painter);
     43  void draw(QGLPainter *painter, const QVector4D &cameraPlane);
     44
     45  typedef std::pair< atomId_t, atomId_t> BondIds;
     46  friend std::ostream &operator<<(std::ostream &ost, const BondIds &t);
     47
     48  static BondIds getBondIds(
     49      const bond::ptr _bond,
     50      const enum GLMoleculeObject_bond::SideOfBond side);
     51
     52  void selected(const bool _isSelected)
     53  { isSelected = _isSelected; }
     54
     55signals:
     56  void changed();
     57  void changeOccured();
     58  void hoverChanged(const atom*);
     59  void atomClicked(atomId_t no);
     60  void changeAtomId(GLMoleculeObject_atom *, int, int);
     61
     62private slots:
     63  //!> grant GLWorldScene access to private slots
     64  friend class GLWorldScene;
     65
     66  void atomInserted(const atomicNumber_t _id);
     67  void atomRemoved(const atomicNumber_t _id);
     68  void bondInserted(const bond::ptr _bond, const GLMoleculeObject_bond::SideOfBond side);
     69  void bondRemoved(const atomId_t leftnr, const atomId_t rightnr);
     70  void hoverChangedSignalled(GLMoleculeObject *ob);
     71
    4072private:
     73  void init();
     74  void reinit();
     75
     76  void addAtomBonds(
     77      const bond::ptr &_bond,
     78      const GLMoleculeObject_bond::SideOfBond _side
     79      );
     80  void addAtomBonds(const atom *_atom);
     81
     82  //!> states whether selection box is additionally drawn or not
     83  bool isSelected;
    4184
    4285  const molecule *_molecule;
     86
     87  typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap;
     88  typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap;
     89  AtomNodeMap AtomsinSceneMap;
     90  BondNodeMap BondsinSceneMap;
     91
     92  const atom *hoverAtom;
    4393};
    4494
     95std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t);
    4596
    4697
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    r7b38d3 r8c001a  
    6060#include "Bond/bond.hpp"
    6161#include "Descriptors/AtomIdDescriptor.hpp"
     62#include "Descriptors/MoleculeIdDescriptor.hpp"
    6263#include "Helpers/helpers.hpp"
    6364#include "Shapes/ShapeRegistry.hpp"
     
    6970using namespace MoleCuilder;
    7071
    71 std::ostream &operator<<(std::ostream &ost, const GLWorldScene::BondIds &t)
    72 {
    73   ost << t.first << "," << t.second;
    74   return ost;
    75 }
    76 
    7772GLWorldScene::GLWorldScene(QObject *parent)
    78    : QObject(parent),
    79      hoverAtom(NULL)
     73   : QObject(parent)
    8074{
    8175  int sphereDetails[] = {5, 3, 2, 0};
     
    8377  for (int i=0;i<GLMoleculeObject::DETAILTYPES_MAX;i++){
    8478    QGLBuilder emptyBuilder;
    85     meshEmpty[i] = emptyBuilder.finalizedSceneNode();
     79    GLMoleculeObject::meshEmpty[i] = emptyBuilder.finalizedSceneNode();
    8680    QGLBuilder sphereBuilder;
    8781    sphereBuilder << QGLSphere(2.0, sphereDetails[i]);
    88     meshSphere[i] = sphereBuilder.finalizedSceneNode();
    89     meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true);
     82    GLMoleculeObject::meshSphere[i] = sphereBuilder.finalizedSceneNode();
     83    GLMoleculeObject::meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true);
    9084    QGLBuilder cylinderBuilder;
    9185    cylinderBuilder << QGLCylinder(.25,.25,1.0,cylinderDetails[i]);
    92     meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
    93     meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
     86    GLMoleculeObject::meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
     87    GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
    9488  }
    9589
    9690  connect(this, SIGNAL(updated()), this, SLOT(update()));
     91
    9792
    9893  setSelectionMode(SelectAtom);
     
    112107void GLWorldScene::init()
    113108{
    114   const std::vector<atom*> &atoms = World::getInstance().getAllAtoms();
    115 
    116   if (atoms.size() > 0) {
    117     for (std::vector<atom*>::const_iterator atomiter = atoms.begin();
    118         atomiter != atoms.end();
    119         atomiter++) {
    120       // create atom objects in scene
    121       atomInserted((*atomiter)->getId());
    122 
    123       // create bond objects in scene
    124       const BondList &bondlist = (*atomiter)->getListOfBonds();
    125       for (BondList::const_iterator bonditer = bondlist.begin();
    126           bonditer != bondlist.end();
    127           ++bonditer) {
    128         const bond::ptr _bond = *bonditer;
    129         const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == *atomiter) ?
    130             GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
    131         bondInserted(_bond, side);
    132       }
    133     }
     109  const std::vector<molecule *> &molecules = World::getInstance().getAllMolecules();
     110
     111  for (std::vector<molecule*>::const_iterator moliter = molecules.begin();
     112      moliter != molecules.end();
     113      moliter++) {
     114    // create molecule objects in scene
     115    moleculeInserted(*moliter);
    134116  }
    135117}
     
    143125void GLWorldScene::update()
    144126{
    145   const std::vector<atom*> &atoms = World::getInstance().getAllAtoms();
    146 
    147   if (atoms.size() > 0) {
    148     for (std::vector<atom*>::const_iterator atomiter = atoms.begin();
    149         atomiter != atoms.end();
    150         atomiter++) {
    151       // check whether atom already exists
    152       const atomId_t atomid = (*atomiter)->getId();
    153       const bool atom_present = AtomsinSceneMap.count(atomid);
    154       if (!atom_present)
    155         atomInserted((*atomiter)->getId());
    156       else
    157         AtomsinSceneMap[atomid]->resetPosition();
    158 
    159 
    160       // create bond objects in scene
    161       const BondList &bondlist = (*atomiter)->getListOfBonds();
    162       for (BondList::const_iterator bonditer = bondlist.begin();
    163           bonditer != bondlist.end();
    164           ++bonditer) {
    165         const bond::ptr _bond = *bonditer;
    166         const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == *atomiter) ?
    167             GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
    168         bool bond_present = false;
    169         const BondIds ids = getBondIds(_bond,side);
    170         if (atom_present) {
    171           // check whether bond is not present already
    172           bond_present = BondsinSceneMap.count(ids);
    173         }
    174         if (!bond_present)
    175           bondInserted(_bond, side);
    176         else {
    177           BondsinSceneMap[ids]->resetPosition();
    178           BondsinSceneMap[ids]->resetWidth();
    179         }
    180       }
    181     }
    182   }
    183 }
    184 
    185 /** Adds an atom to the scene.
    186  *
    187  * @param _atom atom to add
    188  */
    189 void GLWorldScene::atomInserted(const atomicNumber_t _id)
    190 {
    191   LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_id)+".");
    192   GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(meshSphere, this, _id);
    193   AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
    194   ASSERT(iter == AtomsinSceneMap.end(),
    195       "GLWorldScene::atomAdded() - same atom with id "+toString(_id)+" added again.");
    196   AtomsinSceneMap.insert( make_pair(_id, atomObject) );
    197 
    198   qRegisterMetaType<atomId_t>("atomId_t");
    199   qRegisterMetaType<bond::ptr>("bond::ptr");
    200   qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
    201   connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
    202   connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
    203   connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
    204   connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
    205   connect (atomObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
    206   connect (atomObject, SIGNAL(BondsInserted(const bond::ptr , const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond::ptr , const GLMoleculeObject_bond::SideOfBond)));
    207   connect (atomObject, SIGNAL(indexChanged(GLMoleculeObject_atom*, int, int)), this, SLOT(changeAtomId(GLMoleculeObject_atom*, int, int)));
    208   //bondsChanged(_atom);
    209   emit changeOccured();
    210 }
    211 
    212 /** Removes an atom from the scene.
    213  *
    214  * We just the id as the atom might have already been destroyed.
    215  *
    216  * @param _id id of atom to remove
    217  */
    218 void GLWorldScene::atomRemoved(const atomicNumber_t _id)
    219 {
    220   LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_id)+".");
    221   // bonds are removed by signal coming from ~bond
    222   // remove atoms
    223   AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
    224   ASSERT(iter != AtomsinSceneMap.end(),
    225       "GLWorldScene::atomRemoved() - atom "+toString(_id)+" not on display.");
    226   GLMoleculeObject_atom *atomObject = iter->second;
    227   atomObject->disconnect();
    228   AtomsinSceneMap.erase(iter);
    229   delete atomObject;
    230   emit changeOccured();
    231 }
    232 
    233 /** ....
    234  *
    235  */
    236 void GLWorldScene::worldSelectionChanged()
    237 {
    238   LOG(3, "INFO: GLWorldScene: Received signal selectionChanged.");
    239 
    240   const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
    241 
    242   if (molecules.size() > 0) {
    243     for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
    244         Runner != molecules.end();
    245         Runner++) {
    246 
    247       MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find((*Runner)->getId());
    248       bool isSelected = World::getInstance().isSelected(*Runner);
    249 
    250       // molecule selected but not in scene?
    251       if (isSelected && (iter == MoleculesinSceneMap.end())){
    252         // -> create new mesh
    253         GLMoleculeObject_molecule *molObject = new GLMoleculeObject_molecule(meshEmpty, this, *Runner);
    254         MoleculesinSceneMap.insert( make_pair((*Runner)->getId(), molObject) );
    255         connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
    256         connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
    257         connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
    258         emit changed();
    259         emit changeOccured();
    260       }
    261 
    262       // molecule not selected but in scene?
    263       if (!isSelected && (iter != MoleculesinSceneMap.end())){
    264         // -> remove from scene
    265         moleculeRemoved(*Runner);
    266       }
    267 
    268     }
    269   }
    270 }
    271 
    272 /** Removes a molecule from the scene.
    273  *
    274  * @param _molecule molecule to remove
    275  */
    276 void GLWorldScene::moleculeRemoved(const molecule *_molecule)
    277 {
    278   LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molecule->getId())+".");
    279   MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molecule->getId());
    280 
    281   // only remove if the molecule is in the scene
    282   //  (= is selected)
    283   if (iter != MoleculesinSceneMap.end()){
    284     GLMoleculeObject_molecule *molObject = iter->second;
    285     molObject->disconnect();
    286     MoleculesinSceneMap.erase(iter);
    287     delete molObject;
    288     emit changed();
    289     emit changeOccured();
    290   }
    291 }
    292 
    293 /** Helper function to get bond ids in the correct order for BondNodeMap.
    294  *
    295  * \return pair of ids in correct order.
    296  */
    297 GLWorldScene::BondIds GLWorldScene::getBondIds(
    298     const bond::ptr _bond,
    299     const enum GLMoleculeObject_bond::SideOfBond _side) const
    300 {
    301   BondIds ids;
    302   switch (_side) {
    303     case GLMoleculeObject_bond::left:
    304       ids = std::make_pair(_bond->leftatom->getId(), _bond->rightatom->getId());
    305       break;
    306     case GLMoleculeObject_bond::right:
    307       ids = std::make_pair(_bond->rightatom->getId(), _bond->leftatom->getId());
    308       break;
    309   }
    310   return ids;
    311 }
    312 
    313 /** Adds a bond to the scene.
    314  *
    315  * @param _bond bond to add
    316  * @param side which side of the bond (left or right)
    317  */
    318 void GLWorldScene::bondInserted(const bond::ptr _bond, const enum GLMoleculeObject_bond::SideOfBond _side)
    319 {
    320   LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
    321   //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
    322 
    323   const BondIds ids = getBondIds(_bond, _side);
    324   BondNodeMap::iterator iter = BondsinSceneMap.find(ids);
    325   if (iter == BondsinSceneMap.end()) {
    326     GLMoleculeObject_bond * bondObject =
    327         new GLMoleculeObject_bond(meshCylinder, this, _bond, _side);
    328     connect (
    329         bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)),
    330         this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
    331     connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
    332     BondsinSceneMap.insert( make_pair(ids, bondObject) );
    333   //    BondIdsinSceneMap.insert( Leftids );
    334   } else {
    335     iter->second->resetPosition();
    336     iter->second->resetWidth();
    337   }
    338   emit changeOccured();
    339 }
    340 
    341 /** Removes a bond from the scene.
    342  *
    343  * @param _bond bond to remove
    344  */
    345 void GLWorldScene::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
    346 {
    347   LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+".");
    348   {
    349     // left bond
    350     const BondIds Leftids( make_pair(leftnr, rightnr) );
    351     BondNodeMap::iterator leftiter = BondsinSceneMap.find( Leftids );
    352     ASSERT(leftiter != BondsinSceneMap.end(),
    353         "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
    354         +toString(rightnr)+" not on display.");
    355     GLMoleculeObject_bond *bondObject = leftiter->second;
    356     BondsinSceneMap.erase(leftiter);
    357     delete bondObject; // is done by signal from bond itself
    358     //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
    359   }
    360 
    361   emit changeOccured();
    362 }
    363 
    364 /** Adds a shape to the scene.
    365  *
    366  * uses ShapeRegistry::lastChanged()
    367  *
    368  */
    369 void GLWorldScene::addShape()
    370 {
    371   Shape &shape = *ShapeRegistry::getInstance().lastChanged();
    372   GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(shape, this);
    373   ShapeNodeMap::iterator iter = ShapesinSceneMap.find(shape.getName());
    374   ASSERT(iter == ShapesinSceneMap.end(),
    375       "GLWorldScene::addShape() - same shape "+shape.getName()+" added again.");
    376   ShapesinSceneMap.insert( make_pair(shape.getName(), shapeObject) );
    377 }
    378 
    379 void GLWorldScene::removeShape()
    380 {
    381   Shape &shape = *ShapeRegistry::getInstance().lastChanged();
    382   ShapeNodeMap::iterator iter = ShapesinSceneMap.find(shape.getName());
    383   ASSERT(iter != ShapesinSceneMap.end(),
    384       "GLWorldScene::removeShape() - shape "+shape.getName()+" not in scene.");
    385   ShapesinSceneMap.erase(iter);
    386   delete(iter->second);
    387 }
    388 
    389 void GLWorldScene::updateSelectedShapes()
    390 {
    391   foreach (QObject *obj, children()) {
    392     GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj);
    393       if (shapeobj){
    394         shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape()));
    395       }
    396   }
    397 }
    398 
    399 void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
    400 {
    401   // Initialize all of the mesh objects that we have as children.
    402    foreach (QObject *obj, children()) {
    403      GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
    404        if (meshobj)
    405          meshobj->initialize(view, painter);
    406    }
    407 }
    408 
    409 void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
    410 {
    411    // Draw all of the mesh objects that we have as children.
    412    foreach (QObject *obj, children()) {
    413      GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
    414        if (meshobj)
    415          meshobj->draw(painter, cameraPlane);
    416    }
     127  const std::vector<molecule *> &molecules = World::getInstance().getAllMolecules();
     128
     129  for (std::vector<molecule*>::const_iterator moliter = molecules.begin();
     130      moliter != molecules.end();
     131      moliter++) {
     132    // check whether molecule already exists
     133    const moleculeId_t molid = (*moliter)->getId();
     134    const bool mol_present = MoleculesinSceneMap.count(molid);
     135    if (!mol_present)
     136      moleculeInserted(*moliter);
     137  }
    417138}
    418139
    419140void GLWorldScene::atomClicked(atomId_t no)
    420141{
    421    LOG(3, "INFO: GLWorldScene - atom " << no << " has been clicked.");
     142   LOG(3, "INFO: GLMoleculeObject_molecule - atom " << no << " has been clicked.");
    422143   const atom *Walker = World::getInstance().getAtom(AtomById(no));
    423144   if (selectionMode == SelectAtom){
     
    437158}
    438159
     160
     161/** Adds an atom to the scene.
     162 *
     163 * @param _atom atom to add
     164 */
     165void GLWorldScene::atomInserted(const atomId_t _id)
     166{
     167  LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_id)+".");
     168  // find associated molecule
     169  const moleculeId_t molid = World::getInstance().getAtom(AtomById(_id))->getMolecule()->getId();
     170  MoleculeNodeMap::const_iterator moliter = MoleculesinSceneMap.find(molid );
     171  ASSERT(moliter != MoleculesinSceneMap.end(),
     172      "GLWorldScene::atomAdded() - molecule with id of "+toString(molid)
     173      +" atom with id "+toString(_id)+" is unknown.");
     174  GLMoleculeObject_molecule *molObject = moliter->second;
     175
     176  // add atom to internal list
     177#ifndef NDEBUG
     178  AtomMoleculeMap::const_iterator atomiter = AtomsinSceneMap.find(_id);
     179    ASSERT(atomiter == AtomsinSceneMap.end(),
     180        "GLWorldScene::atomRemoved() - atom "+toString(_id)+" already known.");
     181#endif
     182  AtomsinSceneMap.insert( std::make_pair( _id, molObject ));
     183
     184  // inform its GlMoleculeObject_molecule.
     185  molObject->atomInserted(_id);
     186
     187  // emit change
     188  emit changeOccured();
     189}
     190
     191/** Removes an atom from the scene.
     192 *
     193 * We just the id as the atom might have already been destroyed.
     194 *
     195 * @param _id id of atom to remove
     196 */
     197void GLWorldScene::atomRemoved(const atomId_t _id)
     198{
     199  LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_id)+".");
     200  // find associated molecule
     201  AtomMoleculeMap::iterator iter = AtomsinSceneMap.find(_id);
     202  ASSERT(iter != AtomsinSceneMap.end(),
     203      "GLWorldScene::atomRemoved() - atom "+toString(_id)+" not on display.");
     204  GLMoleculeObject_molecule *molObject = iter->second;
     205
     206  // remove from internal list
     207  AtomsinSceneMap.erase(iter);
     208
     209  // inform its GlMoleculeObject_molecule.
     210  molObject->atomRemoved(_id);
     211
     212  // emit change
     213  emit changeOccured();
     214}
     215
     216/** ....
     217 *
     218 */
     219void GLWorldScene::worldSelectionChanged()
     220{
     221  LOG(3, "INFO: GLWorldScene: Received signal selectionChanged.");
     222
     223  const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
     224
     225  if (molecules.size() > 0) {
     226    for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
     227        Runner != molecules.end();
     228        Runner++) {
     229
     230      // molecule selected but not in scene?
     231      const bool isSelected = World::getInstance().isSelected(*Runner);
     232      if (isSelected){
     233        MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find((*Runner)->getId());
     234        ASSERT( iter != MoleculesinSceneMap.end(),
     235            "GLWorldScene::worldSelectionChanged() - selected molecule is unknown.");
     236        GLMoleculeObject_molecule *molObject = iter->second;
     237        // inform molecule object
     238        molObject->selected(isSelected);
     239      }
     240    }
     241  }
     242}
     243
     244/** Inserts a molecule into the scene.
     245 *
     246 * @param _mol molecule to insert
     247 */
     248void GLWorldScene::moleculeInserted(const molecule * _mol)
     249{
     250  LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_mol->getId())+".");
     251  MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(_mol->getId());
     252  ASSERT( iter == MoleculesinSceneMap.end(),
     253      "GLWorldScene::moleculeInserted() - molecule's id "+toString(_mol->getId())+" already present.");
     254
     255  // add new object
     256  GLMoleculeObject_molecule *molObject = new GLMoleculeObject_molecule(GLMoleculeObject::meshEmpty, this, _mol);
     257  MoleculesinSceneMap.insert( make_pair(_mol->getId(), molObject) );
     258  connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
     259  connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
     260  connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
     261  connect (molObject, SIGNAL(changeAtomId(GLMoleculeObject_atom *, int, int)), this, SLOT(changeAtomId(GLMoleculeObject_atom *, int, int)));
     262  connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
     263  connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
     264  connect (molObject, SIGNAL(hoverChanged(const atom *)), this, SIGNAL(hoverChanged(const atom *)));
     265  emit changed();
     266  emit changeOccured();
     267}
     268
     269/** Removes a molecule from the scene.
     270 *
     271 * @param _id id of molecule to remove
     272 */
     273void GLWorldScene::moleculeRemoved(const moleculeId_t _id)
     274{
     275  LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_id)+".");
     276  MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
     277  ASSERT( iter != MoleculesinSceneMap.end(),
     278      "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" is unknown.");
     279
     280  GLMoleculeObject_molecule *molObject = iter->second;
     281  molObject->disconnect();
     282  MoleculesinSceneMap.erase(iter);
     283  delete molObject;
     284  emit changed();
     285  emit changeOccured();
     286}
     287
     288/** Adds a bond to the scene.
     289 *
     290 * @param _bond bond to add
     291 * @param side which side of the bond (left or right)
     292 */
     293void GLWorldScene::bondInserted(const bond::ptr _bond, const enum GLMoleculeObject_bond::SideOfBond _side)
     294{
     295  LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
     296  //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
     297  // bond partners must both belong to same atom
     298  ASSERT( _bond->leftatom->getMolecule() == _bond->rightatom->getMolecule(),
     299      "GLWorldScene::bondInserted() - bond partners do not belong to same molecule.");
     300
     301  // find associated molecule object
     302  const moleculeId_t molid = _bond->leftatom->getMolecule()->getId();
     303  MoleculeNodeMap::const_iterator moliter = MoleculesinSceneMap.find(molid );
     304  ASSERT(moliter != MoleculesinSceneMap.end(),
     305      "GLWorldScene::bondInserted() - molecule with id of "+toString(molid)
     306      +" atom with id "+toString(_bond->leftatom->getId())+" is unknown.");
     307  GLMoleculeObject_molecule *molObject = moliter->second;
     308
     309  // add to internal list
     310  const GLMoleculeObject_molecule::BondIds ids =
     311      GLMoleculeObject_molecule::getBondIds(_bond, _side);
     312  BondMoleculeMap::const_iterator iter = BondsinSceneMap.find(ids);
     313  ASSERT(iter == BondsinSceneMap.end(),
     314      "GLWorldScene::bondInserted() - bond with ids "+toString(ids.first)
     315      +","+toString(ids.second)+" already present.");
     316  BondsinSceneMap.insert( std::make_pair( ids, molObject ));
     317
     318  // inform its GlMoleculeObject_molecule.
     319  molObject->bondInserted(_bond, _side);
     320
     321  // emit change
     322  emit changeOccured();
     323}
     324
     325/** Removes a bond from the scene.
     326 *
     327 * @param _bond bond to remove
     328 */
     329void GLWorldScene::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
     330{
     331  LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+".");
     332  {
     333    // left bond
     334    const GLMoleculeObject_molecule::BondIds Leftids( make_pair(leftnr, rightnr) );
     335    BondMoleculeMap::iterator leftiter = BondsinSceneMap.find( Leftids );
     336    ASSERT(leftiter != BondsinSceneMap.end(),
     337        "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
     338        +toString(rightnr)+" not on display.");
     339    GLMoleculeObject_molecule *molObject = leftiter->second;
     340
     341    // remove from internal list
     342    BondsinSceneMap.erase(leftiter);
     343
     344    // inform its GlMoleculeObject_molecule.
     345    molObject->bondRemoved( leftnr, rightnr );
     346  }
     347
     348  // emit change
     349  emit changeOccured();
     350}
     351
     352/** Adds a shape to the scene.
     353 *
     354 * uses ShapeRegistry::lastChanged()
     355 *
     356 */
     357void GLWorldScene::addShape()
     358{
     359  Shape &shape = *ShapeRegistry::getInstance().lastChanged();
     360  GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(shape, this);
     361  ShapeNodeMap::iterator iter = ShapesinSceneMap.find(shape.getName());
     362  ASSERT(iter == ShapesinSceneMap.end(),
     363      "GLWorldScene::addShape() - same shape "+shape.getName()+" added again.");
     364  ShapesinSceneMap.insert( make_pair(shape.getName(), shapeObject) );
     365}
     366
     367void GLWorldScene::removeShape()
     368{
     369  Shape &shape = *ShapeRegistry::getInstance().lastChanged();
     370  ShapeNodeMap::iterator iter = ShapesinSceneMap.find(shape.getName());
     371  ASSERT(iter != ShapesinSceneMap.end(),
     372      "GLWorldScene::removeShape() - shape "+shape.getName()+" not in scene.");
     373  ShapesinSceneMap.erase(iter);
     374  delete(iter->second);
     375}
     376
     377void GLWorldScene::updateSelectedShapes()
     378{
     379  foreach (QObject *obj, children()) {
     380    GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj);
     381      if (shapeobj){
     382        shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape()));
     383      }
     384  }
     385}
     386
     387void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
     388{
     389  // Initialize all of the mesh objects that we have as children.
     390   foreach (QObject *obj, children()) {
     391     GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
     392       if (meshobj)
     393         meshobj->initialize(view, painter);
     394   }
     395}
     396
     397void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
     398{
     399   // Draw all of the mesh objects that we have as children.
     400   foreach (QObject *obj, children()) {
     401     GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
     402       if (meshobj)
     403         meshobj->draw(painter, cameraPlane);
     404   }
     405}
     406
    439407void GLWorldScene::setSelectionMode(SelectionModeType mode)
    440408{
     
    453421}
    454422
    455 void GLWorldScene::hoverChangedSignalled(GLMoleculeObject *ob)
    456 {
    457   // Find the atom, ob corresponds to.
    458   hoverAtom = NULL;
    459   GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
    460   if (atomObject){
    461     for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
    462       if (iter->second == atomObject)
    463         hoverAtom = World::getInstance().getAtom(AtomById(iter->first));
    464     }
    465   }
    466 
    467   // Propagate signal.
    468   emit hoverChanged(hoverAtom);
    469 }
    470 
    471423void GLWorldScene::changeAtomId(GLMoleculeObject_atom *ob, int oldId, int newId)
    472424{
    473425  LOG(3, "INFO: GLWorldScene - change atom id " << oldId << " to " << newId << ".");
    474426  // Remove from map.
    475   AtomNodeMap::iterator iter = AtomsinSceneMap.find(oldId);
     427  AtomMoleculeMap::iterator iter = AtomsinSceneMap.find(oldId);
    476428  ASSERT(iter != AtomsinSceneMap.end(),
    477         "GLWorldScene::objectIdChangedSignalled() - atom with id "+toString(oldId)+" not on display.");
    478   GLMoleculeObject_atom *atomObject = iter->second;
     429        "GLWorldScene::changeAtomId() - atom with old id "+toString(oldId)+" not on display.");
     430  GLMoleculeObject_molecule *molObject = iter->second;
     431
     432  // erase by signalling removal
     433  molObject->atomRemoved(oldId);
     434
     435  // remove from internal list
    479436  AtomsinSceneMap.erase(iter);
    480437
    481438  // Reinsert with new id.
    482   AtomsinSceneMap.insert( make_pair(newId, atomObject) );
    483 }
    484 
     439  {
     440    AtomMoleculeMap::iterator iter = AtomsinSceneMap.find(newId);
     441    ASSERT(iter == AtomsinSceneMap.end(),
     442          "GLWorldScene::changeAtomId() - atom with new id "+toString(newId)+" already known.");
     443  }
     444  AtomsinSceneMap.insert( make_pair(newId, molObject) );
     445
     446  // inform molecule object
     447  molObject->atomInserted(oldId);
     448}
     449
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    r7b38d3 r8c001a  
    7575  void clicked(atomId_t);
    7676  void doubleClicked();
    77   void hoverChanged(const atom*);
     77  void hoverChanged(const atom *);
    7878
    7979private slots:
    8080  void atomClicked(atomId_t no);
    81   void atomInserted(const atomicNumber_t _id);
    82   void atomRemoved(const atomicNumber_t _id);
    83   void moleculeRemoved(const molecule *_molecule);
     81  void atomInserted(const atomId_t _id);
     82  void atomRemoved(const atomId_t _id);
     83  void moleculeRemoved(const moleculeId_t _id);
     84  void moleculeInserted(const molecule * _mol);
    8485  void worldSelectionChanged();
    8586  void bondInserted(const bond::ptr _bond, const GLMoleculeObject_bond::SideOfBond side);
     
    8788  void setSelectionModeAtom();
    8889  void setSelectionModeMolecule();
    89   void hoverChangedSignalled(GLMoleculeObject *ob);
    9090  void changeAtomId(GLMoleculeObject_atom *ob, int oldId, int newOd);
    9191  void addShape();
     
    100100
    101101private:
    102   typedef std::pair< atomId_t, atomId_t> BondIds;
    103   friend std::ostream &operator<<(std::ostream &ost, const BondIds &t);
    104102
    105   BondIds getBondIds(
    106       const bond::ptr _bond,
    107       const enum GLMoleculeObject_bond::SideOfBond side) const;
    108 
    109   typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap;
    110   typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap;
     103  typedef std::map< atomId_t, GLMoleculeObject_molecule* > AtomMoleculeMap;
     104  typedef std::map< GLMoleculeObject_molecule::BondIds , GLMoleculeObject_molecule* > BondMoleculeMap;
    111105  typedef std::map< moleculeId_t , GLMoleculeObject_molecule* > MoleculeNodeMap;
    112106  typedef std::map< std::string , GLMoleculeObject_shape* > ShapeNodeMap;
    113   AtomNodeMap AtomsinSceneMap;
    114   BondNodeMap BondsinSceneMap;
     107  AtomMoleculeMap AtomsinSceneMap;
     108  BondMoleculeMap BondsinSceneMap;
    115109  MoleculeNodeMap MoleculesinSceneMap;
    116110  ShapeNodeMap ShapesinSceneMap;
    117111
    118   QGLSceneNode *meshEmpty[GLMoleculeObject::DETAILTYPES_MAX];
    119   QGLSceneNode *meshSphere[GLMoleculeObject::DETAILTYPES_MAX];
    120   QGLSceneNode *meshCylinder[GLMoleculeObject::DETAILTYPES_MAX];
    121 
    122112  SelectionModeType selectionMode;
    123   const atom *hoverAtom;
    124113};
    125114
    126 std::ostream &operator<<(std::ostream &ost, const GLWorldScene::BondIds &t);
    127 
    128115#endif /* GLWORLDSCENE_HPP_ */
  • src/UIElements/Views/Qt4/Qt3D/GLWorldView.cpp

    r7b38d3 r8c001a  
    7878  //changeMaterials(false);
    7979
    80   qRegisterMetaType<atomicNumber_t>("atomicNumber_t");
     80  qRegisterMetaType<atomId_t>("atomId_t");
     81  qRegisterMetaType<moleculeId_t>("moleculeId_t");
    8182
    8283  connect(this, SIGNAL(ShapeAdded()), worldscene, SLOT(addShape()));
     
    8687  connect(worldscene, SIGNAL(changed()), this, SIGNAL(changed()));
    8788  connect(worldscene, SIGNAL(hoverChanged(const atom *)), this, SLOT(sceneHoverSignalled(const atom *)));
    88   connect(this, SIGNAL(atomInserted(const atomicNumber_t)), worldscene, SLOT(atomInserted(const atomicNumber_t)));
    89   connect(this, SIGNAL(atomRemoved(const atomicNumber_t)), worldscene, SLOT(atomRemoved(const atomicNumber_t)));
    9089  connect(this, SIGNAL(worldSelectionChanged()), worldscene, SLOT(worldSelectionChanged()));
    91   connect(this, SIGNAL(moleculeRemoved(const molecule *)), worldscene, SLOT(moleculeRemoved(const molecule *)));
    92   //connect(this, SIGNAL(moleculeInserted(const molecule *)), worldscene, SLOT(moleculeInserted(const molecule *)));
     90  connect(this, SIGNAL(moleculeRemoved(const moleculeId_t)), worldscene, SLOT(moleculeRemoved(const moleculeId_t)));
     91  connect(this, SIGNAL(moleculeInserted(const molecule *)), worldscene, SLOT(moleculeInserted(const molecule *)));
    9392  //connect(this, SIGNAL(changed()), this, SLOT(updateGL()));
    9493  connect(this, SIGNAL(changed()), this, SLOT(sceneChangeSignalled()));
     
    9695  // sign on to changes in the world
    9796  World::getInstance().signOn(this);
    98   World::getInstance().signOn(this, World::AtomInserted);
    99   World::getInstance().signOn(this, World::AtomRemoved);
    10097  World::getInstance().signOn(this, World::MoleculeInserted);
    10198  World::getInstance().signOn(this, World::MoleculeRemoved);
     
    338335  if (static_cast<World *>(publisher) == World::getPointer()) {
    339336    switch (notification->getChannelNo()) {
    340       case World::AtomInserted:
    341       {
    342         const atomicNumber_t _id = World::getInstance().lastChanged<atom>()->getId();
    343   #ifdef LOG_OBSERVER
    344         observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted.";
    345   #endif
    346         emit atomInserted(_id);
    347         break;
    348       }
    349       case World::AtomRemoved:
    350       {
    351         const atomicNumber_t _id = World::getInstance().lastChanged<atom>()->getId();
    352   #ifdef LOG_OBSERVER
    353         observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been removed.";
    354   #endif
    355         emit atomRemoved(_id);
    356         break;
    357       }
    358337      case World::SelectionChanged:
    359338      {
     
    366345      case World::MoleculeInserted:
    367346      {
    368         const molecule *_molecule = World::getInstance().lastChanged<molecule>();
     347        const molecule * _mol = World::getInstance().lastChanged<molecule>();
    369348  #ifdef LOG_OBSERVER
    370         observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that molecule "+toString(_molecule->getId())+" has been removed.";
     349        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that molecule "+toString(_mol->getId())+" has been removed.";
    371350  #endif
    372         emit moleculeInserted(_molecule);
     351        emit moleculeInserted(_mol);
    373352        break;
    374353      }
    375354      case World::MoleculeRemoved:
    376355      {
    377         const molecule *_molecule = World::getInstance().lastChanged<molecule>();
     356        const moleculeId_t _id = World::getInstance().lastChanged<molecule>()->getId();
    378357  #ifdef LOG_OBSERVER
    379         observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that molecule "+toString(_molecule->getId())+" has been removed.";
     358        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that molecule "+toString(_id)+" has been removed.";
    380359  #endif
    381         emit moleculeRemoved(_molecule);
     360        emit moleculeRemoved(_id);
    382361        break;
    383362      }
  • src/UIElements/Views/Qt4/Qt3D/GLWorldView.hpp

    r7b38d3 r8c001a  
    5858  void changed();
    5959  void TimeChanged();
    60   void atomInserted(const atomicNumber_t _id);
    61   void atomRemoved(const atomicNumber_t _id);
    62   void moleculeInserted(const molecule *_molecule);
    63   void moleculeRemoved(const molecule *_molecule);
     60  void moleculeInserted(const molecule * _mol);
     61  void moleculeRemoved(const moleculeId_t _id);
    6462  void worldSelectionChanged();
    6563  void hoverChanged(const atom *_atom);
  • src/molecule.cpp

    r7b38d3 r8c001a  
    146146  OBSERVE;
    147147  if(atomIdPool.reserveId(newNr)){
     148    _lastchangedatom = target;
    148149    NOTIFY(AtomNrChanged);
    149150    if (oldNr != -1)  // -1 is reserved and indicates no number
     
    207208{
    208209  OBSERVE;
    209   NOTIFY(AtomRemoved);
    210210  const_iterator iter = loc;
    211211  ++iter;
    212212  atom * const _atom = const_cast<atom *>(*loc);
     213  {
     214    _lastchangedatom = _atom;
     215    NOTIFY(AtomRemoved);
     216  }
    213217  atomIds.erase( _atom->getId() );
    214218  {
     
    226230{
    227231  OBSERVE;
    228   NOTIFY(AtomRemoved);
     232  {
     233    _lastchangedatom = key;
     234    NOTIFY(AtomRemoved);
     235  }
    229236  const_iterator iter = find(key);
    230237  if (iter != end()){
     
    247254  OBSERVE;
    248255  NOTIFY(AtomInserted);
     256  _lastchangedatom = key;
    249257  std::pair<iterator,bool> res = atomIds.insert(key->getId());
    250258  if (res.second) { // push atom if went well
     
    974982    for(const_iterator iter = begin(); iter != end(); ++iter)
    975983      center += (*iter)->getPosition();
    976     center *= 1./(double)size();
     984    if (begin() != end())
     985      center *= 1./(double)size();
    977986    for(const_iterator iter = begin(); iter != end(); ++iter) {
    978987      const Vector &position = (*iter)->getPosition();
  • src/molecule.hpp

    r7b38d3 r8c001a  
    108108    NotificationType_MAX
    109109  };
     110
     111  //>! access to last changed element (atom)
     112  const atom* lastChanged() const
     113  { return _lastchangedatom; }
    110114
    111115public:
     
    319323
    320324private:
     325  friend const atom *detail::lastChanged<atom>();
     326  atom *_lastchangedatom;
     327
    321328  int last_atom; //!< number given to last atom
    322329};
Note: See TracChangeset for help on using the changeset viewer.