From 284dafe5bcb81d9b3d0c72b8cc41682b6c3b6d75 Mon Sep 17 00:00:00 2001 From: stefan <stefan@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Mon, 3 May 2010 10:53:14 +0000 Subject: [PATCH] mol::ResidueView index problem fix git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2167 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/mol/base/src/chain_view.cc | 6 +++++- modules/mol/base/src/residue_view.cc | 18 ++++++++++++------ modules/mol/base/src/residue_view.hh | 9 +++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/modules/mol/base/src/chain_view.cc b/modules/mol/base/src/chain_view.cc index 87fd21870..bb6562c9c 100644 --- a/modules/mol/base/src/chain_view.cc +++ b/modules/mol/base/src/chain_view.cc @@ -221,11 +221,15 @@ void ChainView::RemoveResidue(ResidueView view) { if (!view.IsValid()) return; view.RemoveAtoms(); + int index = view.GetIndex(); ResidueViewList::iterator i=data_->residues.begin(); for (; i!=data_->residues.end(); ++i) { + int res_index = (*i).GetIndex(); if (*i==view) { data_->residues.erase(i); - return; + } + else if(index < res_index){ + (*i).SetIndex(res_index-1); } } } diff --git a/modules/mol/base/src/residue_view.cc b/modules/mol/base/src/residue_view.cc index e97665244..b9cc9b8b7 100644 --- a/modules/mol/base/src/residue_view.cc +++ b/modules/mol/base/src/residue_view.cc @@ -37,17 +37,17 @@ namespace ost { namespace mol { class DLLEXPORT_OST_MOL ResidueViewData { public: - ResidueViewData(); - ResidueViewData(const ChainViewDataPtr& chain_data) - : chain(chain_data) { - } + ResidueViewData(int residue_index): index(residue_index){} + ResidueViewData(const ChainViewDataPtr& chain_data, int residue_index) + : chain(chain_data), index(residue_index) { } ChainViewDataWeakPtr chain; AtomViewList atoms; + int index; }; ResidueView::ResidueView(const ChainView& chain, const ResidueHandle& residue) - : ResidueBase(residue.Impl()), data_(new ResidueViewData(chain.ViewData())) { + : ResidueBase(residue.Impl()), data_(new ResidueViewData(chain.ViewData(), chain.GetResidueCount())) { } ResidueView::ResidueView(const ResidueViewDataPtr& data, @@ -185,7 +185,13 @@ bool ResidueView::operator!=(const ResidueView& rhs) const int ResidueView::GetIndex() const { this->CheckValidity(); - return this->GetChain().GetResidueIndex(this->GetNumber()); + return data_->index; +} + +void ResidueView::SetIndex(int index) +{ + this->CheckValidity(); + data_->index = index; } double ResidueView::GetMass() const diff --git a/modules/mol/base/src/residue_view.hh b/modules/mol/base/src/residue_view.hh index 4ed53d0b1..0cd381e86 100644 --- a/modules/mol/base/src/residue_view.hh +++ b/modules/mol/base/src/residue_view.hh @@ -37,6 +37,9 @@ namespace ost { namespace mol { /// affect the view and do not alter the structure and topology of the underlying /// \ref ResidueHandle "residue". class DLLEXPORT_OST_MOL ResidueView : public ResidueBase { + + friend class ChainView; + public: /// \brief Create invalid ResidueView ResidueView(); @@ -170,6 +173,12 @@ public: bool operator==(const ResidueView& rhs) const; bool operator!=(const ResidueView& rhs) const; + +protected: + /// \brief set the index of residiue view in chain + /// should be called from chainview whenever indexes change + void SetIndex(int index); + private: ResidueViewDataPtr data_; }; -- GitLab