From 4bbce4930648ee2e5b748a5c5a904cadbdc8d1da Mon Sep 17 00:00:00 2001
From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Thu, 4 Mar 2010 18:50:17 +0000
Subject: [PATCH] add handle parameter to CreateEntityFromView

If the handle is valid, the atoms, residues, chains, bonds an torsions
are added to the handle instead of creating a new one. Useful to merge two entity handles into one.

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1765 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/mol/base/pymod/export_entity_view.cc |  3 ++-
 modules/mol/base/src/view_op.cc              | 13 ++++++++-----
 modules/mol/base/src/view_op.hh              | 10 +++++++---
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/modules/mol/base/pymod/export_entity_view.cc b/modules/mol/base/pymod/export_entity_view.cc
index 8d40e6261..765c33f57 100644
--- a/modules/mol/base/pymod/export_entity_view.cc
+++ b/modules/mol/base/pymod/export_entity_view.cc
@@ -157,7 +157,8 @@ void export_EntityView()
   def("CreateViewFromAtoms", create_view_1);
   def("CreateViewFromAtoms", create_view_2);
   
-  def("CreateEntityFromView", &CreateEntityFromView);
+  def("CreateEntityFromView", &CreateEntityFromView, 
+      arg("handle")=EntityHandle());
   class_<EntityViewList>("EntityViewList", init<>())
     .def(vector_indexing_suite<EntityViewList>())
   ;
diff --git a/modules/mol/base/src/view_op.cc b/modules/mol/base/src/view_op.cc
index 2999c1274..88e964d92 100644
--- a/modules/mol/base/src/view_op.cc
+++ b/modules/mol/base/src/view_op.cc
@@ -389,13 +389,16 @@ private:
 }
 
 EntityHandle CreateEntityFromView(const EntityView& view,
-                                  bool include_exlusive_atoms)
+                                  bool include_exlusive_atoms,
+                                  EntityHandle handle)
 {
   Profile create_time("mol::CreateEntityFromView");
-  EntityHandle ent=CreateEntity();
-  Replicator replicator(ent.Impl(), view, include_exlusive_atoms);
-  TorsionAdder adder(replicator, ent.Impl(), view);
-  return ent;
+  if (!handle.IsValid()) {
+    handle=CreateEntity();
+  }
+  Replicator replicator(handle.Impl(), view, include_exlusive_atoms);
+  TorsionAdder adder(replicator, handle.Impl(), view);
+  return handle;
 }
 
 }} // ns
diff --git a/modules/mol/base/src/view_op.hh b/modules/mol/base/src/view_op.hh
index c11b71cbb..809363758 100644
--- a/modules/mol/base/src/view_op.hh
+++ b/modules/mol/base/src/view_op.hh
@@ -26,7 +26,7 @@
 #include <ost/mol/view_type_fw.hh>
 #include <ost/mol/handle_type_fw.hh>
 #include <ost/integrity_error.hh>
-
+#include <ost/mol/entity_handle.hh>
 namespace ost { namespace mol {
   
 
@@ -87,8 +87,12 @@ CompareViews(const EntityView& view1, const EntityView& view2);
 /// \param view is the view to be converted to a handle
 /// \param include_exlusive_atoms if true, atoms that are part of an exclusive
 ///     bond will also be included in the new entity handle.
-EntityHandle DLLEXPORT_OST_MOL CreateEntityFromView(const EntityView& view,
-                                                    bool include_exlusive_atoms);
+/// \param handle If invalid a new entity will be created. If valid, the atoms, 
+///     residues, chains, bonds and torsions will be added to handle. This is 
+///     useful to combine several entities into one.
+EntityHandle DLLEXPORT_OST_MOL 
+CreateEntityFromView(const EntityView& view, bool include_exlusive_atoms,
+                     EntityHandle handle=EntityHandle());
 
 }} // ns
 #endif
-- 
GitLab