]> mj.ucw.cz Git - leo.git/blob - leo.c
Log statistics when a data source is loaded
[leo.git] / leo.c
1 /*
2  *      Hic Est Leo -- Main Program
3  *
4  *      (c) 2014 Martin Mares <mj@ucw.cz>
5  */
6
7 #include <ucw/lib.h>
8 #include <ucw/conf.h>
9 #include <ucw/opt.h>
10
11 #include <stdio.h>
12
13 #include "leo.h"
14 #include "osm.h"
15 #include "svg.h"
16 #include "style.h"
17 #include "css.h"
18 #include "sym.h"
19 #include "map.h"
20
21 uns debug_dump_source, debug_dump_after_proj, debug_dump_after_scaling;
22 uns debug_dump_multipolygons, debug_dump_css, debug_dump_styling, debug_dump_symbols;
23
24 static struct cf_section debug_cf = {
25   CF_ITEMS {
26     CF_UNS("DumpSource", &debug_dump_source),
27     CF_UNS("DumpAfterProj", &debug_dump_after_proj),
28     CF_UNS("DumpAfterScaling", &debug_dump_after_scaling),
29     CF_UNS("DumpMultipolygons", &debug_dump_multipolygons),
30     CF_UNS("DumpCSS", &debug_dump_css),
31     CF_UNS("DumpStyling", &debug_dump_styling),
32     CF_UNS("DumpSymbols", &debug_dump_symbols),
33     CF_END
34   }
35 };
36
37 static const struct opt_section options = {
38   OPT_ITEMS {
39     OPT_HELP("Hic Est Leo -- Experimental Map Renderer"),
40     OPT_HELP(""),
41     OPT_HELP("Options:"),
42     OPT_HELP_OPTION,
43     OPT_CONF_OPTIONS,
44     OPT_END
45   }
46 };
47
48 // FIXME: Make generic
49 static void draw_scale(struct svg *svg)
50 {
51   double dist = 1000;
52   double width = dist * map_scale;
53   double x = page_width - 10 - width;
54   double y = 50;
55
56   svg_push_element(svg, "g");
57   svg_set_attr(svg, "id", "scale");
58   svg_set_attr_format(svg, "transform", "translate(%.6g,%.6g)", x * svg->scale, y * svg->scale);
59
60   for (int outline=1; outline>=0; outline--)
61     {
62       svg_push_element(svg, "g");
63       svg_set_attr(svg, "stroke-linecap", "square");
64       if (outline)
65         {
66           svg_set_attr_dimen(svg, "stroke-width", 1.5);
67           svg_set_attr_color(svg, "stroke", 0xffffff);
68         }
69       else
70         {
71           svg_set_attr_dimen(svg, "stroke-width", 0.5);
72           svg_set_attr_color(svg, "stroke", 0);
73         }
74
75       svg_push_element(svg, "line");
76       svg_set_attr_dimen(svg, "x1", 0);
77       svg_set_attr_dimen(svg, "y1", 0);
78       svg_set_attr_dimen(svg, "x2", width);
79       svg_set_attr_dimen(svg, "y2", 0);
80       svg_pop(svg);
81
82       for (int i=0; i<=10; i++)
83         {
84           double tick;
85           switch (i)
86             {
87             case 0:
88             case 10:
89               tick = 3;
90               break;
91             case 5:
92               tick = 2;
93               break;
94             default:
95               tick = 1;
96             }
97           svg_push_element(svg, "line");
98           svg_set_attr_dimen(svg, "x1", width * i/10);
99           svg_set_attr_dimen(svg, "y1", 0);
100           svg_set_attr_dimen(svg, "x2", width * i/10);
101           svg_set_attr_dimen(svg, "y1", -tick);
102           svg_pop(svg);
103         }
104
105       svg_pop(svg);
106     }
107
108   scale_text(svg, 0, 5, osm_val_encode("0"));
109   scale_text(svg, width, 5, osm_val_encode("1 km"));
110   svg_pop(svg);
111 }
112
113 int main(int argc UNUSED, char **argv)
114 {
115   cf_def_file = "map.cf";
116   cf_declare_section("Debug", &debug_cf, 0);
117   opt_parse(&options, argv+1);
118
119   osm_init();
120   styles_init();
121   map_load_styles();
122   map_load_sources();
123   map_set_scale();
124
125   struct svg *svg = svg_open(map_svg_output);
126   if (!map_rotate)
127     {
128       svg_set_attr_dimen(svg, "width", page_width);
129       svg_set_attr_dimen(svg, "height", page_height);
130     }
131   else
132     {
133       svg_set_attr_dimen(svg, "width", page_height);
134       svg_set_attr_dimen(svg, "height", page_width);
135     }
136
137   sym_init();
138
139   map_apply_styles(svg);
140
141   if (map_clip)
142     {
143       svg_push_element(svg, "defs");
144       svg_push_element(svg, "clipPath");
145       svg_set_attr(svg, "id", "boundary");
146       svg_push_path(svg);
147       svg_path_move_to(svg, page_offset_x, page_offset_y);
148       svg_path_line_to_rel(svg, page_map_width, 0);
149       svg_path_line_to_rel(svg, 0, page_map_height);
150       svg_path_line_to_rel(svg, -page_map_width, 0);
151       svg_path_close(svg);
152       svg_path_end(svg);
153       svg_pop(svg);
154       svg_pop(svg);
155       svg_pop(svg);
156
157       svg_push_element(svg, "g");
158       svg_set_attr_format(svg, "clip-path", "url(#boundary)");
159       if (map_rotate)
160         svg_set_attr_format(svg, "transform", "translate(%.6g,0) rotate(90)", page_height * svg->scale);
161     }
162
163   // FIXME: Replace by generic logo drawing facility
164 #if 0
165   struct svg_icon *logo = svg_icon_load(svg, "../logo/kocka-s-okrajem.svg");
166 #endif
167
168   sym_draw_all(svg);
169
170   // Draw logo
171 #if 0
172   double logo_width = 36.12;
173   double logo_height = 36.12 / logo->width * logo->height;
174   struct svg_icon_request sir = {
175     .icon = logo,
176     .x = page_width - 12 - logo_width / 2,
177     .y = 10 + logo_height / 2,
178     .width = logo_width,
179     .height = logo_height,
180   };
181   svg_icon_put(svg, &sir);
182 #endif
183
184   draw_scale(svg);
185
186   if (map_clip)
187     svg_pop(svg);
188
189   if (map_draw_border)
190     {
191       svg_push_element(svg, "rect");
192       svg_set_attr_dimen(svg, "x", page_offset_x);
193       svg_set_attr_dimen(svg, "y", page_offset_y);
194       svg_set_attr_dimen(svg, "width", page_map_width);
195       svg_set_attr_dimen(svg, "height", page_map_height);
196       svg_set_attr(svg, "fill", "none");
197       svg_set_attr(svg, "stroke", "blue");
198       svg_set_attr_dimen(svg, "stroke-width", 0.2);
199       svg_pop(svg);
200     }
201
202   svg_close(svg);
203
204   msg(L_INFO, "Finished");
205   return 0;
206 }