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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.