Changeset f1b5ca for src/UIElements
- Timestamp:
- Apr 20, 2016, 11:07:46 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:
- 7f185f9
- Parents:
- 785d89
- git-author:
- Frederik Heber <heber@…> (04/12/16 08:51:06)
- git-committer:
- Frederik Heber <heber@…> (04/20/16 23:07:46)
- Location:
- src/UIElements/Views/Qt4/Qt3D
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp
r785d89 rf1b5ca 43 43 44 44 #include "CodePatterns/MemDebug.hpp" 45 46 #include <boost/assign.hpp>47 45 48 46 #include "CodePatterns/Assert.hpp" … … 61 59 #include "World.hpp" 62 60 63 using namespace boost::assign;64 65 static Observable::channels_t getAllAtomicChangesChannels()66 {67 Observable::channels_t channels;68 channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;69 return channels;70 }71 72 const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels());73 74 61 static QGLSceneNode *createMoleculeMesh(const QGeometryData &_geo) 75 62 { … … 83 70 GLMoleculeObject_molecule::GLMoleculeObject_molecule( 84 71 QObject *parent, 85 QtObservedInstanceBoard &_board,86 72 QtObservedMolecule::ptr &_ObservedMolecule) : 87 73 GLMoleculeObject((QGLSceneNode *)NULL, parent), 88 owner(NULL),89 74 hoverAtomId(-1), 90 board(_board),91 75 ObservedMolecule(_ObservedMolecule) 92 76 { … … 97 81 QGLSceneNode *mesh[], 98 82 QObject *parent, 99 QtObservedInstanceBoard &_board,100 83 QtObservedMolecule::ptr &_ObservedMolecule) : 101 84 GLMoleculeObject(mesh, parent), 102 owner(NULL),103 85 hoverAtomId(-1), 104 board(_board),105 86 ObservedMolecule(_ObservedMolecule) 106 87 { … … 118 99 m_visible = false; 119 100 120 connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));121 connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));122 101 connect (ObservedMolecule.get(), SIGNAL(tesselationhullChanged()), this, SLOT(resetTesselationHull())); 123 102 connect (ObservedMolecule.get(), SIGNAL(boundingboxChanged()), this, SLOT(resetBoundingBox())); … … 130 109 // this, SLOT(atomRemoved(const atomId_t)) ); 131 110 connect (ObservedMolecule.get(), SIGNAL(selectedChanged()), this, SLOT(resetSelected())); 132 133 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));134 111 } 135 112 … … 152 129 // check minimum bond radius in molecule 153 130 double minlength = std::numeric_limits<double>::max(); 131 size_t NoAtoms = 0; 154 132 for (molecule::const_iterator iter = molref->begin(); 155 133 iter != molref->end(); ++iter) { … … 160 138 minlength = std::min(bond_distance, minlength); 161 139 } 140 ++NoAtoms; 162 141 } 163 142 minradius = std::max( std::max(minradius, minlength), 1.); 164 143 165 144 // we need at least three points for tesselation 166 if ( AtomsinSceneMap.size()>= 3) {145 if (NoAtoms >= 3) { 167 146 // Tesselate the points. 168 147 Tesselation T; … … 218 197 void GLMoleculeObject_molecule::resetTesselationHull() 219 198 { 220 if (owner != NULL) { 221 TesselationHull = updateTesselationHull(); 222 updateMesh(createMoleculeMesh(TesselationHull)); 223 } 199 TesselationHull = updateTesselationHull(); 200 updateMesh(createMoleculeMesh(TesselationHull)); 224 201 } 225 202 … … 334 311 } 335 312 336 /** Adds an atom of this molecule to the scene.337 *338 * @param _atom atom to add339 */340 void GLMoleculeObject_molecule::atomInserted(QtObservedAtom::ptr _atom)341 {342 const ObservedValue_Index_t atomid = _atom->getIndex();343 LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomInserted for atom "344 << _atom->getAtomIndex());345 346 if (_atom) {347 GLMoleculeObject_atom *atomObject =348 new GLMoleculeObject_atom(349 GLMoleculeObject::meshSphere,350 this,351 _atom);352 ASSERT( atomObject != NULL,353 "GLMoleculeObject_molecule::atomInserted - could not create atom object for "354 +toString(_atom->getAtomIndex()));355 AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid);356 ASSERT(iter == AtomsinSceneMap.end(),357 "GLMoleculeObject_molecule::atomInserted - same atom with id "358 +toString(_atom->getAtomIndex())+" added again.");359 AtomsinSceneMap.insert( make_pair(atomid, atomObject) );360 361 qRegisterMetaType<atomId_t>("atomId_t");362 qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");363 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SIGNAL(atomClicked(atomId_t)));364 connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));365 connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));366 connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));367 368 if (m_objectId == -1)369 setObjectId(_atom->getAtomIndex());370 371 emit changed();372 emit changeOccured();373 }374 }375 376 /** Removes an atom of this molecule from the scene.377 *378 * We just the id as the atom might have already been destroyed.379 *380 * @param _id id of atom to remove381 */382 void GLMoleculeObject_molecule::atomRemoved(ObservedValue_Index_t _id)383 {384 LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomRemoved for atom "+toString(_id)+".");385 // bonds are removed by signal coming from ~bond386 387 // remove atoms388 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);389 ASSERT(iter != AtomsinSceneMap.end(),390 "GLMoleculeObject_molecule::atomRemoved() - atom "+toString(_id)+" not on display.");391 GLMoleculeObject_atom *atomObject = iter->second;392 AtomsinSceneMap.erase(iter);393 atomObject->disconnect();394 delete atomObject;395 396 emit changed();397 emit changeOccured();398 399 if (AtomsinSceneMap.empty())400 emit moleculeEmptied(ObservedMolecule);401 }402 403 void GLMoleculeObject_molecule::hoverChangedSignalled(GLMoleculeObject *ob)404 {405 // Find the atom, ob corresponds to.406 hoverAtomId = -1;407 GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);408 if (atomObject){409 for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){410 if (iter->second == atomObject)411 hoverAtomId = iter->second->objectId();412 }413 414 // Propagate signal.415 emit hoverChanged(hoverAtomId);416 } else {417 // Find the atom, ob corresponds to.418 GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob);419 if (moleculeObject == this){420 // Propagate signal.421 emit hoverChanged(ObservedMolecule->getMolIndex(), 0);422 }423 }424 }425 426 /** Adds a bond to the scene.427 *428 * @param _bond bond to add429 */430 void GLMoleculeObject_molecule::bondInserted(431 QtObservedBond::ptr _bond)432 {433 static const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides =434 boost::assign::list_of<GLMoleculeObject_bond::SideOfBond>435 (GLMoleculeObject_bond::left)436 (GLMoleculeObject_bond::right);437 LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bonds " << _bond->getBondIndex());438 //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");439 440 const ObservedValue_Index_t bondid = _bond->getIndex();441 const std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =442 BondsinSceneMap.equal_range(bondid);443 if (iters.first == iters.second) {444 for (size_t i=0;i<2;++i) {445 GLMoleculeObject_bond * bondObject =446 new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, _bond, bondsides[i]);447 connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));448 BondsinSceneMap.insert( std::make_pair(bondid, bondObject) );449 }450 } else {451 for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {452 iter->second->resetPosition();453 iter->second->resetWidth();454 }455 }456 emit changed();457 emit changeOccured();458 }459 460 /** Removes a bond from the scene.461 *462 * @param _bond bond to remove463 */464 void GLMoleculeObject_molecule::bondRemoved(ObservedValue_Index_t _id)465 {466 LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond to id " << _id);467 {468 // left bond469 const std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =470 BondsinSceneMap.equal_range(_id);471 for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {472 GLMoleculeObject_bond *bondObject = iter->second;473 bondObject->disconnect();474 delete bondObject; // is done by signal from bond itself475 //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");476 }477 BondsinSceneMap.erase(_id);478 }479 480 emit changed();481 emit changeOccured();482 }483 484 313 void GLMoleculeObject_molecule::setVisible(bool value) 485 314 { … … 499 328 return ost; 500 329 } 501 502 void GLMoleculeObject_molecule::wasClicked()503 {504 LOG(4, "INFO: GLMoleculeObject_molecule: atom "505 << ObservedMolecule->getMolIndex() << " has been clicked");506 emit moleculeClicked(ObservedMolecule->getMolIndex());507 } -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp
r785d89 rf1b5ca 41 41 GLMoleculeObject_molecule( 42 42 QObject *parent, 43 QtObservedInstanceBoard &_board,44 43 QtObservedMolecule::ptr &_ObservedMolecule); 45 44 GLMoleculeObject_molecule( 46 45 QGLSceneNode *mesh[], 47 46 QObject *parent, 48 QtObservedInstanceBoard &_board,49 47 QtObservedMolecule::ptr &_ObservedMolecule); 50 48 virtual ~GLMoleculeObject_molecule(); … … 59 57 void changed(); 60 58 void changeOccured(); 61 void hoverChanged(const atomId_t);62 void hoverChanged(const moleculeId_t, int);63 void atomClicked(atomId_t);64 void moleculeClicked(moleculeId_t);65 void moleculeEmptied(QtObservedMolecule::ptr);66 void IsSelectedChanged();67 59 68 60 private slots: 69 61 //!> grant GLWorldScene access to private slots 70 62 friend class GLWorldScene; 71 72 void wasClicked();73 void atomInserted(QtObservedAtom::ptr _atom);74 void atomRemoved(ObservedValue_Index_t _id);75 void bondInserted(QtObservedBond::ptr _bond);76 void bondRemoved(ObservedValue_Index_t _id);77 void hoverChangedSignalled(GLMoleculeObject *ob);78 63 79 64 void setVisible(bool value); … … 90 75 private: 91 76 92 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)93 const Observable * owner;94 95 77 QGeometryData updateTesselationHull() const; 96 97 //!> list of channels when tesselation hull needs to update98 static const Observable::channels_t HullChannels;99 78 100 79 //!> contains current version of the tesselation hull on request 101 80 QGeometryData TesselationHull; 102 81 103 typedef std::map< ObservedValue_Index_t, GLMoleculeObject_atom* > AtomNodeMap;104 typedef std::multimap< ObservedValue_Index_t, GLMoleculeObject_bond* > BondNodeMap;105 AtomNodeMap AtomsinSceneMap;106 BondNodeMap BondsinSceneMap;107 82 108 83 atomId_t hoverAtomId; 109 110 QtObservedInstanceBoard &board;111 84 112 85 QtObservedMolecule::ptr ObservedMolecule; -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp
r785d89 rf1b5ca 54 54 55 55 #include "CodePatterns/Log.hpp" 56 57 #include <boost/assign.hpp> 56 58 57 59 #include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp" … … 79 81 board(_board) 80 82 { 83 qRegisterMetaType<atomId_t>("atomId_t"); 84 qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond"); 85 81 86 int sphereDetails[] = {5, 3, 2, 0}; 82 87 int cylinderDetails[] = {16, 8, 6, 3}; … … 94 99 } 95 100 connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)), 96 this, SLOT(molecule SignOn(QtObservedMolecule::ptr)), Qt::DirectConnection);101 this, SLOT(moleculeInserted(QtObservedMolecule::ptr))); 97 102 connect(board, SIGNAL(moleculeRemoved(ObservedValue_Index_t)), 98 this, SLOT(molecule SignOff(ObservedValue_Index_t)), Qt::DirectConnection);103 this, SLOT(moleculeRemoved(ObservedValue_Index_t))); 99 104 connect(board, SIGNAL(atomInserted(QtObservedAtom::ptr)), 100 105 this, SLOT(atomInserted(QtObservedAtom::ptr))); … … 105 110 connect(board, SIGNAL(bondRemoved(ObservedValue_Index_t)), 106 111 this, SLOT(bondRemoved(ObservedValue_Index_t))); 107 connect(this, SIGNAL(insertMolecule(QtObservedMolecule::ptr)),108 this, SLOT(moleculeInserted(QtObservedMolecule::ptr)) );109 connect(this, SIGNAL(removeMolecule(QtObservedMolecule*)),110 this, SLOT(moleculeRemoved(QtObservedMolecule*)) );111 112 112 113 // connect(this, SIGNAL(updated()), this, SLOT(update())); … … 143 144 } 144 145 146 /** Adds an atom to the scene. 147 * 148 * @param _atom atom to add 149 */ 150 void GLWorldScene::atomInserted(QtObservedAtom::ptr _atom) 151 { 152 LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom " 153 << _atom->getAtomIndex()); 154 155 GLMoleculeObject_atom *atomObject = 156 new GLMoleculeObject_atom( 157 GLMoleculeObject::meshSphere, 158 this, /* parent is GLWorldScene */ 159 _atom); 160 ASSERT( atomObject != NULL, 161 "GLWorldScene::atomInserted - could not create atom object for " 162 +toString(_atom->getAtomIndex())); 163 const ObservedValue_Index_t atomid = _atom->getIndex(); 164 AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid); 165 ASSERT(iter == AtomsinSceneMap.end(), 166 "GLWorldScene::atomInserted - same atom with id " 167 +toString(_atom->getAtomIndex())+" added again."); 168 AtomsinSceneMap.insert( make_pair(atomid, atomObject) ); 169 170 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t))); 171 connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed())); 172 connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed())); 173 connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *))); 174 175 emit changed(); 176 emit changeOccured(); 177 } 178 179 /** Removes an atom. 180 * 181 * @param _atomid index of the atom that is removed 182 */ 183 void GLWorldScene::atomRemoved(ObservedValue_Index_t _atomid) 184 { 185 LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+"."); 186 // bonds are removed by signal coming from ~bond 187 188 // remove atoms 189 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atomid); 190 ASSERT(iter != AtomsinSceneMap.end(), 191 "GLWorldScene::atomRemoved() - atom "+toString(_atomid)+" not on display."); 192 GLMoleculeObject_atom *atomObject = iter->second; 193 AtomsinSceneMap.erase(iter); 194 delete atomObject; 195 196 emit changed(); 197 emit changeOccured(); 198 } 199 200 /** Adds a bond to the scene. 201 * 202 * @param _bond bond to add 203 */ 204 void GLWorldScene::bondInserted(QtObservedBond::ptr _bond) 205 { 206 static const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides = 207 boost::assign::list_of<GLMoleculeObject_bond::SideOfBond> 208 (GLMoleculeObject_bond::left) 209 (GLMoleculeObject_bond::right); 210 LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bonds " << _bond->getBondIndex()); 211 //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << "."); 212 213 const ObservedValue_Index_t bondid = _bond->getIndex(); 214 BondNodeMap::iterator iter = BondsinSceneMap.find(bondid); 215 ASSERT( iter == BondsinSceneMap.end(), 216 "GLWorldScene::bondInserted() - bond "+toString(bondid)+" is already known."); 217 for (size_t i=0;i<2;++i) { 218 GLMoleculeObject_bond * bondObject = 219 new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, _bond, bondsides[i]); 220 connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed())); 221 BondsinSceneMap.insert( std::make_pair(bondid, bondObject) ); 222 } 223 224 emit changed(); 225 emit changeOccured(); 226 } 227 228 /** Removes a bond. 229 * 230 * @param _bondid id of bond to remove 231 */ 232 void GLWorldScene::bondRemoved(ObservedValue_Index_t _bondid) 233 { 234 LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond to id " << _bondid); 235 236 // left bond 237 BondNodeMap::iterator iter = BondsinSceneMap.find(_bondid); 238 ASSERT( iter != BondsinSceneMap.end(), 239 "GLWorldScene::bondRemoved() - could not find bond to id "+toString(_bondid)); 240 GLMoleculeObject_bond *bondObject = iter->second; 241 delete bondObject; // is done by signal from bond itself 242 //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << "."); 243 BondsinSceneMap.erase(iter); 244 245 emit changed(); 246 emit changeOccured(); 247 } 248 249 void GLWorldScene::hoverChangedSignalled(GLMoleculeObject *ob) 250 { 251 // Find the atom, ob corresponds to. 252 hoverAtomId = -1; 253 GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob); 254 if (atomObject){ 255 for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){ 256 if (iter->second == atomObject) 257 hoverAtomId = iter->second->objectId(); 258 } 259 260 // Propagate signal. 261 emit hoverChanged(hoverAtomId); 262 } else { 263 // Find the atom, ob corresponds to. 264 GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob); 265 if (moleculeObject){ 266 // Propagate signal. 267 emit hoverChanged(moleculeObject->objectId(), 0); 268 } 269 } 270 } 271 145 272 void GLWorldScene::moleculeClicked(moleculeId_t no) 146 273 { … … 157 284 } 158 285 159 /** Prepares insertion of a general atom.160 *161 * This is called before the insertion into a molecule and thus before the162 * insertion into the scene.163 *164 * @param _atom atom to insert165 */166 void GLWorldScene::atomInserted(QtObservedAtom::ptr _atom)167 {168 const ObservedValue_Index_t atomid = _atom->getIndex();169 ASSERT( QtObservedAtomMap.find(atomid) == QtObservedAtomMap.end(),170 "GLWorldScene::AtomInserted() - atom with id "+toString(_atom->getAtomIndex())171 +" is already present in QtObservedAtomMap.");172 QtObservedAtomMap[atomid] = _atom;173 }174 175 /** Removes an general atom.176 *177 * This is called when the atom has been removed from the molecule.178 *179 * @param _atom atom to remove180 */181 void GLWorldScene::atomRemoved(ObservedValue_Index_t _atomid)182 {183 const QtObservedAtomMap_t::iterator eraseiter = QtObservedAtomMap.find(_atomid);184 ASSERT( eraseiter != QtObservedAtomMap.end(),185 "GLWorldScene::AtomRemoved() - atom with id "+toString(_atomid)186 +" is not present in QtObservedAtomMap.");187 QtObservedAtomMap.erase(eraseiter);188 }189 190 /** Prepares insertion of a bond.191 *192 * This is called before the insertion into a molecule and thus before the193 * insertion into the scene.194 *195 * @param _bond bond to insert196 */197 void GLWorldScene::bondInserted(QtObservedBond::ptr _bond)198 {199 const ObservedValue_Index_t bondid = _bond->getIndex();200 ASSERT( QtObservedBondMap.find(bondid) == QtObservedBondMap.end(),201 "GLWorldScene::BondInserted() - bond with id "+toString(_bond->getBondIndex())202 +" is already present in QtObservedBondMap.");203 QtObservedBondMap[bondid] = _bond;204 205 // assign to its molecule if present206 const moleculeId_t molid = _bond->getMoleculeIndex();207 if (molid != (moleculeId_t)-1) {208 QtObservedMolecule::ptr mol = board->getObservedMolecule(molid);209 emit moleculesBondInserted(_bond, mol.get());210 } else {211 // watch bond till it has a molecule212 connect( _bond.get(), SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),213 this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));214 }215 }216 217 /** Handle change of molecule from initial none.218 *219 */220 void GLWorldScene::bondsMoleculeChanged(moleculeId_t _oldid, moleculeId_t _newid)221 {222 ASSERT( _oldid == (moleculeId_t)-1,223 "GLWorldScene::bondsMoleculeChanged() - got true index change from "224 +toString(_oldid)+" to "+toString(_newid)+" and not just added to mol.");225 QtObservedBond* bondref = static_cast<QtObservedBond*>(sender());226 227 // disconnect from further molecule changes228 disconnect( bondref, SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),229 this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));230 231 // add it to its molecule232 QtObservedMolecule::ptr mol = board->getObservedMolecule(_newid);233 emit moleculesBondInserted(bondref->getRef(), mol.get());234 }235 236 237 /** Removes an general bond.238 *239 * This is called when the bond has been removed from the molecule.240 *241 * @param _bond bond to remove242 */243 void GLWorldScene::bondRemoved(ObservedValue_Index_t _bondid)244 {245 const QtObservedBondMap_t::iterator eraseiter = QtObservedBondMap.find(_bondid);246 ASSERT( eraseiter != QtObservedBondMap.end(),247 "GLWorldScene::BondRemoved() - bond with id "+toString(_bondid)248 +" is not present in QtObservedBondMap.");249 QtObservedBond::ptr bondref = eraseiter->second;250 251 // tell its assigned molecule if present252 const moleculeId_t molid = bondref->getMoleculeIndex();253 if (molid != (moleculeId_t)-1) {254 QtObservedMolecule::ptr mol = board->getObservedMolecule(molid);255 emit moleculesBondRemoved(_bondid, mol.get());256 } else {257 // it might have still been waiting for a molecule assignment258 disconnect( bondref.get(), SIGNAL(moleculeIndexChanged(moleculeId_t,moleculeId_t)),259 this, SLOT(bondsMoleculeChanged(moleculeId_t, moleculeId_t)));260 }261 QtObservedBondMap.erase(eraseiter);262 }263 264 /** Inserts an atom into the scene when molecule is present.265 *266 * @param _atom atom to insert267 */268 void GLWorldScene::moleculesAtomInserted(QtObservedAtom::ptr _atom, QtObservedMolecule * _mol)269 {270 const ObservedValue_Index_t atomid = _atom->getIndex();271 // this ASSERT cannot work: The same molecule may get reassigned to a different272 // molecule, when e.g. the time step changes (which triggers an update-molecules).273 // The GUI is slow and may lack behind and thus get to execute the event274 // moleculeAtomInserted when the change has been already been done.275 // ASSERT( (atommol == NULL) || (_mol == atommol),276 // "GLWorldScene::moleculesAtomInserted() - atom "+toString(atomid)277 // +" claims to belong to QtObservedMolecule "+toString(atommol)278 // +" but signal came from QtObservedMolecule "+toString(_mol)+".");279 LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom " << _atom->getAtomIndex());280 const ObservedValue_Index_t molid = _mol->getIndex();281 282 // check of molecule is already present283 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);284 const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);285 if (moliter != MoleculesinSceneMap.end()) {286 const RemovedMoleculesMap_t::iterator emptyiter = EmptyMolecules.find(_mol);287 if (emptyiter != EmptyMolecules.end())288 EmptyMolecules.erase(emptyiter);289 // check that it is the right molecule290 QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;291 if (checkmol.get() == _mol) {292 LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomInserted for atom "293 << _atom->getAtomIndex());294 QMetaObject::invokeMethod(moliter->second, // pointer to a QObject295 "atomInserted", // member name (no parameters here)296 Qt::QueuedConnection, // connection type297 Q_ARG(QtObservedAtom::ptr, _atom)); // parameters298 } else {299 // relay atomRemoved to GLMoleculeObject_molecule in RemovedMolecules300 // LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomInserted for atom "+toString(_atomid)301 // +" to molecule in RemovedMolecules.");302 // const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(molid);303 // ASSERT( removedmoliter != RemovedMolecules.end(),304 // "GLWorldScene::moleculesAtomInserted() - signal from old mol "305 // +toString(molid)+", but not present in RemovedMolecules");306 // QMetaObject::invokeMethod(removedmoliter->second, // pointer to a QObject307 // "atomInserted ", // member name (no parameters here)308 // Qt::QueuedConnection, // connection type309 // Q_ARG(QtObservedAtom::ptr, _atom)); // parameters310 ASSERT( 0,311 "GLWorldScene::moleculesAtomInserted() - would need to send atomInserted to already removed molecule.");312 }313 } else {314 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);315 if (removedmoliter != RemovedMolecules.end()) {316 ASSERT( 0,317 "GLWorldScene::moleculesAtomInserted() - would need to send atomInserted to already removed molecule.");318 } else {319 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);320 // only record missed state for molecule if (still) present but not instantiated321 if (QtObservedMoleculeMap.count(molid)) {322 // store signal for when it is instantiated323 if (MoleculeMissedStateMap.count(molid) == 0)324 MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );325 MoleculeMissedStateMap[molid].insert( std::make_pair(atomid, atomInsertedState) );326 ASSERT( QtObservedAtomMap[atomid] == _atom,327 "GLWorldScene::moleculesAtomInserted() - atom "+toString(atomid)328 +" inserted in molecule "+toString(_mol->getMolIndex())329 +" which does not match atom in QtObservedAtomMap.");330 LOG(3, "INFO: GLWorldScene: Placing atomInserted for atom " << _atom->getAtomIndex()331 << " and molecule " << _mol->getMolIndex() << " into missed state map.");332 }333 }334 }335 }336 337 /** Removes an atom into the scene before molecule is present.338 *339 * @param _atomid atom to remove340 */341 void GLWorldScene::moleculesAtomRemoved(ObservedValue_Index_t _atomid, QtObservedMolecule * _mol)342 {343 LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");344 345 const ObservedValue_Index_t molid = _mol->getIndex();346 // check of molecule is already present347 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);348 const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);349 if (moliter != MoleculesinSceneMap.end()) {350 const QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;351 if (checkmol.get() == _mol) {352 LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomRemoved for atom "+toString(_atomid)+".");353 QMetaObject::invokeMethod(moliter->second, // pointer to a QObject354 "atomRemoved", // member name (no parameters here)355 Qt::QueuedConnection, // connection type356 Q_ARG(ObservedValue_Index_t, _atomid)); // parameters357 } else {358 // relay atomRemoved to GLMoleculeObject_molecule in RemovedMolecules359 LOG(3, "INFO: GLWorldScene: Sending signal moleculesAtomRemoved for atom "+toString(_atomid)360 +" to molecule in RemovedMolecules.");361 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);362 ASSERT( removedmoliter != RemovedMolecules.end(),363 "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "364 +toString(molid)+", but not present in RemovedMolecules");365 #ifndef NDEBUG366 const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;367 #endif368 ASSERT( othercheckmol.get() == _mol,369 "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "370 +toString(molid)+", but different one "+toString(othercheckmol)371 +" present in RemovedMolecules.");372 QMetaObject::invokeMethod(removedmoliter->second, // pointer to a QObject373 "atomRemoved", // member name (no parameters here)374 Qt::QueuedConnection, // connection type375 Q_ARG(ObservedValue_Index_t, _atomid)); // parameters376 }377 } else {378 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);379 if (removedmoliter != RemovedMolecules.end()) {380 ASSERT( removedmoliter != RemovedMolecules.end(),381 "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "382 +toString(molid)+", but not present in RemovedMolecules");383 #ifndef NDEBUG384 const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;385 #endif386 ASSERT( othercheckmol.get() == _mol,387 "GLWorldScene::moleculesAtomRemoved() - signal from old molecule "388 +toString(molid)+", but different one "+toString(othercheckmol)389 +" present in RemovedMolecules.");390 QMetaObject::invokeMethod(removedmoliter->second, // pointer to a QObject391 "atomRemoved", // member name (no parameters here)392 Qt::QueuedConnection, // connection type393 Q_ARG(ObservedValue_Index_t, _atomid)); // parameters394 } else {395 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);396 // only record missed state for molecule if (still) present but not instantiated397 if (QtObservedMoleculeMap.count(molid)) {398 // store signal for when it is instantiated399 if (MoleculeMissedStateMap.count(molid) == 0)400 MoleculeMissedStateMap.insert( std::make_pair(molid, StateChangeMap_t()) );401 MoleculeMissedStateMap[molid].insert( std::make_pair(_atomid, atomRemovedState) );402 LOG(3, "INFO: GLWorldScene: Placing atomRemoved for atom " << _atomid403 << " and molecule " << molid << " into missed state map.");404 }405 }406 }407 }408 409 /** Inserts an bond into the scene when molecule is present.410 *411 * @param _bond bond to insert412 */413 void GLWorldScene::moleculesBondInserted(QtObservedBond::ptr _bond, QtObservedMolecule * _mol)414 {415 const ObservedValue_Index_t bondid = _bond->getIndex();416 LOG(3, "INFO: GLWorldScene: Received signal bondInserted for bond " << _bond->getBondIndex());417 const ObservedValue_Index_t molid = _mol->getIndex();418 419 // check of molecule is already present420 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);421 const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);422 if (moliter != MoleculesinSceneMap.end()) {423 // check that it is the right molecule424 QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;425 ASSERT( checkmol.get() == _mol,426 "GLWorldScene::moleculesBondInserted() - claimed and present molecule differ.");427 LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondInserted for bond "428 << _bond->getBondIndex());429 QMetaObject::invokeMethod(moliter->second, // pointer to a QObject430 "bondInserted", // member name (no parameters here)431 Qt::QueuedConnection, // connection type432 Q_ARG(QtObservedBond::ptr, _bond)); // parameters433 } else {434 #ifndef NDEBUG435 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);436 ASSERT( removedmoliter != RemovedMolecules.end(),437 "GLWorldScene::moleculesBondInserted() - would need to send bondInserted to already removed molecule.");438 #endif439 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);440 // only record missed state for molecule if (still) present but not instantiated441 if (QtObservedMoleculeMap.count(molid)) {442 // store signal for when it is instantiated443 if (MoleculeMissedStateMap.count(molid) == 0)444 MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );445 MoleculeMissedStateMap[molid].insert( std::make_pair(bondid, bondInsertedState) );446 ASSERT( QtObservedBondMap[bondid] == _bond,447 "GLWorldScene::moleculesBondInserted() - bond "+toString(bondid)448 +" inserted in molecule "+toString(_mol->getMolIndex())449 +" which does not match bond in QtObservedBondMap.");450 LOG(3, "INFO: GLWorldScene: Placing bondInserted for bond " << _bond->getBondIndex()451 << " and molecule " << _mol->getMolIndex() << " into missed state map.");452 }453 }454 }455 456 /** Removes an bond into the scene before molecule is present.457 *458 * @param _bondid bond to remove459 */460 void GLWorldScene::moleculesBondRemoved(ObservedValue_Index_t _bondid, QtObservedMolecule * _mol)461 {462 LOG(3, "INFO: GLWorldScene: Received signal bondRemoved for bond "+toString(_bondid)+".");463 464 const ObservedValue_Index_t molid = _mol->getIndex();465 // check of molecule is already present466 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);467 const MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);468 if (moliter != MoleculesinSceneMap.end()) {469 const QtObservedMolecule::ptr &checkmol = moliter->second->ObservedMolecule;470 if (checkmol.get() == _mol) {471 LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondRemoved for bond "+toString(_bondid)+".");472 QMetaObject::invokeMethod(moliter->second, // pointer to a QObject473 "bondRemoved", // member name (no parameters here)474 Qt::QueuedConnection, // connection type475 Q_ARG(ObservedValue_Index_t, _bondid)); // parameters476 } else {477 // relay bondRemoved to GLMoleculeObject_molecule in RemovedMolecules478 LOG(3, "INFO: GLWorldScene: Sending signal moleculesBondRemoved for bond "+toString(_bondid)479 +" to molecule in RemovedMolecules.");480 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);481 ASSERT( removedmoliter != RemovedMolecules.end(),482 "GLWorldScene::moleculesBondRemoved() - signal from old molecule "483 +toString(molid)+", but not present in RemovedMolecules");484 #ifndef NDEBUG485 const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;486 ASSERT( othercheckmol.get() == _mol,487 "GLWorldScene::moleculesBondRemoved() - signal from old molecule "488 +toString(molid)+", but different one "+toString(othercheckmol)489 +" present in RemovedMolecules.");490 #endif491 QMetaObject::invokeMethod(removedmoliter->second, // pointer to a QObject492 "bondRemoved", // member name (no parameters here)493 Qt::QueuedConnection, // connection type494 Q_ARG(ObservedValue_Index_t, _bondid)); // parameters495 }496 } else {497 const RemovedMoleculesMap_t::iterator removedmoliter = RemovedMolecules.find(_mol);498 if (removedmoliter != RemovedMolecules.end()) {499 ASSERT( removedmoliter != RemovedMolecules.end(),500 "GLWorldScene::moleculesBondRemoved() - signal from old molecule "501 +toString(molid)+", but not present in RemovedMolecules");502 #ifndef NDEBUG503 const QtObservedMolecule::ptr &othercheckmol = removedmoliter->second->ObservedMolecule;504 ASSERT( othercheckmol.get() == _mol,505 "GLWorldScene::moleculesBondRemoved() - signal from old molecule "506 +toString(molid)+", but different one "+toString(othercheckmol)507 +" present in RemovedMolecules.");508 #endif509 QMetaObject::invokeMethod(removedmoliter->second, // pointer to a QObject510 "bondRemoved", // member name (no parameters here)511 Qt::QueuedConnection, // connection type512 Q_ARG(ObservedValue_Index_t, _bondid)); // parameters513 } else {514 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);515 // only record missed state for molecule if (still) present but not instantiated516 if (QtObservedMoleculeMap.count(molid)) {517 // store signal for when it is instantiated518 if (MoleculeMissedStateMap.count(molid) == 0)519 MoleculeMissedStateMap.insert( std::make_pair(molid, StateChangeMap_t()) );520 MoleculeMissedStateMap[molid].insert( std::make_pair(_bondid, bondRemovedState) );521 LOG(3, "INFO: GLWorldScene: Placing bondRemoved for bond " << _bondid522 << " and molecule " << molid << " into missed state map.");523 }524 }525 }526 }527 528 void GLWorldScene::moleculeSignOn(QtObservedMolecule::ptr _mol)529 {530 // sign on to QtObservedMolecule to get atomInserted/..Removed signals from same531 // source as GLMoleculeObject_molecule would532 connect(_mol.get(), SIGNAL(atomInserted(QtObservedAtom::ptr, QtObservedMolecule *)),533 this, SLOT(moleculesAtomInserted(QtObservedAtom::ptr, QtObservedMolecule *)) );534 connect(_mol.get(), SIGNAL(atomRemoved(ObservedValue_Index_t, QtObservedMolecule *)),535 this, SLOT(moleculesAtomRemoved(ObservedValue_Index_t, QtObservedMolecule *)) );536 const ObservedValue_Index_t molid = _mol->getIndex();537 ASSERT( QtObservedMoleculeMap.find(molid) == QtObservedMoleculeMap.end(),538 "GLWorldScene::moleculeSignOn() - molecule with id "+toString(_mol->getMolIndex())539 +" is already present in QtObservedMoleculeMap.");540 QtObservedMoleculeMap[molid] = _mol;541 542 LOG(3, "INFO: GLWorldScene: Received signal moleculeSignOn for molecule " << _mol->getMolIndex());543 544 emit insertMolecule(_mol);545 }546 547 void GLWorldScene::moleculeSignOff(ObservedValue_Index_t _id)548 {549 const QtObservedMoleculeMap_t::iterator eraseiter = QtObservedMoleculeMap.find(_id);550 ASSERT( eraseiter != QtObservedMoleculeMap.end(),551 "GLWorldScene::moleculeSignOff() - cannot find id "+toString(_id)+" in map.");552 QtObservedMolecule * mol = eraseiter->second.get();553 QtObservedMoleculeMap.erase(eraseiter);554 555 LOG(3, "INFO: GLWorldScene: Received signal moleculeSignOff for molecule " << mol->getMolIndex());556 557 emit removeMolecule(mol);558 }559 560 286 /** Inserts a molecule into the scene. 561 287 * … … 564 290 void GLWorldScene::moleculeInserted(QtObservedMolecule::ptr _mol) 565 291 { 566 ASSERT (_mol,567 "GLWorldScene::moleculeInserted() - received shared_ptr for molecule is empty?");568 292 const ObservedValue_Index_t molid = _mol->getIndex(); 569 293 LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule " 570 294 << _mol->getMolIndex()); 571 572 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);573 295 574 296 MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid); … … 583 305 GLMoleculeObject::meshEmpty, 584 306 this, 585 *board,586 307 _mol); 587 308 ASSERT( molObject != NULL, … … 596 317 +" already present in scene."); 597 318 598 // now handle all state changes that came up before the instantiation599 if (MoleculeMissedStateMap.count(molid) != 0) {600 // ASSERT( !MoleculeMissedStateMap[molid].empty(),601 // "GLWorldScene::moleculeInserted() - we have an empty state change map for molecule with id "602 // +toString(molid));603 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);604 for (StateChangeMap_t::iterator iter = MoleculeMissedStateMap[molid].begin();605 !MoleculeMissedStateMap[molid].empty();606 iter = MoleculeMissedStateMap[molid].begin()) {607 std::pair<StateChangeMap_t::iterator, StateChangeMap_t::iterator> rangeiter =608 MoleculeMissedStateMap[molid].equal_range(iter->first);609 const size_t StateCounts = std::distance(rangeiter.first, rangeiter.second);610 if (StateCounts > 1) {611 // more than one state change, have to combine612 typedef std::map<StateChangeType, size_t> StateChangeAmounts_t;613 StateChangeAmounts_t StateChangeAmounts;614 for (StateChangeMap_t::const_iterator stateiter = rangeiter.first;615 stateiter != rangeiter.second; ++stateiter)616 ++StateChangeAmounts[stateiter->second];617 // is it an atom?618 if ((StateChangeAmounts[atomInsertedState] + StateChangeAmounts[atomRemovedState]) != 0) {619 ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],620 "GLWorldScene::moleculeInserted() - more atomRemoved states "621 +toString(StateChangeAmounts[atomRemovedState])+" than atomInserted "622 +toString(StateChangeAmounts[atomInsertedState])+" for atom "+toString(iter->first));623 if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {624 LOG(1, "INFO: invoking atomInserted for atom " << iter->first);625 QMetaObject::invokeMethod(molObject, // pointer to a QObject626 "atomInserted", // member name (no parameters here)627 Qt::QueuedConnection, // connection type628 Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first])); // parameters629 } else {630 LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");631 }632 }633 // or is it a bond?634 if ((StateChangeAmounts[bondInsertedState] + StateChangeAmounts[bondInsertedState]) != 0) {635 ASSERT( StateChangeAmounts[bondInsertedState] >= StateChangeAmounts[bondRemovedState],636 "GLWorldScene::moleculeInserted() - more bondRemoved states "637 +toString(StateChangeAmounts[bondRemovedState])+" than bondInserted "638 +toString(StateChangeAmounts[bondInsertedState])+" for bond "+toString(iter->first));639 if (StateChangeAmounts[bondInsertedState] > StateChangeAmounts[bondRemovedState]) {640 LOG(1, "INFO: invoking bondInserted for bond " << iter->first);641 QMetaObject::invokeMethod(molObject, // pointer to a QObject642 "bondInserted", // member name (no parameters here)643 Qt::QueuedConnection, // connection type644 Q_ARG(QtObservedBond::ptr, QtObservedBondMap[iter->first])); // parameters645 } else {646 LOG(1, "INFO: Bond " << iter->first << " has been inserted and removed already.");647 }648 }649 ASSERT( (StateChangeAmounts[bondInsertedState] + StateChangeAmounts[bondInsertedState]650 + StateChangeAmounts[atomInsertedState] + StateChangeAmounts[atomRemovedState]) != 0,651 "GLWorldScene::moleculeInserted() - state with no changes for "+toString(iter->first));652 // removed all state changes for this atom/bond653 MoleculeMissedStateMap[molid].erase(rangeiter.first, rangeiter.second);654 } else {655 // can only be an insertion656 switch (rangeiter.first->second) {657 case atomRemovedState:658 ASSERT( 0,659 "GLWorldScene::moleculeInserted() - atomRemoved state without atomInserted for atom "660 +toString(iter->first));661 break;662 case atomInsertedState:663 {664 LOG(1, "INFO: invoking atomInserted for atom " << iter->first);665 QMetaObject::invokeMethod(molObject, // pointer to a QObject666 "atomInserted", // member name (no parameters here)667 Qt::QueuedConnection, // connection type668 Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first])); // parameters669 break;670 }671 case bondRemovedState:672 ASSERT( 0,673 "GLWorldScene::moleculeInserted() - bondRemoved state without bondInserted for bond "674 +toString(iter->first));675 break;676 case bondInsertedState:677 {678 LOG(1, "INFO: invoking bondInserted for bond " << iter->first);679 QMetaObject::invokeMethod(molObject, // pointer to a QObject680 "bondInserted", // member name (no parameters here)681 Qt::QueuedConnection, // connection type682 Q_ARG(QtObservedBond::ptr, QtObservedBondMap[iter->first])); // parameters683 break;684 }685 default:686 ASSERT( 0,687 "GLWorldScene::moleculeInserted() - there are unknown change states.");688 break;689 }690 // removed state changes for this atom/bond691 MoleculeMissedStateMap[molid].erase(iter);692 }693 }694 }695 696 319 connect (molObject, SIGNAL(changed()), this, SIGNAL(changed())); 697 320 connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured())); 698 connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t))); 699 connect (molObject, SIGNAL(moleculeClicked(moleculeId_t)), this, SLOT(moleculeClicked(moleculeId_t))); 700 connect (molObject, SIGNAL(moleculeEmptied(QtObservedMolecule::ptr)), this, SLOT(moleculeEmpty(QtObservedMolecule::ptr))); 701 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed())); 702 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed())); 703 connect (molObject, SIGNAL(hoverChanged(const atomId_t)), this, SIGNAL(hoverChanged(const atomId_t))); 704 connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int))); 705 connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int))); 706 707 emit changed(); 708 emit changeOccured(); 709 710 // remove state change map for the molecule 711 { 712 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex); 713 MoleculeMissedStateMap.erase(molid); 714 } 321 322 emit changed(); 323 emit changeOccured(); 715 324 } 716 325 717 326 /** Removes a molecule from the scene. 718 327 * 719 * @param _mol QtObservedMolecule instance of molecule to remove 720 */ 721 void GLWorldScene::moleculeRemoved(QtObservedMolecule* _mol) 722 { 723 const ObservedValue_Index_t molid = _mol->getIndex(); 724 LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(molid)+"."); 725 726 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex); 727 728 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(molid); 328 * @param _molid index of the molecule to remove 329 */ 330 void GLWorldScene::moleculeRemoved(ObservedValue_Index_t _molid) 331 { 332 LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molid)+"."); 333 334 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid); 729 335 ASSERT ( iter != MoleculesinSceneMap.end(), 730 "GLWorldScene::moleculeRemoved() - to be removed molecule "+toString(_mol ->getMolIndex())336 "GLWorldScene::moleculeRemoved() - to be removed molecule "+toString(_molid) 731 337 +" is already gone."); 732 338 // check if it's already empty 733 const RemovedMoleculesMap_t::iterator emptyiter = EmptyMolecules.find(_mol); 734 if (emptyiter != EmptyMolecules.end()) { 735 LOG(1, "DEBUG: Removing empty GLMoleculeObject_molecule to id " << _mol->getMolIndex() 736 << " from scene."); 737 // it's already empty, remove it 738 ASSERT( emptyiter->second == iter->second, 739 "GLWorldScene::moleculeRemoved() - empty molecule " 740 +toString(emptyiter->second)+" and removed molecule " 741 +toString(iter->second)+" don't match."); 742 LOG(1, "DEBUG: Deleting already empty GLMoleculeObject_molecule to id " << _mol->getMolIndex()); 743 GLMoleculeObject_molecule *molObject = emptyiter->second; 744 EmptyMolecules.erase(emptyiter); 745 molObject->disconnect(); 746 delete molObject; 747 748 emit changed(); 749 emit changeOccured(); 750 } else { 751 // otherwise note it as removal candidate 752 RemovedMolecules.insert( std::make_pair(_mol, iter->second) ); 753 } 339 GLMoleculeObject_molecule *molObject = iter->second; 340 delete molObject; 754 341 MoleculesinSceneMap.erase(iter); 755 342 756 // remove any possible state changes left 757 { 758 boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex); 759 MoleculeMissedStateMap.erase(molid); 760 } 761 } 762 763 void GLWorldScene::moleculeEmpty(QtObservedMolecule::ptr _mol) 764 { 765 LOG(3, "INFO: GLWorldScene: Received signal moleculeEmpty for molecule " 766 +toString(_mol->getMolIndex())+"."); 767 768 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex); 769 770 const ObservedValue_Index_t molid = _mol->getIndex(); 771 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(molid); 772 if ( iter == MoleculesinSceneMap.end()) { 773 RemovedMoleculesMap_t::iterator removeiter = RemovedMolecules.find(_mol.get()); 774 ASSERT ( removeiter != RemovedMolecules.end(), 775 "GLWorldScene::moleculeEmpty() - to be removed molecule "+toString(_mol->getMolIndex()) 776 +" is neither in MoleculesinSceneMap, nor in RemovedMolecules."); 777 // it's noted for removal already, remove it 778 LOG(1, "DEBUG: Deleting empty GLMoleculeObject_molecule to id " << _mol->getMolIndex()); 779 GLMoleculeObject_molecule *molObject = removeiter->second; 780 RemovedMolecules.erase(removeiter); 781 molObject->disconnect(); 782 delete molObject; 783 784 emit changed(); 785 emit changeOccured(); 786 } else { 787 // otherwise just note it as empty 788 EmptyMolecules.insert( std::make_pair(_mol.get(), iter->second) ); 789 } 790 791 // // remove any possible state changes left 792 // { 793 // boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex); 794 // MoleculeMissedStateMap.erase(molid); 795 // } 343 emit changed(); 344 emit changeOccured(); 796 345 } 797 346 798 347 void GLWorldScene::moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible) 799 348 { 800 boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);801 349 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id); 802 350 ASSERT( iter != MoleculesinSceneMap.end(), -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp
r785d89 rf1b5ca 19 19 20 20 #include <iosfwd> 21 22 #include <boost/thread/recursive_mutex.hpp>23 21 24 22 #include "Bond/bond.hpp" … … 85 83 void hoverChanged(const atomId_t); 86 84 void hoverChanged(const moleculeId_t, int); 87 void insertMolecule(QtObservedMolecule::ptr);88 void removeMolecule(QtObservedMolecule*);89 85 90 86 private slots: 91 87 void atomClicked(atomId_t no); 92 void moleculeClicked(moleculeId_t no);93 void moleculeRemoved(QtObservedMolecule* _mol);94 void moleculeEmpty(QtObservedMolecule::ptr _mol);95 void moleculeInserted(QtObservedMolecule::ptr);96 void moleculeSignOn(QtObservedMolecule::ptr);97 void moleculeSignOff(ObservedValue_Index_t _id);98 void moleculesAtomRemoved(ObservedValue_Index_t _atomid, QtObservedMolecule * _mol);99 void moleculesAtomInserted(QtObservedAtom::ptr, QtObservedMolecule *_mol);100 void moleculesBondRemoved(ObservedValue_Index_t _bondid, QtObservedMolecule * _mol);101 void moleculesBondInserted(QtObservedBond::ptr, QtObservedMolecule *_mol);102 88 void atomRemoved(ObservedValue_Index_t _atomid); 103 89 void atomInserted(QtObservedAtom::ptr); 104 90 void bondRemoved(ObservedValue_Index_t _bondid); 105 91 void bondInserted(QtObservedBond::ptr); 106 void bondsMoleculeChanged(moleculeId_t _oldid, moleculeId_t _newid); 92 void moleculeClicked(moleculeId_t no); 93 void moleculeRemoved(ObservedValue_Index_t _molid); 94 void moleculeInserted(QtObservedMolecule::ptr); 107 95 void setSelectionModeAtom(); 108 96 void setSelectionModeMolecule(); … … 111 99 // void update(); 112 100 void moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible); 101 void hoverChangedSignalled(GLMoleculeObject *ob); 113 102 114 103 public: … … 117 106 private: 118 107 108 //!> id of atom hovered over 109 atomId_t hoverAtomId; 110 119 111 typedef std::map< ObservedValue_Index_t , GLMoleculeObject_molecule* > MoleculeNodeMap; 112 typedef std::map< ObservedValue_Index_t, GLMoleculeObject_atom* > AtomNodeMap; 113 typedef std::map< ObservedValue_Index_t, GLMoleculeObject_bond* > BondNodeMap; 120 114 typedef std::map< std::string , GLMoleculeObject_shape* > ShapeNodeMap; 115 116 AtomNodeMap AtomsinSceneMap; 117 BondNodeMap BondsinSceneMap; 121 118 MoleculeNodeMap MoleculesinSceneMap; 122 119 ShapeNodeMap ShapesinSceneMap; 123 //!> flag to indicate whether state map is currently worked on124 boost::recursive_mutex MoleculeinSceneMap_mutex;125 126 //!> enumeration of all possible changes molecule might have missed before instantiation127 enum StateChangeType {128 atomInsertedState,129 atomRemovedState,130 bondInsertedState,131 bondRemovedState,132 MAX_StateChangeType133 };134 typedef std::map< ObservedValue_Index_t, QtObservedAtom::ptr> QtObservedAtomMap_t;135 typedef std::map< ObservedValue_Index_t, QtObservedBond::ptr> QtObservedBondMap_t;136 typedef std::map< ObservedValue_Index_t, QtObservedMolecule::ptr> QtObservedMoleculeMap_t;137 typedef std::multimap< ObservedValue_Index_t, StateChangeType> StateChangeMap_t;138 typedef std::map< ObservedValue_Index_t, StateChangeMap_t> MissedStateMap_t;139 //!> map of all missed state changes140 MissedStateMap_t MoleculeMissedStateMap;141 //!> map to contain all QtObservedAtom that have not been instantiated so far142 QtObservedAtomMap_t QtObservedAtomMap;143 //!> map to contain all QtObservedBond that have not been instantiated so far144 QtObservedBondMap_t QtObservedBondMap;145 //!> map to contain all QtObservedMolecule that have not been instantiated so far146 QtObservedMoleculeMap_t QtObservedMoleculeMap;147 148 //!> map to get from QtObservedMolecule to the visual representant149 typedef std::map< QtObservedMolecule* , GLMoleculeObject_molecule* > RemovedMoleculesMap_t;150 //!> set of all currently removed molecules151 RemovedMoleculesMap_t RemovedMolecules;152 //!> set of all currently empty molecules (about to be removed)153 RemovedMoleculesMap_t EmptyMolecules;154 155 //!> flag to indicate whether state map is currently worked on156 boost::recursive_mutex MoleculeMissedStateMap_mutex;157 120 158 121 SelectionModeType selectionMode;
Note:
See TracChangeset
for help on using the changeset viewer.