]> mj.ucw.cz Git - leo.git/blob - fixed.c
TODO
[leo.git] / fixed.c
1 /*
2  *      Hic Est Leo -- Fixed Objects
3  *
4  *      (c) 2014 Martin Mares <mj@ucw.cz>
5  */
6
7 #include "leo.h"
8 #include "osm.h"
9 #include "fixed.h"
10
11 #include <ucw/conf.h>
12
13 #include <stdio.h>
14
15 struct fixed_tag {
16   cnode n;
17   char *key, *val;
18 };
19
20 struct fixed_object {
21   cnode n;
22   double x, y;
23   clist tags;
24 };
25
26 static clist fixed_objects;
27
28 static struct cf_section fixed_tag_cf = {
29 #define P(_x) PTR_TO(struct fixed_tag, _x)
30   CF_TYPE(struct fixed_object),
31   CF_ITEMS {
32     CF_STRING("Key", P(key)),
33     CF_STRING("Value", P(val)),
34     CF_END
35   }
36 #undef P
37 };
38
39 static struct cf_section fixed_object_cf = {
40 #define P(_x) PTR_TO(struct fixed_object, _x)
41   CF_TYPE(struct fixed_object),
42   CF_ITEMS {
43     CF_DOUBLE("X", P(x)),
44     CF_DOUBLE("Y", P(y)),
45     CF_LIST("Tag", P(tags), &fixed_tag_cf),
46     CF_END
47   }
48 #undef P
49 };
50
51 static struct cf_section fixed_cf = {
52   CF_ITEMS {
53     CF_LIST("Object", &fixed_objects, &fixed_object_cf),
54     CF_END
55   }
56 };
57
58 static void CONSTRUCTOR fixed_preinit(void)
59 {
60   cf_declare_section("FixedObjects", &fixed_cf, 0);
61 }
62
63 void fixed_add(void)
64 {
65   u64 id = 1;
66   CLIST_FOR_EACH(struct fixed_object *, fo, fixed_objects)
67     {
68       struct osm_node *n = osm_node_new(id++);
69       n->x = fo->x;
70       n->y = fo->y;
71       CLIST_FOR_EACH(struct fixed_tag *, ft, fo->tags)
72         osm_obj_add_tag(&n->o, ft->key, ft->val);
73     }
74 }