Changeset 649f59 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:
efeeb7
Parents:
136842
git-author:
Frederik Heber <heber@…> (04/15/16 07:38:55)
git-committer:
Frederik Heber <heber@…> (04/25/16 07:05:31)
Message:

GLWorldScene removes stored observed values only after both parent is NULL and atomRemoved() came in.

  • this is to ensure that lifetime of the observed value instance is as long as required.
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
2 edited

Legend:

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

    r136842 r649f59  
    163163
    164164  // store the object, as we need it on reparenting
     165  {
    165166#ifndef NDEBUG
    166   std::pair< ObservedAtoms_t::iterator, bool > inserter =
     167    std::pair< ObservedAtoms_t::iterator, bool > inserter =
    167168#endif
    168       ObservedAtoms.insert( std::make_pair(_atom->getIndex(), _atom) );
    169   ASSERT( inserter.second,
    170       "GLWorldScene::connectAtom() - observed atom "+toString(_atom)+" already stored?");
    171 
     169        ObservedAtoms.insert( std::make_pair(_atom.get(), _atom) );
     170    ASSERT( inserter.second,
     171        "GLWorldScene::connectAtom() - observed atom "+toString(_atom)+" already stored?");
     172#ifndef NDEBUG
     173    std::pair< ObservedValueIndexLookup_t::iterator, bool > indexinserter =
     174#endif
     175        ObservedValueIndexLookup.insert( std::make_pair(_atom->getIndex(), _atom.get()) );
     176    ASSERT( indexinserter.second,
     177        "GLWorldScene::connectAtom() - observed atom's index "
     178        +toString(_atom->getIndex())+" already stored?");
     179  }
    172180  {
    173181    const ObservedValue_Index_t atomid = _atom->getIndex();
     
    226234}
    227235
     236template <class T>
     237void removeStoredObservedValue(
     238    GLWorldScene::ObservedValueIndexLookup_t &_ObservedValueIndexLookup,
     239    T &_ObservedValues,
     240    ObservedValue_Index_t _id)
     241{
     242  // get QObject* from lookup
     243  const GLWorldScene::ObservedValueIndexLookup_t::iterator iter =
     244      _ObservedValueIndexLookup.find(_id);
     245  ASSERT( iter != _ObservedValueIndexLookup.end(),
     246      "GLWorldScene::removeAtom() - could not find index "+toString(_id)
     247      +" to stored observed value.");
     248  QObject * sender = iter->second;
     249  const size_t erased = _ObservedValues.erase(sender);
     250  ASSERT( erased == 1,
     251      "GLWorldScene::removeStoredObservedValue() - could not erase stored observed value "
     252      +toString(_id));
     253  _ObservedValueIndexLookup.erase(iter);
     254}
     255
    228256/** Removes an atom.
    229257 *
     
    246274  {
    247275    boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
    248     AtomNodeParentMap.left.erase(_atomid);
    249   }
    250   {
    251     const size_t erased = ObservedAtoms.erase(_atomid);
    252     ASSERT( erased == 1,
    253         "GLWorldScene::removeAtom() - could not erase stored observed value "+toString(_atomid));
    254   }
     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  }
     285
    255286  emit changed();
    256287  emit changeOccured();
     
    270301
    271302  // store the object, as we need it on reparenting
     303  {
    272304#ifndef NDEBUG
    273   std::pair< ObservedBonds_t::iterator, bool > inserter =
     305    std::pair< ObservedBonds_t::iterator, bool > inserter =
    274306#endif
    275       ObservedBonds.insert( std::make_pair(_bond->getIndex(), _bond) );
    276   ASSERT( inserter.second,
    277       "GLWorldScene::connectBond() - observed bond "+toString(_bond)+" already stored?");
    278 
     307        ObservedBonds.insert( std::make_pair(_bond.get(), _bond) );
     308    ASSERT( inserter.second,
     309        "GLWorldScene::connectBond() - observed bond "+toString(_bond)+" already stored?");
     310#ifndef NDEBUG
     311    std::pair< ObservedValueIndexLookup_t::iterator, bool > indexinserter =
     312#endif
     313        ObservedValueIndexLookup.insert( std::make_pair(_bond->getIndex(), _bond.get()) );
     314    ASSERT( indexinserter.second,
     315        "GLWorldScene::connectBond() - observed bond's index "
     316        +toString(_bond->getIndex())+" already stored?");
     317  }
    279318  {
    280319    const ObservedValue_Index_t bondid = _bond->getIndex();
     
    365404  {
    366405    boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    367     BondNodeParentMaps[0].left.erase(_bondid);
    368     BondNodeParentMaps[1].left.erase(_bondid);
    369   }
    370   {
    371     const size_t erased = ObservedAtoms.erase(_bondid);
    372     ASSERT( erased == 1,
    373         "GLWorldScene::removeBond() - could not erase stored observed value "+toString(_bondid));
     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    }
    374416  }
    375417
     
    556598void GLWorldScene::reparentAtom()
    557599{
    558   QtObservedAtom *walker = dynamic_cast<QtObservedAtom *>(sender());
    559600  boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
     601  QObject * origin = sender();
     602  ObservedAtoms_t::const_iterator iter = ObservedAtoms.find(origin);
     603  ASSERT( iter != ObservedAtoms.end(),
     604      "GLWorldScene::reparentAtom() - atom's "+toString(origin)+" is no longer stored?");
     605  QtObservedAtom::ptr walker = iter->second;
    560606  const ObservedValue_Index_t walkerid = walker->getIndex();
    561607  LOG(4, "DEBUG: GLWorldScene: Received signal moleculeChanged for atom "+toString(walkerid)+".");
     
    576622    resetParent(atomiter->second, getMoleculeObject(parentiter->second));
    577623  // else atom does not yet exist
     624
     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  }
    578633}
    579634
     
    584639{
    585640  boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    586   QtObservedBond *bond = dynamic_cast<QtObservedBond *>(sender());
     641  QObject * origin = sender();
     642  ObservedBonds_t::const_iterator iter = ObservedBonds.find(origin);
     643  ASSERT( iter != ObservedBonds.end(),
     644      "GLWorldScene::reparentBondLeft() - bond "+toString(origin)+" is no longer stored?");
     645  QtObservedBond::ptr bond = iter->second;
    587646  reparentBond(bond, bond->getLeftAtom(), GLMoleculeObject_bond::left);
     647
     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  }
    588667}
    589668
     
    594673{
    595674  boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    596   QtObservedBond *bond = dynamic_cast<QtObservedBond *>(sender());
     675  QObject * origin = sender();
     676  ObservedBonds_t::const_iterator iter = ObservedBonds.find(origin);
     677  ASSERT( iter != ObservedBonds.end(),
     678      "GLWorldScene::reparentBondRight() - bond "+toString(origin)+" is no longer stored?");
     679  QtObservedBond::ptr bond = iter->second;
    597680  reparentBond(bond, bond->getRightAtom(), GLMoleculeObject_bond::right);
     681
     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  }
    598701}
    599702
     
    621724 */
    622725void GLWorldScene::reparentBond(
    623     QtObservedBond *_bond,
     726    const QtObservedBond::ptr _bond,
    624727    const QtObservedAtom::ptr _atom,
    625728    const GLMoleculeObject_bond::SideOfBond _side)
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    r136842 r649f59  
    127127
    128128  void reparentBond(
    129       QtObservedBond *_bond,
     129      const QtObservedBond::ptr _bond,
    130130      const QtObservedAtom::ptr _atom,
    131131      const GLMoleculeObject_bond::SideOfBond _side);
     
    137137public:
    138138  void updateSelectedShapes();
     139
     140  typedef std::map< QObject*, QtObservedAtom::ptr > ObservedAtoms_t;
     141  typedef std::map< QObject*, QtObservedBond::ptr > ObservedBonds_t;
     142
     143  typedef std::map< ObservedValue_Index_t, QObject* > ObservedValueIndexLookup_t;
    139144
    140145private:
     
    159164  > BondNodeParentMap_t;
    160165
    161   typedef std::map< ObservedValue_Index_t, QtObservedAtom::ptr > ObservedAtoms_t;
    162   typedef std::map< ObservedValue_Index_t, QtObservedBond::ptr > ObservedBonds_t;
    163 
    164166  //!> mutex to ascertain atomic access to NodeParentMaps
    165167  boost::recursive_mutex AtomNodeParentMap_mutex;
     
    177179  //!> stored observed bond such that its signals may always be safely evaluated
    178180  ObservedBonds_t ObservedBonds;
     181  //!> in moleculeChanged() we only have QObject*, in reparent..() we have ObservedValue_Index_t, need lookup
     182  ObservedValueIndexLookup_t ObservedValueIndexLookup;
    179183
    180184  SelectionModeType selectionMode;
Note: See TracChangeset for help on using the changeset viewer.