- Timestamp:
- Jan 10, 2015, 5:14:21 PM (10 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:
- 739ee9
- Parents:
- 7b38d3
- git-author:
- Frederik Heber <heber@…> (11/05/14 19:19:42)
- git-committer:
- Frederik Heber <heber@…> (01/10/15 17:14:21)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp
r7b38d3 r8c001a 56 56 #include "World.hpp" 57 57 58 #include "GLMoleculeObject_atom.hpp" 59 58 60 GLMoleculeObject_molecule::GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const molecule *molref) : 59 61 GLMoleculeObject(mesh, parent), 60 62 Observer(std::string("GLMoleculeObject_molecule")+toString(molref->getId())), 61 _molecule(molref) 63 _molecule(molref), 64 hoverAtom(NULL) 62 65 { 63 66 // sign on as observer (obtain non-const instance before) 67 _molecule->signOn(this, molecule::AtomInserted); 68 _molecule->signOn(this, molecule::AtomRemoved); 64 69 /*molref->signOn(this, AtomObservable::IndexChanged); 65 70 molref->signOn(this, AtomObservable::PositionChanged); … … 69 74 World::getInstance().signOn(this, World::SelectionChanged); 70 75 updateBoundingBox(); 76 77 init(); 71 78 } 72 79 73 80 GLMoleculeObject_molecule::~GLMoleculeObject_molecule() 74 81 { 82 _molecule->signOff(this, molecule::AtomInserted); 83 _molecule->signOff(this, molecule::AtomRemoved); 75 84 /*_atom->signOff(this, AtomObservable::IndexChanged); 76 85 _atom->signOff(this, AtomObservable::PositionChanged); … … 78 87 _atom->signOff(this, AtomObservable::BondsAdded);*/ 79 88 World::getInstance().signOff(this, World::SelectionChanged); 89 } 90 91 /** Initialise the WorldScene with molecules and atoms from World. 92 * 93 */ 94 void GLMoleculeObject_molecule::init() 95 { 96 if (_molecule->begin() != _molecule->end()) { 97 for (molecule::const_iterator atomiter = _molecule->begin(); 98 atomiter != _molecule->end(); 99 atomiter++) { 100 // create atom objects in scene 101 atomInserted((*atomiter)->getId()); 102 103 // create bond objects in scene 104 const BondList &bondlist = (*atomiter)->getListOfBonds(); 105 for (BondList::const_iterator bonditer = bondlist.begin(); 106 bonditer != bondlist.end(); 107 ++bonditer) { 108 const bond::ptr _bond = *bonditer; 109 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == *atomiter) ? 110 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right; 111 bondInserted(_bond, side); 112 } 113 } 114 } 115 } 116 117 void GLMoleculeObject_molecule::addAtomBonds( 118 const bond::ptr &_bond, 119 const GLMoleculeObject_bond::SideOfBond _side 120 ) 121 { 122 bool bond_present = false; 123 const BondIds ids = getBondIds(_bond, _side); 124 // check whether bond is not present already 125 bond_present = BondsinSceneMap.count(ids); 126 if (!bond_present) 127 bondInserted(_bond, _side); 128 else { 129 BondsinSceneMap[ids]->resetPosition(); 130 BondsinSceneMap[ids]->resetWidth(); 131 } 132 } 133 134 void GLMoleculeObject_molecule::addAtomBonds( 135 const atom *_atom) 136 { 137 const bool atom_present = AtomsinSceneMap.count(_atom->getId()); 138 const BondList &bondlist = _atom->getListOfBonds(); 139 for (BondList::const_iterator bonditer = bondlist.begin(); 140 (bonditer != bondlist.end()) && atom_present; 141 ++bonditer) { 142 const bond::ptr _bond = *bonditer; 143 // check if OtherAtom's sphere is already present 144 const atom *OtherAtom = _bond->GetOtherAtom(_atom); 145 const bool otheratom_present = AtomsinSceneMap.count(OtherAtom->getId()); 146 if (otheratom_present && atom_present) { 147 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ? 148 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right; 149 const GLMoleculeObject_bond::SideOfBond otherside = (_bond->leftatom == _atom) ? 150 GLMoleculeObject_bond::right : GLMoleculeObject_bond::left; 151 addAtomBonds(_bond, side); 152 addAtomBonds(_bond, otherside); 153 } 154 } 155 } 156 157 void GLMoleculeObject_molecule::reinit() 158 { 159 if (_molecule->getAtomCount() > 0) { 160 for (molecule::const_iterator atomiter = _molecule->begin(); 161 atomiter != _molecule->end(); 162 atomiter++) { 163 // check whether atom already exists 164 const atomId_t atomid = (*atomiter)->getId(); 165 const bool atom_present = AtomsinSceneMap.count(atomid); 166 if (!atom_present) 167 atomInserted((*atomiter)->getId()); 168 else 169 AtomsinSceneMap[atomid]->resetPosition(); 170 171 172 // create bond objects in scene 173 addAtomBonds(*atomiter); 174 } 175 } 80 176 } 81 177 … … 108 204 << notification->getChannelNo() << "."; 109 205 #endif 206 switch (notification->getChannelNo()) { 207 case molecule::AtomInserted: 208 { 209 const atomId_t _id = _molecule->lastChanged()->getId(); 210 #ifdef LOG_OBSERVER 211 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been inserted."; 212 #endif 213 atomInserted(_id); 214 break; 215 } 216 case World::AtomRemoved: 217 { 218 const atomId_t _id = _molecule->lastChanged()->getId(); 219 #ifdef LOG_OBSERVER 220 observerLog().addMessage() << "++ Observer " << observerLog().getName(static_cast<Observer *>(this)) << " received notification that atom "+toString(_id)+" has been removed."; 221 #endif 222 atomRemoved(_id); 223 break; 224 } 225 default: 226 break; 227 } 110 228 }else{ 111 229 // notification from world … … 125 243 } 126 244 245 void GLMoleculeObject_molecule::initialize(QGLView *view, QGLPainter *painter) 246 { 247 // Initialize all of the mesh objects that we have as children. 248 // GLMoleculeObject::initialize(view, painter); 249 foreach (QObject *obj, children()) { 250 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj); 251 if (meshobj) 252 meshobj->initialize(view, painter); 253 } 254 } 255 256 void GLMoleculeObject_molecule::draw(QGLPainter *painter, const QVector4D &cameraPlane) 257 { 258 // Draw all of the mesh objects that we have as children. 259 GLMoleculeObject::draw(painter, cameraPlane); 260 foreach (QObject *obj, children()) { 261 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj); 262 if (meshobj) 263 meshobj->draw(painter, cameraPlane); 264 } 265 } 266 267 /** Adds an atom of this molecule to the scene. 268 * 269 * @param _atom atom to add 270 */ 271 void GLMoleculeObject_molecule::atomInserted(const atomicNumber_t _id) 272 { 273 LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_id)+"."); 274 GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(GLMoleculeObject::meshSphere, this, _id); 275 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id); 276 ASSERT(iter == AtomsinSceneMap.end(), 277 "GLWorldScene::atomAdded() - same atom with id "+toString(_id)+" added again."); 278 AtomsinSceneMap.insert( make_pair(_id, atomObject) ); 279 280 qRegisterMetaType<atomId_t>("atomId_t"); 281 qRegisterMetaType<bond::ptr>("bond::ptr"); 282 qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond"); 283 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SIGNAL(atomClicked(atomId_t))); 284 connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed())); 285 connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed())); 286 connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *))); 287 connect (atomObject, SIGNAL(selectionChanged()), this, SIGNAL(changed())); 288 connect (atomObject, SIGNAL(BondsInserted(const bond::ptr , const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond::ptr , const GLMoleculeObject_bond::SideOfBond))); 289 connect (atomObject, SIGNAL(indexChanged(GLMoleculeObject_atom*, int, int)), this, SIGNAL(changeAtomId(GLMoleculeObject_atom*, int, int))); 290 291 updateBoundingBox(); 292 293 //bondsChanged(_atom); 294 emit changeOccured(); 295 } 296 297 /** Removes an atom of this molecule from the scene. 298 * 299 * We just the id as the atom might have already been destroyed. 300 * 301 * @param _id id of atom to remove 302 */ 303 void GLMoleculeObject_molecule::atomRemoved(const atomicNumber_t _id) 304 { 305 LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_id)+"."); 306 // bonds are removed by signal coming from ~bond 307 // remove atoms 308 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id); 309 ASSERT(iter != AtomsinSceneMap.end(), 310 "GLWorldScene::atomRemoved() - atom "+toString(_id)+" not on display."); 311 GLMoleculeObject_atom *atomObject = iter->second; 312 atomObject->disconnect(); 313 AtomsinSceneMap.erase(iter); 314 delete atomObject; 315 316 updateBoundingBox(); 317 318 emit changeOccured(); 319 } 320 321 void GLMoleculeObject_molecule::hoverChangedSignalled(GLMoleculeObject *ob) 322 { 323 // Find the atom, ob corresponds to. 324 hoverAtom = NULL; 325 GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob); 326 if (atomObject){ 327 for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){ 328 if (iter->second == atomObject) 329 hoverAtom = World::getInstance().getAtom(AtomById(iter->first)); 330 } 331 } 332 333 // Propagate signal. 334 emit hoverChanged(hoverAtom); 335 } 336 337 338 /** Helper function to get bond ids in the correct order for BondNodeMap. 339 * 340 * \return pair of ids in correct order. 341 */ 342 GLMoleculeObject_molecule::BondIds GLMoleculeObject_molecule::getBondIds( 343 const bond::ptr _bond, 344 const enum GLMoleculeObject_bond::SideOfBond _side) 345 { 346 BondIds ids; 347 switch (_side) { 348 case GLMoleculeObject_bond::left: 349 ids = std::make_pair(_bond->leftatom->getId(), _bond->rightatom->getId()); 350 break; 351 case GLMoleculeObject_bond::right: 352 ids = std::make_pair(_bond->rightatom->getId(), _bond->leftatom->getId()); 353 break; 354 } 355 return ids; 356 } 357 358 /** Adds a bond to the scene. 359 * 360 * @param _bond bond to add 361 * @param side which side of the bond (left or right) 362 */ 363 void GLMoleculeObject_molecule::bondInserted(const bond::ptr _bond, const enum GLMoleculeObject_bond::SideOfBond _side) 364 { 365 LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+"."); 366 //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << "."); 367 368 const BondIds ids = getBondIds(_bond, _side); 369 BondNodeMap::iterator iter = BondsinSceneMap.find(ids); 370 if (iter == BondsinSceneMap.end()) { 371 GLMoleculeObject_bond * bondObject = 372 new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, _bond, _side); 373 connect ( 374 bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)), 375 this, SLOT(bondRemoved(const atomId_t, const atomId_t))); 376 connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed())); 377 BondsinSceneMap.insert( make_pair(ids, bondObject) ); 378 // BondIdsinSceneMap.insert( Leftids ); 379 } else { 380 iter->second->resetPosition(); 381 iter->second->resetWidth(); 382 } 383 emit changeOccured(); 384 } 385 386 /** Removes a bond from the scene. 387 * 388 * @param _bond bond to remove 389 */ 390 void GLMoleculeObject_molecule::bondRemoved(const atomId_t leftnr, const atomId_t rightnr) 391 { 392 LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+"."); 393 { 394 // left bond 395 const BondIds Leftids( make_pair(leftnr, rightnr) ); 396 BondNodeMap::iterator leftiter = BondsinSceneMap.find( Leftids ); 397 ASSERT(leftiter != BondsinSceneMap.end(), 398 "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-" 399 +toString(rightnr)+" not on display."); 400 GLMoleculeObject_bond *bondObject = leftiter->second; 401 bondObject->disconnect(); 402 BondsinSceneMap.erase(leftiter); 403 delete bondObject; // is done by signal from bond itself 404 //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << "."); 405 } 406 407 emit changeOccured(); 408 } 409 410 std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t) 411 { 412 ost << t.first << "," << t.second; 413 return ost; 414 }
Note:
See TracChangeset
for help on using the changeset viewer.