Changeset 4112691 for src/UIElements/Qt4/InstanceBoard
- Timestamp:
- Apr 20, 2016, 11:06:55 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:
- 785d89
- Parents:
- e4b13a
- git-author:
- Frederik Heber <heber@…> (04/06/16 17:04:01)
- git-committer:
- Frederik Heber <heber@…> (04/20/16 23:06:55)
- Location:
- src/UIElements/Qt4/InstanceBoard
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Qt4/InstanceBoard/QtObservedBond.cpp
re4b13a r4112691 103 103 const bondId_t _id, 104 104 const bond::ptr _bond, 105 const QtObservedAtom::ptr &_leftatom, 106 const QtObservedAtom::ptr &_rightatom, 105 107 QtObservedInstanceBoard &_board, 106 108 QWidget * _parent) : … … 109 111 AllsignedOnChannels(initAllsignedOnChannels(_bond)), 110 112 bondowner(NULL), 111 leftatomowner(NULL),112 rightatomowner(NULL),113 moleculeowner(NULL),114 113 oldbondId(_id), 114 leftatom(_leftatom), 115 rightatom(_rightatom), 115 116 oldleftatomId(_id.first), 116 117 oldrightatomId(_id.second), … … 134 135 boost::bind(accessor, 135 136 getObservable(_bond.get())))); 136 const boost::function<void ()> leftatomSubjectKilled( 137 boost::bind(&QtObservedBond::countValuesSubjectKilled, 138 boost::ref(*this), 139 boost::bind(&QtObservedBond::getIndex, boost::cref(*this)), 140 boost::bind(accessor, 141 getObservable(_bond->leftatom)))); 142 const boost::function<void ()> rightatomSubjectKilled( 143 boost::bind(&QtObservedBond::countValuesSubjectKilled, 144 boost::ref(*this), 145 boost::bind(&QtObservedBond::getIndex, boost::cref(*this)), 146 boost::bind(accessor, 147 getObservable(_bond->rightatom)))); 148 const boost::function<void ()> moleculeSubjectKilled( 149 boost::bind(&QtObservedBond::countValuesSubjectKilled, 150 boost::ref(*this), 151 boost::bind(&QtObservedBond::getIndex, boost::cref(*this)), 152 boost::bind(accessor, 153 getObservable(getMolecule(_bond))))); 154 initObservedValues( ObservedValues, _id, _bond, 155 bondSubjectKilled, leftatomSubjectKilled, rightatomSubjectKilled, moleculeSubjectKilled); 137 initObservedValues( ObservedValues, _id, _bond, bondSubjectKilled); 156 138 157 139 // activating Observer is done by ObservedValueContainer when it's inserted … … 161 143 { 162 144 boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(ObservedValues[BondDegree])->noteCallBackIsGone(); 163 boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(ObservedValues[leftAtomIndex])->noteCallBackIsGone();164 boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(ObservedValues[leftAtomElement])->noteCallBackIsGone();165 boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[leftAtomPosition])->noteCallBackIsGone();166 boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(ObservedValues[rightAtomIndex])->noteCallBackIsGone();167 boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(ObservedValues[rightAtomElement])->noteCallBackIsGone();168 boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[rightAtomPosition])->noteCallBackIsGone();169 boost::any_cast<ObservedValue_wCallback<moleculeId_t, ObservedValue_Index_t> *>(ObservedValues[moleculeIndex])->noteCallBackIsGone();170 145 171 146 deactivateObserver(); … … 182 157 } 183 158 184 #ifdef HAVE_INLINE185 inline186 #endif187 atomId_t QtObservedBond::updateLeftAtomIndex(const atom &_atom)188 {189 return _atom.getId();190 }191 192 #ifdef HAVE_INLINE193 inline194 #endif195 atomicNumber_t QtObservedBond::updateLeftAtomElement(const atom &_atom)196 {197 return _atom.getElementNo();198 }199 200 #ifdef HAVE_INLINE201 inline202 #endif203 Vector QtObservedBond::updateLeftAtomPosition(const atom &_atom)204 {205 return _atom.getPosition();206 }207 208 #ifdef HAVE_INLINE209 inline210 #endif211 atomId_t QtObservedBond::updateRightAtomIndex(const atom &_atom)212 {213 return _atom.getId();214 }215 216 #ifdef HAVE_INLINE217 inline218 #endif219 atomicNumber_t QtObservedBond::updateRightAtomElement(const atom &_atom)220 {221 return _atom.getElementNo();222 }223 224 #ifdef HAVE_INLINE225 inline226 #endif227 Vector QtObservedBond::updateRightAtomPosition(const atom &_atom)228 {229 return _atom.getPosition();230 }231 232 #ifdef HAVE_INLINE233 inline234 #endif235 moleculeId_t QtObservedBond::updateMoleculeIndex(const molecule &_mol)236 {237 return _mol.getId();238 }239 240 159 void QtObservedBond::update(Observable *publisher) 241 160 { … … 265 184 void QtObservedBond::checkForRemoval(ObservedValue_Index_t _id) 266 185 { 267 if (leftatomowner != NULL) {268 // left atom gone?269 const ObservableCount_t::const_iterator subjectkilledleftiter =270 subjectKilledCount.find(const_cast<Observable *>(leftatomowner));271 ASSERT( (subjectkilledleftiter != subjectKilledCount.end()),272 "QtObservedBond::checkForRemoval() - leftatomowner not present in subjectKilledCount.");273 if (subjectkilledleftiter->second == 3) {274 leftatomowner = NULL;275 }276 }277 278 if (rightatomowner != NULL) {279 // right atom gone?280 const ObservableCount_t::const_iterator subjectkilledrightiter =281 subjectKilledCount.find(const_cast<Observable *>(rightatomowner));282 ASSERT( (subjectkilledrightiter != subjectKilledCount.end()),283 "QtObservedBond::checkForRemoval() - rightatomowner not present in subjectKilledCount.");284 if (subjectkilledrightiter->second == 3) {285 rightatomowner = NULL;286 }287 }288 289 if (moleculeowner != NULL) {290 // molecule gone?291 const ObservableCount_t::const_iterator subjectkilledmoliter =292 subjectKilledCount.find(const_cast<Observable *>(moleculeowner));293 ASSERT( (subjectkilledmoliter != subjectKilledCount.end()),294 "QtObservedBond::checkForRemoval() - moleculeowner not present in subjectKilledCount.");295 if (subjectkilledmoliter->second == 3) {296 moleculeowner = NULL;297 }298 }299 300 186 if (bondowner != NULL) { 301 187 // only bond needs to be destroyed to signal removal … … 328 214 { 329 215 // ObservedValues have been updated before, hence convert updates to Qt's signals 330 if (publisher == leftatomowner) { 331 switch (notification->getChannelNo()) { 332 case AtomObservable::IndexChanged: 333 { 334 const atomId_t newId = getLeftAtomIndex(); 335 emit leftAtomIndexChanged(oldleftatomId, newId); 336 oldleftatomId = newId; 337 break; 338 } 339 case AtomObservable::ElementChanged: 340 { 341 emit leftAtomElementChanged(); 342 break; 343 } 344 case AtomObservable::PositionChanged: 345 { 346 emit leftAtomPositionChanged(); 347 break; 348 } 349 default: 350 ASSERT(0, "QtObservedBond::recieveNotification() - we are not signed on to channel " 351 +toString(notification->getChannelNo())+" of the left atom " 352 +toString(getLeftAtomIndex())+"."); 353 break; 354 } 355 } else if (publisher == rightatomowner) { 356 switch (notification->getChannelNo()) { 357 case AtomObservable::IndexChanged: 358 { 359 const atomId_t newId = getRightAtomIndex(); 360 emit rightAtomIndexChanged(oldrightatomId, newId); 361 oldrightatomId = newId; 362 break; 363 } 364 case AtomObservable::ElementChanged: 365 { 366 emit rightAtomElementChanged(); 367 break; 368 } 369 case AtomObservable::PositionChanged: 370 { 371 emit rightAtomPositionChanged(); 372 break; 373 } 374 default: 375 ASSERT(0, "QtObservedBond::recieveNotification() - we are not signed on to channel " 376 +toString(notification->getChannelNo())+" of the right atom " 377 +toString(getRightAtomIndex())+"."); 378 break; 379 } 380 } else if (publisher == bondowner) { 216 if (publisher == bondowner) { 381 217 switch (notification->getChannelNo()) { 382 218 case BondObservable::DegreeChanged: … … 389 225 break; 390 226 } 391 } else if (publisher == moleculeowner) {392 switch (notification->getChannelNo()) {393 case molecule::IndexChanged:394 {395 const moleculeId_t newId = getMoleculeIndex();396 emit moleculeIndexChanged(oldmoleculeId, newId);397 oldmoleculeId = newId;398 break;399 }400 default:401 ASSERT(0, "QtObservedBond::recieveNotification() - we are not signed on to channel "402 +toString(notification->getChannelNo())+" of the molecule #"403 +toString(getMoleculeIndex())+".");404 break;405 }406 227 } else 407 228 ASSERT(0, … … 437 258 subjectKilledCount.clear(); 438 259 439 const atom * rightatom = getAtom(getRightAtomIndex()); 440 { 441 const Observable::channels_t channels = getAllObservedAtomChannels(); 442 if (rightatom != NULL) { 443 rightatomowner = static_cast<const Observable *>(rightatom); 444 for (Observable::channels_t::const_iterator iter = channels.begin(); 445 iter != channels.end(); ++iter) 446 rightatomowner->signOn(this, *iter); 447 subjectKilledCount.insert( std::make_pair(const_cast<Observable * const>(rightatomowner), 0)); 448 signedOffChannels.insert( std::make_pair(const_cast<Observable * const>(rightatomowner), 0)); 449 } else { 450 subjectKilledCount.insert( std::make_pair(const_cast<Observable * const>(rightatomowner), channels.size())); 451 assignObservableCountValue(signedOffChannels, rightatomowner, 452 getObservableCountValue(AllsignedOnChannels, rightatomowner)); 260 atom * leftatomref = getAtom(getLeftAtomIndex()); 261 atom * rightatomref = getAtom(getRightAtomIndex()); 262 bond::ptr bondref = leftatomref->getBond(rightatomref); 263 if (bondref != NULL) { 264 // bond 265 { 266 bondowner = static_cast<const Observable *>(bondref.get()); 267 bondowner->signOn(this, BondObservable::DegreeChanged); 268 subjectKilledCount.insert( std::make_pair(const_cast<Observable * const>(bondowner), 0)); 269 signedOffChannels.insert( std::make_pair(const_cast<Observable * const>(bondowner), 0)); 453 270 } 271 272 // and mark as connected 273 if (!BoardIsGone) 274 board.markObservedBondAsConnected(getIndex()); 275 } else { 276 subjectKilledCount.insert( std::make_pair(const_cast<Observable * const>(bondowner), 1)); 277 assignObservableCountValue(signedOffChannels, bondowner, 278 getObservableCountValue(AllsignedOnChannels, bondowner)); 454 279 } 455 280 456 { 457 const atom * leftatom = getAtom(getLeftAtomIndex()); 458 const Observable::channels_t channels = getAllObservedAtomChannels(); 459 if (leftatom != NULL) { 460 leftatomowner = static_cast<const Observable *>(leftatom); 461 for (Observable::channels_t::const_iterator iter = channels.begin(); 462 iter != channels.end(); ++iter) 463 leftatomowner->signOn(this, *iter); 464 subjectKilledCount.insert( std::make_pair(const_cast<Observable * const>(leftatomowner), 0)); 465 signedOffChannels.insert( std::make_pair(const_cast<Observable * const>(leftatomowner), 0)); 466 467 bond::ptr bondref = leftatom->getBond(rightatom); 468 if (bondref != NULL) { 469 // bond 470 { 471 bondowner = static_cast<const Observable *>(bondref.get()); 472 bondowner->signOn(this, BondObservable::DegreeChanged); 473 subjectKilledCount.insert( std::make_pair(const_cast<Observable * const>(bondowner), 0)); 474 signedOffChannels.insert( std::make_pair(const_cast<Observable * const>(bondowner), 0)); 475 } 476 477 const molecule * mol = leftatom->getMolecule(); 478 if (mol != NULL) { 479 // molecule 480 moleculeowner = static_cast<const Observable *>(mol); 481 moleculeowner->signOn(this, molecule::IndexChanged); 482 subjectKilledCount.insert( std::make_pair(const_cast<Observable * const>(moleculeowner), 0)); 483 signedOffChannels.insert( std::make_pair(const_cast<Observable * const>(moleculeowner), 0)); 484 } else { 485 subjectKilledCount.insert( std::make_pair(const_cast<Observable * const>(moleculeowner), 1)); 486 assignObservableCountValue(signedOffChannels, moleculeowner, 487 getObservableCountValue(AllsignedOnChannels, moleculeowner)); 488 } 489 490 // and mark as connected 491 if (!BoardIsGone) 492 board.markObservedBondAsConnected(getIndex()); 493 } else { 494 subjectKilledCount.insert( std::make_pair(const_cast<Observable * const>(bondowner), 1)); 495 assignObservableCountValue(signedOffChannels, bondowner, 496 getObservableCountValue(AllsignedOnChannels, bondowner)); 497 } 498 } else { 499 subjectKilledCount.insert( std::make_pair(const_cast<Observable * const>(leftatomowner), channels.size())); 500 assignObservableCountValue(signedOffChannels, leftatomowner, 501 getObservableCountValue(AllsignedOnChannels, leftatomowner)); 502 } 503 } 281 // pass thru to signals from both atoms 282 connect( leftatom.get(), SIGNAL(indexChanged(const atomId_t, const atomId_t)), 283 this, SLOT(leftAtomIndexChanges(atomId_t, atomId_t))); 284 connect( leftatom.get(), SIGNAL(elementChanged()), this, SIGNAL(leftAtomElementChanged())); 285 connect( leftatom.get(), SIGNAL(positionChanged()), this, SIGNAL(leftAtomPositionChanged())); 286 connect( leftatom.get(), SIGNAL(moleculeChanged()), this, SLOT(moleculeIndexChanges(moleculeId_t, moleculeId_t))); 287 connect( rightatom.get(), SIGNAL(indexChanged(const atomId_t, const atomId_t)), 288 this, SLOT(rightAtomIndexChanges(atomId_t, atomId_t))); 289 connect( rightatom.get(), SIGNAL(elementChanged()), this, SIGNAL(rightAtomElementChanged())); 290 connect( rightatom.get(), SIGNAL(positionChanged()), this, SIGNAL(rightAtomPositionChanged())); 291 } 292 293 void QtObservedBond::leftAtomIndexChanges(atomId_t, atomId_t) 294 { 295 const atomId_t newid = getLeftAtomIndex(); 296 emit leftAtomIndexChanged(oldleftatomId, newid); 297 oldleftatomId = newid; 298 } 299 300 void QtObservedBond::rightAtomIndexChanges(atomId_t, atomId_t) 301 { 302 const atomId_t newid = getRightAtomIndex(); 303 emit rightAtomIndexChanged(oldrightatomId, newid); 304 oldrightatomId = newid; 305 } 306 307 void QtObservedBond::moleculeIndexChanges(moleculeId_t, moleculeId_t) 308 { 309 const moleculeId_t newid = getMoleculeIndex(); 310 emit moleculeIndexChanged(oldmoleculeId, newid); 311 oldmoleculeId = newid; 504 312 } 505 313 506 314 void QtObservedBond::deactivateObserver() 507 315 { 508 // sign Off509 if (leftatomowner != NULL) {510 const ObservableCount_t::iterator subjectkilledleftiter =511 subjectKilledCount.find(const_cast<Observable *>(leftatomowner));512 ASSERT( (subjectkilledleftiter != subjectKilledCount.end()),513 "QtObservedBond::deactivateObserver() - no entry in subjectKilledCount for left atom "514 +toString(leftatomowner)+", has activateObserver() been called?");515 ASSERT( (subjectkilledleftiter->second == 3) || (subjectkilledleftiter->second == 0),516 "QtObservedBond::deactivateObserver() - cannot deal with partially signed off left atom.");517 if (subjectkilledleftiter->second == 0) {518 Observable::channels_t channels = getAllObservedAtomChannels();519 for (Observable::channels_t::const_iterator iter = channels.begin();520 iter != channels.end(); ++iter)521 leftatomowner->signOff(this, *iter);522 subjectkilledleftiter->second = 3;523 }524 leftatomowner = NULL;525 }526 if (rightatomowner != NULL) {527 const ObservableCount_t::iterator subjectkilledrightiter =528 subjectKilledCount.find(const_cast<Observable *>(rightatomowner));529 ASSERT( (subjectkilledrightiter != subjectKilledCount.end()),530 "QtObservedBond::deactivateObserver() - no entry in subjectKilledCount for right atom"531 +toString(rightatomowner)+", has activateObserver() been called?");532 ASSERT( (subjectkilledrightiter->second == 3) || (subjectkilledrightiter->second == 0),533 "QtObservedBond::deactivateObserver() - cannot deal with partially signed off right atom .");534 if (subjectkilledrightiter->second == 0) {535 Observable::channels_t channels = getAllObservedAtomChannels();536 for (Observable::channels_t::const_iterator iter = channels.begin();537 iter != channels.end(); ++iter)538 rightatomowner->signOff(this, *iter);539 subjectkilledrightiter->second = 3;540 }541 rightatomowner = NULL;542 }543 if (moleculeowner != NULL) {544 const ObservableCount_t::iterator subjectkilledmoliter =545 subjectKilledCount.find(const_cast<Observable *>(moleculeowner));546 ASSERT( (subjectkilledmoliter != subjectKilledCount.end()),547 "QtObservedBond::deactivateObserver() - no entry in subjectKilledCount for molecule"548 +toString(moleculeowner)+", has activateObserver() been called?");549 if (subjectkilledmoliter->second == 0)550 moleculeowner->signOff(this, molecule::IndexChanged);551 subjectkilledmoliter->second = 1;552 moleculeowner = NULL;553 }554 316 if (bondowner != NULL) { 555 317 const ObservableCount_t::iterator subjectkilledbonditer = … … 588 350 const bondId_t _id, 589 351 const bond::ptr _bondref, 590 const boost::function<void()> &_bondsubjectKilled, 591 const boost::function<void()> &_leftatomsubjectKilled, 592 const boost::function<void()> &_rightatomsubjectKilled, 593 const boost::function<void()> &_moleculesubjectKilled) 352 const boost::function<void()> &_bondsubjectKilled) 594 353 { 595 354 // fill ObservedValues: index first … … 601 360 const boost::function<int ()> BondDegreeUpdater( 602 361 boost::bind(&QtObservedBond::updateDegree, boost::cref(*_bondref))); 603 const boost::function<atomId_t ()> leftAtomIndexUpdater(604 boost::bind(&QtObservedBond::updateLeftAtomIndex, boost::cref(*_bondref->leftatom)));605 const boost::function<atomicNumber_t ()> leftAtomElementUpdater(606 boost::bind(&QtObservedBond::updateLeftAtomElement, boost::cref(*_bondref->leftatom)));607 const boost::function<Vector ()> leftAtomPositionUpdater(608 boost::bind(&QtObservedBond::updateLeftAtomPosition, boost::cref(*_bondref->leftatom)));609 const boost::function<atomId_t ()> rightAtomIndexUpdater(610 boost::bind(&QtObservedBond::updateRightAtomIndex, boost::cref(*_bondref->rightatom)));611 const boost::function<atomicNumber_t ()> rightAtomElementUpdater(612 boost::bind(&QtObservedBond::updateRightAtomElement, boost::cref(*_bondref->rightatom)));613 const boost::function<Vector ()> rightAtomPositionUpdater(614 boost::bind(&QtObservedBond::updateRightAtomPosition, boost::cref(*_bondref->rightatom)));615 const boost::function<moleculeId_t ()> MoleculeIndexUpdater(616 boost::bind(&QtObservedBond::updateMoleculeIndex, boost::cref(*_bondref->leftatom->getMolecule())));617 362 618 363 _ObservedValues[BondDegree] = new ObservedValue_wCallback<int, ObservedValue_Index_t>( … … 623 368 BondDegreeChannels, 624 369 _bondsubjectKilled); 625 _ObservedValues[leftAtomIndex] = new ObservedValue_wCallback<atomId_t, ObservedValue_Index_t>(626 _bondref->leftatom,627 leftAtomIndexUpdater,628 "LeftAtomIndex_bond"+toString(_id),629 leftAtomIndexUpdater(),630 Observable::channels_t(1, AtomObservable::IndexChanged),631 _leftatomsubjectKilled);632 _ObservedValues[leftAtomElement] = new ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t>(633 _bondref->leftatom,634 leftAtomElementUpdater,635 "LeftAtomElement_bond"+toString(_id),636 leftAtomElementUpdater(),637 Observable::channels_t(1, AtomObservable::ElementChanged),638 _leftatomsubjectKilled);639 _ObservedValues[leftAtomPosition] = new ObservedValue_wCallback<Vector, ObservedValue_Index_t>(640 _bondref->leftatom,641 leftAtomPositionUpdater,642 "LeftAtomPosition_bond"+toString(_id),643 leftAtomPositionUpdater(),644 Observable::channels_t(1, AtomObservable::PositionChanged),645 _leftatomsubjectKilled);646 _ObservedValues[rightAtomIndex] = new ObservedValue_wCallback<atomId_t, ObservedValue_Index_t>(647 _bondref->rightatom,648 rightAtomIndexUpdater,649 "RightAtomIndex_bond"+toString(_id),650 rightAtomIndexUpdater(),651 Observable::channels_t(1, AtomObservable::IndexChanged),652 _rightatomsubjectKilled);653 _ObservedValues[rightAtomElement] = new ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t>(654 _bondref->rightatom,655 rightAtomElementUpdater,656 "RightAtomElement_bond"+toString(_id),657 rightAtomElementUpdater(),658 Observable::channels_t(1, AtomObservable::ElementChanged),659 _rightatomsubjectKilled);660 _ObservedValues[rightAtomPosition] = new ObservedValue_wCallback<Vector, ObservedValue_Index_t>(661 _bondref->rightatom,662 rightAtomPositionUpdater,663 "RightAtomPosition_bond"+toString(_id),664 rightAtomPositionUpdater(),665 Observable::channels_t(1, AtomObservable::PositionChanged),666 _rightatomsubjectKilled);667 _ObservedValues[moleculeIndex] = new ObservedValue_wCallback<moleculeId_t, ObservedValue_Index_t>(668 _bondref->leftatom->getMolecule(),669 MoleculeIndexUpdater,670 "MoleculeIndex_bond"+toString(_id),671 MoleculeIndexUpdater(),672 Observable::channels_t(1, AtomObservable::PositionChanged),673 _moleculesubjectKilled);674 370 } 675 371 … … 678 374 { 679 375 delete boost::any_cast<ObservedValue_wCallback<int, ObservedValue_Index_t> *>(_ObservedValues[BondDegree]); 680 delete boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(_ObservedValues[leftAtomIndex]);681 delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(_ObservedValues[leftAtomElement]);682 delete boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(_ObservedValues[leftAtomPosition]);683 delete boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(_ObservedValues[rightAtomIndex]);684 delete boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(_ObservedValues[rightAtomElement]);685 delete boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(_ObservedValues[rightAtomPosition]);686 delete boost::any_cast<ObservedValue_wCallback<moleculeId_t, ObservedValue_Index_t> *>(_ObservedValues[moleculeIndex]);687 376 _ObservedValues.clear(); 688 377 } … … 707 396 const atomId_t& QtObservedBond::getLeftAtomIndex() const 708 397 { 709 return boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(ObservedValues[leftAtomIndex])->get();398 return leftatom->getAtomIndex(); 710 399 } 711 400 712 401 const atomicNumber_t& QtObservedBond::getLeftAtomElement() const 713 402 { 714 return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(ObservedValues[leftAtomElement])->get();403 return leftatom->getAtomElement(); 715 404 } 716 405 717 406 const Vector& QtObservedBond::getLeftAtomPosition() const 718 407 { 719 return boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[leftAtomPosition])->get();408 return leftatom->getAtomPosition(); 720 409 } 721 410 722 411 const atomId_t& QtObservedBond::getRightAtomIndex() const 723 412 { 724 return boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(ObservedValues[rightAtomIndex])->get();413 return rightatom->getAtomIndex(); 725 414 } 726 415 727 416 const atomicNumber_t& QtObservedBond::getRightAtomElement() const 728 417 { 729 return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(ObservedValues[rightAtomElement])->get();418 return rightatom->getAtomElement(); 730 419 } 731 420 732 421 const Vector& QtObservedBond::getRightAtomPosition() const 733 422 { 734 return boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[rightAtomPosition])->get();423 return rightatom->getAtomPosition(); 735 424 } 736 425 737 426 const moleculeId_t& QtObservedBond::getMoleculeIndex() const 738 427 { 739 return boost::any_cast<ObservedValue_wCallback<moleculeId_t, ObservedValue_Index_t> *>(ObservedValues[moleculeIndex])->get(); 740 } 428 const QtObservedMolecule * leftmol = leftatom->getAtomMolecule(); 429 const QtObservedMolecule * rightmol = rightatom->getAtomMolecule(); 430 ASSERT( leftmol == rightmol, 431 "QtObservedBond::getMoleculeIndex() - left and right atom belong to different molecules, " 432 +toString(leftmol)+" vs. "+toString(rightmol)); 433 return leftmol->getMolIndex(); 434 } -
src/UIElements/Qt4/InstanceBoard/QtObservedBond.hpp
re4b13a r4112691 28 28 #include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp" 29 29 #include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp" 30 #include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp" 30 31 #include "types.hpp" 31 32 … … 71 72 * \param _id id of observed bond 72 73 * \param _bond ref to observed bond 74 * \param _leftatom bond's observed left atom for position, element, ... 75 * \param _rightatom bond's observed right atom for position, element, ... 73 76 * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled() 74 77 * \param _parent Qt parent to automatically destroy when parent is destroyed … … 77 80 const bondId_t _id, 78 81 const bond::ptr _bond, 82 const QtObservedAtom::ptr &_leftatom, 83 const QtObservedAtom::ptr &_rightatom, 79 84 QtObservedInstanceBoard &_board, 80 85 QWidget * _parent=0); … … 176 181 void bondRemoved(); 177 182 178 //private slots: 183 private slots: 184 185 void leftAtomIndexChanges(atomId_t, atomId_t); 186 void rightAtomIndexChanges(atomId_t, atomId_t); 187 void moleculeIndexChanges(moleculeId_t, moleculeId_t); 179 188 180 189 private: … … 187 196 private: 188 197 static int updateDegree(const bond &_bond); 189 static atomId_t updateLeftAtomIndex(const atom &_atomref);190 static atomicNumber_t updateLeftAtomElement(const atom &_atomref);191 static Vector updateLeftAtomPosition(const atom &_atomref);192 static atomId_t updateRightAtomIndex(const atom &_atomref);193 static atomicNumber_t updateRightAtomElement(const atom &_atomref);194 static Vector updateRightAtomPosition(const atom &_atomref);195 static moleculeId_t updateMoleculeIndex(const molecule &_molref);196 198 197 199 //!> enumeration of observed values to match with entries in ObservedValues … … 199 201 //!> contains the current bond degree 200 202 BondDegree, 201 //!> contains the index of the left atom202 leftAtomIndex,203 //!> contains the position of the left atom204 leftAtomPosition,205 //!> contains the element of the left atom206 leftAtomElement,207 //!> contains the index of the right atom208 rightAtomIndex,209 //!> contains the position of the right atom210 rightAtomPosition,211 //!> contains the element of the right atom212 rightAtomElement,213 //!> contains the id of the molecule this bond is associated with214 moleculeIndex,215 203 //!> gives the size of the enumeration 216 204 MAX_ObservedTypes … … 223 211 * \param _bondref reference to bond 224 212 * \param _bondsubjectKilled ref to function to call on subjectKilled() from bond 225 * \param _leftatomsubjectKilled ref to function to call on subjectKilled() from leftatom226 * \param _rightatomsubjectKilled ref to function to call on subjectKilled() from rightatom227 * \param _moleculesubjectKilled ref to function to call on subjectKilled() from molecule228 213 */ 229 214 void initObservedValues( … … 231 216 const bondId_t _id, 232 217 const bond::ptr _bondref, 233 const boost::function<void()> &_bondsubjectKilled, 234 const boost::function<void()> &_leftatomsubjectKilled, 235 const boost::function<void()> &_rightatomsubjectKilled, 236 const boost::function<void()> &_moleculesubjectKilled); 218 const boost::function<void()> &_bondsubjectKilled); 237 219 238 220 /** Destroys all \a ObservedValues entries. … … 278 260 //!> the Observable we are signed on, also indicates whether we are sign on (not NULL) 279 261 const Observable *bondowner; 280 const Observable *leftatomowner;281 const Observable *rightatomowner;282 const Observable *moleculeowner;283 262 284 263 private: … … 310 289 bondId_t oldbondId; 311 290 312 //!> contains still the old id after the index of the left atom changed 291 //!> observed left atom of bond for position, element, ... 292 const QtObservedAtom::ptr leftatom; 293 294 //!> observed right atom of bond for position, element, ... 295 const QtObservedAtom::ptr rightatom; 296 297 //!> contains still the old leftatom id after the index of the bond changed 313 298 atomId_t oldleftatomId; 314 299 315 //!> contains still the old id after the index of the right atomchanged300 //!> contains still the old rightatom id after the index of the bond changed 316 301 atomId_t oldrightatomId; 317 302 318 //!> contains still the old id after the index of the moleculechanged303 //!> contains still the old molecule id after the index of the bond changed 319 304 moleculeId_t oldmoleculeId; 320 305 -
src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp
re4b13a r4112691 252 252 const BondList &ListOfBonds = _atom->getListOfBonds(); 253 253 const bond::ptr bondref = ListOfBonds.back(); 254 const bondId_t bondid = 255 std::make_pair( bondref->leftatom->getId(), bondref->rightatom->getId()); 256 LOG(3, "DEBUG: InformationBoard initializes QtObservedBond for " << bondid); 257 QtObservedBond::ptr observedbond( 258 new QtObservedBond(bondid, bondref, *this)); 259 const ObservedValue_Index_t index = observedbond->getIndex(); 260 bondObservedValues.insert(index, observedbond); 261 bondids_lookup.left.insert( std::make_pair(bondid, index) ); 262 emit bondInserted(observedbond); 254 255 // check whether bond is already present, cause we get BondsAdded from both atoms 256 const ObservedValue_Index_t index = static_cast<const Observable *>(bondref.get()); 257 if (!bondObservedValues.isPresent(index)) { 258 const QtObservedAtom::ptr leftatom = getObservedAtom( 259 static_cast<const Observable *>(bondref->leftatom)); 260 ASSERT( leftatom, 261 "QtObservedInstanceBoard::recieveNotification() - QtObservedAtom leftatom to bond must exist."); 262 const QtObservedAtom::ptr rightatom = getObservedAtom( 263 static_cast<const Observable *>(bondref->rightatom)); 264 ASSERT( rightatom, 265 "QtObservedInstanceBoard::recieveNotification() - QtObservedAtom leftatom to bond must exist."); 266 const bondId_t bondid = 267 std::make_pair( bondref->leftatom->getId(), bondref->rightatom->getId()); 268 LOG(3, "DEBUG: InformationBoard initializes QtObservedBond for " << bondid); 269 QtObservedBond::ptr observedbond( 270 new QtObservedBond(bondid, bondref, leftatom, rightatom, *this)); 271 bondObservedValues.insert(index, observedbond); 272 bondids_lookup.left.insert( std::make_pair(bondid, index) ); 273 emit bondInserted(observedbond); 274 } 263 275 } else { 264 276 ELOG(1, "QtObservedInstanceBoard got BondsAdded for unknown atom id " << _id);
Note:
See TracChangeset
for help on using the changeset viewer.