Changeset 62a0ee for src/UIElements


Ignore:
Timestamp:
Feb 14, 2016, 12:34:29 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:
1c0961
Parents:
1b07b1
git-author:
Frederik Heber <heber@…> (01/07/16 10:28:10)
git-committer:
Frederik Heber <heber@…> (02/14/16 12:34:29)
Message:

QtObserved... now count the subjectKilled() from the containes values.

Location:
src/UIElements/Qt4/InstanceBoard
Files:
8 edited

Legend:

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

    r1b07b1 r62a0ee  
    7474  void markObservedValuesAsDisconnected(const id _id);
    7575
    76   /** Inform this container that subjectKilled() was received by one of the ObservedValues.
    77    *
    78    * \param _id identifier of the receiving instance
    79    */
    80   void countsubjectKilled(const id _id);
    81 
    8276  /** Prepares removeal a vector of observed values of an instance  identified by \a _id.
    8377   *
     
    195189  CountedObservedValues_t ObservedValues;
    196190
    197   //!> typedef for map with subjectKilledCounts for each instance
    198   typedef std::map<id, size_t> subjectKilledCount_t;
    199 
    200   //!> counts how many ObservedValues have already been subjectKilled()
    201   subjectKilledCount_t subjectKilledCount;
    202 
    203191  //!> typedef for the set with ids to be erase
    204192  typedef std::set<id> MarkedForErase_t;
     
    228216  bool checkRefCount(const id _id) const;
    229217
    230   /** Internal function to check whether any ObservedValue identified by
    231    * \a _id is still signOn() to its associated World instance.
    232    *
    233    * \param _id identifier of instance
    234    * \return true - no more signOn()s, false - else
    235    */
    236   bool checksubjectKilled(const id _id) const;
    237 
    238218  /** Internal function to check whether the vector of ObservedValue's
    239219   *  identified by \a _id has been marked for erase.
  • src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp

    r1b07b1 r62a0ee  
    5353void ObservedValuesContainer<T,id>::checkRemoval(const id _id)
    5454{
    55   if (checkRefCount(_id) && checksubjectKilled(_id) && checkMarkedForErase(_id))
     55  if (checkRefCount(_id) && checkMarkedForErase(_id))
    5656    removeObservedValues(_id);
    5757}
     
    113113
    114114template <class T, typename id>
    115 #ifdef HAVE_INLINE
    116 inline
    117 #endif
    118 bool ObservedValuesContainer<T,id>::checksubjectKilled(
    119     const id _id) const
    120 {
    121   boost::recursive_mutex::scoped_lock lock(atomic_mutex);
    122   typename subjectKilledCount_t::const_iterator iter = subjectKilledCount.find(_id);
    123   return ((iter != subjectKilledCount.end()) && (iter->second == T::MAX_ObservedTypes));
    124 }
    125 
    126 template <class T, typename id>
    127 void ObservedValuesContainer<T,id>::countsubjectKilled(const id _id)
    128 {
    129   boost::recursive_mutex::scoped_lock lock(atomic_mutex);
    130   LOG(3, "DEBUG: ObservedValuesContainer got subjectKilled() for an observed value of "
    131       << NameOfType << " " << _id);
    132   typename subjectKilledCount_t::iterator iter = subjectKilledCount.find(_id);
    133   if (iter == subjectKilledCount.end()) {
    134     std::pair<typename subjectKilledCount_t::iterator, bool> inserter =
    135         subjectKilledCount.insert( std::make_pair(_id, 0) );
    136     iter = inserter.first;
    137   }
    138   ASSERT (iter->second < T::MAX_ObservedTypes,
    139       "ObservedValuesContainer<T,id>::countsubjectKilled() - all subjectKilled() for "
    140       +NameOfType+" "+toString(_id)+" for each observed channel came in already.");
    141   ++(iter->second);
    142 
    143   checkRemoval(_id);
    144 }
    145 
    146 template <class T, typename id>
    147115void ObservedValuesContainer<T,id>::removeObservedValues(const id _id)
    148116{
     
    151119  // call callback function
    152120  onDestroy(_id);
    153   subjectKilledCount.erase(_id);
    154121  typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);
    155122  iter->second.eraseCurrentValue();
     
    213180  const typename CountedObservedValues_t::iterator Colditer = ObservedValues.find(_oldid);
    214181  const typename CountedObservedValues_t::iterator Cnewiter = ObservedValues.find(_newid);
    215   const typename subjectKilledCount_t::iterator Solditer = subjectKilledCount.find(_oldid);
    216   const typename subjectKilledCount_t::iterator Snewiter = subjectKilledCount.find(_newid);
    217182  const typename MarkedForErase_t::iterator Eolditer = MarkedForErase.find(_oldid);
    218183  const typename MarkedForErase_t::iterator Enewiter = MarkedForErase.find(_newid);
    219184  bool status = ((Colditer != ObservedValues.end()) && (Cnewiter == ObservedValues.end()));
    220   status &= ((Solditer != subjectKilledCount.end()) && (Snewiter == subjectKilledCount.end()));
    221185  status &= ((Eolditer != MarkedForErase.end()) && (Enewiter == MarkedForErase.end()));
    222186  // change id here only if still present
     
    233197    }
    234198    {
    235       const size_t countvalue = Solditer->second;
    236       subjectKilledCount.erase(Solditer);
    237       subjectKilledCount.insert( std::make_pair(_newid, countvalue) );
    238     }
    239     {
    240199      MarkedForErase.erase(Eolditer);
    241200      MarkedForErase.insert(_newid);
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.cpp

    r1b07b1 r62a0ee  
    9191
    9292QtObservedAtom::QtObservedAtom(
    93     const ObservedValues_t &_ObservedValues,
     93    const atomId_t _id,
     94    const atom * const _atom,
    9495    QtObservedInstanceBoard &_board,
    9596    QWidget * _parent) :
     
    102103  board(_board),
    103104  BoardIsGone(false),
    104   ObservedValues(_ObservedValues)
    105 {
    106   // activating Observer is done by ObservedValueContainer when it's prepared
     105  ObservedValues(QtObservedAtom::MAX_ObservedTypes)
     106{
     107  boost::function<void (const atomId_t)> atomSubjectKilled(
     108      boost::bind(&QtObservedAtom::countValuesSubjectKilled,
     109          boost::ref(*this),
     110          _1));
     111  initObservedValues( ObservedValues, _id, _atom, atomSubjectKilled);
     112
     113  // activating Observer is done by ObservedValueContainer when it's inserted
    107114}
    108115
     
    220227  ++signedOffChannels;
    221228
    222   if (signedOffChannels == AllsignedOnChannels) {
     229  checkForRemoval();
     230}
     231
     232void QtObservedAtom::countValuesSubjectKilled(const atomId_t _id)
     233{
     234  ASSERT( _id == getAtomIndex(),
     235      "QtObservedAtom::countValuesSubjectKilled() - atom "+toString(getAtomIndex())
     236      +" received countValuesSubjectKilled for atom id "+toString(_id)+".");
     237
     238  ++subjectKilledCount;
     239
     240  checkForRemoval();
     241}
     242
     243#ifdef HAVE_INLINE
     244inline
     245#endif
     246void QtObservedAtom::checkForRemoval()
     247{
     248  if ((signedOffChannels == AllsignedOnChannels) && (subjectKilledCount == MAX_ObservedTypes)) {
    223249    // remove owner: no more signOff needed
    224250    owner = NULL;
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp

    r1b07b1 r62a0ee  
    6262  /** Cstor of QtObservedAtom.
    6363   *
    64    * \param _ObservedValues ref to set of observed values for this instance
     64   * \param _id id of observed atom
     65   * \param _atom ref to observed atom
    6566   * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
    6667   * \param _parent Qt parent to automatically destroy when parent is destroyed
    6768   */
    6869  QtObservedAtom(
    69       const ObservedValues_t &_ObservedValues,
     70      const atomId_t _id,
     71      const atom * const _atom,
    7072      QtObservedInstanceBoard &_board,
    7173      QWidget * _parent=0);
     
    189191   * \param _subjectKilled ref to function to call on subjectKilled()
    190192   */
    191   static void initObservedValues(
     193  void initObservedValues(
    192194      ObservedValues_t &_ObservedValues,
    193195      const atomId_t _id,
     
    209211  { BoardIsGone = true; }
    210212
     213  /** Counts the number of subject killed received from the observed values.
     214   *
     215   * \param _id id to check against ours
     216   */
     217  void countValuesSubjectKilled(const atomId_t _id);
     218
    211219  //!> counts how many ObservedValues have already been subjectKilled()
    212220  mutable size_t subjectKilledCount;
     221
     222  /** Helper function to check that all subjectKilled have been received for both
     223   * this instance and all its internal observed values.
     224   *
     225   */
     226  void checkForRemoval();
    213227
    214228private:
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    r1b07b1 r62a0ee  
    6666      *this,
    6767      boost::bind(&QtObservedInstanceBoard::moleculecountsubjectKilled, this, _1)),
    68   atomSubjectKilled(
    69       boost::bind(&ObservedValuesContainer<QtObservedAtom, atomId_t>::countsubjectKilled,
    70           boost::ref(atomObservedValues),
    71           _1)),
    72   moleculeSubjectKilled(
    73       boost::bind(&ObservedValuesContainer<QtObservedMolecule, moleculeId_t>::countsubjectKilled,
    74           boost::ref(moleculeObservedValues),
    75           _1)),
    7668  lastremovedatom((atomId_t)-1),
    7769  lastremovedmolecule((moleculeId_t)-1)
     
    10597  for (SignedOn_t::iterator iter = MoleculeSignedOn.begin(); !MoleculeSignedOn.empty();
    10698      iter = MoleculeSignedOn.begin()) {
    107     (*iter)->signOff(this, molecule::IndexChanged);
    108     (*iter)->signOff(this, molecule::AtomInserted);
    109     (*iter)->signOff(this, molecule::AtomRemoved);
    110     MoleculeSignedOn.erase(*iter); //erase all instances
     99    Observable * const _observable = *iter;
     100    _observable->signOff(this, molecule::IndexChanged);
     101    // remove all three remaining instances in multiset
     102    for (SignedOn_t::iterator sameiter = MoleculeSignedOn.find(_observable);
     103        sameiter != MoleculeSignedOn.end();
     104        sameiter = MoleculeSignedOn.find(_observable))
     105      MoleculeSignedOn.erase(*sameiter); //erase all instances
    111106  }
    112107}
     
    150145            getMolecule(MoleculeById(_id));
    151146        if (_molecule != NULL) {
    152           ObservedValues_t ObservedValues(QtObservedMolecule::MAX_ObservedTypes);
    153           LOG(3, "DEBUG: InformationBoard initializes ObservedValues for molecule " << _id);
    154           QtObservedMolecule::initObservedValues(
    155               ObservedValues,
    156               _id,
    157               _molecule,
    158               moleculeSubjectKilled);
    159           QtObservedMolecule::ptr observedmolecule(new QtObservedMolecule(ObservedValues, *this));
     147          LOG(3, "DEBUG: InformationBoard initializes QtObservedMolecule for " << _id);
     148          QtObservedMolecule::ptr observedmolecule(
     149              new QtObservedMolecule(
     150                  _id,
     151                  _molecule,
     152                  *this));
    160153          moleculeObservedValues.insert(_id, observedmolecule);
    161154          // we need to check for index changes
    162155          LOG(3, "DEBUG: InformationBoard signOn()s to molecule " << _id);
    163156          _molecule->signOn(this, molecule::IndexChanged);
    164           MoleculeSignedOn.insert( static_cast<Observable *>(const_cast<molecule *>(_molecule)) );
    165           _molecule->signOn(this, molecule::AtomInserted);
    166           MoleculeSignedOn.insert( static_cast<Observable *>(const_cast<molecule *>(_molecule)) );
    167           _molecule->signOn(this, molecule::AtomRemoved);
    168157          MoleculeSignedOn.insert( static_cast<Observable *>(const_cast<molecule *>(_molecule)) );
    169158
     
    192181            getAtom(AtomById(_id));
    193182        if (_atom!= NULL) {
    194           ObservedValues_t ObservedValues(QtObservedAtom::MAX_ObservedTypes);
    195           LOG(3, "DEBUG: InformationBoard initializes ObservedValues for atom " << _id);
    196           QtObservedAtom::initObservedValues(
    197               ObservedValues,
    198               _id,
    199               _atom,
    200               atomSubjectKilled);
    201           QtObservedAtom::ptr observedatom(new QtObservedAtom(ObservedValues, *this));
     183          LOG(3, "DEBUG: InformationBoard initializes QtObservedAtom for " << _id);
     184          QtObservedAtom::ptr observedatom(
     185              new QtObservedAtom(_id, _atom, *this));
    202186          atomObservedValues.insert(_id, observedatom);
    203187          // we need to check for index changes
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp

    r1b07b1 r62a0ee  
    136136  ObservedValuesContainer<QtObservedMolecule, moleculeId_t> moleculeObservedValues;
    137137
    138   //!> stored callback function for notifying QtObservedInstanceBoard about subjectKilled in atom
    139   boost::function<void (const atomId_t)> atomSubjectKilled;
    140   //!> stored callback function for notifying QtObservedInstanceBoard about subjectKilled in molecule
    141   boost::function<void (const moleculeId_t)> moleculeSubjectKilled;
    142138  //!> note down atom id of last removed atom to drop its ObservedValues
    143139  atomId_t lastremovedatom;
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.cpp

    r1b07b1 r62a0ee  
    100100
    101101QtObservedMolecule::QtObservedMolecule(
    102     const ObservedValues_t &_ObservedValues,
     102    const moleculeId_t _id,
     103    const molecule * const _mol,
    103104    QtObservedInstanceBoard &_board,
    104105    QWidget * _parent) :
     
    111112  board(_board),
    112113  BoardIsGone(false),
    113   ObservedValues(_ObservedValues)
    114 {
     114  ObservedValues(QtObservedMolecule::MAX_ObservedTypes)
     115{
     116  boost::function<void (const atomId_t)> moleculeSubjectKilled(
     117      boost::bind(&QtObservedMolecule::countValuesSubjectKilled,
     118          boost::ref(*this),
     119          _1));
     120  initObservedValues(ObservedValues, _id, _mol, moleculeSubjectKilled);
     121
    115122  // activating Observer is done by ObservedValueContainer when it's prepared
    116123}
     
    171178  ++signedOffChannels;
    172179
    173   if (signedOffChannels == AllsignedOnChannels) {
     180  checkForRemoval();
     181}
     182
     183void QtObservedMolecule::countValuesSubjectKilled(const moleculeId_t _id)
     184{
     185  ASSERT( _id == getMolIndex(),
     186      "QtObservedAtom::countValuesSubjectKilled() - molecule "+toString(getMolIndex())
     187      +" received countValuesSubjectKilled for molecule id "+toString(_id)+".");
     188
     189  ++subjectKilledCount;
     190
     191  checkForRemoval();
     192}
     193
     194void QtObservedMolecule::checkForRemoval()
     195{
     196  if ((signedOffChannels == AllsignedOnChannels) && (subjectKilledCount == MAX_ObservedTypes)) {
    174197    // remove owner: no more signOff needed
    175198    owner = NULL;
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp

    r1b07b1 r62a0ee  
    6060  /** Cstor of QtObservedMolecule.
    6161   *
    62    * \param _ObservedValues ref to set of observed values for this instance
     62   * \param _id id of observed molecule
     63   * \param _mol ref to observed molecule
    6364   * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
    6465   * \param _parent Qt parent to automatically destroy when parent is destroyed
    6566   */
    6667  QtObservedMolecule(
    67       const ObservedValues_t &_ObservedValues,
     68      const moleculeId_t _id,
     69      const molecule * const _mol,
    6870      QtObservedInstanceBoard &_board,
    6971      QWidget * _parent=0);
     
    249251  { BoardIsGone = true; }
    250252
     253
     254  /** Counts the number of subject killed received from the observed values.
     255   *
     256   * \param _id id to check against ours
     257   */
     258  void countValuesSubjectKilled(const atomId_t _id);
     259
    251260  //!> counts how many ObservedValues have already been subjectKilled()
    252261  mutable size_t subjectKilledCount;
     262
     263  /** Helper function to check that all subjectKilled have been received for both
     264   * this instance and all its internal observed values.
     265   *
     266   */
     267  void checkForRemoval();
    253268
    254269private:
Note: See TracChangeset for help on using the changeset viewer.