From c641643da00b94eed62f6c696c2767a8ccbe385a Mon Sep 17 00:00:00 2001
From: stefan <stefan@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Wed, 24 Mar 2010 16:46:01 +0000
Subject: [PATCH] Merge commit 'local'

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1883 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/gfx/pymod/export_color_ops.cc         |  36 ++++-
 .../gfx/src/color_ops/by_chain_color_op.cc    |   4 +-
 .../gfx/src/color_ops/by_chain_color_op.hh    |   4 +-
 .../gfx/src/color_ops/by_element_color_op.cc  |   4 +-
 .../gfx/src/color_ops/by_element_color_op.hh  |   5 +-
 modules/gfx/src/color_ops/color_op.cc         |  28 +++-
 modules/gfx/src/color_ops/color_op.hh         |  15 +-
 .../gfx/src/color_ops/gradient_color_op.cc    |  24 ++++
 .../gfx/src/color_ops/gradient_color_op.hh    |   9 +-
 .../src/color_ops/gradient_level_color_op.cc  |  33 +++++
 .../src/color_ops/gradient_level_color_op.hh  |  14 ++
 .../gfx/src/color_ops/map_handle_color_op.cc  |  12 +-
 .../gfx/src/color_ops/map_handle_color_op.hh  |   2 +
 modules/gfx/src/color_ops/uniform_color_op.cc |  11 ++
 modules/gfx/src/color_ops/uniform_color_op.hh |   2 +
 modules/gfx/src/impl/connect_renderer_base.cc | 115 +++++-----------
 modules/gfx/src/impl/entity_renderer.hh       |  81 +++++++++++
 modules/gfx/src/impl/trace_renderer_base.cc   | 128 +++++++-----------
 modules/gui/pymod/CMakeLists.txt              |   1 +
 modules/gui/pymod/export_scene_selection.cc   |   1 +
 .../gui/pymod/scene/color_options_widget.py   |  26 +++-
 .../gui/pymod/scene/gradient_editor_widget.py |  11 ++
 modules/gui/pymod/scene/inspector_widget.py   |   2 +
 modules/gui/pymod/scene/preset_widget.py      |  12 ++
 .../gui/pymod/scene/uniform_color_widget.py   |  25 +++-
 modules/gui/src/scene_selection.cc            |   2 +-
 modules/mol/base/pymod/CMakeLists.txt         |   1 +
 .../base/pymod/export_query_view_wrapper.cc   |  48 +++++++
 modules/mol/base/pymod/wrap_mol.cc            |   2 +
 modules/mol/base/src/query_view_wrapper.cc    |  26 +++-
 modules/mol/base/src/query_view_wrapper.hh    |   7 +-
 31 files changed, 484 insertions(+), 207 deletions(-)
 create mode 100644 modules/mol/base/pymod/export_query_view_wrapper.cc

diff --git a/modules/gfx/pymod/export_color_ops.cc b/modules/gfx/pymod/export_color_ops.cc
index 4c5859c5f..d24a15179 100644
--- a/modules/gfx/pymod/export_color_ops.cc
+++ b/modules/gfx/pymod/export_color_ops.cc
@@ -41,6 +41,7 @@ using namespace ost::gfx;
 void export_ColorOps()
 {
   class_<ColorOp>("ColorOp", init<const String& >())
+    .def(init<const mol::QueryViewWrapper&, int>())
     .def("CanApplyTo",&ColorOp::CanApplyTo)
     .def("SetSelection",&ColorOp::SetSelection)
     .def("GetSelection",&ColorOp::GetSelection)
@@ -61,27 +62,39 @@ void export_ColorOps()
   ;
 
   class_<ByElementColorOp, bases<ColorOp> >("ByElementColorOp", init<>())
+    .def(init<const String&>())
+    .def(init<const mol::QueryViewWrapper&>())
     .def(init<const String&, int>())
+    .def(init<const mol::QueryViewWrapper&, int>())
     .def("FromInfo",&ByElementColorOp::FromInfo)
     .staticmethod("FromInfo")
   ;
 
   class_<ByChainColorOp, bases<ColorOp> >("ByChainColorOp", init<>())
+    .def(init<const String&>())
+    .def(init<const mol::QueryViewWrapper&>())
     .def(init<const String&, int>())
+    .def(init<const mol::QueryViewWrapper&, int>())
     .def("FromInfo",&ByChainColorOp::FromInfo)
     .staticmethod("FromInfo")
   ;
 
-  class_<UniformColorOp, bases<ColorOp> >("UniformColorOp", init<const String&, const gfx::Color&>())
+  class_<UniformColorOp, bases<ColorOp> >("UniformColorOp", init<>())
+    .def(init<const String&, const gfx::Color&>())
     .def(init<const String&, int, const gfx::Color&>())
+    .def(init<const mol::QueryViewWrapper&, const gfx::Color&>())
+    .def(init<const mol::QueryViewWrapper&, int, const gfx::Color&>())
     .def("SetColor",&UniformColorOp::SetColor)
     .def("GetColor",&UniformColorOp::GetColor)
     .def("FromInfo",&UniformColorOp::FromInfo)
     .staticmethod("FromInfo")
   ;
 
-  class_<GradientColorOp, bases<ColorOp> >("GradientColorOp", init<const String&, const String&, const gfx::Gradient&, float, float>())
+  class_<GradientColorOp, bases<ColorOp> >("GradientColorOp", init<>())
+    .def(init<const String&, const String&, const gfx::Gradient&, float, float>())
     .def(init<const String&, int, const String&, const gfx::Gradient&, float, float>())
+    .def(init<const mol::QueryViewWrapper&, const String&, const gfx::Gradient&, float, float>())
+    .def(init<const mol::QueryViewWrapper&, int, const String&, const gfx::Gradient&, float, float>())
     .def("SetProperty",&GradientColorOp::SetProperty)
     .def("GetProperty",&GradientColorOp::GetProperty)
     .def("SetGradient",&GradientColorOp::SetGradient)
@@ -95,10 +108,15 @@ void export_ColorOps()
     .staticmethod("FromInfo")
   ;
 
-  class_<GradientLevelColorOp, bases<GradientColorOp> >("GradientLevelColorOp", init<const String&, const String&, const gfx::Gradient&, float, float, mol::Prop::Level>())
+  class_<GradientLevelColorOp, bases<GradientColorOp> >("GradientLevelColorOp", init<>())
+    .def(init<const String&, const String&, const gfx::Gradient&, float, float, mol::Prop::Level>())
     .def(init<const String&, int, const String&, const gfx::Gradient&, float, float, mol::Prop::Level>())
     .def(init<const String&, const String&, const gfx::Gradient&, mol::Prop::Level>())
     .def(init<const String&, int, const String&, const gfx::Gradient&, mol::Prop::Level>())
+    .def(init<const mol::QueryViewWrapper&, const String&, const gfx::Gradient&, float, float, mol::Prop::Level>())
+    .def(init<const mol::QueryViewWrapper&, int, const String&, const gfx::Gradient&, float, float, mol::Prop::Level>())
+    .def(init<const mol::QueryViewWrapper&, const String&, const gfx::Gradient&, mol::Prop::Level>())
+    .def(init<const mol::QueryViewWrapper&, int, const String&, const gfx::Gradient&, mol::Prop::Level>())
     .def("SetLevel",&GradientLevelColorOp::SetLevel)
     .def("GetLevel",&GradientLevelColorOp::GetLevel)
     .def("FromInfo",&GradientLevelColorOp::FromInfo)
@@ -106,19 +124,23 @@ void export_ColorOps()
   ;
 
 
-  class_<EntityViewColorOp, bases<GradientColorOp> >("EntityViewColorOp", init<const String&, const gfx::Gradient&, float, float, const mol::EntityView&>())
+  class_<EntityViewColorOp, bases<GradientColorOp> >("EntityViewColorOp", init<>())
+    .def(init<const String&, const gfx::Gradient&, float, float, const mol::EntityView&>())
     .def(init<int, const String&, const gfx::Gradient&, float, float, const mol::EntityView&>())
     .def("SetEntityView",&EntityViewColorOp::SetEntityView)
-    //.def("GetEntityView",&EntityViewColorOp::GetEntityView)
+    .def("GetEntityView",&EntityViewColorOp::GetEntityView,return_value_policy<copy_const_reference>())
     .def("FromInfo",&EntityViewColorOp::FromInfo)
     .staticmethod("FromInfo")
   ;
 
 #if OST_IMG_ENABLED
-  class_<MapHandleColorOp, bases<GradientColorOp> >("MapHandleColorOp", init<const String&, const String&, const gfx::Gradient&, float, float, const img::MapHandle&>())
+  class_<MapHandleColorOp, bases<GradientColorOp> >("MapHandleColorOp", init<>())
+    .def(init<const String&, const String&, const gfx::Gradient&, float, float, const img::MapHandle&>())
     .def(init<const String&, int, const String&, const gfx::Gradient&, float, float, const img::MapHandle&>())
+    .def(init<const mol::QueryViewWrapper&, const String&, const gfx::Gradient&, float, float, const img::MapHandle&>())
+    .def(init<const mol::QueryViewWrapper&, int, const String&, const gfx::Gradient&, float, float, const img::MapHandle&>())
     .def("SetMapHandle",&MapHandleColorOp::SetMapHandle)
-    //.def("GetMapHandle",&MapHandleColorOp::GetMapHandle)
+    .def("GetMapHandle",&MapHandleColorOp::GetMapHandle,return_value_policy<copy_const_reference>())
     .def("FromInfo",&MapHandleColorOp::FromInfo)
     .staticmethod("FromInfo")
   ;
diff --git a/modules/gfx/src/color_ops/by_chain_color_op.cc b/modules/gfx/src/color_ops/by_chain_color_op.cc
index 0bde2c8c1..908fb591f 100644
--- a/modules/gfx/src/color_ops/by_chain_color_op.cc
+++ b/modules/gfx/src/color_ops/by_chain_color_op.cc
@@ -28,10 +28,10 @@ namespace ost { namespace gfx {
 
 ByChainColorOp::ByChainColorOp() : ColorOp(){this->init();}
 
-ByChainColorOp::ByChainColorOp(const String& selection) : ColorOp(selection){this->init();}
-
 ByChainColorOp::ByChainColorOp(const String& selection, int mask) : ColorOp(selection,mask){this->init();}
 
+ByChainColorOp::ByChainColorOp(const mol::QueryViewWrapper& query_view, int mask) : ColorOp(query_view,mask){this->init();}
+
 void ByChainColorOp::init(){
   color_grad_.SetColorAt(0,Color(1,1,0));
   color_grad_.SetColorAt(0.16666,Color(1,0,0));
diff --git a/modules/gfx/src/color_ops/by_chain_color_op.hh b/modules/gfx/src/color_ops/by_chain_color_op.hh
index 6cd454a6e..fffc89668 100644
--- a/modules/gfx/src/color_ops/by_chain_color_op.hh
+++ b/modules/gfx/src/color_ops/by_chain_color_op.hh
@@ -35,8 +35,8 @@ namespace ost { namespace gfx {
 class DLLEXPORT_OST_GFX ByChainColorOp: public ColorOp {
 public:
   ByChainColorOp();
-  ByChainColorOp(const String& selection);
-  ByChainColorOp(const String& selection, int mask);
+  ByChainColorOp(const String& selection, int mask=DETAIL_COLOR|MAIN_COLOR);
+  ByChainColorOp(const mol::QueryViewWrapper& query_view, int mask=DETAIL_COLOR|MAIN_COLOR);
 
   virtual bool CanApplyTo(const GfxObjP& obj) const;
   virtual void ApplyTo(GfxObjP& obj) const;
diff --git a/modules/gfx/src/color_ops/by_element_color_op.cc b/modules/gfx/src/color_ops/by_element_color_op.cc
index 6851268c0..e2bac71b0 100644
--- a/modules/gfx/src/color_ops/by_element_color_op.cc
+++ b/modules/gfx/src/color_ops/by_element_color_op.cc
@@ -27,10 +27,10 @@ namespace ost { namespace gfx {
 
 ByElementColorOp::ByElementColorOp() : ColorOp(){}
 
-ByElementColorOp::ByElementColorOp(const String& selection) : ColorOp(selection){}
-
 ByElementColorOp::ByElementColorOp(const String& selection, int mask) : ColorOp(selection,mask){}
 
+ByElementColorOp::ByElementColorOp(const mol::QueryViewWrapper& query_view, int mask) : ColorOp(query_view,mask){}
+
 bool ByElementColorOp::CanApplyTo(const GfxObjP& obj) const{
   if(dynamic_cast<Entity*>(obj.get()))
     return true;
diff --git a/modules/gfx/src/color_ops/by_element_color_op.hh b/modules/gfx/src/color_ops/by_element_color_op.hh
index cefc09d41..2de442121 100644
--- a/modules/gfx/src/color_ops/by_element_color_op.hh
+++ b/modules/gfx/src/color_ops/by_element_color_op.hh
@@ -36,9 +36,8 @@ class DLLEXPORT_OST_GFX ByElementColorOp: public ColorOp {
 public:
   ByElementColorOp();
 
-  ByElementColorOp(const String& selection);
-
-  ByElementColorOp(const String& selection, int mask);
+  ByElementColorOp(const mol::QueryViewWrapper& query_view, int mask=DETAIL_COLOR|MAIN_COLOR);
+  ByElementColorOp(const String& selection, int mask=DETAIL_COLOR|MAIN_COLOR);
 
 
   virtual bool CanApplyTo(const GfxObjP& obj) const;
diff --git a/modules/gfx/src/color_ops/color_op.cc b/modules/gfx/src/color_ops/color_op.cc
index 01f78630e..bca45b744 100644
--- a/modules/gfx/src/color_ops/color_op.cc
+++ b/modules/gfx/src/color_ops/color_op.cc
@@ -21,14 +21,17 @@
 
 namespace ost { namespace gfx {
 
-ColorOp::ColorOp(): selection_(), mask_(DETAIL_COLOR|MAIN_COLOR) 
+ColorOp::ColorOp(): query_view_(), mask_(DETAIL_COLOR|MAIN_COLOR)
 { }
 
 
 ColorOp::ColorOp(const String& selection, int mask):
-  selection_(selection), mask_(mask)
+    query_view_(mol::Query(selection),mol::EntityView() ), mask_(mask)
 { }
 
+ColorOp::ColorOp(const mol::QueryViewWrapper& query_view, int mask):
+    query_view_(query_view), mask_(mask)
+{ }
 
 bool ColorOp::CanApplyTo(const GfxObjP& obj) const
 {
@@ -42,18 +45,33 @@ void ColorOp::ApplyTo(GfxObjP& obj) const
 
 void ColorOp::SetSelection(const String& selection)
 {
-  selection_ = selection;
+  query_view_.SetQuery(selection);
 }
 
 String ColorOp::GetSelection() const
 {
-  return selection_;
+  return query_view_.GetQuery().GetQueryString();
+}
+
+bool ColorOp::IsSelectionOnly() const
+{
+  return !query_view_.IsDataValid();
+}
+
+mol::EntityView ColorOp::GetView() const
+{
+  return query_view_.GetEntityView();
+}
+
+void ColorOp::SetView(const mol::EntityView& view)
+{
+  query_view_ = mol::QueryViewWrapper(query_view_.GetQuery(),view);
 }
 
 void ColorOp::ToInfo(info::InfoGroup& group) const
 {
   std::ostringstream ss;
-  ss << (int)mask_ << "\t" << selection_;
+  ss << (int)mask_ << "\t" << query_view_.GetQuery().GetQueryString();
   group.SetTextData(ss.str());
 }
 
diff --git a/modules/gfx/src/color_ops/color_op.hh b/modules/gfx/src/color_ops/color_op.hh
index 9fce6e88a..c2c7c9360 100644
--- a/modules/gfx/src/color_ops/color_op.hh
+++ b/modules/gfx/src/color_ops/color_op.hh
@@ -20,6 +20,9 @@
 #define OST_COLOR_OPS_COLOR_OP_HH
 
 #include <string>
+
+#include <ost/mol/query_view_wrapper.hh>
+
 #include <ost/gfx/gfx_object_fw.hh>
 #include <ost/gfx/module_config.hh>
 
@@ -33,8 +36,8 @@
 namespace ost { namespace gfx {
 
 typedef enum {
-  DETAIL_COLOR =1,
-  MAIN_COLOR   =2
+  DETAIL_COLOR = 1,
+  MAIN_COLOR = 2
 } ColorBit;
 
 typedef unsigned char ColorMask;
@@ -44,6 +47,7 @@ public:
   ColorOp();
   virtual ~ColorOp() {}
   ColorOp(const String& selection, int mask=DETAIL_COLOR|MAIN_COLOR);
+  ColorOp(const mol::QueryViewWrapper& query_view, int mask=DETAIL_COLOR|MAIN_COLOR);
   virtual bool CanApplyTo(const GfxObjP& obj) const;
   virtual void ApplyTo(GfxObjP& obj) const;
 
@@ -54,10 +58,15 @@ public:
   virtual void SetSelection(const String& selection);
   virtual String GetSelection() const;
 
+  virtual bool IsSelectionOnly() const;
+  virtual void SetView(const mol::EntityView& view);
+  virtual mol::EntityView GetView() const;
+
   virtual void ToInfo(info::InfoGroup& group) const;
   static gfx::ColorOp FromInfo(info::InfoGroup& group);
 private:
-  String    selection_;
+  mol::QueryViewWrapper query_view_;
+  mol::EntityView view_;
   ColorMask mask_;
 };
 
diff --git a/modules/gfx/src/color_ops/gradient_color_op.cc b/modules/gfx/src/color_ops/gradient_color_op.cc
index d46af0511..82c06e144 100644
--- a/modules/gfx/src/color_ops/gradient_color_op.cc
+++ b/modules/gfx/src/color_ops/gradient_color_op.cc
@@ -52,6 +52,30 @@ GradientColorOp::GradientColorOp(const String& selection, int mask, const String
   ColorOp(selection,mask), property_(property), gradient_(gradient), calculate_(true)
 { }
 
+GradientColorOp::GradientColorOp(const mol::QueryViewWrapper& query_view, const String& property,
+                                 const gfx::Gradient& gradient,
+                                 float minv, float maxv):
+  ColorOp(query_view), property_(property), gradient_(gradient), calculate_(false),
+  minv_(minv), maxv_(maxv)
+{ }
+
+GradientColorOp::GradientColorOp(const mol::QueryViewWrapper& query_view, int mask, const String& property,
+                                 const gfx::Gradient& gradient,
+                                 float minv, float maxv):
+  ColorOp(query_view,mask), property_(property), gradient_(gradient), calculate_(false),
+  minv_(minv), maxv_(maxv)
+{ }
+
+GradientColorOp::GradientColorOp(const mol::QueryViewWrapper& query_view, const String& property,
+                                 const gfx::Gradient& gradient):
+  ColorOp(query_view), property_(property), gradient_(gradient), calculate_(true)
+{ }
+
+GradientColorOp::GradientColorOp(const mol::QueryViewWrapper& query_view, int mask, const String& property,
+                                 const gfx::Gradient& gradient):
+  ColorOp(query_view,mask), property_(property), gradient_(gradient), calculate_(true)
+{ }
+
 void GradientColorOp::SetProperty(const String& property)
 {
   property_ = property;
diff --git a/modules/gfx/src/color_ops/gradient_color_op.hh b/modules/gfx/src/color_ops/gradient_color_op.hh
index 9cc99fa9f..98a6df76c 100644
--- a/modules/gfx/src/color_ops/gradient_color_op.hh
+++ b/modules/gfx/src/color_ops/gradient_color_op.hh
@@ -37,13 +37,16 @@ public:
   GradientColorOp();
   GradientColorOp(const String& selection, const String& property, const gfx::Gradient& gradient,
                   float minv, float maxv);
-
   GradientColorOp(const String& selection, int mask, const String& property, const gfx::Gradient& gradient,
                     float minv, float maxv);
-
   GradientColorOp(const String& selection, const String& property, const gfx::Gradient& gradient);
-
   GradientColorOp(const String& selection, int mask, const String& property, const gfx::Gradient& gradient);
+  GradientColorOp(const mol::QueryViewWrapper& query_view, const String& property, const gfx::Gradient& gradient,
+                  float minv, float maxv);
+  GradientColorOp(const mol::QueryViewWrapper& query_view, int mask, const String& property, const gfx::Gradient& gradient,
+                    float minv, float maxv);
+  GradientColorOp(const mol::QueryViewWrapper& query_view, const String& property, const gfx::Gradient& gradient);
+  GradientColorOp(const mol::QueryViewWrapper& query_view, int mask, const String& property, const gfx::Gradient& gradient);
 
   virtual void SetProperty(const String& property);
   virtual String GetProperty() const;
diff --git a/modules/gfx/src/color_ops/gradient_level_color_op.cc b/modules/gfx/src/color_ops/gradient_level_color_op.cc
index e4fad9da5..e1e0f2940 100644
--- a/modules/gfx/src/color_ops/gradient_level_color_op.cc
+++ b/modules/gfx/src/color_ops/gradient_level_color_op.cc
@@ -63,6 +63,39 @@ GradientLevelColorOp::GradientLevelColorOp(const String& selection, int mask,
 
 }
 
+GradientLevelColorOp::GradientLevelColorOp(const mol::QueryViewWrapper& query_view,
+                                            const String& property,
+                                            const gfx::Gradient& gradient,
+                                            float minv,
+                                            float maxv, mol::Prop::Level level):
+  GradientColorOp(query_view, property, gradient, minv, maxv), level_(level){
+
+}
+
+GradientLevelColorOp::GradientLevelColorOp(const mol::QueryViewWrapper& query_view, int mask,
+                                            const String& property,
+                                            const gfx::Gradient& gradient,
+                                            float minv,
+                                            float maxv, mol::Prop::Level level):
+  GradientColorOp(query_view, mask, property, gradient, minv, maxv), level_(level){
+
+}
+
+GradientLevelColorOp::GradientLevelColorOp(const mol::QueryViewWrapper& query_view,
+                                            const String& property,
+                                            const gfx::Gradient& gradient,
+                                            mol::Prop::Level level):
+  GradientColorOp(query_view, property, gradient), level_(level){
+
+}
+
+GradientLevelColorOp::GradientLevelColorOp(const mol::QueryViewWrapper& query_view, int mask,
+                                            const String& property,
+                                            const gfx::Gradient& gradient,
+                                            mol::Prop::Level level):
+  GradientColorOp(query_view, mask, property, gradient), level_(level){
+
+}
 
 bool GradientLevelColorOp::CanApplyTo(const GfxObjP& obj) const{
   if(dynamic_cast<Entity*>(obj.get()))
diff --git a/modules/gfx/src/color_ops/gradient_level_color_op.hh b/modules/gfx/src/color_ops/gradient_level_color_op.hh
index 6c829c189..d0c1cac66 100644
--- a/modules/gfx/src/color_ops/gradient_level_color_op.hh
+++ b/modules/gfx/src/color_ops/gradient_level_color_op.hh
@@ -52,6 +52,20 @@ public:
   GradientLevelColorOp(const String& selection, int mask, const String& property, const gfx::Gradient& gradient,
                        mol::Prop::Level level=mol::Prop::UNSPECIFIED);
 
+  GradientLevelColorOp(const mol::QueryViewWrapper& query_view, const String& property, const gfx::Gradient& gradient,
+                       float minv, float maxv,
+                       mol::Prop::Level level=mol::Prop::UNSPECIFIED);
+
+  GradientLevelColorOp(const mol::QueryViewWrapper& query_view, int mask, const String& property, const gfx::Gradient& gradient,
+                       float minv, float maxv,
+                       mol::Prop::Level level=mol::Prop::UNSPECIFIED);
+
+  GradientLevelColorOp(const mol::QueryViewWrapper& query_view, const String& property, const gfx::Gradient& gradient,
+                       mol::Prop::Level level=mol::Prop::UNSPECIFIED);
+
+  GradientLevelColorOp(const mol::QueryViewWrapper& query_view, int mask, const String& property, const gfx::Gradient& gradient,
+                       mol::Prop::Level level=mol::Prop::UNSPECIFIED);
+
   virtual bool CanApplyTo(const GfxObjP& obj) const;
   virtual void ApplyTo(GfxObjP& obj) const;
 
diff --git a/modules/gfx/src/color_ops/map_handle_color_op.cc b/modules/gfx/src/color_ops/map_handle_color_op.cc
index 6e0af785a..c8cf2ebb7 100644
--- a/modules/gfx/src/color_ops/map_handle_color_op.cc
+++ b/modules/gfx/src/color_ops/map_handle_color_op.cc
@@ -30,14 +30,16 @@ MapHandleColorOp::MapHandleColorOp() : GradientColorOp(), mh_(){
 }
 
 MapHandleColorOp::MapHandleColorOp(const String& selection, const String& property, const gfx::Gradient& gradient, float minv, float maxv, const img::MapHandle& mh) :
-  GradientColorOp(selection, property, gradient, minv, maxv), mh_(mh){
-
-}
+  GradientColorOp(selection, property, gradient, minv, maxv), mh_(mh){ }
 
 MapHandleColorOp::MapHandleColorOp(const String& selection, int mask, const String& property, const gfx::Gradient& gradient, float minv, float maxv, const img::MapHandle& mh) :
-  GradientColorOp(selection, mask, property, gradient, minv, maxv), mh_(mh){
+  GradientColorOp(selection, mask, property, gradient, minv, maxv), mh_(mh){ }
 
-}
+MapHandleColorOp::MapHandleColorOp(const mol::QueryViewWrapper& query_view, const String& property, const gfx::Gradient& gradient, float minv, float maxv, const img::MapHandle& mh) :
+  GradientColorOp(query_view, property, gradient, minv, maxv), mh_(mh){ }
+
+MapHandleColorOp::MapHandleColorOp(const mol::QueryViewWrapper& query_view, int mask, const String& property, const gfx::Gradient& gradient, float minv, float maxv, const img::MapHandle& mh) :
+  GradientColorOp(query_view, mask, property, gradient, minv, maxv), mh_(mh){ }
 
 bool MapHandleColorOp::CanApplyTo(const GfxObjP& obj) const{
   if(dynamic_cast<Entity*>(obj.get())){
diff --git a/modules/gfx/src/color_ops/map_handle_color_op.hh b/modules/gfx/src/color_ops/map_handle_color_op.hh
index aee4cf6b7..3dd6b302c 100644
--- a/modules/gfx/src/color_ops/map_handle_color_op.hh
+++ b/modules/gfx/src/color_ops/map_handle_color_op.hh
@@ -39,6 +39,8 @@ public:
   MapHandleColorOp();
   MapHandleColorOp(const String& selection, const String& property, const gfx::Gradient& gradient, float minv, float maxv, const img::MapHandle& mh);
   MapHandleColorOp(const String& selection, int mask, const String& property, const gfx::Gradient& gradient, float minv, float maxv, const img::MapHandle& mh);
+  MapHandleColorOp(const mol::QueryViewWrapper& query_view, const String& property, const gfx::Gradient& gradient, float minv, float maxv, const img::MapHandle& mh);
+  MapHandleColorOp(const mol::QueryViewWrapper& query_view, int mask, const String& property, const gfx::Gradient& gradient, float minv, float maxv, const img::MapHandle& mh);
 
   virtual bool CanApplyTo(const GfxObjP& obj) const;
   virtual void ApplyTo(GfxObjP& obj) const;
diff --git a/modules/gfx/src/color_ops/uniform_color_op.cc b/modules/gfx/src/color_ops/uniform_color_op.cc
index 9cd5f3b7b..8247fb0d2 100644
--- a/modules/gfx/src/color_ops/uniform_color_op.cc
+++ b/modules/gfx/src/color_ops/uniform_color_op.cc
@@ -41,6 +41,17 @@ UniformColorOp::UniformColorOp(const String& selection, int mask,
   ColorOp(selection,mask), color_(color){
 }
 
+UniformColorOp::UniformColorOp(const mol::QueryViewWrapper& query_view,
+                               const gfx::Color& color):
+  ColorOp(query_view), color_(color){
+
+}
+
+UniformColorOp::UniformColorOp(const mol::QueryViewWrapper& query_view,
+                               int mask, const gfx::Color& color):
+  ColorOp(query_view,mask), color_(color){
+}
+
 bool UniformColorOp::CanApplyTo(const GfxObjP& obj) const
 {
   return dynamic_cast<Entity*>(obj.get()) || dynamic_cast<Surface*>(obj.get());
diff --git a/modules/gfx/src/color_ops/uniform_color_op.hh b/modules/gfx/src/color_ops/uniform_color_op.hh
index a6609a116..03e7ccd7f 100644
--- a/modules/gfx/src/color_ops/uniform_color_op.hh
+++ b/modules/gfx/src/color_ops/uniform_color_op.hh
@@ -36,6 +36,8 @@ namespace ost { namespace gfx {
 class DLLEXPORT_OST_GFX UniformColorOp: public ColorOp {
 public:
   UniformColorOp();
+  UniformColorOp(const mol::QueryViewWrapper& query_view, const gfx::Color& color);
+  UniformColorOp(const mol::QueryViewWrapper& query_view, int mask, const gfx::Color& color);
   UniformColorOp(const String& selection, const gfx::Color& color);
   UniformColorOp(const String& selection, int mask, const gfx::Color& color);
 
diff --git a/modules/gfx/src/impl/connect_renderer_base.cc b/modules/gfx/src/impl/connect_renderer_base.cc
index 3eccdac57..36df3b365 100644
--- a/modules/gfx/src/impl/connect_renderer_base.cc
+++ b/modules/gfx/src/impl/connect_renderer_base.cc
@@ -20,12 +20,7 @@
 /*
   Authors: Ansgar Philippsen, Marco Biasini
  */
-#include <ost/mol/mol.hh>
-
-#include <ost/mol/entity_property_mapper.hh>
-
 #include <ost/gfx/scene.hh>
-#include <ost/gfx/impl/mapped_property.hh>
 #include <ost/gfx/impl/connect_renderer_base.hh>
 
 namespace ost { namespace gfx { namespace impl {
@@ -135,6 +130,32 @@ private:
   bool af_,bf_;
 };
 
+template <typename T1>
+inline void apply_color_op(ConnectRendererBase* rend, GfxView* v, T1 get_col, const ColorOp& op)
+{
+  if ((op.GetMask() & MAIN_COLOR)==0) {
+    return;
+  }
+  rend->UpdateViews();
+  if(op.IsSelectionOnly()){
+    mol::Query q(op.GetSelection());
+    for (AtomEntryMap::iterator it=v->atom_map.begin();
+         it!=v->atom_map.end();++it) {
+      if (q.IsAtomSelected(it->second.atom)) {
+        it->second.color=get_col.ColorOfAtom(it->second.atom);
+      }
+    }
+  }
+  else{
+    mol::EntityView view = op.GetView();
+    for(AtomEntryMap::iterator it=v->atom_map.begin();it!=v->atom_map.end();++it){
+      if(view.FindAtom(it->second.atom)){
+        it->second.color=get_col.ColorOfAtom(it->second.atom);
+      }
+    }
+  }
+};
+
 } // anon ns
   
 ConnectRendererBase::ConnectRendererBase(): pick_radius_(0.0)
@@ -193,108 +214,38 @@ geom::AlignedCuboid ConnectRendererBase::GetBoundingBox() const
 
 void ConnectRendererBase::Apply(const gfx::ByElementColorOp& op)
 {
-  if ((op.GetMask() & MAIN_COLOR)==0) {
-    return;
-  }  
-  this->UpdateViews();
-  mol::Query q(op.GetSelection());
-  for (AtomEntryMap::iterator it=view_.atom_map.begin();
-       it!=view_.atom_map.end();++it) {
-    if (q.IsAtomSelected(it->second.atom)) {
-      it->second.color=GfxObj::Ele2Color(it->second.atom.GetProp().element);
-    }
-  }
+  apply_color_op(this,&view_,ByElementGetCol(),op);
   state_|=DIRTY_VA;
 }
 
 void ConnectRendererBase::Apply(const gfx::ByChainColorOp& op)
 {
-  if ((op.GetMask() & MAIN_COLOR)==0) {
-    return;
-  }
-  this->UpdateViews();
-  mol::Query q(op.GetSelection());
-  for (AtomEntryMap::iterator it=view_.atom_map.begin();
-       it!=view_.atom_map.end();++it) {
-    if (q.IsAtomSelected(it->second.atom)) {
-      it->second.color=op.GetColor(it->second.atom.GetResidue().GetChain().GetName());
-    }
-  }
+  apply_color_op(this,&view_,ByChainGetCol(op),op);
   state_|=DIRTY_VA;
 }
 
 void ConnectRendererBase::Apply(const gfx::UniformColorOp& op)
 {
-  if ((op.GetMask() & MAIN_COLOR)==0) {
-    return;
-  }  
-  this->UpdateViews();
-  mol::Query q(op.GetSelection());
-  for (AtomEntryMap::iterator it=view_.atom_map.begin();
-       it!=view_.atom_map.end();++it) {
-    if (q.IsAtomSelected(it->second.atom)) {
-      it->second.color=op.GetColor();
-    }
-  }
+  apply_color_op(this,&view_,UniformGetCol(op.GetColor()),op);
   state_|=DIRTY_VA;
 }
 
 void ConnectRendererBase::Apply(const gfx::GradientLevelColorOp& op)
 {
-  if ((op.GetMask() & MAIN_COLOR)==0) {
-    return;
-  }  
-  this->UpdateViews();
-  mol::EntityPropertyMapper epm(op.GetProperty(), op.GetLevel());
-  gfx::Gradient gradient = op.GetGradient();  
-  for (AtomEntryMap::iterator it=view_.atom_map.begin();
-       it!=view_.atom_map.end();++it) {
-    try {
-      float n=Normalize(epm.Get(it->second.atom), op.GetMinV(), op.GetMaxV());
-      it->second.color=gradient.GetColorAt(n);
-    } catch (std::exception&) {
-      LOGN_DEBUG("property " << op.GetProperty() << " not found");
-    }
-  }
-  state_|=DIRTY_VA;  
+  apply_color_op(this,&view_,GradientLevelGetCol(op),op);
+  state_|=DIRTY_VA;
 }
 
 void ConnectRendererBase::Apply(const gfx::EntityViewColorOp& op)
 {
-  if ((op.GetMask() & MAIN_COLOR)==0) {
-    return;
-  }  
-  this->UpdateViews();  
-  mol::EntityView ev = op.GetEntityView();
-  gfx::Gradient g = op.GetGradient();
-  const String prop = op.GetProperty();
-  float minv = op.GetMinV();
-  float maxv = op.GetMaxV();  
-  for (AtomEntryMap::iterator it=view_.atom_map.begin();
-       it!=view_.atom_map.end();++it) {
-    it->second.color = MappedProperty(ev,prop,g,minv,maxv,
-                                      it->second.atom.GetPos());
-  }
+  apply_color_op(this,&view_,EntityViewGetCol(op),op);
   state_|=DIRTY_VA;
 }
 
 #if OST_IMG_ENABLED
 void ConnectRendererBase::Apply(const gfx::MapHandleColorOp& op)
 {
-  if ((op.GetMask() & MAIN_COLOR)==0) {
-    return;
-  }  
-  this->UpdateViews();  
-  img::MapHandle mh = op.GetMapHandle();
-  gfx::Gradient g = op.GetGradient();
-  const String& prop = op.GetProperty();
-  float minv = op.GetMinV();
-  float maxv = op.GetMaxV();    
-  for (AtomEntryMap::iterator it=view_.atom_map.begin();
-       it!=view_.atom_map.end();++it) {
-    it->second.color=MappedProperty(mh,prop,g,minv,maxv,
-                                    it->second.atom.GetPos());
-  }
+  apply_color_op(this,&view_,MapHandleGetCol(op),op);
   state_|=DIRTY_VA;
 }
 #endif
diff --git a/modules/gfx/src/impl/entity_renderer.hh b/modules/gfx/src/impl/entity_renderer.hh
index b3f3b0cb1..fe0d54138 100644
--- a/modules/gfx/src/impl/entity_renderer.hh
+++ b/modules/gfx/src/impl/entity_renderer.hh
@@ -27,11 +27,16 @@
 
 #include <ost/mol/query_view_wrapper.hh>
 #include <ost/mol/entity_view.hh>
+#include <ost/mol/atom_handle.hh>
+#include <ost/mol/entity_property_mapper.hh>
 
+#include <ost/gfx/color.hh>
+#include <ost/gfx/gfx_object.hh>
 #include <ost/gfx/module_config.hh>
 #include <ost/gfx/render_pass.hh>
 #include <ost/gfx/vertex_array.hh>
 #include <ost/gfx/render_options/render_options.hh>
+#include <ost/gfx/impl/mapped_property.hh>
 
 #include <ost/gfx/color_ops/color_op.hh>
 #include <ost/gfx/color_ops/by_element_color_op.hh>
@@ -169,6 +174,82 @@ protected:
   DirtyFlags            state_;
 };
 
+//Simplify color ops
+struct ByElementGetCol {
+  Color ColorOfAtom(mol::AtomHandle& atom) const{
+    return GfxObj::Ele2Color(atom.GetProp().element);
+  }
+};
+
+struct ByChainGetCol {
+  ByChainGetCol(const ByChainColorOp& op):op_(op){}
+  Color ColorOfAtom(mol::AtomHandle& atom) const{
+    return op_.GetColor(atom.GetResidue().GetChain().GetName());
+  }
+  const ByChainColorOp& op_;
+};
+
+struct UniformGetCol {
+  UniformGetCol(const Color& col):col_(col){ }
+  Color ColorOfAtom(mol::AtomHandle& atom) const{
+    return col_;
+  }
+  const Color& col_;
+};
+
+struct GradientLevelGetCol {
+  GradientLevelGetCol(const GradientLevelColorOp& op):property_(op.GetProperty()),
+      epm_(property_, op.GetLevel()),
+      gradient_(op.GetGradient()),
+      minv_(op.GetMinV()),
+      maxv_(op.GetMaxV()){}
+  Color ColorOfAtom(mol::AtomHandle& atom) const{
+    try{
+      float n=Normalize(epm_.Get(atom), minv_, maxv_);
+      return gradient_.GetColorAt(n);
+    }catch(std::exception&){
+      LOGN_DEBUG("property " << property_ << " not found");
+      return Color();
+    }
+  }
+  String property_;
+  mol::EntityPropertyMapper epm_;
+  Gradient gradient_;
+  float minv_, maxv_;
+};
+
+struct EntityViewGetCol {
+  EntityViewGetCol(const EntityViewColorOp& op):property_(op.GetProperty()),
+      ev_(op.GetEntityView()),
+      gradient_(op.GetGradient()),
+      minv_(op.GetMinV()),
+      maxv_(op.GetMaxV()){}
+  Color ColorOfAtom(mol::AtomHandle& atom) const{
+    return MappedProperty(ev_,property_,gradient_,minv_,maxv_,atom.GetPos());
+  }
+  String property_;
+  mol::EntityView ev_;
+  Gradient gradient_;
+  float minv_, maxv_;
+};
+
+#if OST_IMG_ENABLED
+struct MapHandleGetCol {
+  MapHandleGetCol(const MapHandleColorOp& op):property_(op.GetProperty()),
+      mh_(op.GetMapHandle()),
+      gradient_(op.GetGradient()),
+      minv_(op.GetMinV()),
+      maxv_(op.GetMaxV()){}
+  Color ColorOfAtom(mol::AtomHandle& atom) const{
+    return MappedProperty(mh_,property_,gradient_,minv_,maxv_,atom.GetPos());
+  }
+  String property_;
+  img::MapHandle mh_;
+  Gradient gradient_;
+  float minv_, maxv_;
+};
+#endif
+
 }}} //ns
 
 #endif /* ENTITYRENDERER_HH_ */
diff --git a/modules/gfx/src/impl/trace_renderer_base.cc b/modules/gfx/src/impl/trace_renderer_base.cc
index eab535115..46084a880 100644
--- a/modules/gfx/src/impl/trace_renderer_base.cc
+++ b/modules/gfx/src/impl/trace_renderer_base.cc
@@ -17,16 +17,56 @@
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 //------------------------------------------------------------------------------
 
-#include <ost/mol/entity_property_mapper.hh>
 #include <ost/gfx/scene.hh>
 
-#include "mapped_property.hh"
-
 #include "trace_renderer_base.hh"
 
 
 namespace ost { namespace gfx { namespace impl {
 
+namespace {
+
+void set_node_entry_color(NodeEntry& e, ColorMask mask,
+                                             const Color& c)
+{
+  if (mask & MAIN_COLOR) e.color1=c;
+  if (mask & DETAIL_COLOR) e.color2=c;
+}
+
+template <typename T1>
+inline void apply_color_op(TraceRendererBase* rend, TraceSubset& trace_subset, T1 get_col, const ColorOp& op)
+{
+  rend->UpdateViews();
+  ColorMask mask = op.GetMask();
+  if(op.IsSelectionOnly()){
+    mol::Query q(op.GetSelection());
+    for (int node_list=0; node_list<trace_subset.GetSize(); ++node_list) {
+      NodeListSubset& nl=trace_subset[node_list];
+      for (int i=0; i<nl.GetSize();++i) {
+        if (q.IsAtomSelected(nl[i].atom)) {
+          Color clr =get_col.ColorOfAtom(nl[i].atom);
+          set_node_entry_color(nl[i],mask,clr);
+        }
+      }
+    }
+  }
+  else{
+    mol::EntityView view = op.GetView();
+    for (int node_list=0; node_list<trace_subset.GetSize(); ++node_list) {
+      NodeListSubset& nl=trace_subset[node_list];
+      for (int i=0; i<nl.GetSize();++i) {
+        if(view.FindAtom(nl[i].atom)){
+          Color clr =get_col.ColorOfAtom(nl[i].atom);
+          set_node_entry_color(nl[i],mask,clr);
+        }
+      }
+    }
+  }
+};
+
+
+} //ns
+
 TraceRendererBase::TraceRendererBase(BackboneTrace& trace, int n):
   trace_(trace), trace_subset_(trace, n), sel_subset_(trace, n)
 {
@@ -80,90 +120,32 @@ geom::AlignedCuboid TraceRendererBase::GetBoundingBox() const
 
 void TraceRendererBase::Apply(const gfx::ByElementColorOp& op)
 {
-  this->UpdateViews();
-  mol::Query q(op.GetSelection());
-  for (int node_list=0; node_list<trace_subset_.GetSize(); ++node_list) {
-    NodeListSubset& nl=trace_subset_[node_list];
-    for (int i=0; i<nl.GetSize();++i) {
-      if (q.IsAtomSelected(nl[i].atom)) {
-        Color clr=GfxObj::Ele2Color(nl[i].atom.GetProp().element);
-        this->set_node_entry_color(nl[i], op.GetMask(), clr);
-      }
-    } 
-  }  
+  apply_color_op(this,trace_subset_,ByElementGetCol(),op);
   state_|=DIRTY_VA;
 }
 
 void TraceRendererBase::Apply(const gfx::ByChainColorOp& op)
 {
-  this->UpdateViews();
-  mol::Query q(op.GetSelection());
-  for (int node_list=0; node_list<trace_subset_.GetSize(); ++node_list) {
-    NodeListSubset& nl=trace_subset_[node_list];
-    for (int i=0; i<nl.GetSize();++i) {
-      if (q.IsAtomSelected(nl[i].atom)) {
-        Color clr =op.GetColor(nl[i].atom.GetResidue().GetChain().GetName());
-        this->set_node_entry_color(nl[i],op.GetMask(),clr);
-      }
-    }
-  }
+  apply_color_op(this,trace_subset_,ByChainGetCol(op),op);
   state_|=DIRTY_VA;
 }
 
 
 void TraceRendererBase::Apply(const gfx::UniformColorOp& op)
 {
-  this->UpdateViews();  
-  mol::Query q(op.GetSelection());
-  for (int node_list=0; node_list<trace_subset_.GetSize(); ++node_list) {
-    NodeListSubset& nl=trace_subset_[node_list];
-    for (int i=0; i<nl.GetSize();++i) {
-      if (q.IsAtomSelected(nl[i].atom)) {
-        this->set_node_entry_color(nl[i], op.GetMask(), op.GetColor());
-      }
-    }
-  }
+  apply_color_op(this,trace_subset_,UniformGetCol(op.GetColor()),op);
   state_|=DIRTY_VA;
 }
 
 void TraceRendererBase::Apply(const gfx::GradientLevelColorOp& op)
 {
-  this->UpdateViews();
-  mol::Query q(op.GetSelection());
-  mol::EntityPropertyMapper epm(op.GetProperty(), op.GetLevel());
-  gfx::Gradient gradient = op.GetGradient();  
-  for (int node_list=0; node_list<trace_subset_.GetSize(); ++node_list) {
-    NodeListSubset& nl=trace_subset_[node_list];
-    for (int i=0; i<nl.GetSize();++i) {
-      try {
-        if (q.IsAtomSelected(nl[i].atom)) {
-          float n=Normalize(epm.Get(nl[i].atom), op.GetMinV(), op.GetMaxV());
-          this->set_node_entry_color(nl[i], op.GetMask(), gradient.GetColorAt(n));
-        }
-      } catch (std::exception&) {
-        LOGN_DEBUG("property " << op.GetProperty() << " not found");
-      }
-    }
-  }
+  apply_color_op(this,trace_subset_,GradientLevelGetCol(op),op);
   state_|=DIRTY_VA;
 }
 
 void TraceRendererBase::Apply(const gfx::EntityViewColorOp& op)
 {
-  this->UpdateViews();
-  mol::EntityView ev = op.GetEntityView();
-  gfx::Gradient g = op.GetGradient();
-  const String prop = op.GetProperty();
-  float minv = op.GetMinV();
-  float maxv = op.GetMaxV();  
-  for (int node_list=0; node_list<trace_subset_.GetSize(); ++node_list) {
-    NodeListSubset& nl=trace_subset_[node_list];
-    for (int i=0; i<nl.GetSize();++i) {
-        Color clr=MappedProperty(ev,prop,g,minv,maxv,
-                                 nl[i].atom.GetPos());      
-        this->set_node_entry_color(nl[i], op.GetMask(), clr);
-    }
-  }
+  apply_color_op(this,trace_subset_,EntityViewGetCol(op),op);
   state_|=DIRTY_VA;
 }
 
@@ -237,19 +219,7 @@ void TraceRendererBase::PickBond(const geom::Line3& line, Real line_width,
 #if OST_IMG_ENABLED
 void TraceRendererBase::Apply(const gfx::MapHandleColorOp& op)
 {
-  this->UpdateViews();  
-  img::MapHandle mh = op.GetMapHandle();
-  gfx::Gradient g = op.GetGradient();
-  const String& prop = op.GetProperty();
-  float minv = op.GetMinV();
-  float maxv = op.GetMaxV();  
-  for (int node_list=0; node_list<trace_subset_.GetSize(); ++node_list) {
-    NodeListSubset& nl=trace_subset_[node_list];
-    for (int i=0; i<nl.GetSize();++i) {
-      set_node_entry_color(nl[i], 0xff, MappedProperty(mh,prop,g,minv,maxv,
-                                                       nl[i].atom.GetPos()));
-    }
-  }
+  apply_color_op(this,trace_subset_,MapHandleGetCol(op),op);
   state_|=DIRTY_VA;
 }
 #endif
diff --git a/modules/gui/pymod/CMakeLists.txt b/modules/gui/pymod/CMakeLists.txt
index 911f91d3c..e60d52db8 100644
--- a/modules/gui/pymod/CMakeLists.txt
+++ b/modules/gui/pymod/CMakeLists.txt
@@ -85,6 +85,7 @@ install(FILES ${PRESET_FILES} DESTINATION "share/openstructure/scene")
 
 set(INSPECTOR_ICONS
   scene/icons/color_icon.png
+  scene/icons/preset_icon.png  
   scene/icons/render_icon.png
   scene/icons/tool_icon.png
 )
diff --git a/modules/gui/pymod/export_scene_selection.cc b/modules/gui/pymod/export_scene_selection.cc
index c44a0d4db..03d957202 100644
--- a/modules/gui/pymod/export_scene_selection.cc
+++ b/modules/gui/pymod/export_scene_selection.cc
@@ -35,5 +35,6 @@ void export_SceneSelection()
     .def("GetViewEntity", &SceneSelection::GetViewEntity)
     .def("GetActiveViewCount", &SceneSelection::GetActiveViewCount)
     .def("GetActiveView", &SceneSelection::GetActiveView)
+    .def("GetViewUnion", &SceneSelection::GetViewUnion)
     ;
 }
diff --git a/modules/gui/pymod/scene/color_options_widget.py b/modules/gui/pymod/scene/color_options_widget.py
index b8d111112..2683a745d 100644
--- a/modules/gui/pymod/scene/color_options_widget.py
+++ b/modules/gui/pymod/scene/color_options_widget.py
@@ -19,13 +19,13 @@
 # -*- coding: utf-8 -*-
 
 import sys
+from ost import mol
 from ost import gui
 from ost import gfx
 from PyQt4 import QtCore, QtGui
 from gradient_editor_widget import GradientEditor
 from uniform_color_widget import UniformColorWidget
 from combo_options_widget import ComboOptionsWidget
-from preset_widget import PresetWidget
 
 class ColorOptionsWidget(ComboOptionsWidget):
   def __init__(self, parent=None):
@@ -35,7 +35,6 @@ class ColorOptionsWidget(ComboOptionsWidget):
     self.text_ = "Color Options"
     
     #Add options to menu
-    self.AddWidget("Presets", PresetWidget(self))
     self.AddWidget("Color by Element", ByElementWidget("Color by Element"))
     self.AddWidget("Color by Chain", ByChainWidget("Color by Chain"))
     self.AddWidget("Color by Property", GradientEditor(self))
@@ -48,19 +47,26 @@ class ColorOptionsWidget(ComboOptionsWidget):
     for i in range(0,scene_selection.GetActiveNodeCount()):
       node = scene_selection.GetActiveNode(i)
       item.ChangeColor(node)
+    
+    if(scene_selection.GetActiveViewCount() > 0):
+      entity = scene_selection.GetViewEntity()
+      view = scene_selection.GetViewUnion()
+      item.ChangeViewColor(entity,view)
+
     self.DoResize()
     
     
   def Update(self):
     ComboOptionsWidget.setEnabled(self,True)
     scene_selection = gui.SceneSelection.Instance()
-    if scene_selection.GetActiveNodeCount() == 0:
+    
+    if scene_selection.GetActiveNodeCount() == 0 and scene_selection.GetActiveViewCount() == 0:
       ComboOptionsWidget.setEnabled(self,False)
       return
-    
+        
     for i in range(0,scene_selection.GetActiveNodeCount()):
       node = scene_selection.GetActiveNode(i)
-      if not isinstance(node, gfx.Entity) or isinstance(node, gfx.Surface):
+      if not (isinstance(node, gfx.Entity) or isinstance(node, gfx.Surface)):
         ComboOptionsWidget.setEnabled(self,False)
         return
 
@@ -95,6 +101,11 @@ class ByElementWidget(QtGui.QWidget):
       node.CleanColorOps()
       node.ColorByElement()
       
+  def ChangeViewColor(self, entity, view):
+    if isinstance(entity, gfx.Entity) and isinstance(view, mol.EntityView):
+      beco=gfx.ByElementColorOp(mol.QueryViewWrapper(view))
+      entity.Apply(beco)
+      
   def GetText(self):
     return self.text_
   
@@ -125,6 +136,11 @@ class ByChainWidget(QtGui.QWidget):
     if isinstance(node, gfx.Entity):
       node.CleanColorOps()
       node.ColorByChain()
+     
+  def ChangeViewColor(self, entity, view):
+    if isinstance(entity, gfx.Entity) and isinstance(view, mol.EntityView):
+      bco=gfx.ByChainColorOp(mol.QueryViewWrapper(view))
+      entity.Apply(bco)
       
   def GetText(self):
     return self.text_
diff --git a/modules/gui/pymod/scene/gradient_editor_widget.py b/modules/gui/pymod/scene/gradient_editor_widget.py
index 220a4d236..60be773b1 100644
--- a/modules/gui/pymod/scene/gradient_editor_widget.py
+++ b/modules/gui/pymod/scene/gradient_editor_widget.py
@@ -20,6 +20,7 @@
 
 from ost import gui
 from ost import gfx
+from ost import mol
 from PyQt4 import QtCore, QtGui
 from color_select_widget import ColorSelectWidget
 from gradient_preset_widget import GradientPresetWidget
@@ -70,6 +71,11 @@ class GradientEditor(QtGui.QWidget):
     for i in range(0,scene_selection.GetActiveNodeCount()):
       node = scene_selection.GetActiveNode(i)
       self.ChangeColor(node)
+      
+    if(scene_selection.GetActiveViewCount() > 0):
+      entity = scene_selection.GetViewEntity()
+      view = scene_selection.GetViewUnion()
+      self.ChangeViewColor(entity,view)
   
   def ChangeColor(self,node):
     if isinstance(node, gfx.Entity) or isinstance(node, gfx.Surface):
@@ -77,6 +83,11 @@ class GradientEditor(QtGui.QWidget):
       node.ColorBy(self.props[self.prop_combo_box_.currentIndex()],
                      self.gradient_edit_.GetGfxGradient())
   
+  def ChangeViewColor(self, entity, view):
+    if isinstance(entity, gfx.Entity) and isinstance(view, mol.EntityView):
+      glco=gfx.GradientLevelColorOp(mol.QueryViewWrapper(view),self.props[self.prop_combo_box_.currentIndex()],self.gradient_edit_.GetGfxGradient(),mol.Prop.Level.UNSPECIFIED)
+      entity.Apply(glco)
+      
 #Gradient Preview
 class GradientPreview(QtGui.QWidget):
   def __init__(self, parent=None):
diff --git a/modules/gui/pymod/scene/inspector_widget.py b/modules/gui/pymod/scene/inspector_widget.py
index 7116f8d98..b23f0bb7f 100644
--- a/modules/gui/pymod/scene/inspector_widget.py
+++ b/modules/gui/pymod/scene/inspector_widget.py
@@ -28,6 +28,7 @@ from toolbar_options_widget import ToolBarOptionsWidget
 from render_options_widget import RenderOptionsWidget
 from color_options_widget import ColorOptionsWidget
 from ost.gui.scene.scene_observer_impl import SceneObserverImpl
+from preset_widget import PresetWidget
 
 class InspectorWidget(ToolBarOptionsWidget):
   ICONS_PATH = os.path.join(ost.GetSharedDataPath(), "scene", "icons/")
@@ -37,6 +38,7 @@ class InspectorWidget(ToolBarOptionsWidget):
     options = [
                 [InspectorWidget.ICONS_PATH+"render_icon.png",RenderOptionsWidget(self),None], 
                 [InspectorWidget.ICONS_PATH+"color_icon.png",ColorOptionsWidget(self),None],
+                [InspectorWidget.ICONS_PATH+"preset_icon.png", PresetWidget(self),None],
                 [InspectorWidget.ICONS_PATH+"tool_icon.png",sip.wrapinstance(app.GetToolOptionsWin().GetSipHandle(),QtGui.QWidget),"Tool Options"]
               ]
     for o in options:
diff --git a/modules/gui/pymod/scene/preset_widget.py b/modules/gui/pymod/scene/preset_widget.py
index 590772c28..d581a38ea 100644
--- a/modules/gui/pymod/scene/preset_widget.py
+++ b/modules/gui/pymod/scene/preset_widget.py
@@ -143,7 +143,19 @@ class PresetWidget(QtGui.QWidget):
   def ChangeColor(self,node):
     self.LoadCurrentIndex()
   
+  def Update(self):
+    self.setEnabled(True)
+    scene_selection = gui.SceneSelection.Instance()
+    if scene_selection.GetActiveNodeCount() == 0:
+      self.setEnabled(False)
+      return
     
+    for i in range(0,scene_selection.GetActiveNodeCount()):
+      entity = scene_selection.GetActiveNode(i)
+      if not isinstance(scene_selection.GetActiveNode(i), gfx.Entity):
+        self.setEnabled(False)
+        return
+
   def Rename(self):
     if(self.list_view_.currentIndex().isValid()):
       self.list_view_.edit(self.list_view_.currentIndex())
diff --git a/modules/gui/pymod/scene/uniform_color_widget.py b/modules/gui/pymod/scene/uniform_color_widget.py
index 15a85313c..ff2cdc2dd 100644
--- a/modules/gui/pymod/scene/uniform_color_widget.py
+++ b/modules/gui/pymod/scene/uniform_color_widget.py
@@ -20,6 +20,7 @@
 
 from ost import gui
 from ost import gfx
+from ost import mol
 from PyQt4 import QtCore, QtGui
 from color_select_widget import ColorSelectWidget
 
@@ -60,15 +61,27 @@ class UniformColorWidget(QtGui.QWidget):
     for i in range(0,scene_selection.GetActiveNodeCount()):
       node = scene_selection.GetActiveNode(i)
       self.ChangeColor(node)
-
+      
+    if(scene_selection.GetActiveViewCount() > 0):
+      entity = scene_selection.GetViewEntity()
+      view = scene_selection.GetViewUnion()
+      self.ChangeViewColor(entity,view)
+        
   def ChangeColor(self, node):
-    color = self.color_select_widget_.GetColor()
-    gfxColor = gfx.Color(color.redF(), 
-                       color.greenF(),
-                       color.blueF())
     if isinstance(node, gfx.Entity) or isinstance(node, gfx.Surface):
+      gfx_color = self.GetGfxColor()
       node.CleanColorOps()
-      node.SetColor(gfxColor,"")
+      node.SetColor(gfx_color,"")
+  
+  def ChangeViewColor(self, entity, view):
+    if isinstance(entity, gfx.Entity) and isinstance(view, mol.EntityView):
+      gfx_color = self.GetGfxColor()
+      ufco=gfx.UniformColorOp(mol.QueryViewWrapper(view),gfx_color)
+      entity.Apply(ufco)
+  
+  def GetGfxColor(self):
+    color = self.color_select_widget_.GetColor()
+    return gfx.Color(color.redF(), color.greenF(), color.blueF())
   
   def resizeEvent(self, event):
     self.color_select_widget_.SetSize(self.width()/2,self.height()/2)
diff --git a/modules/gui/src/scene_selection.cc b/modules/gui/src/scene_selection.cc
index 9210d561a..edcc057b2 100644
--- a/modules/gui/src/scene_selection.cc
+++ b/modules/gui/src/scene_selection.cc
@@ -71,7 +71,7 @@ mol::EntityView SceneSelection::GetActiveView(unsigned int pos) const{
     return views_[pos].GetEntityView();
   }
   else{
-    throw Error("Index out of bounds: There is no active vies at the given position");
+    throw Error("Index out of bounds: There is no active view at the given position");
   }
 }
 
diff --git a/modules/mol/base/pymod/CMakeLists.txt b/modules/mol/base/pymod/CMakeLists.txt
index 451e7ef34..590af6909 100644
--- a/modules/mol/base/pymod/CMakeLists.txt
+++ b/modules/mol/base/pymod/CMakeLists.txt
@@ -14,6 +14,7 @@ export_residue.cc
 export_residue_view.cc
 export_surface.cc
 export_bounding_box.cc
+export_query_view_wrapper.cc
 export_torsion.cc
 export_visitor.cc
 wrap_mol.cc
diff --git a/modules/mol/base/pymod/export_query_view_wrapper.cc b/modules/mol/base/pymod/export_query_view_wrapper.cc
new file mode 100644
index 000000000..4af480ff1
--- /dev/null
+++ b/modules/mol/base/pymod/export_query_view_wrapper.cc
@@ -0,0 +1,48 @@
+//------------------------------------------------------------------------------
+// This file is part of the OpenStructure project <www.openstructure.org>
+//
+// Copyright (C) 2008-2010 by the OpenStructure authors
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License as published by the Free
+// Software Foundation; either version 3.0 of the License, or (at your option)
+// any later version.
+// This library is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+// details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+//------------------------------------------------------------------------------
+#include <boost/python.hpp>
+using namespace boost::python;
+
+#include <ost/mol/entity_view.hh>
+#include <ost/mol/query.hh>
+#include <ost/mol/query_view_wrapper.hh>
+
+
+using namespace ost;
+using namespace ost::mol;
+
+void export_QueryViewWrapper()
+{
+  class_<QueryViewWrapper>("QueryViewWrapper", init<>())
+    .def(init<const EntityHandle&>())
+    .def(init<const EntityView&>())
+    .def(init<const Query&, const EntityHandle&>())
+    .def(init<const Query&, const EntityView&>())
+    .def("GetEntityView",&QueryViewWrapper::GetEntityView)
+    .def("DependsOnQuery",&QueryViewWrapper::DependsOnQuery)
+    .def("IsDataValid", &QueryViewWrapper::IsDataValid)
+    .def("SetQuery", &QueryViewWrapper::SetQuery)
+    .def("GetQuery", &QueryViewWrapper::GetQuery
+        ,return_value_policy<copy_const_reference>())
+    .add_property("entity_view", &QueryViewWrapper::GetEntityView)
+    .add_property("query", make_function(&QueryViewWrapper::GetQuery
+        ,return_value_policy<copy_const_reference>()))
+  ;
+
+}
diff --git a/modules/mol/base/pymod/wrap_mol.cc b/modules/mol/base/pymod/wrap_mol.cc
index 1ca7adbf1..82a449f68 100644
--- a/modules/mol/base/pymod/wrap_mol.cc
+++ b/modules/mol/base/pymod/wrap_mol.cc
@@ -40,6 +40,7 @@ void export_Editors();
 void export_CoordGroup();
 void export_PropertyID();
 void export_BoundingBox();
+void export_QueryViewWrapper();
 BOOST_PYTHON_MODULE(_mol)
 {
   export_Entity();
@@ -59,6 +60,7 @@ BOOST_PYTHON_MODULE(_mol)
   export_CoordGroup();
   export_PropertyID();  
   export_BoundingBox();
+  export_QueryViewWrapper();
 
   class_<Transform>("Transform", init<>())
     .def("GetMatrix",&Transform::GetMatrix)
diff --git a/modules/mol/base/src/query_view_wrapper.cc b/modules/mol/base/src/query_view_wrapper.cc
index bb2e7b954..fc755f6e0 100644
--- a/modules/mol/base/src/query_view_wrapper.cc
+++ b/modules/mol/base/src/query_view_wrapper.cc
@@ -22,6 +22,12 @@
 
 namespace ost { namespace mol {
 
+QueryViewWrapper::QueryViewWrapper():
+        view_set_(false),
+        entity_handle_(),
+        entity_view_(),
+        query_(){}
+
 QueryViewWrapper::QueryViewWrapper(const EntityHandle& entity_handle):
     view_set_(false),
     entity_handle_(entity_handle),
@@ -55,8 +61,26 @@ EntityView QueryViewWrapper::GetEntityView() const
   if(view_set_) {
     return query_.MatchAll() ? entity_view_ : entity_view_.Select(query_);
   } else {
-    return entity_handle_.Select(query_);
+    if(entity_handle_.IsValid()){
+      return entity_handle_.Select(query_);
+    }
+    return entity_view_;
+  }
+}
+
+const Query& QueryViewWrapper::GetQuery() const{
+  return query_;
+}
+
+void QueryViewWrapper::SetQuery(const Query& query){
+  query_ = query;
+}
+
+bool QueryViewWrapper::IsDataValid() const{
+  if(view_set_){
+    return entity_view_.IsValid();
   }
+  return entity_handle_.IsValid();
 }
 
 bool QueryViewWrapper::DependsOnQuery() const
diff --git a/modules/mol/base/src/query_view_wrapper.hh b/modules/mol/base/src/query_view_wrapper.hh
index e2dc1fc1b..596b5cbf1 100644
--- a/modules/mol/base/src/query_view_wrapper.hh
+++ b/modules/mol/base/src/query_view_wrapper.hh
@@ -31,11 +31,16 @@ class DLLEXPORT_OST_MOL QueryViewWrapper {
 public:
   explicit QueryViewWrapper(const EntityHandle& entity_handle);
   explicit QueryViewWrapper(const EntityView& entity_view);
+  QueryViewWrapper();
   QueryViewWrapper(const Query& query, const EntityHandle& handle);
   QueryViewWrapper(const Query& query, const EntityView& view);  
   EntityView GetEntityView() const;
-  
   bool DependsOnQuery() const;
+  bool IsDataValid() const;
+
+  void SetQuery(const Query& query);
+  const Query& GetQuery() const;
+
 private:
   bool view_set_;
   EntityHandle entity_handle_;
-- 
GitLab