diff --git a/modules/gfx/pymod/export_color.cc b/modules/gfx/pymod/export_color.cc index 5eb1b7777ba6590d914ba67f6ecd3a6c1fd4c2e6..e673212501ffa23d1331e9682e995866857125fb 100644 --- a/modules/gfx/pymod/export_color.cc +++ b/modules/gfx/pymod/export_color.cc @@ -152,6 +152,10 @@ void export_color() def("RGBh",rgbh); def("RGBb",RGBb); def("RGBi",RGBi); + def("RGBA",RGBA); + def("RGBAh",rgbah); + def("RGBAb",RGBAb); + def("RGBAi",RGBAi); def("HSV",HSV); def("HSVi",HSVi); def("HSVA",HSVA); 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 b2cd381a2003fb1e0262491d04c566dfc2b0a718..d2c6789f9c5b6d4b21239f490b9b29a70bad8de4 100644 --- a/modules/gfx/src/color_ops/by_chain_color_op.cc +++ b/modules/gfx/src/color_ops/by_chain_color_op.cc @@ -59,22 +59,37 @@ void ByChainColorOp::ApplyTo(GfxObjP& objP) const{ } } -gfx::Color ByChainColorOp::GetColor(String ident) const{ - if(colors_.find(ident) == colors_.end()) - { - colors_[ident] = GenerateColor(ident); +/* + The first chain will be assigned a gradient stop of 0. + The next chain will be assigned a gradient stop of n/(N-1), where + n is the number of chains assigned so far, and N is the total + number of chains; thus for 3 total chains, the second gets a stop + of 0.5 (1/(3-1)), and the third gets a stop of 1.0 (2/(3-1)) +*/ +gfx::Color ByChainColorOp::GetColor(const String& ident) const +{ + std::map<String,Color>::const_iterator cit = colors_.find(ident); + if(cit == colors_.end()) { + float f = static_cast<float>(colors_.size())*cm_; + Color c = color_grad_.GetColorAt(f); + colors_[ident] = c; + return c; + } else { + return cit->second; } - return colors_[ident]; } -int ByChainColorOp::GetChainCount() const +unsigned int ByChainColorOp::GetChainCount() const { return chain_count_; } -void ByChainColorOp::SetChainCount(int chain_count) +void ByChainColorOp::SetChainCount(unsigned int chain_count) { chain_count_ = chain_count; + cm_=chain_count>1 ? 1.0/static_cast<float>(chain_count_-1) : 0.0; + // invalidate all assigned colors so far + colors_.clear(); } gfx::ByChainColorOp ByChainColorOp::FromInfo(info::InfoGroup& group){ @@ -84,16 +99,5 @@ gfx::ByChainColorOp ByChainColorOp::FromInfo(info::InfoGroup& group){ return gfx::ByChainColorOp(wrapper, mask); } -gfx::Color ByChainColorOp::GenerateColor(String& ident) const{ - unsigned int size=colors_.size()-1; - if(size<=0){ - colors_[ident] = color_grad_.GetColorAt(0.0); - } - else{ - colors_[ident] = color_grad_.GetColorAt(float(size) / chain_count_); - } - return colors_[ident]; -} - }} 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 2b41e737fa78e3438a0d69f98d50f85199f77878..58485af37577c0d5848992020608c9a54c593fbd 100644 --- a/modules/gfx/src/color_ops/by_chain_color_op.hh +++ b/modules/gfx/src/color_ops/by_chain_color_op.hh @@ -38,13 +38,14 @@ public: ByChainColorOp(const String& selection, int mask=DETAIL_COLOR|MAIN_COLOR); ByChainColorOp(const mol::QueryViewWrapper& query_view, int mask=DETAIL_COLOR|MAIN_COLOR); + // Color Op interface virtual bool CanApplyTo(const GfxObjP& obj) const; virtual void ApplyTo(GfxObjP& obj) const; - virtual gfx::Color GetColor(String ident) const; - - virtual int GetChainCount() const; - virtual void SetChainCount(int chain_count); + // this interface + Color GetColor(const String& ident) const; + unsigned int GetChainCount() const; + void SetChainCount(unsigned int chain_count); //virtual void ToInfo(info::InfoGroup& group) const; static gfx::ByChainColorOp FromInfo(info::InfoGroup& group); @@ -53,8 +54,9 @@ private: void Init(); gfx::Color GenerateColor(String& ident) const; - mutable int chain_count_; - mutable std::map<String,gfx::Color> colors_; + unsigned int chain_count_; + float cm_; // 1 over chain_count + mutable std::map<String,Color> colors_; gfx::Gradient color_grad_; }; diff --git a/modules/gui/pymod/__init__.py b/modules/gui/pymod/__init__.py index 0d430feefbcd33586d821b1bdf98c61b65391a32..7848916906ee02d47ef8d685c1551051a4e7fd21 100644 --- a/modules/gui/pymod/__init__.py +++ b/modules/gui/pymod/__init__.py @@ -59,7 +59,7 @@ def PickColor(default=gfx.WHITE): qt_color=dialog.getColor(qt_color) if not qt_color.isValid(): return None - return gfx.RGBAb(qt_color.red(), qt_color.green(),qt_color.blue()) + return gfx.RGBb(qt_color.red(), qt_color.green(),qt_color.blue()) def GetMenu(menu_name, create=False): persp=GostyApp.Instance().perspective