Fix:core:Modified sunrise/set calculation coefficients
[navit-package] / navit / maptool / maptool.h
1 #include <glib.h>
2 #include "config.h"
3 #include "coord.h"
4 #include "item.h"
5 #include "attr.h"
6
7 #define BUFFER_SIZE 1280
8
9 #define debug_tile(x) 0
10 #define debug_itembin(x) 0
11
12 struct rect {
13         struct coord l,h;
14 };
15
16 struct tile_data {
17         char buffer[1024];
18         int tile_depth;
19         struct rect item_bbox;
20         struct rect tile_bbox;
21 };
22
23 struct tile_parameter {
24         int min;
25         int max;
26         int overlap;
27 };
28
29 struct tile_info {
30         int write;
31         int maxlen;
32         char *suffix;
33         GList **tiles_list;
34         FILE *tilesdir_out;
35 };
36
37 extern struct tile_head {
38         int num_subtiles;
39         int total_size;
40         char *name;
41         char *zip_data;
42         int total_size_used;
43         int zipnum;
44         int process;
45         struct tile_head *next;
46         // char subtiles[0];
47 } *tile_head_root;
48
49
50
51 struct item_bin {
52         int len;
53         enum item_type type;
54         int clen;
55 };
56
57 struct attr_bin {
58         int len;
59         enum attr_type type;
60 };
61
62
63 struct item_bin_sink_func {
64         int (*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data);
65         void *priv_data[8];
66 };
67
68 struct item_bin_sink {
69         void *priv_data[8];
70         GList *sink_funcs;
71 };
72
73 struct zip_info {
74         int zipnum;
75         int dir_size;
76         long long offset;
77         int compression_level;
78         int maxnamelen;
79         int zip64;
80         FILE *res;
81         FILE *index;
82         FILE *dir;
83 };
84
85 /* buffer.c */
86 struct buffer {
87         int malloced_step;
88         long long malloced;
89         unsigned char *base;
90         long long size;
91 };
92
93 void save_buffer(char *filename, struct buffer *b, long long offset);
94 void load_buffer(char *filename, struct buffer *b, long long offset, long long size);
95
96 /* ch.c */
97
98 void ch_generate_tiles(char *map_suffix, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info);
99 void ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info);
100
101 /* coastline.c */
102
103 void process_coastlines(FILE *in, FILE *out);
104
105 /* geom.c */
106
107 enum geom_poly_segment_type {
108         geom_poly_segment_type_none,
109         geom_poly_segment_type_way_inner,
110         geom_poly_segment_type_way_outer,
111         geom_poly_segment_type_way_left_side,
112         geom_poly_segment_type_way_right_side,
113         geom_poly_segment_type_way_unknown,
114
115 };
116
117 struct geom_poly_segment {
118         enum geom_poly_segment_type type;
119         struct coord *first,*last;
120 };
121
122 void geom_coord_copy(struct coord *from, struct coord *to, int count, int reverse);
123 void geom_coord_revert(struct coord *c, int count);
124 long long geom_poly_area(struct coord *c, int count);
125 GList *geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third);
126 void geom_poly_segment_destroy(struct geom_poly_segment *seg);
127 GList *geom_poly_segments_remove(GList *list, struct geom_poly_segment *seg);
128 int geom_poly_segment_compatible(struct geom_poly_segment *s1, struct geom_poly_segment *s2, int dir);
129 GList *geom_poly_segments_sort(GList *in, enum geom_poly_segment_type type);
130 struct geom_poly_segment *item_bin_to_poly_segment(struct item_bin *ib, int type);
131 void clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out);
132 void clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out);
133
134 /* itembin.c */
135
136 struct item_bin *read_item(FILE *in);
137 int item_bin_read(struct item_bin *ib, FILE *in);
138 void item_bin_set_type(struct item_bin *ib, enum item_type type);
139 void item_bin_init(struct item_bin *ib, enum item_type type);
140 void item_bin_add_coord(struct item_bin *ib, struct coord *c, int count);
141 void item_bin_bbox(struct item_bin *ib, struct rect *r);
142 void item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir);
143 void item_bin_add_coord_rect(struct item_bin *ib, struct rect *r);
144 void item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data, int size);
145 void item_bin_add_attr(struct item_bin *ib, struct attr *attr);
146 void item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val);
147 void *item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last);
148 struct attr_bin * item_bin_get_attr_bin_last(struct item_bin *ib);
149 void item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val);
150 void item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str);
151 void item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max);
152 void item_bin_write(struct item_bin *ib, FILE *out);
153 void item_bin_write_clipped(struct item_bin *ib, struct tile_parameter *param, struct item_bin_sink *out);
154 void item_bin_dump(struct item_bin *ib, FILE *out);
155 void dump_itembin(struct item_bin *ib);
156 void item_bin_set_type_by_population(struct item_bin *ib, int population);
157 void item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, FILE *out);
158 int item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size);
159
160
161
162 /* maptool.c */
163
164 extern char buffer[400000];
165 extern long long slice_size;
166 extern int attr_debug_level;
167 extern char *suffix;
168 extern int ignore_unkown;
169 extern GHashTable *dedupe_ways_hash;
170 extern int phase;
171 extern int slices;
172 extern struct buffer node_buffer;
173 extern int processed_nodes, processed_nodes_out, processed_ways, processed_relations, processed_tiles;
174 extern struct item_bin *item_bin;
175 extern int bytes_read;
176 extern int overlap;
177 void sig_alrm(int sig);
178 void sig_alrm_end(void);
179
180 /* misc.c */
181 extern struct rect world_bbox;
182
183
184 void bbox_extend(struct coord *c, struct rect *r);
185 void bbox(struct coord *c, int count, struct rect *r);
186 int contains_bbox(int xl, int yl, int xh, int yh, struct rect *r);
187 void phase1_map(struct map *map, FILE *out_ways, FILE *out_nodes);
188 void dump(FILE *in);
189 int phase4(FILE **in, int in_count, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info);
190 int phase5(FILE **in, FILE **references, int in_count, char *suffix, struct zip_info *zip_info);
191 void process_binfile(FILE *in, FILE *out);
192 void cat(FILE *in, FILE *out);
193
194
195 /* osm.c */
196
197 long long item_bin_get_id(struct item_bin *ib);
198 void flush_nodes(int final);
199 void sort_countries(int keep_tmpfiles);
200 void process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out);
201 int resolve_ways(FILE *in, FILE *out);
202 int map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions);
203 int map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_nodes);
204 int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final);
205 void write_countrydir(struct zip_info *zip_info);
206 void remove_countryfiles(void);
207 void osm_init(void);
208
209 /* sourcesink.c */
210
211 struct item_bin_sink *item_bin_sink_new(void);
212 struct item_bin_sink_func *item_bin_sink_func_new(int (*func)(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data));
213 void item_bin_sink_func_destroy(struct item_bin_sink_func *func);
214 void item_bin_sink_add_func(struct item_bin_sink *sink, struct item_bin_sink_func *func);
215 void item_bin_sink_destroy(struct item_bin_sink *sink);
216 int item_bin_write_to_sink(struct item_bin *ib, struct item_bin_sink *sink, struct tile_data *tile_data);
217 struct item_bin_sink *file_reader_new(FILE *in, int limit, int offset);
218 int file_reader_finish(struct item_bin_sink *sink);
219 int file_writer_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data);
220 struct item_bin_sink_func *file_writer_new(FILE *out);
221 int file_writer_finish(struct item_bin_sink_func *file_writer);
222 int tile_collector_process(struct item_bin_sink_func *tile_collector, struct item_bin *ib, struct tile_data *tile_data);
223 struct item_bin_sink_func *tile_collector_new(struct item_bin_sink *out);
224
225 /* tempfile.c */
226
227 char *tempfile_name(char *suffix, char *name);
228 FILE *tempfile(char *suffix, char *name, int mode);
229 void tempfile_unlink(char *suffix, char *name);
230 void tempfile_rename(char *suffix, char *from, char *to);
231
232 /* tile.c */
233 extern GHashTable *tile_hash,*tile_hash2;
234
235 struct aux_tile {
236         char *name;
237         char *filename;
238         int size;
239 };
240
241 extern GList *aux_tile_list;
242
243 int tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr);
244 void tile_bbox(char *tile, struct rect *r, int overlap);
245 int tile_len(char *tile);
246 void tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name);
247 void tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max);
248 int add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size);
249 int write_aux_tiles(struct zip_info *zip_info);
250 int create_tile_hash(void);
251 void write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out);
252 void merge_tiles(struct tile_info *info);
253 void index_init(struct zip_info *info, int version);
254 void index_submap_add(struct tile_info *info, struct tile_head *th);
255
256 /* zip.c */
257
258 void write_zipmember(struct zip_info *zip_info, char *name, int filelen, char *data, int data_size);
259 void zip_write_index(struct zip_info *info);
260 int zip_write_directory(struct zip_info *info);