00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMPDISPLAY_COLORED_H
00009 #define IMPDISPLAY_COLORED_H
00010
00011 #include "display_config.h"
00012
00013 #include "Color.h"
00014 #include <IMP/Decorator.h>
00015
00016 IMPDISPLAY_BEGIN_NAMESPACE
00017
00018
00019
00020
00021
00022 class IMPDISPLAYEXPORT Colored: public Decorator
00023 {
00024 public:
00025 static Colored setup_particle(Particle *p, Color c) {
00026 p->add_attribute(get_color_keys()[0], c.get_red(), false);
00027 p->add_attribute(get_color_keys()[1], c.get_green(), false);
00028 p->add_attribute(get_color_keys()[2], c.get_blue(), false);
00029 return Colored(p);
00030 }
00031
00032 void set_color(const Color &c) {
00033 get_particle()->set_value(get_color_keys()[0], c.get_red());
00034 get_particle()->set_value(get_color_keys()[1], c.get_green());
00035 get_particle()->set_value(get_color_keys()[2], c.get_blue());
00036 }
00037
00038 Color get_color() const {
00039 return Color(get_particle()->get_value(get_color_keys()[0]),
00040 get_particle()->get_value(get_color_keys()[1]),
00041 get_particle()->get_value(get_color_keys()[2]));
00042 }
00043
00044 static bool particle_is_instance(Particle *p) {
00045 IMP_USAGE_CHECK((!p->has_attribute(get_color_keys()[0])
00046 && !p->has_attribute(get_color_keys()[1])
00047 && !p->has_attribute(get_color_keys()[2]))
00048 || (p->has_attribute(get_color_keys()[0])
00049 && p->has_attribute(get_color_keys()[1])
00050 && p->has_attribute(get_color_keys()[2])),
00051 "Only partially colored " << p->get_name());
00052 return p->has_attribute(get_color_keys()[2]);
00053 }
00054
00055 static FloatKeys get_color_keys();
00056
00057 IMP_DECORATOR(Colored, Decorator);
00058 };
00059
00060
00061 IMPDISPLAY_END_NAMESPACE
00062
00063 #endif