Changeset 59eabc for src/UIElements/Qt4/InstanceBoard
- Timestamp:
- Apr 20, 2016, 7:17:41 AM (9 years ago)
- 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:
- 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)
- Location:
- src/UIElements/Qt4/InstanceBoard
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp
rbff202 r59eabc 19 19 #include <boost/any.hpp> 20 20 21 class Observable; 22 21 23 /** typedef for a vector of ObservedValue's (each is due to templating its 22 24 * own type. Therefore, we need to use boost::any). … … 24 26 typedef std::vector<boost::any> ObservedValues_t; 25 27 28 /** typedef for the permanent and (for the lifetime of the object) never 29 * changing index. 30 * 31 * Note that this is slightly dangerous because two objects may get the same 32 * index if one is destroyed and another one instantiated at the same address. 33 */ 34 typedef const Observable * ObservedValue_Index_t; 26 35 27 36 -
src/UIElements/Qt4/InstanceBoard/QtObservedAtom.cpp
rbff202 r59eabc 255 255 256 256 if (!BoardIsGone) { 257 board.markObservedAtomAsDisconnected(get AtomIndex());258 board.markObservedAtomForErase(get AtomIndex());257 board.markObservedAtomAsDisconnected(getIndex()); 258 board.markObservedAtomForErase(getIndex()); 259 259 } 260 260 } … … 308 308 owner->signOn(this, *iter); 309 309 if (!BoardIsGone) 310 board.markObservedAtomAsConnected(get AtomIndex());310 board.markObservedAtomAsConnected(getIndex()); 311 311 } else 312 312 signedOffChannels = AllsignedOnChannels; … … 324 324 signedOffChannels = AllsignedOnChannels; 325 325 if (!BoardIsGone) 326 board.markObservedAtomAsDisconnected(get AtomIndex());326 board.markObservedAtomAsDisconnected(getIndex()); 327 327 } 328 328 } … … 440 440 } 441 441 442 ObservedValue_Index_t QtObservedAtom::getIndex() const 443 { 444 ASSERT( owner != NULL, 445 "QtObservedAtom::getIndex() - index is NULL"); 446 return owner; 447 } 448 442 449 const atomId_t& QtObservedAtom::getAtomIndex() const 443 450 { -
src/UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp
rbff202 r59eabc 60 60 private: 61 61 //!> ObservedValuesContainer needs to access private cstor and dstor 62 friend class ObservedValuesContainer<QtObservedAtom, atomId_t>;62 friend class ObservedValuesContainer<QtObservedAtom, ObservedValue_Index_t>; 63 63 //!> QtObservedInstanceBoard needs to access private cstor and dstor 64 64 friend class QtObservedInstanceBoard; … … 88 88 void subjectKilled(Observable *publisher); 89 89 void recieveNotification(Observable *publisher, Notification_ptr notification); 90 91 /** Getter for a permanent and unique index of this instance. 92 * 93 * \note ALWAYS use this index if you need to store and identifier to this 94 * instance which you might need to retrieve at some later date. 95 * 96 * \warning DO NOT STORE the QtObserved...:ptr directly. This will possibly 97 * prevent their eventual destruction. Only store the ObservedValue_Index_t 98 * as means to obtain the ptr from the QtObservedInstanceBoard. 99 * 100 * \return returns a unique and permanent index that can be used to retrieve this 101 * instance from the QtObservedInstanceBoard as it must not be stored. 102 */ 103 ObservedValue_Index_t getIndex() const; 90 104 91 105 /** Getter to atom index contained in \a ObservedValues. -
src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp
rbff202 r59eabc 67 67 boost::bind(&QtObservedInstanceBoard::moleculecountsubjectKilled, this, _1)) 68 68 { 69 qRegisterMetaType<ObservedValue_Index_t>("ObservedValue_Index_t"); 69 70 qRegisterMetaType<QtObservedAtom::ptr>("QtObservedAtom::ptr"); 70 71 qRegisterMetaType<QtObservedMolecule::ptr>("QtObservedMolecule::ptr"); … … 141 142 *this)); 142 143 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) ); 144 147 // we need to check for index changes 145 148 LOG(3, "DEBUG: InformationBoard signOn()s to molecule " << _id); … … 167 170 new QtObservedAtom(_id, _atom, *this)); 168 171 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) ); 170 175 // we need to check for index changes 171 176 LOG(3, "DEBUG: InformationBoard signOn()s to atom " << _id); … … 190 195 const moleculeId_t newmoleculeId = dynamic_cast<molecule *>(publisher)->getId(); 191 196 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 } 199 206 // no need update SignedOn, ref does not change 200 207 emit moleculeIndexChanged(molid, newmoleculeId); … … 212 219 const atomId_t newatomId = dynamic_cast<atom *>(publisher)->getId(); 213 220 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 } 221 230 // no need update SignedOn, ref does not change 222 231 emit atomIndexChanged(oldatomId, newatomId); … … 232 241 } 233 242 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);243 void QtObservedInstanceBoard::atomcountsubjectKilled(ObservedValue_Index_t _id) 244 { 245 LOG(3, "DEBUG: InstanceBoard emits atomRemoved for " << _id); 246 emit atomRemoved(_id); 247 } 248 249 void QtObservedInstanceBoard::moleculecountsubjectKilled(ObservedValue_Index_t _id) 250 { 251 LOG(3, "DEBUG: InstanceBoard emits moleculeRemoved for " << _id); 252 emit moleculeRemoved(_id); 244 253 } 245 254 246 255 QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(const atomId_t _id) 247 256 { 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]); 255 258 } 256 259 257 260 QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const moleculeId_t _id) 258 261 { 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 265 void QtObservedInstanceBoard::markObservedAtomAsConnected(ObservedValue_Index_t _id) 269 266 { 270 267 atomObservedValues.markObservedValuesAsConnected(_id); 271 268 } 272 269 273 void QtObservedInstanceBoard::markObservedAtomAsDisconnected( const atomId_t _id)270 void QtObservedInstanceBoard::markObservedAtomAsDisconnected(ObservedValue_Index_t _id) 274 271 { 275 272 atomObservedValues.markObservedValuesAsDisconnected(_id); 276 273 } 277 274 278 void QtObservedInstanceBoard::markObservedAtomForErase( const atomId_t _id)275 void QtObservedInstanceBoard::markObservedAtomForErase(ObservedValue_Index_t _id) 279 276 { 280 277 atomObservedValues.eraseObservedValues(_id); 281 278 } 282 279 283 void QtObservedInstanceBoard::markObservedMoleculeAsConnected( const moleculeId_t _id)280 void QtObservedInstanceBoard::markObservedMoleculeAsConnected(ObservedValue_Index_t _id) 284 281 { 285 282 moleculeObservedValues.markObservedValuesAsConnected(_id); 286 283 } 287 284 288 void QtObservedInstanceBoard::markObservedMoleculeAsDisconnected( const moleculeId_t _id)285 void QtObservedInstanceBoard::markObservedMoleculeAsDisconnected(ObservedValue_Index_t _id) 289 286 { 290 287 moleculeObservedValues.markObservedValuesAsDisconnected(_id); 291 288 } 292 289 293 void QtObservedInstanceBoard::markObservedMoleculeForErase( const moleculeId_t _id)290 void QtObservedInstanceBoard::markObservedMoleculeForErase(ObservedValue_Index_t _id) 294 291 { 295 292 moleculeObservedValues.eraseObservedValues(_id); -
src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp
rbff202 r59eabc 80 80 81 81 QtObservedAtom::ptr getObservedAtom(const atomId_t _id); 82 QtObservedAtom::ptr getObservedAtom(const Observable * _obs);83 82 QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id); 84 QtObservedMolecule::ptr getObservedMolecule(const Observable * _obs); 85 void markObservedAtomAsConnected(const atomId_t _id); 86 void markObservedAtomAsDisconnected(const atomId_t _id); 87 void markObservedAtomForErase(const atomId_t _id); 88 void markObservedMoleculeAsConnected(const moleculeId_t _id); 89 void markObservedMoleculeAsDisconnected(const moleculeId_t _id); 90 void markObservedMoleculeForErase(const moleculeId_t _id); 83 void markObservedAtomAsConnected(ObservedValue_Index_t _id); 84 void markObservedAtomAsDisconnected(ObservedValue_Index_t _id); 85 void markObservedAtomForErase(ObservedValue_Index_t _id); 86 void markObservedMoleculeAsConnected(ObservedValue_Index_t _id); 87 void markObservedMoleculeAsDisconnected(ObservedValue_Index_t _id); 88 void markObservedMoleculeForErase(ObservedValue_Index_t _id); 91 89 92 90 signals: 93 91 void atomInserted(QtObservedAtom::ptr _atom); 94 void atomRemoved( const atomId_t _atomid);92 void atomRemoved(ObservedValue_Index_t _atomid); 95 93 void atomIndexChanged(const atomId_t _oldid, const atomId_t _newid); 96 94 void moleculeInserted(QtObservedMolecule::ptr _mol); 97 void moleculeRemoved( const moleculeId_t _molid);95 void moleculeRemoved(ObservedValue_Index_t _molid); 98 96 void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid); 99 97 … … 113 111 SignedOn_t MoleculeSignedOn; 114 112 113 //!> "templated typedef" for an id to index map. 114 template <class id> 115 struct IdtoIndex_t : std::map<id, ObservedValue_Index_t> {}; 116 IdtoIndex_t<atomId_t> atomids_lookup; 117 IdtoIndex_t<moleculeId_t> moleculeids_lookup; 118 115 119 /** Counts how many atom's ObservedValues got subjectKilled. 116 120 * … … 119 123 * monitored Observable. Only then can we safely remove the instance. 120 124 * 121 * \param _ atomid id of the atom125 * \param _id observable that received the subjectKilled() 122 126 */ 123 void atomcountsubjectKilled( const atomId_t _atomid);127 void atomcountsubjectKilled(ObservedValue_Index_t _id); 124 128 125 129 /** Counts how many molecule's ObservedValues got subjectKilled. … … 129 133 * monitored Observable. Only then can we safely remove the instance. 130 134 * 131 * \param _ molid id of the molecule135 * \param _id observable that received the subjectKilled() 132 136 */ 133 void moleculecountsubjectKilled( const moleculeId_t _molid);137 void moleculecountsubjectKilled(ObservedValue_Index_t _id); 134 138 135 139 //!> container with all ObservedValues for each atom, associated by id 136 ObservedValuesContainer<QtObservedAtom, atomId_t> atomObservedValues;140 ObservedValuesContainer<QtObservedAtom, ObservedValue_Index_t> atomObservedValues; 137 141 //!> container with all ObservedValues for each molecule, associated by id 138 ObservedValuesContainer<QtObservedMolecule, moleculeId_t> moleculeObservedValues;142 ObservedValuesContainer<QtObservedMolecule, ObservedValue_Index_t> moleculeObservedValues; 139 143 }; 140 144 -
src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.cpp
rbff202 r59eabc 151 151 signedOffChannels = AllsignedOnChannels; 152 152 if (!BoardIsGone) 153 board.markObservedMoleculeAsDisconnected(get MolIndex());153 board.markObservedMoleculeAsDisconnected(getIndex()); 154 154 } 155 155 } … … 166 166 owner->signOn(this, *iter); 167 167 if (!BoardIsGone) 168 board.markObservedMoleculeAsConnected(get MolIndex());168 board.markObservedMoleculeAsConnected(getIndex()); 169 169 } else 170 170 signedOffChannels = AllsignedOnChannels; … … 204 204 205 205 if (!BoardIsGone) { 206 board.markObservedMoleculeAsDisconnected(get MolIndex());207 board.markObservedMoleculeForErase(get MolIndex());206 board.markObservedMoleculeAsDisconnected(getIndex()); 207 board.markObservedMoleculeForErase(getIndex()); 208 208 } 209 209 } … … 523 523 } 524 524 525 ObservedValue_Index_t QtObservedMolecule::getIndex() const 526 { 527 ASSERT( owner != NULL, 528 "QtObservedMolecule::getIndex() - index is NULL"); 529 return owner; 530 } 531 525 532 const int& QtObservedMolecule::getAtomCount() const 526 533 { -
src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp
rbff202 r59eabc 57 57 private: 58 58 //!> ObservedValuesContainer needs to access private cstor and dstor 59 friend class ObservedValuesContainer<QtObservedMolecule, moleculeId_t>;59 friend class ObservedValuesContainer<QtObservedMolecule, ObservedValue_Index_t>; 60 60 //!> QtObservedInstanceBoard needs to access private cstor and dstor 61 61 friend class QtObservedInstanceBoard; … … 85 85 void subjectKilled(Observable *publisher); 86 86 void recieveNotification(Observable *publisher, Notification_ptr notification); 87 88 /** Getter for a permanent and unique index of this instance. 89 * 90 * \note ALWAYS use this index if you need to store and identifier to this 91 * instance which you might need to retrieve at some later date. 92 * 93 * \warning DO NOT STORE the QtObserved...:ptr directly. This will possibly 94 * prevent their eventual destruction. Only store the ObservedValue_Index_t 95 * as means to obtain the ptr from the QtObservedInstanceBoard. 96 * 97 * \return returns a unique and permanent index that can be used to retrieve this 98 * instance from the QtObservedInstanceBoard as it must not be stored. 99 */ 100 ObservedValue_Index_t getIndex() const; 87 101 88 102 /** Getter to molecule atom count contained in \a ObservedValues.
Note:
See TracChangeset
for help on using the changeset viewer.