Ignore:
Timestamp:
Feb 12, 2016, 11:15:05 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:
16bd37
Parents:
7a205a
git-author:
Frederik Heber <heber@…> (10/17/15 12:40:14)
git-committer:
Frederik Heber <heber@…> (02/12/16 23:15:05)
Message:

GLMoleculeObject_molecule's ObservedValues is now all static.

  • this is preparatory for extracting their instantation to an external class InstanceInformationBoard that keeps track of the lives of instances in the World that are needed inside QtGui (e.g. for visual representation).
Location:
src/UIElements/Views/Qt4/Qt3D
Files:
1 added
2 edited

Legend:

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

    r7a205a r8688ef  
    6565
    6666#include "ObservedValue_wCallback.hpp"
     67#include "ObservedValue_UpdateAtoms.hpp"
    6768
    6869using namespace boost::assign;
     
    109110   * the class has not been fully constructed yet. "This" itself seems to be working fine.
    110111   */
    111   MolIndexUpdater(
    112       boost::bind(&GLMoleculeObject_molecule::updateIndex, this)
    113       ),
    114   MolNameUpdater(
    115       boost::bind(&GLMoleculeObject_molecule::updateName, this)
    116       ),
     112  ObservedValues(MAX_ObservedTypes),
     113  subjectKilledCount(0),
    117114  TesselationHullUpdater(
    118115      boost::bind(&GLMoleculeObject_molecule::updateTesselationHull, this)
    119116      ),
    120   BoundingBoxUpdater(
    121       boost::bind(&GLMoleculeObject_molecule::updateBoundingBox, this)
    122       ),
    123   PresentAtomsUpdater(
    124       boost::bind(&GLMoleculeObject_molecule::updateAtoms, this)
    125       ),
    126   ObservedValues(MAX_ObservedTypes),
    127   subjectKilledCount(0),
    128117  TesselationHull(
    129118      molref,
     
    133122  hoverAtomId(-1)
    134123{
    135   initObservedValues(_molid);
     124  boost::function<void()> subjectKilled =
     125      boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this);
     126  initObservedValues(ObservedValues, _molid, molref, subjectKilled);
    136127
    137128  setObjectId(_molid);
     
    166157   * the class has not been fully constructed yet. "This" itself seems to be working fine.
    167158   */
    168   MolIndexUpdater(
    169       boost::bind(&GLMoleculeObject_molecule::updateIndex, this)
    170       ),
    171   MolNameUpdater(
    172       boost::bind(&GLMoleculeObject_molecule::updateName, this)
    173       ),
     159  ObservedValues(MAX_ObservedTypes),
     160  subjectKilledCount(0),
    174161  TesselationHullUpdater(
    175162      boost::bind(&GLMoleculeObject_molecule::updateTesselationHull, this)
    176163      ),
    177   BoundingBoxUpdater(
    178       boost::bind(&GLMoleculeObject_molecule::updateBoundingBox, this)
    179       ),
    180   PresentAtomsUpdater(
    181       boost::bind(&GLMoleculeObject_molecule::updateAtoms, this)
    182       ),
    183   ObservedValues(MAX_ObservedTypes),
    184   subjectKilledCount(0),
    185164  TesselationHull(
    186165      molref,
     
    190169  hoverAtomId(-1)
    191170{
    192   initObservedValues(_molid);
     171  boost::function<void()> subjectKilled =
     172      boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this);
     173  initObservedValues(ObservedValues, _molid, molref, subjectKilled);
    193174
    194175  setObjectId(_molid);
     
    216197{
    217198  deactivateObserver();
    218   destroyObservedValues();
     199  destroyObservedValues(ObservedValues);
    219200}
    220201
     
    366347}
    367348
    368 molecule::BoundingBoxInfo GLMoleculeObject_molecule::initBoundingBox() const
     349molecule::BoundingBoxInfo GLMoleculeObject_molecule::initBoundingBox()
    369350{
    370351  molecule::BoundingBoxInfo info;
     
    374355}
    375356
    376 molecule::BoundingBoxInfo GLMoleculeObject_molecule::updateBoundingBox() const
    377 {
    378   return getBoundingBox();
    379 }
    380 
    381 GLMoleculeObject_molecule::atoms_t GLMoleculeObject_molecule::updateAtoms()
    382 {
    383   atoms_t current_atomset = getPresentAtoms();
    384   const molecule * const mol = getMolecule(getMolIndex());
    385   if (mol != NULL) {
    386     const atomId_t id = mol->lastChangedAtomId();
    387     if (mol->containsAtom(id))
    388       current_atomset.insert(id);
    389     else
    390       current_atomset.erase(id);
    391   }
    392   return current_atomset;
    393 }
    394 
    395 moleculeId_t GLMoleculeObject_molecule::updateIndex() const
     357molecule::BoundingBoxInfo GLMoleculeObject_molecule::updateBoundingBox(
     358    const boost::function<const moleculeId_t ()> &_getMolIndex)
     359{
     360  const molecule * const mol = getMolecule(_getMolIndex());
     361  return mol->getBoundingBox();
     362}
     363
     364moleculeId_t GLMoleculeObject_molecule::updateIndex()
    396365{
    397366  return const_cast<const World &>(World::getInstance()).lastChangedMolId();
    398367}
    399368
    400 std::string GLMoleculeObject_molecule::updateName() const
    401 {
    402   const molecule * const mol = getMolecule(getMolIndex());
     369std::string GLMoleculeObject_molecule::updateName(
     370    const boost::function<const moleculeId_t ()> &_getMolIndex)
     371{
     372  const molecule * const mol = getMolecule(_getMolIndex());
    403373  return mol->getName();
    404374}
     
    540510      case World::AtomRemoved:
    541511      {
    542         const atomId_t _id = _molecule->lastChangedAtomId();
     512//        const atomId_t _id = _molecule->lastChangedAtomId();
    543513  #ifdef LOG_OBSERVER
    544514        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been removed.";
     
    882852}
    883853
    884 void GLMoleculeObject_molecule::initObservedValues(const moleculeId_t _molid)
    885 {
    886   // fill ObservedValues
    887   boost::function<void()> subjectKilled =
    888       boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this);
    889   ObservedValues[MolIndex] = new ObservedValue_wCallback<moleculeId_t>(
    890       molref,
    891       MolIndexUpdater,
    892       "MoleculeIndex_"+toString(_molid),
    893       _molid,
    894       IndexChannels,
    895       subjectKilled);
    896   ObservedValues[MolName] = new ObservedValue_wCallback<std::string>(
    897       molref,
     854void GLMoleculeObject_molecule::initObservedValues(
     855    std::vector<boost::any> &_ObservedValues,
     856    const moleculeId_t _molid,
     857    const molecule * const _molref,
     858    const boost::function<void()> &_subjectKilled)
     859{
     860  /* This is an old note from when the code was still part of cstor's initializer body.
     861   * TODO: Probably does not apply anymore but has not yet been tested.
     862   *
     863   * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly
     864   * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because
     865   * the class has not been fully constructed yet. "This" itself seems to be working fine.
     866   */
     867
     868  ASSERT( _ObservedValues.size() == MAX_ObservedTypes,
     869      "GLMoleculeObject_molecule::initObservedValues() - given ObservedValues has not correct size.");
     870
     871  // fill ObservedValues: index first
     872  const boost::function<moleculeId_t ()> MolIndexUpdater(
     873      boost::bind(&GLMoleculeObject_molecule::updateIndex));
     874
     875  ObservedValue_wCallback<moleculeId_t> * const IndexObservable =
     876      new ObservedValue_wCallback<moleculeId_t>(
     877        _molref,
     878        MolIndexUpdater,
     879        "MoleculeIndex_"+toString(_molid),
     880        _molid,
     881        IndexChannels,
     882        _subjectKilled);
     883  _ObservedValues[MolIndex] = IndexObservable;
     884
     885  const boost::function<const moleculeId_t ()> MolIndexGetter =
     886      boost::bind(&ObservedValue_wCallback<moleculeId_t>::get,
     887          IndexObservable);
     888
     889  // fill ObservedValues: then all the other that need index
     890  const boost::function<std::string ()> MolNameUpdater(
     891      boost::bind(&GLMoleculeObject_molecule::updateName, MolIndexGetter));
     892  const boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater(
     893      boost::bind(&GLMoleculeObject_molecule::updateBoundingBox, MolIndexGetter));
     894
     895  _ObservedValues[MolName] = new ObservedValue_wCallback<std::string>(
     896      _molref,
    898897      MolNameUpdater,
    899898      "MoleculeName_"+toString(_molid),
    900       updateName(),
     899      MolNameUpdater(),
    901900      NameChannels,
    902       subjectKilled);
    903   ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo>(
    904       molref,
     901      _subjectKilled);
     902  _ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo>(
     903      _molref,
    905904      BoundingBoxUpdater,
    906905      "MoleculeBoundingBox_"+toString(_molid),
    907906      initBoundingBox(),
    908907      BoundingBoxChannels,
    909       subjectKilled);
    910   ObservedValues[PresentAtoms] = new ObservedValue_wCallback<atoms_t>(
    911       molref,
    912       PresentAtomsUpdater,
     908      _subjectKilled);
     909  _ObservedValues[PresentAtoms] = new ObservedValue_UpdateAtoms(
     910      _molref,
    913911      "MoleculeAtoms_"+toString(_molid),
    914       updateAtoms(),
    915912      AtomsChannels,
    916       subjectKilled);
    917 }
    918 
    919 void GLMoleculeObject_molecule::destroyObservedValues()
    920 {
    921   delete boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(ObservedValues[MolIndex]);
    922   delete boost::any_cast<ObservedValue_wCallback<std::string> *>(ObservedValues[MolName]);
    923   delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo> *>(ObservedValues[BoundingBox]);
    924   delete boost::any_cast<ObservedValue_wCallback<atoms_t> *>(ObservedValues[PresentAtoms]);
    925   ObservedValues.clear();
     913      _subjectKilled,
     914      MolIndexGetter);
     915}
     916
     917void GLMoleculeObject_molecule::destroyObservedValues(
     918    std::vector<boost::any> &_ObservedValues)
     919{
     920  delete boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(_ObservedValues[MolIndex]);
     921  delete boost::any_cast<ObservedValue_wCallback<std::string> *>(_ObservedValues[MolName]);
     922  delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo> *>(_ObservedValues[BoundingBox]);
     923  delete boost::any_cast<ObservedValue_UpdateAtoms *>(_ObservedValues[PresentAtoms]);
     924  _ObservedValues.clear();
    926925}
    927926
     
    943942GLMoleculeObject_molecule::atoms_t GLMoleculeObject_molecule::getPresentAtoms() const
    944943{
    945   return boost::any_cast<ObservedValue_wCallback<atoms_t> *>(ObservedValues[PresentAtoms])->get();
    946 }
     944  return boost::any_cast<ObservedValue_UpdateAtoms *>(ObservedValues[PresentAtoms])->get();
     945}
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp

    r7a205a r8688ef  
    2020#include <vector>
    2121#include <boost/any.hpp>
     22#include <boost/function.hpp>
    2223
    2324#include "CodePatterns/Cacheable.hpp"
     
    114115  typedef std::set<atomId_t> atoms_t;
    115116
    116   molecule::BoundingBoxInfo initBoundingBox() const;
     117  static molecule::BoundingBoxInfo initBoundingBox();
    117118
    118119  QGeometryData updateTesselationHull() const;
    119   molecule::BoundingBoxInfo updateBoundingBox() const;
    120   atoms_t updateAtoms();
    121   moleculeId_t updateIndex() const;
    122   std::string updateName() const;
     120  static molecule::BoundingBoxInfo updateBoundingBox(
     121      const boost::function<const moleculeId_t ()> &_getMolIndex);
     122  static moleculeId_t updateIndex();
     123  static std::string updateName(
     124      const boost::function<const moleculeId_t ()> &_getMolIndex);
    123125
    124126  //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
     
    138140  //!> list of channels when the name needs to update
    139141  static const Observable::channels_t NameChannels;
    140 
    141   boost::function<moleculeId_t ()> MolIndexUpdater;
    142   boost::function<std::string ()> MolNameUpdater;
    143   boost::function<QGeometryData ()> TesselationHullUpdater;
    144   boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater;
    145   boost::function<atoms_t ()> PresentAtomsUpdater;
    146142
    147143private:
     
    165161  std::vector<boost::any> ObservedValues;
    166162
    167   /** Initializes all \a ObservedValues entries.
    168    *
     163  /** Initializes all \a _ObservedValues entries.
     164   *
     165   * \param _ObservedValues vector of ObservedValue to be filled
    169166   * \param _moid molecule id
    170    */
    171   void initObservedValues(const moleculeId_t _molid);
     167   * \param _molref reference to molecule
     168   * \param _subjectKilled ref to function to call on subjectKilled()
     169   */
     170  static void initObservedValues(
     171      std::vector<boost::any> &_ObservedValues,
     172      const moleculeId_t _molid,
     173      const molecule * const _molref,
     174      const boost::function<void()> &_subjectKilled);
    172175
    173176  /** Destroys all \a ObservedValues entries.
    174177   *
    175    */
    176   void destroyObservedValues();
     178   * \param _ObservedValues vector of ObservedValue to be destroyed
     179   */
     180  static void destroyObservedValues(
     181      std::vector<boost::any> &_ObservedValues);
    177182
    178183  /** Getter to molecule index contained in \a ObservedValues.
     
    212217  mutable size_t subjectKilledCount;
    213218
     219private:
     220
     221  boost::function<QGeometryData ()> TesselationHullUpdater;
     222
    214223  //!> contains current version of the tesselation hull on request
    215224  Cacheable<QGeometryData> TesselationHull;
    216225
    217 private:
    218226  //!> contains the set of atoms displayed
    219227  atoms_t DisplayedAtoms;
Note: See TracChangeset for help on using the changeset viewer.