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_bond.cpp

    re25448 r7c7c4a  
    5757#include "World.hpp"
    5858
     59#include "ObservedValue_wCallback.hpp"
     60
    5961
    6062// static entities
     
    8284  bondowner(getAtom(leftatomId)->getBond(getAtom(rightatomId)).get()),
    8385  BondSide(side),
    84   leftPosition(
    85       leftowner,
    86       boost::bind(&GLMoleculeObject_bond::updateLeftPosition, this),
    87       "BondleftPosition_"+toString(leftatomId),
    88       updateLeftPosition(),
    89       BondPositionChannels),
    90   rightPosition(
    91       rightowner,
    92       boost::bind(&GLMoleculeObject_bond::updateRightPosition, this),
    93       "BondrightPosition_"+toString(rightatomId),
    94       updateRightPosition(),
    95       BondPositionChannels),
    96   leftElement(
    97       leftowner,
    98       boost::bind(&GLMoleculeObject_bond::updateLeftElement, this),
    99       "BondleftElement"+toString(leftatomId),
    100       updateLeftElement(),
    101       BondElementChannels),
    102   rightElement(
    103       rightowner,
    104       boost::bind(&GLMoleculeObject_bond::updateRightElement, this),
    105       "BondrightElement"+toString(rightatomId),
    106       updateRightElement(),
    107       BondElementChannels),
    108   Degree(
    109       bondowner,
    110       boost::bind(&GLMoleculeObject_bond::updateDegree, this),
    111       "BondDegree"+toString(leftatomId)+"_"+toString(rightatomId),
    112       updateDegree(),
    113       BondDegreeChannels),
     86  ObservedValues(MAX_ObservedTypes),
     87  subjectKilledCount(0),
    11488  leftobservable_enabled(false),
    11589  rightobservable_enabled(false)
    11690{
     91  initObservedValues();
     92
    11793  // sign on as observer (obtain non-const instance before)
    11894  bondowner->signOn(this, BondObservable::BondRemoved);
     
    141117  // signOff() if not already done
    142118  removeChannels();
     119  destroyObservedValues();
    143120}
    144121
     
    170147}
    171148
    172 void GLMoleculeObject_bond::removeMe()
    173 {
    174   // sign off
    175   emit BondRemoved(leftatomId, rightatomId);
    176 }
    177 
    178149void GLMoleculeObject_bond::update(Observable *publisher)
    179150{
     
    185156  // we signOff from all other sources
    186157  removeChannels();
    187   // then indicate to remove us
    188   removeMe();
     158  // check whether we should be removed
     159  countsubjectKilled();
    189160}
    190161
     
    278249void GLMoleculeObject_bond::resetElement()
    279250{
    280   size_t elementno = rightElement.get();
     251  size_t elementno = getrightElement();
    281252  QGLMaterial *elementmaterial = getMaterial(elementno);
    282253  setMaterial(elementmaterial);
     
    285256void GLMoleculeObject_bond::resetWidth()
    286257{
    287   const double factor = 1.0f+.5f*(Degree.get()-1);
     258  const double factor = 1.0f+.5f*(getDegree()-1);
    288259  LOG(2, "DEBUG: GLMoleculeObject_bond::resetWidth() - setting bond's width to " << factor << ".");
    289260  setScaleX(factor);
     
    295266void GLMoleculeObject_bond::resetPosition()
    296267{
    297   Vector Position = leftPosition.get();
    298   Vector OtherPosition = rightPosition.get();
     268  Vector Position = getleftPosition();
     269  Vector OtherPosition = getrightPosition();
    299270  const double distance =
    300271      Position.distance(OtherPosition)/2.;
     
    346317  return _atom;
    347318}
     319
     320void GLMoleculeObject_bond::countsubjectKilled()
     321{
     322  ++subjectKilledCount;
     323
     324  if (subjectKilledCount > ObservedValues.size())
     325    emit BondRemoved(leftatomId, rightatomId);
     326}
     327
     328void GLMoleculeObject_bond::initObservedValues()
     329{
     330  // fill ObservedValues
     331  boost::function<void()> subjectKilled =
     332      boost::bind(&GLMoleculeObject_bond::countsubjectKilled, this);
     333  ObservedValues[leftPosition] = new ObservedValue_wCallback<Vector>(
     334      leftowner,
     335      boost::bind(&GLMoleculeObject_bond::updateLeftPosition, this),
     336      "BondleftPosition_"+toString(leftatomId),
     337      updateLeftPosition(),
     338      BondPositionChannels,
     339      subjectKilled);
     340  ObservedValues[rightPosition] = new ObservedValue_wCallback<Vector>(
     341      rightowner,
     342      boost::bind(&GLMoleculeObject_bond::updateRightPosition, this),
     343      "BondrightPosition_"+toString(rightatomId),
     344      updateRightPosition(),
     345      BondPositionChannels,
     346      subjectKilled);
     347  ObservedValues[leftElement] = new ObservedValue_wCallback<atomicNumber_t>(
     348      leftowner,
     349      boost::bind(&GLMoleculeObject_bond::updateLeftElement, this),
     350      "BondleftElement"+toString(leftatomId),
     351      updateLeftElement(),
     352      BondElementChannels,
     353      subjectKilled);
     354  ObservedValues[rightElement] = new ObservedValue_wCallback<atomicNumber_t>(
     355      rightowner,
     356      boost::bind(&GLMoleculeObject_bond::updateRightElement, this),
     357      "BondrightElement"+toString(rightatomId),
     358      updateRightElement(),
     359      BondElementChannels,
     360      subjectKilled);
     361  ObservedValues[Degree] = new ObservedValue_wCallback<int>(
     362      bondowner,
     363      boost::bind(&GLMoleculeObject_bond::updateDegree, this),
     364      "BondDegree"+toString(leftatomId)+"_"+toString(rightatomId),
     365      updateDegree(),
     366      BondDegreeChannels,
     367      subjectKilled);
     368}
     369
     370void GLMoleculeObject_bond::destroyObservedValues()
     371{
     372  delete boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[leftPosition]);
     373  delete boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[rightPosition]);
     374  delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[leftElement]);
     375  delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[rightElement]);
     376  delete boost::any_cast<ObservedValue_wCallback<int> *>(ObservedValues[Degree]);
     377  ObservedValues.clear();
     378}
     379
     380Vector GLMoleculeObject_bond::getleftPosition() const
     381{
     382  return boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[leftPosition])->get();
     383}
     384
     385Vector GLMoleculeObject_bond::getrightPosition() const
     386{
     387  return boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[rightPosition])->get();
     388}
     389
     390atomicNumber_t GLMoleculeObject_bond::getleftElement() const
     391{
     392  return boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[leftElement])->get();
     393}
     394
     395atomicNumber_t GLMoleculeObject_bond::getrightElement() const
     396{
     397  return boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[rightElement])->get();
     398}
     399
     400int GLMoleculeObject_bond::getDegree() const
     401{
     402  return boost::any_cast<ObservedValue_wCallback<int> *>(ObservedValues[Degree])->get();
     403}
Note: See TracChangeset for help on using the changeset viewer.