Ignore:
Timestamp:
Feb 12, 2016, 11:15:06 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:
0f7ffe
Parents:
47f0e4
git-author:
Frederik Heber <heber@…> (01/25/16 11:09:33)
git-committer:
Frederik Heber <heber@…> (02/12/16 23:15:06)
Message:

GLMoleculeObject_atom, _bond, _molecule all use QtInstanceInformationBoard passed via GLWorldScene.

Location:
src/UIElements/Views/Qt4/Qt3D
Files:
7 edited

Legend:

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

    r47f0e4 r8d5fbf1  
    5353#include "Element/periodentafel.hpp"
    5454#include "LinearAlgebra/Vector.hpp"
    55 #include "GLMoleculeObject_bond.hpp"
     55#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp"
     56#include "UIElements/Views/Qt4/QtInstanceInformationBoard.hpp"
    5657#include "World.hpp"
    5758#include "WorldTime.hpp"
     
    6566  Observable::channels_t channels;
    6667  channels += AtomObservable::BondsAdded, AtomObservable::BondsRemoved;
     68  return channels;
     69}
     70
     71static const Observable::channels_t getAllObservedChannels()
     72{
     73  Observable::channels_t channels;
     74  channels +=
     75      AtomObservable::IndexChanged,
     76      AtomObservable::PositionChanged,
     77      AtomObservable::ElementChanged,
     78      AtomObservable::BondsAdded,
     79      AtomObservable::BondsRemoved;
    6780  return channels;
    6881}
     
    8194    QGLSceneNode *mesh[],
    8295    QObject *parent,
    83     const atomId_t _id) :
    84   GLMoleculeObject(mesh, parent),
    85   Observer(std::string("GLMoleculeObject_atom")+toString(_id)),
    86   atomref(getAtom(_id)),
    87   ObservedValues(MAX_ObservedTypes),
    88   subjectKilledCount(0),
    89   owner(NULL)
    90 {
    91   boost::function<void(const atomId_t)> subjectKilled =
    92       boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this, _id);
    93   initObservedValues(ObservedValues, _id, atomref, subjectKilled);
    94 
    95   init(_id);
    96 }
    97 
    98 GLMoleculeObject_atom::GLMoleculeObject_atom(
    99     QGLSceneNode *mesh[],
    100     QObject *parent,
    10196    const atomId_t _id,
     97    QtInstanceInformationBoard * _board,
    10298    std::vector<boost::any> _ObservedValues) :
    10399  GLMoleculeObject(mesh, parent),
     
    106102  ObservedValues(_ObservedValues),
    107103  subjectKilledCount(0),
    108   owner(NULL)
     104  owner(NULL),
     105  AllsignedOnChannels(getAllObservedChannels().size()),
     106  signedOnChannels(0),
     107  board(_board)
    109108{
    110109  init(_id);
     
    130129  connect( this, SIGNAL(positionChanged()), this, SLOT(resetPosition()), Qt::QueuedConnection);
    131130  connect( this, SIGNAL(bondsChanged()), this, SLOT(resetPosition()), Qt::QueuedConnection);
     131
     132  // use that ObservedValues::AtomBonds is always up-to-date
     133  resetBonds();
    132134}
    133135
     
    135137{
    136138  if (atomref != NULL) {
     139    Observable::channels_t channels = getAllObservedChannels();
    137140    owner = static_cast<const Observable *>(atomref);
    138     owner->signOn(this, AtomObservable::IndexChanged);
    139     owner->signOn(this, AtomObservable::PositionChanged);
    140     owner->signOn(this, AtomObservable::ElementChanged);
    141     owner->signOn(this, AtomObservable::BondsAdded);
    142     owner->signOn(this, AtomObservable::BondsRemoved);
     141    for (Observable::channels_t::const_iterator iter = channels.begin();
     142        iter != channels.end(); ++iter)
     143      owner->signOn(this, *iter);
    143144  }
    144145}
     
    149150  // sign Off
    150151  if (owner != NULL) {
    151     owner->signOff(this, AtomObservable::IndexChanged);
    152     owner->signOff(this, AtomObservable::PositionChanged);
    153     owner->signOff(this, AtomObservable::ElementChanged);
    154     owner->signOff(this, AtomObservable::BondsAdded);
    155     owner->signOff(this, AtomObservable::BondsRemoved);
     152    Observable::channels_t channels = getAllObservedChannels();
     153    for (Observable::channels_t::const_iterator iter = channels.begin();
     154        iter != channels.end(); ++iter)
     155      owner->signOff(this, *iter);
    156156    owner = NULL;
     157    signedOnChannels = 0;
    157158  }
    158159}
     
    161162{
    162163  deactivateObserver();
    163   destroyObservedValues(ObservedValues);
     164  board->returnAtomObservedValues(getAtomIndex(), ObservedValues);
    164165}
    165166
     
    338339void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
    339340{
    340   deactivateObserver();
    341 
    342   countsubjectKilled(getAtomIndex());
     341  ++signedOnChannels;
     342
     343  if (signedOnChannels == AllsignedOnChannels) {
     344    // remove owner: no more signOff needed
     345    owner = NULL;
     346
     347    board->atomcountsubjectKilled(getAtomIndex());
     348  }
    343349}
    344350
     
    371377}
    372378
    373 void GLMoleculeObject_atom::countsubjectKilled(const atomId_t)
    374 {
    375   ++subjectKilledCount;
    376 
    377   if (subjectKilledCount > ObservedValues.size())
    378     emit InstanceRemoved(getAtomIndex());
    379 }
    380 
    381379void GLMoleculeObject_atom::initObservedValues(
    382380    std::vector<boost::any> &_ObservedValues,
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp

    r47f0e4 r8d5fbf1  
    3838      QGLSceneNode *mesh[],
    3939      QObject *parent,
    40       const atomId_t id
    41       );
    42   GLMoleculeObject_atom(
    43       QGLSceneNode *mesh[],
    44       QObject *parent,
    4540      const atomId_t id,
     41      QtInstanceInformationBoard * _board,
    4642      std::vector<boost::any> _ObservedValues
    4743      );
     
    7571  void elementChanged();
    7672  void bondsChanged();
    77   void InstanceRemoved(const atomId_t);
    7873
    7974private:
     
    173168  ListOfBonds_t getAtomBonds() const;
    174169
    175   /** Counts how many ObservedValues got subjectKilled.
    176    *
    177    * This is used to give InstanceRemoved() signal only when each and every
    178    * ObservedValue (and the instance itself) has been subjectKilled by the
    179    * monitored Observable. Only then can we safely remove the instance.
    180    *
    181    * \param _atomid id of atom who signalled subjectKilled()
    182    */
    183   void countsubjectKilled(const atomId_t _atomid);
    184 
    185170  //!> counts how many ObservedValues have already been subjectKilled()
    186171  mutable size_t subjectKilledCount;
     
    199184  //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
    200185  const Observable *owner;
     186
     187  //!> we get multiple subjectKilled(), count and call callback() only on last
     188  const unsigned int AllsignedOnChannels;
     189  unsigned int signedOnChannels;
     190
     191  QtInstanceInformationBoard * board;
    201192};
    202193
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp

    r47f0e4 r8d5fbf1  
    5555#include "LinearAlgebra/Line.hpp"
    5656#include "LinearAlgebra/Vector.hpp"
     57#include "UIElements/Views/Qt4/QtInstanceInformationBoard.hpp"
    5758#include "World.hpp"
    5859
     
    6970const Observable::channels_t
    7071GLMoleculeObject_bond::BondElementChannels(1, AtomObservable::ElementChanged);
     72
     73static GLMoleculeObject_bond::bondIds_t getBondIdsForIds(
     74    const boost::function<const atomId_t()> &_left,
     75    const boost::function<const atomId_t()> &_right)
     76{
     77  return std::make_pair(_left(), _right());
     78}
    7179
    7280GLMoleculeObject_bond::GLMoleculeObject_bond(
     
    8795  subjectKilledCount(0),
    8896  leftobservable_enabled(false),
    89   rightobservable_enabled(false)
     97  rightobservable_enabled(false),
     98  board_subjectKilled(
     99      boost::bind(
     100          static_cast<void (GLMoleculeObject_bond::*) ()>(
     101              &GLMoleculeObject_bond::countsubjectKilled),
     102          this))
    90103{
    91104  boost::function<void(const atomId_t &)> leftsubjectKilled =
     
    123136    const bondIds_t bondIds,
    124137    const enum SideOfBond side,
    125     std::vector<boost::any> &_ObservedValues) :
     138    std::vector<boost::any> &_ObservedValues,
     139    const boost::function<void (const bondIds_t)> &_subjectKilled) :
    126140  GLMoleculeObject(mesh, parent),
    127141  Observer(std::string("GLMoleculeObject_bond")
     
    136150  subjectKilledCount(0),
    137151  leftobservable_enabled(false),
    138   rightobservable_enabled(false)
     152  rightobservable_enabled(false),
     153  board_subjectKilled(_subjectKilled)
    139154{
    140155  init();
     
    209224  removeChannels();
    210225  // check whether we should be removed
    211   countsubjectKilled(std::make_pair(getleftIndex(), getrightIndex()));
     226  board_subjectKilled(std::make_pair(getleftIndex(), getrightIndex()));
    212227}
    213228
     
    389404}
    390405
    391 static GLMoleculeObject_bond::bondIds_t getBondIdsForIds(
    392     const boost::function<const atomId_t ()> _left,
    393     const boost::function<const atomId_t ()> _right)
    394 {
    395   return std::make_pair( _left(), _right());
    396 }
    397 
    398406void GLMoleculeObject_bond::initObservedValues(
    399407    std::vector<boost::any> &_ObservedValues,
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp

    r47f0e4 r8d5fbf1  
    1818#include <vector>
    1919#include <boost/any.hpp>
     20#include <boost/function.hpp>
    2021
    2122#include "CodePatterns/Observer/Observer.hpp"
     
    4950      const bondIds_t bondIds,
    5051      const enum SideOfBond side,
    51       std::vector<boost::any> &_ObservedValues);
     52      std::vector<boost::any> &_ObservedValues,
     53      const boost::function<void (const bondIds_t)> &_subjectKilled);
    5254  virtual ~GLMoleculeObject_bond();
    5355
     
    255257  //!> list of channels when element needs to update
    256258  static const Observable::channels_t BondElementChannels;
     259
     260  //!> callback function to inform about subjectKilled()
     261  const boost::function<void (const bondIds_t)> board_subjectKilled;
    257262};
    258263
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    r47f0e4 r8d5fbf1  
    4545
    4646#include "CodePatterns/Assert.hpp"
     47#include "CodePatterns/IteratorAdaptors.hpp"
    4748#include "CodePatterns/Log.hpp"
    4849#include "CodePatterns/Observer/Notification.hpp"
     
    6162#include "Tesselation/BoundaryTriangleSet.hpp"
    6263#include "Tesselation/CandidateForTesselation.hpp"
     64#include "UIElements/Views/Qt4/QtInstanceInformationBoard.hpp"
    6365#include "Atom/TesselPoint.hpp"
    6466#include "World.hpp"
     
    7072
    7173#include "GLMoleculeObject_atom.hpp"
    72 
    73 static Observable::channels_t getAtomsChannels()
    74 {
    75   Observable::channels_t channels;
    76   channels += molecule::AtomInserted, molecule::AtomRemoved;
    77   return channels;
    78 }
    7974
    8075static Observable::channels_t getAllAtomicChangesChannels()
     
    8580}
    8681
     82static Observable::channels_t getAllAtomicObservedChannels()
     83{
     84  Observable::channels_t channels;
     85  channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
     86  return channels;
     87}
     88
    8789// static instances
    88 const Observable::channels_t GLMoleculeObject_molecule::AtomsChannels(getAtomsChannels());
    8990const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels());
    9091const Observable::channels_t GLMoleculeObject_molecule::BoundingBoxChannels(1, molecule::BoundingBoxChanged);
     
    101102}
    102103
    103 GLMoleculeObject_molecule::GLMoleculeObject_molecule(QObject *parent, const moleculeId_t _molid) :
     104GLMoleculeObject_molecule::GLMoleculeObject_molecule(
     105    QObject *parent,
     106    const moleculeId_t _molid,
     107    QtInstanceInformationBoard * _board,
     108    std::vector<boost::any> _ObservedValues) :
    104109  GLMoleculeObject((QGLSceneNode *)NULL, parent),
    105110  Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)),
     
    110115   * the class has not been fully constructed yet. "This" itself seems to be working fine.
    111116   */
    112   ObservedValues(MAX_ObservedTypes),
     117  ObservedValues(_ObservedValues),
    113118  subjectKilledCount(0),
    114119  TesselationHullUpdater(
     
    120125      "MoleculeTesselationHull_"+toString(_molid),
    121126      HullChannels),
    122   hoverAtomId(-1)
    123 {
    124   boost::function<void(const moleculeId_t)> subjectKilled =
    125       boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this, _molid);
    126   initObservedValues(ObservedValues, _molid, molref, subjectKilled);
    127 
     127  hoverAtomId(-1),
     128  AllsignedOnChannels(getAllAtomicObservedChannels().size()),
     129  signedOnChannels(0),
     130  board(_board)
     131{
     132  init(_molid);
     133}
     134
     135GLMoleculeObject_molecule::GLMoleculeObject_molecule(
     136    QGLSceneNode *mesh[],
     137    QObject *parent,
     138    const moleculeId_t _molid,
     139    QtInstanceInformationBoard * _board,
     140    std::vector<boost::any> _ObservedValues) :
     141  GLMoleculeObject(mesh, parent),
     142  Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)),
     143  owner(NULL),
     144  molref(getMolecule(_molid)),
     145  /* We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
     146   * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
     147   * the class has not been fully constructed yet. "This" itself seems to be working fine.
     148   */
     149  ObservedValues(_ObservedValues),
     150  subjectKilledCount(0),
     151  TesselationHullUpdater(
     152      boost::bind(&GLMoleculeObject_molecule::updateTesselationHull, this)
     153      ),
     154  TesselationHull(
     155      molref,
     156      TesselationHullUpdater,
     157      "MoleculeTesselationHull_"+toString(_molid),
     158      HullChannels),
     159  hoverAtomId(-1),
     160  AllsignedOnChannels(getAllAtomicObservedChannels().size()),
     161  signedOnChannels(0),
     162  board(_board)
     163{
     164  init(_molid);
     165}
     166
     167void GLMoleculeObject_molecule::init(const moleculeId_t _molid)
     168{
    128169  setObjectId(_molid);
    129170  setMaterial(getMaterial(1));
     
    133174  // initially, atoms and bonds should be visible
    134175  m_visible = false;
     176
     177  activateObserver();
    135178
    136179  connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
     
    147190}
    148191
    149 GLMoleculeObject_molecule::GLMoleculeObject_molecule(
    150     QGLSceneNode *mesh[],
    151     QObject *parent,
    152     const moleculeId_t _molid) :
    153   GLMoleculeObject(mesh, parent),
    154   Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)),
    155   owner(NULL),
    156   molref(getMolecule(_molid)),
    157   /* We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
    158    * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
    159    * the class has not been fully constructed yet. "This" itself seems to be working fine.
    160    */
    161   ObservedValues(MAX_ObservedTypes),
    162   subjectKilledCount(0),
    163   TesselationHullUpdater(
    164       boost::bind(&GLMoleculeObject_molecule::updateTesselationHull, this)
    165       ),
    166   TesselationHull(
    167       molref,
    168       TesselationHullUpdater,
    169       "MoleculeTesselationHull_"+toString(_molid),
    170       HullChannels),
    171   hoverAtomId(-1)
    172 {
    173   boost::function<void(const moleculeId_t)> subjectKilled =
    174       boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this, _molid);
    175   initObservedValues(ObservedValues, _molid, molref, subjectKilled);
    176 
    177   setObjectId(_molid);
    178   setMaterial(getMaterial(1));
    179 
    180   m_selected = const_cast<const World &>(World::getInstance()).isMoleculeSelected(_molid);
    181 
    182   // initially, atoms and bonds should be visible
    183   m_visible = false;
    184 
    185   connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
    186   connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
    187   connect (this, SIGNAL(TesselationHullChanged()), this, SLOT(resetTesselationHull()), Qt::QueuedConnection);
    188   connect (this, SIGNAL(BoundingBoxChanged()), this, SLOT(resetBoundingBox()), Qt::QueuedConnection);
    189   connect (this, SIGNAL(IdChanged()), this, SLOT(resetIndex()), Qt::QueuedConnection);
    190   connect (this, SIGNAL(AtomInserted(const atomId_t)), this, SLOT(atomInserted(const atomId_t)), Qt::QueuedConnection);
    191   connect (this, SIGNAL(AtomInserted(const atomId_t)), this, SLOT(resetAtoms()), Qt::QueuedConnection);
    192   connect (this, SIGNAL(AtomRemoved(const atomId_t)), this, SLOT(resetAtoms()), Qt::QueuedConnection);
    193   connect (this, SIGNAL(AtomRemoved(const atomId_t)), this, SLOT(atomRemoved(const atomId_t)), Qt::QueuedConnection);
    194 
    195   connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
    196 }
    197 
    198192GLMoleculeObject_molecule::~GLMoleculeObject_molecule()
    199193{
    200194  deactivateObserver();
    201   destroyObservedValues(ObservedValues);
     195  board->returnMoleculeObservedValues(getMolIndex(), ObservedValues);
    202196}
    203197
     
    205199{
    206200  if (owner != NULL) {
    207     owner->signOff(this, molecule::AtomInserted);
    208     owner->signOff(this, molecule::AtomRemoved);
    209     owner->signOff(this, molecule::AtomMoved);
    210     owner->signOff(this, molecule::IndexChanged);
     201    Observable::channels_t channels = getAllAtomicObservedChannels();
     202    for (Observable::channels_t::const_iterator iter = channels.begin();
     203        iter != channels.end(); ++iter)
     204      owner->signOff(this, *iter);
    211205    owner = NULL;
     206    signedOnChannels = 0;
    212207  }
    213208}
     
    218213  const molecule * const _molecule = getMolecule(getMolIndex());
    219214  if (_molecule != NULL) {
     215    Observable::channels_t channels = getAllAtomicObservedChannels();
    220216    owner = static_cast<const Observable *>(_molecule);
    221     owner->signOn(this, molecule::AtomInserted);
    222     owner->signOn(this, molecule::AtomRemoved);
    223     owner->signOn(this, molecule::AtomMoved);
    224     owner->signOn(this, molecule::IndexChanged);
     217    for (Observable::channels_t::const_iterator iter = channels.begin();
     218        iter != channels.end(); ++iter)
     219      owner->signOn(this, *iter);
    225220  } else {
    226221    ELOG(1, "GLMoleculeObject_molecule() - added null object for not present mol id " << getMolIndex());
     
    244239    BondsinSceneMap[ids]->resetWidth();
    245240  }
    246 }
    247 
    248 void GLMoleculeObject_molecule::addAtomBonds(
    249     const atomId_t _id)
    250 {
    251   const atom * const Walker = const_cast<const World &>(World::getInstance()).
    252       getAtom(AtomById(_id));
    253   if (Walker != NULL) {
    254     const bool atom_present = AtomsinSceneMap.count(_id);
    255     const BondList &bondlist = Walker->getListOfBonds();
    256     for (BondList::const_iterator bonditer = bondlist.begin();
    257         (bonditer != bondlist.end()) && atom_present;
    258         ++bonditer) {
    259       const bond::ptr _bond = *bonditer;
    260       // check if OtherAtom's sphere is already present
    261       const atom *OtherAtom = _bond->GetOtherAtom(Walker);
    262       const bool otheratom_present = AtomsinSceneMap.count(OtherAtom->getId());
    263       if (otheratom_present && atom_present) {
    264         const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == Walker) ?
    265             GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
    266         const GLMoleculeObject_bond::SideOfBond otherside = (_bond->leftatom == Walker) ?
    267             GLMoleculeObject_bond::right : GLMoleculeObject_bond::left;
    268         addAtomBonds(_bond, side);
    269         addAtomBonds(_bond, otherside);
    270       }
    271     }
    272   } else
    273     ELOG(1, "GLMoleculeObject_atom disappeared while about to add bonds.");
    274241}
    275242
     
    389356}
    390357
    391 void GLMoleculeObject_molecule::resetAtoms()
    392 {
    393   const atoms_t atoms = getPresentAtoms();
    394   std::vector<atomId_t> InsertedAtoms;
    395   std::vector<atomId_t> RemovedAtoms;
    396   // obtain all newly inserted and removed atoms
    397   std::set_difference(
    398       atoms.begin(), atoms.end(),
    399       DisplayedAtoms.begin(), DisplayedAtoms.end(),
    400       std::back_inserter(InsertedAtoms));
    401   std::set_difference(
    402       DisplayedAtoms.begin(), DisplayedAtoms.end(),
    403       atoms.begin(), atoms.end(),
    404       std::back_inserter(RemovedAtoms));
    405   // remove the atoms
    406   std::for_each(RemovedAtoms.begin(), RemovedAtoms.end(),
    407       boost::bind(&GLMoleculeObject_molecule::atomRemoved, this, _1));
    408   // insert the atoms
    409   std::for_each(InsertedAtoms.begin(), InsertedAtoms.end(),
    410       boost::bind(&GLMoleculeObject_molecule::atomInserted, this, _1));
    411   DisplayedAtoms = atoms;
    412 
    413   emit changed();
    414 }
    415 
    416358void GLMoleculeObject_molecule::resetIndex()
    417359{
     
    479421void GLMoleculeObject_molecule::subjectKilled(Observable *publisher)
    480422{
    481   // remove owner: no more signOff needed
    482   owner = NULL;
    483 
    484   countsubjectKilled(getMolIndex());
     423  ++signedOnChannels;
     424
     425  if (signedOnChannels == AllsignedOnChannels) {
     426    // remove owner: no more signOff needed
     427    owner = NULL;
     428
     429    board->moleculecountsubjectKilled(getMolIndex());
     430  }
    485431}
    486432
     
    492438    return;
    493439  if (publisher == dynamic_cast<const Observable*>(_molecule)){
    494     // notofication from atom
     440    // notification from atom
    495441#ifdef LOG_OBSERVER
    496442    observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this))
     
    500446    switch (notification->getChannelNo()) {
    501447      case molecule::AtomInserted:
    502       {
    503         const atomId_t _id = _molecule->lastChangedAtomId();
    504   #ifdef LOG_OBSERVER
    505         observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted.";
    506   #endif
    507         emit AtomInserted(_id);
    508         emit TesselationHullChanged();
    509         emit BoundingBoxChanged();
    510         break;
    511       }
    512       case World::AtomRemoved:
    513       {
    514 //        const atomId_t _id = _molecule->lastChangedAtomId();
    515   #ifdef LOG_OBSERVER
    516         observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been removed.";
    517   #endif
    518         emit TesselationHullChanged();
    519         emit BoundingBoxChanged();
    520         break;
    521       }
     448      case molecule::AtomRemoved:
    522449      case molecule::AtomMoved:
    523450      {
    524451  #ifdef LOG_OBSERVER
    525         const atomId_t _id = _molecule->lastChangedAtomId();
    526452        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted.";
    527453  #endif
     
    638564  LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomInserted for atom "+toString(_id)+".");
    639565
    640   GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(GLMoleculeObject::meshSphere, this, _id);
     566  GLMoleculeObject_atom *atomObject =
     567      new GLMoleculeObject_atom(
     568          GLMoleculeObject::meshSphere,
     569          this,
     570          _id,
     571          board,
     572          board->getAtomObservedValues(_id));
    641573  ASSERT( atomObject != NULL,
    642574      "GLMoleculeObject_molecule::atomInserted - could not create atom object for "+toString(_id));
     
    657589  connect (atomObject, SIGNAL(BondsRemoved(const atomId_t, const atomId_t)), this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
    658590  connect (atomObject, SIGNAL(indexChanged(GLMoleculeObject_atom*, const atomId_t, const atomId_t)), this, SLOT(changeAtomId(GLMoleculeObject_atom*, const atomId_t, const atomId_t)));
    659   connect (atomObject, SIGNAL(InstanceRemoved(const atomId_t)), this, SIGNAL(AtomRemoved(const atomId_t)));
    660591
    661592  if (m_objectId  == -1)
    662593    setObjectId(_id);
    663594
    664   // add all bonds
    665   addAtomBonds(_id);
    666 
     595  emit changed();
    667596  emit changeOccured();
    668597}
     
    691620  delete atomObject;
    692621
     622  emit changed();
    693623  emit changeOccured();
    694624}
     
    766696    iter->second->resetWidth();
    767697  }
     698  emit changed();
    768699  emit changeOccured();
    769700}
     
    790721  }
    791722
     723  emit changed();
    792724  emit changeOccured();
    793725}
     
    800732  // then emit onward
    801733  GLMoleculeObject::setVisible(value);
     734
     735  emit changed();
     736  emit changeOccured();
    802737}
    803738
     
    844779      getMolecule(MoleculeById(_id));
    845780  return mol;
    846 }
    847 
    848 void GLMoleculeObject_molecule::countsubjectKilled(const moleculeId_t)
    849 {
    850   ++subjectKilledCount;
    851 
    852   if (subjectKilledCount > ObservedValues.size())
    853     emit InstanceRemoved(getMolIndex());
    854781}
    855782
     
    911838      _subjectKilled,
    912839      MolIndexGetter);
    913   _ObservedValues[PresentAtoms] = new ObservedValue_UpdateAtoms(
    914       _molref,
    915       "MoleculeAtoms_"+toString(_molid),
    916       AtomsChannels,
    917       _subjectKilled,
    918       MolIndexGetter);
    919840}
    920841
     
    925846  delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[MolName]);
    926847  delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(_ObservedValues[BoundingBox]);
    927   delete boost::any_cast<ObservedValue_UpdateAtoms *>(_ObservedValues[PresentAtoms]);
    928848  _ObservedValues.clear();
    929849}
     
    946866GLMoleculeObject_molecule::atoms_t GLMoleculeObject_molecule::getPresentAtoms() const
    947867{
    948   return boost::any_cast<ObservedValue_UpdateAtoms *>(ObservedValues[PresentAtoms])->get();
    949 }
     868  atoms_t returnAtomIds;
     869  returnAtomIds.insert(
     870      MapKeyConstIterator<AtomNodeMap::const_iterator>(const_cast<const AtomNodeMap &>(AtomsinSceneMap).begin()),
     871      MapKeyConstIterator<AtomNodeMap::const_iterator>(const_cast<const AtomNodeMap &>(AtomsinSceneMap).end()));
     872  return returnAtomIds;
     873}
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp

    r47f0e4 r8d5fbf1  
    4242  GLMoleculeObject_molecule(
    4343      QObject *parent,
    44       const moleculeId_t molid);
     44      const moleculeId_t molid,
     45      QtInstanceInformationBoard * _board,
     46      std::vector<boost::any> _ObservedValues);
    4547  GLMoleculeObject_molecule(
    4648      QGLSceneNode *mesh[],
    4749      QObject *parent,
    48       const moleculeId_t molid);
     50      const moleculeId_t molid,
     51      QtInstanceInformationBoard * _board,
     52      std::vector<boost::any> _ObservedValues);
    4953  virtual ~GLMoleculeObject_molecule();
    5054
     
    7882  void AtomRemoved(const atomId_t _id);
    7983  void IdChanged();
    80   void InstanceRemoved(const moleculeId_t);
    8184
    8285private slots:
     
    99102  void resetTesselationHull();
    100103  void resetBoundingBox();
    101   void resetAtoms();
    102104  void resetIndex();
    103105  void resetName();
     
    111113  static const molecule * const getMolecule(const moleculeId_t _id);
    112114
     115  void init(const moleculeId_t _molid);
     116
    113117private:
    114118  void addAtomBonds(
     
    116120      const GLMoleculeObject_bond::SideOfBond _side
    117121      );
    118   void addAtomBonds(const atomId_t _id);
    119122
    120123  //!> typedef for the internal set of atoms
     
    130133      const boost::function<const moleculeId_t ()> &_getMolIndex);
    131134
     135  /** Getter to contained atoms contained in \a ObservedValues.
     136   *
     137   * \return molecule's contained atoms
     138   */
     139  atoms_t getPresentAtoms() const;
     140
    132141  //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
    133142  const Observable * owner;
     
    136145  const molecule * const molref;
    137146
    138   //!> list of channels when contained atoms needs to update
    139   static const Observable::channels_t AtomsChannels;
    140147  //!> list of channels when tesselation hull needs to update
    141148  static const Observable::channels_t HullChannels;
     
    159166    //!> contains newest version of the bounding box on request
    160167    BoundingBox,
    161     //!> contains the current live set of atoms for the molecule
    162     PresentAtoms,
    163168    //!> gives the size of the enumeration
    164169    MAX_ObservedTypes
     
    206211  molecule::BoundingBoxInfo getBoundingBox() const;
    207212
    208   /** Getter to contained atoms contained in \a ObservedValues.
    209    *
    210    * \return molecule's contained atoms
    211    */
    212   atoms_t getPresentAtoms() const;
    213 
    214   /** Counts how many ObservedValues got subjectKilled.
    215    *
    216    * This is used to give InstanceRemoved() signal only when each and every
    217    * ObservedValue (and the instance itself) has been subjectKilled by the
    218    * monitored Observable. Only then can we safely remove the instance.
    219    *
    220    * \param _molid molecule id who signalled subjectKilled()
    221    */
    222   void countsubjectKilled(const moleculeId_t _molid);
    223 
    224213  //!> counts how many ObservedValues have already been subjectKilled()
    225214  mutable size_t subjectKilledCount;
     
    241230
    242231  atomId_t hoverAtomId;
     232
     233  //!> we get multiple subjectKilled(), count and call callback() only on last
     234  const unsigned int AllsignedOnChannels;
     235  unsigned int signedOnChannels;
     236
     237  QtInstanceInformationBoard * board;
    243238};
    244239
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    r47f0e4 r8d5fbf1  
    9494    GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
    9595  }
    96   connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)),
    97       this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)));
    9896  connect(board, SIGNAL(moleculeInserted(const moleculeId_t)),
    9997      this, SLOT(moleculeInserted(const moleculeId_t)));
     
    102100  connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)),
    103101      this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)));
     102  connect(board, SIGNAL(atomInserted(const moleculeId_t, const atomId_t)),
     103      this, SLOT(atomInserted(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
     104  connect(board, SIGNAL(atomRemoved(const moleculeId_t, const atomId_t)),
     105      this, SLOT(atomRemoved(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
    104106
    105107//  connect(this, SIGNAL(updated()), this, SLOT(update()));
     
    199201
    200202  // check of molecule is already present
    201   if (MoleculesinSceneMap.count(_molid) != 0) {
     203  MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid);
     204  if (moliter != MoleculesinSceneMap.end()) {
    202205    // pass signal through
     206    GLMoleculeObject_molecule *molObject = moliter->second;
     207    QMetaObject::invokeMethod(molObject,        // pointer to a QObject
     208                              "atomInserted",       // member name (no parameters here)
     209                              Qt::QueuedConnection,     // connection type
     210                              Q_ARG(const atomId_t, _atomid));     // parameters
    203211  } else {
    204212    // store signal for when it is instantiated
     
    221229
    222230  // check of molecule is already present
    223   if (MoleculesinSceneMap.count(_molid) != 0) {
     231  MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid);
     232  if (moliter != MoleculesinSceneMap.end()) {
    224233    // pass signal through
     234    GLMoleculeObject_molecule *molObject = moliter->second;
     235    QMetaObject::invokeMethod(molObject,        // pointer to a QObject
     236                              "atomRemoved",       // member name (no parameters here)
     237                              Qt::QueuedConnection,     // connection type
     238                              Q_ARG(const atomId_t, _atomid));     // parameters
    225239  } else {
    226240    // store signal for when it is instantiated
     
    259273  GLMoleculeObject_molecule *molObject =
    260274      new GLMoleculeObject_molecule(
    261           GLMoleculeObject::meshEmpty, this, _id);
     275          GLMoleculeObject::meshEmpty,
     276          this,
     277          _id,
     278          board,
     279          board->getMoleculeObservedValues(_id));
    262280  ASSERT( molObject != NULL,
    263281      "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(_id));
     
    290308          QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    291309                                    "atomInserted",       // member name (no parameters here)
    292                                     Qt::DirectConnection,     // connection type
     310                                    Qt::QueuedConnection,     // connection type
    293311                                    Q_ARG(const atomId_t, iter->first));     // parameters
    294312        } else {
     
    307325            QMetaObject::invokeMethod(molObject,        // pointer to a QObject
    308326                                      "atomInserted",       // member name (no parameters here)
    309                                       Qt::DirectConnection,     // connection type
     327                                      Qt::QueuedConnection,     // connection type
    310328                                      Q_ARG(const atomId_t, iter->first));     // parameters
    311329            break;
     
    323341  }
    324342
    325   // now let the molObject sign on to molecule
    326   molObject->activateObserver();
    327 
    328343  connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
    329344  connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
     
    335350  connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
    336351  connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
     352  connect(board, SIGNAL(atomInserted(const atomId_t)),
     353      molObject, SLOT(atomInserted(const atomId_t)));
     354  connect(board, SIGNAL(atomRemoved(const atomId_t)),
     355      molObject, SLOT(atomRemoved(const atomId_t)));
    337356
    338357  emit changed();
Note: See TracChangeset for help on using the changeset viewer.