Changeset 7188b1
- Timestamp:
- Oct 6, 2011, 4:06:10 PM (13 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:
- db7e6d
- Parents:
- e638f9
- git-author:
- Frederik Heber <heber@…> (09/01/11 13:49:14)
- git-committer:
- Frederik Heber <heber@…> (10/06/11 16:06:10)
- Files:
-
- 2 added
- 2 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
configure.ac
re638f9 r7188b1 126 126 #AC_MSG_NOTICE(["GLU_CFLAGS: $GLU_CFLAGS, GLU_CXXFLAGS: $GLU_CXXFLAGS, GLU_LDFLAGS: $GLU_LDFLAGS, GLU_LIBS: $GLU_LIBS"]) 127 127 128 # CodePatterns library (needs operator<<(.., range<>))129 AM_PATH_CODEPATTERNS([1. 0.13], $have_debug,,[AC_MSG_ERROR([Missing CodePatterns library, please specify PKG_CONFIG_PATH or use --with-codepatterns...])])128 # CodePatterns library (needs Observer::Channels ) 129 AM_PATH_CODEPATTERNS([1.1.5], $have_debug,,[AC_MSG_ERROR([Missing CodePatterns library, please specify PKG_CONFIG_PATH or use --with-codepatterns...])]) 130 130 131 131 # Checks for header files. -
src/Makefile.am
re638f9 r7188b1 25 25 atom_graphnode.cpp \ 26 26 atom_graphnodeinfo.cpp \ 27 atom_observable.cpp \ 27 28 atom_particleinfo.cpp 28 29 ATOMHEADER = \ … … 33 34 atom_graphnode.hpp \ 34 35 atom_graphnodeinfo.hpp \ 36 atom_observable.hpp \ 35 37 atom_particleinfo.hpp \ 36 38 AtomicInfo.hpp \ -
src/UIElements/Makefile.am
re638f9 r7188b1 195 195 UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp \ 196 196 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp \ 197 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp \ 198 UIElements/Views/Qt4/Qt3D/GLMoleculeScene.cpp 197 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp 199 198 # UIElements/Views/Qt4/dialoglight.cpp 200 199 … … 226 225 UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp \ 227 226 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp \ 228 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp \ 229 UIElements/Views/Qt4/Qt3D/GLMoleculeScene.hpp 227 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp 230 228 231 229 #QTUIUI_HEADER = \ -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp
re638f9 r7188b1 35 35 36 36 //!> Allow it to call cleanMaterialMap() 37 friend class GL MoleculeScene;37 friend class GLWorldScene; 38 38 public: 39 39 explicit GLMoleculeObject(QGLSceneNode *GLMoleculeObject, QObject *parent=0); -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp
re638f9 r7188b1 27 27 28 28 #include "CodePatterns/Assert.hpp" 29 #include "CodePatterns/Log.hpp" 29 30 31 #include "Descriptors/AtomIdDescriptor.hpp" 30 32 #include "element.hpp" 31 33 #include "LinearAlgebra/Vector.hpp" 32 34 #include "World.hpp" 33 35 34 36 static QGLSceneNode * createAtom(QObject *parent) … … 42 44 43 45 GLMoleculeObject_atom::GLMoleculeObject_atom(QObject *parent, const atom *atomref) : 44 GLMoleculeObject(createAtom(parent), parent), _atom(atomref) 46 GLMoleculeObject(createAtom(parent), parent), Observer("GLMoleculeObject_atom"), _atom(atomref) 47 { 48 // sign on as observer (obtain non-const instance before) 49 atomref->signOn(this, atomref->getChannel(AtomObservable::IndexChanged)); 50 atomref->signOn(this, atomref->getChannel(AtomObservable::PositionChanged)); 51 atomref->signOn(this, atomref->getChannel(AtomObservable::ElementChanged)); 52 53 // set the object's id 54 resetProperties(); 55 56 std::cout << "Created sphere for atom " << _atom->getId() << "." << endl; 57 58 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked())); 59 } 60 61 void GLMoleculeObject_atom::update(Observable *publisher) 62 { 63 LOG(0, "GLMoleculeObject_atom::update() - called fro atom "+toString(_atom->getId())+"."); 64 resetProperties(); 65 } 66 67 void GLMoleculeObject_atom::resetPosition() 45 68 { 46 69 const Vector Position = _atom->getPosition(); 47 const size_t elementno = _atom->getType()->getNumber(); 70 LOG(1, "GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+"."); 71 setPosition(QVector3D(Position[0], Position[1], Position[2])); 72 } 73 74 void GLMoleculeObject_atom::resetElement() 75 { 76 size_t elementno = 0; 77 if (_atom->getType() != NULL) { 78 elementno = _atom->getType()->getNumber(); 79 } else { // if no element yet, set to hydrogen 80 elementno = 1; 81 } 82 LOG(1, "GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+"."); 48 83 49 84 // set materials … … 57 92 setHoverMaterial(hovermaterial); 58 93 94 // set scale 95 double radius = 0.; 96 if (_atom->getType() != NULL) { 97 radius = _atom->getType()->getVanDerWaalsRadius(); 98 } else { 99 radius = 0.5; 100 } 101 setScale( radius ); 102 } 103 104 void GLMoleculeObject_atom::resetIndex() 105 { 106 const size_t atomno = _atom->getId(); 107 LOG(1, "GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomno)+"."); 108 setObjectId(atomno); 109 } 110 111 void GLMoleculeObject_atom::resetProperties() 112 { 59 113 // set position 60 setPosition(QVector3D(Position[0], Position[1], Position[2]));114 resetPosition(); 61 115 62 // set scale63 setScale( _atom->getType()->getVanDerWaalsRadius());116 // set element 117 resetElement(); 64 118 65 119 // set the object's id 66 setObjectId(_atom->getId()); 120 resetIndex(); 121 } 67 122 68 std::cout << "Created sphere at " << Position << " with elementno " << elementno << "." << endl; 123 void GLMoleculeObject_atom::subjectKilled(Observable *publisher) 124 {} 69 125 70 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked())); 126 void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification) 127 { 128 LOG(0, "GLMoleculeObject_atom::recieveNotification() - notification type " 129 +toString(notification->getChannelNo())+"."); 130 switch (notification->getChannelNo()) { 131 case AtomObservable::ElementChanged: 132 resetElement(); 133 break; 134 case AtomObservable::IndexChanged: 135 resetIndex(); 136 break; 137 case AtomObservable::PositionChanged: 138 resetPosition(); 139 break; 140 default: 141 //setProperties(); 142 break; 143 } 71 144 } 72 145 -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp
re638f9 r7188b1 16 16 #include "GLMoleculeObject.hpp" 17 17 18 #include "CodePatterns/Observer.hpp" 19 18 20 #include "atom.hpp" 19 21 20 class GLMoleculeObject_atom : public GLMoleculeObject 22 class GLMoleculeObject_atom : public GLMoleculeObject, public Observer 21 23 { 22 24 Q_OBJECT 23 25 public: 24 26 GLMoleculeObject_atom(QObject *parent, const atom *atomref); 25 ~GLMoleculeObject_atom() {} 27 virtual ~GLMoleculeObject_atom() {} 28 29 // Observer functions 30 void update(Observable *publisher); 31 void subjectKilled(Observable *publisher); 32 void recieveNotification(Observable *publisher, Notification_ptr notification); 26 33 27 34 private slots: … … 32 39 33 40 private: 41 void resetPosition(); 42 void resetElement(); 43 void resetIndex(); 44 void resetProperties(); 45 34 46 const atom *_atom; 35 47 }; -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp
re638f9 r7188b1 58 58 Position = _bond->leftatom->getPosition(); 59 59 OtherPosition = _bond->rightatom->getPosition(); 60 elementno = _bond->leftatom->getType()->getNumber(); 60 if (_bond->leftatom->getType() != NULL) { 61 elementno = _bond->leftatom->getType()->getNumber(); 62 } else { // if not element yet set, set to hydrogen 63 elementno = 1; 64 } 61 65 break; 62 66 case right: 63 67 Position = _bond->rightatom->getPosition(); 64 68 OtherPosition = _bond->leftatom->getPosition(); 65 elementno = _bond->rightatom->getType()->getNumber(); 69 if (_bond->rightatom->getType() != NULL) { 70 elementno = _bond->rightatom->getType()->getNumber(); 71 } else { // if not element yet set, set to hydrogen 72 elementno = 1; 73 } 74 66 75 break; 67 76 default: -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp
re638f9 r7188b1 25 25 26 26 GLMoleculeObject_bond(QObject *parent, const bond *bondref, double distance, enum SideOfBond side); 27 ~GLMoleculeObject_bond() {}27 virtual ~GLMoleculeObject_bond() {} 28 28 29 29 -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp
re638f9 r7188b1 22 22 #include "GLWorldScene.hpp" 23 23 24 #include "GLMoleculeScene.hpp"25 24 #include "GLMoleculeObject.hpp" 25 #include "GLMoleculeObject_atom.hpp" 26 #include "GLMoleculeObject_bond.hpp" 26 27 27 28 #include "CodePatterns/MemDebug.hpp" 28 29 30 #include "CodePatterns/Log.hpp" 31 29 32 #include "atom.hpp" 33 #include "Bond/bond.hpp" 30 34 #include "molecule.hpp" 31 35 #include "World.hpp" … … 41 45 42 46 GLWorldScene::~GLWorldScene() 43 {} 47 { 48 // remove all elements 49 GLMoleculeObject::cleanMaterialMap(); 50 } 44 51 45 52 /** Initialise the WorldScene with molecules and atoms from World. … … 55 62 Runner++) { 56 63 // create molecule 57 GLMoleculeScene * const molObject = new GLMoleculeScene(this, *Runner); 58 MoleculeSceneList.push_back(molObject); 59 connect (molObject, SIGNAL(clicked(atomId_t, moleculeId_t)), this, SLOT(molClicked(atomId_t, moleculeId_t))); 60 connect (molObject, SIGNAL(hoverChanged()), this, SIGNAL(changed())); 64 for (molecule::const_iterator atomiter = (*Runner)->begin(); 65 atomiter != (*Runner)->end(); 66 ++atomiter) { 67 // create atom objects in scene 68 atomInserted(*atomiter); 69 70 // create its bonds 71 const BondList &bonds = (*atomiter)->getListOfBonds(); 72 for (BondList::const_iterator bonditer = bonds.begin(); 73 bonditer != bonds.end(); 74 ++bonditer) { 75 if ((*bonditer)->leftatom->getId() == (*atomiter)->getId()) { 76 // create bond objects in scene 77 bondInserted(*bonditer); 78 } 79 } 80 } 61 81 } 62 82 } 63 83 } 64 84 85 /** Adds an atom to the scene. 86 * 87 * @param _atom atom to add 88 */ 89 void GLWorldScene::atomInserted(const atom *_atom) 90 { 91 LOG(0, "GLWorldScene: Received signal atomInserted for atom "+toString(_atom->getId())+"."); 92 GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(this, _atom); 93 AtomNodeMap::iterator iter = AtomsinMoleculeMap.find(_atom->getId()); 94 ASSERT(iter == AtomsinMoleculeMap.end(), 95 "GLWorldScene::atomAdded() - same atom "+_atom->getName()+" added again."); 96 AtomsinMoleculeMap.insert( make_pair(_atom->getId(), atomObject) ); 97 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t))); 98 connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(hoverChanged())); 99 emit changed(); 100 } 101 102 /** Removes an atom from the scene. 103 * 104 * @param _atom atom to remove 105 */ 106 void GLWorldScene::atomRemoved(const atom *_atom) 107 { 108 LOG(0, "GLWorldScene: Received signal atomRemoved for atom "+toString(_atom->getId())+"."); 109 // remove all its bonds 110 const BondList& bondlist = _atom->getListOfBonds(); 111 for (BondList::const_iterator iter = bondlist.begin(); iter != bondlist.end(); ++iter) { 112 bondRemoved(*iter); 113 } 114 // remove atoms 115 AtomNodeMap::iterator iter = AtomsinMoleculeMap.find(_atom->getId()); 116 ASSERT(iter != AtomsinMoleculeMap.end(), 117 "GLWorldScene::atomRemoved() - atom "+_atom->getName()+" not on display."); 118 GLMoleculeObject_atom *atomObject = iter->second; 119 atomObject->disconnect(); 120 AtomsinMoleculeMap.erase(iter); 121 delete atomObject; 122 emit changed(); 123 } 124 125 /** Adds an bond to the scene. 126 * 127 * @param _bond bond to add 128 */ 129 void GLWorldScene::bondInserted(const bond *_bond) 130 { 131 const double distance = 132 _bond->leftatom->getPosition().distance(_bond->rightatom->getPosition())/2.; 133 { 134 // left bond 135 const BondIds Leftids( make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()) ); 136 BondNodeMap::iterator iter = BondsinMoleculeMap.find(Leftids); 137 ASSERT(iter == BondsinMoleculeMap.end(), 138 "GLWorldScene::bondAdded() - same left-sided bond "+toString(*_bond)+" added again."); 139 GLMoleculeObject_bond *bondObject = 140 new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::left); 141 BondsinMoleculeMap.insert( make_pair(Leftids, bondObject) ); 142 } 143 { 144 // right bond 145 const BondIds Rightids( make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()) ); 146 BondNodeMap::iterator iter = BondsinMoleculeMap.find(Rightids); 147 ASSERT(iter == BondsinMoleculeMap.end(), 148 "GLWorldScene::bondAdded() - same right-sided bond "+toString(*_bond)+" added again."); 149 GLMoleculeObject_bond *bondObject = 150 new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::right); 151 BondsinMoleculeMap.insert( make_pair(Rightids, bondObject) ); 152 } 153 emit changed(); 154 } 155 156 /** Removes an bond from the scene. 157 * 158 * @param _bond bond to remove 159 */ 160 void GLWorldScene::bondRemoved(const bond *_bond) 161 { 162 { 163 // left bond 164 const BondIds Leftids( make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()) ); 165 BondNodeMap::iterator leftiter = BondsinMoleculeMap.find( Leftids ); 166 ASSERT(leftiter != BondsinMoleculeMap.end(), 167 "GLWorldScene::bondRemoved() - bond "+toString(*_bond)+" not on display."); 168 GLMoleculeObject_bond *bondObject = leftiter->second; 169 BondsinMoleculeMap.erase(leftiter); 170 delete bondObject; 171 } 172 { 173 // right bond 174 const BondIds Rightids( make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()) ); 175 BondNodeMap::iterator rightiter = BondsinMoleculeMap.find( Rightids ); 176 ASSERT(rightiter != BondsinMoleculeMap.end(), 177 "GLWorldScene::bondRemoved() - bond "+toString(*_bond)+" not on display."); 178 GLMoleculeObject_bond *bondObject = rightiter->second; 179 BondsinMoleculeMap.erase(rightiter); 180 delete bondObject; 181 } 182 emit changed(); 183 } 184 65 185 void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const 66 186 { 67 for (List_MoleculeScene::const_iterator iter = MoleculeSceneList.begin();68 iter != MoleculeSceneList.end();69 ++iter) {70 (*iter)->initialize(view, painter);71 }72 }73 187 // Initialize all of the mesh objects that we have as children. 188 foreach (QObject *obj, children()) { 189 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj); 190 if (meshobj) 191 meshobj->initialize(view, painter); 192 } 193 } 74 194 75 195 void GLWorldScene::draw(QGLPainter *painter) const 76 196 { 77 for (List_MoleculeScene::const_iterator iter = MoleculeSceneList.begin(); 78 iter != MoleculeSceneList.end(); 79 ++iter) { 80 (*iter)->draw(painter); 81 } 82 } 83 84 void GLWorldScene::molClicked(atomId_t atom_no, moleculeId_t mol_no) 85 { 86 qDebug("WorldScene: atom %d of molecule %d has been clicked", atom_no, mol_no); 87 } 88 197 // Draw all of the mesh objects that we have as children. 198 foreach (QObject *obj, children()) { 199 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj); 200 if (meshobj) 201 meshobj->draw(painter); 202 } 203 } 204 205 void GLWorldScene::atomClicked(atomId_t no) 206 { 207 qDebug("GLWorldScene: atom %d has been clicked.", no); 208 emit clicked(no); 209 } 210 -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp
re638f9 r7188b1 18 18 #include <Qt/qobject.h> 19 19 20 #include "atom.hpp"21 20 #include "molecule.hpp" 21 22 class atom; 22 23 23 24 class QGLPainter; … … 28 29 class GLMoleculeObject_atom; 29 30 class GLMoleculeObject_bond; 30 class GLMoleculeScene;31 31 32 32 /** This class contains a list of all molecules in the world. … … 53 53 signals: 54 54 void changed(); 55 void pressed(); 56 void released(); 57 void clicked(); 58 void clicked(atomId_t); 59 void doubleClicked(); 60 void hoverChanged(); 55 61 56 62 private slots: 57 void molClicked(atomId_t atom_no, moleculeId_t mol_no); 63 void atomClicked(atomId_t no); 64 void atomInserted(const atom *_atom); 65 void atomRemoved(const atom *_atom); 66 void bondInserted(const bond *_bond); 67 void bondRemoved(const bond *_bond); 58 68 59 69 private: 60 70 void init(); 61 71 62 typedef std::list< GLMoleculeScene * > List_MoleculeScene; 63 64 List_MoleculeScene MoleculeSceneList; 72 typedef std::pair< size_t, size_t> BondIds; 73 typedef std::map< size_t, GLMoleculeObject_atom* > AtomNodeMap; 74 typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap; 75 AtomNodeMap AtomsinMoleculeMap; 76 BondNodeMap BondsinMoleculeMap; 65 77 }; 66 78 -
src/UIElements/Views/Qt4/Qt3D/GLWorldView.cpp
re638f9 r7188b1 26 26 #include "CodePatterns/MemDebug.hpp" 27 27 28 #include "CodePatterns/Log.hpp" 29 30 #include "World.hpp" 31 28 32 GLWorldView::GLWorldView(QWidget *parent) 29 : QGLView(parent), worldscene(NULL)33 : QGLView(parent), Observer("GLWorldView"), worldscene(NULL) 30 34 { 31 35 worldscene = new GLWorldScene(this); … … 34 38 35 39 connect(worldscene, SIGNAL(changed()), this, SLOT(updateGL())); 40 connect(this, SIGNAL(atomInserted(const atom *)), worldscene, SLOT(atomInserted(const atom *))); 41 connect(this, SIGNAL(atomRemoved(const atom *)), worldscene, SLOT(atomRemoved(const atom *))); 42 connect(this, SIGNAL(changed()), this, SLOT(updateGL())); 43 44 // sign on to changes in the world 45 World::getInstance().signOn(this); 46 World::getInstance().signOn(this, World::getInstance().getChannel(World::AtomInserted)); 47 World::getInstance().signOn(this, World::getInstance().getChannel(World::AtomRemoved)); 36 48 } 37 49 … … 41 53 } 42 54 55 /** 56 * Update operation which can be invoked by the observable (which should be the 57 * change tracker here). 58 */ 59 void GLWorldView::update(Observable *publisher) 60 { 61 emit changed(); 62 } 63 64 /** 65 * The observable can tell when it dies. 66 */ 67 void GLWorldView::subjectKilled(Observable *publisher) {} 68 69 /** Listen to specific changes to the world. 70 * 71 * @param publisher ref to observable. 72 * @param notification type of notification 73 */ 74 void GLWorldView::recieveNotification(Observable *publisher, Notification_ptr notification) 75 { 76 switch (notification->getChannelNo()) { 77 case World::AtomInserted: 78 { 79 const atom *_atom = World::getInstance().lastChanged<atom>(); 80 LOG(0, "GLWorldView: Received notification that atom "+toString(_atom->getId())+" has been inserted."); 81 emit atomInserted(_atom); 82 break; 83 } 84 case World::AtomRemoved: 85 { 86 const atom *_atom = World::getInstance().lastChanged<atom>(); 87 LOG(0, "GLWorldView: Received notification that atom "+toString(_atom->getId())+" has been removed."); 88 emit atomRemoved(_atom); 89 break; 90 } 91 default: 92 ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here."); 93 break; 94 } 95 } 43 96 44 97 void GLWorldView::initializeGL(QGLPainter *painter) -
src/UIElements/Views/Qt4/Qt3D/GLWorldView.hpp
re638f9 r7188b1 16 16 #include "qglview.h" 17 17 18 #include "CodePatterns/Observer.hpp" 19 20 #include "World.hpp" 21 18 22 class QKeyEvent; 19 23 class GLWorldScene; … … 24 28 * 25 29 */ 26 class GLWorldView : public QGLView 30 class GLWorldView : public QGLView, public Observer 27 31 { 28 32 Q_OBJECT … … 31 35 virtual ~GLWorldView(); 32 36 37 // Observer functions 38 void update(Observable *publisher); 39 void subjectKilled(Observable *publisher); 40 void recieveNotification(Observable *publisher, Notification_ptr notification); 41 33 42 public slots: 43 44 signals: 45 void changed(); 46 void atomInserted(const atom *_atom); 47 void atomRemoved(const atom *_atom); 48 void moleculeInserted(const molecule *_mol); 49 void moleculeRemoved(const molecule *_mol); 34 50 35 51 protected: -
src/World.cpp
re638f9 r7188b1 52 52 const unsigned int MAX_FRAGMENTATION_SKIPS=100; 53 53 54 /******************************* Notifications ************************/ 55 56 57 atom* World::_lastchangedatom = NULL; 58 molecule* World::_lastchangedmol = NULL; 59 54 60 /******************************* getter and setter ************************/ 55 61 periodentafel *&World::getPeriode() … … 173 179 molecules[mol->getId()] = mol; 174 180 mol->signOn(this); 181 _lastchangedmol = mol; 182 NOTIFY(MoleculeInserted); 175 183 return mol; 176 184 } … … 186 194 molecule *mol = molecules[id]; 187 195 ASSERT(mol,"Molecule id that was meant to be destroyed did not exist"); 196 _lastchangedmol = mol; 197 NOTIFY(MoleculeRemoved); 188 198 DeleteMolecule(mol); 189 199 molecules.erase(id); … … 199 209 // store the atom by ID 200 210 atoms[res->getId()] = res; 211 _lastchangedatom = res; 212 NOTIFY(AtomInserted); 201 213 return res; 202 214 } … … 222 234 atom *atom = atoms[id]; 223 235 ASSERT(atom,"Atom ID that was meant to be destroyed did not exist"); 236 _lastchangedatom = atom; 237 NOTIFY(AtomRemoved); 224 238 DeleteAtom(atom); 225 239 atoms.erase(id); … … 778 792 cell_size->setM(domain); 779 793 defaultName = "none"; 794 NotificationChannels = new Channels(this); 795 for (size_t type = 0; type < (size_t)NotificationType_MAX; ++type) 796 NotificationChannels->addChannel(type); 780 797 molecules_deprecated->signOn(this); 781 798 } … … 796 813 } 797 814 atoms.clear(); 815 816 // empty notifications 817 delete NotificationChannels; 818 798 819 delete BG; 799 820 delete periode; -
src/World.hpp
re638f9 r7188b1 55 55 /********************************************** Class World *******************************/ 56 56 57 namespace detail { 58 template <class T> const T* lastChanged() 59 { 60 ASSERT(0, "detail::lastChanged() - only specializations may be used."); 61 return NULL; 62 } 63 } 64 57 65 class World : public Singleton<World>, public Observable 58 66 { … … 84 92 typedef ATOMSET(std::vector) AtomComposite; 85 93 86 /***** getter and setter *****/ 94 /******* Notifications *******/ 95 96 //!> enumeration of present notification types 97 enum NotificationType { 98 AtomInserted, 99 AtomRemoved, 100 AtomChanged, 101 MoleculeInserted, 102 MoleculeRemoved, 103 MoleculeChanged, 104 NotificationType_MAX 105 }; 106 107 //>! access to last changed element (atom or molecule) 108 template <class T> const T* lastChanged() const 109 { return detail::lastChanged<T>(); } 110 111 /***** getter and setter *****/ 87 112 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object 88 113 /** … … 106 131 */ 107 132 config *&getConfig(); 133 134 /** Returns a notification_ptr for a specific type. 135 * 136 * @param type request type 137 * @return reference to instance 138 */ 139 Notification_ptr getNotification(enum NotificationType type) const; 108 140 109 141 /** … … 385 417 void defragMoleculeIdPool(); 386 418 419 friend const atom *detail::lastChanged<atom>(); 420 friend const molecule *detail::lastChanged<molecule>(); 421 static atom *_lastchangedatom; 422 static molecule*_lastchangedmol; 423 387 424 BondGraph *BG; 388 425 periodentafel *periode; … … 442 479 }; 443 480 481 /** Externalized stuff as member functions cannot be specialized without 482 * specializing the class, too. 483 */ 484 namespace detail { 485 template <> inline const atom* lastChanged<atom>() { return World::_lastchangedatom; } 486 template <> inline const molecule* lastChanged<molecule>() { return World::_lastchangedmol; } 487 } 488 489 444 490 #endif /* WORLD_HPP_ */ -
src/atom_atominfo.cpp
re638f9 r7188b1 121 121 void AtomInfo::set(size_t i, const double value) 122 122 { 123 OBSERVE; 124 NOTIFY(AtomObservable::PositionChanged); 123 125 ASSERT(AtomicPosition.size() > WorldTime::getTime(), 124 126 "AtomInfo::set() - Access out of range: " … … 146 148 } 147 149 148 void AtomInfo::setType(const element* _type) { 150 void AtomInfo::setType(const element* _type) 151 { 152 OBSERVE; 153 NOTIFY(AtomObservable::ElementChanged); 149 154 AtomicElement = _type; 150 155 } 151 156 152 void AtomInfo::setType(const int Z) { 157 void AtomInfo::setType(const int Z) 158 { 159 OBSERVE; 160 NOTIFY(AtomObservable::ElementChanged); 153 161 const element *elem = World::getInstance().getPeriode()->FindElement(Z); 154 162 setType(elem); … … 187 195 void AtomInfo::setAtomicVelocity(const Vector &_newvelocity) 188 196 { 197 OBSERVE; 198 NOTIFY(AtomObservable::VelocityChanged); 189 199 ASSERT(WorldTime::getTime() < AtomicVelocity.size(), 190 200 "AtomInfo::setAtomicVelocity() - Access out of range: " … … 196 206 void AtomInfo::setAtomicVelocityAtStep(const unsigned int _step, const Vector &_newvelocity) 197 207 { 208 OBSERVE; 209 if (WorldTime::getTime() == _step) 210 NOTIFY(AtomObservable::VelocityChanged); 198 211 const unsigned int size = AtomicVelocity.size(); 199 212 ASSERT(_step <= size, … … 229 242 void AtomInfo::setAtomicForce(const Vector &_newforce) 230 243 { 244 OBSERVE; 245 NOTIFY(AtomObservable::VelocityChanged); 231 246 ASSERT(WorldTime::getTime() < AtomicForce.size(), 232 247 "AtomInfo::setAtomicForce() - Access out of range: " … … 238 253 void AtomInfo::setAtomicForceAtStep(const unsigned int _step, const Vector &_newforce) 239 254 { 255 OBSERVE; 256 if (WorldTime::getTime() == _step) 257 NOTIFY(AtomObservable::VelocityChanged); 240 258 const unsigned int size = AtomicForce.size(); 241 259 ASSERT(_step <= size, … … 258 276 void AtomInfo::setFixedIon(const bool _fixedion) 259 277 { 278 OBSERVE; 279 NOTIFY(AtomObservable::PropertyChanged); 260 280 FixedIon = _fixedion; 261 281 } … … 263 283 void AtomInfo::setPosition(const Vector& _vector) 264 284 { 285 OBSERVE; 286 NOTIFY(AtomObservable::PositionChanged); 265 287 ASSERT(WorldTime::getTime() < AtomicPosition.size(), 266 288 "AtomInfo::setPosition() - Access out of range: " … … 273 295 void AtomInfo::setPositionAtStep(unsigned int _step, const Vector& _vector) 274 296 { 297 OBSERVE; 298 if (WorldTime::getTime() == _step) 299 NOTIFY(AtomObservable::PositionChanged); 275 300 const unsigned int size = AtomicPosition.size(); 276 301 ASSERT(_step <= size, … … 289 314 const VectorInterface& AtomInfo::operator+=(const Vector& b) 290 315 { 316 OBSERVE; 317 NOTIFY(AtomObservable::PositionChanged); 291 318 ASSERT(WorldTime::getTime() < AtomicPosition.size(), 292 319 "AtomInfo::operator+=() - Access out of range: " … … 299 326 const VectorInterface& AtomInfo::operator-=(const Vector& b) 300 327 { 328 OBSERVE; 329 NOTIFY(AtomObservable::PositionChanged); 301 330 ASSERT(WorldTime::getTime() < AtomicPosition.size(), 302 331 "AtomInfo::operator-=() - Access out of range: " … … 367 396 VectorInterface &AtomInfo::operator=(const Vector& _vector) 368 397 { 398 OBSERVE; 399 NOTIFY(AtomObservable::PositionChanged); 369 400 ASSERT(WorldTime::getTime() < AtomicPosition.size(), 370 401 "AtomInfo::operator=() - Access out of range: " … … 377 408 void AtomInfo::ScaleAll(const double *factor) 378 409 { 410 OBSERVE; 411 NOTIFY(AtomObservable::PositionChanged); 379 412 ASSERT(WorldTime::getTime() < AtomicPosition.size(), 380 413 "AtomInfo::ScaleAll() - Access out of range: " … … 386 419 void AtomInfo::ScaleAll(const Vector &factor) 387 420 { 421 OBSERVE; 422 NOTIFY(AtomObservable::PositionChanged); 388 423 ASSERT(WorldTime::getTime() < AtomicPosition.size(), 389 424 "AtomInfo::ScaleAll() - Access out of range: " … … 395 430 void AtomInfo::Scale(const double factor) 396 431 { 432 OBSERVE; 433 NOTIFY(AtomObservable::PositionChanged); 397 434 ASSERT(WorldTime::getTime() < AtomicPosition.size(), 398 435 "AtomInfo::Scale() - Access out of range: " … … 404 441 void AtomInfo::Zero() 405 442 { 443 OBSERVE; 444 NOTIFY(AtomObservable::PositionChanged); 406 445 ASSERT(WorldTime::getTime() < AtomicPosition.size(), 407 446 "AtomInfo::Zero() - Access out of range: " … … 413 452 void AtomInfo::One(const double one) 414 453 { 454 OBSERVE; 455 NOTIFY(AtomObservable::PositionChanged); 415 456 ASSERT(WorldTime::getTime() < AtomicPosition.size(), 416 457 "AtomInfo::One() - Access out of range: " … … 422 463 void AtomInfo::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors) 423 464 { 465 OBSERVE; 466 NOTIFY(AtomObservable::PositionChanged); 424 467 ASSERT(WorldTime::getTime() < AtomicPosition.size(), 425 468 "AtomInfo::LinearCombinationOfVectors() - Access out of range: " … … 432 475 * returns the kinetic energy of this atom at a given time step 433 476 */ 434 double AtomInfo::getKineticEnergy(const unsigned int _step) const{ 477 double AtomInfo::getKineticEnergy(const unsigned int _step) const 478 { 435 479 ASSERT(_step < AtomicPosition.size(), 436 480 "AtomInfo::getKineticEnergy() - Access out of range: " … … 440 484 } 441 485 442 Vector AtomInfo::getMomentum(const unsigned int _step) const{ 486 Vector AtomInfo::getMomentum(const unsigned int _step) const 487 { 443 488 ASSERT(_step < AtomicPosition.size(), 444 489 "AtomInfo::getMomentum() - Access out of range: " … … 475 520 if (dest == src) // self assignment check 476 521 return; 522 523 if (WorldTime::getTime() == dest){ 524 NOTIFY(AtomObservable::PositionChanged); 525 NOTIFY(AtomObservable::VelocityChanged); 526 NOTIFY(AtomObservable::ForceChanged); 527 } 477 528 478 529 ASSERT(dest < AtomicPosition.size(), -
src/atom_atominfo.hpp
re638f9 r7188b1 21 21 #include <vector> 22 22 23 #include "atom_observable.hpp" 24 23 25 #include "LinearAlgebra/Vector.hpp" 24 26 #include "LinearAlgebra/VectorInterface.hpp" … … 33 35 /********************************************** declarations *******************************/ 34 36 35 class AtomInfo : public VectorInterface {37 class AtomInfo : public VectorInterface, public virtual AtomObservable { 36 38 37 39 public: -
src/atom_bondedparticleinfo.cpp
re638f9 r7188b1 56 56 BondList& BondedParticleInfo::getListOfBonds() 57 57 { 58 // todo: here we actually need a container on whose destruction notifiy is emitted, i.e. 59 // similar or simply an ObservedContainer. 60 OBSERVE; 61 NOTIFY(AtomObservable::BondsChanged); 58 62 const unsigned int size = ListOfBonds.size(); 59 63 ASSERT(WorldTime::getTime() <= size, -
src/atom_bondedparticleinfo.hpp
re638f9 r7188b1 19 19 #endif 20 20 21 #include "atom_observable.hpp" 22 21 23 #include <list> 22 24 … … 30 32 /********************************************** declarations *******************************/ 31 33 32 class BondedParticleInfo {34 class BondedParticleInfo : public virtual AtomObservable { 33 35 friend class BondedParticle; 34 36 public: -
src/atom_particleinfo.cpp
re638f9 r7188b1 47 47 48 48 void ParticleInfo::setName(const string& _name){ 49 OBSERVE; 50 NOTIFY(AtomObservable::NameChanged); 49 51 name = _name; 50 52 } … … 63 65 void ParticleInfo::setNr(const int newnr) 64 66 { 67 OBSERVE; 68 NOTIFY(AtomObservable::PropertyChanged); 65 69 Nr = newnr; 66 70 } -
src/atom_particleinfo.hpp
re638f9 r7188b1 18 18 #endif 19 19 20 #include "atom_observable.hpp" 21 20 22 #include <iosfwd> 21 23 #include <string> … … 26 28 /********************************************** declarations *******************************/ 27 29 28 class ParticleInfo {30 class ParticleInfo : public virtual AtomObservable { 29 31 public: 30 32 ParticleInfo();
Note:
See TracChangeset
for help on using the changeset viewer.