From f5dda2f207390537c6bdd250df56cad31661b3df Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Thu, 8 Sep 2005 13:20:37 +0000 Subject: [PATCH] 1. more pythonic feel:) 2. added CSS color string parser and color factory 3. added docs dir --- include/color.hpp | 40 ++-- include/color_factory.hpp | 48 +++++ include/colorcube.hpp | 90 -------- include/css_color_parser.hpp | 384 +++++++++++++++++++++++++++++++++ include/feature_type_style.hpp | 6 +- include/filter_parser.hpp | 2 +- include/layer.hpp | 5 +- include/line_symbolizer.hpp | 2 - include/map.hpp | 1 + include/mapnik.hpp | 3 +- include/pool.hpp | 2 +- include/rule.hpp | 24 +-- include/style.hpp | 2 - python/mapnik_color.cpp | 21 +- python/mapnik_layer.cpp | 23 +- python/mapnik_map.cpp | 17 +- python/mapnik_parameters.cpp | 2 +- python/mapnik_python.cpp | 7 +- python/mapnik_rule.cpp | 37 ++-- python/mapnik_style.cpp | 10 +- src/layer.cpp | 5 + src/map.cpp | 7 +- 22 files changed, 563 insertions(+), 175 deletions(-) create mode 100644 include/color_factory.hpp delete mode 100644 include/colorcube.hpp create mode 100644 include/css_color_parser.hpp diff --git a/include/color.hpp b/include/color.hpp index fc74b9bcb..d6d923c1a 100644 --- a/include/color.hpp +++ b/include/color.hpp @@ -26,7 +26,7 @@ namespace mapnik { class Color { private: - int rgba_; + unsigned int rgba_; public: Color() :rgba_(0xffffffff) {} @@ -46,11 +46,11 @@ namespace mapnik { rgba_=rhs.rgba_; return *this; } - inline int blue() const + inline unsigned int blue() const { return (rgba_>>16)&0xff; } - inline int green() const + inline unsigned int green() const { return (rgba_>>8)&0xff; } @@ -58,23 +58,39 @@ namespace mapnik { { return rgba_&0xff; } + + inline void set_red(unsigned int r) + { + rgba_ = (rgba_ & 0xffffff00) | (r&0xff); + } + + inline void set_green(unsigned int g) + { + rgba_ = (rgba_ & 0xffff00ff) | ((g&0xff) << 8); + } + + inline void set_blue(unsigned int b) + { + rgba_ = (rgba_ & 0xff00ffff) | ((b&0xff) << 16); + } - inline int alpha() const + inline unsigned int alpha() const { return (rgba_>>24)&0xff; } - inline int rgba() const + inline unsigned int rgba() const { return rgba_; } - static const Color White; - static const Color Black; - static const Color Gray; - static const Color Red; - static const Color Green; - static const Color Blue; - static const Color Yellow; + inline void set_bgr(unsigned bgr) + { + rgba_ = (rgba_ & 0xff000000) | (bgr & 0xffffff); + } + inline bool operator==(Color const& other) const + { + return rgba_ == other.rgba_; + } }; } diff --git a/include/color_factory.hpp b/include/color_factory.hpp new file mode 100644 index 000000000..88c288d28 --- /dev/null +++ b/include/color_factory.hpp @@ -0,0 +1,48 @@ +/* This file is part of Mapnik (c++ mapping toolkit) + * Copyright (C) 2005 Artem Pavlenko + * + * Mapnik is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +//$Id$ + +#ifndef COLOR_FACTORY_HPP +#define COLOR_FACTORY_HPP + +#include "css_color_parser.hpp" + +namespace mapnik +{ + using namespace boost::spirit; + class color_factory + { + public: + static Color from_string(char const* css_color) + { + Color color; + actions a(color); + css_color_grammar > grammar(a); + parse_info<> info = parse(css_color, grammar, space_p); + if (info.full) return color; + return Color(0,0,0); + } + private: + color_factory(); + color_factory(color_factory const&); + color_factory& operator=(color_factory const&); + }; +} + +#endif //COLOR_FACTORY_HPP diff --git a/include/colorcube.hpp b/include/colorcube.hpp deleted file mode 100644 index c20a525ea..000000000 --- a/include/colorcube.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/* This file is part of Mapnik (c++ mapping toolkit) - * Copyright (C) 2005 Artem Pavlenko - * - * Mapnik is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -//$Id$ - -#include - -#ifndef COLORCUBE_HPP -#define COLORCUBE_HPP - - -namespace mapnik -{ - template - struct color_cube - { - const static unsigned maxcolors=rLevel * gLevel * bLevel + 32; - static unsigned cube[maxcolors]; - static bool initialized; - static unsigned rDiv; - static unsigned gDiv; - static unsigned bDiv; - - static unsigned color(unsigned red,unsigned green,unsigned blue) - { - if (!initialized) - init(); - unsigned index=rgb_level_index(red/rDiv,green/gDiv,blue/bDiv); - return cube[index]; - } - - private: - static unsigned rgb_level_index(unsigned red,unsigned green,unsigned blue) - { - return (red * gLevel * bLevel + green * bLevel + blue); - } - - static void init() - { - unsigned red,green,blue; - unsigned count=0; - for (int r=0;r - //unsigned color_cube::cube[color_cube::maxcolors]; - template - unsigned color_cube::rDiv=52; - template - unsigned color_cube::gDiv=52; - template - unsigned color_cube::bDiv=52; - template - bool color_cube::initialized=false; -} - -#endif diff --git a/include/css_color_parser.hpp b/include/css_color_parser.hpp new file mode 100644 index 000000000..293a7c911 --- /dev/null +++ b/include/css_color_parser.hpp @@ -0,0 +1,384 @@ +/* This file is part of Mapnik (c++ mapping toolkit) + * Copyright (C) 2005 Artem Pavlenko + * + * Mapnik is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +//$Id$ + +#ifndef CSS_COLOR_PARSER_HPP +#define CSS_COLOR_PARSER_HPP + +#include +#include + +using namespace boost::spirit; + +namespace mapnik +{ + template + struct named_colors : public symbols + { + named_colors() + { + add + ("aliceblue", ColorT(240, 248, 255)) + ("antiquewhite", ColorT(250, 235, 215)) + ("aqua", ColorT(0, 255, 255)) + ("aquamarine", ColorT(127, 255, 212)) + ("azure", ColorT(240, 255, 255)) + ("beige", ColorT(245, 245, 220)) + ("bisque", ColorT(255, 228, 196)) + ("black", ColorT(0, 0, 0)) + ("blanchedalmond", ColorT(255,235,205)) + ("blue", ColorT(0, 0, 255)) + ("blueviolet", ColorT(138, 43, 226)) + ("brown", ColorT(165, 42, 42)) + ("burlywood", ColorT(222, 184, 135)) + ("cadetblue", ColorT(95, 158, 160)) + ("chartreuse", ColorT(127, 255, 0)) + ("chocolate", ColorT(210, 105, 30)) + ("coral", ColorT(255, 127, 80)) + ("cornflowerblue", ColorT(100, 149, 237)) + ("cornsilk", ColorT(255, 248, 220)) + ("crimson", ColorT(220, 20, 60)) + ("cyan", ColorT(0, 255, 255)) + ("darkblue", ColorT(0, 0, 139)) + ("darkcyan", ColorT(0, 139, 139)) + ("darkgoldenrod", ColorT(184, 134, 11)) + ("darkgray", ColorT(169, 169, 169)) + ("darkgreen", ColorT(0, 100, 0)) + ("darkgrey", ColorT(169, 169, 169)) + ("darkkhaki", ColorT(189, 183, 107)) + ("darkmagenta", ColorT(139, 0, 139)) + ("darkolivegreen", ColorT(85, 107, 47)) + ("darkorange", ColorT(255, 140, 0)) + ("darkorchid", ColorT(153, 50, 204)) + ("darkred", ColorT(139, 0, 0)) + ("darksalmon", ColorT(233, 150, 122)) + ("darkseagreen", ColorT(143, 188, 143)) + ("darkslateblue", ColorT(72, 61, 139)) + ("darkslategrey", ColorT(47, 79, 79)) + ("darkturquoise", ColorT(0, 206, 209)) + ("darkviolet", ColorT(148, 0, 211)) + ("deeppink", ColorT(255, 20, 147)) + ("deepskyblue", ColorT(0, 191, 255)) + ("dimgray", ColorT(105, 105, 105)) + ("dimgrey", ColorT(105, 105, 105)) + ("dodgerblue", ColorT(30, 144, 255)) + ("firebrick", ColorT(178, 34, 34)) + ("floralwhite", ColorT(255, 250, 240)) + ("forestgreen", ColorT(34, 139, 34)) + ("fuchsia", ColorT(255, 0, 255)) + ("gainsboro", ColorT(220, 220, 220)) + ("ghostwhite", ColorT(248, 248, 255)) + ("gold", ColorT(255, 215, 0)) + ("goldenrod", ColorT(218, 165, 32)) + ("gray", ColorT(128, 128, 128)) + ("grey", ColorT(128, 128, 128)) + ("green", ColorT(0, 128, 0)) + ("greenyellow", ColorT(173, 255, 47)) + ("honeydew", ColorT(240, 255, 240)) + ("hotpink", ColorT(255, 105, 180)) + ("indianred", ColorT(205, 92, 92)) + ("indigo", ColorT(75, 0, 130)) + ("ivory", ColorT(255, 255, 240)) + ("khaki", ColorT(240, 230, 140)) + ("lavender", ColorT(230, 230, 250)) + ("lavenderblush", ColorT(255, 240, 245)) + ("lawngreen", ColorT(124, 252, 0)) + ("lemonchiffon", ColorT(255, 250, 205)) + ("lightblue", ColorT(173, 216, 230)) + ("lightcoral", ColorT(240, 128, 128)) + ("lightcyan", ColorT(224, 255, 255)) + ("lightgoldenrodyellow", ColorT(250, 250, 210)) + ("lightgray", ColorT(211, 211, 211)) + ("lightgreen", ColorT(144, 238, 144)) + ("lightgrey", ColorT(211, 211, 211)) + ("lightpink", ColorT(255, 182, 193)) + ("lightsalmon", ColorT(255, 160, 122)) + ("lightseagreen", ColorT(32, 178, 170)) + ("lightskyblue", ColorT(135, 206, 250)) + ("lightslategray", ColorT(119, 136, 153)) + ("lightslategrey", ColorT(119, 136, 153)) + ("lightsteelblue", ColorT(176, 196, 222)) + ("lightyellow", ColorT(255, 255, 224)) + ("lime", ColorT(0, 255, 0)) + ("limegreen", ColorT(50, 205, 50)) + ("linen", ColorT(250, 240, 230)) + ("magenta", ColorT(255, 0, 255)) + ("maroon", ColorT(128, 0, 0)) + ("mediumaquamarine", ColorT(102, 205, 170)) + ("mediumblue", ColorT(0, 0, 205)) + ("mediumorchid", ColorT(186, 85, 211)) + ("mediumpurple", ColorT(147, 112, 219)) + ("mediumseagreen", ColorT(60, 179, 113)) + ("mediumslateblue", ColorT(123, 104, 238)) + ("mediumspringgreen", ColorT(0, 250, 154)) + ("mediumturquoise", ColorT(72, 209, 204)) + ("mediumvioletred", ColorT(199, 21, 133)) + ("midnightblue", ColorT(25, 25, 112)) + ("mintcream", ColorT(245, 255, 250)) + ("mistyrose", ColorT(255, 228, 225)) + ("moccasin", ColorT(255, 228, 181)) + ("navajowhite", ColorT(255, 222, 173)) + ("navy", ColorT(0, 0, 128)) + ("oldlace", ColorT(253, 245, 230)) + ("olive", ColorT(128, 128, 0)) + ("olivedrab", ColorT(107, 142, 35)) + ("orange", ColorT(255, 165, 0)) + ("orangered", ColorT(255, 69, 0)) + ("orchid", ColorT(218, 112, 214)) + ("palegoldenrod", ColorT(238, 232, 170)) + ("palegreen", ColorT(152, 251, 152)) + ("paleturquoise", ColorT(175, 238, 238)) + ("palevioletred", ColorT(219, 112, 147)) + ("papayawhip", ColorT(255, 239, 213)) + ("peachpuff", ColorT(255, 218, 185)) + ("peru", ColorT(205, 133, 63)) + ("pink", ColorT(255, 192, 203)) + ("plum", ColorT(221, 160, 221)) + ("powderblue", ColorT(176, 224, 230)) + ("purple", ColorT(128, 0, 128)) + ("red", ColorT(255, 0, 0)) + ("rosybrown", ColorT(188, 143, 143)) + ("royalblue", ColorT(65, 105, 225)) + ("saddlebrown", ColorT(139, 69, 19)) + ("salmon", ColorT(250, 128, 114)) + ("sandybrown", ColorT(244, 164, 96)) + ("seagreen", ColorT(46, 139, 87)) + ("seashell", ColorT(255, 245, 238)) + ("sienna", ColorT(160, 82, 45)) + ("silver", ColorT(192, 192, 192)) + ("skyblue", ColorT(135, 206, 235)) + ("slateblue", ColorT(106, 90, 205)) + ("slategray", ColorT(112, 128, 144)) + ("slategrey", ColorT(112, 128, 144)) + ("snow", ColorT(255, 250, 250)) + ("springgreen", ColorT(0, 255, 127)) + ("steelblue", ColorT(70, 130, 180)) + ("tan", ColorT(210, 180, 140)) + ("teal", ColorT(0, 128, 128)) + ("thistle", ColorT(216, 191, 216)) + ("tomato", ColorT(255, 99, 71)) + ("turquoise", ColorT(64, 224, 208)) + ("violet", ColorT(238, 130, 238)) + ("wheat", ColorT(245, 222, 179)) + ("white", ColorT(255, 255, 255)) + ("whitesmoke", ColorT(245, 245, 245)) + ("yellow", ColorT(255, 255, 0)) + ("yellowgreen", ColorT(154, 205, 50)) + ; + } + }; + + template + struct css_color_grammar : public grammar > + { + css_color_grammar(ActionsT& actions_) + : actions(actions_) {} + + template + struct definition + { + definition(css_color_grammar const& self) + { + hex6 = ch_p('#') >> uint6x_p[self.actions.hex6_]; + hex3 = ch_p('#') >> uint3x_p[self.actions.hex3_]; + rgb = str_p("rgb") >> '(' >> uint3_p[self.actions.red_] + >> ',' >> uint3_p[self.actions.green_] + >> ',' >> uint3_p[self.actions.blue_] + >> ')'; + rgb_percent = str_p("rgb") >> '(' >> ureal_p[self.actions.red_p_] >> '%' + >> ',' >> ureal_p[self.actions.green_p_] >> '%' + >> ',' >> ureal_p[self.actions.blue_p_] >> '%' + >> ')'; + css_color = named_colors_p[self.actions.named_] | hex6 | hex3 | rgb_percent | rgb; + } + boost::spirit::rule rgb; + boost::spirit::rule rgb_percent; + boost::spirit::rule hex6; + boost::spirit::rule hex3; + boost::spirit::rule css_color; + boost::spirit::rule const& start() const + { + return css_color; + } + uint_parser uint3_p; + uint_parser uint6x_p; + uint_parser uint3x_p; + named_colors named_colors_p; + + }; + ActionsT& actions; + }; + + template + struct named_color_action + { + named_color_action(ColorT& c) + : c_(c) {} + + void operator() (ColorT const&c) const + { + c_=c; + } + ColorT& c_; + }; + + template + struct hex6_action + { + hex6_action(ColorT& c) + : c_(c) {} + + void operator () (unsigned int hex) const + { + unsigned r = (hex >> 16) & 0xff; + unsigned g = (hex >> 8) & 0xff; + unsigned b = hex & 0xff; + c_.set_red(r); + c_.set_green(g); + c_.set_blue(b); + } + ColorT& c_; + }; + + template + struct hex3_action + { + hex3_action(ColorT& c) + : c_(c) {} + + void operator () (unsigned int hex) const + { + unsigned int r = (hex >> 8) & 0xf; + unsigned int g = (hex >> 4) & 0xf; + unsigned int b = hex & 0xf; + c_.set_red( r | r << 4); + c_.set_green(g | g << 4); + c_.set_blue(b | b << 4); + } + ColorT& c_; + }; + + template + struct red_action + { + red_action(ColorT& c) + : c_(c) {} + + void operator () (unsigned int r) const + { + c_.set_red(r); + } + ColorT& c_; + }; + + template + struct green_action + { + green_action(ColorT& c) + : c_(c) {} + + void operator () (unsigned int g) const + { + c_.set_green(g); + } + ColorT& c_; + }; + + template + struct blue_action + { + blue_action(ColorT& c) + : c_(c) {} + + void operator () (unsigned int b) const + { + c_.set_blue(b); + } + ColorT& c_; + }; + + + template + struct red_action_p + { + red_action_p(ColorT& c) + : c_(c) {} + + void operator () (double r) const + { + c_.set_red(unsigned((255.0 * r)/100.0)); + } + ColorT& c_; + }; + + template + struct green_action_p + { + green_action_p(ColorT& c) + : c_(c) {} + + void operator () (double g) const + { + c_.set_green(unsigned((255.0 * g)/100.0)); + } + ColorT& c_; + }; + + template + struct blue_action_p + { + blue_action_p(ColorT& c) + : c_(c) {} + + void operator () (double b) const + { + c_.set_blue(unsigned((255.0 * b)/100.0)); + } + ColorT& c_; + }; + + + template + struct actions + { + typedef ColorT color_type; + actions(ColorT& c) + : named_(c), + hex6_(c), + hex3_(c), + red_(c), + green_(c), + blue_(c), + red_p_(c), + green_p_(c), + blue_p_(c) {} + + named_color_action named_; + hex6_action hex6_; + hex3_action hex3_; + red_action red_; + green_action green_; + blue_action blue_; + red_action_p red_p_; + green_action_p green_p_; + blue_action_p blue_p_; + }; +} + +#endif //CSS_COLOR_PARSER_HPP diff --git a/include/feature_type_style.hpp b/include/feature_type_style.hpp index 7121eadbc..952f76ccd 100644 --- a/include/feature_type_style.hpp +++ b/include/feature_type_style.hpp @@ -29,11 +29,11 @@ namespace mapnik { typedef rule rule_type; - + typedef std::vector rules; class feature_type_style { private: - std::vector rules_; + rules rules_; public: feature_type_style() {} @@ -51,7 +51,7 @@ namespace mapnik { rules_.push_back(rule); } - const std::vector& rules() const + rules const& get_rules() const { return rules_; } diff --git a/include/filter_parser.hpp b/include/filter_parser.hpp index 9e3fde45a..9bf9fd7c1 100644 --- a/include/filter_parser.hpp +++ b/include/filter_parser.hpp @@ -355,7 +355,7 @@ namespace mapnik string_ = confix_p(L'\'',(*lex_escape_ch_p) [push_string(self.exprs)], - '\''); + L'\''); property = L'[' >> ( (Letter | L'_' | L':') >> *NameChar )[push_property(self.exprs)] >> L']'; diff --git a/include/layer.hpp b/include/layer.hpp index 5000cb6ee..5724c1855 100644 --- a/include/layer.hpp +++ b/include/layer.hpp @@ -44,8 +44,9 @@ namespace mapnik public: explicit Layer(const Parameters& params); - Layer(const Layer& l); - Layer& operator=(const Layer& l); + Layer(Layer const& l); + Layer& operator=(Layer const& l); + bool operator==(Layer const& other) const; Parameters const& params() const; const std::string& name() const; void add_style(std::string const& stylename); diff --git a/include/line_symbolizer.hpp b/include/line_symbolizer.hpp index 1be7e8a0c..c4d9fee05 100644 --- a/include/line_symbolizer.hpp +++ b/include/line_symbolizer.hpp @@ -25,10 +25,8 @@ #include "agg_rendering_buffer.h" #include "agg_rasterizer_scanline_aa.h" #include "agg_conv_stroke.h" -#include "agg_conv_curve.h" #include "agg_conv_dash.h" #include "agg_conv_contour.h" -#include "agg_conv_stroke.h" #include "agg_vcgen_stroke.h" #include "agg_conv_adaptor_vcgen.h" #include "agg_conv_smooth_poly1.h" diff --git a/include/map.hpp b/include/map.hpp index 8d03f8538..0b62edebf 100644 --- a/include/map.hpp +++ b/include/map.hpp @@ -45,6 +45,7 @@ namespace mapnik const Layer& getLayer(size_t index) const; void removeLayer(size_t index); void removeLayer(const char* lName); + std::vector const& layers() const; int getWidth() const; int getHeight() const; int srid() const; diff --git a/include/mapnik.hpp b/include/mapnik.hpp index 155c890cf..0c5e068aa 100644 --- a/include/mapnik.hpp +++ b/include/mapnik.hpp @@ -56,7 +56,6 @@ #include "datasource_cache.hpp" #include "wkb.hpp" #include "map.hpp" -#include "colorcube.hpp" #include "feature_type_style.hpp" #include "math_expr.hpp" #include "value.hpp" @@ -67,6 +66,8 @@ #include "text_symbolizer.hpp" #include "label_placement.hpp" #include "feature_layer_desc.hpp" +#include "css_color_parser.hpp" +#include "color_factory.hpp" namespace mapnik { diff --git a/include/pool.hpp b/include/pool.hpp index 9ec506954..ede9a6990 100644 --- a/include/pool.hpp +++ b/include/pool.hpp @@ -31,7 +31,7 @@ namespace mapnik { - template + template class PoolGuard { private: diff --git a/include/rule.hpp b/include/rule.hpp index 085006fdb..397226b23 100644 --- a/include/rule.hpp +++ b/include/rule.hpp @@ -56,19 +56,11 @@ namespace mapnik syms_(), filter_(new all_filter), else_filter_(false) {} - - rule(const std::string& name,const std::string& title) - : name_(name), - title_(title), - abstract_(), - min_scale_(0), - max_scale_(std::numeric_limits::infinity()), - syms_(), - filter_(new all_filter), - else_filter_(false) {} - - rule(const std::string& name,const std::string& title, - double min_scale_denominator,double max_scale_denominator) + + rule(const std::string& name, + const std::string& title="", + double min_scale_denominator=0, + double max_scale_denominator=std::numeric_limits::infinity()) : name_(name), title_(title), min_scale_(min_scale_denominator), @@ -93,7 +85,11 @@ namespace mapnik swap(tmp); return *this; } - + bool operator==(rule const& other) + { + return (this == &other); + } + void set_max_scale(double scale) { max_scale_=scale; diff --git a/include/style.hpp b/include/style.hpp index bf7a95af5..13bcfc492 100644 --- a/include/style.hpp +++ b/include/style.hpp @@ -21,11 +21,9 @@ #ifndef STYLE_HPP #define STYLE_HPP -//#include "feature.hpp" #include "color.hpp" #include "ptr.hpp" #include "symbolizer.hpp" -//#include "rule.hpp" #include #include diff --git a/python/mapnik_color.cpp b/python/mapnik_color.cpp index 97ac036d6..cc4de37fa 100644 --- a/python/mapnik_color.cpp +++ b/python/mapnik_color.cpp @@ -19,10 +19,12 @@ //$Id: mapnik_color.cc 17 2005-03-08 23:58:43Z pavlenko $ -#include + #include +#include using mapnik::Color; +using mapnik::color_factory; struct color_pickle_suite : boost::python::pickle_suite { @@ -34,17 +36,22 @@ struct color_pickle_suite : boost::python::pickle_suite } }; +Color create_from_string(const char* str) +{ + return color_factory::from_string(str); +} + void export_color () { using namespace boost::python; class_("color",init<>()) - .def(init()) - .def("red",&Color::red) - .def("green",&Color::green) - .def("blue",&Color::blue) + .def(init >()) + .add_property("r",&Color::red,&Color::set_red) + .add_property("g",&Color::green,&Color::set_green) + .add_property("b",&Color::blue,&Color::set_blue) + .add_property("a",&Color::alpha) .def_pickle(color_pickle_suite()) ; + def("color_from_string",&create_from_string); } - - diff --git a/python/mapnik_layer.cpp b/python/mapnik_layer.cpp index d68fb390a..68a9a5803 100644 --- a/python/mapnik_layer.cpp +++ b/python/mapnik_layer.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using mapnik::Layer; using mapnik::Parameters; @@ -42,8 +43,8 @@ struct layer_pickle_suite : boost::python::pickle_suite std::vector const& styles=l.styles(); std::vector::const_iterator itr=styles.begin(); - list py_styles; - + boost::python::list py_styles; + while (itr!=styles.end()) { py_styles.append(*itr++); @@ -70,7 +71,7 @@ struct layer_pickle_suite : boost::python::pickle_suite l.setMinZoom(extract(state[0])); l.setMaxZoom(extract(state[1])); - list styles=extract(state[2]); + boost::python::list styles=extract(state[2]); for (int i=0;i(styles[i])); @@ -85,7 +86,7 @@ namespace Layer create_layer(const dict& d) { Parameters params; - list keys=d.keys(); + boost::python::list keys=d.keys(); for (int i=0;i(keys[i]); @@ -100,14 +101,18 @@ namespace void export_layer() { using namespace boost::python; - class_("layer",init("Layer constructor")) - //class_("layer",no_init) + class_ >("styles") + .def(vector_indexing_suite,true >()) + ; + //class_("layer",init("Layer constructor")) + class_("layer",no_init) .def("name",&Layer::name,return_value_policy()) .def("params",&Layer::params,return_value_policy()) .def("envelope",&Layer::envelope,return_value_policy()) - .def("minzoom",&Layer::setMinZoom) - .def("maxzoom",&Layer::setMaxZoom) - .def("style",&Layer::add_style) + .add_property("minzoom",&Layer::getMinZoom,&Layer::setMinZoom) + .add_property("maxzoom",&Layer::getMaxZoom,&Layer::setMaxZoom) + .add_property("styles",make_function + (&Layer::styles,return_value_policy())) .def_pickle(layer_pickle_suite()) ; def("create_layer",&create_layer); diff --git a/python/mapnik_map.cpp b/python/mapnik_map.cpp index 9e8bf22a1..453a9177c 100644 --- a/python/mapnik_map.cpp +++ b/python/mapnik_map.cpp @@ -21,6 +21,7 @@ #include #include #include +#include using mapnik::Color; using mapnik::coord; @@ -33,15 +34,13 @@ struct map_pickle_suite : boost::python::pickle_suite static boost::python::tuple getinitargs(const Map& m) { - using namespace boost::python; return boost::python::make_tuple(m.getWidth(),m.getHeight(),m.srid()); } static boost::python::tuple getstate(const Map& m) { - using namespace boost::python; - list l; + boost::python::list l; for (unsigned i=0;i(state[1]); m.zoomToBox(ext); m.setBackground(bg); - list l=extract(state[2]); + boost::python::list l=extract(state[2]); for (int i=0;i(l[i])); @@ -76,17 +75,23 @@ struct map_pickle_suite : boost::python::pickle_suite void export_map() { using namespace boost::python; + class_ >("layers") + .def(vector_indexing_suite >()) + ; class_("map",init >()) .add_property("width",&Map::getWidth) .add_property("height",&Map::getHeight) - .def("background",&Map::setBackground) + .add_property("srid",&Map::srid) + .add_property("background",make_function + (&Map::getBackground,return_value_policy()), + &Map::setBackground) .def("scale", &Map::scale) .def("add",&Map::addLayer) .def("zoom_to_box",&Map::zoomToBox) .def("pan",&Map::pan) .def("zoom",&Map::zoom) .def("pan_and_zoom",&Map::pan_and_zoom) + .def("layers",&Map::layers,return_value_policy()) .def_pickle(map_pickle_suite()) ; - } diff --git a/python/mapnik_parameters.cpp b/python/mapnik_parameters.cpp index 526761656..f94dd9176 100644 --- a/python/mapnik_parameters.cpp +++ b/python/mapnik_parameters.cpp @@ -67,7 +67,7 @@ struct parameters_pickle_suite : boost::python::pickle_suite throw_error_already_set(); } dict d = extract(state[0]); - list keys=d.keys(); + boost::python::list keys=d.keys(); for (int i=0;i(keys[i]); diff --git a/python/mapnik_python.cpp b/python/mapnik_python.cpp index 18af42191..a9596420a 100644 --- a/python/mapnik_python.cpp +++ b/python/mapnik_python.cpp @@ -112,9 +112,12 @@ BOOST_PYTHON_MODULE(_mapnik) .def("envelope",&datasource::envelope, return_value_policy()) ; - class_ ("symbolizer",no_init) - ; + class_ ("symbolizer_",no_init) + ; + class_, + boost::noncopyable>("symbolizer",no_init) + ; export_parameters(); export_color(); export_envelope(); diff --git a/python/mapnik_rule.cpp b/python/mapnik_rule.cpp index fb4472c6d..ecfae90e7 100644 --- a/python/mapnik_rule.cpp +++ b/python/mapnik_rule.cpp @@ -32,32 +32,33 @@ void export_rule() { using namespace boost::python; - class_("symbolizers",init<>("symbolizers TODO")) + class_("symbolizers",init<>("TODO")) .def(vector_indexing_suite()) ; - class_("rule",init<>("default rule constructor")) - //name,title - .def(init()) - //name,title,min_scale_denominator,max_scale_denominator - .def(init()) - .def("name",&rule_type::get_name,return_value_policy()) - .def("name",&rule_type::set_name) - .def("title",&rule_type::get_title,return_value_policy()) - .def("title",&rule_type::set_title) - .def("abstract",&rule_type::get_abstract,return_value_policy()) - .def("abstract",&rule_type::set_abstract) - .def("filter",&rule_type::get_filter,return_value_policy()) - .def("filter",&rule_type::set_filter) + class_("rule",init<>("default ctor")) + .def(init >()) + .add_property("name",make_function + (&rule_type::get_name, + return_value_policy()), + &rule_type::set_name) + .add_property("title",make_function + (&rule_type::get_title,return_value_policy()), + &rule_type::set_title) + .add_property("abstract",make_function + (&rule_type::get_abstract,return_value_policy()), + &rule_type::set_abstract) + .add_property("filter",make_function + (&rule_type::get_filter,return_value_policy()), + &rule_type::set_filter) .add_property("min_scale",&rule_type::get_min_scale,&rule_type::set_min_scale) .add_property("max_scale",&rule_type::get_max_scale,&rule_type::set_max_scale) .def("set_else",&rule_type::set_else) .def("has_else",&rule_type::has_else_filter) .def("active",&rule_type::active) - .def("append",&rule_type::append) - .def("remove",&rule_type::remove_at) - .def("__iter__",boost::python::range(&rule_type::begin,&rule_type::end)) - .def("symbols",&rule_type::get_symbolizers,return_value_policy()) + .add_property("symbols",make_function + (&rule_type::get_symbolizers,return_value_policy())) ; } diff --git a/python/mapnik_style.cpp b/python/mapnik_style.cpp index e85d6553a..ee5c19b31 100644 --- a/python/mapnik_style.cpp +++ b/python/mapnik_style.cpp @@ -20,18 +20,24 @@ #include "mapnik.hpp" #include +#include using mapnik::feature_type_style; using mapnik::named_style_cache; using mapnik::singleton; using mapnik::CreateStatic; +using mapnik::rules; void export_style() { using namespace boost::python; + + class_("rules",init<>("default ctor")) + .def(vector_indexing_suite()) + ; class_("style",init<>("default style constructor")) - .def("append_rule",&feature_type_style::add_rule) - //.def("rules",&feature_type_style::rules) + .add_property("rules",make_function + (&feature_type_style::get_rules,return_value_policy())) ; class_,boost::noncopyable>("singleton",no_init) diff --git a/src/layer.cpp b/src/layer.cpp index f0312dbbb..00383f759 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -70,6 +70,11 @@ namespace mapnik return *this; } + bool Layer::operator==(Layer const& other) const + { + return (this == &other); + } + void Layer::swap(const Layer& rhs) { params_=rhs.params_; diff --git a/src/map.cpp b/src/map.cpp index 4b7da47d3..751c16850 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -68,12 +68,15 @@ namespace mapnik { //todo } - const Layer& Map::getLayer(size_t index) const { return layers_[index]; } - + std::vector const& Map::layers() const + { + return layers_; + } + int Map::getWidth() const { return width_;