diff --git a/modules/gfx/pymod/export_color_ops.cc b/modules/gfx/pymod/export_color_ops.cc index 4c5859c5fb447c9c2b913d20d92380d10de532a1..d24a15179a9bbecbc7d10ee32c4454f288fd868d 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 0bde2c8c147f34b208ec9910b94e52adfca5a071..908fb591ff42e49f66d885dabee617ef33bb193e 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 6cd454a6e1b96eecf38aa900398d8b7867ba0959..fffc8966864ea7d9770d79ffe59053f5cb2b4964 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 6851268c01e3f59127f09e184b2d60d561c4d0b9..e2bac71b0bd02e88c333b8b55a3f4ca858358eb5 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 cefc09d41701a7706d44efc4ef1c10c7f19a32e8..2de442121cc12f0433a702a02a3e09bac79e5b10 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 01f78630ea1729ca6acd4060fd80c122b22e24ab..bca45b744617f8140fb4cf4c5038c35e2a89c621 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 9fce6e88aa01d3e2e10f14c7fad0374c197841cc..c2c7c9360e610912922abdc84b96eddaf3079fdb 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 d46af05118c769f9f89a59d18e3bd79b40f293c9..82c06e144871ce127a2080c385d676ba6b2659ad 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 9cc99fa9f75b1780b41662e500248342ebb9f1b9..98a6df76caae580e89936d89e05495198ab3cc52 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 e4fad9da58dff184746426a17aaa7c4dae6374da..e1e0f2940e94227de57752d7667c7d02ab2acf84 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 6c829c1895a2ddd0c1d28c952cf1e4fbb7a2fda1..d0c1cac667f41b28f9b7b8b5e4cf11c656f6d686 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 6e0af785a4e3d5792686a47442854812398f8b4b..c8cf2ebb7a9895187140f314f50c038a13b5eb6d 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 aee4cf6b77d1dd5bbfec678502f4ff26dbc309bb..3dd6b302c36f16e6883f0f805ea01d3ff6ed89ac 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 9cd5f3b7b66aa90b0795dc91f26a31c6b3c09371..8247fb0d2e3bd6a41a246139f7c26472aad26be0 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 a6609a1168e96ca93f082aed92b7032e96888564..03e7ccd7f5f4f878b5cef81e7b8beb48bb5adb04 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 3eccdac572f7b3afa0d2ebf6abdbfddb8808e5aa..36df3b365b4a069c6fe4f6dc9a22ad226ac11c42 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 b3f3b0cb129e36849de23cac5123df1d5020677f..fe0d541383fff746d73770f7458b259decfbcad2 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 eab5351156850b2d2685bbf7b679f1cb9dafe564..46084a880b330f86fe618c86cb88e4eb315bc3d1 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 911f91d3c576f6aaa8ed72cb74f01bd3ce0b509d..e60d52db820c53ab44a5ac3ecd366f4f999bf1fd 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 c44a0d4db9dba2f3747ace70afbc887b06383484..03d957202e041f43b4b68c5e4b39f4b1632539fc 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 b8d111112a98ac8a916c0c8fde4a512718121f9c..2683a745dfdf180e4e1ebe1ccbac474342b24d06 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 220a4d236a6398489a0c5c63bad58a4e5c39a335..60be773b100954da5c42462ef86fa0826f4f9d24 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 7116f8d9891fb85bfae615f3db0a1b741bcee890..b23f0bb7f0f5e0393855393eb180b548ae2906ae 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 590772c2832a0dbf45d2f3623abdd2249c886fbd..d581a38ea137c80a16baaf07584f8ed81f25986d 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 15a85313c5853586817115ead3a295f15fcf88c5..ff2cdc2ddfcd52a0a0ea828f812c2d161e176f32 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 9210d561a1bebb6251b54f19904a088f15bee942..edcc057b2342298793460df763b50599f298e532 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 451e7ef34dead7cc3baff87083cfdc7e5b55f706..590af690986b9c300a28917bdbc0aea48f6f0cd9 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 0000000000000000000000000000000000000000..4af480ff1a151f17e113136bd60f734059724fcb --- /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 1ca7adbf1b4be916ac63f7196b121eca8a52703b..82a449f681fbe98866c42acb0b8581fefd66d331 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 bb2e7b9547e50a372c4524612374a9453d31b1ef..fc755f6e0f162e53158b904ec8892532fd18b09a 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 e2dc1fc1b2fec8313082cf5de0b7ca84375583b6..596b5cbf12aa464ee01e7a9ebba0f734da387328 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_;