From 3488422aacac00a18e74386e9a2438f3fb4e849e Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@stud.unibas.ch>
Date: Thu, 30 May 2013 23:46:38 +0200
Subject: [PATCH] fixed bug with possible naming conflicts

When a chain has been inserted in an entity with a ChainHandle as
argument, the name of the given ChainHandle has been used.
The chain then got subsequently renamed to the given name.
This can cause problems, if a chain with the same name as the
input ChanHandle is already present.
---
 modules/mol/base/src/editor_base.cc      | 3 +--
 modules/mol/base/src/impl/entity_impl.cc | 6 +++---
 modules/mol/base/src/impl/entity_impl.hh | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/modules/mol/base/src/editor_base.cc b/modules/mol/base/src/editor_base.cc
index b6cc4ab45..76e41f216 100644
--- a/modules/mol/base/src/editor_base.cc
+++ b/modules/mol/base/src/editor_base.cc
@@ -42,8 +42,7 @@ ChainHandle EditorBase::InsertChain(const String& chain_name)
 
 ChainHandle EditorBase::InsertChain(const String& chain_name, ChainHandle chain, bool deep)
 {
-  impl::ChainImplPtr inserted_chain=ent_.Impl()->InsertChain(chain.Impl(), deep);
-  inserted_chain->SetName(chain_name);
+  impl::ChainImplPtr inserted_chain=ent_.Impl()->InsertChain(chain_name, chain.Impl(), deep);
   return inserted_chain;
 }
 
diff --git a/modules/mol/base/src/impl/entity_impl.cc b/modules/mol/base/src/impl/entity_impl.cc
index 865ef7172..937a63213 100644
--- a/modules/mol/base/src/impl/entity_impl.cc
+++ b/modules/mol/base/src/impl/entity_impl.cc
@@ -126,9 +126,9 @@ EntityImplPtr EntityImpl::Copy()
   return ent_p;
 }
 
-ChainImplPtr EntityImpl::InsertChain(const ChainImplPtr& chain, bool deep)
+ChainImplPtr EntityImpl::InsertChain(const String& chain_name, const ChainImplPtr& chain, bool deep)
 {
-  ChainImplPtr dst_chain=this->InsertChain(chain->GetName());
+  ChainImplPtr dst_chain=this->InsertChain(chain_name);
   dst_chain->Assign(*chain.get());
   if(deep)
   {
@@ -147,7 +147,7 @@ void EntityImpl::ReplicateHierarchy(EntityImplPtr dest)
   for (ChainImplList::const_iterator i=chain_list_.begin(), 
        e1=chain_list_.end(); i!=e1; ++i) {
     ChainImplPtr src_chain=*i;
-    dest->InsertChain(src_chain,true);
+    dest->InsertChain(src_chain->GetName(),src_chain,true);
   }
 }
 
diff --git a/modules/mol/base/src/impl/entity_impl.hh b/modules/mol/base/src/impl/entity_impl.hh
index 6862e5e27..5033bd55e 100644
--- a/modules/mol/base/src/impl/entity_impl.hh
+++ b/modules/mol/base/src/impl/entity_impl.hh
@@ -111,7 +111,7 @@ public:
   /// The chain will have no residues and atoms
   // force deep to be set explicitely, because it is better than implicit
   // (and since we are on the impl level interface consistency isn't that critical)
-  ChainImplPtr InsertChain(const ChainImplPtr& chain, bool deep);
+  ChainImplPtr InsertChain(const String& chain_name, const ChainImplPtr& chain, bool deep);
   ConnectorImplP Connect(const AtomImplPtr& first, const AtomImplPtr& second,
                          Real len, Real theta, Real phi,
                          unsigned char bond_order);
-- 
GitLab