Add bindings for formating::list_node.
This commit is contained in:
parent
060545b9aa
commit
c94d32b41b
4 changed files with 63 additions and 3 deletions
|
@ -618,6 +618,8 @@ __all__ = [
|
|||
'FontSet',
|
||||
'FormatingNode',
|
||||
'FormatingTextNode',
|
||||
'FormatingFormatNode',
|
||||
'FormatingListNode',
|
||||
'Geometry2d',
|
||||
'Image',
|
||||
'ImageView',
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/stl_iterator.hpp>
|
||||
|
||||
#include <mapnik/text_placements.hpp>
|
||||
#include "mapnik_enumeration.hpp"
|
||||
|
@ -147,6 +148,43 @@ struct FormatNodeWrap: formating::format_node, wrapper<formating::format_node>
|
|||
}
|
||||
};
|
||||
|
||||
struct ListNodeWrap: formating::list_node, wrapper<formating::list_node>
|
||||
{
|
||||
//Default constructor
|
||||
ListNodeWrap() : formating::list_node(), wrapper<formating::list_node>()
|
||||
{
|
||||
}
|
||||
|
||||
//Special constructor: Takes a python sequence as its argument
|
||||
ListNodeWrap(object l) : formating::list_node(), wrapper<formating::list_node>()
|
||||
{
|
||||
stl_input_iterator<formating::node_ptr> begin(l), end;
|
||||
children_.insert(children_.end(), begin, end);
|
||||
}
|
||||
|
||||
/* TODO: Add constructor taking variable number of arguments.
|
||||
http://wiki.python.org/moin/boost.python/HowTo#A.22Raw.22_function */
|
||||
|
||||
|
||||
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const
|
||||
{
|
||||
if(override o = this->get_override("apply"))
|
||||
{
|
||||
python_block_auto_unblock b;
|
||||
o(ptr(&p), ptr(&feature), ptr(&output));
|
||||
}
|
||||
else
|
||||
{
|
||||
formating::list_node::apply(p, feature, output);
|
||||
}
|
||||
}
|
||||
|
||||
void default_apply(char_properties const& p, Feature const& feature, processed_text &output) const
|
||||
{
|
||||
formating::list_node::apply(p, feature, output);
|
||||
}
|
||||
};
|
||||
|
||||
struct TextPlacementsWrap: text_placements, wrapper<text_placements>
|
||||
{
|
||||
text_placement_info_ptr get_placement_info(double scale_factor_, dimension_type dim,
|
||||
|
@ -402,4 +440,16 @@ void export_text_placement()
|
|||
&formating::format_node::set_child)
|
||||
;
|
||||
register_ptr_to_python<boost::shared_ptr<formating::format_node> >();
|
||||
|
||||
class_<ListNodeWrap,
|
||||
boost::shared_ptr<ListNodeWrap>,
|
||||
bases<formating::node>,
|
||||
boost::noncopyable>
|
||||
("FormatingListNode", init<>())
|
||||
.def(init<list>())
|
||||
.def("append", &formating::list_node::push_back)
|
||||
.def("apply", &formating::list_node::apply, &ListNodeWrap::default_apply)
|
||||
;
|
||||
|
||||
register_ptr_to_python<boost::shared_ptr<formating::list_node> >();
|
||||
}
|
||||
|
|
|
@ -119,8 +119,9 @@ public:
|
|||
void push_back(node_ptr n);
|
||||
void set_children(std::vector<node_ptr> const& children);
|
||||
std::vector<node_ptr> const& get_children() const;
|
||||
|
||||
void clear();
|
||||
private:
|
||||
protected:
|
||||
std::vector<node_ptr> children_;
|
||||
};
|
||||
|
||||
|
|
|
@ -74,14 +74,21 @@ m.layers.append(layer)
|
|||
bbox = mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)
|
||||
m.zoom_to_box(bbox)
|
||||
|
||||
formatnode = mapnik.FormatingFormatNode()
|
||||
formatnode.child = mapnik.FormatingTextNode(mapnik.Expression("[name]"))
|
||||
formatnode.fill = mapnik.Color("green")
|
||||
|
||||
format_trees = [
|
||||
('TextNode', mapnik.FormatingTextNode(mapnik.Expression("[name]"))),
|
||||
('MyText', MyText()),
|
||||
('IfElse', IfElse("[nr] != '5'",
|
||||
mapnik.FormatingTextNode(mapnik.Expression("[name]")),
|
||||
mapnik.FormatingTextNode(mapnik.Expression("'SPECIAL!'"))))
|
||||
|
||||
mapnik.FormatingTextNode(mapnik.Expression("'SPECIAL!'")))),
|
||||
('Format', formatnode),
|
||||
('List', mapnik.FormatingListNode([
|
||||
mapnik.FormatingTextNode(mapnik.Expression("[name]+'\n'")),
|
||||
MyText()
|
||||
]))
|
||||
]
|
||||
|
||||
for format_tree in format_trees:
|
||||
|
|
Loading…
Reference in a new issue