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

    re25448 r7c7c4a  
    6363#include "Atom/TesselPoint.hpp"
    6464#include "World.hpp"
     65
     66#include "ObservedValue_wCallback.hpp"
    6567
    6668using namespace boost::assign;
     
    122124      boost::bind(&GLMoleculeObject_molecule::updateAtoms, this)
    123125      ),
    124   MolIndex(
    125       molref,
    126       MolIndexUpdater,
    127       "MoleculeIndex_"+toString(_molid),
    128       _molid,
    129       IndexChannels),
    130   MolName(
    131       molref,
    132       MolNameUpdater,
    133       "MoleculeName_"+toString(_molid),
    134       updateName(),
    135       NameChannels),
     126  ObservedValues(MAX_ObservedTypes),
     127  subjectKilledCount(0),
    136128  TesselationHull(
    137129      molref,
     
    139131      "MoleculeTesselationHull_"+toString(_molid),
    140132      HullChannels),
    141   BoundingBox(
    142       molref,
    143       BoundingBoxUpdater,
    144       "MoleculeBoundingBox_"+toString(_molid),
    145       initBoundingBox(),
    146       BoundingBoxChannels),
    147   PresentAtoms(
    148       molref,
    149       PresentAtomsUpdater,
    150       "MoleculeAtoms_"+toString(_molid),
    151       updateAtoms(),
    152       AtomsChannels),
    153133  hoverAtomId(-1)
    154134{
     135  initObservedValues(_molid);
     136
    155137  setObjectId(_molid);
    156138  setMaterial(getMaterial(1));
     
    199181      boost::bind(&GLMoleculeObject_molecule::updateAtoms, this)
    200182      ),
    201   MolIndex(
    202       molref,
    203       MolIndexUpdater,
    204       "MoleculeIndex_"+toString(_molid),
    205       _molid,
    206       IndexChannels),
    207   MolName(
    208       molref,
    209       MolNameUpdater,
    210       "MoleculeName_"+toString(_molid),
    211       updateName(),
    212       NameChannels),
     183  ObservedValues(MAX_ObservedTypes),
     184  subjectKilledCount(0),
    213185  TesselationHull(
    214186      molref,
     
    216188      "MoleculeTesselationHull_"+toString(_molid),
    217189      HullChannels),
    218   BoundingBox(
    219       molref,
    220       BoundingBoxUpdater,
    221       "MoleculeBoundingBox_"+toString(_molid),
    222       initBoundingBox(),
    223       BoundingBoxChannels),
    224   PresentAtoms(
    225       molref,
    226       PresentAtomsUpdater,
    227       "MoleculeAtoms_"+toString(_molid),
    228       atoms_t(),
    229       AtomsChannels),
    230190  hoverAtomId(-1)
    231191{
     192  initObservedValues(_molid);
     193
    232194  setObjectId(_molid);
    233195  setMaterial(getMaterial(1));
     
    254216{
    255217  deactivateObserver();
     218  destroyObservedValues();
    256219}
    257220
     
    270233{
    271234  // sign on as observer (obtain non-const instance before)
    272   const molecule * const _molecule = getMolecule(MolIndex.get());
     235  const molecule * const _molecule = getMolecule(getMolIndex());
    273236  if (_molecule != NULL) {
    274237    owner = static_cast<const Observable *>(_molecule);
     
    278241    owner->signOn(this, molecule::IndexChanged);
    279242  } else {
    280     ELOG(1, "GLMoleculeObject_molecule() - added null object for not present mol id " << MolIndex.get());
     243    ELOG(1, "GLMoleculeObject_molecule() - added null object for not present mol id " << getMolIndex());
    281244  }
    282245
     
    332295  QGeometryData geo;
    333296
    334   const molecule * const molref = getMolecule(MolIndex.get());
     297  const molecule * const molref = getMolecule(getMolIndex());
    335298  if (molref == NULL) {
    336     ELOG(1, "Could not createMoleculeMesh, molecule with id " << MolIndex.get() << " already gone.");
     299    ELOG(1, "Could not createMoleculeMesh, molecule with id " << getMolIndex() << " already gone.");
    337300    return geo;
    338301  }
     
    353316
    354317  // we need at least three points for tesselation
    355   if (PresentAtoms.get().size() >= 3) {
     318  if (getPresentAtoms().size() >= 3) {
    356319    // Tesselate the points.
    357320    Tesselation T;
    358     PointCloudAdaptor<molecule> cloud(const_cast<molecule *>(molref), MolName.get());
     321    PointCloudAdaptor<molecule> cloud(const_cast<molecule *>(molref), getMolName());
    359322    T(cloud, minradius);
    360323
     
    413376molecule::BoundingBoxInfo GLMoleculeObject_molecule::updateBoundingBox() const
    414377{
    415   return BoundingBox.get();
     378  return getBoundingBox();
    416379}
    417380
    418381GLMoleculeObject_molecule::atoms_t GLMoleculeObject_molecule::updateAtoms()
    419382{
    420   const molecule * const mol = getMolecule(MolIndex.get());
     383  const molecule * const mol = getMolecule(getMolIndex());
    421384  if (mol != NULL) {
    422385    const atomId_t id = mol->lastChangedAtomId();
     
    436399std::string GLMoleculeObject_molecule::updateName() const
    437400{
    438   const molecule * const mol = getMolecule(MolIndex.get());
     401  const molecule * const mol = getMolecule(getMolIndex());
    439402  return mol->getName();
    440403}
     
    448411void GLMoleculeObject_molecule::resetBoundingBox()
    449412{
    450   molecule::BoundingBoxInfo info = BoundingBox.get();
     413  molecule::BoundingBoxInfo info = getBoundingBox();
    451414  setPosition(QVector3D(info.position[0], info.position[1], info.position[2]));
    452415  setScale(info.radius + 0.3); // getBoundingSphere() only sees atoms as points, so make the box a bit bigger
     
    455418void GLMoleculeObject_molecule::resetAtoms()
    456419{
    457   const atoms_t atoms = PresentAtoms.get();
     420  const atoms_t atoms = getPresentAtoms();
    458421  std::vector<atomId_t> InsertedAtoms;
    459422  std::vector<atomId_t> RemovedAtoms;
     
    479442void GLMoleculeObject_molecule::resetIndex()
    480443{
    481   const atomId_t newId = MolIndex.get();
     444  const atomId_t newId = getMolIndex();
    482445  const size_t oldId = objectId();
    483446  ASSERT( newId != oldId,
     
    544507  // remove owner: no more signOff needed
    545508  owner = NULL;
     509
     510  countsubjectKilled();
    546511}
    547512
    548513void GLMoleculeObject_molecule::recieveNotification(Observable *publisher, Notification_ptr notification)
    549514{
    550   const molecule * const _molecule = getMolecule(MolIndex.get());
     515  const molecule * const _molecule = getMolecule(getMolIndex());
    551516  // when molecule is NULL we will soon get destroyed anyway
    552517  if (_molecule == NULL)
     
    556521#ifdef LOG_OBSERVER
    557522    observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
    558           << " received notification from molecule " << MolIndex.get() << " for channel "
     523          << " received notification from molecule " << getMolIndex() << " for channel "
    559524          << notification->getChannelNo() << ".";
    560525#endif
     
    577542        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been removed.";
    578543  #endif
    579         emit AtomRemoved(_id);
    580544        emit TesselationHullChanged();
    581545        emit BoundingBoxChanged();
     
    719683  connect (atomObject, SIGNAL(BondsRemoved(const atomId_t, const atomId_t)), this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
    720684  connect (atomObject, SIGNAL(indexChanged(GLMoleculeObject_atom*, const atomId_t, const atomId_t)), this, SLOT(changeAtomId(GLMoleculeObject_atom*, const atomId_t, const atomId_t)));
     685  connect (atomObject, SIGNAL(InstanceRemoved(const atomId_t)), this, SIGNAL(AtomRemoved(const atomId_t)));
    721686
    722687  if (m_objectId  == -1)
     
    773738    if (moleculeObject == this){
    774739      // Propagate signal.
    775       emit hoverChanged(MolIndex.get(), 0);
     740      emit hoverChanged(getMolIndex(), 0);
    776741    }
    777742  }
     
    871836void GLMoleculeObject_molecule::wasClicked()
    872837{
    873   LOG(4, "INFO: GLMoleculeObject_molecule: atom " << MolIndex.get() << " has been clicked");
    874   emit moleculeClicked(MolIndex.get());
     838  LOG(4, "INFO: GLMoleculeObject_molecule: atom " << getMolIndex() << " has been clicked");
     839  emit moleculeClicked(getMolIndex());
    875840}
    876841
     
    906871  return mol;
    907872}
     873
     874void GLMoleculeObject_molecule::countsubjectKilled()
     875{
     876  ++subjectKilledCount;
     877
     878  if (subjectKilledCount > ObservedValues.size())
     879    emit InstanceRemoved(getMolIndex());
     880}
     881
     882void GLMoleculeObject_molecule::initObservedValues(const moleculeId_t _molid)
     883{
     884  // fill ObservedValues
     885  boost::function<void()> subjectKilled =
     886      boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this);
     887  ObservedValues[MolIndex] = new ObservedValue_wCallback<moleculeId_t>(
     888      molref,
     889      MolIndexUpdater,
     890      "MoleculeIndex_"+toString(_molid),
     891      _molid,
     892      IndexChannels,
     893      subjectKilled);
     894  ObservedValues[MolName] = new ObservedValue_wCallback<std::string>(
     895      molref,
     896      MolNameUpdater,
     897      "MoleculeName_"+toString(_molid),
     898      updateName(),
     899      NameChannels,
     900      subjectKilled);
     901  ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo>(
     902      molref,
     903      BoundingBoxUpdater,
     904      "MoleculeBoundingBox_"+toString(_molid),
     905      initBoundingBox(),
     906      BoundingBoxChannels,
     907      subjectKilled);
     908  ObservedValues[PresentAtoms] = new ObservedValue_wCallback<atoms_t>(
     909      molref,
     910      PresentAtomsUpdater,
     911      "MoleculeAtoms_"+toString(_molid),
     912      updateAtoms(),
     913      AtomsChannels,
     914      subjectKilled);
     915}
     916
     917void GLMoleculeObject_molecule::destroyObservedValues()
     918{
     919  delete boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(ObservedValues[MolIndex]);
     920  delete boost::any_cast<ObservedValue_wCallback<std::string> *>(ObservedValues[MolName]);
     921  delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo> *>(ObservedValues[BoundingBox]);
     922  delete boost::any_cast<ObservedValue_wCallback<atoms_t> *>(ObservedValues[PresentAtoms]);
     923  ObservedValues.clear();
     924}
     925
     926moleculeId_t GLMoleculeObject_molecule::getMolIndex() const
     927{
     928  return boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(ObservedValues[MolIndex])->get();
     929}
     930
     931std::string GLMoleculeObject_molecule::getMolName() const
     932{
     933  return boost::any_cast<ObservedValue_wCallback<std::string> *>(ObservedValues[MolName])->get();
     934}
     935
     936molecule::BoundingBoxInfo GLMoleculeObject_molecule::getBoundingBox() const
     937{
     938  return boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo> *>(ObservedValues[BoundingBox])->get();
     939}
     940
     941GLMoleculeObject_molecule::atoms_t GLMoleculeObject_molecule::getPresentAtoms() const
     942{
     943  return boost::any_cast<ObservedValue_wCallback<atoms_t> *>(ObservedValues[PresentAtoms])->get();
     944}
Note: See TracChangeset for help on using the changeset viewer.