- Timestamp:
- Feb 12, 2016, 11:15:06 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:
- 0f7ffe
- Parents:
- 47f0e4
- git-author:
- Frederik Heber <heber@…> (01/25/16 11:09:33)
- git-committer:
- Frederik Heber <heber@…> (02/12/16 23:15:06)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp
r47f0e4 r8d5fbf1 45 45 46 46 #include "CodePatterns/Assert.hpp" 47 #include "CodePatterns/IteratorAdaptors.hpp" 47 48 #include "CodePatterns/Log.hpp" 48 49 #include "CodePatterns/Observer/Notification.hpp" … … 61 62 #include "Tesselation/BoundaryTriangleSet.hpp" 62 63 #include "Tesselation/CandidateForTesselation.hpp" 64 #include "UIElements/Views/Qt4/QtInstanceInformationBoard.hpp" 63 65 #include "Atom/TesselPoint.hpp" 64 66 #include "World.hpp" … … 70 72 71 73 #include "GLMoleculeObject_atom.hpp" 72 73 static Observable::channels_t getAtomsChannels()74 {75 Observable::channels_t channels;76 channels += molecule::AtomInserted, molecule::AtomRemoved;77 return channels;78 }79 74 80 75 static Observable::channels_t getAllAtomicChangesChannels() … … 85 80 } 86 81 82 static Observable::channels_t getAllAtomicObservedChannels() 83 { 84 Observable::channels_t channels; 85 channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved; 86 return channels; 87 } 88 87 89 // static instances 88 const Observable::channels_t GLMoleculeObject_molecule::AtomsChannels(getAtomsChannels());89 90 const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels()); 90 91 const Observable::channels_t GLMoleculeObject_molecule::BoundingBoxChannels(1, molecule::BoundingBoxChanged); … … 101 102 } 102 103 103 GLMoleculeObject_molecule::GLMoleculeObject_molecule(QObject *parent, const moleculeId_t _molid) : 104 GLMoleculeObject_molecule::GLMoleculeObject_molecule( 105 QObject *parent, 106 const moleculeId_t _molid, 107 QtInstanceInformationBoard * _board, 108 std::vector<boost::any> _ObservedValues) : 104 109 GLMoleculeObject((QGLSceneNode *)NULL, parent), 105 110 Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)), … … 110 115 * the class has not been fully constructed yet. "This" itself seems to be working fine. 111 116 */ 112 ObservedValues( MAX_ObservedTypes),117 ObservedValues(_ObservedValues), 113 118 subjectKilledCount(0), 114 119 TesselationHullUpdater( … … 120 125 "MoleculeTesselationHull_"+toString(_molid), 121 126 HullChannels), 122 hoverAtomId(-1) 123 { 124 boost::function<void(const moleculeId_t)> subjectKilled = 125 boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this, _molid); 126 initObservedValues(ObservedValues, _molid, molref, subjectKilled); 127 127 hoverAtomId(-1), 128 AllsignedOnChannels(getAllAtomicObservedChannels().size()), 129 signedOnChannels(0), 130 board(_board) 131 { 132 init(_molid); 133 } 134 135 GLMoleculeObject_molecule::GLMoleculeObject_molecule( 136 QGLSceneNode *mesh[], 137 QObject *parent, 138 const moleculeId_t _molid, 139 QtInstanceInformationBoard * _board, 140 std::vector<boost::any> _ObservedValues) : 141 GLMoleculeObject(mesh, parent), 142 Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)), 143 owner(NULL), 144 molref(getMolecule(_molid)), 145 /* We must not use boost::cref(this) as "this" has not been properly constructed and seemingly 146 * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because 147 * the class has not been fully constructed yet. "This" itself seems to be working fine. 148 */ 149 ObservedValues(_ObservedValues), 150 subjectKilledCount(0), 151 TesselationHullUpdater( 152 boost::bind(&GLMoleculeObject_molecule::updateTesselationHull, this) 153 ), 154 TesselationHull( 155 molref, 156 TesselationHullUpdater, 157 "MoleculeTesselationHull_"+toString(_molid), 158 HullChannels), 159 hoverAtomId(-1), 160 AllsignedOnChannels(getAllAtomicObservedChannels().size()), 161 signedOnChannels(0), 162 board(_board) 163 { 164 init(_molid); 165 } 166 167 void GLMoleculeObject_molecule::init(const moleculeId_t _molid) 168 { 128 169 setObjectId(_molid); 129 170 setMaterial(getMaterial(1)); … … 133 174 // initially, atoms and bonds should be visible 134 175 m_visible = false; 176 177 activateObserver(); 135 178 136 179 connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *))); … … 147 190 } 148 191 149 GLMoleculeObject_molecule::GLMoleculeObject_molecule(150 QGLSceneNode *mesh[],151 QObject *parent,152 const moleculeId_t _molid) :153 GLMoleculeObject(mesh, parent),154 Observer(std::string("GLMoleculeObject_molecule")+toString(_molid)),155 owner(NULL),156 molref(getMolecule(_molid)),157 /* We must not use boost::cref(this) as "this" has not been properly constructed and seemingly158 * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because159 * the class has not been fully constructed yet. "This" itself seems to be working fine.160 */161 ObservedValues(MAX_ObservedTypes),162 subjectKilledCount(0),163 TesselationHullUpdater(164 boost::bind(&GLMoleculeObject_molecule::updateTesselationHull, this)165 ),166 TesselationHull(167 molref,168 TesselationHullUpdater,169 "MoleculeTesselationHull_"+toString(_molid),170 HullChannels),171 hoverAtomId(-1)172 {173 boost::function<void(const moleculeId_t)> subjectKilled =174 boost::bind(&GLMoleculeObject_molecule::countsubjectKilled, this, _molid);175 initObservedValues(ObservedValues, _molid, molref, subjectKilled);176 177 setObjectId(_molid);178 setMaterial(getMaterial(1));179 180 m_selected = const_cast<const World &>(World::getInstance()).isMoleculeSelected(_molid);181 182 // initially, atoms and bonds should be visible183 m_visible = false;184 185 connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));186 connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));187 connect (this, SIGNAL(TesselationHullChanged()), this, SLOT(resetTesselationHull()), Qt::QueuedConnection);188 connect (this, SIGNAL(BoundingBoxChanged()), this, SLOT(resetBoundingBox()), Qt::QueuedConnection);189 connect (this, SIGNAL(IdChanged()), this, SLOT(resetIndex()), Qt::QueuedConnection);190 connect (this, SIGNAL(AtomInserted(const atomId_t)), this, SLOT(atomInserted(const atomId_t)), Qt::QueuedConnection);191 connect (this, SIGNAL(AtomInserted(const atomId_t)), this, SLOT(resetAtoms()), Qt::QueuedConnection);192 connect (this, SIGNAL(AtomRemoved(const atomId_t)), this, SLOT(resetAtoms()), Qt::QueuedConnection);193 connect (this, SIGNAL(AtomRemoved(const atomId_t)), this, SLOT(atomRemoved(const atomId_t)), Qt::QueuedConnection);194 195 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));196 }197 198 192 GLMoleculeObject_molecule::~GLMoleculeObject_molecule() 199 193 { 200 194 deactivateObserver(); 201 destroyObservedValues(ObservedValues);195 board->returnMoleculeObservedValues(getMolIndex(), ObservedValues); 202 196 } 203 197 … … 205 199 { 206 200 if (owner != NULL) { 207 owner->signOff(this, molecule::AtomInserted);208 owner->signOff(this, molecule::AtomRemoved);209 owner->signOff(this, molecule::AtomMoved);210 owner->signOff(this, molecule::IndexChanged);201 Observable::channels_t channels = getAllAtomicObservedChannels(); 202 for (Observable::channels_t::const_iterator iter = channels.begin(); 203 iter != channels.end(); ++iter) 204 owner->signOff(this, *iter); 211 205 owner = NULL; 206 signedOnChannels = 0; 212 207 } 213 208 } … … 218 213 const molecule * const _molecule = getMolecule(getMolIndex()); 219 214 if (_molecule != NULL) { 215 Observable::channels_t channels = getAllAtomicObservedChannels(); 220 216 owner = static_cast<const Observable *>(_molecule); 221 owner->signOn(this, molecule::AtomInserted); 222 owner->signOn(this, molecule::AtomRemoved); 223 owner->signOn(this, molecule::AtomMoved); 224 owner->signOn(this, molecule::IndexChanged); 217 for (Observable::channels_t::const_iterator iter = channels.begin(); 218 iter != channels.end(); ++iter) 219 owner->signOn(this, *iter); 225 220 } else { 226 221 ELOG(1, "GLMoleculeObject_molecule() - added null object for not present mol id " << getMolIndex()); … … 244 239 BondsinSceneMap[ids]->resetWidth(); 245 240 } 246 }247 248 void GLMoleculeObject_molecule::addAtomBonds(249 const atomId_t _id)250 {251 const atom * const Walker = const_cast<const World &>(World::getInstance()).252 getAtom(AtomById(_id));253 if (Walker != NULL) {254 const bool atom_present = AtomsinSceneMap.count(_id);255 const BondList &bondlist = Walker->getListOfBonds();256 for (BondList::const_iterator bonditer = bondlist.begin();257 (bonditer != bondlist.end()) && atom_present;258 ++bonditer) {259 const bond::ptr _bond = *bonditer;260 // check if OtherAtom's sphere is already present261 const atom *OtherAtom = _bond->GetOtherAtom(Walker);262 const bool otheratom_present = AtomsinSceneMap.count(OtherAtom->getId());263 if (otheratom_present && atom_present) {264 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == Walker) ?265 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;266 const GLMoleculeObject_bond::SideOfBond otherside = (_bond->leftatom == Walker) ?267 GLMoleculeObject_bond::right : GLMoleculeObject_bond::left;268 addAtomBonds(_bond, side);269 addAtomBonds(_bond, otherside);270 }271 }272 } else273 ELOG(1, "GLMoleculeObject_atom disappeared while about to add bonds.");274 241 } 275 242 … … 389 356 } 390 357 391 void GLMoleculeObject_molecule::resetAtoms()392 {393 const atoms_t atoms = getPresentAtoms();394 std::vector<atomId_t> InsertedAtoms;395 std::vector<atomId_t> RemovedAtoms;396 // obtain all newly inserted and removed atoms397 std::set_difference(398 atoms.begin(), atoms.end(),399 DisplayedAtoms.begin(), DisplayedAtoms.end(),400 std::back_inserter(InsertedAtoms));401 std::set_difference(402 DisplayedAtoms.begin(), DisplayedAtoms.end(),403 atoms.begin(), atoms.end(),404 std::back_inserter(RemovedAtoms));405 // remove the atoms406 std::for_each(RemovedAtoms.begin(), RemovedAtoms.end(),407 boost::bind(&GLMoleculeObject_molecule::atomRemoved, this, _1));408 // insert the atoms409 std::for_each(InsertedAtoms.begin(), InsertedAtoms.end(),410 boost::bind(&GLMoleculeObject_molecule::atomInserted, this, _1));411 DisplayedAtoms = atoms;412 413 emit changed();414 }415 416 358 void GLMoleculeObject_molecule::resetIndex() 417 359 { … … 479 421 void GLMoleculeObject_molecule::subjectKilled(Observable *publisher) 480 422 { 481 // remove owner: no more signOff needed 482 owner = NULL; 483 484 countsubjectKilled(getMolIndex()); 423 ++signedOnChannels; 424 425 if (signedOnChannels == AllsignedOnChannels) { 426 // remove owner: no more signOff needed 427 owner = NULL; 428 429 board->moleculecountsubjectKilled(getMolIndex()); 430 } 485 431 } 486 432 … … 492 438 return; 493 439 if (publisher == dynamic_cast<const Observable*>(_molecule)){ 494 // not ofication from atom440 // notification from atom 495 441 #ifdef LOG_OBSERVER 496 442 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this)) … … 500 446 switch (notification->getChannelNo()) { 501 447 case molecule::AtomInserted: 502 { 503 const atomId_t _id = _molecule->lastChangedAtomId(); 504 #ifdef LOG_OBSERVER 505 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted."; 506 #endif 507 emit AtomInserted(_id); 508 emit TesselationHullChanged(); 509 emit BoundingBoxChanged(); 510 break; 511 } 512 case World::AtomRemoved: 513 { 514 // const atomId_t _id = _molecule->lastChangedAtomId(); 515 #ifdef LOG_OBSERVER 516 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been removed."; 517 #endif 518 emit TesselationHullChanged(); 519 emit BoundingBoxChanged(); 520 break; 521 } 448 case molecule::AtomRemoved: 522 449 case molecule::AtomMoved: 523 450 { 524 451 #ifdef LOG_OBSERVER 525 const atomId_t _id = _molecule->lastChangedAtomId();526 452 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted."; 527 453 #endif … … 638 564 LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomInserted for atom "+toString(_id)+"."); 639 565 640 GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(GLMoleculeObject::meshSphere, this, _id); 566 GLMoleculeObject_atom *atomObject = 567 new GLMoleculeObject_atom( 568 GLMoleculeObject::meshSphere, 569 this, 570 _id, 571 board, 572 board->getAtomObservedValues(_id)); 641 573 ASSERT( atomObject != NULL, 642 574 "GLMoleculeObject_molecule::atomInserted - could not create atom object for "+toString(_id)); … … 657 589 connect (atomObject, SIGNAL(BondsRemoved(const atomId_t, const atomId_t)), this, SLOT(bondRemoved(const atomId_t, const atomId_t))); 658 590 connect (atomObject, SIGNAL(indexChanged(GLMoleculeObject_atom*, const atomId_t, const atomId_t)), this, SLOT(changeAtomId(GLMoleculeObject_atom*, const atomId_t, const atomId_t))); 659 connect (atomObject, SIGNAL(InstanceRemoved(const atomId_t)), this, SIGNAL(AtomRemoved(const atomId_t)));660 591 661 592 if (m_objectId == -1) 662 593 setObjectId(_id); 663 594 664 // add all bonds 665 addAtomBonds(_id); 666 595 emit changed(); 667 596 emit changeOccured(); 668 597 } … … 691 620 delete atomObject; 692 621 622 emit changed(); 693 623 emit changeOccured(); 694 624 } … … 766 696 iter->second->resetWidth(); 767 697 } 698 emit changed(); 768 699 emit changeOccured(); 769 700 } … … 790 721 } 791 722 723 emit changed(); 792 724 emit changeOccured(); 793 725 } … … 800 732 // then emit onward 801 733 GLMoleculeObject::setVisible(value); 734 735 emit changed(); 736 emit changeOccured(); 802 737 } 803 738 … … 844 779 getMolecule(MoleculeById(_id)); 845 780 return mol; 846 }847 848 void GLMoleculeObject_molecule::countsubjectKilled(const moleculeId_t)849 {850 ++subjectKilledCount;851 852 if (subjectKilledCount > ObservedValues.size())853 emit InstanceRemoved(getMolIndex());854 781 } 855 782 … … 911 838 _subjectKilled, 912 839 MolIndexGetter); 913 _ObservedValues[PresentAtoms] = new ObservedValue_UpdateAtoms(914 _molref,915 "MoleculeAtoms_"+toString(_molid),916 AtomsChannels,917 _subjectKilled,918 MolIndexGetter);919 840 } 920 841 … … 925 846 delete boost::any_cast<ObservedValue_wCallback<std::string, moleculeId_t> *>(_ObservedValues[MolName]); 926 847 delete boost::any_cast<ObservedValue_wCallback<molecule::BoundingBoxInfo, moleculeId_t> *>(_ObservedValues[BoundingBox]); 927 delete boost::any_cast<ObservedValue_UpdateAtoms *>(_ObservedValues[PresentAtoms]);928 848 _ObservedValues.clear(); 929 849 } … … 946 866 GLMoleculeObject_molecule::atoms_t GLMoleculeObject_molecule::getPresentAtoms() const 947 867 { 948 return boost::any_cast<ObservedValue_UpdateAtoms *>(ObservedValues[PresentAtoms])->get(); 949 } 868 atoms_t returnAtomIds; 869 returnAtomIds.insert( 870 MapKeyConstIterator<AtomNodeMap::const_iterator>(const_cast<const AtomNodeMap &>(AtomsinSceneMap).begin()), 871 MapKeyConstIterator<AtomNodeMap::const_iterator>(const_cast<const AtomNodeMap &>(AtomsinSceneMap).end())); 872 return returnAtomIds; 873 }
Note:
See TracChangeset
for help on using the changeset viewer.