Changeset 04c3a3 for src/UIElements


Ignore:
Timestamp:
Feb 14, 2016, 12:33:42 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:
4e6ffe
Parents:
b2c2e4
git-author:
Frederik Heber <heber@…> (01/25/16 14:15:23)
git-committer:
Frederik Heber <heber@…> (02/14/16 12:33:42)
Message:

QtObservedAtom, ..Molecule, and ObservedValue_wCallback have flag to indicate invalid callback.

  • due to Qt's signal/slot destruction, which follows no proper order, we need to invalidate callback when their owners are destroyed. Each has a note-function() that flips the boolean to show the callbacks invalidity.
  • TODO: So far this is not nice, especially w.r.t to ObservedValue_wCallback because of templatization. We cannot place them in a loop and this makes this very error-prone once more Values are added ...
Location:
src/UIElements/Qt4/InstanceBoard
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/InstanceBoard/ObservedValue_wCallback.hpp

    rb2c2e4 r04c3a3  
    4343        signedOnChannels(std::max((size_t)1,_channels.size())),
    4444        callback(_callback),
     45        CallbackIsGone(false),
    4546        getId(_getId)
    4647  {}
     
    4849  {}
    4950
     51  /** Function is called by callback owner to inform about its destruction.
     52   *
     53   * \note callback must not be used after this
     54   */
     55  void noteCallBackIsGone()
     56  { CallbackIsGone = true; }
     57
    5058protected:
    5159  virtual void subjectKilled(Observable *publisher)
    5260  {
    53     ObservedValue<T>::subjectKilled(publisher);
    5461    ASSERT(signedOnChannels > 0,
    5562        "ObservedValue_wCallback::subjectKilled() - signedOnChannels is already zero.");
    56     if ((--signedOnChannels) == 0)
    57       callback(getId());
     63    if ((--signedOnChannels) == 0) {
     64      ObservedValue<T>::subjectKilled(publisher);
     65      if (!CallbackIsGone)
     66        callback(getId());
     67    }
    5868  }
    5969
     
    6373  //!> callback function to tell other entity about subjectKilled
    6474  const boost::function<void(const id)> callback;
     75  //!> is callback still alive or not
     76  bool CallbackIsGone;
     77  //!> callback function to get id
    6578  const boost::function<const id()> getId;
    6679};
     
    94107        signedOnChannels(std::max((size_t)1,_channels.size())),
    95108        callback(_callback),
     109        CallbackIsGone(false),
    96110        getId(_getId)
    97111  {}
     
    106120        signedOnChannels(std::max((size_t)1,_channels.size())),
    107121        callback(_callback),
     122        CallbackIsGone(false),
    108123        getId(boost::bind(&ObservedValue<T>::get, this))
    109124  {}
    110125  virtual ~ObservedValue_wCallback()
    111126  {}
     127
     128  /** Function is called by callback owner to inform about its destruction.
     129   *
     130   * \note callback must not be used after this
     131   */
     132  void noteCallBackIsGone()
     133  { CallbackIsGone = true; }
    112134
    113135protected:
     
    118140        "ObservedValue_wCallback::subjectKilled() - signedOnChannels is already zero.");
    119141    if ((--signedOnChannels) == 0)
    120       callback(getId());
     142      ObservedValue<T>::subjectKilled(publisher);
     143      if (!CallbackIsGone)
     144        callback(getId());
    121145  }
    122146
     
    126150  //!> callback function to tell other entity about subjectKilled
    127151  const boost::function<void(const T)> callback;
     152  //!> is callback still alive or not
     153  bool CallbackIsGone;
     154  //!> callback function to get id
    128155  const boost::function<const T()> getId;
    129156};
  • src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp

    rb2c2e4 r04c3a3  
    4848      QtObservedInstanceBoard &_board,
    4949      const onDestroy_t _onDestroy);
     50
     51  /** Destor of class ObservedValuesContainer.
     52   *
     53   */
     54  ~ObservedValuesContainer();
    5055
    5156  /** Delivers the set of Observed value for the instance identified by \a _id.
  • src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp

    rb2c2e4 r04c3a3  
    2828  onDestroy(_onDestroy)
    2929{}
     30
     31template <class T, typename id>
     32ObservedValuesContainer<T,id>::~ObservedValuesContainer()
     33{
     34  for (typename CountedObservedValues_t::iterator iter = ObservedValues.begin();
     35      iter != ObservedValues.end(); ++iter)
     36    iter->second.first->noteBoardIsGone();
     37}
    3038
    3139template <class T, typename id>
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.cpp

    rb2c2e4 r04c3a3  
    9898  owner(NULL),
    9999  board(_board),
     100  BoardIsGone(false),
    100101  ObservedValues(_ObservedValues)
    101102{
     
    105106QtObservedAtom::~QtObservedAtom()
    106107{
     108  boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex])->noteCallBackIsGone();
     109  boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, atomId_t> *>(ObservedValues[AtomBonds])->noteCallBackIsGone();
     110  boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(ObservedValues[AtomElement])->noteCallBackIsGone();
     111  boost::any_cast<ObservedValue_wCallback<moleculeId_t, atomId_t> *>(ObservedValues[AtomMoleculeIndex])->noteCallBackIsGone();
     112  boost::any_cast<ObservedValue_wCallback<std::string, atomId_t> *>(ObservedValues[AtomName])->noteCallBackIsGone();
     113  boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(ObservedValues[AtomPosition])->noteCallBackIsGone();
     114
    107115  deactivateObserver();
    108116}
     
    201209    owner = NULL;
    202210
    203     board.markObservedAtomAsDisconnected(getAtomIndex());
     211    if (!BoardIsGone)
     212      board.markObservedAtomAsDisconnected(getAtomIndex());
    204213
    205214    emit atomRemoved();
     
    246255        iter != channels.end(); ++iter)
    247256      owner->signOn(this, *iter);
     257    if (!BoardIsGone)
     258      board.markObservedAtomAsConnected(getAtomIndex());
    248259  } else
    249     signedOffChannels = getAllObservedChannels().size();
     260    signedOffChannels = AllsignedOnChannels;
    250261}
    251262
     
    260271    owner = NULL;
    261272    signedOffChannels = AllsignedOnChannels;
    262     board.markObservedAtomAsDisconnected(getAtomIndex());
     273    if (!BoardIsGone)
     274      board.markObservedAtomAsDisconnected(getAtomIndex());
    263275  }
    264276}
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp

    rb2c2e4 r04c3a3  
    191191      std::vector<boost::any> &_ObservedValues);
    192192
     193  /** Function is called by InstanceBoard to inform about its destruction.
     194   *
     195   * \note callbacks must not be used after this
     196   */
     197  void noteBoardIsGone()
     198  { BoardIsGone = true; }
     199
    193200  //!> counts how many ObservedValues have already been subjectKilled()
    194201  mutable size_t subjectKilledCount;
     
    221228  QtObservedInstanceBoard & board;
    222229
     230  //!> is board still alive or not, impacts callbacks
     231  bool BoardIsGone;
     232
    223233  //!> internal reference to ObservedValues held by QtObservedInstanceBoard
    224234  ObservedValues_t ObservedValues;
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    rb2c2e4 r04c3a3  
    3535
    3636#include "QtObservedInstanceBoard.hpp"
     37
     38#include <QtCore/QMetaType>
    3739
    3840#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
     
    7678  lastremovedmolecule((moleculeId_t)-1)
    7779{
     80  qRegisterMetaType<QtObservedAtom::ptr>("QtObservedAtom::ptr");
     81  qRegisterMetaType<QtObservedMolecule::ptr>("QtObservedMolecule::ptr");
     82
    7883  // be first (besides ObservedValues to know about new insertions)
    7984  World::getInstance().signOn(this, World::AtomInserted, GlobalObservableInfo::PriorityLevel(int(-10)));
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.cpp

    rb2c2e4 r04c3a3  
    108108  owner(NULL),
    109109  board(_board),
     110  BoardIsGone(false),
    110111  ObservedValues(_ObservedValues)
    111112{
     
    115116QtObservedMolecule::~QtObservedMolecule()
    116117{
     118  boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(ObservedValues[MolIndex])->noteCallBackIsGone();
     119  boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(ObservedValues[AtomCount])->noteCallBackIsGone();
     120  boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(ObservedValues[BondCount])->noteCallBackIsGone();
     121  boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(ObservedValues[BoundingBox])->noteCallBackIsGone();
     122  boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[FormulaString])->noteCallBackIsGone();
     123  boost::any_cast<ObservedValue_wCallback<Vector, moleculeId_t> *>(ObservedValues[MolCenter])->noteCallBackIsGone();
     124  boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[MolName])->noteCallBackIsGone();
     125  boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(ObservedValues[NonHydrogenCount])->noteCallBackIsGone();
     126
    117127  deactivateObserver();
    118128}
     
    127137    owner = NULL;
    128138    signedOffChannels = AllsignedOnChannels;
    129     board.markObservedMoleculeAsDisconnected(getMolIndex());
     139    if (!BoardIsGone)
     140      board.markObservedMoleculeAsDisconnected(getMolIndex());
    130141  }
    131142}
     
    141152        iter != channels.end(); ++iter)
    142153      owner->signOn(this, *iter);
     154    if (!BoardIsGone)
     155      board.markObservedMoleculeAsConnected(getMolIndex());
    143156  } else
    144157    signedOffChannels = AllsignedOnChannels;
     
    159172    owner = NULL;
    160173
    161     board.markObservedMoleculeAsDisconnected(getMolIndex());
     174    if (!BoardIsGone)
     175      board.markObservedMoleculeAsDisconnected(getMolIndex());
    162176
    163177    emit moleculeRemoved();
     
    376390  delete boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(_ObservedValues[AtomCount]);
    377391  delete boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(_ObservedValues[BondCount]);
     392  delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(_ObservedValues[BoundingBox]);
    378393  delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[FormulaString]);
    379394  delete boost::any_cast<ObservedValue_wCallback<Vector, moleculeId_t> *>(_ObservedValues[MolCenter]);
    380   delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(_ObservedValues[BoundingBox]);
    381395  delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[MolName]);
    382396  delete boost::any_cast<ObservedValue_wCallback<int, moleculeId_t> *>(_ObservedValues[NonHydrogenCount]);
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp

    rb2c2e4 r04c3a3  
    188188  //!> enumeration of observed values to match with entries in ObservedValues
    189189  enum ObservedTypes {
     190    //!> contains the current molecule index
     191    MolIndex,
    190192    //!> contains the current molecule's atom count
    191193    AtomCount,
     
    198200    //!> contains the current molecule's center
    199201    MolCenter,
    200     //!> contains the current molecule index
    201     MolIndex,
    202202    //!> contains the current molecule name
    203203    MolName,
     
    228228      std::vector<boost::any> &_ObservedValues);
    229229
     230  /** Function is called by InstanceBoard to inform about its destruction.
     231   *
     232   * \note callbacks must not be used after this
     233   */
     234  void noteBoardIsGone()
     235  { BoardIsGone = true; }
     236
    230237  //!> counts how many ObservedValues have already been subjectKilled()
    231238  mutable size_t subjectKilledCount;
     
    245252  QtObservedInstanceBoard & board;
    246253
     254  //!> is board still alive or not, impacts callbacks
     255  bool BoardIsGone;
     256
    247257  //!> internal reference to ObservedValues held by QtObservedInstanceBoard
    248258  ObservedValues_t ObservedValues;
Note: See TracChangeset for help on using the changeset viewer.