root/trunk/bindings/python/mapnik_symbolizer.cpp

Revision 1814, 5.4 kB (checked in by artem, 2 months ago)

+ apply 'mapnik-format' to *.cpp *.hpp

Line 
1/*****************************************************************************
2 *
3 * This file is part of Mapnik (c++ mapping toolkit)
4 *
5 * Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 *
21 *****************************************************************************/
22//$Id$
23
24#include <boost/python.hpp>
25
26//symbolizer typdef here rather than mapnik/symbolizer.hpp
27#include <mapnik/rule.hpp>
28
29using mapnik::symbolizer;
30
31using mapnik::rule_type;
32using mapnik::point_symbolizer;
33using mapnik::line_symbolizer;
34using mapnik::line_pattern_symbolizer;
35using mapnik::polygon_symbolizer;
36using mapnik::polygon_pattern_symbolizer;
37using mapnik::raster_symbolizer;
38using mapnik::shield_symbolizer;
39using mapnik::text_symbolizer;
40using mapnik::building_symbolizer;
41using mapnik::markers_symbolizer;
42using mapnik::glyph_symbolizer;
43
44struct get_symbolizer_type : public boost::static_visitor<std::string>
45{
46public:
47    get_symbolizer_type() {}
48       
49    std::string operator () ( const  point_symbolizer & sym )
50    {
51        return "point";
52    }
53   
54    std::string operator () ( const line_symbolizer & sym )
55    {
56        return "line";
57    }
58   
59    std::string operator () ( const line_pattern_symbolizer & sym )
60    {
61        return "line_pattern";
62    }
63   
64    std::string operator () ( const polygon_symbolizer & sym )
65    {
66        return "polygon";
67    }
68   
69    std::string operator () ( const polygon_pattern_symbolizer & sym )
70    {
71        return "polygon_pattern";
72    }
73   
74    std::string operator () ( const raster_symbolizer & sym )
75    {
76        return "raster";
77    }
78   
79    std::string operator () ( const shield_symbolizer & sym )
80    {
81        return "shield";
82    }
83   
84    std::string operator () ( const text_symbolizer & sym )
85    {
86        return "text";
87    }
88   
89    std::string operator () ( const building_symbolizer & sym )
90    {
91        return "building";
92    }
93   
94    std::string operator () ( const markers_symbolizer & sym )
95    {
96        return "markers";
97    }
98
99    std::string operator () ( const glyph_symbolizer & sym )
100    {
101        return "glyph";
102    }
103
104};
105
106std::string get_symbol_type(const symbolizer& symbol)
107{
108    get_symbolizer_type serializer;
109    std::string type = boost::apply_visitor( serializer, symbol );
110    return type;
111}
112
113const point_symbolizer& point_( const symbolizer& symbol )
114{
115    return boost::get<point_symbolizer>(symbol);
116}
117
118const line_symbolizer& line_( const symbolizer& symbol )
119{
120    return boost::get<line_symbolizer>(symbol);
121}
122
123const polygon_symbolizer& polygon_( const symbolizer& symbol )
124{
125    return boost::get<polygon_symbolizer>(symbol);
126}
127
128const raster_symbolizer& raster_( const symbolizer& symbol )
129{
130    return boost::get<raster_symbolizer>(symbol);
131}
132
133const text_symbolizer& text_( const symbolizer& symbol )
134{
135    return boost::get<text_symbolizer>(symbol);
136}
137
138const shield_symbolizer& shield_( const symbolizer& symbol )
139{
140    return boost::get<shield_symbolizer>(symbol);
141}
142
143const line_pattern_symbolizer& line_pattern_( const symbolizer& symbol )
144{
145    return boost::get<line_pattern_symbolizer>(symbol);
146}
147
148const polygon_pattern_symbolizer& polygon_pattern_( const symbolizer& symbol )
149{
150    return boost::get<polygon_pattern_symbolizer>(symbol);
151}
152
153const building_symbolizer& building_( const symbolizer& symbol )
154{
155    return boost::get<building_symbolizer>(symbol);
156}
157
158const markers_symbolizer& markers_( const symbolizer& symbol )
159{
160    return boost::get<markers_symbolizer>(symbol);
161}
162
163const glyph_symbolizer& glyph_( const symbolizer& symbol )
164{
165    return boost::get<glyph_symbolizer>(symbol);
166}
167
168void export_symbolizer()
169{
170    using namespace boost::python;
171
172    class_<symbolizer>("Symbolizer",no_init)
173
174        .def("type",get_symbol_type)
175
176        .def("point",point_,
177             return_value_policy<copy_const_reference>())
178
179        .def("line",line_,
180             return_value_policy<copy_const_reference>())
181
182        .def("line_pattern",line_pattern_,
183             return_value_policy<copy_const_reference>())
184
185        .def("polygon",polygon_,
186             return_value_policy<copy_const_reference>())
187
188        .def("polygon_pattern",polygon_pattern_,
189             return_value_policy<copy_const_reference>())
190
191        .def("raster",raster_,
192             return_value_policy<copy_const_reference>())
193
194        .def("shield",shield_,
195             return_value_policy<copy_const_reference>())
196
197        .def("text",text_,
198             return_value_policy<copy_const_reference>())
199
200        .def("building",building_,
201             return_value_policy<copy_const_reference>())
202
203        .def("markers",markers_,
204             return_value_policy<copy_const_reference>())
205
206        .def("glyph",glyph_,
207             return_value_policy<copy_const_reference>())
208
209        ;
210}
Note: See TracBrowser for help on using the browser.