1. more pythonic feel:)

2. added CSS color string  parser and  color factory
3. added docs dir
This commit is contained in:
Artem Pavlenko 2005-09-08 13:20:37 +00:00
parent 820b6bb23a
commit f5dda2f207
22 changed files with 563 additions and 175 deletions

View file

@ -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_;
}
};
}

48
include/color_factory.hpp Normal file
View file

@ -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<Color> a(color);
css_color_grammar<actions<Color> > 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

View file

@ -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 <iostream>
#ifndef COLORCUBE_HPP
#define COLORCUBE_HPP
namespace mapnik
{
template <int rLevel,int gLevel,int bLevel>
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<rLevel;++r)
{
for (int g=0;g<gLevel;++g)
{
for (int b=0;b<bLevel;++b)
{
red = std::min(255,r * (255 /(rLevel - 1)));
green = std::min(255,g * (255 /(gLevel - 1)));
blue = std::min(255,b * (255 /(bLevel - 1)));
cube[rgb_level_index(r,g,b)]= (red) | (green<<8) | (blue<<16);
//std::cout<<std::hex<<cube[rgb_level_index(r,g,b)]<<std::dec<<"\n";
++count;
}
}
}
std::cout<<"number of colours="<<count<<"\n";
}
};
//template<int rLevel,int gLevel,int bLevel>
//unsigned color_cube<rLevel,gLevel,bLevel>::cube[color_cube<rLevel,gLevel, bLevel>::maxcolors];
template<int rLevel,int gLevel,int bLevel>
unsigned color_cube<rLevel,gLevel,bLevel>::rDiv=52;
template<int rLevel,int gLevel,int bLevel>
unsigned color_cube<rLevel,gLevel,bLevel>::gDiv=52;
template<int rLevel,int gLevel,int bLevel>
unsigned color_cube<rLevel,gLevel,bLevel>::bDiv=52;
template<int rLevel,int gLevel,int bLevel>
bool color_cube<rLevel,gLevel,bLevel>::initialized=false;
}
#endif

View file

@ -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 <boost/spirit/core.hpp>
#include <boost/spirit/symbols.hpp>
using namespace boost::spirit;
namespace mapnik
{
template <typename ColorT>
struct named_colors : public symbols<ColorT>
{
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 <typename ActionsT>
struct css_color_grammar : public grammar<css_color_grammar<ActionsT> >
{
css_color_grammar(ActionsT& actions_)
: actions(actions_) {}
template <typename ScannerT>
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<ScannerT> rgb;
boost::spirit::rule<ScannerT> rgb_percent;
boost::spirit::rule<ScannerT> hex6;
boost::spirit::rule<ScannerT> hex3;
boost::spirit::rule<ScannerT> css_color;
boost::spirit::rule<ScannerT> const& start() const
{
return css_color;
}
uint_parser<unsigned, 10, 1, 3> uint3_p;
uint_parser<unsigned, 16, 6, 6> uint6x_p;
uint_parser<unsigned, 16, 3, 3> uint3x_p;
named_colors<typename ActionsT::color_type> named_colors_p;
};
ActionsT& actions;
};
template <typename ColorT>
struct named_color_action
{
named_color_action(ColorT& c)
: c_(c) {}
void operator() (ColorT const&c) const
{
c_=c;
}
ColorT& c_;
};
template <typename ColorT>
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 <typename ColorT>
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 <typename ColorT>
struct red_action
{
red_action(ColorT& c)
: c_(c) {}
void operator () (unsigned int r) const
{
c_.set_red(r);
}
ColorT& c_;
};
template <typename ColorT>
struct green_action
{
green_action(ColorT& c)
: c_(c) {}
void operator () (unsigned int g) const
{
c_.set_green(g);
}
ColorT& c_;
};
template <typename ColorT>
struct blue_action
{
blue_action(ColorT& c)
: c_(c) {}
void operator () (unsigned int b) const
{
c_.set_blue(b);
}
ColorT& c_;
};
template <typename ColorT>
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 <typename ColorT>
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 <typename ColorT>
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 <typename ColorT>
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<ColorT> named_;
hex6_action<ColorT> hex6_;
hex3_action<ColorT> hex3_;
red_action<ColorT> red_;
green_action<ColorT> green_;
blue_action<ColorT> blue_;
red_action_p<ColorT> red_p_;
green_action_p<ColorT> green_p_;
blue_action_p<ColorT> blue_p_;
};
}
#endif //CSS_COLOR_PARSER_HPP

View file

@ -29,11 +29,11 @@
namespace mapnik
{
typedef rule<Feature,filter> rule_type;
typedef std::vector<rule_type> rules;
class feature_type_style
{
private:
std::vector<rule_type> rules_;
rules rules_;
public:
feature_type_style() {}
@ -51,7 +51,7 @@ namespace mapnik
{
rules_.push_back(rule);
}
const std::vector<rule_type>& rules() const
rules const& get_rules() const
{
return rules_;
}

View file

@ -355,7 +355,7 @@ namespace mapnik
string_ = confix_p(L'\'',(*lex_escape_ch_p)
[push_string<FeatureT>(self.exprs)],
'\'');
L'\'');
property = L'[' >> ( (Letter | L'_' | L':')
>> *NameChar )[push_property<FeatureT>(self.exprs)] >> L']';

View file

@ -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);

View file

@ -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"

View file

@ -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<Layer> const& layers() const;
int getWidth() const;
int getHeight() const;
int srid() const;

View file

@ -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
{

View file

@ -31,7 +31,7 @@
namespace mapnik
{
template <typename T, typename PoolT>
template <typename T, typename PoolT>
class PoolGuard
{
private:

View file

@ -56,19 +56,11 @@ namespace mapnik
syms_(),
filter_(new all_filter<FeatureT>),
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<double>::infinity()),
syms_(),
filter_(new all_filter<FeatureT>),
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<double>::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;

View file

@ -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 <vector>
#include <algorithm>

View file

@ -19,10 +19,12 @@
//$Id: mapnik_color.cc 17 2005-03-08 23:58:43Z pavlenko $
#include <mapnik.hpp>
#include <boost/python.hpp>
#include <mapnik.hpp>
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>("color",init<>())
.def(init<int,int,int>())
.def("red",&Color::red)
.def("green",&Color::green)
.def("blue",&Color::blue)
.def(init<int,int,int,boost::python::optional<int> >())
.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);
}

View file

@ -22,6 +22,7 @@
#include <mapnik.hpp>
#include <boost/python.hpp>
#include <boost/python/detail/api_placeholder.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
using mapnik::Layer;
using mapnik::Parameters;
@ -42,8 +43,8 @@ struct layer_pickle_suite : boost::python::pickle_suite
std::vector<std::string> const& styles=l.styles();
std::vector<std::string>::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<double>(state[0]));
l.setMaxZoom(extract<double>(state[1]));
list styles=extract<list>(state[2]);
boost::python::list styles=extract<boost::python::list>(state[2]);
for (int i=0;i<len(styles);++i)
{
l.add_style(extract<std::string>(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<len(keys);++i)
{
std::string key=extract<std::string>(keys[i]);
@ -100,14 +101,18 @@ namespace
void export_layer()
{
using namespace boost::python;
class_<Layer>("layer",init<const Parameters&>("Layer constructor"))
//class_<Layer>("layer",no_init)
class_<std::vector<std::string> >("styles")
.def(vector_indexing_suite<std::vector<std::string>,true >())
;
//class_<Layer>("layer",init<const Parameters&>("Layer constructor"))
class_<Layer>("layer",no_init)
.def("name",&Layer::name,return_value_policy<copy_const_reference>())
.def("params",&Layer::params,return_value_policy<reference_existing_object>())
.def("envelope",&Layer::envelope,return_value_policy<reference_existing_object>())
.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<reference_existing_object>()))
.def_pickle(layer_pickle_suite())
;
def("create_layer",&create_layer);

View file

@ -21,6 +21,7 @@
#include <mapnik.hpp>
#include <boost/python.hpp>
#include <boost/python/detail/api_placeholder.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
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<m.layerCount();++i)
{
l.append(m.getLayer(i));
@ -65,7 +64,7 @@ struct map_pickle_suite : boost::python::pickle_suite
Color bg = extract<Color>(state[1]);
m.zoomToBox(ext);
m.setBackground(bg);
list l=extract<list>(state[2]);
boost::python::list l=extract<boost::python::list>(state[2]);
for (int i=0;i<len(l);++i)
{
m.addLayer(extract<Layer>(l[i]));
@ -76,17 +75,23 @@ struct map_pickle_suite : boost::python::pickle_suite
void export_map()
{
using namespace boost::python;
class_<std::vector<Layer> >("layers")
.def(vector_indexing_suite<std::vector<Layer> >())
;
class_<Map>("map",init<int,int,boost::python::optional<int> >())
.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<copy_const_reference>()),
&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<reference_existing_object>())
.def_pickle(map_pickle_suite())
;
}

View file

@ -67,7 +67,7 @@ struct parameters_pickle_suite : boost::python::pickle_suite
throw_error_already_set();
}
dict d = extract<dict>(state[0]);
list keys=d.keys();
boost::python::list keys=d.keys();
for (int i=0;i<len(keys);++i)
{
std::string key=extract<std::string>(keys[i]);

View file

@ -112,9 +112,12 @@ BOOST_PYTHON_MODULE(_mapnik)
.def("envelope",&datasource::envelope,
return_value_policy<reference_existing_object>())
;
class_<symbolizer,boost::noncopyable> ("symbolizer",no_init)
;
class_<symbolizer,boost::noncopyable> ("symbolizer_",no_init)
;
class_<ref_ptr<symbolizer,mapnik::DefaultDeletePolicy>,
boost::noncopyable>("symbolizer",no_init)
;
export_parameters();
export_color();
export_envelope();

View file

@ -32,32 +32,33 @@ void export_rule()
{
using namespace boost::python;
class_<symbolizers>("symbolizers",init<>("symbolizers TODO"))
class_<symbolizers>("symbolizers",init<>("TODO"))
.def(vector_indexing_suite<symbolizers>())
;
class_<rule_type>("rule",init<>("default rule constructor"))
//name,title
.def(init<std::string,std::string>())
//name,title,min_scale_denominator,max_scale_denominator
.def(init<std::string,std::string,double,double>())
.def("name",&rule_type::get_name,return_value_policy<copy_const_reference>())
.def("name",&rule_type::set_name)
.def("title",&rule_type::get_title,return_value_policy<copy_const_reference>())
.def("title",&rule_type::set_title)
.def("abstract",&rule_type::get_abstract,return_value_policy<copy_const_reference>())
.def("abstract",&rule_type::set_abstract)
.def("filter",&rule_type::get_filter,return_value_policy<copy_const_reference>())
.def("filter",&rule_type::set_filter)
class_<rule_type>("rule",init<>("default ctor"))
.def(init<std::string const&,
boost::python::optional<std::string const&,double,double> >())
.add_property("name",make_function
(&rule_type::get_name,
return_value_policy<copy_const_reference>()),
&rule_type::set_name)
.add_property("title",make_function
(&rule_type::get_title,return_value_policy<copy_const_reference>()),
&rule_type::set_title)
.add_property("abstract",make_function
(&rule_type::get_abstract,return_value_policy<copy_const_reference>()),
&rule_type::set_abstract)
.add_property("filter",make_function
(&rule_type::get_filter,return_value_policy<copy_const_reference>()),
&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<copy_const_reference>())
.add_property("symbols",make_function
(&rule_type::get_symbolizers,return_value_policy<reference_existing_object>()))
;
}

View file

@ -20,18 +20,24 @@
#include "mapnik.hpp"
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
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>("rules",init<>("default ctor"))
.def(vector_indexing_suite<rules>())
;
class_<feature_type_style>("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<reference_existing_object>()))
;
class_<singleton<named_style_cache,CreateStatic>,boost::noncopyable>("singleton",no_init)

View file

@ -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_;

View file

@ -68,12 +68,15 @@ namespace mapnik
{
//todo
}
const Layer& Map::getLayer(size_t index) const
{
return layers_[index];
}
std::vector<Layer> const& Map::layers() const
{
return layers_;
}
int Map::getWidth() const
{
return width_;