Changeset 37b2575 for src


Ignore:
Timestamp:
Oct 6, 2011, 4:06:10 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
5e2f80
Parents:
db7e6d
git-author:
Frederik Heber <heber@…> (09/01/11 16:33:11)
git-committer:
Frederik Heber <heber@…> (10/06/11 16:06:10)
Message:

GLMoleculeObject_atom listens to BondsChanged notification.

  • signal is sent to slot in GLWorldScene which inserts or removes bonds for the specific atom.
  • i.e. now we may load a file and both atoms and bonds are correctly shown via the observer mechanism.
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
5 edited

Legend:

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

    rdb7e6d r37b2575  
    5050  atomref->signOn(this, atomref->getChannel(AtomObservable::PositionChanged));
    5151  atomref->signOn(this, atomref->getChannel(AtomObservable::ElementChanged));
     52  atomref->signOn(this, atomref->getChannel(AtomObservable::BondsChanged));
    5253
    5354  // set the object's id
     
    126127void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
    127128{
    128   LOG(0, "GLMoleculeObject_atom::recieveNotification() - notification type "
     129  LOG(0, "GLMoleculeObject_atom::recieveNotification() - atom "
     130      +toString(_atom->getId())+" got notification type "
    129131      +toString(notification->getChannelNo())+".");
    130132  switch (notification->getChannelNo()) {
     
    137139    case AtomObservable::PositionChanged:
    138140      resetPosition();
     141      break;
     142    case AtomObservable::BondsChanged:
     143      emit BondsChanged(_atom);
    139144      break;
    140145    default:
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp

    rdb7e6d r37b2575  
    3737signals:
    3838  void clicked(atomId_t);
     39  void BondsChanged(const atom *_atom);
    3940
    4041private:
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    rdb7e6d r37b2575  
    3232#include "atom.hpp"
    3333#include "Bond/bond.hpp"
     34#include "Helpers/helpers.hpp"
    3435#include "molecule.hpp"
    3536#include "World.hpp"
     
    9192  LOG(0, "GLWorldScene: Received signal atomInserted for atom "+toString(_atom->getId())+".");
    9293  GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(this, _atom);
    93   AtomNodeMap::iterator iter = AtomsinMoleculeMap.find(_atom->getId());
    94   ASSERT(iter == AtomsinMoleculeMap.end(),
     94  AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId());
     95  ASSERT(iter == AtomsinSceneMap.end(),
    9596      "GLWorldScene::atomAdded() - same atom "+_atom->getName()+" added again.");
    96   AtomsinMoleculeMap.insert( make_pair(_atom->getId(), atomObject) );
     97  AtomsinSceneMap.insert( make_pair(_atom->getId(), atomObject) );
    9798  connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
    9899  connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(hoverChanged()));
     100  connect (atomObject, SIGNAL(BondsChanged(const atom *)), this, SLOT(bondsChanged(const atom *)));
     101  bondsChanged(_atom);
    99102  emit changed();
    100103}
     
    110113  const BondList& bondlist = _atom->getListOfBonds();
    111114  for (BondList::const_iterator iter = bondlist.begin(); iter != bondlist.end(); ++iter) {
    112     bondRemoved(*iter);
     115    bondRemoved((*iter)->leftatom->getId(), (*iter)->rightatom->getId());
     116    bondRemoved((*iter)->rightatom->getId(), (*iter)->leftatom->getId());
    113117  }
    114118  // remove atoms
    115   AtomNodeMap::iterator iter = AtomsinMoleculeMap.find(_atom->getId());
    116   ASSERT(iter != AtomsinMoleculeMap.end(),
     119  AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId());
     120  ASSERT(iter != AtomsinSceneMap.end(),
    117121      "GLWorldScene::atomRemoved() - atom "+_atom->getName()+" not on display.");
    118122  GLMoleculeObject_atom *atomObject = iter->second;
    119123  atomObject->disconnect();
    120   AtomsinMoleculeMap.erase(iter);
     124  AtomsinSceneMap.erase(iter);
    121125  delete atomObject;
    122126  emit changed();
    123127}
    124128
    125 /** Adds an bond to the scene.
     129/** Updates the bond structure of the signaled \a _atom.
     130 *
     131 * @param _atom atom whose bonds changed.
     132 */
     133void GLWorldScene::bondsChanged(const atom *_atom)
     134{
     135  const atomId_t id = _atom->getId();
     136
     137  // create list with all present bonds
     138  std::set< atomId_t > presentBonds;
     139  std::pair< BondIdsMap::const_iterator, BondIdsMap::const_iterator> range =
     140      BondIdsinSceneMap.equal_range( id );
     141  for (BondIdsMap::const_iterator iter = range.first; iter != range.second; ++iter) {
     142    const atomId_t otherid = iter->second;
     143#ifndef NDEBUG
     144    std::set< atomId_t >::const_iterator iter = presentBonds.find(otherid);
     145    ASSERT(iter == presentBonds.end(),
     146        "GLWorldScene::BondsChanged() - bond id "+toString(otherid)+" for atom "
     147        +toString(id)+" present twice.");
     148#endif
     149    presentBonds.insert( otherid );
     150  }
     151  LOG(0, "We have the following bonds: "+toString(presentBonds)+".");
     152
     153  // search for added bonds
     154  const BondList &bondlist = _atom->getListOfBonds();
     155  for (BondList::const_iterator bonditer = bondlist.begin();
     156      bonditer != bondlist.end();
     157      ++bonditer) {
     158    const bond *_bond = *bonditer;
     159    const atomId_t otherid = _bond->GetOtherAtom(_atom)->getId();
     160    const BondIds ids = std::make_pair( id, otherid );
     161    BondNodeMap::const_iterator iter = BondsinSceneMap.find(ids);
     162    if (iter != BondsinSceneMap.end()) {
     163      // bond is already present
     164      std::set< atomId_t >::const_iterator iter = presentBonds.find(otherid);
     165      ASSERT(iter != presentBonds.end(),
     166          "GLWorldScene::BondsChanged() - other id "+toString(otherid)+" for atom "
     167          +toString(_atom->getId())+" not present in BondIdsinSceneMap.");
     168      presentBonds.erase(otherid);
     169      LOG(0, "Removing "+toString(otherid)+" from presentBonds.");
     170    } else {
     171      // insert new bond
     172      bondInserted(_bond);
     173    }
     174  }
     175  LOG(0, "The following bonds should not be present: "+toString(presentBonds)+".");
     176
     177  // remove all still presentBonds
     178  for (std::set< atomId_t >::iterator iter = presentBonds.begin();
     179      !presentBonds.empty(); iter = presentBonds.begin()) {
     180    bondRemoved( id, *iter );
     181  }
     182}
     183
     184/** Adds a bond to the scene.
    126185 *
    127186 * @param _bond bond to add
     
    129188void GLWorldScene::bondInserted(const bond *_bond)
    130189{
     190  LOG(0, "GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
    131191  const double distance =
    132192      _bond->leftatom->getPosition().distance(_bond->rightatom->getPosition())/2.;
     
    134194    // left bond
    135195    const BondIds Leftids( make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()) );
    136     BondNodeMap::iterator iter = BondsinMoleculeMap.find(Leftids);
    137     ASSERT(iter == BondsinMoleculeMap.end(),
     196    BondNodeMap::iterator iter = BondsinSceneMap.find(Leftids);
     197    ASSERT(iter == BondsinSceneMap.end(),
    138198        "GLWorldScene::bondAdded() - same left-sided bond "+toString(*_bond)+" added again.");
    139199    GLMoleculeObject_bond *bondObject =
    140200        new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::left);
    141     BondsinMoleculeMap.insert( make_pair(Leftids, bondObject) );
     201    BondsinSceneMap.insert( make_pair(Leftids, bondObject) );
     202    BondIdsinSceneMap.insert( Leftids );
    142203  }
    143204  {
    144205    // right bond
    145206    const BondIds Rightids( make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()) );
    146     BondNodeMap::iterator iter = BondsinMoleculeMap.find(Rightids);
    147     ASSERT(iter == BondsinMoleculeMap.end(),
     207    BondNodeMap::iterator iter = BondsinSceneMap.find(Rightids);
     208    ASSERT(iter == BondsinSceneMap.end(),
    148209        "GLWorldScene::bondAdded() - same right-sided bond "+toString(*_bond)+" added again.");
    149210    GLMoleculeObject_bond *bondObject =
    150211        new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::right);
    151     BondsinMoleculeMap.insert( make_pair(Rightids, bondObject) );
    152   }
    153   emit changed();
    154 }
    155 
    156 /** Removes an bond from the scene.
     212    BondsinSceneMap.insert( make_pair(Rightids, bondObject) );
     213    BondIdsinSceneMap.insert( Rightids );
     214  }
     215  emit changed();
     216}
     217
     218/** Removes a bond from the scene.
    157219 *
    158220 * @param _bond bond to remove
    159221 */
    160 void GLWorldScene::bondRemoved(const bond *_bond)
    161 {
     222void GLWorldScene::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
     223{
     224  LOG(0, "GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(leftnr)+".");
    162225  {
    163226    // left bond
    164     const BondIds Leftids( make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()) );
    165     BondNodeMap::iterator leftiter = BondsinMoleculeMap.find( Leftids );
    166     ASSERT(leftiter != BondsinMoleculeMap.end(),
    167         "GLWorldScene::bondRemoved() - bond "+toString(*_bond)+" not on display.");
     227    const BondIds Leftids( make_pair(leftnr, rightnr) );
     228    BondNodeMap::iterator leftiter = BondsinSceneMap.find( Leftids );
     229    ASSERT(leftiter != BondsinSceneMap.end(),
     230        "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
     231        +toString(rightnr)+" not on display.");
    168232    GLMoleculeObject_bond *bondObject = leftiter->second;
    169     BondsinMoleculeMap.erase(leftiter);
     233    BondsinSceneMap.erase(leftiter);
    170234    delete bondObject;
    171235  }
    172   {
    173     // right bond
    174     const BondIds Rightids( make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()) );
    175     BondNodeMap::iterator rightiter = BondsinMoleculeMap.find( Rightids );
    176     ASSERT(rightiter != BondsinMoleculeMap.end(),
    177         "GLWorldScene::bondRemoved() - bond "+toString(*_bond)+" not on display.");
    178     GLMoleculeObject_bond *bondObject = rightiter->second;
    179     BondsinMoleculeMap.erase(rightiter);
    180     delete bondObject;
    181   }
     236  // remove from bond ids
     237  std::pair<BondIdsMap::iterator, BondIdsMap::iterator> leftrange =
     238      BondIdsinSceneMap.equal_range(leftnr);
     239  BondIdsMap::iterator iter;
     240  for (iter = leftrange.first; iter != leftrange.second; ++iter) {
     241    if (iter->second == rightnr) {
     242      BondIdsinSceneMap.erase(iter);
     243      break;
     244    }
     245  }
     246  ASSERT(iter != leftrange.second,
     247      "GLWorldScene::bondRemoved() - could not find ("
     248      +toString(leftnr)+"-"+toString(rightnr)+" in BondIdsinSceneMap.");
    182249  emit changed();
    183250}
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    rdb7e6d r37b2575  
    6464  void atomInserted(const atom *_atom);
    6565  void atomRemoved(const atom *_atom);
    66   void bondInserted(const bond *_bond);
    67   void bondRemoved(const bond *_bond);
     66  void bondsChanged(const atom *_atom);
    6867
    6968private:
    7069  void init();
     70  void bondInserted(const bond *_bond);
     71  void bondRemoved(const atomId_t leftnr, const atomId_t rightnr);
    7172
    72   typedef std::pair< size_t, size_t> BondIds;
    73   typedef std::map< size_t, GLMoleculeObject_atom* > AtomNodeMap;
     73  typedef std::pair< atomId_t, atomId_t> BondIds;
     74  typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap;
    7475  typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap;
    75   AtomNodeMap AtomsinMoleculeMap;
    76   BondNodeMap BondsinMoleculeMap;
     76  typedef std::multimap< atomId_t, atomId_t > BondIdsMap;
     77  AtomNodeMap AtomsinSceneMap;
     78  BondIdsMap BondIdsinSceneMap;
     79  BondNodeMap BondsinSceneMap;
    7780};
    7881
  • src/UIElements/Views/Qt4/Qt3D/GLWorldView.hpp

    rdb7e6d r37b2575  
    4646  void atomInserted(const atom *_atom);
    4747  void atomRemoved(const atom *_atom);
    48   void moleculeInserted(const molecule *_mol);
    49   void moleculeRemoved(const molecule *_mol);
    5048
    5149protected:
Note: See TracChangeset for help on using the changeset viewer.