Ignore:
Timestamp:
Feb 12, 2016, 11:15:04 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:
2831b3
Parents:
e25448
git-author:
Frederik Heber <heber@…> (10/16/15 11:51:16)
git-committer:
Frederik Heber <heber@…> (02/12/16 23:15:04)
Message:

FIX: All ObservedValue's of GLMoleculeObject_atom/bond/molecule wrapped into vector.

  • the idea is that a GLMoleculeObject may only remove itself _after_ each and every contained Observer has gotten the subjectKilled() signal from the Observables. Only then will destroying the Object and its members thereby not cause any signOff() which try to access Observables or their channels which are no longer present. This can be imagined as a graph where we have to start destroying object at the very bottom.
  • This is the avoid the following conflict: A superior object gets note of a molecule to be removed. It sends the visual representation a signal to remove itself, which causes it to use signOff(). On a parallel track (in another thread) we have the observed object calling subjectKilled() to inform any Observer about its immediate destruction. These two tracks collide. Now, we let first pass all subjectKilled() and when the last Observable has gotten its signal, we begin destroying the visual rep.
  • rerouted signal/slots accordingly.
File:
1 edited

Legend:

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

    re25448 r7c7c4a  
    5757#include "WorldTime.hpp"
    5858
     59#include "ObservedValue_wCallback.hpp"
     60
    5961using namespace boost::assign;
    6062
     
    8082  Observer(std::string("GLMoleculeObject_atom")+toString(_id)),
    8183  atomref(getAtom(_id)),
    82   AtomIndex(
    83       atomref,
    84       boost::bind(&GLMoleculeObject_atom::updateIndex, this),
    85       "AtomIndex_"+toString(_id),
    86       _id,
    87       AtomIndexChannels),
    88   AtomPosition(
    89       atomref,
    90       boost::bind(&GLMoleculeObject_atom::updatePosition, this),
    91       "AtomPosition_"+toString(_id),
    92       updatePosition(),
    93       AtomPositionChannels),
    94   AtomElement(
    95       atomref,
    96       boost::bind(&GLMoleculeObject_atom::updateElement, this),
    97       "AtomElement"+toString(_id),
    98       updateElement(),
    99       AtomElementChannels),
    100   AtomBonds(
    101       atomref,
    102       boost::bind(&GLMoleculeObject_atom::updateBonds, this),
    103       "AtomBonds_"+toString(_id),
    104       updateBonds(),
    105       AtomBondsChannels),
     84  ObservedValues(MAX_ObservedTypes),
     85  subjectKilledCount(0),
    10686  owner(NULL)
    10787{
     88  initObservedValues(_id);
     89
    10890  setObjectId(_id);
    10991  resetPosition();
     
    154136{
    155137  deactivateObserver();
     138  destroyObservedValues();
    156139}
    157140
    158141void GLMoleculeObject_atom::resetIndex()
    159142{
    160   const atomId_t newId = AtomIndex.get();
     143  const atomId_t newId = getAtomIndex();
    161144  const size_t oldId = objectId();
    162145  ASSERT( newId != oldId,
     
    170153void GLMoleculeObject_atom::resetPosition()
    171154{
    172   const Vector Position = AtomPosition.get();
     155  const Vector Position = getAtomPosition();
    173156  LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
    174157  setPosition(QVector3D(Position[0], Position[1], Position[2]));
     
    179162  size_t elementno = 0;
    180163  const element * const _type = World::getInstance().
    181       getPeriode()->FindElement(AtomElement.get());
     164      getPeriode()->FindElement(getAtomElement());
    182165  if (_type != NULL) {
    183166    elementno = _type->getAtomicNumber();
     
    205188void GLMoleculeObject_atom::resetBonds()
    206189{
    207   ListOfBonds_t ListOfBonds_new = AtomBonds.get();
     190  ListOfBonds_t ListOfBonds_new = getAtomBonds();
    208191  std::sort(ListOfBonds_new.begin(), ListOfBonds_new.end());
    209192  ListOfBonds_t BondsToAdd;
     
    220203      iter != BondsToAdd.end();
    221204      ++iter) {
    222     const GLMoleculeObject_bond::SideOfBond side = (iter->first == AtomIndex.get()) ?
     205    const GLMoleculeObject_bond::SideOfBond side = (iter->first == getAtomIndex()) ?
    223206        GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
    224207    emit BondsAdded(iter->first, iter->second, side);
     
    259242void GLMoleculeObject_atom::wasClicked()
    260243{
    261   LOG(4, "INFO: GLMoleculeObject_atom: atom " << AtomIndex.get() << " has been clicked");
    262   emit clicked(AtomIndex.get());
     244  LOG(4, "INFO: GLMoleculeObject_atom: atom " << getAtomIndex() << " has been clicked");
     245  emit clicked(getAtomIndex());
    263246}
    264247
     
    283266Vector GLMoleculeObject_atom::updatePosition() const
    284267{
    285   const atom * const _atom = getAtom(AtomIndex.get());
     268  const atom * const _atom = getAtom(getAtomIndex());
    286269  if (_atom != NULL) {
    287270    return _atom->getPosition();
     
    293276atomicNumber_t GLMoleculeObject_atom::updateElement() const
    294277{
    295   const atom * const _atom = getAtom(AtomIndex.get());
     278  const atom * const _atom = getAtom(getAtomIndex());
    296279  if (_atom != NULL) {
    297280    return _atom->getElementNo();
     
    304287{
    305288  ListOfBonds_t ListOfBonds;
    306   const atom * const _atom = getAtom(AtomIndex.get());
     289  const atom * const _atom = getAtom(getAtomIndex());
    307290  if (_atom != NULL) {
    308291    // make sure position is up-to-date
     
    315298          (*iter)->rightatom->getId()) );
    316299  } else {
    317     ELOG(2, "Atom with id "+toString(AtomIndex.get())+" is already gone.");
     300    ELOG(2, "Atom with id "+toString(getAtomIndex())+" is already gone.");
    318301  }
    319302  return ListOfBonds;
     
    328311{
    329312  deactivateObserver();
     313
     314  countsubjectKilled();
    330315}
    331316
     
    357342    ASSERT(0, "GLMoleculeObject_atom::recieveNotification() - received notification from unexpected source.");
    358343}
     344
     345void GLMoleculeObject_atom::countsubjectKilled()
     346{
     347  ++subjectKilledCount;
     348
     349  if (subjectKilledCount > ObservedValues.size())
     350    emit InstanceRemoved(getAtomIndex());
     351}
     352
     353void GLMoleculeObject_atom::initObservedValues(const atomId_t _id)
     354{
     355  // fill ObservedValues
     356  boost::function<void()> subjectKilled =
     357      boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this);
     358  ObservedValues[AtomIndex] = new ObservedValue_wCallback<atomId_t>(
     359      atomref,
     360      boost::bind(&GLMoleculeObject_atom::updateIndex, this),
     361      "AtomIndex_"+toString(_id),
     362      _id,
     363      AtomIndexChannels,
     364      subjectKilled);
     365  ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector>(
     366      atomref,
     367      boost::bind(&GLMoleculeObject_atom::updatePosition, this),
     368      "AtomPosition_"+toString(_id),
     369      updatePosition(),
     370      AtomPositionChannels,
     371      subjectKilled);
     372  ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t>(
     373      atomref,
     374      boost::bind(&GLMoleculeObject_atom::updateElement, this),
     375      "AtomElement"+toString(_id),
     376      updateElement(),
     377      AtomElementChannels,
     378      subjectKilled);
     379  ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t>(
     380      atomref,
     381      boost::bind(&GLMoleculeObject_atom::updateBonds, this),
     382      "AtomBonds_"+toString(_id),
     383      updateBonds(),
     384      AtomBondsChannels,
     385      subjectKilled);
     386}
     387
     388void GLMoleculeObject_atom::destroyObservedValues()
     389{
     390  delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex]);
     391  delete boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[AtomPosition]);
     392  delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[AtomElement]);
     393  delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(ObservedValues[AtomBonds]);
     394  ObservedValues.clear();
     395}
     396
     397atomId_t GLMoleculeObject_atom::getAtomIndex() const
     398{
     399  return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex])->get();
     400}
     401
     402Vector GLMoleculeObject_atom::getAtomPosition() const
     403{
     404  return boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[AtomPosition])->get();
     405}
     406
     407atomicNumber_t GLMoleculeObject_atom::getAtomElement() const
     408{
     409  return boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[AtomElement])->get();
     410}
     411
     412GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::getAtomBonds() const
     413{
     414  return boost::any_cast<ObservedValue_wCallback<ListOfBonds_t> *>(ObservedValues[AtomBonds])->get();
     415}
Note: See TracChangeset for help on using the changeset viewer.