Ignore:
File:
1 edited

Legend:

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

    r2ad1ec r3927ef  
    2525#include "GLMoleculeObject_atom.hpp"
    2626#include "GLMoleculeObject_bond.hpp"
     27#include "GLMoleculeObject_molecule.hpp"
    2728
    2829#include "CodePatterns/MemDebug.hpp"
     
    7475        Runner != molecules.end();
    7576        Runner++) {
    76       // create molecule
     77
    7778      for (molecule::const_iterator atomiter = (*Runner)->begin();
    7879          atomiter != (*Runner)->end();
     
    109110  AtomsinSceneMap.insert( make_pair(_atom->getId(), atomObject) );
    110111  connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
     112  connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
    111113  connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(changed()));
     114  connect (atomObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
    112115  connect (atomObject, SIGNAL(BondsInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)));
    113116  //bondsChanged(_atom);
     
    134137}
    135138
     139/** ....
     140 *
     141 */
     142void GLWorldScene::worldSelectionChanged()
     143{
     144  LOG(3, "INFO: GLWorldScene: Received signal selectionChanged.");
     145
     146  const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
     147
     148  if (molecules.size() > 0) {
     149    for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
     150        Runner != molecules.end();
     151        Runner++) {
     152
     153      MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find((*Runner)->getId());
     154      bool isSelected = World::getInstance().isSelected(*Runner);
     155
     156      // molecule selected but not in scene?
     157      if (isSelected && (iter == MoleculesinSceneMap.end())){
     158        // -> create new mesh
     159        GLMoleculeObject_molecule *molObject = new GLMoleculeObject_molecule(this, *Runner);
     160        MoleculesinSceneMap.insert( make_pair((*Runner)->getId(), molObject) );
     161        connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
     162        connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
     163        connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
     164        emit changed();
     165        emit changeOccured();
     166      }
     167
     168      // molecule not selected but in scene?
     169      if (!isSelected && (iter != MoleculesinSceneMap.end())){
     170        // -> remove from scene
     171        moleculeRemoved(*Runner);
     172      }
     173
     174    }
     175  }
     176}
     177
     178/** Removes a molecule from the scene.
     179 *
     180 * @param _molecule molecule to remove
     181 */
     182void GLWorldScene::moleculeRemoved(const molecule *_molecule)
     183{
     184  LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molecule->getId())+".");
     185  MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molecule->getId());
     186
     187  // only remove if the molecule is in the scene
     188  //  (= is selected)
     189  if (iter != MoleculesinSceneMap.end()){
     190    GLMoleculeObject_molecule *molObject = iter->second;
     191    molObject->disconnect();
     192    MoleculesinSceneMap.erase(iter);
     193    delete molObject;
     194    emit changed();
     195    emit changeOccured();
     196  }
     197}
     198
    136199/** Adds a bond to the scene.
    137200 *
     
    143206  LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
    144207  //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
    145   const double distance =
    146       _bond->leftatom->getPosition().distance(_bond->rightatom->getPosition())/2.;
    147208
    148209  BondIds ids;
     
    161222#endif
    162223  GLMoleculeObject_bond *bondObject =
    163       new GLMoleculeObject_bond(this, _bond, distance, side);
     224      new GLMoleculeObject_bond(this, _bond, side);
    164225  connect (
    165226      bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)),
    166227      this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
     228  connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
    167229  BondsinSceneMap.insert( make_pair(ids, bondObject) );
    168230//    BondIdsinSceneMap.insert( Leftids );
Note: See TracChangeset for help on using the changeset viewer.