Changeset 59f1bc for src/UIElements


Ignore:
Timestamp:
Feb 14, 2016, 12:34:29 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:
23221f
Parents:
03e69e
git-author:
Frederik Heber <heber@…> (01/06/16 08:36:58)
git-committer:
Frederik Heber <heber@…> (02/14/16 12:34:29)
Message:

All ..Inserted/..Removed signals now go through GLWorldScene.

  • this should enforce synchronicity of the signals. If we mix direct and queued connections, then this cannot be ensured.
  • the idea is that GLWorldScene gets all Inserted/Removed signals for atoms and molecules from the QtObservedInstanceBoard. It connects to each QtObservedMolecule and thus can call the GLMoleculeObject_molecule's atomInserted, atomRemoved functions in sequence.
  • removed RemovalMolecules, no longer needed.
  • we now enforce with mutexes that instantation of molecule and MissedStateMap do not interfere, i.e. it is always perfectly clear whether to push a signal into the Map or whether to call the function of the present GLMolObj_mol.
  • FIX: MoleculesInScene_mutex has not been used properly, now is.
  • DOCU: Updated construct qt-gu documentation with the new concept.
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
3 edited

Legend:

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

    r03e69e r59f1bc  
    126126  connect (ObservedMolecule.get(), SIGNAL(indexChanged(const moleculeId_t, const moleculeId_t)),
    127127      this, SLOT(resetIndex(const moleculeId_t, const moleculeId_t)));
    128   connect (ObservedMolecule.get(), SIGNAL(atomInserted(QtObservedAtom::ptr)),
    129       this, SLOT(atomInserted(QtObservedAtom::ptr)) );
    130   connect (ObservedMolecule.get(), SIGNAL(atomRemoved(const atomId_t)),
    131       this, SLOT(atomRemoved(const atomId_t)) );
     128  /// these are channeled through GLWorldScene instead to ensure synchronicity
     129//  connect (ObservedMolecule.get(), SIGNAL(atomInserted(QtObservedAtom::ptr)),
     130//      this, SLOT(atomInserted(QtObservedAtom::ptr)) );
     131//  connect (ObservedMolecule.get(), SIGNAL(atomRemoved(const atomId_t)),
     132//      this, SLOT(atomRemoved(const atomId_t)) );
    132133  connect (ObservedMolecule.get(), SIGNAL(selectedChanged()), this, SLOT(resetSelected()));
    133134
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    r03e69e r59f1bc  
    9494  }
    9595  connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
    96       this, SLOT(moleculeSignOn(QtObservedMolecule::ptr)));
     96      this, SLOT(moleculeSignOn(QtObservedMolecule::ptr)), Qt::DirectConnection);
    9797  connect(board, SIGNAL(moleculeRemoved(const moleculeId_t)),
    98       this, SLOT(moleculeSignOff(const moleculeId_t)));
     98      this, SLOT(moleculeSignOff(const moleculeId_t)), Qt::DirectConnection);
    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(QtObservedAtom::ptr)),
     102      this, SLOT(atomInserted(QtObservedAtom::ptr)));
     103  connect(board, SIGNAL(atomRemoved(const atomId_t)),
     104      this, SLOT(atomRemoved(const atomId_t)));
    101105  connect(this, SIGNAL(insertMolecule(QtObservedMolecule::ptr)),
    102106      this, SLOT(moleculeInserted(QtObservedMolecule::ptr)) );
     
    151155}
    152156
    153 /** Inserts an atom into the scene before molecule is present.
    154  *
    155  * @param _molid molecule to insert atom for
    156  * @param _atomid atom to insert
     157/** Prepares insertion of a general atom.
     158 *
     159 * This is called before the insertion into a molecule and thus before the
     160 * insertion into the scene.
     161 *
     162 * @param _atom atom to insert
    157163 */
    158164void GLWorldScene::atomInserted(QtObservedAtom::ptr _atom)
    159165{
    160   ASSERT (_atom,
    161       "GLWorldScene::moleculeInserted() - received shared_ptr for atom is empty?");
     166  const atomId_t atomid = _atom->getAtomIndex();
     167  ASSERT( QtObservedAtomMap.find(atomid) == QtObservedAtomMap.end(),
     168      "GLWorldScene::AtomInserted() - atom with id "+toString(atomid)
     169      +" is already present in QtObservedAtomMap.");
     170  QtObservedAtomMap[atomid] = _atom;
     171  connect(_atom.get(), SIGNAL(indexChanged(const atomId_t,const atomId_t)),
     172      this, SLOT(atomIndexChanged(const atomId_t,const atomId_t)) );
     173}
     174
     175/** Removes an general atom.
     176 *
     177 * This is called when the atom has been removed from the molecule.
     178 *
     179 * @param _atom atom to remove
     180 */
     181void GLWorldScene::atomRemoved(const atomId_t _atomid)
     182{
     183  const QtObservedAtomMap_t::iterator eraseiter = QtObservedAtomMap.find(_atomid);
     184  ASSERT( eraseiter != QtObservedAtomMap.end(),
     185      "GLWorldScene::AtomRemoved() - atom with id "+toString(_atomid)
     186      +" is not present in QtObservedAtomMap.");
     187  disconnect(eraseiter->second.get(), SIGNAL(indexChanged(const atomId_t,const atomId_t)),
     188      this, SLOT(atomIndexChanged(const atomId_t,const atomId_t)) );
     189  QtObservedAtomMap.erase(eraseiter);
     190}
     191
     192/** Inserts an atom into the scene when molecule is present.
     193 *
     194 * @param _atom atom to insert
     195 */
     196void GLWorldScene::moleculesAtomInserted(QtObservedAtom::ptr _atom)
     197{
    162198  const atomId_t atomid = _atom->getAtomIndex();
    163199  const atomId_t molid = _atom->getAtomMoleculeIndex();
     
    165201
    166202  // check of molecule is already present
     203  boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    167204  MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
    168205  if (moliter != MoleculesinSceneMap.end()) {
    169     // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
     206    LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomInserted for atom "+toString(atomid)+".");
     207    QMetaObject::invokeMethod(moliter->second,        // pointer to a QObject
     208                              "atomInserted",       // member name (no parameters here)
     209                              Qt::QueuedConnection,     // connection type
     210                              Q_ARG(QtObservedAtom::ptr, _atom));     // parameters
    170211  } else {
    171     // store signal for when it is instantiated
    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     connect(_atom.get(), SIGNAL(indexChanged(const atomId_t,const atomId_t)),
    177         this, SLOT(atomIndexChanged(const atomId_t,const atomId_t)) );
    178     LOG(3, "INFO: GLWorldScene: Placing atomInserted for atom " << atomid
    179          << " and molecule " << molid << " into missed state map.");
     212    boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
     213    // only record missed state for molecule if (still) present but not instantiated
     214    if (QtObservedMoleculeMap.count(molid)) {
     215      // store signal for when it is instantiated
     216      if (MoleculeMissedStateMap.count(molid) == 0)
     217        MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );
     218      MoleculeMissedStateMap[molid].insert( std::make_pair(atomid, atomInsertedState) );
     219      ASSERT( QtObservedAtomMap[atomid] == _atom,
     220          "GLWorldScene::moleculesAtomInserted() - atom "+toString(atomid)
     221          +" inserted in molecule "+toString(molid)
     222          +" which does not match atom in QtObservedAtomMap.");
     223      LOG(3, "INFO: GLWorldScene: Placing atomInserted for atom " << atomid
     224           << " and molecule " << molid << " into missed state map.");
     225    }
    180226  }
    181227}
     
    183229/** Removes an atom into the scene before molecule is present.
    184230 *
    185  * @param _molid molecule to insert atom for
    186  * @param _atomid atom to insert
    187  */
    188 void GLWorldScene::atomRemoved(const atomId_t _atomid)
    189 {
    190   boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
    191 
     231 * @param _atomid atom to remove
     232 */
     233void GLWorldScene::moleculesAtomRemoved(const atomId_t _atomid)
     234{
    192235  LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
    193236
     
    197240    const moleculeId_t molid = atom->getAtomMoleculeIndex();
    198241    // check of molecule is already present
     242    boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
    199243    MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
    200244    if (moliter != MoleculesinSceneMap.end()) {
    201       // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
     245      LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomRemoved for atom "+toString(_atomid)+".");
     246      QMetaObject::invokeMethod(moliter->second,        // pointer to a QObject
     247                                "atomRemoved",       // member name (no parameters here)
     248                                Qt::QueuedConnection,     // connection type
     249                                Q_ARG(const atomId_t, _atomid));     // parameters
    202250    } else {
    203       // store signal for when it is instantiated
    204       if (MoleculeMissedStateMap.count(molid) == 0)
    205         MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );
    206       MoleculeMissedStateMap[molid].insert( std::make_pair(_atomid, atomRemovedState) );
    207       LOG(3, "INFO: GLWorldScene: Placing atomRemoved for atom " << _atomid
    208            << " and molecule " << molid << " into missed state map.");
     251      boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
     252      // only record missed state for molecule if (still) present but not instantiated
     253      if (QtObservedMoleculeMap.count(molid)) {
     254        // store signal for when it is instantiated
     255        if (MoleculeMissedStateMap.count(molid) == 0)
     256          MoleculeMissedStateMap.insert( std::make_pair(molid, StateChangeMap_t()) );
     257        MoleculeMissedStateMap[molid].insert( std::make_pair(_atomid, atomRemovedState) );
     258        LOG(3, "INFO: GLWorldScene: Placing atomRemoved for atom " << _atomid
     259             << " and molecule " << molid << " into missed state map.");
     260      }
    209261    }
    210262  }
     
    216268  // source as GLMoleculeObject_molecule would
    217269  connect(_mol.get(), SIGNAL(atomInserted(QtObservedAtom::ptr)),
    218       this, SLOT(atomInserted(QtObservedAtom::ptr)) );
     270      this, SLOT(moleculesAtomInserted(QtObservedAtom::ptr)) );
    219271  connect(_mol.get(), SIGNAL(atomRemoved(const atomId_t)),
    220       this, SLOT(atomRemoved(const atomId_t)) );
     272      this, SLOT(moleculesAtomRemoved(const atomId_t)) );
    221273  const moleculeId_t molid = _mol->getMolIndex();
    222   QtObservedMoleculeMap.insert( std::make_pair(molid, _mol) );
     274  ASSERT( QtObservedMoleculeMap.find(molid) == QtObservedMoleculeMap.end(),
     275      "GLWorldScene::moleculeSignOn() - molecule with id "+toString(molid)
     276      +" is already present in QtObservedMoleculeMap.");
     277  QtObservedMoleculeMap[molid] = _mol;
     278  connect(_mol.get(), SIGNAL(indexChanged(const moleculeId_t,const moleculeId_t)),
     279      this, SLOT(moleculeIndexChanged(const moleculeId_t,const moleculeId_t)) );
    223280
    224281  LOG(3, "INFO: GLWorldScene: Received signal moleculeSignOn for molecule "+toString(molid)+".");
     
    229286void GLWorldScene::moleculeSignOff(const moleculeId_t _id)
    230287{
    231   ASSERT( QtObservedMoleculeMap.count(_id),
     288  const QtObservedMoleculeMap_t::iterator eraseiter = QtObservedMoleculeMap.find(_id);
     289  ASSERT( eraseiter != QtObservedMoleculeMap.end(),
    232290      "GLWorldScene::moleculeSignOff() - cannot find id "+toString(_id)+" in map.");
    233   const QtObservedMolecule::ptr mol = QtObservedMoleculeMap[_id];
    234   mol->disconnect(this);
    235   QtObservedMoleculeMap.erase(_id);
     291  disconnect(eraseiter->second.get(), SIGNAL(indexChanged(const moleculeId_t,const moleculeId_t)),
     292      this, SLOT(moleculeIndexChanged(const moleculeId_t,const moleculeId_t)) );
     293  QtObservedMoleculeMap.erase(eraseiter);
    236294
    237295  LOG(3, "INFO: GLWorldScene: Received signal moleculeSignOff for molecule "+toString(_id)+".");
     
    256314  ASSERT( iter == MoleculesinSceneMap.end(),
    257315      "GLWorldScene::moleculeInserted() - molecule's id "+toString(molid)+" already present.");
    258 
    259   // check whether molecule is still present
    260   if (RemovalMolecules.count(molid) != 0) {
    261     RemovalMolecules.erase(molid);
    262     return;
    263   }
    264316
    265317  // add new object
     
    325377          {
    326378            LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
    327             const QtObservedAtom::ptr walker = QtObservedAtomMap[iter->first];
    328379            QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    329380                                      "atomInserted",       // member name (no parameters here)
     
    374425
    375426  MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
    376   if ( iter == MoleculesinSceneMap.end()) {
    377     RemovalMolecules.insert(_id);
    378   } else {
     427  if ( iter != MoleculesinSceneMap.end()) {
    379428    LOG(1, "DEBUG: Removing GLMoleculeObject_molecule to id " << _id);
    380429    GLMoleculeObject_molecule *molObject = iter->second;
     
    405454void GLWorldScene::moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid)
    406455{
    407   MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_oldid);
    408   if ( iter == MoleculesinSceneMap.end()) {
    409     RemovalMolecule_t::iterator removeiter =
    410         RemovalMolecules.find(_oldid);
    411     ASSERT( removeiter != RemovalMolecules.end(),
    412         "GLWorldScene::moleculeIndexChanged() - cannot find id "+toString(_oldid)+" in any map.");
    413     RemovalMolecules.erase(removeiter);
    414     RemovalMolecules.insert(_newid);
    415     if (QtObservedMoleculeMap.count(_oldid)) {
    416       const QtObservedMolecule::ptr mol = QtObservedMoleculeMap[_oldid];
    417       QtObservedMoleculeMap.erase(_oldid);
    418       QtObservedMoleculeMap.insert( std::make_pair(_newid, mol) );
     456  {
     457    QtObservedMoleculeMap_t::iterator const olditer = QtObservedMoleculeMap.find(_oldid);
     458    ASSERT ( olditer != QtObservedMoleculeMap.end(),
     459        "GLWorldScene::moleculeIndexChanged() - molecule "
     460        +toString(_oldid)+" not present in QtObservedMoleculeMap.");
     461#ifndef NDEBUG
     462    QtObservedMoleculeMap_t::iterator const newiter = QtObservedMoleculeMap.find(_newid);
     463    ASSERT ( newiter == QtObservedMoleculeMap.end(),
     464        "GLWorldScene::moleculeIndexChanged() - molecule "
     465        +toString(_newid)+" already present in QtObservedMoleculeMap.");
     466#endif
     467    const QtObservedMolecule::ptr mol = olditer->second;
     468    QtObservedMoleculeMap.erase(olditer);
     469    QtObservedMoleculeMap[_newid] = mol;
     470  }
     471  {
     472    MoleculeNodeMap::iterator const olditer = MoleculesinSceneMap.find(_oldid);
     473    if ( olditer != MoleculesinSceneMap.end()) {
     474#ifndef NDEBUG
     475      MoleculeNodeMap::iterator const newiter = MoleculesinSceneMap.find(_newid);
     476      ASSERT ( newiter == MoleculesinSceneMap.end(),
     477          "GLWorldScene::moleculeIndexChanged() - molecule "
     478          +toString(_newid)+" already present in MoleculesinSceneMap.");
     479#endif
     480      LOG(1, "DEBUG: Changing GLMoleculeObject_molecule from " << _oldid << " to id " << _newid);
     481      GLMoleculeObject_molecule* const molObject = olditer->second;
     482      MoleculesinSceneMap.erase(olditer);
     483      MoleculesinSceneMap[_newid] = molObject;
    419484    }
    420   } else {
    421     LOG(1, "DEBUG: Changing GLMoleculeObject_molecule from " << _oldid << " to id " << _newid);
    422     GLMoleculeObject_molecule* molObject = iter->second;
    423     MoleculesinSceneMap.erase(iter);
    424     MoleculesinSceneMap.insert(
    425         std::make_pair( _newid, molObject) );
    426485  }
    427486}
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    r03e69e r59f1bc  
    9595  void moleculeSignOn(QtObservedMolecule::ptr);
    9696  void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
     97  void moleculesAtomRemoved(const atomId_t _atomid);
     98  void moleculesAtomInserted(QtObservedAtom::ptr);
    9799  void atomRemoved(const atomId_t _atomid);
    98100  void atomInserted(QtObservedAtom::ptr);
     
    109111
    110112private:
    111 
    112   typedef std::set<moleculeId_t> RemovalMolecule_t;
    113   //!> list of molecule ids whose moleculeRemoved we have received but who have not been inserted yet
    114   RemovalMolecule_t RemovalMolecules;
    115113
    116114  typedef std::map< moleculeId_t , GLMoleculeObject_molecule* > MoleculeNodeMap;
     
    137135  //!> map to contain all QtObservedMolecule that have not been instantiated so far
    138136  QtObservedMoleculeMap_t QtObservedMoleculeMap;
     137
    139138  //!> flag to indicate whether state map is currently worked on
    140139  boost::recursive_mutex MoleculeMissedStateMap_mutex;
Note: See TracChangeset for help on using the changeset viewer.