Ignore:
Timestamp:
Apr 20, 2016, 10:58:43 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:
d48a16
Parents:
b4bd0e
git-author:
Frederik Heber <heber@…> (03/24/16 13:26:51)
git-committer:
Frederik Heber <heber@…> (04/20/16 22:58:43)
Message:

Modified all GLMoleculeObjects and GLWorldScene to the new QtObservedBond.

  • GLWorldScene transmits bondInserted/bondRemoved similarly to those for the atoms to the molecule if aLready present and otherwise into the MissedStateMap.
File:
1 edited

Legend:

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

    rb4bd0e r96f14a  
    101101  connect(board, SIGNAL(atomRemoved(ObservedValue_Index_t)),
    102102      this, SLOT(atomRemoved(ObservedValue_Index_t)));
     103  connect(board, SIGNAL(bondInserted(QtObservedBond::ptr)),
     104      this, SLOT(bondInserted(QtObservedBond::ptr)));
     105  connect(board, SIGNAL(bondRemoved(ObservedValue_Index_t)),
     106      this, SLOT(bondRemoved(ObservedValue_Index_t)));
    103107  connect(this, SIGNAL(insertMolecule(QtObservedMolecule::ptr)),
    104108      this, SLOT(moleculeInserted(QtObservedMolecule::ptr)) );
     
    182186      +" is not present in QtObservedAtomMap.");
    183187  QtObservedAtomMap.erase(eraseiter);
     188}
     189
     190/** Prepares insertion of a bond.
     191 *
     192 * This is called before the insertion into a molecule and thus before the
     193 * insertion into the scene.
     194 *
     195 * @param _bond bond to insert
     196 */
     197void GLWorldScene::bondInserted(QtObservedBond::ptr _bond)
     198{
     199  const ObservedValue_Index_t bondid = _bond->getIndex();
     200  ASSERT( QtObservedBondMap.find(bondid) == QtObservedBondMap.end(),
     201      "GLWorldScene::BondInserted() - bond with id "+toString(_bond->getBondIndex())
     202      +" is already present in QtObservedBondMap.");
     203  QtObservedBondMap[bondid] = _bond;
     204
     205  // assign to its molecule if present
     206  const moleculeId_t molid = _bond->getMoleculeIndex();
     207  if (molid != (moleculeId_t)-1) {
     208    QtObservedMolecule::ptr mol = board->getObservedMolecule(molid);
     209    emit moleculesBondInserted(_bond, mol.get());
     210  } else {
     211    // watch bond till it has a molecule
     212    connect( _bond.get(), SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),
     213        this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));
     214  }
     215}
     216
     217/** Handle change of molecule from initial none.
     218 *
     219 */
     220void GLWorldScene::bondsMoleculeChanged(moleculeId_t _oldid, moleculeId_t _newid)
     221{
     222  ASSERT( _oldid == (moleculeId_t)-1,
     223      "GLWorldScene::bondsMoleculeChanged() - got true index change from "
     224      +toString(_oldid)+" to "+toString(_newid)+" and not just added to mol.");
     225  QtObservedBond* bondref = static_cast<QtObservedBond*>(sender());
     226
     227  // disconnect from further molecule changes
     228  disconnect( bondref, SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),
     229      this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));
     230
     231  // add it to its molecule
     232  QtObservedMolecule::ptr mol = board->getObservedMolecule(_newid);
     233  emit moleculesBondInserted(bondref->getRef(), mol.get());
     234}
     235
     236
     237/** Removes an general bond.
     238 *
     239 * This is called when the bond has been removed from the molecule.
     240 *
     241 * @param _bond bond to remove
     242 */
     243void GLWorldScene::bondRemoved(ObservedValue_Index_t _bondid)
     244{
     245  const QtObservedBondMap_t::iterator eraseiter = QtObservedBondMap.find(_bondid);
     246  ASSERT( eraseiter != QtObservedBondMap.end(),
     247      "GLWorldScene::BondRemoved() - bond with id "+toString(_bondid)
     248      +" is not present in QtObservedBondMap.");
     249  QtObservedBond::ptr bondref = eraseiter->second;
     250
     251  // tell its assigned molecule if present
     252  const moleculeId_t molid = bondref->getMoleculeIndex();
     253  if (molid != (moleculeId_t)-1) {
     254    QtObservedMolecule::ptr mol = board->getObservedMolecule(molid);
     255    emit moleculesBondRemoved(_bondid, mol.get());
     256  } else {
     257    // it might have still been waiting for a molecule assignment
     258    disconnect( bondref.get(), SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),
     259        this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));
     260  }
     261  QtObservedBondMap.erase(eraseiter);
    184262}
    185263
     
    329407}
    330408
     409/** Inserts an bond into the scene when molecule is present.
     410 *
     411 * @param _bond bond to insert
     412 */
     413void GLWorldScene::moleculesBondInserted(QtObservedBond::ptr _bond, QtObservedMolecule * _mol)
     414{
     415  const ObservedValue_Index_t bondid = _bond->getIndex();
     416  LOG(3, "INFO: GLWorldScene: Received signal bondInserted for bond " << _bond->getBondIndex());
     417  const ObservedValue_Index_t molid = _mol->getIndex();
     418
     419  // check of molecule is already present
     420  boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
     421  const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
     422  if (moliter != MoleculesinSceneMap.end()) {
     423    // check that it is the right molecule
     424    QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;
     425    ASSERT( checkmol.get() == _mol,
     426        "GLWorldScene::moleculesBondInserted() - claimed and present molecule differ.");
     427    LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondInserted for bond "
     428        << _bond->getBondIndex());
     429    QMetaObject::invokeMethod(moliter->second,        // pointer to a QObject
     430                              "bondInserted",       // member name (no parameters here)
     431                              Qt::QueuedConnection,     // connection type
     432                              Q_ARG(QtObservedBond::ptr, _bond));     // parameters
     433  } else {
     434#ifndef NDEBUG
     435    const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
     436    ASSERT( removedmoliter != RemovedMolecules.end(),
     437          "GLWorldScene::moleculesBondInserted() - would need to send bondInserted to already removed molecule.");
     438#endif
     439    boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
     440    // only record missed state for molecule if (still) present but not instantiated
     441    if (QtObservedMoleculeMap.count(molid)) {
     442      // store signal for when it is instantiated
     443      if (MoleculeMissedStateMap.count(molid) == 0)
     444        MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );
     445      MoleculeMissedStateMap[molid].insert( std::make_pair(bondid, bondInsertedState) );
     446      ASSERT( QtObservedBondMap[bondid] == _bond,
     447          "GLWorldScene::moleculesBondInserted() - bond "+toString(bondid)
     448          +" inserted in molecule "+toString(_mol->getMolIndex())
     449          +" which does not match bond in QtObservedBondMap.");
     450      LOG(3, "INFO: GLWorldScene: Placing bondInserted for bond " << _bond->getBondIndex()
     451           << " and molecule " << _mol->getMolIndex() << " into missed state map.");
     452    }
     453  }
     454}
     455
     456/** Removes an bond into the scene before molecule is present.
     457 *
     458 * @param _bondid bond to remove
     459 */
     460void GLWorldScene::moleculesBondRemoved(ObservedValue_Index_t _bondid, QtObservedMolecule * _mol)
     461{
     462  LOG(3, "INFO: GLWorldScene: Received signal bondRemoved for bond "+toString(_bondid)+".");
     463
     464  const ObservedValue_Index_t molid = _mol->getIndex();
     465  // check of molecule is already present
     466  boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
     467  const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
     468  if (moliter != MoleculesinSceneMap.end()) {
     469    const QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;
     470    if (checkmol.get() == _mol) {
     471      LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondRemoved for bond "+toString(_bondid)+".");
     472      QMetaObject::invokeMethod(moliter->second,        // pointer to a QObject
     473                                "bondRemoved",       // member name (no parameters here)
     474                                Qt::QueuedConnection,     // connection type
     475                                Q_ARG(ObservedValue_Index_t, _bondid));     // parameters
     476    } else {
     477      // relay bondRemoved to GLMoleculeObject_molecule in RemovedMolecules
     478      LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondRemoved for bond "+toString(_bondid)
     479          +" to molecule in RemovedMolecules.");
     480      const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
     481      ASSERT( removedmoliter != RemovedMolecules.end(),
     482          "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
     483          +toString(molid)+", but not present in RemovedMolecules");
     484#ifndef NDEBUG
     485      const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;
     486      ASSERT( othercheckmol.get() == _mol,
     487          "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
     488          +toString(molid)+", but different one "+toString(othercheckmol)
     489          +" present in RemovedMolecules.");
     490#endif
     491      QMetaObject::invokeMethod(removedmoliter->second,        // pointer to a QObject
     492                                "bondRemoved",       // member name (no parameters here)
     493                                Qt::QueuedConnection,     // connection type
     494                                Q_ARG(ObservedValue_Index_t, _bondid));     // parameters
     495    }
     496  } else {
     497    const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);
     498    if (removedmoliter != RemovedMolecules.end()) {
     499      ASSERT( removedmoliter != RemovedMolecules.end(),
     500          "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
     501          +toString(molid)+", but not present in RemovedMolecules");
     502#ifndef NDEBUG
     503      const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;
     504      ASSERT( othercheckmol.get() == _mol,
     505          "GLWorldScene::moleculesBondRemoved() - signal from old molecule "
     506          +toString(molid)+", but different one "+toString(othercheckmol)
     507          +" present in RemovedMolecules.");
     508#endif
     509      QMetaObject::invokeMethod(removedmoliter->second,        // pointer to a QObject
     510                                "bondRemoved",       // member name (no parameters here)
     511                                Qt::QueuedConnection,     // connection type
     512                                Q_ARG(ObservedValue_Index_t, _bondid));     // parameters
     513    } else {
     514      boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
     515      // only record missed state for molecule if (still) present but not instantiated
     516      if (QtObservedMoleculeMap.count(molid)) {
     517        // store signal for when it is instantiated
     518        if (MoleculeMissedStateMap.count(molid) == 0)
     519          MoleculeMissedStateMap.insert( std::make_pair(molid, StateChangeMap_t()) );
     520        MoleculeMissedStateMap[molid].insert( std::make_pair(_bondid, bondRemovedState) );
     521        LOG(3, "INFO: GLWorldScene: Placing bondRemoved for bond " << _bondid
     522             << " and molecule " << molid << " into missed state map.");
     523      }
     524    }
     525  }
     526}
     527
    331528void GLWorldScene::moleculeSignOn(QtObservedMolecule::ptr _mol)
    332529{
     
    418615            stateiter != rangeiter.second; ++stateiter)
    419616          ++StateChangeAmounts[stateiter->second];
    420         ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
    421             "GLWorldScene::moleculeInserted() - more atomRemoved states "
    422             +toString(StateChangeAmounts[atomRemovedState])+" than atomInserted "
    423             +toString(StateChangeAmounts[atomInsertedState])+" for atom "+toString(iter->first));
    424         if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
    425           LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
    426           QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    427                                     "atomInserted",       // member name (no parameters here)
    428                                     Qt::QueuedConnection,     // connection type
    429                                     Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first]));     // parameters
    430         } else {
    431           LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
     617        // is it an atom?
     618        if ((StateChangeAmounts[atomInsertedState] + StateChangeAmounts[atomRemovedState]) != 0) {
     619          ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
     620              "GLWorldScene::moleculeInserted() - more atomRemoved states "
     621              +toString(StateChangeAmounts[atomRemovedState])+" than atomInserted "
     622              +toString(StateChangeAmounts[atomInsertedState])+" for atom "+toString(iter->first));
     623          if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
     624            LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
     625            QMetaObject::invokeMethod(molObject,        // pointer to a QObject
     626                                      "atomInserted",       // member name (no parameters here)
     627                                      Qt::QueuedConnection,     // connection type
     628                                      Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first]));     // parameters
     629          } else {
     630            LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
     631          }
    432632        }
    433         // removed all state changes for this atom
     633        // or is it a bond?
     634        if ((StateChangeAmounts[bondInsertedState] + StateChangeAmounts[bondInsertedState]) != 0) {
     635          ASSERT( StateChangeAmounts[bondInsertedState] >= StateChangeAmounts[bondRemovedState],
     636              "GLWorldScene::moleculeInserted() - more bondRemoved states "
     637              +toString(StateChangeAmounts[bondRemovedState])+" than bondInserted "
     638              +toString(StateChangeAmounts[bondInsertedState])+" for bond "+toString(iter->first));
     639          if (StateChangeAmounts[bondInsertedState] > StateChangeAmounts[bondRemovedState]) {
     640            LOG(1, "INFO: invoking bondInserted for bond " << iter->first);
     641            QMetaObject::invokeMethod(molObject,        // pointer to a QObject
     642                                      "bondInserted",       // member name (no parameters here)
     643                                      Qt::QueuedConnection,     // connection type
     644                                      Q_ARG(QtObservedBond::ptr, QtObservedBondMap[iter->first]));     // parameters
     645          } else {
     646            LOG(1, "INFO: Bond " << iter->first << " has been inserted and removed already.");
     647          }
     648        }
     649        ASSERT( (StateChangeAmounts[bondInsertedState] + StateChangeAmounts[bondInsertedState]
     650            + StateChangeAmounts[atomInsertedState] + StateChangeAmounts[atomRemovedState]) != 0,
     651            "GLWorldScene::moleculeInserted() - state with no changes for "+toString(iter->first));
     652        // removed all state changes for this atom/bond
    434653        MoleculeMissedStateMap[molid].erase(rangeiter.first, rangeiter.second);
    435654      } else {
     
    450669            break;
    451670          }
     671          case bondRemovedState:
     672            ASSERT( 0,
     673                "GLWorldScene::moleculeInserted() - bondRemoved state without bondInserted for bond "
     674                +toString(iter->first));
     675            break;
     676          case bondInsertedState:
     677          {
     678            LOG(1, "INFO: invoking bondInserted for bond " << iter->first);
     679            QMetaObject::invokeMethod(molObject,        // pointer to a QObject
     680                                      "bondInserted",       // member name (no parameters here)
     681                                      Qt::QueuedConnection,     // connection type
     682                                      Q_ARG(QtObservedBond::ptr, QtObservedBondMap[iter->first]));     // parameters
     683            break;
     684          }
    452685          default:
    453686            ASSERT( 0,
     
    455688            break;
    456689        }
    457         // removed state changes for this atom
     690        // removed state changes for this atom/bond
    458691        MoleculeMissedStateMap[molid].erase(iter);
    459692      }
Note: See TracChangeset for help on using the changeset viewer.