Changeset 65c323
- Timestamp:
- Feb 12, 2016, 11:15:23 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:
- 494478
- Parents:
- 41e287
- git-author:
- Frederik Heber <heber@…> (10/29/15 10:46:45)
- git-committer:
- Frederik Heber <heber@…> (02/12/16 23:15:23)
- Location:
- src/UIElements
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp
r41e287 r65c323 33 33 * 34 34 * \param _name name used in debugging and prints 35 * \param _board ref to InstanceBoard 35 36 */ 36 ObservedValuesContainer(const std::string _name) : 37 NameOfType(_name) 38 {} 39 40 /** Dstor of class ObservedValuesContainer. 41 * 42 */ 43 ~ObservedValuesContainer() 44 {} 37 ObservedValuesContainer( 38 const std::string _name, 39 QtObservedInstanceBoard &_board); 45 40 46 41 /** Delivers the set of Observed value for the instance identified by \a _id. … … 69 64 //!> name used in describing the instance type 70 65 const std::string NameOfType; 66 67 //!> reference to InstanceBoard for callbacks on subjectKilled() 68 QtObservedInstanceBoard &board; 71 69 72 70 private: -
src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp
r41e287 r65c323 20 20 21 21 template <class T, typename id> 22 ObservedValuesContainer<T,id>::ObservedValuesContainer( 23 const std::string _name, 24 QtObservedInstanceBoard &_board) : 25 NameOfType(_name), 26 board(_board) 27 {} 28 29 template <class T, typename id> 22 30 typename T::ptr ObservedValuesContainer<T,id>::get(const id _id) 23 31 { … … 29 37 // increase refcount 30 38 ++(iter->second.second); 31 typename T::ptr _molecule(new T(obsvalues)); 39 typename T::ptr _molecule(new T(obsvalues, board)); 40 41 return _molecule; 42 } 43 44 template <> 45 typename QtObservedMolecule::ptr 46 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 refcount 54 ++(iter->second.second); 55 typename QtObservedMolecule::ptr _molecule(new QtObservedMolecule(obsvalues)); 32 56 33 57 return _molecule; -
src/UIElements/Qt4/InstanceBoard/QtObservedAtom.cpp
r41e287 r65c323 36 36 #include "QtObservedAtom.hpp" 37 37 38 #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp" 39 38 40 #include "CodePatterns/MemDebug.hpp" 39 41 42 #include <boost/assign.hpp> 43 44 #include "Atom/atom.hpp" 45 #include "Bond/bond.hpp" 46 #include "Descriptors/AtomIdDescriptor.hpp" 47 #include "Element/element.hpp" 48 #include "World.hpp" 49 50 #include "UIElements/Views/Qt4/Qt3D/ObservedValue_wCallback.hpp" 51 52 using namespace boost::assign; 53 54 static const Observable::channels_t getAtomBondsChannels() 55 { 56 Observable::channels_t channels; 57 channels += AtomObservable::BondsAdded, AtomObservable::BondsRemoved; 58 return channels; 59 } 60 61 static const Observable::channels_t getAllObservedChannels() 62 { 63 Observable::channels_t channels; 64 channels += 65 AtomObservable::IndexChanged, 66 AtomObservable::PositionChanged, 67 AtomObservable::ElementChanged, 68 AtomObservable::BondsAdded, 69 AtomObservable::BondsRemoved; 70 return channels; 71 } 72 73 // static entities 74 const Observable::channels_t 75 QtObservedAtom::AtomIndexChannels(1, AtomObservable::IndexChanged); 76 const Observable::channels_t 77 QtObservedAtom::AtomPositionChannels(1, AtomObservable::PositionChanged); 78 const Observable::channels_t 79 QtObservedAtom::AtomElementChannels(1, AtomObservable::ElementChanged); 80 const Observable::channels_t 81 QtObservedAtom::AtomBondsChannels(getAtomBondsChannels()); 82 40 83 QtObservedAtom::QtObservedAtom( 41 const ObservedValues_t &_obsvalues, 84 const ObservedValues_t &_ObservedValues, 85 QtObservedInstanceBoard &_board, 42 86 QWidget * _parent) : 43 87 QWidget(_parent), 44 88 Observer("QtObservedAtom"), 45 obsvalues(_obsvalues) 46 {} 89 subjectKilledCount(0), 90 AllsignedOnChannels(getAllObservedChannels().size()), 91 signedOffChannels(0), 92 owner(NULL), 93 board(_board), 94 ObservedValues(_ObservedValues) 95 { 96 activateObserver(); 97 } 47 98 48 99 QtObservedAtom::~QtObservedAtom() 49 {} 100 { 101 deactivateObserver(); 102 } 103 104 const atom * const QtObservedAtom::getAtomConst(const atomId_t _id) 105 { 106 const atom * const _atom = const_cast<const World &>(World::getInstance()). 107 getAtom(AtomById(_id)); 108 return _atom; 109 } 110 111 atom * const QtObservedAtom::getAtom(const atomId_t _id) 112 { 113 atom * const _atom = World::getInstance().getAtom(AtomById(_id)); 114 return _atom; 115 } 116 117 atomId_t QtObservedAtom::updateIndex() 118 { 119 return const_cast<const World &>(World::getInstance()).lastChangedAtomId(); 120 } 121 122 Vector QtObservedAtom::updatePosition( 123 const boost::function<const atomId_t ()> &_getAtomIndex) 124 { 125 const atom * const _atom = getAtomConst(_getAtomIndex()); 126 if (_atom != NULL) { 127 return _atom->getPosition(); 128 } else { 129 return zeroVec; 130 } 131 } 132 133 atomicNumber_t QtObservedAtom::updateElement( 134 const boost::function<const atomId_t ()> &_getAtomIndex) 135 { 136 const atom * const _atom = getAtomConst(_getAtomIndex()); 137 if (_atom != NULL) { 138 return _atom->getElementNo(); 139 } else { 140 return (atomicNumber_t)-1; 141 } 142 } 143 144 QtObservedAtom::ListOfBonds_t QtObservedAtom::updateBonds( 145 const boost::function<const atomId_t ()> &_getAtomIndex) 146 { 147 ListOfBonds_t ListOfBonds; 148 const atom * const _atom = getAtomConst(_getAtomIndex()); 149 if (_atom != NULL) { 150 // make sure bonds is up-to-date 151 const BondList ListBonds = _atom->getListOfBonds(); 152 for (BondList::const_iterator iter = ListBonds.begin(); 153 iter != ListBonds.end(); 154 ++iter) 155 ListOfBonds.insert( ListOfBonds.end(), std::make_pair( 156 (*iter)->leftatom->getId(), 157 (*iter)->rightatom->getId()) ); 158 } 159 return ListOfBonds; 160 } 50 161 51 162 void QtObservedAtom::update(Observable *publisher) 52 {} 163 { 164 ASSERT(0, "QtObservedAtom::update() - we are not signed on for global updates."); 165 } 53 166 54 167 void QtObservedAtom::subjectKilled(Observable *publisher) 55 {} 168 { 169 ++signedOffChannels; 170 171 if (signedOffChannels == AllsignedOnChannels) { 172 // remove owner: no more signOff needed 173 owner = NULL; 174 175 board.atomcountsubjectKilled(getAtomIndex()); 176 } 177 } 56 178 57 179 void QtObservedAtom::recieveNotification(Observable *publisher, Notification_ptr notification) 58 {} 180 { 181 // ObservedValues have been updated before, hence convert updates to Qt's signals 182 switch (notification->getChannelNo()) { 183 case AtomObservable::IndexChanged: 184 emit indexChanged(); 185 break; 186 case AtomObservable::PositionChanged: 187 emit positionChanged(); 188 break; 189 case AtomObservable::ElementChanged: 190 emit elementChanged(); 191 break; 192 case AtomObservable::BondsAdded: 193 case AtomObservable::BondsRemoved: 194 emit bondsChanged(); 195 break; 196 default: 197 ASSERT(0, "QtObservedAtom::recieveNotification() - we are not signed on to channel " 198 +toString(notification->getChannelNo())+" of the atom."); 199 break; 200 } 201 } 202 203 void QtObservedAtom::activateObserver() 204 { 205 atom * atomref = getAtom(getAtomIndex()); 206 if (atomref != NULL) { 207 Observable::channels_t channels = getAllObservedChannels(); 208 owner = static_cast<const Observable *>(atomref); 209 for (Observable::channels_t::const_iterator iter = channels.begin(); 210 iter != channels.end(); ++iter) 211 owner->signOn(this, *iter); 212 } else 213 signedOffChannels = getAllObservedChannels().size(); 214 } 215 216 void QtObservedAtom::deactivateObserver() 217 { 218 // sign Off 219 if (owner != NULL) { 220 Observable::channels_t channels = getAllObservedChannels(); 221 for (Observable::channels_t::const_iterator iter = channels.begin(); 222 iter != channels.end(); ++iter) 223 owner->signOff(this, *iter); 224 owner = NULL; 225 signedOffChannels = AllsignedOnChannels; 226 } 227 } 228 229 void QtObservedAtom::initObservedValues( 230 ObservedValues_t &_ObservedValues, 231 const atomId_t _id, 232 const atom * const _atomref, 233 const boost::function<void(const atomId_t)> &_subjectKilled) 234 { 235 /* This is an old note from when the code was still part of cstor's initializer body. 236 * TODO: Probably does not apply anymore but has not yet been tested. 237 * 238 * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly 239 * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because 240 * the class has not been fully constructed yet. "This" itself seems to be working fine. 241 */ 242 243 ASSERT( _ObservedValues.size() == MAX_ObservedTypes, 244 "QtObservedAtom::initObservedValues() - given ObservedValues has not correct size."); 245 246 // fill ObservedValues: index first 247 const boost::function<atomId_t ()> AtomIndexUpdater( 248 boost::bind(&QtObservedAtom::updateIndex)); 249 250 ObservedValue_wCallback<atomId_t> * const IndexObservable = 251 new ObservedValue_wCallback<atomId_t>( 252 _atomref, 253 boost::bind(&QtObservedAtom::updateIndex), 254 "AtomIndex_"+toString(_id), 255 _id, 256 AtomIndexChannels, 257 _subjectKilled); 258 _ObservedValues[AtomIndex] = IndexObservable; 259 260 const boost::function<const atomId_t ()> AtomIndexGetter = 261 boost::bind(&ObservedValue_wCallback<atomId_t>::get, 262 IndexObservable); 263 264 // fill ObservedValues: then all the other that need index 265 const boost::function<Vector ()> AtomPositionUpdater( 266 boost::bind(&QtObservedAtom::updatePosition, AtomIndexGetter)); 267 const boost::function<atomicNumber_t ()> AtomElementUpdater( 268 boost::bind(&QtObservedAtom::updateElement, AtomIndexGetter)); 269 const boost::function<ListOfBonds_t ()> AtomBondsUpdater( 270 boost::bind(&QtObservedAtom::updateBonds, AtomIndexGetter)); 271 272 _ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector, atomId_t>( 273 _atomref, 274 AtomPositionUpdater, 275 "AtomPosition_"+toString(_id), 276 AtomPositionUpdater(), 277 AtomPositionChannels, 278 _subjectKilled, 279 AtomIndexGetter); 280 _ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t, atomId_t>( 281 _atomref, 282 AtomElementUpdater, 283 "AtomElement"+toString(_id), 284 AtomElementUpdater(), 285 AtomElementChannels, 286 _subjectKilled, 287 AtomIndexGetter); 288 _ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t, atomId_t>( 289 _atomref, 290 AtomBondsUpdater, 291 "AtomBonds_"+toString(_id), 292 AtomBondsUpdater(), 293 AtomBondsChannels, 294 _subjectKilled, 295 AtomIndexGetter); 296 } 297 298 void QtObservedAtom::destroyObservedValues( 299 std::vector<boost::any> &_ObservedValues) 300 { 301 delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[AtomIndex]); 302 delete boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(_ObservedValues[AtomPosition]); 303 delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(_ObservedValues[AtomElement]); 304 delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, atomId_t> *>(_ObservedValues[AtomBonds]); 305 _ObservedValues.clear(); 306 } 307 308 atomId_t QtObservedAtom::getAtomIndex() const 309 { 310 return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex])->get(); 311 } 312 313 Vector QtObservedAtom::getAtomPosition() const 314 { 315 return boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(ObservedValues[AtomPosition])->get(); 316 } 317 318 atomicNumber_t QtObservedAtom::getAtomElement() const 319 { 320 return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(ObservedValues[AtomElement])->get(); 321 } 322 323 QtObservedAtom::ListOfBonds_t QtObservedAtom::getAtomBonds() const 324 { 325 return boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, atomId_t> *>(ObservedValues[AtomBonds])->get(); 326 } -
src/UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp
r41e287 r65c323 17 17 #include <QtGui/QWidget> 18 18 19 19 #include <boost/function.hpp> 20 20 #include <boost/shared_ptr.hpp> 21 21 22 #include "CodePatterns/Observer/Observable.hpp" 22 23 #include "CodePatterns/Observer/Observer.hpp" 24 25 #include "LinearAlgebra/Vector.hpp" 23 26 24 27 #include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp" … … 26 29 #include "types.hpp" 27 30 31 class atom; 28 32 class QtObservedInstanceBoard; 29 33 … … 37 41 * 38 42 * This is the instance for information about a particular atom. 43 * 44 * Essentially, this is the interface between molecuilder's World (and a 45 * particular atom) and the QtGui part of the code. 39 46 */ 40 47 class QtObservedAtom : public QWidget, public Observer … … 42 49 Q_OBJECT 43 50 51 public: 52 53 //!> typedef for instance wrapped in shared ptr 54 typedef boost::shared_ptr<QtObservedAtom> ptr; 55 56 private: 44 57 //!> ObservedValuesContainer needs to access private cstor and dstor 45 58 friend class ObservedValuesContainer<QtObservedAtom, atomId_t>; … … 47 60 friend class QtObservedInstanceBoard; 48 61 49 //!> typedef for instance wrapped in shared ptr50 typedef boost::shared_ptr<QtObservedAtom> ptr;51 52 62 /** Cstor of QtObservedAtom. 53 63 * 54 * \param _obsvalues ref to set of observed values for this instance 64 * \param _ObservedValues ref to set of observed values for this instance 65 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled() 55 66 * \param _parent Qt parent to automatically destroy when parent is destroyed 56 67 */ 57 68 QtObservedAtom( 58 const ObservedValues_t &_obsvalues, 69 const ObservedValues_t &_ObservedValues, 70 QtObservedInstanceBoard &_board, 59 71 QWidget * _parent=0); 60 72 … … 71 83 void recieveNotification(Observable *publisher, Notification_ptr notification); 72 84 85 /** Getter to atom index contained in \a ObservedValues. 86 * 87 * \return atom's index 88 */ 89 atomId_t getAtomIndex() const; 90 91 /** Getter to atom position contained in \a ObservedValues. 92 * 93 * \return atom's position 94 */ 95 Vector getAtomPosition() const; 96 97 /** Getter to atom element contained in \a ObservedValues. 98 * 99 * \return atom's elemnt 100 */ 101 atomicNumber_t getAtomElement() const; 102 103 //!> typedef for list of bonds, defined by pairs of atom ids 104 typedef std::vector< std::pair<atomId_t, atomId_t> > ListOfBonds_t; 105 106 /** Getter to atom bonds contained in \a ObservedValues. 107 * 108 * \return atom's bonds 109 */ 110 ListOfBonds_t getAtomBonds() const; 111 73 112 signals: 74 75 private slots: 76 77 78 private: 113 void indexChanged(); 114 void positionChanged(); 115 void elementChanged(); 116 void bondsChanged(); 117 118 //private slots: 119 120 private: 121 void activateObserver(); 122 void deactivateObserver(); 123 124 static const atom * const getAtomConst(const atomId_t _id); 125 static atom * const getAtom(const atomId_t _id); 126 127 private: 128 static atomId_t updateIndex(); 129 static Vector updatePosition( 130 const boost::function<const atomId_t ()> &_getAtomIndex); 131 static atomicNumber_t updateElement( 132 const boost::function<const atomId_t ()> &_getAtomIndex); 133 static ListOfBonds_t updateBonds( 134 const boost::function<const atomId_t ()> &_getAtomIndex); 135 136 //!> enumeration of observed values to match with entries in ObservedValues 137 enum ObservedTypes { 138 //!> contains the current atom index 139 AtomIndex, 140 //!> contains the current atom position 141 AtomPosition, 142 //!> contains the current atom element 143 AtomElement, 144 //!> contains the current set of bonds atoms fort the atom 145 AtomBonds, 146 //!> gives the size of the enumeration 147 MAX_ObservedTypes 148 }; 149 150 /** Initializes all \a ObservedValues entries. 151 * 152 * \param _ObservedValues vector of ObservedValue to be filled 153 * \param _id atom id 154 * \param _atomref reference to atom 155 * \param _subjectKilled ref to function to call on subjectKilled() 156 */ 157 static void initObservedValues( 158 ObservedValues_t &_ObservedValues, 159 const atomId_t _id, 160 const atom * const _atomref, 161 const boost::function<void(const atomId_t)> &_subjectKilled); 162 163 /** Destroys all \a ObservedValues entries. 164 * 165 * \param _ObservedValues vector of ObservedValue to be destroyed 166 */ 167 static void destroyObservedValues( 168 std::vector<boost::any> &_ObservedValues); 169 170 //!> counts how many ObservedValues have already been subjectKilled() 171 mutable size_t subjectKilledCount; 172 173 private: 174 175 //!> list of channels when index needs to update 176 static const Observable::channels_t AtomIndexChannels; 177 //!> list of channels when position needs to update 178 static const Observable::channels_t AtomPositionChannels; 179 //!> list of channels when element needs to update 180 static const Observable::channels_t AtomElementChannels; 181 //!> list of channels when bonds needs to update 182 static const Observable::channels_t AtomBondsChannels; 183 184 //!> we get multiple subjectKilled(), count and call callback() only on last 185 const unsigned int AllsignedOnChannels; 186 unsigned int signedOffChannels; 187 188 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL) 189 const Observable *owner; 190 191 private: 192 193 //!> reference to InstanceBoard for callbacks on subjectKilled() 194 QtObservedInstanceBoard & board; 195 79 196 //!> internal reference to ObservedValues held by QtObservedInstanceBoard 80 const ObservedValues_t &obsvalues;197 ObservedValues_t ObservedValues; 81 198 }; 82 199 -
src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp
r41e287 r65c323 36 36 #include "QtObservedInstanceBoard.hpp" 37 37 38 #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp"39 38 #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp" 39 #include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp" 40 40 41 41 #include "CodePatterns/MemDebug.hpp" … … 54 54 Observer("QtObservedInstanceBoard"), 55 55 WorldSignedOn(false), 56 atomObservedValues("atom" ),57 moleculeObservedValues("molecule" ),56 atomObservedValues("atom", *this), 57 moleculeObservedValues("molecule", *this), 58 58 atomSubjectKilled( 59 59 boost::bind(&QtObservedInstanceBoard::atomcountsubjectKilled, this, _1)), … … 181 181 getAtom(AtomById(_id)); 182 182 if (_atom!= NULL) { 183 ObservedValues_t ObservedValues( GLMoleculeObject_atom::MAX_ObservedTypes);183 ObservedValues_t ObservedValues(QtObservedAtom::MAX_ObservedTypes); 184 184 LOG(3, "DEBUG: InformationBoard initializes ObservedValues for atom " << _id); 185 GLMoleculeObject_atom::initObservedValues(185 QtObservedAtom::initObservedValues( 186 186 ObservedValues, 187 187 _id, … … 303 303 ++(iter->second); 304 304 305 if (iter->second > GLMoleculeObject_atom::MAX_ObservedTypes) {305 if (iter->second > QtObservedAtom::MAX_ObservedTypes) { 306 306 ASSERT( atomObservedValues.getRefCount(_atomid) == 0, 307 307 "QtObservedInstanceBoard::atomcountsubjectKilled() - observed Values for atom " -
src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp
r41e287 r65c323 30 30 31 31 class GLWorldScene; 32 class GLMoleculeObject_atom;33 32 class GLMoleculeObject_bond; 34 33 class GLMoleculeObject_molecule; … … 101 100 private: 102 101 friend class GLWorldScene; 103 friend class GLMoleculeObject_atom;104 102 friend class GLMoleculeObject_bond; 105 103 friend class GLMoleculeObject_molecule; 104 friend class QtObservedAtom; 106 105 107 106 //!> indicating whether we are still signedOn to World or not -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp
r41e287 r65c323 45 45 46 46 #include <algorithm> 47 #include <boost/assign.hpp>48 47 49 48 #include "Atom/atom.hpp" 50 49 #include "Bond/bond.hpp" 51 #include "Descriptors/AtomIdDescriptor.hpp"52 50 #include "Element/element.hpp" 53 51 #include "Element/periodentafel.hpp" … … 56 54 #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp" 57 55 #include "World.hpp" 58 #include "WorldTime.hpp"59 60 #include "ObservedValue_wCallback.hpp"61 62 using namespace boost::assign;63 64 static const Observable::channels_t getAtomBondsChannels()65 {66 Observable::channels_t channels;67 channels += AtomObservable::BondsAdded, AtomObservable::BondsRemoved;68 return channels;69 }70 71 static const Observable::channels_t getAllObservedChannels()72 {73 Observable::channels_t channels;74 channels +=75 AtomObservable::IndexChanged,76 AtomObservable::PositionChanged,77 AtomObservable::ElementChanged,78 AtomObservable::BondsAdded,79 AtomObservable::BondsRemoved;80 return channels;81 }82 83 // static entities84 const Observable::channels_t85 GLMoleculeObject_atom::AtomIndexChannels(1, AtomObservable::IndexChanged);86 const Observable::channels_t87 GLMoleculeObject_atom::AtomPositionChannels(1, AtomObservable::PositionChanged);88 const Observable::channels_t89 GLMoleculeObject_atom::AtomElementChannels(1, AtomObservable::ElementChanged);90 const Observable::channels_t91 GLMoleculeObject_atom::AtomBondsChannels(getAtomBondsChannels());92 56 93 57 GLMoleculeObject_atom::GLMoleculeObject_atom( 94 58 QGLSceneNode *mesh[], 95 59 QObject *parent, 96 const atomId_t _id, 97 QtObservedInstanceBoard * _board, 98 std::vector<boost::any> _ObservedValues) : 60 QtObservedAtom::ptr _ObservedAtom) : 99 61 GLMoleculeObject(mesh, parent), 100 Observer(std::string("GLMoleculeObject_atom")+toString(_id)), 101 atomref(getAtom(_id)), 102 ObservedValues(_ObservedValues), 103 subjectKilledCount(0), 104 owner(NULL), 105 AllsignedOnChannels(getAllObservedChannels().size()), 106 signedOnChannels(0), 107 board(_board) 62 ObservedAtom(_ObservedAtom) 108 63 { 109 init( _id);64 init(ObservedAtom->getAtomIndex()); 110 65 } 111 66 … … 118 73 m_selected = const_cast<const World &>(World::getInstance()).isAtomSelected(_id); 119 74 120 // sign On121 activateObserver();122 123 // atomref is only used for caching the ref, it must be used elswhere124 const_cast<atom *&>(atomref) = NULL;125 126 75 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked())); 127 connect( this, SIGNAL(idChanged()), this, SLOT(resetIndex()), Qt::QueuedConnection);128 connect( this, SIGNAL(elementChanged()), this, SLOT(resetElement()), Qt::QueuedConnection);129 connect( this, SIGNAL(positionChanged()), this, SLOT(resetPosition()), Qt::QueuedConnection);130 connect( this, SIGNAL(bondsChanged()), this, SLOT(resetPosition()), Qt::QueuedConnection);76 connect( ObservedAtom.get(), SIGNAL(indexChanged()), this, SLOT(resetIndex())); 77 connect( ObservedAtom.get(), SIGNAL(elementChanged()), this, SLOT(resetElement())); 78 connect( ObservedAtom.get(), SIGNAL(positionChanged()), this, SLOT(resetPosition())); 79 connect( ObservedAtom.get(), SIGNAL(bondsChanged()), this, SLOT(resetPosition())); 131 80 132 81 // use that ObservedValues::AtomBonds is always up-to-date … … 134 83 } 135 84 136 void GLMoleculeObject_atom::activateObserver()137 {138 if (atomref != NULL) {139 Observable::channels_t channels = getAllObservedChannels();140 owner = static_cast<const Observable *>(atomref);141 for (Observable::channels_t::const_iterator iter = channels.begin();142 iter != channels.end(); ++iter)143 owner->signOn(this, *iter);144 }145 }146 147 148 void GLMoleculeObject_atom::deactivateObserver()149 {150 // sign Off151 if (owner != NULL) {152 Observable::channels_t channels = getAllObservedChannels();153 for (Observable::channels_t::const_iterator iter = channels.begin();154 iter != channels.end(); ++iter)155 owner->signOff(this, *iter);156 owner = NULL;157 signedOnChannels = 0;158 }159 }160 161 85 GLMoleculeObject_atom::~GLMoleculeObject_atom() 162 { 163 deactivateObserver(); 164 board->returnAtomObservedValues(getAtomIndex(), ObservedValues); 165 } 86 {} 166 87 167 88 void GLMoleculeObject_atom::resetIndex() 168 89 { 169 const atomId_t newId = getAtomIndex();90 const atomId_t newId = ObservedAtom->getAtomIndex(); 170 91 const size_t oldId = objectId(); 171 92 ASSERT( newId != oldId, … … 173 94 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(newId)+"."); 174 95 setObjectId(newId); 175 176 emit indexChanged(this, oldId, newId);177 96 } 178 97 179 98 void GLMoleculeObject_atom::resetPosition() 180 99 { 181 const Vector Position = getAtomPosition();100 const Vector Position = ObservedAtom->getAtomPosition(); 182 101 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+"."); 183 102 setPosition(QVector3D(Position[0], Position[1], Position[2])); … … 188 107 size_t elementno = 0; 189 108 const element * const _type = World::getInstance(). 190 getPeriode()->FindElement( getAtomElement());109 getPeriode()->FindElement(ObservedAtom->getAtomElement()); 191 110 if (_type != NULL) { 192 111 elementno = _type->getAtomicNumber(); … … 214 133 void GLMoleculeObject_atom::resetBonds() 215 134 { 216 ListOfBonds_t ListOfBonds_new =getAtomBonds();135 QtObservedAtom::ListOfBonds_t ListOfBonds_new = ObservedAtom->getAtomBonds(); 217 136 std::sort(ListOfBonds_new.begin(), ListOfBonds_new.end()); 218 ListOfBonds_t BondsToAdd;137 QtObservedAtom::ListOfBonds_t BondsToAdd; 219 138 std::set_difference( 220 139 ListOfBonds_new.begin(), ListOfBonds_new.end(), 221 140 ListOfBonds.begin(), ListOfBonds.end(), 222 141 std::back_inserter(BondsToAdd)); 223 ListOfBonds_t BondsToRemove;142 QtObservedAtom::ListOfBonds_t BondsToRemove; 224 143 std::set_difference( 225 144 ListOfBonds.begin(), ListOfBonds.end(), 226 145 ListOfBonds_new.begin(), ListOfBonds_new.end(), 227 146 std::back_inserter(BondsToRemove)); 228 for ( ListOfBonds_t::const_iterator iter = BondsToAdd.begin();147 for (QtObservedAtom::ListOfBonds_t::const_iterator iter = BondsToAdd.begin(); 229 148 iter != BondsToAdd.end(); 230 149 ++iter) { 231 const GLMoleculeObject_bond::SideOfBond side = (iter->first == getAtomIndex()) ?150 const GLMoleculeObject_bond::SideOfBond side = (iter->first == ObservedAtom->getAtomIndex()) ? 232 151 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right; 233 152 emit BondsAdded(iter->first, iter->second, side); 234 153 } 235 for ( ListOfBonds_t::const_iterator iter = BondsToRemove.begin();154 for (QtObservedAtom::ListOfBonds_t::const_iterator iter = BondsToRemove.begin(); 236 155 iter != BondsToRemove.end(); 237 156 ++iter) { … … 268 187 void GLMoleculeObject_atom::wasClicked() 269 188 { 270 LOG(4, "INFO: GLMoleculeObject_atom: atom " << getAtomIndex() << " has been clicked"); 271 emit clicked(getAtomIndex()); 189 LOG(4, "INFO: GLMoleculeObject_atom: atom " 190 << ObservedAtom->getAtomIndex() << " has been clicked"); 191 emit clicked(ObservedAtom->getAtomIndex()); 272 192 } 273 274 const atom * const GLMoleculeObject_atom::getAtomConst(const atomId_t _id)275 {276 const atom * const _atom = const_cast<const World &>(World::getInstance()).277 getAtom(AtomById(_id));278 return _atom;279 }280 281 atom * const GLMoleculeObject_atom::getAtom(const atomId_t _id)282 {283 atom * const _atom = World::getInstance().getAtom(AtomById(_id));284 return _atom;285 }286 287 atomId_t GLMoleculeObject_atom::updateIndex()288 {289 return const_cast<const World &>(World::getInstance()).lastChangedAtomId();290 }291 292 Vector GLMoleculeObject_atom::updatePosition(293 const boost::function<const atomId_t ()> &_getAtomIndex)294 {295 const atom * const _atom = getAtomConst(_getAtomIndex());296 if (_atom != NULL) {297 return _atom->getPosition();298 } else {299 return zeroVec;300 }301 }302 303 atomicNumber_t GLMoleculeObject_atom::updateElement(304 const boost::function<const atomId_t ()> &_getAtomIndex)305 {306 const atom * const _atom = getAtomConst(_getAtomIndex());307 if (_atom != NULL) {308 return _atom->getElementNo();309 } else {310 return (atomicNumber_t)-1;311 }312 }313 314 GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::updateBonds(315 const boost::function<const atomId_t ()> &_getAtomIndex)316 {317 ListOfBonds_t ListOfBonds;318 const atom * const _atom = getAtomConst(_getAtomIndex());319 if (_atom != NULL) {320 // make sure bonds is up-to-date321 const BondList ListBonds = _atom->getListOfBonds();322 for (BondList::const_iterator iter = ListBonds.begin();323 iter != ListBonds.end();324 ++iter)325 ListOfBonds.insert( ListOfBonds.end(), std::make_pair(326 (*iter)->leftatom->getId(),327 (*iter)->rightatom->getId()) );328 } else {329 ELOG(2, "Atom with id "+toString(_getAtomIndex())+" is already gone.");330 }331 return ListOfBonds;332 }333 334 void GLMoleculeObject_atom::update(Observable *publisher)335 {336 ASSERT(0, "GLMoleculeObject_atom::update() - we are not signed on for global updates.");337 }338 339 void GLMoleculeObject_atom::subjectKilled(Observable *publisher)340 {341 ++signedOnChannels;342 343 if (signedOnChannels == AllsignedOnChannels) {344 // remove owner: no more signOff needed345 owner = NULL;346 347 board->atomcountsubjectKilled(getAtomIndex());348 }349 }350 351 void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)352 {353 // ObservedValues have been updated before, hence convert updates to Qt's signals354 atom * const _atom = dynamic_cast<atom *>(publisher);355 if (_atom != NULL) {356 switch (notification->getChannelNo()) {357 case AtomObservable::IndexChanged:358 emit idChanged();359 break;360 case AtomObservable::PositionChanged:361 emit positionChanged();362 break;363 case AtomObservable::ElementChanged:364 emit elementChanged();365 break;366 case AtomObservable::BondsAdded:367 case AtomObservable::BondsRemoved:368 emit bondsChanged();369 break;370 default:371 ASSERT(0, "GLMoleculeObject_atom::recieveNotification() - we are not signed on to channel "372 +toString(notification->getChannelNo())+" of the atom.");373 break;374 }375 } else376 ASSERT(0, "GLMoleculeObject_atom::recieveNotification() - received notification from unexpected source.");377 }378 379 void GLMoleculeObject_atom::initObservedValues(380 std::vector<boost::any> &_ObservedValues,381 const atomId_t _id,382 const atom * const _atomref,383 const boost::function<void(const atomId_t)> &_subjectKilled)384 {385 /* This is an old note from when the code was still part of cstor's initializer body.386 * TODO: Probably does not apply anymore but has not yet been tested.387 *388 * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly389 * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because390 * the class has not been fully constructed yet. "This" itself seems to be working fine.391 */392 393 ASSERT( _ObservedValues.size() == MAX_ObservedTypes,394 "GLMoleculeObject_atom::initObservedValues() - given ObservedValues has not correct size.");395 396 // fill ObservedValues: index first397 const boost::function<atomId_t ()> AtomIndexUpdater(398 boost::bind(&GLMoleculeObject_atom::updateIndex));399 400 ObservedValue_wCallback<atomId_t> * const IndexObservable =401 new ObservedValue_wCallback<atomId_t>(402 _atomref,403 boost::bind(&GLMoleculeObject_atom::updateIndex),404 "AtomIndex_"+toString(_id),405 _id,406 AtomIndexChannels,407 _subjectKilled);408 _ObservedValues[AtomIndex] = IndexObservable;409 410 const boost::function<const atomId_t ()> AtomIndexGetter =411 boost::bind(&ObservedValue_wCallback<atomId_t>::get,412 IndexObservable);413 414 // fill ObservedValues: then all the other that need index415 const boost::function<Vector ()> AtomPositionUpdater(416 boost::bind(&GLMoleculeObject_atom::updatePosition, AtomIndexGetter));417 const boost::function<atomicNumber_t ()> AtomElementUpdater(418 boost::bind(&GLMoleculeObject_atom::updateElement, AtomIndexGetter));419 const boost::function<ListOfBonds_t ()> AtomBondsUpdater(420 boost::bind(&GLMoleculeObject_atom::updateBonds, AtomIndexGetter));421 422 _ObservedValues[AtomPosition] = new ObservedValue_wCallback<Vector, atomId_t>(423 _atomref,424 AtomPositionUpdater,425 "AtomPosition_"+toString(_id),426 AtomPositionUpdater(),427 AtomPositionChannels,428 _subjectKilled,429 AtomIndexGetter);430 _ObservedValues[AtomElement] = new ObservedValue_wCallback<atomicNumber_t, atomId_t>(431 _atomref,432 AtomElementUpdater,433 "AtomElement"+toString(_id),434 AtomElementUpdater(),435 AtomElementChannels,436 _subjectKilled,437 AtomIndexGetter);438 _ObservedValues[AtomBonds] = new ObservedValue_wCallback<ListOfBonds_t, atomId_t>(439 _atomref,440 AtomBondsUpdater,441 "AtomBonds_"+toString(_id),442 AtomBondsUpdater(),443 AtomBondsChannels,444 _subjectKilled,445 AtomIndexGetter);446 }447 448 void GLMoleculeObject_atom::destroyObservedValues(449 std::vector<boost::any> &_ObservedValues)450 {451 delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[AtomIndex]);452 delete boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(_ObservedValues[AtomPosition]);453 delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(_ObservedValues[AtomElement]);454 delete boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, atomId_t> *>(_ObservedValues[AtomBonds]);455 _ObservedValues.clear();456 }457 458 atomId_t GLMoleculeObject_atom::getAtomIndex() const459 {460 return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[AtomIndex])->get();461 }462 463 Vector GLMoleculeObject_atom::getAtomPosition() const464 {465 return boost::any_cast<ObservedValue_wCallback<Vector, atomId_t> *>(ObservedValues[AtomPosition])->get();466 }467 468 atomicNumber_t GLMoleculeObject_atom::getAtomElement() const469 {470 return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, atomId_t> *>(ObservedValues[AtomElement])->get();471 }472 473 GLMoleculeObject_atom::ListOfBonds_t GLMoleculeObject_atom::getAtomBonds() const474 {475 return boost::any_cast<ObservedValue_wCallback<ListOfBonds_t, atomId_t> *>(ObservedValues[AtomBonds])->get();476 } -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp
r41e287 r65c323 20 20 21 21 #include "CodePatterns/ObservedValue.hpp" 22 #include "CodePatterns/Observer/Observer.hpp"23 22 24 #include "LinearAlgebra/Vector.hpp"25 26 #include "Bond/bond.hpp"27 23 #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp" 24 #include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp" 28 25 #include "types.hpp" 29 26 … … 31 28 class QtObservedInstanceBoard; 32 29 33 class GLMoleculeObject_atom : public GLMoleculeObject , Observer30 class GLMoleculeObject_atom : public GLMoleculeObject 34 31 { 35 32 Q_OBJECT … … 38 35 QGLSceneNode *mesh[], 39 36 QObject *parent, 40 const atomId_t id, 41 QtObservedInstanceBoard * _board, 42 std::vector<boost::any> _ObservedValues 37 QtObservedAtom::ptr _ObservedAtom 43 38 ); 44 39 virtual ~GLMoleculeObject_atom(); 45 40 46 41 void draw(QGLPainter *painter, const QVector4D &cameraPlane); 47 48 // Observer functions49 void update(Observable *publisher);50 void subjectKilled(Observable *publisher);51 void recieveNotification(Observable *publisher, Notification_ptr notification);52 42 53 43 public slots: … … 67 57 void BondsRemoved(const atomId_t _left, const atomId_t _right); 68 58 void indexChanged(GLMoleculeObject_atom *ob, const atomId_t oldId, const atomId_t newId); 69 void idChanged();70 void positionChanged();71 void elementChanged();72 void bondsChanged();73 59 74 60 private: 75 //!> grant GLMoleculeObject_molecule acess to reset functions76 friend class GLMoleculeObject_molecule;77 78 //!> typedef for list of bonds, defined by pairs of atom ids79 typedef std::vector< std::pair<atomId_t, atomId_t> > ListOfBonds_t;80 81 static const atom * const getAtomConst(const atomId_t _id);82 static atom * const getAtom(const atomId_t _id);83 84 static atomId_t updateIndex();85 static Vector updatePosition(86 const boost::function<const atomId_t ()> &_getAtomIndex);87 static atomicNumber_t updateElement(88 const boost::function<const atomId_t ()> &_getAtomIndex);89 static ListOfBonds_t updateBonds(90 const boost::function<const atomId_t ()> &_getAtomIndex);91 92 void activateObserver();93 void deactivateObserver();94 95 61 void init(const atomId_t _id); 96 62 97 63 private: 64 //!> current list of bonds to compare new onw against for changes 65 QtObservedAtom::ListOfBonds_t ListOfBonds; 98 66 99 //!> current list of bonds to compare new onw against for changes 100 ListOfBonds_t ListOfBonds; 101 102 //!> temporary variable used in cstor 103 atom * const atomref; 104 105 private: 106 friend class QtObservedInstanceBoard; 107 /** Observed Values **/ 108 109 //!> enumeration of observed values to match with entries in ObservedValues 110 enum ObservedTypes { 111 //!> contains the current atom index 112 AtomIndex, 113 //!> contains the current atom position 114 AtomPosition, 115 //!> contains the current atom element 116 AtomElement, 117 //!> contains the current set of bonds atoms fort the atom 118 AtomBonds, 119 //!> gives the size of the enumeration 120 MAX_ObservedTypes 121 }; 122 123 //!> vector with all observed values 124 std::vector<boost::any> ObservedValues; 125 126 /** Initializes all \a ObservedValues entries. 127 * 128 * \param _ObservedValues vector of ObservedValue to be filled 129 * \param _id atom id 130 * \param _atomref reference to atom 131 * \param _subjectKilled ref to function to call on subjectKilled() 132 */ 133 static void initObservedValues( 134 std::vector<boost::any> &_ObservedValues, 135 const atomId_t _id, 136 const atom * const _atomref, 137 const boost::function<void(const atomId_t)> &_subjectKilled); 138 139 /** Destroys all \a ObservedValues entries. 140 * 141 * \param _ObservedValues vector of ObservedValue to be destroyed 142 */ 143 static void destroyObservedValues( 144 std::vector<boost::any> &_ObservedValues); 145 146 /** Getter to atom index contained in \a ObservedValues. 147 * 148 * \return atom's index 149 */ 150 atomId_t getAtomIndex() const; 151 152 /** Getter to atom position contained in \a ObservedValues. 153 * 154 * \return atom's position 155 */ 156 Vector getAtomPosition() const; 157 158 /** Getter to atom element contained in \a ObservedValues. 159 * 160 * \return atom's elemnt 161 */ 162 atomicNumber_t getAtomElement() const; 163 164 /** Getter to atom bonds contained in \a ObservedValues. 165 * 166 * \return atom's bonds 167 */ 168 ListOfBonds_t getAtomBonds() const; 169 170 //!> counts how many ObservedValues have already been subjectKilled() 171 mutable size_t subjectKilledCount; 172 173 private: 174 175 //!> list of channels when index needs to update 176 static const Observable::channels_t AtomIndexChannels; 177 //!> list of channels when position needs to update 178 static const Observable::channels_t AtomPositionChannels; 179 //!> list of channels when element needs to update 180 static const Observable::channels_t AtomElementChannels; 181 //!> list of channels when bonds needs to update 182 static const Observable::channels_t AtomBondsChannels; 183 184 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL) 185 const Observable *owner; 186 187 //!> we get multiple subjectKilled(), count and call callback() only on last 188 const unsigned int AllsignedOnChannels; 189 unsigned int signedOnChannels; 190 191 QtObservedInstanceBoard * board; 67 QtObservedAtom::ptr ObservedAtom; 192 68 }; 193 69 -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp
r41e287 r65c323 573 573 GLMoleculeObject::meshSphere, 574 574 this, 575 _id, 576 board, 577 board->getAtomObservedValues(_id)); 575 board->getObservedAtom(_id)); 578 576 ASSERT( atomObject != NULL, 579 577 "GLMoleculeObject_molecule::atomInserted - could not create atom object for "+toString(_id));
Note:
See TracChangeset
for help on using the changeset viewer.