Ignore:
Timestamp:
Jul 25, 2015, 1:01:20 PM (10 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:
f759e5
Parents:
8923ad8
git-author:
Frederik Heber <heber@…> (06/11/15 07:33:58)
git-committer:
Frederik Heber <heber@…> (07/25/15 13:01:20)
Message:

FIX: GLWorldScene/View capture all missed signals for each GLMoleculeObject_molecule.

  • Taking note of subscribed molecules to sign Off on GLWorldView's destruct.
  • GLWorldView::recieveNotification() is checking for whether molecule actually exists still.
File:
1 edited

Legend:

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

    r8923ad8 r9c259e  
    5959#include "CodePatterns/Observer/Notification.hpp"
    6060#include "CodePatterns/Observer/ObserverLog.hpp"
     61#include "Descriptors/MoleculeIdDescriptor.hpp"
    6162#include "molecule.hpp"
    6263#include "Shapes/ShapeRegistry.hpp"
     
    9091  connect(worldscene, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SLOT(sceneHoverSignalled(const moleculeId_t, int)));
    9192  connect(this, SIGNAL(worldSelectionChanged()), worldscene, SLOT(worldSelectionChanged()));
    92   connect(this, SIGNAL(moleculeRemoved(const moleculeId_t)), worldscene, SLOT(moleculeRemoved(const moleculeId_t)));
    93   connect(this, SIGNAL(moleculeInserted(const moleculeId_t)), worldscene, SLOT(moleculeInserted(const moleculeId_t)));
     93  connect(this, SIGNAL(atomRemoved(const moleculeId_t, const atomId_t)), worldscene, SLOT(atomRemoved(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
     94  connect(this, SIGNAL(atomInserted(const moleculeId_t, const atomId_t)), worldscene, SLOT(atomInserted(const moleculeId_t, const atomId_t)), Qt::DirectConnection);
     95  connect(this, SIGNAL(moleculeRemoved(const moleculeId_t)), worldscene, SLOT(moleculeRemoved(const moleculeId_t)), Qt::DirectConnection);
     96  connect(this, SIGNAL(moleculeInserted(const moleculeId_t)), worldscene, SLOT(moleculeInserted(const moleculeId_t)), Qt::DirectConnection);
    9497  //connect(this, SIGNAL(changed()), this, SLOT(updateGL()));
    9598  connect(this, SIGNAL(changed()), this, SLOT(sceneChangeSignalled()));
     
    114117GLWorldView::~GLWorldView()
    115118{
     119  // remove me from all observed molecules
     120  for (ObservedMolecules_t::iterator iter = ObservedMolecules.begin();
     121      !ObservedMolecules.empty();
     122      iter = ObservedMolecules.begin())
     123    signOffFromMolecule(*iter);
     124
    116125  QSettings settings;
    117126  settings.beginGroup("WorldView");
     
    324333}
    325334
     335void GLWorldView::signOnToMolecule(const molecule *_mol)
     336{
     337  ASSERT( _mol != NULL,
     338      "GLWorldView::signOnToMolecule() - molecule ref is NULL.");
     339  _mol->signOn(this, molecule::AtomInserted);
     340  _mol->signOn(this, molecule::AtomRemoved);
     341
     342  ObservedMolecules.insert(const_cast<molecule *>(_mol));
     343}
     344
     345void GLWorldView::signOffFromMolecule(const molecule *_mol)
     346{
     347  ObservedMolecules_t::const_iterator iter = ObservedMolecules.find(
     348      const_cast<molecule *>(_mol));
     349  ASSERT( iter != ObservedMolecules.end(),
     350      "GLWorldView::signOffFromMolecule() - molecule "+toString(_mol)
     351      +" gave subjectKilled we are not signed on.");
     352//    LOG(1, "INFO: Erasing " << mol << " from ObservedMolecules.");
     353  ObservedMolecules.erase(iter);
     354
     355  ASSERT( _mol != NULL,
     356      "GLWorldView::signOffFromMolecule() - molecule ref is NULL.");
     357  _mol->signOff(this, molecule::AtomInserted);
     358  _mol->signOff(this, molecule::AtomRemoved);
     359}
     360
    326361/**
    327362 * The observable can tell when it dies.
    328363 */
    329 void GLWorldView::subjectKilled(Observable *publisher) {}
     364void GLWorldView::subjectKilled(Observable *publisher)
     365{
     366  molecule * mol = static_cast<molecule *>(publisher);
     367
     368//  std::copy(ObservedMolecules.begin(), ObservedMolecules.end(),
     369//      std::ostream_iterator<molecule *>(std::cout, "\n"));
     370
     371  if (mol != NULL) {
     372
     373    // sign off
     374    signOffFromMolecule(mol);
     375
     376    // emit removed signal
     377    const moleculeId_t _id = World::getInstance().lastChanged<molecule>()->getId();
     378    emit moleculeRemoved(_id);
     379  }
     380}
    330381
    331382/** Listen to specific changes to the world.
     
    352403        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that molecule "+toString(_id)+" has been inserted.";
    353404  #endif
    354         emit moleculeInserted(_id);
     405        const molecule * const _molecule = const_cast<const World &>(World::getInstance()).
     406            getMolecule(MoleculeById(_id));
     407        if (_molecule != NULL) {
     408          signOnToMolecule(_molecule);
     409
     410          emit moleculeInserted(_id);
     411        }
    355412        break;
    356413      }
     
    361418        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that molecule "+toString(_id)+" has been removed.";
    362419  #endif
     420        // removed from ObservedMolecules via subjectKilled
    363421        emit moleculeRemoved(_id);
    364422        break;
     
    383441        break;
    384442    }
    385 } else if (dynamic_cast<AtomObservable *>(publisher) != NULL) {
     443  } else if (dynamic_cast<molecule *>(publisher) != NULL) {
     444    const molecule * mol = const_cast<const molecule * const>(dynamic_cast<molecule *>(publisher));
     445    const atomId_t atomid = mol->lastChanged()->getId();
     446    const moleculeId_t molid = mol->getId();
     447    switch (notification->getChannelNo()) {
     448      case molecule::AtomInserted:
     449      {
     450#ifdef LOG_OBSERVER
     451        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this))
     452            << " received notification that atom "+toString(atomid)+" has been inserted into molecule "+toString(molid)+".";
     453#endif
     454        emit atomInserted(molid, atomid);
     455        break;
     456      }
     457      case World::AtomRemoved:
     458      {
     459#ifdef LOG_OBSERVER
     460        observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this))
     461            << " received notification that atom "+toString(atomid)+" has been removed from molecule "+toString(molid)+".";
     462#endif
     463        emit atomRemoved(molid, atomid);
     464        break;
     465      }
     466      default:
     467        ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here for molecule.");
     468        break;
     469    }
     470  } else if (dynamic_cast<AtomObservable *>(publisher) != NULL) {
    386471    switch (notification->getChannelNo()) {
    387472      case AtomObservable::PositionChanged:
Note: See TracChangeset for help on using the changeset viewer.