Ignore:
Timestamp:
Apr 20, 2016, 10:58: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:
96f14a
Parents:
6af6a62
git-author:
Frederik Heber <heber@…> (03/15/16 10:10:54)
git-committer:
Frederik Heber <heber@…> (04/20/16 22:58:42)
Message:

Added QtObservedBond, managed by QtObservedInstanceBoard.

  • QtObservedBond is special because it observes not only a bond, but also two atoms and a molecule in total.
  • but the general idea is to rather have information duplicate, i.e. the left atom's position is also available via the QtObservedAtom. But in this way QtObservedBond does not depend on the QtObservedAtom being still or already present.
Location:
src/UIElements/Qt4/InstanceBoard
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    r6af6a62 rb4bd0e  
    6262      *this,
    6363      boost::bind(&QtObservedInstanceBoard::atomcountsubjectKilled, this, _1)),
     64  bondObservedValues(
     65      "bond",
     66      *this,
     67      boost::bind(&QtObservedInstanceBoard::bondcountsubjectKilled, this, _1)),
    6468  moleculeObservedValues(
    6569      "molecule",
     
    6973  qRegisterMetaType<ObservedValue_Index_t>("ObservedValue_Index_t");
    7074  qRegisterMetaType<QtObservedAtom::ptr>("QtObservedAtom::ptr");
     75  qRegisterMetaType<QtObservedBond::ptr>("QtObservedBond::ptr");
    7176  qRegisterMetaType<QtObservedMolecule::ptr>("QtObservedMolecule::ptr");
    7277
     
    8388    World::getInstance().signOff(this, World::MoleculeInserted);
    8489  }
    85   // sign off from all remaining molecules and atoms
     90  // sign off from all remaining molecules, bonds, and atoms
    8691  for (SignedOn_t::iterator iter = AtomSignedOn.begin(); !AtomSignedOn.empty();
    8792      iter = AtomSignedOn.begin()) {
    8893    (*iter)->signOff(this, atom::IndexChanged);
    89     AtomSignedOn.erase(iter);
     94    (*iter)->signOff(this, atom::BondsAdded);
     95    AtomSignedOn.erase(*iter);
    9096  }
    9197
     
    108114  if ( iter != AtomSignedOn.end()) {
    109115    LOG(3, "DEBUG: InstanceBoard got subjectKilled() from atom " << publisher);
    110     AtomSignedOn.erase(iter);
     116    AtomSignedOn.erase(iter); // only remove one
    111117  } else {
    112118    iter = MoleculeSignedOn.find(publisher);
     
    176182          LOG(3, "DEBUG: InformationBoard signOn()s to atom " << _id);
    177183          _atom->signOn(this, atom::IndexChanged);
     184          _atom->signOn(this, atom::BondsAdded);
     185          AtomSignedOn.insert( static_cast<Observable *>(const_cast<atom *>(_atom)) );
    178186          AtomSignedOn.insert( static_cast<Observable *>(const_cast<atom *>(_atom)) );
    179187          emit atomInserted(observedatom);
     
    232240        break;
    233241      }
     242      case AtomObservable::BondsAdded:
     243      {
     244        const atom * _atom = dynamic_cast<atom *>(publisher);
     245        const atomId_t _id = _atom->getId();
     246#ifdef LOG_OBSERVER
     247      observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted.";
     248#endif
     249        LOG(3, "DEBUG: InformationBoard got bondInserted signal for atom " << _id);
     250        if (_atom != NULL) {
     251          // find the new bond by simply taking the last added to the list
     252          const BondList &ListOfBonds = _atom->getListOfBonds();
     253          const bond::ptr bondref = ListOfBonds.back();
     254          const bondId_t bondid =
     255              std::make_pair( bondref->leftatom->getId(), bondref->rightatom->getId());
     256          LOG(3, "DEBUG: InformationBoard initializes QtObservedBond for " << bondid);
     257          QtObservedBond::ptr observedbond(
     258              new QtObservedBond(bondid, bondref, *this));
     259          const ObservedValue_Index_t index = observedbond->getIndex();
     260          bondObservedValues.insert(index, observedbond);
     261          bondids_lookup.left.insert( std::make_pair(bondid, index) );
     262          emit bondInserted(observedbond);
     263        } else {
     264          ELOG(1, "QtObservedInstanceBoard got BondsAdded for unknown atom id " << _id);
     265        }
     266        break;
     267      }
    234268      default:
    235269        ASSERT(0, "QtObservedInstanceBoard::recieveNotification() - we cannot get here.");
     
    239273    ASSERT(0, "QtObservedInstanceBoard::recieveNotification() - notification from unknown source.");
    240274  }
    241 }
    242 
    243 void QtObservedInstanceBoard::atomcountsubjectKilled(ObservedValue_Index_t _id)
    244 {
    245   LOG(3, "DEBUG: InstanceBoard emits atomRemoved for " << _id);
    246   emit atomRemoved(_id);
    247 }
    248 
    249 void QtObservedInstanceBoard::moleculecountsubjectKilled(ObservedValue_Index_t _id)
    250 {
    251   LOG(3, "DEBUG: InstanceBoard emits moleculeRemoved for " << _id);
    252   emit moleculeRemoved(_id);
    253275}
    254276
     
    262284}
    263285
     286const QtObservedInstanceBoard::bondId_t
     287QtObservedInstanceBoard::getBondIdToIndex(ObservedValue_Index_t _id) const
     288{
     289  typename IdtoIndex_t<bondId_t>::right_const_iterator iter = bondids_lookup.right.find(_id);
     290  ASSERT( iter != bondids_lookup.right.end(),
     291      "QtObservedInstanceBoard::getBondIdToIndex() - index "
     292      +toString(_id)+" is unknown.");
     293  return iter->second;
     294}
     295
    264296const moleculeId_t QtObservedInstanceBoard::getMoleculeIdToIndex(ObservedValue_Index_t _id) const
    265297{
     
    271303}
    272304
     305void QtObservedInstanceBoard::atomcountsubjectKilled(ObservedValue_Index_t _id)
     306{
     307  LOG(3, "DEBUG: InstanceBoard emits atomRemoved for " << getAtomIdToIndex(_id));
     308  emit atomRemoved(_id);
     309}
     310
     311void QtObservedInstanceBoard::bondcountsubjectKilled(ObservedValue_Index_t _id)
     312{
     313  LOG(3, "DEBUG: InstanceBoard emits bondRemoved for " << getBondIdToIndex(_id));
     314  emit bondRemoved(_id);
     315}
     316
     317void QtObservedInstanceBoard::moleculecountsubjectKilled(ObservedValue_Index_t _id)
     318{
     319  LOG(3, "DEBUG: InstanceBoard emits moleculeRemoved for " << getMoleculeIdToIndex(_id));
     320  emit moleculeRemoved(_id);
     321}
     322
    273323QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(const atomId_t _id)
    274324{
     
    279329{
    280330  return atomObservedValues.get(_id);
     331}
     332
     333QtObservedBond::ptr QtObservedInstanceBoard::getObservedBond(const bondId_t _id)
     334{
     335  return bondObservedValues.get(bondids_lookup.left.at(_id));
     336}
     337
     338QtObservedBond::ptr QtObservedInstanceBoard::getObservedBond(ObservedValue_Index_t _id)
     339{
     340  return bondObservedValues.get(_id);
    281341}
    282342
     
    307367}
    308368
     369void QtObservedInstanceBoard::markObservedBondAsConnected(ObservedValue_Index_t _id)
     370{
     371  bondObservedValues.markObservedValuesAsConnected(_id);
     372}
     373
     374void QtObservedInstanceBoard::markObservedBondAsDisconnected(ObservedValue_Index_t _id)
     375{
     376  bondObservedValues.markObservedValuesAsDisconnected(_id);
     377}
     378
     379void QtObservedInstanceBoard::markObservedBondForErase(ObservedValue_Index_t _id)
     380{
     381  bondObservedValues.eraseObservedValues(_id);
     382  bondids_lookup.right.erase(_id);
     383}
     384
    309385void QtObservedInstanceBoard::markObservedMoleculeAsConnected(ObservedValue_Index_t _id)
    310386{
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp

    r6af6a62 rb4bd0e  
    1818
    1919#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
     20#include "UIElements/Qt4/InstanceBoard/QtObservedBond.hpp"
    2021#include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp"
    2122
     
    6465
    6566public:
     67  //!> copy bond id type from QtObservedBond
     68  typedef QtObservedBond::bondId_t bondId_t;
     69
    6670  /** Cstor of QtObservedInstanceBoard.
    6771   *
     
    8185
    8286  const atomId_t getAtomIdToIndex(ObservedValue_Index_t _id) const;
     87  const bondId_t getBondIdToIndex(ObservedValue_Index_t _id) const;
    8388  const moleculeId_t getMoleculeIdToIndex(ObservedValue_Index_t _id) const;
    8489
    8590  QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
    8691  QtObservedAtom::ptr getObservedAtom(ObservedValue_Index_t _id);
     92  QtObservedBond::ptr getObservedBond(const bondId_t _id);
     93  QtObservedBond::ptr getObservedBond(ObservedValue_Index_t _id);
    8794  QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
    8895  QtObservedMolecule::ptr getObservedMolecule(ObservedValue_Index_t _id);
     
    9097  void markObservedAtomAsDisconnected(ObservedValue_Index_t _id);
    9198  void markObservedAtomForErase(ObservedValue_Index_t _id);
     99  void markObservedBondAsConnected(ObservedValue_Index_t _id);
     100  void markObservedBondAsDisconnected(ObservedValue_Index_t _id);
     101  void markObservedBondForErase(ObservedValue_Index_t _id);
    92102  void markObservedMoleculeAsConnected(ObservedValue_Index_t _id);
    93103  void markObservedMoleculeAsDisconnected(ObservedValue_Index_t _id);
     
    98108  void atomRemoved(ObservedValue_Index_t _atomid);
    99109  void atomIndexChanged(const atomId_t _oldid, const atomId_t _newid);
     110  void bondInserted(QtObservedBond::ptr _bond);
     111  void bondRemoved(ObservedValue_Index_t _bondid);
     112  void bondIndexChanged(const bondId_t _oldid, const bondId_t _newid);
    100113  void moleculeInserted(QtObservedMolecule::ptr _mol);
    101114  void moleculeRemoved(ObservedValue_Index_t _molid);
     
    111124  bool WorldSignedOn;
    112125
    113   typedef std::set<Observable *> SignedOn_t;
     126  typedef std::multiset<Observable *> SignedOn_t;
    114127  //!> map indicating to which atom we are currently signed on
    115128  SignedOn_t AtomSignedOn;
     
    121134  struct IdtoIndex_t : boost::bimap<id, ObservedValue_Index_t> {};
    122135  IdtoIndex_t<atomId_t> atomids_lookup;
     136  IdtoIndex_t<bondId_t> bondids_lookup;
    123137  IdtoIndex_t<moleculeId_t> moleculeids_lookup;
    124138
     
    132146   */
    133147  void atomcountsubjectKilled(ObservedValue_Index_t _id);
     148
     149  /** Counts how many bond's ObservedValues got subjectKilled.
     150   *
     151   * This is used to give removal signal only when each and every
     152   * ObservedValue (and the instance itself) has been subjectKilled by the
     153   * monitored Observable. Only then can we safely remove the instance.
     154   *
     155   * \param _bondid id of the bond
     156   */
     157  void bondcountsubjectKilled(ObservedValue_Index_t _bondid);
    134158
    135159  /** Counts how many molecule's ObservedValues got subjectKilled.
     
    145169  //!> container with all ObservedValues for each atom, associated by id
    146170  ObservedValuesContainer<QtObservedAtom, ObservedValue_Index_t> atomObservedValues;
     171  //!> container with all ObservedValues for each bond, associated by id pairs
     172  ObservedValuesContainer<QtObservedBond, ObservedValue_Index_t> bondObservedValues;
    147173  //!> container with all ObservedValues for each molecule, associated by id
    148174  ObservedValuesContainer<QtObservedMolecule, ObservedValue_Index_t> moleculeObservedValues;
Note: See TracChangeset for help on using the changeset viewer.