Changeset a13f2b for src


Ignore:
Timestamp:
Apr 20, 2016, 11:07:47 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:
b2eeaf
Parents:
502614
git-author:
Frederik Heber <heber@…> (04/12/16 18:37:31)
git-committer:
Frederik Heber <heber@…> (04/20/16 23:07:47)
Message:

GLWorldScene can now reparent atoms and bonds whose molecule is instantiated later.

  • parent maps are now bimaps.
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
2 edited

Legend:

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

    r502614 ra13f2b  
    7878    QObject *parent) :
    7979  QObject(parent),
     80  BondNodeParentMaps(std::vector<BondNodeParentMap_t>(2)),
    8081  selectionMode(SelectAtom),
    8182  board(_board)
     
    164165    const ObservedValue_Index_t atomid = _atom->getIndex();
    165166    boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
    166     AtomNodeParentMap.insert( std::make_pair(atomid, (ObservedValue_Index_t)NULL) );
     167    AtomNodeParentMap.left.insert( std::make_pair(atomid, (ObservedValue_Index_t)NULL) );
    167168  }
    168169
     
    184185  {
    185186    boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
    186     AtomNodeParentMap_t::iterator parentiter = AtomNodeParentMap.find(atomid);
    187     ASSERT (parentiter != AtomNodeParentMap.end(),
     187    AtomNodeParentMap_t::left_iterator parentiter = AtomNodeParentMap.left.find(atomid);
     188    ASSERT (parentiter != AtomNodeParentMap.left.end(),
    188189        "GLWorldScene::insertAtom() - parent to atom id "+toString(atomid)+" unknown?");
    189190    const ObservedValue_Index_t parentindex = parentiter->second;
     
    235236  {
    236237    boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
    237     AtomNodeParentMap.erase(_atomid);
     238    AtomNodeParentMap.left.erase(_atomid);
    238239  }
    239240  emit changed();
     
    256257    const ObservedValue_Index_t bondid = _bond->getIndex();
    257258    boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    258     std::vector<ObservedValue_Index_t> parents(2, (ObservedValue_Index_t)NULL);
    259259    if ((_bond->getLeftAtom() != NULL) && (_bond->getLeftAtom()->getMoleculeRef() != NULL))
    260       parents[0] = _bond->getLeftAtom()->getMoleculeRef()->getIndex();
     260      BondNodeParentMaps[0].left.insert(
     261          std::make_pair(bondid, _bond->getLeftAtom()->getMoleculeRef()->getIndex()) );
     262    else
     263      BondNodeParentMaps[0].left.insert(
     264          std::make_pair(bondid, (ObservedValue_Index_t)NULL) );
    261265    if ((_bond->getRightAtom() != NULL) && (_bond->getRightAtom()->getMoleculeRef() != NULL))
    262       parents[1] = _bond->getRightAtom()->getMoleculeRef()->getIndex();
    263     BondNodeParentMap.insert( std::make_pair(bondid, parents) );
     266      BondNodeParentMaps[1].left.insert(
     267          std::make_pair(bondid, _bond->getRightAtom()->getMoleculeRef()->getIndex()) );
     268    else
     269      BondNodeParentMaps[1].left.insert(
     270          std::make_pair(bondid, (ObservedValue_Index_t)NULL) );
    264271  }
    265272
     
    280287
    281288  const ObservedValue_Index_t bondid = _bond->getIndex();
    282   std::vector<QObject *> parents(2, static_cast<QObject *>(this));
     289#ifdef NDEBUG
     290  BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
     291  ASSERT( iter == BondsinSceneMap.end(),
     292    "GLWorldScene::insertBond() - bond "+toString(bondid)+" is already known.");
     293#endif
    283294  {
    284295    boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    285     BondNodeParentMap_t::iterator parentiter = BondNodeParentMap.find(bondid);
    286     ASSERT (parentiter != BondNodeParentMap.end(),
    287         "GLWorldScene::insertBond() - parent to bond id "+toString(bondid)+" unknown?");
    288     const std::vector<ObservedValue_Index_t> &molindices = parentiter->second;
    289     for (size_t i = 0; i < molindices.size(); ++i) {
    290       if (molindices[i] != (ObservedValue_Index_t)NULL) {
    291         const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molindices[i]);
     296    for (size_t i=0;i<2;++i) {
     297      BondNodeParentMap_t::left_iterator parentiter = BondNodeParentMaps[i].left.find(bondid);
     298      ASSERT (parentiter != BondNodeParentMaps[i].left.end(),
     299          "GLWorldScene::insertBond() - parent to bond id "+toString(bondid)+" unknown?");
     300      QObject *parent = this;
     301      if (parentiter->second != (ObservedValue_Index_t)NULL) {
     302        const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(parentiter->second);
    292303        if (moliter != MoleculesinSceneMap.end())
    293           parents[i] = moliter->second;
     304          parent = moliter->second;
    294305      }
    295     }
    296 
    297     BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
    298     ASSERT( iter == BondsinSceneMap.end(),
    299         "GLWorldScene::insertBond() - bond "+toString(bondid)+" is already known.");
    300     for (size_t i=0;i<2;++i) {
     306
    301307      GLMoleculeObject_bond *bondObject = new GLMoleculeObject_bond(
    302308              GLMoleculeObject::meshCylinder,
    303               parents[i],
     309              parent,
    304310              _bond,
    305311              bondsides[i]);
     
    334340  {
    335341    boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
    336     BondNodeParentMap.erase(_bondid);
     342    BondNodeParentMaps[0].left.erase(_bondid);
     343    BondNodeParentMaps[1].left.erase(_bondid);
    337344  }
    338345
     
    390397  MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid);
    391398  ASSERT( iter == MoleculesinSceneMap.end(),
    392       "GLWorldScene::insertMolecule() - molecule's id "+toString(_mol->getMolIndex())
     399      "GLWorldScene::insertMolecule() - molecule's id "+toString(molid)
    393400      +" already present.");
    394401
    395402  // add new object
    396   LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << _mol->getMolIndex());
     403  LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << molid);
    397404  GLMoleculeObject_molecule *molObject =
    398405      new GLMoleculeObject_molecule(
     
    402409  ASSERT( molObject != NULL,
    403410      "GLWorldScene::insertMolecule - could not create molecule object for "
    404       +toString(_mol->getMolIndex()));
     411      +toString(molid));
     412
     413  // check all atoms for not yet assigned parents
     414  {
     415    boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
     416    std::pair<AtomNodeParentMap_t::right_const_iterator, AtomNodeParentMap_t::right_const_iterator> iters =
     417        AtomNodeParentMap.right.equal_range(molid);
     418    for (AtomNodeParentMap_t::right_const_iterator iter = iters.first;
     419        iter != iters.second; ++iter) {
     420      AtomNodeMap::const_iterator atomiter = AtomsinSceneMap.find(iter->second);
     421      if (atomiter != AtomsinSceneMap.end())
     422        resetParent(atomiter->second, molObject);
     423    }
     424  }
     425  // check all bonds for not yet assigned parents
     426  {
     427    boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     428    for (size_t i=0;i<2;++i) {
     429      std::pair<BondNodeParentMap_t::right_const_iterator, BondNodeParentMap_t::right_const_iterator> iters =
     430          BondNodeParentMaps[i].right.equal_range(molid);
     431      for (BondNodeParentMap_t::right_const_iterator iter = iters.first;
     432          iter != iters.second; ++iter) {
     433        BondNodeMap::const_iterator bonditer = BondsinSceneMap.find(iter->second);
     434        if (bonditer != BondsinSceneMap.end())
     435          resetParent(bonditer->second, molObject);
     436      }
     437    }
     438  }
     439
    405440#ifndef NDEBUG
    406441  std::pair<MoleculeNodeMap::iterator, bool> inserter =
     
    453488}
    454489
     490/** This converts safely index into a GLMoleculeObject_molecule.
     491 *
     492 * \param _MoleculesinSceneMap all present molecules
     493 * \param _molid index to look for
     494 * \return MolObject or NULL when not found
     495 */
     496GLMoleculeObject_molecule *GLWorldScene::getMoleculeObject(
     497    const ObservedValue_Index_t _molid) const
     498{
     499  const MoleculeNodeMap::const_iterator moliter = MoleculesinSceneMap.find(_molid);
     500  if (moliter != MoleculesinSceneMap.end())
     501    return moliter->second;
     502  else
     503    return NULL;
     504}
     505
    455506/** Changes the parent of an object in the scene.
    456507 *
     
    463514  boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
    464515  const ObservedValue_Index_t walkerid = walker->getIndex();
    465   AtomNodeParentMap_t::iterator parentiter = AtomNodeParentMap.find(walkerid);
    466   ASSERT( parentiter != AtomNodeParentMap.end(),
     516  AtomNodeParentMap_t::left_iterator parentiter = AtomNodeParentMap.left.find(walkerid);
     517  ASSERT( parentiter != AtomNodeParentMap.left.end(),
    467518      "GLWorldScene::reparentAtom() - could not find object to id "+toString(walkerid));
    468519
    469520  // change parent entry
     521  AtomNodeParentMap.left.erase(parentiter);
    470522  if (walker->getMoleculeRef() != NULL)
    471     parentiter->second = walker->getMoleculeRef()->getIndex();
     523    AtomNodeParentMap.left.insert( std::make_pair(walkerid, walker->getMoleculeRef()->getIndex()) );
    472524  else
    473     parentiter->second = NULL;
    474   parentiter = AtomNodeParentMap.find(walkerid);
    475 
    476   // reset parent if atom exists
    477   AtomNodeMap::iterator atomiter = AtomsinSceneMap.find(walkerid);
    478   if (atomiter != AtomsinSceneMap.end()) {
    479     QObject *parent = this;
    480     if (parentiter->second != NULL) {
    481       MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(parentiter->second);
    482       if (moliter != MoleculesinSceneMap.end())
    483         parent = moliter->second;
    484       else {
    485         // molecule does not yet exist
    486         ASSERT(0, "GLWorldScene::reparentAtom() - molecule not existent not implemented.");
    487       }
    488     }
    489     atomiter->second->setParent(parent);
    490   }
     525    AtomNodeParentMap.left.insert( std::make_pair(walkerid, (ObservedValue_Index_t)NULL) );
     526  parentiter = AtomNodeParentMap.left.find(walkerid);
     527
     528  const AtomNodeMap::iterator atomiter = AtomsinSceneMap.find(walkerid);
     529  if (atomiter != AtomsinSceneMap.end())
     530    resetParent(atomiter->second, getMoleculeObject(parentiter->second));
     531  // else atom does not yet exist
    491532}
    492533
     
    539580{
    540581  boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     582  const size_t dim = (_side == GLMoleculeObject_bond::left) ? 0 : 1;
    541583  const ObservedValue_Index_t bondid = _bond->getIndex();
    542   BondNodeParentMap_t::iterator parentiter = BondNodeParentMap.find(bondid);
    543   ASSERT( parentiter != BondNodeParentMap.end(),
     584  BondNodeParentMap_t::left_iterator parentiter = BondNodeParentMaps[dim].left.find(bondid);
     585  ASSERT( parentiter != BondNodeParentMaps[dim].left.end(),
    544586      "GLWorldScene::reparentBond() - could not find object to id "+toString(bondid));
    545587
    546588  // change parent entry
    547   const size_t dim = (_side == GLMoleculeObject_bond::left) ? 0 : 1;
     589  BondNodeParentMaps[dim].left.erase(bondid);
    548590  if ((_atom != NULL) && (_atom->getMoleculeRef() != NULL))
    549     parentiter->second[dim] = _atom->getMoleculeRef()->getIndex();
     591    BondNodeParentMaps[dim].left.insert( std::make_pair( bondid, _atom->getMoleculeRef()->getIndex()));
    550592  else
    551     parentiter->second[dim] = NULL;
     593    BondNodeParentMaps[dim].left.insert( std::make_pair( bondid, (ObservedValue_Index_t)NULL) );
     594  parentiter = BondNodeParentMaps[dim].left.find(bondid);
    552595
    553596  // reset parent
    554   GLMoleculeObject_bond *bondobj = getBondInScene(bondid, _side);
    555   if (bondobj != NULL) {
     597  resetParent(getBondInScene(bondid, _side), getMoleculeObject(parentiter->second));
     598}
     599
     600/** Resets the parent of an GLMoleculeObject.
     601 *
     602 * \param _obj object to reparent
     603 * \param _molid index of parent molecule
     604 */
     605void GLWorldScene::resetParent(
     606    GLMoleculeObject *_obj,
     607    GLMoleculeObject_molecule *_molobj)
     608{
     609  if (_obj != NULL) {
    556610    QObject *parent = this;
    557     if (parentiter->second[dim] != NULL) {
    558       MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(parentiter->second[dim]);
    559       if (moliter != MoleculesinSceneMap.end())
    560         parent = moliter->second;
    561       else {
    562         // molecule does not yet exist
    563         ASSERT(0, "GLWorldScene::reparentAtom() - molecule not existent not implemented.");
    564       }
    565     }
    566     bondobj->setParent(parent);
    567   }
     611    if (_molobj != NULL)
     612      parent = _molobj;
     613    // else: molecule does not yet exist: is done when molecule is instantiated
     614    _obj->setParent(parent);
     615  }
     616  // else object does not yet exist
    568617}
    569618
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    r502614 ra13f2b  
    2020#include <iosfwd>
    2121
     22#include <boost/bimap.hpp>
    2223#include <boost/thread/recursive_mutex.hpp>
    2324
     
    117118
    118119private:
     120
     121  GLMoleculeObject_molecule *getMoleculeObject(
     122      const ObservedValue_Index_t _molid) const;
     123
     124  void resetParent(
     125      GLMoleculeObject *_obj,
     126      GLMoleculeObject_molecule *_molobj);
     127
    119128  void reparentBond(
    120129      QtObservedBond *_bond,
     
    140149
    141150  //!> typedef for storing the current parent to each atom node in scene, NULL indicates GLWorldScene is parent
    142   typedef std::map<ObservedValue_Index_t, ObservedValue_Index_t> AtomNodeParentMap_t;
     151  typedef boost::bimap<
     152      boost::bimaps::set_of< ObservedValue_Index_t >,
     153      boost::bimaps::multiset_of< ObservedValue_Index_t >
     154  > AtomNodeParentMap_t;
    143155  //!> typedef for storing the current parent to each bond node in scene, NULL indicates GLWorldScene is parent
    144   typedef std::map<ObservedValue_Index_t, std::vector<ObservedValue_Index_t> > BondNodeParentMap_t;
     156  typedef boost::bimap<
     157      boost::bimaps::set_of< ObservedValue_Index_t >,
     158      boost::bimaps::multiset_of< ObservedValue_Index_t >
     159  > BondNodeParentMap_t;
    145160
    146161  //!> mutex to ascertain atomic access to NodeParentMaps
     
    153168  ShapeNodeMap ShapesinSceneMap;
    154169  AtomNodeParentMap_t AtomNodeParentMap;
    155   BondNodeParentMap_t BondNodeParentMap;
     170  std::vector<BondNodeParentMap_t> BondNodeParentMaps;
    156171
    157172  SelectionModeType selectionMode;
Note: See TracChangeset for help on using the changeset viewer.