- Timestamp:
- Feb 12, 2016, 11:15:05 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:
- 026bef
- Parents:
- 16bd37
- git-author:
- Frederik Heber <heber@…> (10/17/15 13:28:19)
- git-committer:
- Frederik Heber <heber@…> (02/12/16 23:15:05)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp
r16bd37 r099f67 62 62 // static entities 63 63 const Observable::channels_t 64 GLMoleculeObject_bond::IndexChannels(1, AtomObservable::IndexChanged); 65 const Observable::channels_t 64 66 GLMoleculeObject_bond::BondPositionChannels(1, AtomObservable::PositionChanged); 65 67 const Observable::channels_t … … 78 80 +std::string("-") 79 81 +toString(bondIds.second)), 80 leftatomId(bondIds.first), 81 rightatomId(bondIds.second), 82 leftowner(getAtom(leftatomId)), 83 rightowner(getAtom(rightatomId)), 84 bondowner(getAtom(leftatomId)->getBond(getAtom(rightatomId)).get()), 82 leftowner(getAtomConst(bondIds.first)), 83 rightowner(getAtomConst(bondIds.second)), 84 bondowner(getAtomConst(bondIds.first)->getBond(getAtomConst(bondIds.second)).get()), 85 85 BondSide(side), 86 86 ObservedValues(MAX_ObservedTypes), … … 89 89 rightobservable_enabled(false) 90 90 { 91 initObservedValues(); 91 boost::function<void()> subjectKilled = 92 boost::bind(&GLMoleculeObject_bond::countsubjectKilled, this); 93 initObservedValues(ObservedValues, bondIds.first, bondIds.second, leftowner, rightowner, bondowner, subjectKilled); 92 94 93 95 // sign on as observer (obtain non-const instance before) … … 114 116 { 115 117 LOG(3, "DEBUG: Destroying GLMoleculeObject_bond to bond [" << 116 leftatomId << "," << rightatomId<< "] and side " << BondSide << ".");118 getleftIndex() << "," << getrightIndex() << "] and side " << BondSide << "."); 117 119 // signOff() if not already done 118 120 removeChannels(); 119 destroyObservedValues( );121 destroyObservedValues(ObservedValues); 120 122 } 121 123 … … 171 173 observerLog().addMessage() << "++ Update of Observer " 172 174 << observerLog().getName(static_cast<Observer*>(this)) 173 << " received notification from leftatom " << leftatomId<< " for channel "175 << " received notification from leftatom " << getleftIndex() << " for channel " 174 176 << notification->getChannelNo() << "."; 175 177 } else if (publisher == static_cast<const Observable * const>(rightowner)) { 176 178 observerLog().addMessage() << "++ Update of Observer " 177 179 << observerLog().getName(static_cast<Observer*>(this)) 178 << " received notification from rightatom " << rightatomId<< " for channel "180 << " received notification from rightatom " << getrightIndex() << " for channel " 179 181 << notification->getChannelNo() << "."; 180 182 } … … 209 211 } 210 212 211 Vector GLMoleculeObject_bond::updateLeftPosition() const 212 { 213 const atom * const _atom = getAtomConst(leftatomId); 213 atomId_t GLMoleculeObject_bond::updateIndex() 214 { 215 return const_cast<const World &>(World::getInstance()).lastChangedAtomId(); 216 } 217 218 Vector GLMoleculeObject_bond::updateLeftPosition( 219 const boost::function<const atomId_t ()> &_getLeftAtomIndex) 220 { 221 const atom * const _atom = getAtomConst(_getLeftAtomIndex()); 214 222 return _atom->getPosition(); 215 223 } 216 224 217 Vector GLMoleculeObject_bond::updateRightPosition() const 218 { 219 const atom * const _atom = getAtomConst(rightatomId); 225 Vector GLMoleculeObject_bond::updateRightPosition( 226 const boost::function<const atomId_t ()> &_getRightAtomIndex) 227 { 228 const atom * const _atom = getAtomConst(_getRightAtomIndex()); 220 229 return _atom->getPosition(); 221 230 } 222 231 223 atomicNumber_t GLMoleculeObject_bond::updateLeftElement() const 224 { 225 const atom * const _atom = getAtomConst(leftatomId); 232 atomicNumber_t GLMoleculeObject_bond::updateLeftElement( 233 const boost::function<const atomId_t ()> &_getLeftAtomIndex) 234 { 235 const atom * const _atom = getAtomConst(_getLeftAtomIndex()); 226 236 return _atom->getElementNo(); 227 237 } 228 238 229 atomicNumber_t GLMoleculeObject_bond::updateRightElement() const 230 { 231 const atom * const _atom = getAtomConst(rightatomId); 239 atomicNumber_t GLMoleculeObject_bond::updateRightElement( 240 const boost::function<const atomId_t ()> &_getRightAtomIndex) 241 { 242 const atom * const _atom = getAtomConst(_getRightAtomIndex()); 232 243 return _atom->getElementNo(); 233 244 } 234 245 235 int GLMoleculeObject_bond::updateDegree() const 246 int GLMoleculeObject_bond::updateDegree( 247 const boost::function<const atomId_t ()> &_getLeftAtomIndex, 248 const boost::function<const atomId_t ()> &_getRightAtomIndex) 236 249 { 237 250 const atom * const _leftatom = const_cast<const World &>(World::getInstance()). 238 getAtom(AtomById( leftatomId));251 getAtom(AtomById(_getLeftAtomIndex())); 239 252 const atom * const _rightatom = const_cast<const World &>(World::getInstance()). 240 getAtom(AtomById( rightatomId));253 getAtom(AtomById(_getRightAtomIndex())); 241 254 if ((_leftatom != NULL) && (_rightatom != NULL)) { 242 255 bond::ptr _bond = _leftatom->getBond(_rightatom); … … 323 336 324 337 if (subjectKilledCount > ObservedValues.size()) 325 emit BondRemoved(leftatomId, rightatomId); 326 } 327 328 void GLMoleculeObject_bond::initObservedValues() 329 { 330 // fill ObservedValues 331 boost::function<void()> subjectKilled = 332 boost::bind(&GLMoleculeObject_bond::countsubjectKilled, this); 333 ObservedValues[leftPosition] = new ObservedValue_wCallback<Vector>( 334 leftowner, 335 boost::bind(&GLMoleculeObject_bond::updateLeftPosition, this), 336 "BondleftPosition_"+toString(leftatomId), 337 updateLeftPosition(), 338 emit BondRemoved(getleftIndex(), getrightIndex()); 339 } 340 341 void GLMoleculeObject_bond::initObservedValues( 342 std::vector<boost::any> &_ObservedValues, 343 const atomId_t _leftatomId, 344 const atomId_t _rightatomId, 345 const Observable * const _leftowner, 346 const Observable * const _rightowner, 347 const Observable * const _bondowner, 348 const boost::function<void()> &_subjectKilled) 349 { 350 /* This is an old note from when the code was still part of cstor's initializer body. 351 * TODO: Probably does not apply anymore but has not yet been tested. 352 * 353 * We must not use boost::cref(this) as "this" has not been properly constructed and seemingly 354 * boost::cref tries to do some magic to grasp the inheritance hierarchy which fails because 355 * the class has not been fully constructed yet. "This" itself seems to be working fine. 356 */ 357 358 ASSERT( _ObservedValues.size() == MAX_ObservedTypes, 359 "GLMoleculeObject_bond::initObservedValues() - given ObservedValues has not correct size."); 360 361 // fill ObservedValues: index first 362 // Note that we only need one as the function just checks on the last changed id 363 // and ids cannot be changed simultaneously 364 const boost::function<atomId_t ()> AtomIndexUpdater( 365 boost::bind(&GLMoleculeObject_bond::updateIndex)); 366 367 ObservedValue_wCallback<atomId_t> * const LeftIndexObservable = 368 new ObservedValue_wCallback<atomId_t>( 369 _leftowner, 370 AtomIndexUpdater, 371 "Bonds_LeftAtomIndex_"+toString(_leftatomId), 372 _leftatomId, 373 IndexChannels, 374 _subjectKilled); 375 _ObservedValues[leftIndex] = LeftIndexObservable; 376 ObservedValue_wCallback<atomId_t> * const RightIndexObservable = 377 new ObservedValue_wCallback<atomId_t>( 378 _rightowner, 379 AtomIndexUpdater, 380 "Bonds_RightAtomIndex_"+toString(_rightatomId), 381 _rightatomId, 382 IndexChannels, 383 _subjectKilled); 384 _ObservedValues[rightIndex] = RightIndexObservable; 385 386 const boost::function<const atomId_t ()> LeftIndexGetter = 387 boost::bind(&ObservedValue_wCallback<atomId_t>::get, 388 LeftIndexObservable); 389 const boost::function<const atomId_t ()> RightIndexGetter = 390 boost::bind(&ObservedValue_wCallback<atomId_t>::get, 391 RightIndexObservable); 392 393 // fill ObservedValues: then all the other that need index 394 const boost::function<Vector ()> LeftPositionUpdater( 395 boost::bind(&GLMoleculeObject_bond::updateLeftPosition, LeftIndexGetter)); 396 const boost::function<Vector ()> RightPositionUpdater( 397 boost::bind(&GLMoleculeObject_bond::updateRightPosition, RightIndexGetter)); 398 const boost::function<atomicNumber_t ()> LeftElementUpdater( 399 boost::bind(&GLMoleculeObject_bond::updateLeftElement, LeftIndexGetter)); 400 const boost::function<atomicNumber_t ()> RightElementUpdater( 401 boost::bind(&GLMoleculeObject_bond::updateRightElement, RightIndexGetter)); 402 const boost::function<int ()> DegreeUpdater( 403 boost::bind(&GLMoleculeObject_bond::updateDegree, LeftIndexGetter, RightIndexGetter)); 404 405 _ObservedValues[leftPosition] = new ObservedValue_wCallback<Vector>( 406 _leftowner, 407 LeftPositionUpdater, 408 "BondleftPosition_"+toString(_leftatomId), 409 LeftPositionUpdater(), 338 410 BondPositionChannels, 339 subjectKilled);340 ObservedValues[rightPosition] = new ObservedValue_wCallback<Vector>(341 rightowner,342 boost::bind(&GLMoleculeObject_bond::updateRightPosition, this),343 "BondrightPosition_"+toString( rightatomId),344 updateRightPosition(),411 _subjectKilled); 412 _ObservedValues[rightPosition] = new ObservedValue_wCallback<Vector>( 413 _rightowner, 414 RightPositionUpdater, 415 "BondrightPosition_"+toString(_rightatomId), 416 RightPositionUpdater(), 345 417 BondPositionChannels, 346 subjectKilled);347 ObservedValues[leftElement] = new ObservedValue_wCallback<atomicNumber_t>(348 leftowner,349 boost::bind(&GLMoleculeObject_bond::updateLeftElement, this),350 "BondleftElement"+toString( leftatomId),351 updateLeftElement(),418 _subjectKilled); 419 _ObservedValues[leftElement] = new ObservedValue_wCallback<atomicNumber_t>( 420 _leftowner, 421 LeftElementUpdater, 422 "BondleftElement"+toString(_leftatomId), 423 LeftElementUpdater(), 352 424 BondElementChannels, 353 subjectKilled);354 ObservedValues[rightElement] = new ObservedValue_wCallback<atomicNumber_t>(355 rightowner,356 boost::bind(&GLMoleculeObject_bond::updateRightElement, this),357 "BondrightElement"+toString( rightatomId),358 updateRightElement(),425 _subjectKilled); 426 _ObservedValues[rightElement] = new ObservedValue_wCallback<atomicNumber_t>( 427 _rightowner, 428 RightElementUpdater, 429 "BondrightElement"+toString(_rightatomId), 430 RightElementUpdater(), 359 431 BondElementChannels, 360 subjectKilled);361 ObservedValues[Degree] = new ObservedValue_wCallback<int>(362 bondowner,363 boost::bind(&GLMoleculeObject_bond::updateDegree, this),364 "BondDegree"+toString( leftatomId)+"_"+toString(rightatomId),365 updateDegree(),432 _subjectKilled); 433 _ObservedValues[Degree] = new ObservedValue_wCallback<int>( 434 _bondowner, 435 DegreeUpdater, 436 "BondDegree"+toString(_leftatomId)+"_"+toString(_rightatomId), 437 DegreeUpdater(), 366 438 BondDegreeChannels, 367 subjectKilled); 368 } 369 370 void GLMoleculeObject_bond::destroyObservedValues() 371 { 372 delete boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[leftPosition]); 373 delete boost::any_cast<ObservedValue_wCallback<Vector> *>(ObservedValues[rightPosition]); 374 delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[leftElement]); 375 delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(ObservedValues[rightElement]); 376 delete boost::any_cast<ObservedValue_wCallback<int> *>(ObservedValues[Degree]); 377 ObservedValues.clear(); 439 _subjectKilled); 440 } 441 442 void GLMoleculeObject_bond::destroyObservedValues( 443 std::vector<boost::any> &_ObservedValues) 444 { 445 delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[leftIndex]); 446 delete boost::any_cast<ObservedValue_wCallback<atomId_t> *>(_ObservedValues[rightIndex]); 447 delete boost::any_cast<ObservedValue_wCallback<Vector> *>(_ObservedValues[leftPosition]); 448 delete boost::any_cast<ObservedValue_wCallback<Vector> *>(_ObservedValues[rightPosition]); 449 delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(_ObservedValues[leftElement]); 450 delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t> *>(_ObservedValues[rightElement]); 451 delete boost::any_cast<ObservedValue_wCallback<int> *>(_ObservedValues[Degree]); 452 _ObservedValues.clear(); 453 } 454 455 atomId_t GLMoleculeObject_bond::getleftIndex() const 456 { 457 return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[leftIndex])->get(); 458 } 459 460 atomId_t GLMoleculeObject_bond::getrightIndex() const 461 { 462 return boost::any_cast<ObservedValue_wCallback<atomId_t> *>(ObservedValues[rightIndex])->get(); 378 463 } 379 464
Note:
See TracChangeset
for help on using the changeset viewer.