Changeset c60665


Ignore:
Timestamp:
Oct 5, 2013, 9:30:38 AM (11 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:
07414d7
Parents:
917659
git-author:
Frederik Heber <heber@…> (09/05/13 07:27:00)
git-committer:
Frederik Heber <heber@…> (10/05/13 09:30:38)
Message:

Rewrote Observer structure of GLMoleculeObject_bond.

  • renamed leftatom/rightatom to ...observable to clarify what they are used for, and we check whether either is still there before signing off.
  • we have three instances to take care of: bond, leftatom, rightatom.
  • we signOn to each Observable as well to get noticed via subjectKilled().
  • we only use subjectKilled() where we signOff() from the other two and then from all Notifications.
  • GLWorldScene is informed via BondRemoved and actually deletes the GLMoleculeObject_bond instance.
  • we use booleans to indicate whether we are still connected and sign off via subjectKilled(), emitting BondRemoved, or in dstor, without emit.
  • we do not use BlockingQueuedConnection yet but as soon as threads are introcued.
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp

    r917659 rc60665  
    116116  size_t elementno = 0;
    117117  const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
     118  const element *_type = NULL;
    118119  if (_atom != NULL) {
    119     const element *_type = _atom->getType();
    120     if (_type != NULL) {
    121       elementno = _type->getAtomicNumber();
    122     } else { // if no element yet, set to hydrogen
    123       elementno = 1;
    124     }
    125     LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
    126 
    127     // set materials
    128     QGLMaterial *elementmaterial = getMaterial(elementno);
    129     ASSERT(elementmaterial != NULL,
    130         "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
    131     setMaterial(elementmaterial);
    132 
    133     // set scale
    134     double radius = 0.;
    135     if (_type != NULL) {
    136       radius = _type->getVanDerWaalsRadius();
    137     } else {
    138       radius = 0.5;
    139     }
    140     setScale( radius / 4. );
     120    _type = _atom->getType();
    141121  } else {
    142122    ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
    143123  }
     124  if (_type != NULL) {
     125    elementno = _type->getAtomicNumber();
     126  } else { // if no element yet, set to hydrogen
     127    elementno = 1;
     128  }
     129  LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
     130
     131  // set materials
     132  QGLMaterial *elementmaterial = getMaterial(elementno);
     133  ASSERT(elementmaterial != NULL,
     134      "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
     135  setMaterial(elementmaterial);
     136
     137  // set scale
     138  double radius = 0.;
     139  if (_type != NULL) {
     140    radius = _type->getVanDerWaalsRadius();
     141  } else {
     142    radius = 0.5;
     143  }
     144  setScale( radius / 4. );
    144145}
    145146
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp

    r917659 rc60665  
    4848#include "CodePatterns/Observer/Notification.hpp"
    4949#include "CodePatterns/Observer/ObserverLog.hpp"
     50#include "Descriptors/AtomIdDescriptor.hpp"
    5051#include "Atom/atom.hpp"
    5152#include "Bond/bond.hpp"
     
    5455#include "LinearAlgebra/Line.hpp"
    5556#include "LinearAlgebra/Vector.hpp"
     57#include "World.hpp"
    5658
    5759GLMoleculeObject_bond::GLMoleculeObject_bond(QGLSceneNode *mesh[], QObject *parent, const bond::ptr bondref, const enum SideOfBond side) :
     
    6264      +toString(bondref->rightatom->getId())),
    6365  _bond(*bondref),
    64   leftatom(bondref->leftatom),
    65   rightatom(bondref->rightatom),
     66  leftobservable(bondref->leftatom),
     67  rightobservable(bondref->rightatom),
    6668  leftatomId(bondref->leftatom->getId()),
    6769  rightatomId(bondref->rightatom->getId()),
    68   BondSide(side)
     70  BondSide(side),
     71  leftobservable_enabled(false),
     72  rightobservable_enabled(false),
     73  bond_enabled(false)
    6974{
    7075  // sign on as observer (obtain non-const instance before)
     76  _bond.signOn(this);
    7177  _bond.signOn(this, BondObservable::BondRemoved);
    7278  _bond.signOn(this, BondObservable::DegreeChanged);
    73   leftatom->signOn(this, AtomObservable::PositionChanged);
    74   leftatom->signOn(this, AtomObservable::ElementChanged);
    75   rightatom->signOn(this, AtomObservable::PositionChanged);
    76   rightatom->signOn(this, AtomObservable::ElementChanged);
     79  bond_enabled = true;
     80  leftobservable->signOn(this);
     81  leftobservable->signOn(this, AtomObservable::PositionChanged);
     82  leftobservable->signOn(this, AtomObservable::ElementChanged);
     83  leftobservable_enabled = true;
     84  rightobservable->signOn(this);
     85  rightobservable->signOn(this, AtomObservable::PositionChanged);
     86  rightobservable->signOn(this, AtomObservable::ElementChanged);
     87  rightobservable_enabled = true;
    7788
    7889  size_t elementno = 0;
    7990  switch (BondSide) {
    8091    case left:
    81       if (_bond.rightatom->getType() != NULL) {
    82         elementno = _bond.rightatom->getType()->getAtomicNumber();
     92    {
     93      const atom *_rightatom = World::getInstance().getAtom(AtomById(rightatomId));
     94      if (_rightatom->getType() != NULL) {
     95        elementno = _rightatom->getType()->getAtomicNumber();
    8396      } else { // if not element yet set, set to hydrogen
    8497        elementno = 1;
    8598      }
    8699      break;
     100    }
    87101    case right:
    88       if (_bond.leftatom->getType() != NULL) {
    89         elementno = _bond.leftatom->getType()->getAtomicNumber();
     102    {
     103      const atom *_leftatom = World::getInstance().getAtom(AtomById(leftatomId));
     104      if (_leftatom->getType() != NULL) {
     105        elementno = _leftatom->getType()->getAtomicNumber();
    90106      } else { // if not element yet set, set to hydrogen
    91107        elementno = 1;
     
    93109
    94110      break;
     111    }
    95112    default:
    96113      ASSERT(0,
     
    107124
    108125GLMoleculeObject_bond::~GLMoleculeObject_bond()
     126{
     127  LOG(3, "DEBUG: Destroying  GLMoleculeObject_bond to bond " << &_bond << " and side " << BondSide << ".");
     128  // signOff() if not already done
     129  removeLeftAtom();
     130  removeRightAtom();
     131  removeBond();
     132  removeChannels();
     133}
     134
     135void GLMoleculeObject_bond::removeLeftAtom()
     136{
     137  // at this point both atoms should still be alive, hence we may safely sign off
     138  // from the AtomObservable itself
     139  if (leftobservable_enabled) {
     140    const atom *_leftatom = World::getInstance().getAtom(AtomById(leftatomId));
     141    if (_leftatom != NULL) {
     142      _leftatom->signOff(this);
     143    } else {
     144      ELOG(2, "Left atom of bond with id "+toString(leftatomId)+" is already gone.");
     145    }
     146  }
     147}
     148
     149void GLMoleculeObject_bond::removeRightAtom()
     150{
     151  // at this point both atoms should still be alive, hence we may safely sign off
     152  // from the AtomObservable itself
     153  if (rightobservable_enabled) {
     154    const atom *_rightatom = World::getInstance().getAtom(AtomById(rightatomId));
     155    if (_rightatom != NULL) {
     156      _rightatom->signOff(this);
     157    } else {
     158      ELOG(2, "Right atom of bond with id "+toString(rightatomId)+" is already gone.");
     159    }
     160  }
     161}
     162
     163void GLMoleculeObject_bond::removeBond()
     164{
     165  if (bond_enabled)
     166    _bond.signOff(this);
     167}
     168
     169void GLMoleculeObject_bond::removeChannels()
     170{
     171  // at this point both atoms should still be alive, hence we may safely sign off
     172  // from the AtomObservable itself
     173  if (leftobservable_enabled) {
     174    const atom *_leftatom = World::getInstance().getAtom(AtomById(leftatomId));
     175    if (_leftatom != NULL) {
     176      _leftatom->signOff(this, AtomObservable::PositionChanged);
     177      _leftatom->signOff(this, AtomObservable::ElementChanged);
     178    } else {
     179      ELOG(2, "Left atom of bond with id "+toString(leftatomId)+" is already gone.");
     180    }
     181    leftobservable_enabled = false;
     182  }
     183  if (rightobservable_enabled) {
     184    const atom *_rightatom = World::getInstance().getAtom(AtomById(rightatomId));
     185    if (_rightatom != NULL) {
     186      _rightatom->signOff(this, AtomObservable::PositionChanged);
     187      _rightatom->signOff(this, AtomObservable::ElementChanged);
     188    } else {
     189      ELOG(2, "Right atom of bond with id "+toString(rightatomId)+" is already gone.");
     190    }
     191    rightobservable_enabled = false;
     192  }
     193  if (bond_enabled) {
     194    _bond.signOff(this, BondObservable::BondRemoved);
     195    _bond.signOff(this, BondObservable::DegreeChanged);
     196    bond_enabled = false;
     197  }
     198}
     199
     200
     201void GLMoleculeObject_bond::removeMe()
    109202{
    110203  // sign off
     
    122215      break;
    123216  }
    124   _bond.signOff(this, BondObservable::BondRemoved);
    125   _bond.signOff(this, BondObservable::DegreeChanged);
    126   leftatom->signOff(this, AtomObservable::PositionChanged);
    127   leftatom->signOff(this, AtomObservable::ElementChanged);
    128   rightatom->signOff(this, AtomObservable::PositionChanged);
    129   rightatom->signOff(this, AtomObservable::ElementChanged);
    130   LOG(3, "DEBUG: Destroying  GLMoleculeObject_bond to bond " << &_bond << " and side " << BondSide << ".");
    131217}
    132218
     
    138224        << observerLog().getName(static_cast<Observer*>(this))
    139225        << " from bond.";
    140   } else if (publisher == leftatom) {
    141     observerLog().addMessage() << "++ Update of Observer "
    142         << observerLog().getName(static_cast<Observer*>(this))
    143         << " from leftatom " << _bond.leftatom->getId() << ".";
    144   } else if (publisher == rightatom) {
     226  } else if (publisher == leftobservable) {
     227    observerLog().addMessage() << "++ Update of Observer "
     228        << observerLog().getName(static_cast<Observer*>(this))
     229        << " from leftatom " << leftatomId << ".";
     230  } else if (publisher == rightobservable) {
    145231    observerLog().addMessage() << "++ Update of Observer " <<
    146232        observerLog().getName(static_cast<Observer*>(this))
    147         << " from rightatom " << _bond.rightatom->getId() << ".";
     233        << " from rightatom " << rightatomId << ".";
    148234  } else
    149235    observerLog().addMessage() << "++ Update of Observer " <<
     
    154240void GLMoleculeObject_bond::subjectKilled(Observable *publisher)
    155241{
    156   delete this;
     242  // assume subjectKilled() is from Observable's own subjectKilled(), not notifications
     243  // but we must always signOff from all other sources!
     244  if (publisher == static_cast<const Observable *>(&_bond)) {
     245#ifdef LOG_OBSERVER
     246    observerLog().addMessage() << "++ subjectKilled of Observer "
     247        << observerLog().getName(static_cast<Observer*>(this))
     248        << " from bond.";
     249#endif
     250    removeLeftAtom();
     251    removeRightAtom();
     252  } else if (publisher == leftobservable) {
     253#ifdef LOG_OBSERVER
     254    observerLog().addMessage() << "++ subjectKilled of Observer "
     255        << observerLog().getName(static_cast<Observer*>(this))
     256        << " from leftatom " << leftatomId << ".";
     257#endif
     258    removeRightAtom();
     259    removeBond();
     260  } else if (publisher == rightobservable) {
     261#ifdef LOG_OBSERVER
     262    observerLog().addMessage() << "++ subjectKilled of Observer " <<
     263        observerLog().getName(static_cast<Observer*>(this))
     264        << " from rightatom " << rightatomId << ".";
     265#endif
     266    removeLeftAtom();
     267    removeBond();
     268  } else {
     269#ifdef LOG_OBSERVER
     270    observerLog().addMessage() << "++ subjectKilled of Observer " <<
     271    observerLog().getName(static_cast<Observer*>(this)) << " from unknown source.";
     272#endif
     273  }
     274  // then indicate to remove us
     275  removeChannels();
     276  removeMe();
    157277}
    158278
     
    165285        << " received notification from bond for channel "
    166286        << notification->getChannelNo() << ".";
    167   } else if (publisher == leftatom) {
    168     observerLog().addMessage() << "++ Update of Observer "
    169         << observerLog().getName(static_cast<Observer*>(this))
    170         << " received notification from leftatom " << _bond.leftatom->getId() << " for channel "
     287  } else if (publisher == leftobservable) {
     288    observerLog().addMessage() << "++ Update of Observer "
     289        << observerLog().getName(static_cast<Observer*>(this))
     290        << " received notification from leftatom " << leftatomId << " for channel "
    171291        << notification->getChannelNo() << ".";
    172   } else if (publisher == rightatom) {
    173     observerLog().addMessage() << "++ Update of Observer "
    174         << observerLog().getName(static_cast<Observer*>(this))
    175         << " received notification from rightatom " << _bond.rightatom->getId() << " for channel "
     292  } else if (publisher == rightobservable) {
     293    observerLog().addMessage() << "++ Update of Observer "
     294        << observerLog().getName(static_cast<Observer*>(this))
     295        << " received notification from rightatom " << rightatomId << " for channel "
    176296        << notification->getChannelNo() << ".";
    177297  } else
     
    185305    switch (notification->getChannelNo()) {
    186306    case BondObservable::BondRemoved:
    187       delete this;
     307//      removeMe();
    188308      break;
    189309    case BondObservable::DegreeChanged:
     
    231351  Vector Position;
    232352  Vector OtherPosition;
     353  const atom *_leftatom = World::getInstance().getAtom(AtomById(leftatomId));
     354  Vector LeftPos = _leftatom->getPosition();
     355  const atom *_rightatom = World::getInstance().getAtom(AtomById(rightatomId));
     356  Vector RightPos = _rightatom->getPosition();
    233357  switch (BondSide) {
    234358    case left:
    235       Position = _bond.leftatom->getPosition();
    236       OtherPosition = _bond.rightatom->getPosition();
     359      Position = LeftPos;
     360      OtherPosition = RightPos;
    237361      break;
    238362    case right:
    239       Position = _bond.rightatom->getPosition();
    240       OtherPosition = _bond.leftatom->getPosition();
     363      Position = RightPos;
     364      OtherPosition = LeftPos;
    241365      break;
    242366    default:
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp

    r917659 rc60665  
    5151  void resetWidth();
    5252
     53  /** This must be called from subjectKilled() only.
     54   *
     55   * We remove from all other Observables in a controlled manner.
     56   * However, we assume that either bond, leftobservable, or rightobservable
     57   * called subjectKilled(). Hence, we may still signOff() from all noifications
     58   * but not from the calling Observable.
     59   *
     60   * removeLeftAtom(), removeRightAtom(), removeBond(), and removeChannels()
     61   * must have been called before (or one of the subjects has been killed).
     62   *
     63   */
     64  void removeMe();
     65  void removeLeftAtom();
     66  void removeRightAtom();
     67  void removeChannels();
     68  void removeBond();
     69
     70private:
    5371  const bond& _bond;
    5472  /** Observable instance inside atom_observable for left bond partner.
     
    5775   *
    5876   */
    59   const Observable *leftatom;
     77  const Observable *leftobservable;
    6078  /** Observable instance inside atom_observable for right bond partner.
    6179   * We require this knowledge as subjectKilled is called by Observable, not
     
    6381   *
    6482   */
    65   const Observable *rightatom;
     83  const Observable *rightobservable;
    6684  //!> id of left bond partner for safely emitting BondRemoved sigbal
    6785  const atomId_t leftatomId;
     
    6987  const atomId_t rightatomId;
    7088  const enum SideOfBond BondSide;
     89
     90  //!> indicate whether we are signed in to leftobservable
     91  bool leftobservable_enabled;
     92  //!> indicate whether we are signed in to rightobservable
     93  bool rightobservable_enabled;
     94  //!> indicate whether we are signed in to _bond
     95  bool bond_enabled;
    7196};
    7297
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    r917659 rc60665  
    295295        "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
    296296        +toString(rightnr)+" not on display.");
    297     //GLMoleculeObject_bond::ptr bondObject = leftiter->second;
     297    GLMoleculeObject_bond *bondObject = leftiter->second;
    298298    BondsinSceneMap.erase(leftiter);
    299     //delete bondObject; // is done by signal from bond itself
     299    delete bondObject; // is done by signal from bond itself
    300300    //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
    301301  }
Note: See TracChangeset for help on using the changeset viewer.