Changeset 8d5fbf1 for src/UIElements/Views/Qt4/Qt3D
- 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)
- Location:
- src/UIElements/Views/Qt4/Qt3D
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp
r47f0e4 r8d5fbf1 53 53 #include "Element/periodentafel.hpp" 54 54 #include "LinearAlgebra/Vector.hpp" 55 #include "GLMoleculeObject_bond.hpp" 55 #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp" 56 #include "UIElements/Views/Qt4/QtInstanceInformationBoard.hpp" 56 57 #include "World.hpp" 57 58 #include "WorldTime.hpp" … … 65 66 Observable::channels_t channels; 66 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; 67 80 return channels; 68 81 } … … 81 94 QGLSceneNode *mesh[], 82 95 QObject *parent, 83 const atomId_t _id) :84 GLMoleculeObject(mesh, parent),85 Observer(std::string("GLMoleculeObject_atom")+toString(_id)),86 atomref(getAtom(_id)),87 ObservedValues(MAX_ObservedTypes),88 subjectKilledCount(0),89 owner(NULL)90 {91 boost::function<void(const atomId_t)> subjectKilled =92 boost::bind(&GLMoleculeObject_atom::countsubjectKilled, this, _id);93 initObservedValues(ObservedValues, _id, atomref, subjectKilled);94 95 init(_id);96 }97 98 GLMoleculeObject_atom::GLMoleculeObject_atom(99 QGLSceneNode *mesh[],100 QObject *parent,101 96 const atomId_t _id, 97 QtInstanceInformationBoard * _board, 102 98 std::vector<boost::any> _ObservedValues) : 103 99 GLMoleculeObject(mesh, parent), … … 106 102 ObservedValues(_ObservedValues), 107 103 subjectKilledCount(0), 108 owner(NULL) 104 owner(NULL), 105 AllsignedOnChannels(getAllObservedChannels().size()), 106 signedOnChannels(0), 107 board(_board) 109 108 { 110 109 init(_id); … … 130 129 connect( this, SIGNAL(positionChanged()), this, SLOT(resetPosition()), Qt::QueuedConnection); 131 130 connect( this, SIGNAL(bondsChanged()), this, SLOT(resetPosition()), Qt::QueuedConnection); 131 132 // use that ObservedValues::AtomBonds is always up-to-date 133 resetBonds(); 132 134 } 133 135 … … 135 137 { 136 138 if (atomref != NULL) { 139 Observable::channels_t channels = getAllObservedChannels(); 137 140 owner = static_cast<const Observable *>(atomref); 138 owner->signOn(this, AtomObservable::IndexChanged); 139 owner->signOn(this, AtomObservable::PositionChanged); 140 owner->signOn(this, AtomObservable::ElementChanged); 141 owner->signOn(this, AtomObservable::BondsAdded); 142 owner->signOn(this, AtomObservable::BondsRemoved); 141 for (Observable::channels_t::const_iterator iter = channels.begin(); 142 iter != channels.end(); ++iter) 143 owner->signOn(this, *iter); 143 144 } 144 145 } … … 149 150 // sign Off 150 151 if (owner != NULL) { 151 owner->signOff(this, AtomObservable::IndexChanged); 152 owner->signOff(this, AtomObservable::PositionChanged); 153 owner->signOff(this, AtomObservable::ElementChanged); 154 owner->signOff(this, AtomObservable::BondsAdded); 155 owner->signOff(this, AtomObservable::BondsRemoved); 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 156 owner = NULL; 157 signedOnChannels = 0; 157 158 } 158 159 } … … 161 162 { 162 163 deactivateObserver(); 163 destroyObservedValues(ObservedValues);164 board->returnAtomObservedValues(getAtomIndex(), ObservedValues); 164 165 } 165 166 … … 338 339 void GLMoleculeObject_atom::subjectKilled(Observable *publisher) 339 340 { 340 deactivateObserver(); 341 342 countsubjectKilled(getAtomIndex()); 341 ++signedOnChannels; 342 343 if (signedOnChannels == AllsignedOnChannels) { 344 // remove owner: no more signOff needed 345 owner = NULL; 346 347 board->atomcountsubjectKilled(getAtomIndex()); 348 } 343 349 } 344 350 … … 371 377 } 372 378 373 void GLMoleculeObject_atom::countsubjectKilled(const atomId_t)374 {375 ++subjectKilledCount;376 377 if (subjectKilledCount > ObservedValues.size())378 emit InstanceRemoved(getAtomIndex());379 }380 381 379 void GLMoleculeObject_atom::initObservedValues( 382 380 std::vector<boost::any> &_ObservedValues, -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp
r47f0e4 r8d5fbf1 38 38 QGLSceneNode *mesh[], 39 39 QObject *parent, 40 const atomId_t id41 );42 GLMoleculeObject_atom(43 QGLSceneNode *mesh[],44 QObject *parent,45 40 const atomId_t id, 41 QtInstanceInformationBoard * _board, 46 42 std::vector<boost::any> _ObservedValues 47 43 ); … … 75 71 void elementChanged(); 76 72 void bondsChanged(); 77 void InstanceRemoved(const atomId_t);78 73 79 74 private: … … 173 168 ListOfBonds_t getAtomBonds() const; 174 169 175 /** Counts how many ObservedValues got subjectKilled.176 *177 * This is used to give InstanceRemoved() signal only when each and every178 * ObservedValue (and the instance itself) has been subjectKilled by the179 * monitored Observable. Only then can we safely remove the instance.180 *181 * \param _atomid id of atom who signalled subjectKilled()182 */183 void countsubjectKilled(const atomId_t _atomid);184 185 170 //!> counts how many ObservedValues have already been subjectKilled() 186 171 mutable size_t subjectKilledCount; … … 199 184 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL) 200 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 QtInstanceInformationBoard * board; 201 192 }; 202 193 -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp
r47f0e4 r8d5fbf1 55 55 #include "LinearAlgebra/Line.hpp" 56 56 #include "LinearAlgebra/Vector.hpp" 57 #include "UIElements/Views/Qt4/QtInstanceInformationBoard.hpp" 57 58 #include "World.hpp" 58 59 … … 69 70 const Observable::channels_t 70 71 GLMoleculeObject_bond::BondElementChannels(1, AtomObservable::ElementChanged); 72 73 static GLMoleculeObject_bond::bondIds_t getBondIdsForIds( 74 const boost::function<const atomId_t()> &_left, 75 const boost::function<const atomId_t()> &_right) 76 { 77 return std::make_pair(_left(), _right()); 78 } 71 79 72 80 GLMoleculeObject_bond::GLMoleculeObject_bond( … … 87 95 subjectKilledCount(0), 88 96 leftobservable_enabled(false), 89 rightobservable_enabled(false) 97 rightobservable_enabled(false), 98 board_subjectKilled( 99 boost::bind( 100 static_cast<void (GLMoleculeObject_bond::*) ()>( 101 &GLMoleculeObject_bond::countsubjectKilled), 102 this)) 90 103 { 91 104 boost::function<void(const atomId_t &)> leftsubjectKilled = … … 123 136 const bondIds_t bondIds, 124 137 const enum SideOfBond side, 125 std::vector<boost::any> &_ObservedValues) : 138 std::vector<boost::any> &_ObservedValues, 139 const boost::function<void (const bondIds_t)> &_subjectKilled) : 126 140 GLMoleculeObject(mesh, parent), 127 141 Observer(std::string("GLMoleculeObject_bond") … … 136 150 subjectKilledCount(0), 137 151 leftobservable_enabled(false), 138 rightobservable_enabled(false) 152 rightobservable_enabled(false), 153 board_subjectKilled(_subjectKilled) 139 154 { 140 155 init(); … … 209 224 removeChannels(); 210 225 // check whether we should be removed 211 countsubjectKilled(std::make_pair(getleftIndex(), getrightIndex()));226 board_subjectKilled(std::make_pair(getleftIndex(), getrightIndex())); 212 227 } 213 228 … … 389 404 } 390 405 391 static GLMoleculeObject_bond::bondIds_t getBondIdsForIds(392 const boost::function<const atomId_t ()> _left,393 const boost::function<const atomId_t ()> _right)394 {395 return std::make_pair( _left(), _right());396 }397 398 406 void GLMoleculeObject_bond::initObservedValues( 399 407 std::vector<boost::any> &_ObservedValues, -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp
r47f0e4 r8d5fbf1 18 18 #include <vector> 19 19 #include <boost/any.hpp> 20 #include <boost/function.hpp> 20 21 21 22 #include "CodePatterns/Observer/Observer.hpp" … … 49 50 const bondIds_t bondIds, 50 51 const enum SideOfBond side, 51 std::vector<boost::any> &_ObservedValues); 52 std::vector<boost::any> &_ObservedValues, 53 const boost::function<void (const bondIds_t)> &_subjectKilled); 52 54 virtual ~GLMoleculeObject_bond(); 53 55 … … 255 257 //!> list of channels when element needs to update 256 258 static const Observable::channels_t BondElementChannels; 259 260 //!> callback function to inform about subjectKilled() 261 const boost::function<void (const bondIds_t)> board_subjectKilled; 257 262 }; 258 263 -
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 } -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp
r47f0e4 r8d5fbf1 42 42 GLMoleculeObject_molecule( 43 43 QObject *parent, 44 const moleculeId_t molid); 44 const moleculeId_t molid, 45 QtInstanceInformationBoard * _board, 46 std::vector<boost::any> _ObservedValues); 45 47 GLMoleculeObject_molecule( 46 48 QGLSceneNode *mesh[], 47 49 QObject *parent, 48 const moleculeId_t molid); 50 const moleculeId_t molid, 51 QtInstanceInformationBoard * _board, 52 std::vector<boost::any> _ObservedValues); 49 53 virtual ~GLMoleculeObject_molecule(); 50 54 … … 78 82 void AtomRemoved(const atomId_t _id); 79 83 void IdChanged(); 80 void InstanceRemoved(const moleculeId_t);81 84 82 85 private slots: … … 99 102 void resetTesselationHull(); 100 103 void resetBoundingBox(); 101 void resetAtoms();102 104 void resetIndex(); 103 105 void resetName(); … … 111 113 static const molecule * const getMolecule(const moleculeId_t _id); 112 114 115 void init(const moleculeId_t _molid); 116 113 117 private: 114 118 void addAtomBonds( … … 116 120 const GLMoleculeObject_bond::SideOfBond _side 117 121 ); 118 void addAtomBonds(const atomId_t _id);119 122 120 123 //!> typedef for the internal set of atoms … … 130 133 const boost::function<const moleculeId_t ()> &_getMolIndex); 131 134 135 /** Getter to contained atoms contained in \a ObservedValues. 136 * 137 * \return molecule's contained atoms 138 */ 139 atoms_t getPresentAtoms() const; 140 132 141 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL) 133 142 const Observable * owner; … … 136 145 const molecule * const molref; 137 146 138 //!> list of channels when contained atoms needs to update139 static const Observable::channels_t AtomsChannels;140 147 //!> list of channels when tesselation hull needs to update 141 148 static const Observable::channels_t HullChannels; … … 159 166 //!> contains newest version of the bounding box on request 160 167 BoundingBox, 161 //!> contains the current live set of atoms for the molecule162 PresentAtoms,163 168 //!> gives the size of the enumeration 164 169 MAX_ObservedTypes … … 206 211 molecule::BoundingBoxInfo getBoundingBox() const; 207 212 208 /** Getter to contained atoms contained in \a ObservedValues.209 *210 * \return molecule's contained atoms211 */212 atoms_t getPresentAtoms() const;213 214 /** Counts how many ObservedValues got subjectKilled.215 *216 * This is used to give InstanceRemoved() signal only when each and every217 * ObservedValue (and the instance itself) has been subjectKilled by the218 * monitored Observable. Only then can we safely remove the instance.219 *220 * \param _molid molecule id who signalled subjectKilled()221 */222 void countsubjectKilled(const moleculeId_t _molid);223 224 213 //!> counts how many ObservedValues have already been subjectKilled() 225 214 mutable size_t subjectKilledCount; … … 241 230 242 231 atomId_t hoverAtomId; 232 233 //!> we get multiple subjectKilled(), count and call callback() only on last 234 const unsigned int AllsignedOnChannels; 235 unsigned int signedOnChannels; 236 237 QtInstanceInformationBoard * board; 243 238 }; 244 239 -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp
r47f0e4 r8d5fbf1 94 94 GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true); 95 95 } 96 connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)),97 this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)));98 96 connect(board, SIGNAL(moleculeInserted(const moleculeId_t)), 99 97 this, SLOT(moleculeInserted(const moleculeId_t))); … … 102 100 connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)), 103 101 this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t))); 102 connect(board, SIGNAL(atomInserted(const moleculeId_t, const atomId_t)), 103 this, SLOT(atomInserted(const moleculeId_t, const atomId_t)), Qt::DirectConnection); 104 connect(board, SIGNAL(atomRemoved(const moleculeId_t, const atomId_t)), 105 this, SLOT(atomRemoved(const moleculeId_t, const atomId_t)), Qt::DirectConnection); 104 106 105 107 // connect(this, SIGNAL(updated()), this, SLOT(update())); … … 199 201 200 202 // check of molecule is already present 201 if (MoleculesinSceneMap.count(_molid) != 0) { 203 MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid); 204 if (moliter != MoleculesinSceneMap.end()) { 202 205 // pass signal through 206 GLMoleculeObject_molecule *molObject = moliter->second; 207 QMetaObject::invokeMethod(molObject, // pointer to a QObject 208 "atomInserted", // member name (no parameters here) 209 Qt::QueuedConnection, // connection type 210 Q_ARG(const atomId_t, _atomid)); // parameters 203 211 } else { 204 212 // store signal for when it is instantiated … … 221 229 222 230 // check of molecule is already present 223 if (MoleculesinSceneMap.count(_molid) != 0) { 231 MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(_molid); 232 if (moliter != MoleculesinSceneMap.end()) { 224 233 // pass signal through 234 GLMoleculeObject_molecule *molObject = moliter->second; 235 QMetaObject::invokeMethod(molObject, // pointer to a QObject 236 "atomRemoved", // member name (no parameters here) 237 Qt::QueuedConnection, // connection type 238 Q_ARG(const atomId_t, _atomid)); // parameters 225 239 } else { 226 240 // store signal for when it is instantiated … … 259 273 GLMoleculeObject_molecule *molObject = 260 274 new GLMoleculeObject_molecule( 261 GLMoleculeObject::meshEmpty, this, _id); 275 GLMoleculeObject::meshEmpty, 276 this, 277 _id, 278 board, 279 board->getMoleculeObservedValues(_id)); 262 280 ASSERT( molObject != NULL, 263 281 "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(_id)); … … 290 308 QMetaObject::invokeMethod(molObject, // pointer to a QObject 291 309 "atomInserted", // member name (no parameters here) 292 Qt:: DirectConnection, // connection type310 Qt::QueuedConnection, // connection type 293 311 Q_ARG(const atomId_t, iter->first)); // parameters 294 312 } else { … … 307 325 QMetaObject::invokeMethod(molObject, // pointer to a QObject 308 326 "atomInserted", // member name (no parameters here) 309 Qt:: DirectConnection, // connection type327 Qt::QueuedConnection, // connection type 310 328 Q_ARG(const atomId_t, iter->first)); // parameters 311 329 break; … … 323 341 } 324 342 325 // now let the molObject sign on to molecule326 molObject->activateObserver();327 328 343 connect (molObject, SIGNAL(changed()), this, SIGNAL(changed())); 329 344 connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured())); … … 335 350 connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int))); 336 351 connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int))); 352 connect(board, SIGNAL(atomInserted(const atomId_t)), 353 molObject, SLOT(atomInserted(const atomId_t))); 354 connect(board, SIGNAL(atomRemoved(const atomId_t)), 355 molObject, SLOT(atomRemoved(const atomId_t))); 337 356 338 357 emit changed();
Note:
See TracChangeset
for help on using the changeset viewer.