Changeset bd6768 for src/UIElements


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:
691533
Parents:
273c8a
git-author:
Frederik Heber <heber@…> (04/12/16 12:02:45)
git-committer:
Frederik Heber <heber@…> (04/20/16 23:07:47)
Message:

GLWorldScene now properly reassigns parents of GLMoleculeObjects.

  • this is important for atoms and bonds such that they disappear when their associated molecule is visualized as a tesselated surface.
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp

    r273c8a rbd6768  
    4949
    5050private slots:
    51   //!> grant GLMoleculeObject_molecule acess to reset functions
    52   friend class GLMoleculeObject_molecule;
     51  //!> grant GLWorldScene access to SideOfBond
     52  friend class GLWorldScene;
    5353
    5454  /** Recalculates the element of the cylinder representing the bond.
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    r273c8a rbd6768  
    9999  }
    100100  connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
    101       this, SLOT(moleculeInserted(QtObservedMolecule::ptr)));
     101      this, SLOT(insertMolecule(QtObservedMolecule::ptr)));
    102102  connect(board, SIGNAL(moleculeRemoved(ObservedValue_Index_t)),
    103       this, SLOT(moleculeRemoved(ObservedValue_Index_t)));
     103      this, SLOT(removeMolecule(ObservedValue_Index_t)));
     104
    104105  connect(board, SIGNAL(atomInserted(QtObservedAtom::ptr)),
    105       this, SLOT(atomInserted(QtObservedAtom::ptr)));
     106      this, SLOT(connectAtom(QtObservedAtom::ptr)), Qt::DirectConnection);
     107  connect(this, SIGNAL(atomConnected(QtObservedAtom::ptr)),
     108      this, SLOT(insertAtom(QtObservedAtom::ptr)));
    106109  connect(board, SIGNAL(atomRemoved(ObservedValue_Index_t)),
    107       this, SLOT(atomRemoved(ObservedValue_Index_t)));
     110      this, SLOT(removeAtom(ObservedValue_Index_t)));
     111
    108112  connect(board, SIGNAL(bondInserted(QtObservedBond::ptr)),
    109       this, SLOT(bondInserted(QtObservedBond::ptr)));
     113      this, SLOT(connectBond(QtObservedBond::ptr)), Qt::DirectConnection);
     114  connect(this, SIGNAL(bondConnected(QtObservedBond::ptr)),
     115      this, SLOT(insertBond(QtObservedBond::ptr)));
    110116  connect(board, SIGNAL(bondRemoved(ObservedValue_Index_t)),
    111       this, SLOT(bondRemoved(ObservedValue_Index_t)));
     117      this, SLOT(removeBond(ObservedValue_Index_t)));
    112118
    113119//  connect(this, SIGNAL(updated()), this, SLOT(update()));
     
    120126}
    121127
    122 void GLWorldScene::atomClicked(atomId_t no)
    123 {
    124    LOG(3, "INFO: GLMoleculeObject_molecule - atom " << no << " has been clicked.");
     128void GLWorldScene::clickAtom(atomId_t no)
     129{
     130   LOG(3, "INFO: GLWorldScene - atom " << no << " has been clicked.");
    125131   const atom * const Walker = const_cast<const World &>(World::getInstance()).
    126132       getAtom(AtomById(no));
    127133   ASSERT( Walker != NULL,
    128        "GLWorldScene::atomClicked() - clicked atom has disappeared.");
     134       "GLWorldScene::clickAtom() - clicked atom has disappeared.");
    129135   if (selectionMode == SelectAtom){
    130136     if (!World::getInstance().isSelected(Walker))
     
    144150}
    145151
     152/** Prepares adding an atom to the scene
     153 *
     154 * We need to listen to moleculeChanged() in order to properly re-parent()
     155 * this QObject
     156 *
     157 * @param _atom atom to connect
     158 */
     159void GLWorldScene::connectAtom(QtObservedAtom::ptr _atom)
     160{
     161  connect(_atom.get(), SIGNAL(moleculeChanged()), this, SLOT(reparentAtom()));
     162
     163  {
     164    const ObservedValue_Index_t atomid = _atom->getIndex();
     165    boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
     166    AtomNodeParentMap[atomid] = static_cast<QObject *>(this);
     167  }
     168
     169  emit atomConnected(_atom);
     170}
     171
    146172/** Adds an atom to the scene.
    147173 *
    148174 * @param _atom atom to add
    149175 */
    150 void GLWorldScene::atomInserted(QtObservedAtom::ptr _atom)
     176void GLWorldScene::insertAtom(QtObservedAtom::ptr _atom)
    151177{
    152178  LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "
    153179      << _atom->getAtomIndex());
    154180
    155   GLMoleculeObject_atom *atomObject =
    156       new GLMoleculeObject_atom(
    157           GLMoleculeObject::meshSphere,
    158           this, /* parent is GLWorldScene */
    159           _atom);
    160   ASSERT( atomObject != NULL,
    161       "GLWorldScene::atomInserted - could not create atom object for "
    162       +toString(_atom->getAtomIndex()));
    163181  const ObservedValue_Index_t atomid = _atom->getIndex();
     182  QObject *parent = static_cast<QObject *>(this);
     183  GLMoleculeObject_atom *atomObject = NULL;
     184  {
     185    boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
     186    AtomNodeParentMap_t::iterator parentiter = AtomNodeParentMap.find(atomid);
     187    if (parentiter != AtomNodeParentMap.end())
     188      parent = parentiter->second;
     189    else
     190      AtomNodeParentMap[atomid] = parent;
     191
     192    atomObject = new GLMoleculeObject_atom(
     193            GLMoleculeObject::meshSphere,
     194            parent,
     195            _atom);
     196    ASSERT( atomObject != NULL,
     197        "GLWorldScene::atomInserted - could not create atom object for "
     198        +toString(_atom->getAtomIndex()));
     199  }
    164200  AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid);
    165201  ASSERT(iter == AtomsinSceneMap.end(),
    166       "GLWorldScene::atomInserted - same atom with id "
     202      "GLWorldScene::insertAtom - same atom with id "
    167203      +toString(_atom->getAtomIndex())+" added again.");
    168204  AtomsinSceneMap.insert( make_pair(atomid, atomObject) );
    169205
    170   connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
     206  connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(clickAtom(atomId_t)));
    171207  connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
    172208  connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
     
    181217 * @param _atomid index of the atom that is removed
    182218 */
    183 void GLWorldScene::atomRemoved(ObservedValue_Index_t _atomid)
     219void GLWorldScene::removeAtom(ObservedValue_Index_t _atomid)
    184220{
    185221  LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
     
    189225  AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atomid);
    190226  ASSERT(iter != AtomsinSceneMap.end(),
    191       "GLWorldScene::atomRemoved() - atom "+toString(_atomid)+" not on display.");
     227      "GLWorldScene::removeAtom() - atom "+toString(_atomid)+" not on display.");
    192228  GLMoleculeObject_atom *atomObject = iter->second;
    193229  AtomsinSceneMap.erase(iter);
    194230  delete atomObject;
    195 
     231  {
     232    boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
     233    AtomNodeParentMap.erase(_atomid);
     234  }
    196235  emit changed();
    197236  emit changeOccured();
    198237}
    199238
     239/** Prepares adding a bond to the scene
     240 *
     241 * We need to listen to moleculeChanged() in order to properly re-parent()
     242 * this QObject
     243 *
     244 * @param _bond bond to connect
     245 */
     246void GLWorldScene::connectBond(QtObservedBond::ptr _bond)
     247{
     248  connect(_bond.get(), SIGNAL(leftmoleculeChanged()), this, SLOT(reparentBondLeft()));
     249  connect(_bond.get(), SIGNAL(rightmoleculeChanged()), this, SLOT(reparentBondRight()));
     250
     251  {
     252    const ObservedValue_Index_t bondid = _bond->getIndex();
     253    boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     254    std::vector<QObject *> parents(2, static_cast<QObject *>(this));
     255    if ((_bond->getLeftAtom() != NULL) && (_bond->getLeftAtom()->getMoleculeRef() != NULL)) {
     256      const ObservedValue_Index_t molid = _bond->getLeftAtom()->getMoleculeRef()->getIndex();
     257      const MoleculeNodeMap::iterator leftiter = MoleculesinSceneMap.find(molid);
     258      if (leftiter != MoleculesinSceneMap.end())
     259        parents[0] = leftiter->second;
     260    }
     261    if ((_bond->getRightAtom() != NULL) && (_bond->getRightAtom()->getMoleculeRef() != NULL)) {
     262      const ObservedValue_Index_t molid = _bond->getRightAtom()->getMoleculeRef()->getIndex();
     263      const MoleculeNodeMap::iterator leftiter = MoleculesinSceneMap.find(molid);
     264      if (leftiter != MoleculesinSceneMap.end())
     265        parents[1] = leftiter->second;
     266    }
     267    BondNodeParentMap.insert( std::make_pair(bondid, parents) );
     268  }
     269
     270  emit bondConnected(_bond);
     271}
     272
    200273/** Adds a bond to the scene.
    201274 *
    202275 * @param _bond bond to add
    203276 */
    204 void GLWorldScene::bondInserted(QtObservedBond::ptr _bond)
     277void GLWorldScene::insertBond(QtObservedBond::ptr _bond)
    205278{
    206279  static const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides =
     
    208281          (GLMoleculeObject_bond::left)
    209282          (GLMoleculeObject_bond::right);
    210   LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bonds " << _bond->getBondIndex());
    211   //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
     283  LOG(3, "INFO: GLWorldScene::insertBond() - Adding bonds " << _bond->getBondIndex());
    212284
    213285  const ObservedValue_Index_t bondid = _bond->getIndex();
    214   BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
    215   ASSERT( iter == BondsinSceneMap.end(),
    216       "GLWorldScene::bondInserted() - bond "+toString(bondid)+" is already known.");
    217   for (size_t i=0;i<2;++i) {
    218     GLMoleculeObject_bond * bondObject =
    219         new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, _bond, bondsides[i]);
    220     connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
    221     BondsinSceneMap.insert( std::make_pair(bondid, bondObject) );
     286  std::vector<QObject *> parents(2, static_cast<QObject *>(this));
     287  {
     288    boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     289    BondNodeParentMap_t::iterator parentiter = BondNodeParentMap.find(bondid);
     290    if (parentiter != BondNodeParentMap.end()) {
     291      parents = parentiter->second;
     292    } else
     293      BondNodeParentMap.insert( std::make_pair(bondid, parents) );
     294
     295    BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
     296    ASSERT( iter == BondsinSceneMap.end(),
     297        "GLWorldScene::insertBond() - bond "+toString(bondid)+" is already known.");
     298    for (size_t i=0;i<2;++i) {
     299      GLMoleculeObject_bond *bondObject = new GLMoleculeObject_bond(
     300              GLMoleculeObject::meshCylinder,
     301              parents[i],
     302              _bond,
     303              bondsides[i]);
     304      connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
     305      BondsinSceneMap.insert( std::make_pair(bondid, bondObject) );
     306    }
    222307  }
    223308
     
    230315 * @param _bondid id of bond to remove
    231316 */
    232 void GLWorldScene::bondRemoved(ObservedValue_Index_t _bondid)
    233 {
    234   LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond to id " << _bondid);
     317void GLWorldScene::removeBond(ObservedValue_Index_t _bondid)
     318{
     319  LOG(3, "INFO: GLWorldScene::removedBond() - Removing bond to id " << _bondid);
    235320
    236321  // left bond
    237   BondNodeMap::iterator iter = BondsinSceneMap.find(_bondid);
    238   ASSERT( iter != BondsinSceneMap.end(),
    239       "GLWorldScene::bondRemoved() - could not find bond to id "+toString(_bondid));
    240   GLMoleculeObject_bond *bondObject = iter->second;
    241   delete bondObject; // is done by signal from bond itself
    242   //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
    243   BondsinSceneMap.erase(iter);
     322  std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =
     323      BondsinSceneMap.equal_range(_bondid);
     324  ASSERT( iters.first != iters.second,
     325      "GLWorldScene::removedBond() - could not find bond to id "+toString(_bondid));
     326  for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {
     327    GLMoleculeObject_bond *bondObject = iter->second;
     328    delete bondObject; // is done by signal from bond itself
     329    //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
     330  }
     331  BondsinSceneMap.erase(_bondid);
     332  {
     333    boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     334    BondNodeParentMap.erase(_bondid);
     335  }
    244336
    245337  emit changed();
     
    270362}
    271363
    272 void GLWorldScene::moleculeClicked(moleculeId_t no)
     364void GLWorldScene::clickMolecule(moleculeId_t no)
    273365{
    274366   LOG(3, "INFO: GLMoleculeObject_molecule - mol " << no << " has been clicked.");
     
    288380 * @param _mol molecule to insert
    289381 */
    290 void GLWorldScene::moleculeInserted(QtObservedMolecule::ptr _mol)
     382void GLWorldScene::insertMolecule(QtObservedMolecule::ptr _mol)
    291383{
    292384  const ObservedValue_Index_t molid = _mol->getIndex();
     
    296388  MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid);
    297389  ASSERT( iter == MoleculesinSceneMap.end(),
    298       "GLWorldScene::moleculeInserted() - molecule's id "+toString(_mol->getMolIndex())
     390      "GLWorldScene::insertMolecule() - molecule's id "+toString(_mol->getMolIndex())
    299391      +" already present.");
    300392
     
    307399          _mol);
    308400  ASSERT( molObject != NULL,
    309       "GLWorldScene::moleculeInserted - could not create molecule object for "
     401      "GLWorldScene::insertMolecule - could not create molecule object for "
    310402      +toString(_mol->getMolIndex()));
    311403#ifndef NDEBUG
     
    314406  MoleculesinSceneMap.insert( make_pair(molid, molObject) );
    315407  ASSERT(inserter.second,
    316       "GLWorldScene::moleculeInserted() - molecule "+toString(_mol->getMolIndex())
     408      "GLWorldScene::insertMolecule() - molecule "+toString(_mol->getMolIndex())
    317409      +" already present in scene.");
    318410
     
    328420 * @param _molid index of the molecule to remove
    329421 */
    330 void GLWorldScene::moleculeRemoved(ObservedValue_Index_t _molid)
     422void GLWorldScene::removeMolecule(ObservedValue_Index_t _molid)
    331423{
    332424  LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molid)+".");
     
    334426  MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
    335427  ASSERT ( iter != MoleculesinSceneMap.end(),
    336       "GLWorldScene::moleculeRemoved() - to be removed molecule "+toString(_molid)
     428      "GLWorldScene::removeMolecule() - to be removed molecule "+toString(_molid)
    337429      +" is already gone.");
    338430  // check if it's already empty
     
    357449  emit changed();
    358450  emit changeOccured();
     451}
     452
     453/** Changes the parent of an object in the scene.
     454 *
     455 * \param _id index of the object whose parent to change
     456 * \param _ob new parent
     457 */
     458void GLWorldScene::reparentAtom()
     459{
     460  QtObservedAtom *walker = dynamic_cast<QtObservedAtom *>(sender());
     461  boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
     462  const ObservedValue_Index_t walkerid = walker->getIndex();
     463  AtomNodeParentMap_t::iterator parentiter = AtomNodeParentMap.find(walkerid);
     464  ASSERT( parentiter != AtomNodeParentMap.end(),
     465      "GLWorldScene::reparentAtom() - could not find object to id "+toString(walkerid));
     466  AtomNodeMap::iterator atomiter = AtomsinSceneMap.find(walkerid);
     467  ASSERT( atomiter != AtomsinSceneMap.end(),
     468      "GLWorldScene::reparentAtom() - could not find GLMoleculeObject to id "+toString(walkerid));
     469  if (walker->getMoleculeRef() != NULL) {
     470    const ObservedValue_Index_t molid = walker->getMoleculeRef()->getIndex();
     471    MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
     472    if (moliter != MoleculesinSceneMap.end()) {
     473      parentiter->second = moliter->second;
     474      atomiter->second->setParent(moliter->second);
     475    } else {
     476      // associated molecule has not yet been instantiated, keep in mind
     477      ASSERT(0,
     478          "GLWorldScene::reparentAtom() - new molecule not present yet?");
     479    }
     480  } else {
     481    parentiter->second = static_cast<QObject*>(this);
     482    atomiter->second->setParent(this);
     483  }
     484}
     485
     486/** Changes the parent of an object in the scene.
     487 *
     488 * \param _id index of the object whose parent to change
     489 * \param _ob new parent
     490 */
     491void GLWorldScene::reparentBondLeft()
     492{
     493  QtObservedBond *bond = dynamic_cast<QtObservedBond *>(sender());
     494  boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     495  const ObservedValue_Index_t bondid = bond->getIndex();
     496  BondNodeParentMap_t::iterator parentiter = BondNodeParentMap.find(bondid);
     497  ASSERT( parentiter != BondNodeParentMap.end(),
     498      "GLWorldScene::reparentBondLeft() - could not find object to id "+toString(bondid));
     499  BondNodeMap::iterator bonditer = BondsinSceneMap.find(bondid);
     500  ASSERT( bonditer != BondsinSceneMap.end(),
     501      "GLWorldScene::reparentBondLeft() - could not find GLMoleculeObject to id "+toString(bondid));
     502  if (bonditer->second->BondSide != GLMoleculeObject_bond::left)
     503    ++bonditer;
     504  ASSERT( (bonditer->first == bondid)
     505      && (bonditer->second->BondSide == GLMoleculeObject_bond::left),
     506      "GLWorldScene::reparentBondLeft() - could not find left-side bond.");
     507  if ((bond->getLeftAtom() != NULL) && (bond->getLeftAtom()->getMoleculeRef() != NULL)) {
     508    const ObservedValue_Index_t molid = bond->getLeftAtom()->getMoleculeRef()->getIndex();
     509    MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
     510    if (moliter != MoleculesinSceneMap.end()) {
     511      parentiter->second[0] = moliter->second;
     512      bonditer->second->setParent(moliter->second);
     513    } else {
     514      // associated molecule has not yet been instantiated, keep in mind
     515      ASSERT(0,
     516          "GLWorldScene::reparentBondLeft() - new molecule not present yet?");
     517    }
     518  } else {
     519    parentiter->second[0] = static_cast<QObject*>(this);
     520    bonditer->second->setParent(this);
     521  }
     522}
     523
     524/** Changes the parent of an object in the scene.
     525 *
     526 * \param _id index of the object whose parent to change
     527 * \param _ob new parent
     528 */
     529void GLWorldScene::reparentBondRight()
     530{
     531  QtObservedBond *bond = dynamic_cast<QtObservedBond *>(sender());
     532  boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
     533  const ObservedValue_Index_t bondid = bond->getIndex();
     534  BondNodeParentMap_t::iterator parentiter = BondNodeParentMap.find(bondid);
     535  ASSERT( parentiter != BondNodeParentMap.end(),
     536      "GLWorldScene::reparentBondLeft() - could not find object to id "+toString(bondid));
     537  BondNodeMap::iterator bonditer = BondsinSceneMap.find(bondid);
     538  ASSERT( bonditer != BondsinSceneMap.end(),
     539      "GLWorldScene::reparentBondLeft() - could not find GLMoleculeObject to id "+toString(bondid));
     540  if (bonditer->second->BondSide != GLMoleculeObject_bond::right)
     541    ++bonditer;
     542  ASSERT( (bonditer->first == bondid)
     543      && (bonditer->second->BondSide == GLMoleculeObject_bond::right),
     544      "GLWorldScene::reparentBondLeft() - could not find right-side bond.");
     545  if ((bond->getRightAtom() != NULL) && (bond->getRightAtom()->getMoleculeRef() != NULL)) {
     546    const ObservedValue_Index_t molid = bond->getRightAtom()->getMoleculeRef()->getIndex();
     547    MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
     548    if (moliter != MoleculesinSceneMap.end()) {
     549      parentiter->second[1] = moliter->second;
     550      bonditer->second->setParent(moliter->second);
     551    } else {
     552      // associated molecule has not yet been instantiated, keep in mind
     553      ASSERT(0,
     554          "GLWorldScene::reparentBondRight() - new molecule not present yet?");
     555    }
     556  } else {
     557    parentiter->second[1] = static_cast<QObject*>(this);
     558    bonditer->second->setParent(this);
     559  }
    359560}
    360561
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    r273c8a rbd6768  
    1919
    2020#include <iosfwd>
     21
     22#include <boost/thread/recursive_mutex.hpp>
    2123
    2224#include "Bond/bond.hpp"
     
    8385  void hoverChanged(const atomId_t);
    8486  void hoverChanged(const moleculeId_t, int);
     87  void atomConnected(QtObservedAtom::ptr);
     88  void bondConnected(QtObservedBond::ptr);
    8589
    8690private slots:
    87   void atomClicked(atomId_t no);
    88   void atomRemoved(ObservedValue_Index_t _atomid);
    89   void atomInserted(QtObservedAtom::ptr);
    90   void bondRemoved(ObservedValue_Index_t _bondid);
    91   void bondInserted(QtObservedBond::ptr);
    92   void moleculeClicked(moleculeId_t no);
    93   void moleculeRemoved(ObservedValue_Index_t _molid);
    94   void moleculeInserted(QtObservedMolecule::ptr);
     91
     92  void clickAtom(atomId_t no);
     93  void connectAtom(QtObservedAtom::ptr);
     94  void insertAtom(QtObservedAtom::ptr);
     95  void removeAtom(ObservedValue_Index_t _atomid);
     96
     97  void connectBond(QtObservedBond::ptr);
     98  void insertBond(QtObservedBond::ptr);
     99  void removeBond(ObservedValue_Index_t _bondid);
     100
     101  void clickMolecule(moleculeId_t no);
     102  void insertMolecule(QtObservedMolecule::ptr);
     103  void removeMolecule(ObservedValue_Index_t _molid);
     104
    95105  void setSelectionModeAtom();
    96106  void setSelectionModeMolecule();
     107
    97108  void addShape(const std::string &_name);
    98109  void removeShape(const std::string &_name);
     
    100111  void moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible);
    101112  void hoverChangedSignalled(GLMoleculeObject *ob);
     113
     114  void reparentAtom();
     115  void reparentBondLeft();
     116  void reparentBondRight();
    102117
    103118public:
     
    111126  typedef std::map< ObservedValue_Index_t , GLMoleculeObject_molecule* > MoleculeNodeMap;
    112127  typedef std::map< ObservedValue_Index_t, GLMoleculeObject_atom* > AtomNodeMap;
    113   typedef std::map< ObservedValue_Index_t, GLMoleculeObject_bond* > BondNodeMap;
     128  typedef std::multimap< ObservedValue_Index_t, GLMoleculeObject_bond* > BondNodeMap;
    114129  typedef std::map< std::string , GLMoleculeObject_shape* > ShapeNodeMap;
     130
     131  //!> typedef for storing the current parent to each node in scene
     132  typedef std::map<ObservedValue_Index_t, QObject *> AtomNodeParentMap_t;
     133  typedef std::map<ObservedValue_Index_t, std::vector<QObject *> > BondNodeParentMap_t;
     134
     135  //!> mutex to ascertain atomic access to NodeParentMaps
     136  boost::recursive_mutex AtomNodeParentMap_mutex;
     137  boost::recursive_mutex BondNodeParentMap_mutex;
    115138
    116139  AtomNodeMap AtomsinSceneMap;
     
    118141  MoleculeNodeMap MoleculesinSceneMap;
    119142  ShapeNodeMap ShapesinSceneMap;
     143  AtomNodeParentMap_t AtomNodeParentMap;
     144  BondNodeParentMap_t BondNodeParentMap;
    120145
    121146  SelectionModeType selectionMode;
Note: See TracChangeset for help on using the changeset viewer.