Changeset efeeb7 for src/UIElements


Ignore:
Timestamp:
Apr 25, 2016, 7:05:31 AM (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:
1eba7c
Parents:
649f59
git-author:
Frederik Heber <heber@…> (04/17/16 21:26:58)
git-committer:
Frederik Heber <heber@…> (04/25/16 07:05:31)
Message:

GLWorldScene now holds onto atoms and bonds until ..Removed() signal and parent(s) is reset.

Location:
src/UIElements/Views/Qt4/Qt3D
Files:
2 edited

Legend:

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

    r649f59 refeeb7  
    7373
    7474using namespace MoleCuilder;
     75
     76// static functions
     77
     78static void eraseBondNodeParents(
     79    std::vector<GLWorldScene::BondNodeParentMap_t> &_BondNodeParentMaps,
     80    const ObservedValue_Index_t &_bondid)
     81{
     82  const size_t left_erased = _BondNodeParentMaps[0].left.erase(_bondid);
     83  const size_t right_erased = _BondNodeParentMaps[1].left.erase(_bondid);
     84  ASSERT( (left_erased == 1) && (right_erased == 1),
     85      "eraseBondNodeParents() - could not erase both parents of "+toString(_bondid)+"?");
     86}
     87
     88/** Checks whether both parents of the bond are set to GLWorldScene and the
     89 * bondRemoved() signals was received for this bond.
     90 *
     91 * \param _BondNodeParent_Maps - map containing parents
     92 * \param _ToBeRemovedNodes - set with all bonds that are to be removed
     93 * \param _bondid id of bond
     94 * \return true - both parents are assigned to GLWorldScene, false - else
     95 */
     96static bool checkBondRemoval(
     97    const std::vector<GLWorldScene::BondNodeParentMap_t> &_BondNodeParentMaps,
     98    const GLWorldScene::ToBeRemovedNodes_t &_ToBeRemovedNodes,
     99    const ObservedValue_Index_t &_bondid)
     100{
     101  GLWorldScene::BondNodeParentMap_t::left_const_iterator leftiter =
     102      _BondNodeParentMaps[0].left.find(_bondid);
     103  GLWorldScene::BondNodeParentMap_t::left_const_iterator rightiter =
     104      _BondNodeParentMaps[1].left.find(_bondid);
     105  ASSERT( leftiter != _BondNodeParentMaps[0].left.end(),
     106      "checkBondRemoval() - left parent to index "+toString(_bondid)+" missing?");
     107  ASSERT( rightiter != _BondNodeParentMaps[1].left.end(),
     108      "checkBondRemoval() - right parent to index "+toString(_bondid)+" missing?");
     109  return ((leftiter->second == (ObservedValue_Index_t)NULL)
     110      && (rightiter->second == (ObservedValue_Index_t)NULL)
     111      && (_ToBeRemovedNodes.count(_bondid)));
     112}
     113
     114void removeBondFromScene(
     115    GLWorldScene::BondNodeMap &_BondsinSceneMap,
     116    const ObservedValue_Index_t &_bondid)
     117{
     118  std::pair<GLWorldScene::BondNodeMap::iterator, GLWorldScene::BondNodeMap::iterator> iters =
     119      _BondsinSceneMap.equal_range(_bondid);
     120  ASSERT( iters.first != iters.second,
     121      "removeBondFromScene() - could not find bond to id "+toString(_bondid));
     122  for (GLWorldScene::BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {
     123    GLMoleculeObject_bond *bondObject = iter->second;
     124    delete bondObject; // is done by signal from bond itself
     125    //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
     126  }
     127  _BondsinSceneMap.erase(_bondid);
     128}
     129
     130static bool checkAtomRemoval(
     131    const GLWorldScene::AtomNodeParentMap_t &_AtomNodeParentMap,
     132    const GLWorldScene::ToBeRemovedNodes_t &_ToBeRemovedNodes,
     133    const ObservedValue_Index_t &_atomid)
     134{
     135  GLWorldScene::AtomNodeParentMap_t::left_const_iterator iter = _AtomNodeParentMap.left.find(_atomid);
     136  ASSERT( iter != _AtomNodeParentMap.left.end(),
     137      "checkAtomRemoval() - missing parent entry for "+toString(_atomid));
     138  return ((iter->second == (ObservedValue_Index_t)NULL) && (_ToBeRemovedNodes.count(_atomid)));
     139}
     140
     141// class definitions
    75142
    76143GLWorldScene::GLWorldScene(
     
    238305    GLWorldScene::ObservedValueIndexLookup_t &_ObservedValueIndexLookup,
    239306    T &_ObservedValues,
    240     ObservedValue_Index_t _id)
     307    const ObservedValue_Index_t &_id)
    241308{
    242309  // get QObject* from lookup
     
    244311      _ObservedValueIndexLookup.find(_id);
    245312  ASSERT( iter != _ObservedValueIndexLookup.end(),
    246       "GLWorldScene::removeAtom() - could not find index "+toString(_id)
     313      "removeStoredObservedValue() - could not find index "+toString(_id)
    247314      +" to stored observed value.");
    248315  QObject * sender = iter->second;
    249316  const size_t erased = _ObservedValues.erase(sender);
    250317  ASSERT( erased == 1,
    251       "GLWorldScene::removeStoredObservedValue() - could not erase stored observed value "
     318      "removeStoredObservedValue() - could not erase stored observed value "
    252319      +toString(_id));
    253320  _ObservedValueIndexLookup.erase(iter);
    254321}
    255322
     323void removeAtomFromScene(
     324    GLWorldScene::AtomNodeMap &_AtomsinSceneMap,
     325    const ObservedValue_Index_t &_atomid)
     326{
     327  GLWorldScene::AtomNodeMap::iterator iter = _AtomsinSceneMap.find(_atomid);
     328  ASSERT(iter != _AtomsinSceneMap.end(),
     329      "removeAtomFromScene() - atom "+toString(_atomid)+" not on display.");
     330  GLMoleculeObject_atom *atomObject = iter->second;
     331  _AtomsinSceneMap.erase(iter);
     332  delete atomObject;
     333}
     334
     335void GLWorldScene::checkAndRemoveAtom(const ObservedValue_Index_t &_atomid)
     336{
     337  boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
     338
     339  if (checkAtomRemoval(AtomNodeParentMap, ToBeRemovedNodes, _atomid)) {
     340    LOG(4, "DEBUG: Found parent of to be removed atom as GLWorldScene, removing.");
     341    removeAtomFromScene(AtomsinSceneMap, _atomid);
     342    AtomNodeParentMap.left.erase(_atomid);
     343    ToBeRemovedNodes.erase(_atomid);
     344    removeStoredObservedValue(ObservedValueIndexLookup, ObservedAtoms, _atomid);
     345  }
     346}
     347
    256348/** Removes an atom.
    257349 *
     
    263355  // bonds are removed by signal coming from ~bond
    264356
     357  ASSERT( ToBeRemovedNodes.count(_atomid) == 0,
     358      "GLWorldScene::removeAtom() - removedAtom signal for id "+toString(_atomid)
     359      +" came in twice?");
     360  ToBeRemovedNodes.insert( _atomid );
     361
    265362  // remove atoms
    266   {
    267     AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atomid);
    268     ASSERT(iter != AtomsinSceneMap.end(),
    269         "GLWorldScene::removeAtom() - atom "+toString(_atomid)+" not on display.");
    270     GLMoleculeObject_atom *atomObject = iter->second;
    271     AtomsinSceneMap.erase(iter);
    272     delete atomObject;
    273   }
    274   {
    275     boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
    276     AtomNodeParentMap_t::left_iterator iter = AtomNodeParentMap.left.find(_atomid);
    277     ASSERT( iter != AtomNodeParentMap.left.end(),
    278         "GLWorldScene::removeAtom() - missing parent entry for "+toString(_atomid));
    279     if (iter->second == (ObservedValue_Index_t)NULL) {
    280       LOG(4, "DEBUG: Found parent of atom as GLWorldScene, removing.");
    281       removeStoredObservedValue(ObservedValueIndexLookup, ObservedAtoms, _atomid);
    282     }
    283     AtomNodeParentMap.left.erase(iter);
    284   }
     363  checkAndRemoveAtom( _atomid );
    285364
    286365  emit changed();
     
    297376void GLWorldScene::connectBond(QtObservedBond::ptr _bond)
    298377{
    299   connect(_bond.get(), SIGNAL(leftmoleculeChanged()), this, SLOT(reparentBondLeft()));
    300   connect(_bond.get(), SIGNAL(rightmoleculeChanged()), this, SLOT(reparentBondRight()));
     378  LOG(3, "INFO: GLWorldScene::connectBond() - connecting to bonds " << _bond->getBondIndex());
     379
     380  connect(_bond.get(), SIGNAL(leftmoleculeChanged()), this, SLOT(reparentBondLeft()), Qt::QueuedConnection);
     381  connect(_bond.get(), SIGNAL(rightmoleculeChanged()), this, SLOT(reparentBondRight()), Qt::QueuedConnection);
    301382
    302383  // store the object, as we need it on reparenting
     
    381462}
    382463
     464void GLWorldScene::checkAndRemoveBond(const ObservedValue_Index_t &_bondid)
     465{
     466  if (checkBondRemoval(BondNodeParentMaps, ToBeRemovedNodes, _bondid)) {
     467    LOG(3, "DEBUG: Found both parents of to be removed bond " << _bondid << " as GLWorldScene, removing.");
     468    removeBondFromScene(BondsinSceneMap, _bondid);
     469    removeStoredObservedValue(ObservedValueIndexLookup, ObservedBonds, _bondid);
     470    eraseBondNodeParents(BondNodeParentMaps, _bondid);
     471    ToBeRemovedNodes.erase(_bondid);
     472  }
     473}
     474
    383475/** Removes a bond.
    384476 *
     
    387479void GLWorldScene::removeBond(ObservedValue_Index_t _bondid)
    388480{
    389   LOG(3, "INFO: GLWorldScene::removedBond() - Removing bond to id " << _bondid);
    390 
    391   // left bond
    392   {
    393     std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =
    394         BondsinSceneMap.equal_range(_bondid);
    395     ASSERT( iters.first != iters.second,
    396         "GLWorldScene::removedBond() - could not find bond to id "+toString(_bondid));
    397     for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {
    398       GLMoleculeObject_bond *bondObject = iter->second;
    399       delete bondObject; // is done by signal from bond itself
    400       //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
    401     }
    402     BondsinSceneMap.erase(_bondid);
    403   }
    404   {
    405     boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    406     for (size_t i=0;i<2;++i) {
    407       BondNodeParentMap_t::left_iterator iter = BondNodeParentMaps[i].left.find(_bondid);
    408       ASSERT( iter != BondNodeParentMaps[i].left.end(),
    409           "GLWorldScene::removeBond() - missing parent entry for "+toString(_bondid));
    410       if (iter->second == (ObservedValue_Index_t)NULL) {
    411         LOG(4, "DEBUG: Found parent of bond as GLWorldScene, removing.");
    412         removeStoredObservedValue(ObservedValueIndexLookup, ObservedBonds, _bondid);
    413       }
    414       BondNodeParentMaps[i].left.erase(iter);
    415     }
    416   }
     481  boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     482  LOG(3, "INFO: GLWorldScene::removedBond() - got bondRemoved signal from board for id " << _bondid);
     483
     484  ASSERT( ToBeRemovedNodes.find(_bondid) == ToBeRemovedNodes.end(),
     485      "GLWorldScene::removeBond() - bondRemoved for "+toString(_bondid)+" obtained twice?");
     486  ToBeRemovedNodes.insert( _bondid );
     487
     488  // check whether node has still non-NULL parents, otherwise remove completely
     489  checkAndRemoveBond( _bondid );
    417490
    418491  emit changed();
     
    600673  boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
    601674  QObject * origin = sender();
     675  if (origin == NULL) {
     676    ELOG(1, "Got reparentAtom() with sender being NULL.");
     677    return;
     678  }
    602679  ObservedAtoms_t::const_iterator iter = ObservedAtoms.find(origin);
    603680  ASSERT( iter != ObservedAtoms.end(),
     
    623700  // else atom does not yet exist
    624701
    625   // check whether node is still shown, otherwise remove from lists completely
    626   {
    627     AtomNodeMap::iterator iter = AtomsinSceneMap.find(walkerid);
    628     if (iter == AtomsinSceneMap.end()) {
    629       LOG(3, "DEBUG: Reparented atom that is no longer on display, removing.");
    630       removeStoredObservedValue(ObservedValueIndexLookup, ObservedAtoms, walkerid);
    631     }
    632   }
     702  // check whether node is still shown, otherwise remove completely
     703  checkAndRemoveAtom( walkerid );
    633704}
    634705
     
    640711  boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    641712  QObject * origin = sender();
     713  if (origin == NULL) {
     714    ELOG(1, "Got reparentBondLeft() with sender being NULL.");
     715    return;
     716  }
    642717  ObservedBonds_t::const_iterator iter = ObservedBonds.find(origin);
    643718  ASSERT( iter != ObservedBonds.end(),
    644719      "GLWorldScene::reparentBondLeft() - bond "+toString(origin)+" is no longer stored?");
    645720  QtObservedBond::ptr bond = iter->second;
     721  LOG(3, "INFO: GLWorldScene::reparentBondLeft() - Reparenting left side of bond "
     722      << bond->getBondIndex() << ".");
    646723  reparentBond(bond, bond->getLeftAtom(), GLMoleculeObject_bond::left);
    647724
    648   // check whether node is still shown, otherwise remove from lists completely
    649   {
    650     const ObservedValue_Index_t bondid = bond->getIndex();
    651     BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
    652     if (iter == BondsinSceneMap.end()) {
    653       // check whether both parents are now NULL
    654       BondNodeParentMap_t::left_iterator leftiter = BondNodeParentMaps[0].left.find(bondid);
    655       BondNodeParentMap_t::left_iterator rightiter = BondNodeParentMaps[1].left.find(bondid);
    656       ASSERT( leftiter != BondNodeParentMaps[0].left.end(),
    657           "GLWorldScene::reparentBondRight() - left parent to index "+toString(bondid)+" missing?");
    658       ASSERT( rightiter != BondNodeParentMaps[1].left.end(),
    659           "GLWorldScene::reparentBondRight() - right parent to index "+toString(bondid)+" missing?");
    660       if ((leftiter->second == (ObservedValue_Index_t)NULL)
    661           && (rightiter->second == (ObservedValue_Index_t)NULL)) {
    662         LOG(3, "DEBUG: Reparented both left and right bond that is also no longer on display, removing.");
    663         removeStoredObservedValue(ObservedValueIndexLookup, ObservedBonds, bondid);
    664       }
    665     }
    666   }
     725  // check whether node is still shown, otherwise remove completely
     726  checkAndRemoveBond( bond->getIndex() );
    667727}
    668728
     
    674734  boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    675735  QObject * origin = sender();
     736  if (origin == NULL) {
     737    ELOG(1, "Got reparentBondRight() with sender being NULL.");
     738    return;
     739  }
    676740  ObservedBonds_t::const_iterator iter = ObservedBonds.find(origin);
    677741  ASSERT( iter != ObservedBonds.end(),
    678742      "GLWorldScene::reparentBondRight() - bond "+toString(origin)+" is no longer stored?");
    679743  QtObservedBond::ptr bond = iter->second;
     744  LOG(3, "INFO: GLWorldScene::reparentBondRight() - Reparenting right side of bond "
     745      << bond->getBondIndex() << ".");
    680746  reparentBond(bond, bond->getRightAtom(), GLMoleculeObject_bond::right);
    681747
    682   // check whether node is still shown, otherwise remove from lists completely
    683   {
    684     const ObservedValue_Index_t bondid = bond->getIndex();
    685     BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
    686     if (iter == BondsinSceneMap.end()) {
    687       // check whether both parents are now NULL
    688       BondNodeParentMap_t::left_iterator leftiter = BondNodeParentMaps[0].left.find(bondid);
    689       BondNodeParentMap_t::left_iterator rightiter = BondNodeParentMaps[1].left.find(bondid);
    690       ASSERT( leftiter != BondNodeParentMaps[0].left.end(),
    691           "GLWorldScene::reparentBondRight() - left parent to index "+toString(bondid)+" missing?");
    692       ASSERT( rightiter != BondNodeParentMaps[1].left.end(),
    693           "GLWorldScene::reparentBondRight() - right parent to index "+toString(bondid)+" missing?");
    694       if ((leftiter->second == (ObservedValue_Index_t)NULL)
    695           && (rightiter->second == (ObservedValue_Index_t)NULL)) {
    696         LOG(3, "DEBUG: Reparented both left and right bond that is also no longer on display, removing.");
    697         removeStoredObservedValue(ObservedValueIndexLookup, ObservedBonds, bondid);
    698       }
    699     }
    700   }
     748  // check whether node is still shown, otherwise remove completely
     749  checkAndRemoveBond( bond->getIndex() );
    701750}
    702751
     
    707756  std::pair<GLWorldScene::BondNodeMap::const_iterator, GLWorldScene::BondNodeMap::const_iterator> iters =
    708757      BondsinSceneMap.equal_range(_bondid);
    709   ASSERT( std::distance(iters.first, iters.second) == 2,
    710       "GLWorldScene::getBondInScene() - not exactly two bonds of same id "
     758  ASSERT( std::distance(iters.first, iters.second) >= 1,
     759      "GLWorldScene::getBondInScene() - not at least one bond of id "
    711760      +toString(_bondid)+" present in scene.");
    712761  for (GLWorldScene::BondNodeMap::const_iterator bonditer = iters.first;
     
    731780  const size_t dim = (_side == GLMoleculeObject_bond::left) ? 0 : 1;
    732781  const ObservedValue_Index_t bondid = _bond->getIndex();
    733   LOG(4, "DEBUG: GLWorldScene: Received signal moleculeChanged for bond "+toString(bondid)+".");
    734782  BondNodeParentMap_t::left_iterator parentiter = BondNodeParentMaps[dim].left.find(bondid);
    735783  ASSERT( parentiter != BondNodeParentMaps[dim].left.end(),
     
    743791    BondNodeParentMaps[dim].left.insert( std::make_pair( bondid, (ObservedValue_Index_t)NULL) );
    744792  parentiter = BondNodeParentMaps[dim].left.find(bondid);
     793  LOG(3, "INFO: GLWorldScene::reparentBond() - Reparented bond "
     794      << _bond->getBondIndex() << " to " << parentiter->second);
    745795
    746796  // reset parent
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    r649f59 refeeb7  
    135135      GLMoleculeObject_bond::SideOfBond _side) const;
    136136
     137  void checkAndRemoveBond(const ObservedValue_Index_t &_bondid);
     138
     139  void checkAndRemoveAtom(const ObservedValue_Index_t &_atomid);
     140
    137141public:
    138142  void updateSelectedShapes();
     
    142146
    143147  typedef std::map< ObservedValue_Index_t, QObject* > ObservedValueIndexLookup_t;
    144 
    145 private:
    146 
    147   //!> id of atom hovered over
    148   atomId_t hoverAtomId;
    149148
    150149  typedef std::map< ObservedValue_Index_t, GLMoleculeObject_molecule* > MoleculeNodeMap;
     
    163162      boost::bimaps::multiset_of< ObservedValue_Index_t >
    164163  > BondNodeParentMap_t;
     164
     165  typedef std::set< ObservedValue_Index_t > ToBeRemovedNodes_t;
     166
     167private:
     168
     169  //!> id of atom hovered over
     170  atomId_t hoverAtomId;
    165171
    166172  //!> mutex to ascertain atomic access to NodeParentMaps
     
    182188  ObservedValueIndexLookup_t ObservedValueIndexLookup;
    183189
     190  //!> all atoms and bond id where we got the ...Removed signals for
     191  ToBeRemovedNodes_t ToBeRemovedNodes;
     192
    184193  SelectionModeType selectionMode;
    185194
Note: See TracChangeset for help on using the changeset viewer.