Ignore:
Timestamp:
Apr 20, 2016, 7:17:41 AM (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, Candidate_v1.7.0, Candidate_v1.7.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:
1a58ce
Parents:
bff202
git-author:
Frederik Heber <heber@…> (03/21/16 20:42:05)
git-committer:
Frederik Heber <heber@…> (04/20/16 07:17:41)
Message:

Introduced unique and permanent ObservedValue_Index_t.

  • this is currently the address of the observable which is not perfectly secure but might work for the moment.
  • QtObservedInstanceBoard uses the index internally and only has an additional map to serve instances on request for the their atomId_t, moleculeId_t, .... However, this id should nowhere else be used because it may change during the lifetime of the object.
  • this should prevent the hazzle with the possibly changing atomId_t, moleculeId_t, ... in all classes that work with QtObserved... instances.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    rbff202 r59eabc  
    6767      boost::bind(&QtObservedInstanceBoard::moleculecountsubjectKilled, this, _1))
    6868{
     69  qRegisterMetaType<ObservedValue_Index_t>("ObservedValue_Index_t");
    6970  qRegisterMetaType<QtObservedAtom::ptr>("QtObservedAtom::ptr");
    7071  qRegisterMetaType<QtObservedMolecule::ptr>("QtObservedMolecule::ptr");
     
    141142                  *this));
    142143          observedmolecule->setSelfRef(observedmolecule);
    143           moleculeObservedValues.insert(_id, observedmolecule);
     144          const ObservedValue_Index_t index = static_cast<const Observable *>(_molecule);
     145          moleculeObservedValues.insert(index, observedmolecule);
     146          moleculeids_lookup.insert( std::make_pair(_id, index) );
    144147          // we need to check for index changes
    145148          LOG(3, "DEBUG: InformationBoard signOn()s to molecule " << _id);
     
    167170              new QtObservedAtom(_id, _atom, *this));
    168171          observedatom->setSelfRef(observedatom);
    169           atomObservedValues.insert(_id, observedatom);
     172          const ObservedValue_Index_t index = static_cast<const Observable *>(_atom);
     173          atomObservedValues.insert(index, observedatom);
     174          atomids_lookup.insert( std::make_pair(_id, index) );
    170175          // we need to check for index changes
    171176          LOG(3, "DEBUG: InformationBoard signOn()s to atom " << _id);
     
    190195        const moleculeId_t newmoleculeId = dynamic_cast<molecule *>(publisher)->getId();
    191196        LOG(3, "DEBUG: InformationBoard got IndexChanged from molecule " << molid << " to " << newmoleculeId);
    192 #ifndef NDEBUG
    193         bool status =
    194 #endif
    195         moleculeObservedValues.changeIdentifier(molid, newmoleculeId);
    196         ASSERT( status,
    197             "QtObservedInstanceBoard::recieveNotification() - cannot change molecule's id "
    198             +toString(molid)+" "+toString(newmoleculeId)+" in moleculeObservedValues.");
     197        {
     198          typename IdtoIndex_t<moleculeId_t>::iterator iter = moleculeids_lookup.find(molid);
     199          ASSERT( iter != moleculeids_lookup.end(),
     200              "QtObservedInstanceBoard::recieveNotification() - mol id "
     201              +toString(molid)+" unknown to lookup.");
     202          const ObservedValue_Index_t index = iter->second;
     203          moleculeids_lookup.erase(iter);
     204          moleculeids_lookup.insert( std::pair<moleculeId_t, ObservedValue_Index_t>(newmoleculeId, index) );
     205        }
    199206        // no need update SignedOn, ref does not change
    200207        emit moleculeIndexChanged(molid, newmoleculeId);
     
    212219        const atomId_t newatomId = dynamic_cast<atom *>(publisher)->getId();
    213220        LOG(3, "DEBUG: InformationBoard got IndexChanged from atom " << oldatomId << " to " << newatomId);
    214 #ifndef NDEBUG
    215         bool status =
    216 #endif
    217         atomObservedValues.changeIdentifier(oldatomId, newatomId);
    218         ASSERT( status,
    219             "QtObservedInstanceBoard::recieveNotification() - cannot change atom's id "
    220             +toString(oldatomId)+" "+toString(newatomId)+" in atomObservedValues.");
     221        {
     222          typename IdtoIndex_t<atomId_t>::iterator iter = atomids_lookup.find(oldatomId);
     223          ASSERT( iter != atomids_lookup.end(),
     224              "QtObservedInstanceBoard::recieveNotification() - atom id "
     225              +toString(oldatomId)+" unknown to lookup.");
     226          const ObservedValue_Index_t index = iter->second;
     227          atomids_lookup.erase(iter);
     228          atomids_lookup.insert( std::pair<atomId_t, ObservedValue_Index_t>(newatomId, index) );
     229        }
    221230        // no need update SignedOn, ref does not change
    222231        emit atomIndexChanged(oldatomId, newatomId);
     
    232241}
    233242
    234 void QtObservedInstanceBoard::atomcountsubjectKilled(const atomId_t _atomid)
    235 {
    236   LOG(3, "DEBUG: InstanceBoard emits atomRemoved for " << _atomid);
    237   emit atomRemoved(_atomid);
    238 }
    239 
    240 void QtObservedInstanceBoard::moleculecountsubjectKilled(const moleculeId_t _molid)
    241 {
    242   LOG(3, "DEBUG: InstanceBoard emits moleculeRemoved for " << _molid);
    243   emit moleculeRemoved(_molid);
     243void QtObservedInstanceBoard::atomcountsubjectKilled(ObservedValue_Index_t _id)
     244{
     245  LOG(3, "DEBUG: InstanceBoard emits atomRemoved for " << _id);
     246  emit atomRemoved(_id);
     247}
     248
     249void QtObservedInstanceBoard::moleculecountsubjectKilled(ObservedValue_Index_t _id)
     250{
     251  LOG(3, "DEBUG: InstanceBoard emits moleculeRemoved for " << _id);
     252  emit moleculeRemoved(_id);
    244253}
    245254
    246255QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(const atomId_t _id)
    247256{
    248   return atomObservedValues.get(_id);
    249 }
    250 
    251 QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(const Observable * _obs)
    252 {
    253   const atom * walker = dynamic_cast<const atom *>(_obs);
    254   return atomObservedValues.get(walker->getId());
     257  return atomObservedValues.get(atomids_lookup[_id]);
    255258}
    256259
    257260QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const moleculeId_t _id)
    258261{
    259   return moleculeObservedValues.get(_id);
    260 }
    261 
    262 QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const Observable * _obs)
    263 {
    264   const molecule * mol = dynamic_cast<const molecule *>(_obs);
    265   return moleculeObservedValues.get(mol->getId());
    266 }
    267 
    268 void QtObservedInstanceBoard::markObservedAtomAsConnected(const atomId_t _id)
     262  return moleculeObservedValues.get(moleculeids_lookup[_id]);
     263}
     264
     265void QtObservedInstanceBoard::markObservedAtomAsConnected(ObservedValue_Index_t _id)
    269266{
    270267  atomObservedValues.markObservedValuesAsConnected(_id);
    271268}
    272269
    273 void QtObservedInstanceBoard::markObservedAtomAsDisconnected(const atomId_t _id)
     270void QtObservedInstanceBoard::markObservedAtomAsDisconnected(ObservedValue_Index_t _id)
    274271{
    275272  atomObservedValues.markObservedValuesAsDisconnected(_id);
    276273}
    277274
    278 void QtObservedInstanceBoard::markObservedAtomForErase(const atomId_t _id)
     275void QtObservedInstanceBoard::markObservedAtomForErase(ObservedValue_Index_t _id)
    279276{
    280277  atomObservedValues.eraseObservedValues(_id);
    281278}
    282279
    283 void QtObservedInstanceBoard::markObservedMoleculeAsConnected(const moleculeId_t _id)
     280void QtObservedInstanceBoard::markObservedMoleculeAsConnected(ObservedValue_Index_t _id)
    284281{
    285282  moleculeObservedValues.markObservedValuesAsConnected(_id);
    286283}
    287284
    288 void QtObservedInstanceBoard::markObservedMoleculeAsDisconnected(const moleculeId_t _id)
     285void QtObservedInstanceBoard::markObservedMoleculeAsDisconnected(ObservedValue_Index_t _id)
    289286{
    290287  moleculeObservedValues.markObservedValuesAsDisconnected(_id);
    291288}
    292289
    293 void QtObservedInstanceBoard::markObservedMoleculeForErase(const moleculeId_t _id)
     290void QtObservedInstanceBoard::markObservedMoleculeForErase(ObservedValue_Index_t _id)
    294291{
    295292  moleculeObservedValues.eraseObservedValues(_id);
Note: See TracChangeset for help on using the changeset viewer.