Changeset 1b07b1 for src/UIElements


Ignore:
Timestamp:
Feb 14, 2016, 12:34:28 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:
62a0ee
Parents:
e7ed12
git-author:
Frederik Heber <heber@…> (01/06/16 17:34:22)
git-committer:
Frederik Heber <heber@…> (02/14/16 12:34:28)
Message:

QtObservedInstanceBoard now sends QtObserved..::ptr around in signals.

  • this should get rid of the problem that we need to keep the QtObservedAtom until it was requested at least once. And we don't know for how long. Now, we simply place the shared_ptr into the signal (to which it seems to be copied) and hence a representation of the atoms remains valid.
  • cstor of GLMoleculeObject_.. take Observed.. as ref.
Location:
src/UIElements
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    re7ed12 r1b07b1  
    7575          _1)),
    7676  lastremovedatom((atomId_t)-1),
    77   lastremovedatomsmolecule( std::make_pair((moleculeId_t)-1,(atomId_t)-1) ),
    7877  lastremovedmolecule((moleculeId_t)-1)
    7978{
     
    169168          MoleculeSignedOn.insert( static_cast<Observable *>(const_cast<molecule *>(_molecule)) );
    170169
    171           emit moleculeInserted(_id);
     170          emit moleculeInserted(observedmolecule);
    172171        } else {
    173172          ELOG(1, "QtObservedInstanceBoard got MoleculeInserted for unknown molecule id " << _id);
     
    206205          _atom->signOn(this, atom::IndexChanged);
    207206          AtomSignedOn.insert( static_cast<Observable *>(const_cast<atom *>(_atom)) );
    208           emit atomInserted(observedatom->getAtomMoleculeIndex(), observedatom->getAtomIndex());
     207          emit atomInserted(observedatom);
    209208        } else {
    210209          ELOG(1, "QtObservedInstanceBoard got AtomInserted for unknown atom id " << _id);
     
    227226    const moleculeId_t molid = const_cast<const World &>(World::getInstance()).lastChangedMolId();
    228227    switch (notification->getChannelNo()) {
    229       case molecule::AtomInserted:
    230       {
    231         const molecule * const _molecule = const_cast<const World &>(World::getInstance()).
    232             getMolecule(MoleculeById(molid));
    233         if (_molecule != NULL) {
    234           const atomId_t atomid = const_cast<const molecule *>(_molecule)->lastChangedAtomId();
    235           LOG(3, "DEBUG: InformationBoard got AtomInserted signal for atom "
    236               << atomid << " from molecule " << molid);
    237           // check whether atom's observedvalues are present
    238           ASSERT( atomObservedValues.isPresent(atomid),
    239               "QtObservedInstanceBoard::recieveNotification() - ObservedValues for atom "
    240               +toString(atomid)+" are not present yet.");
    241           // and emit
    242           emit atomInserted(molid, atomid);
    243         } else {
    244           ELOG(2, "QtObservedInstanceBoard::recieveNotification() - molecule "
    245               << molid << " has disappeared.");
    246         }
    247         break;
    248       }
    249       case molecule::AtomRemoved:
    250       {
    251         const molecule * const _molecule = const_cast<const World &>(World::getInstance()).
    252             getMolecule(MoleculeById(molid));
    253         if (_molecule != NULL) {
    254           const atomId_t atomid = const_cast<const molecule *>(_molecule)->lastChangedAtomId();
    255           LOG(3, "DEBUG: InformationBoard got AtomRemoved signal for atom "
    256               << atomid << " from molecule " << molid);
    257           lastremovedatomsmolecule = std::make_pair(molid, atomid);
    258         }
    259         break;
    260       }
    261228      case molecule::IndexChanged:
    262229      {
     
    293260            "QtObservedInstanceBoard::recieveNotification() - cannot change atom's id "
    294261            +toString(oldatomId)+" "+toString(newatomId)+" in atomObservedValues.");
    295         // changed insertion delayed
    296         atomInsertionDelayed_t::iterator iter = atomInsertionDelayed.find(oldatomId);
    297         if (iter != atomInsertionDelayed.end()) {
    298           const moleculeId_t molid = iter->second;
    299           atomInsertionDelayed.erase(iter);
    300 #ifndef NDEBUG
    301           std::pair<atomInsertionDelayed_t::iterator, bool> inserter =
    302 #endif
    303           atomInsertionDelayed.insert( std::make_pair(newatomId, molid) );
    304           ASSERT( inserter.second,
    305               "QtObservedInstanceBoard::recieveNotification() - id "
    306               +toString(newatomId)+" already present in atomInsertionDelayed.");
    307         }
    308262        // no need update SignedOn, ref does not change
    309263        emit atomIndexChanged(oldatomId, newatomId);
     
    321275void QtObservedInstanceBoard::atomcountsubjectKilled(const atomId_t _atomid)
    322276{
    323   if ((_atomid == lastremovedatomsmolecule.second) && (_atomid == lastremovedatom)) {
     277  if ((_atomid == lastremovedatom)) {
    324278    LOG(3, "DEBUG: InstanceBoard emits atomRemoved for " << _atomid);
    325     emit atomRemoved(lastremovedatomsmolecule.first, lastremovedatomsmolecule.second);
     279    emit atomRemoved(lastremovedatom);
    326280  } else
    327281    ELOG(2, "QtObservedInstanceBoard::atomcountsubjectKilled() - id " << _atomid
    328         << " not fitting with " << lastremovedatomsmolecule << " or " << lastremovedatom);
     282        << " not fitting with " << lastremovedatom);
    329283}
    330284
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp

    re7ed12 r1b07b1  
    8989
    9090signals:
    91   void atomInserted(const moleculeId_t _molid, const atomId_t _atomid);
    92   void atomRemoved(const moleculeId_t _molid, const atomId_t _atomid);
     91  void atomInserted(QtObservedAtom::ptr _atom);
     92  void atomRemoved(const atomId_t _atomid);
    9393  void atomIndexChanged(const atomId_t _oldid, const atomId_t _newid);
    94   void moleculeInserted(const moleculeId_t _molid);
     94  void moleculeInserted(QtObservedMolecule::ptr _mol);
    9595  void moleculeRemoved(const moleculeId_t _molid);
    9696  void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
     
    143143  atomId_t lastremovedatom;
    144144
    145   //!> note down atom id of last removed atom to drop its ObservedValues
    146   std::pair<moleculeId_t, atomId_t> lastremovedatomsmolecule;
    147 
    148145  //!> note down molecule id of last removed molecule to drop its ObservedValues
    149146  moleculeId_t lastremovedmolecule;
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.cpp

    re7ed12 r1b07b1  
    201201      {
    202202        const atomId_t _id = _molecule->lastChangedAtomId();
     203        QtObservedAtom::ptr _atom = board.getObservedAtom(_id);
    203204        emit atomcountChanged();
    204         emit atomInserted(_id);
     205        emit atomInserted(_atom);
    205206        emit bondcountChanged();
    206207        emit boundingboxChanged();
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp

    re7ed12 r1b07b1  
    2828#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
    2929#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
     30#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
    3031#include "types.hpp"
    3132
     
    146147  void tesselationhullChanged();
    147148  void boundingboxChanged();
    148   void atomInserted(const atomId_t);
     149  void atomInserted(QtObservedAtom::ptr);
    149150  void atomRemoved(const atomId_t);
    150151  void moleculeRemoved();
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.cpp

    re7ed12 r1b07b1  
    8282  connect(this,SIGNAL(itemChanged(QStandardItem*)),this,SLOT(moleculeNameChanged(QStandardItem*)));
    8383  connect(this, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(checkForVisibilityChange(QStandardItem*)));
    84   connect(board, SIGNAL(moleculeInserted(const moleculeId_t)), this, SLOT(moleculeInserted(const moleculeId_t)));
     84  connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)), this, SLOT(moleculeInserted(QtObservedMolecule::ptr)));
    8585  connect(board, SIGNAL(moleculeRemoved(const moleculeId_t)), this, SLOT(moleculeRemoved(const moleculeId_t)));
    8686  connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t,const moleculeId_t)),
     
    102102}
    103103
    104 void QtMoleculeList::moleculeInserted(const moleculeId_t _id)
     104void QtMoleculeList::moleculeInserted(QtObservedMolecule::ptr _mol)
    105105{
    106106  // get ObservedMolecule from board
    107107  boost::recursive_mutex::scoped_lock lock(listAccessing_mutex);
    108   newMolecules.push_back( _id );
     108  newMolecules.push_back( _mol );
    109109}
    110110
     
    678678  list_of_group_items_t visibilityGroupItems_copy = visibilityGroupItems;
    679679  visibilityGroupItems.clear();
    680   std::vector<moleculeId_t> newMolecules_copy = newMolecules;
     680  std::vector<QtObservedMolecule::ptr> newMolecules_copy = newMolecules;
    681681  newMolecules.clear();
    682682  std::vector<moleculeId_t> removedMolecules_copy = removedMolecules;
     
    784784
    785785  /// 4. instantiate all new items
    786   for (std::vector<moleculeId_t>::iterator moliter = newMolecules_copy.begin();
     786  for (std::vector<QtObservedMolecule::ptr>::iterator moliter = newMolecules_copy.begin();
    787787      moliter != newMolecules_copy.end(); ++moliter) {
    788     QtObservedMolecule::ptr ObservedMolecule = board->getObservedMolecule(*moliter);
    789     if (ObservedMolecule) {
    790 //     LOG(1, "Adding molecule " << ObservedMolecule->getMoleculeName());
    791       // check that World knows the molecule still
    792       const std::string formula = addMolecule(ObservedMolecule);
    793 //        LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
    794       toBeSetOccurrence.insert( formula );
    795     }
     788//   LOG(1, "Adding molecule " << ObservedMolecule->getMoleculeName());
     789    // check that World knows the molecule still
     790    const std::string formula = addMolecule(*moliter);
     791//      LOG(1, "Adding " << formula << " to toBeSetOccurrence.");
     792    toBeSetOccurrence.insert( formula );
    796793  }
    797794
  • src/UIElements/Views/Qt4/MoleculeList/QtMoleculeList.hpp

    re7ed12 r1b07b1  
    6565
    6666private slots:
    67   void moleculeInserted(const moleculeId_t _id);
     67  void moleculeInserted(QtObservedMolecule::ptr _mol);
    6868  void moleculeRemoved(const moleculeId_t _id);
    6969  void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
     
    155155  list_of_group_items_t visibilityGroupItems;
    156156  //!> list of new molecules which need to be added
    157   std::vector<moleculeId_t> newMolecules;
     157  std::vector<QtObservedMolecule::ptr> newMolecules;
    158158  //!> list of molecules that have been removed
    159159  std::vector<moleculeId_t> removedMolecules;
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp

    re7ed12 r1b07b1  
    5858    QGLSceneNode *mesh[],
    5959    QObject *parent,
    60     QtObservedAtom::ptr _ObservedAtom) :
     60    QtObservedAtom::ptr &_ObservedAtom) :
    6161  GLMoleculeObject(mesh, parent),
    6262  ObservedAtom(_ObservedAtom)
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp

    re7ed12 r1b07b1  
    3535      QGLSceneNode *mesh[],
    3636      QObject *parent,
    37       QtObservedAtom::ptr _ObservedAtom
     37      QtObservedAtom::ptr &_ObservedAtom
    3838      );
    3939  virtual ~GLMoleculeObject_atom();
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    re7ed12 r1b07b1  
    8484    QObject *parent,
    8585    QtObservedInstanceBoard &_board,
    86     QtObservedMolecule::ptr _ObservedMolecule) :
     86    QtObservedMolecule::ptr &_ObservedMolecule) :
    8787  GLMoleculeObject((QGLSceneNode *)NULL, parent),
    8888  owner(NULL),
     
    9999    QObject *parent,
    100100    QtObservedInstanceBoard &_board,
    101     QtObservedMolecule::ptr _ObservedMolecule) :
     101    QtObservedMolecule::ptr &_ObservedMolecule) :
    102102  GLMoleculeObject(mesh, parent),
    103103  owner(NULL),
     
    125125  connect (ObservedMolecule.get(), SIGNAL(boundingboxChanged()), this, SLOT(resetBoundingBox()));
    126126  connect (ObservedMolecule.get(), SIGNAL(indexChanged()), this, SLOT(resetIndex()));
    127   connect (ObservedMolecule.get(), SIGNAL(atomInserted(const atomId_t)), this, SLOT(atomInserted(const atomId_t)));
     127  connect (ObservedMolecule.get(), SIGNAL(atomInserted(QtObservedAtom::ptr)), this, SLOT(atomInserted(QtObservedAtom::ptr)));
    128128  connect (ObservedMolecule.get(), SIGNAL(atomRemoved(const atomId_t)), this, SLOT(atomRemoved(const atomId_t)));
    129129  connect (ObservedMolecule.get(), SIGNAL(selectedChanged()), this, SLOT(resetSelected()));
     
    357357 * @param _atom atom to add
    358358 */
    359 void GLMoleculeObject_molecule::atomInserted(const atomId_t _id)
    360 {
    361   LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomInserted for atom "+toString(_id)+".");
    362 
    363   const QtObservedAtom::ptr _atom = board.getObservedAtom(_id);
     359void GLMoleculeObject_molecule::atomInserted(QtObservedAtom::ptr _atom)
     360{
     361  const atomId_t atomid = _atom->getAtomIndex();
     362  LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomInserted for atom "+toString(atomid)+".");
     363
    364364  if (_atom) {
    365365    GLMoleculeObject_atom *atomObject =
     
    369369            _atom);
    370370    ASSERT( atomObject != NULL,
    371         "GLMoleculeObject_molecule::atomInserted - could not create atom object for "+toString(_id));
    372     AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
     371        "GLMoleculeObject_molecule::atomInserted - could not create atom object for "+toString(atomid));
     372    AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid);
    373373    ASSERT(iter == AtomsinSceneMap.end(),
    374         "GLMoleculeObject_molecule::atomInserted - same atom with id "+toString(_id)+" added again.");
    375     AtomsinSceneMap.insert( make_pair(_id, atomObject) );
     374        "GLMoleculeObject_molecule::atomInserted - same atom with id "+toString(atomid)+" added again.");
     375    AtomsinSceneMap.insert( make_pair(atomid, atomObject) );
    376376
    377377    qRegisterMetaType<atomId_t>("atomId_t");
     
    387387
    388388    if (m_objectId  == -1)
    389       setObjectId(_id);
     389      setObjectId(atomid);
    390390
    391391    emit changed();
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp

    re7ed12 r1b07b1  
    4545      QObject *parent,
    4646      QtObservedInstanceBoard &_board,
    47       QtObservedMolecule::ptr _ObservedMolecule);
     47      QtObservedMolecule::ptr &_ObservedMolecule);
    4848  GLMoleculeObject_molecule(
    4949      QGLSceneNode *mesh[],
    5050      QObject *parent,
    5151      QtObservedInstanceBoard &_board,
    52       QtObservedMolecule::ptr _ObservedMolecule);
     52      QtObservedMolecule::ptr &_ObservedMolecule);
    5353  virtual ~GLMoleculeObject_molecule();
    5454
     
    7878
    7979  void wasClicked();
    80   void atomInserted(const atomId_t _id);
     80  void atomInserted(QtObservedAtom::ptr _atom);
    8181  void atomRemoved(const atomId_t _id);
    8282  void bondInserted(const atomId_t, const atomId_t, const GLMoleculeObject_bond::SideOfBond side);
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    re7ed12 r1b07b1  
    9393    GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
    9494  }
    95   connect(board, SIGNAL(moleculeInserted(const moleculeId_t)),
    96       this, SLOT(moleculeInserted(const moleculeId_t)));
     95  connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
     96      this, SLOT(moleculeInserted(QtObservedMolecule::ptr)));
    9797  connect(board, SIGNAL(moleculeRemoved(const moleculeId_t)),
    9898      this, SLOT(moleculeRemoved(const moleculeId_t)));
    9999  connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)),
    100100      this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)));
    101   connect(board, SIGNAL(atomInserted(const moleculeId_t, const atomId_t)),
    102       this, SLOT(atomInserted(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
     101  connect(board, SIGNAL(atomInserted(QtObservedAtom::ptr)),
     102      this, SLOT(atomInserted(QtObservedAtom::ptr)));
    103103  connect(board, SIGNAL(atomRemoved(const moleculeId_t, const atomId_t)),
    104       this, SLOT(atomRemoved(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
     104      this, SLOT(atomRemoved(const moleculeId_t, const atomId_t)));
    105105
    106106//  connect(this, SIGNAL(updated()), this, SLOT(update()));
     
    156156 * @param _atomid atom to insert
    157157 */
    158 void GLWorldScene::atomInserted(const moleculeId_t _molid, const atomId_t _atomid)
    159 {
    160   boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    161 
    162   LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_atomid)+".");
     158void GLWorldScene::atomInserted(QtObservedAtom::ptr _atom)
     159{
     160  ASSERT (_atom,
     161      "GLWorldScene::moleculeInserted() - received shared_ptr for atom is empty?");
     162  const atomId_t atomid = _atom->getAtomIndex();
     163  const atomId_t molid = _atom->getAtomMoleculeIndex();
     164  LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(atomid)+".");
    163165
    164166  // check of molecule is already present
    165   MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid);
     167  MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
    166168  if (moliter != MoleculesinSceneMap.end()) {
    167169    // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
    168170  } else {
    169171    // store signal for when it is instantiated
    170     if (MoleculeMissedStateMap.count(_molid) == 0)
    171       MoleculeMissedStateMap.insert( std::make_pair(_molid ,StateChangeMap_t()) );
    172     MoleculeMissedStateMap[_molid].insert( std::make_pair(_atomid, atomInsertedState) );
     172    if (MoleculeMissedStateMap.count(molid) == 0)
     173      MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );
     174    MoleculeMissedStateMap[molid].insert( std::make_pair(atomid, atomInsertedState) );
     175    QtObservedAtomMap[atomid] = _atom;
     176    LOG(3, "INFO: GLWorldScene: Placing atomInserted for atom " << atomid
     177         << " and molecule " << molid << " into missed state map.");
    173178  }
    174179}
     
    194199      MoleculeMissedStateMap.insert( std::make_pair(_molid ,StateChangeMap_t()) );
    195200    MoleculeMissedStateMap[_molid].insert( std::make_pair(_atomid, atomRemovedState) );
     201    LOG(3, "INFO: GLWorldScene: Placing atomRemoved for atom " << _atomid
     202         << " and molecule " << _molid << " into missed state map.");
    196203  }
    197204}
     
    201208 * @param _mol molecule to insert
    202209 */
    203 void GLWorldScene::moleculeInserted(const moleculeId_t _id)
    204 {
    205   LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "+toString(_id)+".");
     210void GLWorldScene::moleculeInserted(QtObservedMolecule::ptr _mol)
     211{
     212  ASSERT (_mol,
     213      "GLWorldScene::moleculeInserted() - received shared_ptr for molecule is empty?");
     214  const moleculeId_t molid = _mol->getMolIndex();
     215  LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "+toString(molid)+".");
    206216
    207217  boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    208218
    209   MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(_id);
     219  MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid);
    210220  ASSERT( iter == MoleculesinSceneMap.end(),
    211       "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" already present.");
     221      "GLWorldScene::moleculeInserted() - molecule's id "+toString(molid)+" already present.");
    212222
    213223  // check whether molecule is still present
    214   if (RemovalMolecules.count(_id) != 0) {
    215     RemovalMolecules.erase(_id);
     224  if (RemovalMolecules.count(molid) != 0) {
     225    RemovalMolecules.erase(molid);
    216226    return;
    217227  }
    218   if (const_cast<const World &>(World::getInstance()).getMolecule(MoleculeById(_id)) == NULL) {
    219     ELOG(2, "Molecule with id " << _id << " has disappeared.");
    220     return;
    221   }
    222228
    223229  // add new object
    224   LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << _id);
    225   const QtObservedMolecule::ptr mol = board->getObservedMolecule(_id);
    226   if (mol) {
    227     GLMoleculeObject_molecule *molObject =
    228         new GLMoleculeObject_molecule(
    229             GLMoleculeObject::meshEmpty,
    230             this,
    231             *board,
    232             mol);
    233     ASSERT( molObject != NULL,
    234         "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(_id));
    235     MoleculesinSceneMap.insert( make_pair(_id, molObject) );
    236 
    237     // now handle all state changes that came up before the instantiation
    238     while (MoleculeMissedStateMap.count(_id) != 0) {
    239 //      ASSERT( !MoleculeMissedStateMap[_id].empty(),
     230  LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << molid);
     231  GLMoleculeObject_molecule *molObject =
     232      new GLMoleculeObject_molecule(
     233          GLMoleculeObject::meshEmpty,
     234          this,
     235          *board,
     236          _mol);
     237  ASSERT( molObject != NULL,
     238      "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(molid));
     239#ifndef NDEBUG
     240  std::pair<MoleculeNodeMap::iterator, bool> inserter =
     241#endif
     242  MoleculesinSceneMap.insert( make_pair(molid, molObject) );
     243  ASSERT(inserter.second,
     244      "GLWorldScene::moleculeInserted() - molecule "+toString(molid)+" already present in scene.");
     245
     246  // now handle all state changes that came up before the instantiation
     247  if (MoleculeMissedStateMap.count(molid) != 0) {
     248//      ASSERT( !MoleculeMissedStateMap[molid].empty(),
    240249//          "GLWorldScene::moleculeInserted() - we have an empty state change map for molecule with id "
    241 //          +toString(_id));
    242       boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    243       for (StateChangeMap_t::iterator iter = MoleculeMissedStateMap[_id].begin();
    244           !MoleculeMissedStateMap[_id].empty();
    245           iter = MoleculeMissedStateMap[_id].begin()) {
    246         std::pair<StateChangeMap_t::iterator, StateChangeMap_t::iterator> rangeiter =
    247             MoleculeMissedStateMap[_id].equal_range(iter->first);
    248         const size_t StateCounts = std::distance(rangeiter.first, rangeiter.second);
    249         if (StateCounts > 1) {
    250           // more than one state change, have to combine
    251           typedef std::map<StateChangeType, size_t> StateChangeAmounts_t;
    252           StateChangeAmounts_t StateChangeAmounts;
    253           for (StateChangeMap_t::const_iterator stateiter = rangeiter.first;
    254               stateiter != rangeiter.second; ++stateiter)
    255             ++StateChangeAmounts[stateiter->second];
    256           ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
    257               "GLWorldScene::moleculeInserted() - more atomRemoved states than atomInserted for atom "
    258               +toString(iter->first));
    259           if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
     250//          +toString(molid));
     251    boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
     252    for (StateChangeMap_t::iterator iter = MoleculeMissedStateMap[molid].begin();
     253        !MoleculeMissedStateMap[molid].empty();
     254        iter = MoleculeMissedStateMap[molid].begin()) {
     255      std::pair<StateChangeMap_t::iterator, StateChangeMap_t::iterator> rangeiter =
     256          MoleculeMissedStateMap[molid].equal_range(iter->first);
     257      const size_t StateCounts = std::distance(rangeiter.first, rangeiter.second);
     258      if (StateCounts > 1) {
     259        // more than one state change, have to combine
     260        typedef std::map<StateChangeType, size_t> StateChangeAmounts_t;
     261        StateChangeAmounts_t StateChangeAmounts;
     262        for (StateChangeMap_t::const_iterator stateiter = rangeiter.first;
     263            stateiter != rangeiter.second; ++stateiter)
     264          ++StateChangeAmounts[stateiter->second];
     265        ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
     266            "GLWorldScene::moleculeInserted() - more atomRemoved states "
     267            +toString(StateChangeAmounts[atomRemovedState])+" than atomInserted "
     268            +toString(StateChangeAmounts[atomInsertedState])+" for atom "+toString(iter->first));
     269        if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
     270          LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
     271          QMetaObject::invokeMethod(molObject,        // pointer to a QObject
     272                                    "atomInserted",       // member name (no parameters here)
     273                                    Qt::QueuedConnection,     // connection type
     274                                    Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first]));     // parameters
     275        } else {
     276          LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
     277        }
     278        // removed all state changes for this atom
     279        MoleculeMissedStateMap[molid].erase(rangeiter.first, rangeiter.second);
     280      } else {
     281        // can only be an insertion
     282        switch (rangeiter.first->second) {
     283          case atomRemovedState:
     284            ASSERT( 0,
     285                "GLWorldScene::moleculeInserted() - atomRemoved state without atomInserted for atom "
     286                +toString(iter->first));
     287            break;
     288          case atomInsertedState:
     289          {
    260290            LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
    261291            QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    262292                                      "atomInserted",       // member name (no parameters here)
    263293                                      Qt::QueuedConnection,     // connection type
    264                                       Q_ARG(const atomId_t, iter->first));     // parameters
    265           } else {
    266             LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
     294                                      Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first]));     // parameters
     295            break;
    267296          }
    268         } else {
    269           // can only be an insertion
    270           switch (rangeiter.first->second) {
    271             case atomRemovedState:
    272               ASSERT( 0,
    273                   "GLWorldScene::moleculeInserted() - atomRemoved state without atomInserted for atom "
    274                   +toString(iter->first));
    275               break;
    276             case atomInsertedState:
    277               LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
    278               QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    279                                         "atomInserted",       // member name (no parameters here)
    280                                         Qt::QueuedConnection,     // connection type
    281                                         Q_ARG(const atomId_t, iter->first));     // parameters
    282               break;
    283             default:
    284               ASSERT( 0,
    285                   "GLWorldScene::moleculeInserted() - there are unknown change states.");
    286               break;
    287           }
     297          default:
     298            ASSERT( 0,
     299                "GLWorldScene::moleculeInserted() - there are unknown change states.");
     300            break;
    288301        }
    289302        // removed state changes for this atom
    290         MoleculeMissedStateMap[_id].erase(iter);
     303        MoleculeMissedStateMap[molid].erase(iter);
    291304      }
    292305    }
    293 
    294     connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
    295     connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
    296     connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
    297     connect (molObject, SIGNAL(moleculeClicked(moleculeId_t)), this, SLOT(moleculeClicked(moleculeId_t)));
    298     connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
    299     connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
    300     connect (molObject, SIGNAL(hoverChanged(const atomId_t)), this, SIGNAL(hoverChanged(const atomId_t)));
    301     connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
    302     connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
    303 
    304     emit changed();
    305     emit changeOccured();
    306   }
     306  }
     307
     308  connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
     309  connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
     310  connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
     311  connect (molObject, SIGNAL(moleculeClicked(moleculeId_t)), this, SLOT(moleculeClicked(moleculeId_t)));
     312  connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
     313  connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
     314  connect (molObject, SIGNAL(hoverChanged(const atomId_t)), this, SIGNAL(hoverChanged(const atomId_t)));
     315  connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
     316  connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
     317
     318  emit changed();
     319  emit changeOccured();
    307320
    308321  // remove state change map for the molecule
    309322  {
    310323    boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    311     MoleculeMissedStateMap.erase(_id);
     324    MoleculeMissedStateMap.erase(molid);
    312325  }
    313326}
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    re7ed12 r1b07b1  
    2727#include "types.hpp"
    2828
    29 class atom;
    30 class molecule;
     29#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
     30#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
     31
    3132class Shape;
    3233
     
    8889  void moleculeClicked(moleculeId_t no);
    8990  void moleculeRemoved(const moleculeId_t _id);
    90   void moleculeInserted(const moleculeId_t _id);
     91  void moleculeInserted(QtObservedMolecule::ptr);
    9192  void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
    9293  void atomRemoved(const moleculeId_t _molid, const atomId_t _atomid);
    93   void atomInserted(const moleculeId_t _molid, const atomId_t _atomid);
     94  void atomInserted(QtObservedAtom::ptr);
    9495  void setSelectionModeAtom();
    9596  void setSelectionModeMolecule();
     
    122123    MAX_StateChangeType
    123124  };
     125  typedef std::map< atomId_t, QtObservedAtom::ptr> QtObservedAtomMap_t;
    124126  typedef std::multimap< atomId_t, StateChangeType> StateChangeMap_t;
    125127  typedef std::map< moleculeId_t, StateChangeMap_t> MoleculeMissedStateMap_t;
    126128  //!> map of all missed state changes
    127129  MoleculeMissedStateMap_t MoleculeMissedStateMap;
     130  //!> map to contain all QtObservedAtom that have not been instantiated so far
     131  QtObservedAtomMap_t QtObservedAtomMap;
    128132  //!> flag to indicate whether state map is currently worked on
    129133  boost::recursive_mutex MoleculeMissedStateMap_mutex;
Note: See TracChangeset for help on using the changeset viewer.