Changeset 2ad1ec for src/UIElements
- Timestamp:
- Feb 17, 2012, 3:24:17 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:
- 8bf9c6
- Parents:
- 3f7587
- git-author:
- Frederik Heber <heber@…> (01/05/12 16:10:53)
- git-committer:
- Frederik Heber <heber@…> (02/17/12 15:24:17)
- Location:
- src/UIElements/Views/Qt4/Qt3D
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp
r3f7587 r2ad1ec 30 30 #include "CodePatterns/Observer/Notification.hpp" 31 31 32 #include "Atom/atom.hpp" 33 #include "Bond/bond.hpp" 32 34 #include "Descriptors/AtomIdDescriptor.hpp" 33 35 #include "Element/element.hpp" 34 36 #include "LinearAlgebra/Vector.hpp" 37 #include "GLMoleculeObject_bond.hpp" 35 38 #include "World.hpp" 36 39 … … 45 48 46 49 GLMoleculeObject_atom::GLMoleculeObject_atom(QObject *parent, const atom *atomref) : 47 GLMoleculeObject(createAtom(parent), parent), Observer("GLMoleculeObject_atom"), _atom(atomref) 50 GLMoleculeObject(createAtom(parent), parent), 51 Observer(std::string("GLMoleculeObject_atom")+toString(atomref->getId())), 52 _atom(atomref) 48 53 { 49 54 // sign on as observer (obtain non-const instance before) … … 51 56 atomref->signOn(this, AtomObservable::PositionChanged); 52 57 atomref->signOn(this, AtomObservable::ElementChanged); 53 atomref->signOn(this, AtomObservable::Bonds Changed);58 atomref->signOn(this, AtomObservable::BondsAdded); 54 59 55 60 // set the object's id … … 66 71 _atom->signOff(this, AtomObservable::PositionChanged); 67 72 _atom->signOff(this, AtomObservable::ElementChanged); 68 _atom->signOff(this, AtomObservable::Bonds Changed);73 _atom->signOff(this, AtomObservable::BondsAdded); 69 74 } 70 75 … … 153 158 resetPosition(); 154 159 break; 155 case AtomObservable::BondsChanged: 156 emit BondsChanged(_atom); 157 break; 160 case AtomObservable::BondsAdded: 161 { 162 ASSERT(!_atom->getListOfBonds().empty(), 163 "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty."); 164 const bond * _bond = *(_atom->getListOfBonds().rbegin()); 165 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ? 166 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right; 167 emit BondsInserted(_bond, side); 168 break; 169 } 158 170 default: 159 171 //setProperties(); -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp
r3f7587 r2ad1ec 18 18 #include "CodePatterns/Observer/Observer.hpp" 19 19 20 #include "Atom/atom.hpp" 20 #include "GLMoleculeObject_bond.hpp" 21 22 class atom; 23 class bond; 21 24 22 25 class GLMoleculeObject_atom : public GLMoleculeObject, public Observer … … 37 40 signals: 38 41 void clicked(atomId_t); 39 void Bonds Changed(const atom *_atom);42 void BondsInserted(const bond *_bond, const GLMoleculeObject_bond::SideOfBond side); 40 43 41 44 private: -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp
r3f7587 r2ad1ec 31 31 #include "CodePatterns/Assert.hpp" 32 32 #include "CodePatterns/Log.hpp" 33 #include "CodePatterns/Observer/Notification.hpp" 33 34 #include "Atom/atom.hpp" 34 35 #include "Bond/bond.hpp" … … 49 50 } 50 51 51 GLMoleculeObject_bond::GLMoleculeObject_bond(QObject *parent, const bond *bondref, double distance, enum SideOfBond side) : 52 GLMoleculeObject(createBond(parent, distance), parent), _bond(bondref) 52 GLMoleculeObject_bond::GLMoleculeObject_bond(QObject *parent, const bond *bondref, const double distance, const enum SideOfBond side) : 53 GLMoleculeObject(createBond(parent, distance), parent), 54 Observer(std::string("GLMoleculeObject_bond") 55 +toString(bondref->leftatom->getId()) 56 +std::string("-") 57 +toString(bondref->rightatom->getId())), 58 _bond(bondref), 59 BondSide(side) 53 60 { 61 // sign on as observer (obtain non-const instance before) 62 _bond->signOn(this, BondObservable::BondRemoved); 63 54 64 Vector Position; 55 65 Vector OtherPosition; 56 66 size_t elementno = 0; 57 switch ( side) {67 switch (BondSide) { 58 68 case left: 59 69 Position = _bond->leftatom->getPosition(); … … 77 87 default: 78 88 ASSERT(0, 79 "GLMoleculeObject_bond::GLMoleculeObject_bond() - side is not a valid argument: "+toString( side)+".");89 "GLMoleculeObject_bond::GLMoleculeObject_bond() - side is not a valid argument: "+toString(BondSide)+"."); 80 90 break; 81 91 } … … 113 123 setRotationAngle(alpha/M_PI*180.); 114 124 } 125 126 GLMoleculeObject_bond::~GLMoleculeObject_bond() 127 { 128 // sign on as observer (obtain non-const instance before) 129 _bond->signOff(this, BondObservable::BondRemoved); 130 131 LOG(2, "INFO: Destroying GLMoleculeObject_bond to bond " << *_bond << " and side " << BondSide << "."); 132 } 133 134 void GLMoleculeObject_bond::update(Observable *publisher) 135 { 136 #ifdef LOG_OBSERVER 137 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(this) << " from bond " << *_bond << "."; 138 #endif 139 } 140 141 void GLMoleculeObject_bond::subjectKilled(Observable *publisher) 142 { 143 LOG(2, "INFO: Received subjectKilled from " << *_bond << "."); 144 switch (BondSide) { 145 case left: 146 emit BondRemoved(_bond->leftatom->getId(), _bond->rightatom->getId()); 147 break; 148 case right: 149 emit BondRemoved(_bond->rightatom->getId(), _bond->leftatom->getId()); 150 break; 151 default: 152 ASSERT(0, 153 "GLMoleculeObject_bond::subjectKilled() - side is not a valid argument: "+toString(BondSide)+"."); 154 break; 155 } 156 delete this; 157 } 158 159 void GLMoleculeObject_bond::recieveNotification(Observable *publisher, Notification_ptr notification) 160 { 161 #ifdef LOG_OBSERVER 162 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this) 163 << " received notification from bond " << *_bond << " for channel " 164 << notification->getChannelNo() << "."; 165 #endif 166 switch (notification->getChannelNo()) { 167 case BondObservable::BondRemoved: 168 LOG(2, "INFO: Received notification of BondRemoved from " << *_bond << "."); 169 switch (BondSide) { 170 case left: 171 emit BondRemoved(_bond->leftatom->getId(), _bond->rightatom->getId()); 172 break; 173 case right: 174 emit BondRemoved(_bond->rightatom->getId(), _bond->leftatom->getId()); 175 break; 176 default: 177 ASSERT(0, 178 "GLMoleculeObject_bond::recieveNotification() - side is not a valid argument: "+toString(BondSide)+"."); 179 break; 180 } 181 delete this; 182 break; 183 default: 184 break; 185 } 186 } -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp
r3f7587 r2ad1ec 16 16 #include "GLMoleculeObject.hpp" 17 17 18 #include "CodePatterns/Observer/Observer.hpp" 19 20 #include "types.hpp" 21 18 22 class bond; 19 23 20 class GLMoleculeObject_bond : public GLMoleculeObject 24 class GLMoleculeObject_bond : public GLMoleculeObject, public Observer 21 25 { 22 26 Q_OBJECT … … 24 28 enum SideOfBond { left, right }; 25 29 26 GLMoleculeObject_bond(QObject *parent, const bond *bondref, double distance,enum SideOfBond side);27 virtual ~GLMoleculeObject_bond() {}30 GLMoleculeObject_bond(QObject *parent, const bond *bondref, const double distance, const enum SideOfBond side); 31 virtual ~GLMoleculeObject_bond(); 28 32 33 // Observer functions 34 void update(Observable *publisher); 35 void subjectKilled(Observable *publisher); 36 void recieveNotification(Observable *publisher, Notification_ptr notification); 37 38 signals: 39 void BondRemoved(const atomId_t leftnr, const atomId_t rightnr); 29 40 30 41 private: 31 42 const bond *_bond; 43 const enum SideOfBond BondSide; 32 44 }; 33 45 -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp
r3f7587 r2ad1ec 39 39 #include "World.hpp" 40 40 41 #include <iostream> 42 41 43 using namespace MoleCuilder; 44 45 std::ostream &operator<<(std::ostream &ost, const GLWorldScene::BondIds &t) 46 { 47 ost << t.first << "," << t.second; 48 return ost; 49 } 42 50 43 51 GLWorldScene::GLWorldScene(QObject *parent) … … 74 82 75 83 // create bond objects in scene 76 bondsChanged(*atomiter); 84 const BondList &bondlist = (*atomiter)->getListOfBonds(); 85 for (BondList::const_iterator bonditer = bondlist.begin(); 86 bonditer != bondlist.end(); 87 ++bonditer) { 88 const bond *_bond = *bonditer; 89 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == *atomiter) ? 90 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right; 91 bondInserted(_bond, side); 92 } 77 93 } 78 94 } … … 94 110 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t))); 95 111 connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(changed())); 96 connect (atomObject, SIGNAL(Bonds Changed(const atom *)), this, SLOT(bondsChanged(const atom *)));97 bondsChanged(_atom);112 connect (atomObject, SIGNAL(BondsInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond *, const GLMoleculeObject_bond::SideOfBond))); 113 //bondsChanged(_atom); 98 114 emit changeOccured(); 99 115 } … … 106 122 { 107 123 LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atom->getId())+"."); 108 // remove all its bonds 109 const BondList& bondlist = _atom->getListOfBonds(); 110 for (BondList::const_iterator iter = bondlist.begin(); iter != bondlist.end(); ++iter) { 111 bondRemoved((*iter)->leftatom->getId(), (*iter)->rightatom->getId()); 112 bondRemoved((*iter)->rightatom->getId(), (*iter)->leftatom->getId()); 113 } 124 // bonds are removed by signal coming from ~bond 114 125 // remove atoms 115 126 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId()); … … 123 134 } 124 135 125 /** Updates the bond structure of the signaled \a _atom.126 *127 * @param _atom atom whose bonds changed.128 */129 void GLWorldScene::bondsChanged(const atom *_atom)130 {131 const atomId_t id = _atom->getId();132 133 // create list with all present bonds134 std::set< atomId_t > presentBonds;135 std::pair< BondIdsMap::const_iterator, BondIdsMap::const_iterator> range =136 BondIdsinSceneMap.equal_range( id );137 for (BondIdsMap::const_iterator iter = range.first; iter != range.second; ++iter) {138 const atomId_t otherid = iter->second;139 #ifndef NDEBUG140 std::set< atomId_t >::const_iterator iter = presentBonds.find(otherid);141 ASSERT(iter == presentBonds.end(),142 "GLWorldScene::BondsChanged() - bond id "+toString(otherid)+" for atom "143 +toString(id)+" present twice.");144 #endif145 presentBonds.insert( otherid );146 }147 LOG(3, "INFO: We have the following bonds: "+toString(presentBonds)+".");148 149 // search for added bonds150 const BondList &bondlist = _atom->getListOfBonds();151 for (BondList::const_iterator bonditer = bondlist.begin();152 bonditer != bondlist.end();153 ++bonditer) {154 const bond *_bond = *bonditer;155 const atomId_t otherid = _bond->GetOtherAtom(_atom)->getId();156 const BondIds ids = std::make_pair( id, otherid );157 BondNodeMap::const_iterator iter = BondsinSceneMap.find(ids);158 if (iter != BondsinSceneMap.end()) {159 // bond is already present160 std::set< atomId_t >::const_iterator iter = presentBonds.find(otherid);161 ASSERT(iter != presentBonds.end(),162 "GLWorldScene::BondsChanged() - other id "+toString(otherid)+" for atom "163 +toString(_atom->getId())+" not present in BondIdsinSceneMap.");164 presentBonds.erase(otherid);165 LOG(0, "Removing "+toString(otherid)+" from presentBonds.");166 } else {167 // insert new bond168 bondInserted(_bond);169 }170 }171 if (!presentBonds.empty())172 ELOG(2, "The following bonds should not be present: "+toString(presentBonds)+".");173 174 // remove all still presentBonds175 for (std::set< atomId_t >::iterator iter = presentBonds.begin();176 !presentBonds.empty(); iter = presentBonds.begin()) {177 bondRemoved( id, *iter );178 }179 }180 181 136 /** Adds a bond to the scene. 182 137 * 183 138 * @param _bond bond to add 184 */ 185 void GLWorldScene::bondInserted(const bond *_bond) 139 * @param side which side of the bond (left or right) 140 */ 141 void GLWorldScene::bondInserted(const bond *_bond, const enum GLMoleculeObject_bond::SideOfBond side) 186 142 { 187 143 LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+"."); 144 //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << "."); 188 145 const double distance = 189 146 _bond->leftatom->getPosition().distance(_bond->rightatom->getPosition())/2.; 190 { 191 // left bond 192 const BondIds Leftids( make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()) ); 193 BondNodeMap::iterator iter = BondsinSceneMap.find(Leftids); 194 ASSERT(iter == BondsinSceneMap.end(), 195 "GLWorldScene::bondAdded() - same left-sided bond "+toString(*_bond)+" added again."); 196 GLMoleculeObject_bond *bondObject = 197 new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::left); 198 BondsinSceneMap.insert( make_pair(Leftids, bondObject) ); 199 BondIdsinSceneMap.insert( Leftids ); 147 148 BondIds ids; 149 switch (side) { 150 case GLMoleculeObject_bond::left: 151 ids = std::make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()); 152 break; 153 case GLMoleculeObject_bond::right: 154 ids = std::make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()); 155 break; 200 156 } 201 { 202 // right bond 203 const BondIds Rightids( make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()) ); 204 BondNodeMap::iterator iter = BondsinSceneMap.find(Rightids); 205 ASSERT(iter == BondsinSceneMap.end(), 206 "GLWorldScene::bondAdded() - same right-sided bond "+toString(*_bond)+" added again."); 207 GLMoleculeObject_bond *bondObject = 208 new GLMoleculeObject_bond(this, _bond, distance, GLMoleculeObject_bond::right); 209 BondsinSceneMap.insert( make_pair(Rightids, bondObject) ); 210 BondIdsinSceneMap.insert( Rightids ); 211 } 157 #ifndef NDEBUG 158 BondNodeMap::iterator iter = BondsinSceneMap.find(ids); 159 ASSERT(iter == BondsinSceneMap.end(), 160 "GLWorldScene::bondAdded() - same left-sided bond "+toString(*_bond)+" added again."); 161 #endif 162 GLMoleculeObject_bond *bondObject = 163 new GLMoleculeObject_bond(this, _bond, distance, side); 164 connect ( 165 bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)), 166 this, SLOT(bondRemoved(const atomId_t, const atomId_t))); 167 BondsinSceneMap.insert( make_pair(ids, bondObject) ); 168 // BondIdsinSceneMap.insert( Leftids ); 212 169 emit changeOccured(); 213 170 } … … 219 176 void GLWorldScene::bondRemoved(const atomId_t leftnr, const atomId_t rightnr) 220 177 { 221 LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString( leftnr)+".");178 LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+"."); 222 179 { 223 180 // left bond … … 227 184 "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-" 228 185 +toString(rightnr)+" not on display."); 229 GLMoleculeObject_bond *bondObject = leftiter->second;186 //GLMoleculeObject_bond *bondObject = leftiter->second; 230 187 BondsinSceneMap.erase(leftiter); 231 delete bondObject; 188 //delete bondObject; // is done by signal from bond itself 189 //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << "."); 232 190 } 233 // remove from bond ids 234 std::pair<BondIdsMap::iterator, BondIdsMap::iterator> leftrange = 235 BondIdsinSceneMap.equal_range(leftnr); 236 BondIdsMap::iterator iter; 237 for (iter = leftrange.first; iter != leftrange.second; ++iter) { 238 if (iter->second == rightnr) { 239 BondIdsinSceneMap.erase(iter); 240 break; 241 } 242 } 243 ASSERT(iter != leftrange.second, 244 "GLWorldScene::bondRemoved() - could not find (" 245 +toString(leftnr)+"-"+toString(rightnr)+" in BondIdsinSceneMap."); 191 246 192 emit changeOccured(); 247 193 } -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp
r3f7587 r2ad1ec 20 20 #include "molecule.hpp" 21 21 22 #include <iosfwd> 23 24 #include "GLMoleculeObject_bond.hpp" 25 22 26 class atom; 23 27 … … 28 32 class GLMoleculeObject; 29 33 class GLMoleculeObject_atom; 30 class GLMoleculeObject_bond;31 34 32 35 /** This class contains a list of all molecules in the world. … … 65 68 void atomInserted(const atom *_atom); 66 69 void atomRemoved(const atom *_atom); 67 void bondsChanged(const atom *_atom); 70 void bondInserted(const bond *_bond, const GLMoleculeObject_bond::SideOfBond side); 71 void bondRemoved(const atomId_t leftnr, const atomId_t rightnr); 68 72 69 73 private: 70 74 void init(); 71 void bondInserted(const bond *_bond);72 void bondRemoved(const atomId_t leftnr, const atomId_t rightnr);73 75 76 private: 74 77 typedef std::pair< atomId_t, atomId_t> BondIds; 78 friend std::ostream &operator<<(std::ostream &ost, const BondIds &t); 79 75 80 typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap; 76 81 typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap; 77 typedef std::multimap< atomId_t, atomId_t > BondIdsMap;78 82 AtomNodeMap AtomsinSceneMap; 79 BondIdsMap BondIdsinSceneMap;80 83 BondNodeMap BondsinSceneMap; 81 84 }; 82 85 83 86 std::ostream &operator<<(std::ostream &ost, const GLWorldScene::BondIds &t); 84 87 85 88 #endif /* GLWORLDSCENE_HPP_ */
Note:
See TracChangeset
for help on using the changeset viewer.