Changeset 494478 for src/UIElements/Qt4/InstanceBoard
- Timestamp:
- Feb 12, 2016, 11:15:24 PM (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:
- 90821d
- Parents:
- 65c323
- git-author:
- Frederik Heber <heber@…> (10/29/15 12:52:29)
- git-committer:
- Frederik Heber <heber@…> (02/12/16 23:15:24)
- Location:
- src/UIElements/Qt4/InstanceBoard
- Files:
-
- 6 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp
r65c323 r494478 38 38 ++(iter->second.second); 39 39 typename T::ptr _molecule(new T(obsvalues, board)); 40 41 return _molecule;42 }43 44 template <>45 typename QtObservedMolecule::ptr46 ObservedValuesContainer<QtObservedMolecule,moleculeId_t>::get(const moleculeId_t _id)47 {48 typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);49 ASSERT( iter != ObservedValues.end(),50 "ObservedValuesContainer::getObservedValues() - no observed values present for "51 +NameOfType+" "+toString(_id));52 const ObservedValues_t &obsvalues = iter->second.first;53 // increase refcount54 ++(iter->second.second);55 typename QtObservedMolecule::ptr _molecule(new QtObservedMolecule(obsvalues));56 40 57 41 return _molecule; -
src/UIElements/Qt4/InstanceBoard/QtObservedAtom.cpp
r65c323 r494478 48 48 #include "World.hpp" 49 49 50 #include "UIElements/ Views/Qt4/Qt3D/ObservedValue_wCallback.hpp"50 #include "UIElements/Qt4/InstanceBoard/ObservedValue_wCallback.hpp" 51 51 52 52 using namespace boost::assign; -
src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp
r65c323 r494478 36 36 #include "QtObservedInstanceBoard.hpp" 37 37 38 #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp"39 38 #include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp" 39 #include "UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp" 40 40 41 41 #include "CodePatterns/MemDebug.hpp" … … 134 134 getMolecule(MoleculeById(_id)); 135 135 if (_molecule != NULL) { 136 ObservedValues_t ObservedValues( GLMoleculeObject_molecule::MAX_ObservedTypes);136 ObservedValues_t ObservedValues(QtObservedMolecule::MAX_ObservedTypes); 137 137 LOG(3, "DEBUG: InformationBoard initializes ObservedValues for molecule " << _id); 138 GLMoleculeObject_molecule::initObservedValues(138 QtObservedMolecule::initObservedValues( 139 139 ObservedValues, 140 140 _id, … … 327 327 ++(iter->second); 328 328 329 if (iter->second > GLMoleculeObject_molecule::MAX_ObservedTypes) {329 if (iter->second > QtObservedMolecule::MAX_ObservedTypes) { 330 330 ASSERT( moleculeObservedValues.getRefCount(_molid) == 0, 331 331 "QtObservedInstanceBoard::moleculecountsubjectKilled() - observed Values for molecule " -
src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp
r65c323 r494478 101 101 friend class GLWorldScene; 102 102 friend class GLMoleculeObject_bond; 103 friend class GLMoleculeObject_molecule;104 103 friend class QtObservedAtom; 104 friend class QtObservedMolecule; 105 105 106 106 //!> indicating whether we are still signedOn to World or not -
src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.cpp
r65c323 r494478 36 36 #include "QtObservedMolecule.hpp" 37 37 38 #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp" 39 38 40 #include "CodePatterns/MemDebug.hpp" 41 #include "CodePatterns/Assert.hpp" 42 #include "CodePatterns/Log.hpp" 43 44 #include <boost/assign.hpp> 45 #include <boost/bind.hpp> 46 47 #include "UIElements/Qt4/InstanceBoard/ObservedValue_wCallback.hpp" 48 #include "UIElements/Qt4/InstanceBoard/ObservedValue_UpdateAtoms.hpp" 49 50 #include "Atom/atom.hpp" 51 #include "Descriptors/MoleculeIdDescriptor.hpp" 52 #include "World.hpp" 53 54 using namespace boost::assign; 55 56 static const Observable::channels_t getAllObservedChannels() 57 { 58 Observable::channels_t channels; 59 channels += 60 molecule::AtomInserted, 61 molecule::AtomRemoved, 62 molecule::IndexChanged, 63 molecule::MoleculeNameChanged, 64 molecule::BoundingBoxChanged; 65 return channels; 66 } 67 68 // static instances 69 const Observable::channels_t QtObservedMolecule::BoundingBoxChannels(1, molecule::BoundingBoxChanged); 70 const Observable::channels_t QtObservedMolecule::IndexChannels(1, molecule::IndexChanged); 71 const Observable::channels_t QtObservedMolecule::NameChannels(1, molecule::MoleculeNameChanged); 39 72 40 73 QtObservedMolecule::QtObservedMolecule( 41 const ObservedValues_t &_obsvalues, 74 const ObservedValues_t &_ObservedValues, 75 QtObservedInstanceBoard &_board, 42 76 QWidget * _parent) : 43 77 QWidget(_parent), 44 78 Observer("QtObservedMolecule"), 45 obsvalues(_obsvalues) 46 {} 79 subjectKilledCount(0), 80 AllsignedOnChannels(getAllObservedChannels().size()), 81 signedOffChannels(0), 82 owner(NULL), 83 board(_board), 84 ObservedValues(_ObservedValues) 85 { 86 activateObserver(); 87 } 47 88 48 89 QtObservedMolecule::~QtObservedMolecule() 49 {} 90 { 91 deactivateObserver(); 92 } 93 94 void QtObservedMolecule::deactivateObserver() 95 { 96 if (owner != NULL) { 97 Observable::channels_t channels = getAllObservedChannels(); 98 for (Observable::channels_t::const_iterator iter = channels.begin(); 99 iter != channels.end(); ++iter) 100 owner->signOff(this, *iter); 101 owner = NULL; 102 signedOffChannels = AllsignedOnChannels; 103 } 104 } 105 106 void QtObservedMolecule::activateObserver() 107 { 108 // sign on as observer (obtain non-const instance before) 109 const molecule * const _molecule = getMolecule(getMolIndex()); 110 if (_molecule != NULL) { 111 Observable::channels_t channels = getAllObservedChannels(); 112 owner = static_cast<const Observable *>(_molecule); 113 for (Observable::channels_t::const_iterator iter = channels.begin(); 114 iter != channels.end(); ++iter) 115 owner->signOn(this, *iter); 116 } else 117 signedOffChannels = AllsignedOnChannels; 118 } 50 119 51 120 void QtObservedMolecule::update(Observable *publisher) 52 {} 121 { 122 ASSERT(0, 123 "QtObservedMolecule::update() - general update from unexpected source."); 124 } 53 125 54 126 void QtObservedMolecule::subjectKilled(Observable *publisher) 55 {} 127 { 128 ++signedOffChannels; 129 130 if (signedOffChannels == AllsignedOnChannels) { 131 // remove owner: no more signOff needed 132 owner = NULL; 133 134 board.moleculecountsubjectKilled(getMolIndex()); 135 } 136 } 56 137 57 138 void QtObservedMolecule::recieveNotification(Observable *publisher, Notification_ptr notification) 58 {} 139 { 140 const molecule * const _molecule = getMolecule(getMolIndex()); 141 // when molecule is NULL we will soon get destroyed anyway 142 if (_molecule == NULL) 143 return; 144 if (publisher == dynamic_cast<const Observable*>(_molecule)){ 145 // notification from atom 146 #ifdef LOG_OBSERVER 147 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this)) 148 << " received notification from molecule " << getMolIndex() << " for channel " 149 << notification->getChannelNo() << "."; 150 #endif 151 switch (notification->getChannelNo()) { 152 case molecule::AtomInserted: 153 { 154 const atomId_t _id = _molecule->lastChangedAtomId(); 155 emit atomInserted(_id); 156 break; 157 } 158 case molecule::AtomRemoved: 159 { 160 const atomId_t _id = _molecule->lastChangedAtomId(); 161 emit atomRemoved(_id); 162 break; 163 } 164 case molecule::BoundingBoxChanged: 165 { 166 #ifdef LOG_OBSERVER 167 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that bounding box has changed."; 168 #endif 169 emit tesselationhullChanged(); 170 emit boundingboxChanged(); 171 break; 172 } 173 case molecule::IndexChanged: 174 { 175 #ifdef LOG_OBSERVER 176 const atomId_t _id = _molecule->lastChangedAtomId(); 177 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+"'s index has changed."; 178 #endif 179 emit indexChanged(); 180 break; 181 } 182 case molecule::MoleculeNameChanged: 183 { 184 #ifdef LOG_OBSERVER 185 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that name has changed."; 186 #endif 187 emit nameChanged(); 188 break; 189 } 190 default: 191 break; 192 } 193 } 194 } 195 196 const molecule * const QtObservedMolecule::getMolecule(const moleculeId_t _id) 197 { 198 const molecule * const mol = const_cast<const World &>(World::getInstance()). 199 getMolecule(MoleculeById(_id)); 200 return mol; 201 } 202 203 static molecule::BoundingBoxInfo initBoundingBox() 204 { 205 molecule::BoundingBoxInfo info; 206 info.position = zeroVec; 207 info.radius = 0.; 208 return info; 209 } 210 211 void QtObservedMolecule::initObservedValues( 212 ObservedValues_t &_ObservedValues, 213 const moleculeId_t _molid, 214 const molecule * const _molref, 215 const boost::function<void(const moleculeId_t)> &_subjectKilled) 216 { 217 /* This is an old note from when the code was still part of cstor's initializer body. 218 * TODO: Probably does not apply anymore but has not yet been tested. 219 * 220 * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly 221 * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because 222 * the class has not been fully constructed yet. "This" itself seems to be working fine. 223 */ 224 225 ASSERT( _ObservedValues.size() == MAX_ObservedTypes, 226 "QtObservedMolecule::initObservedValues() - given ObservedValues has not correct size."); 227 228 // fill ObservedValues: index first 229 const boost::function<moleculeId_t ()> MolIndexUpdater( 230 boost::bind(&QtObservedMolecule::updateIndex)); 231 232 ObservedValue_wCallback<moleculeId_t> * const IndexObservable = 233 new ObservedValue_wCallback<moleculeId_t>( 234 _molref, 235 MolIndexUpdater, 236 "MoleculeIndex_"+toString(_molid), 237 _molid, 238 IndexChannels, 239 _subjectKilled); 240 _ObservedValues[MolIndex] = IndexObservable; 241 242 const boost::function<const moleculeId_t ()> MolIndexGetter = 243 boost::bind(&ObservedValue_wCallback<moleculeId_t>::get, 244 IndexObservable); 245 246 // fill ObservedValues: then all the other that need index 247 const boost::function<std::string ()> MolNameUpdater( 248 boost::bind(&QtObservedMolecule::updateName, MolIndexGetter)); 249 const boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater( 250 boost::bind(&QtObservedMolecule::updateBoundingBox, MolIndexGetter)); 251 252 _ObservedValues[MolName] = new ObservedValue_wCallback<std::string, moleculeId_t>( 253 _molref, 254 MolNameUpdater, 255 "MoleculeName_"+toString(_molid), 256 MolNameUpdater(), 257 NameChannels, 258 _subjectKilled, 259 MolIndexGetter); 260 _ObservedValues[BoundingBox] = new ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t>( 261 _molref, 262 BoundingBoxUpdater, 263 "MoleculeBoundingBox_"+toString(_molid), 264 initBoundingBox(), 265 BoundingBoxChannels, 266 _subjectKilled, 267 MolIndexGetter); 268 } 269 270 void QtObservedMolecule::destroyObservedValues( 271 std::vector<boost::any> &_ObservedValues) 272 { 273 delete boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(_ObservedValues[MolIndex]); 274 delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[MolName]); 275 delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(_ObservedValues[BoundingBox]); 276 _ObservedValues.clear(); 277 } 278 279 molecule::BoundingBoxInfo QtObservedMolecule::updateBoundingBox( 280 const boost::function<const moleculeId_t ()> &_getMolIndex) 281 { 282 const molecule * const mol = getMolecule(_getMolIndex()); 283 if (mol != NULL) 284 return mol->getBoundingBox(); 285 else 286 return molecule::BoundingBoxInfo(); 287 } 288 289 moleculeId_t QtObservedMolecule::updateIndex() 290 { 291 return const_cast<const World &>(World::getInstance()).lastChangedMolId(); 292 } 293 294 std::string QtObservedMolecule::updateName( 295 const boost::function<const moleculeId_t ()> &_getMolIndex) 296 { 297 const molecule * const mol = getMolecule(_getMolIndex()); 298 if (mol != NULL) 299 return mol->getName(); 300 else 301 return std::string(""); 302 } 303 304 moleculeId_t QtObservedMolecule::getMolIndex() const 305 { 306 return boost::any_cast<ObservedValue_wCallback<moleculeId_t> *>(ObservedValues[MolIndex])->get(); 307 } 308 309 std::string QtObservedMolecule::getMolName() const 310 { 311 return boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(ObservedValues[MolName])->get(); 312 } 313 314 molecule::BoundingBoxInfo QtObservedMolecule::getBoundingBox() const 315 { 316 return boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(ObservedValues[BoundingBox])->get(); 317 } -
src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp
r65c323 r494478 17 17 #include <QtGui/QWidget> 18 18 19 #include <boost/function.hpp> 19 20 #include <boost/shared_ptr.hpp> 20 21 22 #include "CodePatterns/Observer/Observable.hpp" 21 23 #include "CodePatterns/Observer/Observer.hpp" 22 24 25 #include "molecule.hpp" 23 26 #include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp" 24 27 #include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp" … … 41 44 Q_OBJECT 42 45 46 public: 47 48 //!> typedef for instance wrapped in shared ptr 49 typedef boost::shared_ptr<QtObservedMolecule> ptr; 50 51 private: 43 52 //!> ObservedValuesContainer needs to access private cstor and dstor 44 53 friend class ObservedValuesContainer<QtObservedMolecule, moleculeId_t>; … … 46 55 friend class QtObservedInstanceBoard; 47 56 48 //!> typedef for instance wrapped in shared ptr49 typedef boost::shared_ptr<QtObservedMolecule> ptr;50 51 57 /** Cstor of QtObservedMolecule. 52 58 * 53 * \param _obsvalues ref to set of observed values for this instance 59 * \param _ObservedValues ref to set of observed values for this instance 60 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled() 54 61 * \param _parent Qt parent to automatically destroy when parent is destroyed 55 62 */ 56 63 QtObservedMolecule( 57 const ObservedValues_t &_obsvalues, 64 const ObservedValues_t &_ObservedValues, 65 QtObservedInstanceBoard &_board, 58 66 QWidget * _parent=0); 59 67 … … 70 78 void recieveNotification(Observable *publisher, Notification_ptr notification); 71 79 80 /** Getter to molecule index contained in \a ObservedValues. 81 * 82 * \return molecule's index 83 */ 84 moleculeId_t getMolIndex() const; 85 86 /** Getter to molecule name contained in \a ObservedValues. 87 * 88 * \return molecule's name 89 */ 90 std::string getMolName() const; 91 92 /** Getter to molecule's bounding box contained in \a ObservedValues. 93 * 94 * \return molecule's bounding box 95 */ 96 molecule::BoundingBoxInfo getBoundingBox() const; 97 98 static const molecule * const getMolecule(const moleculeId_t _id); 99 72 100 signals: 73 74 private slots: 75 101 void indexChanged(); 102 void nameChanged(); 103 void tesselationhullChanged(); 104 void boundingboxChanged(); 105 void atomInserted(const atomId_t); 106 void atomRemoved(const atomId_t); 76 107 77 108 private: 109 110 void activateObserver(); 111 void deactivateObserver(); 112 113 private: 114 static molecule::BoundingBoxInfo updateBoundingBox( 115 const boost::function<const moleculeId_t ()> &_getMolIndex); 116 static moleculeId_t updateIndex(); 117 static std::string updateName( 118 const boost::function<const moleculeId_t ()> &_getMolIndex); 119 120 //!> list of channels when bounding box needs to update 121 static const Observable::channels_t BoundingBoxChannels; 122 //!> list of channels when the index needs to update 123 static const Observable::channels_t IndexChannels; 124 //!> list of channels when the name needs to update 125 static const Observable::channels_t NameChannels; 126 127 private: 128 /** Observed Values **/ 129 130 //!> enumeration of observed values to match with entries in ObservedValues 131 enum ObservedTypes { 132 //!> contains the current molecule index 133 MolIndex, 134 //!> contains the current molecule name 135 MolName, 136 //!> contains newest version of the bounding box on request 137 BoundingBox, 138 //!> gives the size of the enumeration 139 MAX_ObservedTypes 140 }; 141 142 /** Initializes all \a _ObservedValues entries. 143 * 144 * \param _ObservedValues vector of ObservedValue to be filled 145 * \param _moid molecule id 146 * \param _molref reference to molecule 147 * \param _subjectKilled ref to function to call on subjectKilled() 148 */ 149 static void initObservedValues( 150 ObservedValues_t &_ObservedValues, 151 const moleculeId_t _molid, 152 const molecule * const _molref, 153 const boost::function<void(const moleculeId_t)> &_subjectKilled); 154 155 /** Destroys all \a ObservedValues entries. 156 * 157 * \param _ObservedValues vector of ObservedValue to be destroyed 158 */ 159 static void destroyObservedValues( 160 std::vector<boost::any> &_ObservedValues); 161 162 //!> counts how many ObservedValues have already been subjectKilled() 163 mutable size_t subjectKilledCount; 164 165 private: 166 167 //!> we get multiple subjectKilled(), count and call callback() only on last 168 const unsigned int AllsignedOnChannels; 169 unsigned int signedOffChannels; 170 171 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL) 172 const Observable *owner; 173 174 private: 175 176 //!> reference to InstanceBoard for callbacks on subjectKilled() 177 QtObservedInstanceBoard & board; 178 78 179 //!> internal reference to ObservedValues held by QtObservedInstanceBoard 79 const ObservedValues_t &obsvalues;180 ObservedValues_t ObservedValues; 80 181 }; 81 182
Note:
See TracChangeset
for help on using the changeset viewer.