Ignore:
Timestamp:
Apr 20, 2016, 11:06:55 PM (9 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

QtObservedBond now simply gets both QtObservedAtoms on construction.

  • they must exist as QtObservedInstanceBoard is in the current update() loop.
  • and we don't need to take care of them and may throw them away when the bonf itself is removed. We don't need to care for anything else.
Location:
src/UIElements/Qt4/InstanceBoard
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/InstanceBoard/QtObservedBond.cpp

    re4b13a r4112691  
    103103    const bondId_t _id,
    104104    const bond::ptr _bond,
     105    const QtObservedAtom::ptr &_leftatom,
     106    const QtObservedAtom::ptr &_rightatom,
    105107    QtObservedInstanceBoard &_board,
    106108    QWidget * _parent) :
     
    109111  AllsignedOnChannels(initAllsignedOnChannels(_bond)),
    110112  bondowner(NULL),
    111   leftatomowner(NULL),
    112   rightatomowner(NULL),
    113   moleculeowner(NULL),
    114113  oldbondId(_id),
     114  leftatom(_leftatom),
     115  rightatom(_rightatom),
    115116  oldleftatomId(_id.first),
    116117  oldrightatomId(_id.second),
     
    134135          boost::bind(accessor,
    135136              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);
    156138
    157139  // activating Observer is done by ObservedValueContainer when it's inserted
     
    161143{
    162144  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();
    170145
    171146  deactivateObserver();
     
    182157}
    183158
    184 #ifdef HAVE_INLINE
    185 inline
    186 #endif
    187 atomId_t QtObservedBond::updateLeftAtomIndex(const atom &_atom)
    188 {
    189   return _atom.getId();
    190 }
    191 
    192 #ifdef HAVE_INLINE
    193 inline
    194 #endif
    195 atomicNumber_t QtObservedBond::updateLeftAtomElement(const atom &_atom)
    196 {
    197   return _atom.getElementNo();
    198 }
    199 
    200 #ifdef HAVE_INLINE
    201 inline
    202 #endif
    203 Vector QtObservedBond::updateLeftAtomPosition(const atom &_atom)
    204 {
    205   return _atom.getPosition();
    206 }
    207 
    208 #ifdef HAVE_INLINE
    209 inline
    210 #endif
    211 atomId_t QtObservedBond::updateRightAtomIndex(const atom &_atom)
    212 {
    213   return _atom.getId();
    214 }
    215 
    216 #ifdef HAVE_INLINE
    217 inline
    218 #endif
    219 atomicNumber_t QtObservedBond::updateRightAtomElement(const atom &_atom)
    220 {
    221   return _atom.getElementNo();
    222 }
    223 
    224 #ifdef HAVE_INLINE
    225 inline
    226 #endif
    227 Vector QtObservedBond::updateRightAtomPosition(const atom &_atom)
    228 {
    229   return _atom.getPosition();
    230 }
    231 
    232 #ifdef HAVE_INLINE
    233 inline
    234 #endif
    235 moleculeId_t QtObservedBond::updateMoleculeIndex(const molecule &_mol)
    236 {
    237   return _mol.getId();
    238 }
    239 
    240159void QtObservedBond::update(Observable *publisher)
    241160{
     
    265184void QtObservedBond::checkForRemoval(ObservedValue_Index_t _id)
    266185{
    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 
    300186  if (bondowner != NULL) {
    301187    // only bond needs to be destroyed to signal removal
     
    328214{
    329215  // 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) {
    381217    switch (notification->getChannelNo()) {
    382218      case BondObservable::DegreeChanged:
     
    389225        break;
    390226    }
    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     }
    406227  } else
    407228    ASSERT(0,
     
    437258  subjectKilledCount.clear();
    438259
    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));
    453270    }
     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));
    454279  }
    455280
    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
     293void QtObservedBond::leftAtomIndexChanges(atomId_t, atomId_t)
     294{
     295  const atomId_t newid = getLeftAtomIndex();
     296  emit leftAtomIndexChanged(oldleftatomId, newid);
     297  oldleftatomId = newid;
     298}
     299
     300void QtObservedBond::rightAtomIndexChanges(atomId_t, atomId_t)
     301{
     302  const atomId_t newid = getRightAtomIndex();
     303  emit rightAtomIndexChanged(oldrightatomId, newid);
     304  oldrightatomId = newid;
     305}
     306
     307void QtObservedBond::moleculeIndexChanges(moleculeId_t, moleculeId_t)
     308{
     309  const moleculeId_t newid = getMoleculeIndex();
     310  emit moleculeIndexChanged(oldmoleculeId, newid);
     311  oldmoleculeId = newid;
    504312}
    505313
    506314void QtObservedBond::deactivateObserver()
    507315{
    508   // sign Off
    509   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   }
    554316  if (bondowner != NULL) {
    555317    const ObservableCount_t::iterator subjectkilledbonditer =
     
    588350    const bondId_t _id,
    589351    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)
    594353{
    595354  // fill ObservedValues: index first
     
    601360  const boost::function<int ()> BondDegreeUpdater(
    602361      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())));
    617362
    618363  _ObservedValues[BondDegree] = new ObservedValue_wCallback<int, ObservedValue_Index_t>(
     
    623368      BondDegreeChannels,
    624369      _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);
    674370}
    675371
     
    678374{
    679375  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]);
    687376  _ObservedValues.clear();
    688377}
     
    707396const atomId_t& QtObservedBond::getLeftAtomIndex() const
    708397{
    709   return boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(ObservedValues[leftAtomIndex])->get();
     398  return leftatom->getAtomIndex();
    710399}
    711400
    712401const atomicNumber_t& QtObservedBond::getLeftAtomElement() const
    713402{
    714   return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(ObservedValues[leftAtomElement])->get();
     403  return leftatom->getAtomElement();
    715404}
    716405
    717406const Vector& QtObservedBond::getLeftAtomPosition() const
    718407{
    719   return boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[leftAtomPosition])->get();
     408  return leftatom->getAtomPosition();
    720409}
    721410
    722411const atomId_t& QtObservedBond::getRightAtomIndex() const
    723412{
    724   return boost::any_cast<ObservedValue_wCallback<atomId_t, ObservedValue_Index_t> *>(ObservedValues[rightAtomIndex])->get();
     413  return rightatom->getAtomIndex();
    725414}
    726415
    727416const atomicNumber_t& QtObservedBond::getRightAtomElement() const
    728417{
    729   return boost::any_cast<ObservedValue_wCallback<atomicNumber_t, ObservedValue_Index_t> *>(ObservedValues[rightAtomElement])->get();
     418  return rightatom->getAtomElement();
    730419}
    731420
    732421const Vector& QtObservedBond::getRightAtomPosition() const
    733422{
    734   return boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[rightAtomPosition])->get();
     423  return rightatom->getAtomPosition();
    735424}
    736425
    737426const moleculeId_t& QtObservedBond::getMoleculeIndex() const
    738427{
    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  
    2828#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
    2929#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
     30#include "UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp"
    3031#include "types.hpp"
    3132
     
    7172   * \param _id id of observed bond
    7273   * \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, ...
    7376   * \param _board ref to InstanceBoard for callbacks on occasion of subjectKilled()
    7477   * \param _parent Qt parent to automatically destroy when parent is destroyed
     
    7780      const bondId_t _id,
    7881      const bond::ptr _bond,
     82      const QtObservedAtom::ptr &_leftatom,
     83      const QtObservedAtom::ptr &_rightatom,
    7984      QtObservedInstanceBoard &_board,
    8085      QWidget * _parent=0);
     
    176181  void bondRemoved();
    177182
    178 //private slots:
     183private slots:
     184
     185  void leftAtomIndexChanges(atomId_t, atomId_t);
     186  void rightAtomIndexChanges(atomId_t, atomId_t);
     187  void moleculeIndexChanges(moleculeId_t, moleculeId_t);
    179188
    180189private:
     
    187196private:
    188197  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);
    196198
    197199  //!> enumeration of observed values to match with entries in ObservedValues
     
    199201    //!> contains the current bond degree
    200202    BondDegree,
    201     //!> contains the index of the left atom
    202     leftAtomIndex,
    203     //!> contains the position of the left atom
    204     leftAtomPosition,
    205     //!> contains the element of the left atom
    206     leftAtomElement,
    207     //!> contains the index of the right atom
    208     rightAtomIndex,
    209     //!> contains the position of the right atom
    210     rightAtomPosition,
    211     //!> contains the element of the right atom
    212     rightAtomElement,
    213     //!> contains the id of the molecule this bond is associated with
    214     moleculeIndex,
    215203    //!> gives the size of the enumeration
    216204    MAX_ObservedTypes
     
    223211   * \param _bondref reference to bond
    224212   * \param _bondsubjectKilled ref to function to call on subjectKilled() from bond
    225    * \param _leftatomsubjectKilled ref to function to call on subjectKilled() from leftatom
    226    * \param _rightatomsubjectKilled ref to function to call on subjectKilled() from rightatom
    227    * \param _moleculesubjectKilled ref to function to call on subjectKilled() from molecule
    228213   */
    229214  void initObservedValues(
     
    231216      const bondId_t _id,
    232217      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);
    237219
    238220  /** Destroys all \a ObservedValues entries.
     
    278260  //!> the Observable we are signed on, also indicates whether we are sign on (not NULL)
    279261  const Observable *bondowner;
    280   const Observable *leftatomowner;
    281   const Observable *rightatomowner;
    282   const Observable *moleculeowner;
    283262
    284263private:
     
    310289  bondId_t oldbondId;
    311290
    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
    313298  atomId_t oldleftatomId;
    314299
    315   //!> contains still the old id after the index of the right atom changed
     300  //!> contains still the old rightatom id after the index of the bond changed
    316301  atomId_t oldrightatomId;
    317302
    318   //!> contains still the old id after the index of the molecule changed
     303  //!> contains still the old molecule id after the index of the bond changed
    319304  moleculeId_t oldmoleculeId;
    320305
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    re4b13a r4112691  
    252252          const BondList &ListOfBonds = _atom->getListOfBonds();
    253253          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          }
    263275        } else {
    264276          ELOG(1, "QtObservedInstanceBoard got BondsAdded for unknown atom id " << _id);
Note: See TracChangeset for help on using the changeset viewer.