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