Parent Directory | Revision Log
Code cleanups
1 | /* |
2 | * Copyright (C) 2008 Till Harbaum <till@harbaum.org>. |
3 | * |
4 | * This file is part of OSM2Go. |
5 | * |
6 | * OSM2Go is free software: you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation, either version 3 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * OSM2Go is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with OSM2Go. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | #ifndef OSM_H |
21 | #define OSM_H |
22 | |
23 | #include <math.h> |
24 | |
25 | #define OSM_FLAG_DIRTY (1<<0) |
26 | #define OSM_FLAG_DELETED (1<<1) |
27 | #define OSM_FLAG_NEW (1<<2) |
28 | #define OSM_FLAG_HIDDEN (1<<3) |
29 | |
30 | /* item_id_t needs to be signed as osm2go uses negative ids for items */ |
31 | /* not yet registered with the main osm database */ |
32 | typedef glong item_id_t; |
33 | #define G_TYPE_ITEM_ID_T G_TYPE_LONG |
34 | |
35 | #define ID_ILLEGAL ((item_id_t)0) |
36 | |
37 | /* icon stuff is required since nodes may held a icon reference */ |
38 | struct icon_s; |
39 | |
40 | typedef struct bounds_s { |
41 | pos_t ll_min, ll_max; |
42 | lpos_t min, max; |
43 | lpos_t center; |
44 | float scale; |
45 | } bounds_t; |
46 | |
47 | typedef struct user_s { |
48 | char *name; |
49 | struct user_s *next; |
50 | } user_t; |
51 | |
52 | typedef struct tag_s { |
53 | char *key, *value; |
54 | struct tag_s *next; |
55 | } tag_t; |
56 | |
57 | typedef struct node_s { |
58 | item_id_t id; |
59 | pos_t pos; |
60 | lpos_t lpos; |
61 | user_t *user; |
62 | gboolean visible; |
63 | time_t time; |
64 | tag_t *tag; |
65 | int ways; |
66 | int flags; |
67 | float zoom_max; |
68 | |
69 | /* icon */ |
70 | GdkPixbuf *icon_buf; |
71 | |
72 | /* a link to the visual representation on screen */ |
73 | struct map_item_chain_s *map_item_chain; |
74 | |
75 | struct node_s *next; |
76 | } node_t; |
77 | |
78 | typedef struct node_chain { |
79 | node_t *node; |
80 | struct node_chain *next; |
81 | } node_chain_t; |
82 | |
83 | #define OSM_DRAW_FLAG_AREA (1<<0) |
84 | #define OSM_DRAW_FLAG_BG (1<<1) |
85 | |
86 | typedef struct way_s { |
87 | item_id_t id; |
88 | user_t *user; |
89 | gboolean visible; |
90 | time_t time; |
91 | tag_t *tag; |
92 | node_chain_t *node_chain; |
93 | int flags; |
94 | |
95 | /* visual representation from elemstyle */ |
96 | struct { |
97 | guint flags; |
98 | gulong color; |
99 | gint width; |
100 | float zoom_max; |
101 | gboolean dashed; |
102 | guint dash_length; |
103 | |
104 | union { |
105 | struct { |
106 | gulong color; |
107 | gint width; |
108 | } bg; |
109 | |
110 | struct { |
111 | gulong color; |
112 | } area; |
113 | }; |
114 | } draw; |
115 | |
116 | /* a link to the visual representation on screen */ |
117 | struct map_item_chain_s *map_item_chain; |
118 | |
119 | struct way_s *next; |
120 | } way_t; |
121 | |
122 | typedef struct way_chain { |
123 | way_t *way; |
124 | struct way_chain *next; |
125 | } way_chain_t; |
126 | |
127 | typedef struct relation_s { |
128 | item_id_t id; |
129 | user_t *user; |
130 | gboolean visible; |
131 | time_t time; |
132 | tag_t *tag; |
133 | struct member_s *member; |
134 | int flags; |
135 | |
136 | struct relation_s *next; |
137 | } relation_t; |
138 | |
139 | typedef struct relation_chain_s { |
140 | relation_t *relation; |
141 | struct relation_chain_s *next; |
142 | } relation_chain_t; |
143 | |
144 | /* two of these hash tables are used, one for nodes and one for ways */ |
145 | /* currently relations aren't used often enough to justify the use */ |
146 | /* of a hash table */ |
147 | |
148 | /* the current hash table uses 16 bits. each table thus is */ |
149 | /* 256 kbytes (2^16 * sizeof(void*)) in size */ |
150 | #define ID2HASH(a) ((unsigned short)(a) ^ (unsigned short)((a)>>16)) |
151 | |
152 | typedef struct hash_item_s { |
153 | union { |
154 | node_t *node; |
155 | way_t *way; |
156 | relation_t *relation; |
157 | } data; |
158 | |
159 | struct hash_item_s *next; |
160 | } hash_item_t; |
161 | |
162 | typedef struct { |
163 | hash_item_t *hash[65536]; |
164 | } hash_table_t; |
165 | |
166 | typedef enum { |
167 | ILLEGAL=0, NODE, WAY, RELATION, NODE_ID, WAY_ID, RELATION_ID |
168 | } type_t; |
169 | |
170 | typedef struct { |
171 | type_t type; |
172 | union { |
173 | node_t *node; |
174 | way_t *way; |
175 | relation_t *relation; |
176 | void *ptr; |
177 | }; |
178 | } object_t; |
179 | |
180 | typedef struct member_s { |
181 | type_t type; |
182 | char *role; |
183 | |
184 | union { |
185 | node_t *node; |
186 | way_t *way; |
187 | relation_t *relation; |
188 | void *ptr; |
189 | item_id_t id; |
190 | }; |
191 | |
192 | struct member_s *next; |
193 | } member_t; |
194 | |
195 | typedef struct osm_s { |
196 | bounds_t *bounds; // original bounds as they appear in the file |
197 | user_t *user; |
198 | |
199 | node_t *node; |
200 | hash_table_t *node_hash; |
201 | |
202 | way_t *way; |
203 | hash_table_t *way_hash; |
204 | |
205 | // hashing relations doesn't yet make much sense as relations are quite rare |
206 | relation_t *relation; |
207 | |
208 | } osm_t; |
209 | |
210 | #include <libxml/parser.h> |
211 | #include <libxml/tree.h> |
212 | |
213 | osm_t *osm_parse(char *filename); |
214 | gboolean osm_sanity_check(GtkWidget *parent, osm_t *osm); |
215 | tag_t *osm_parse_osm_tag(osm_t *osm, xmlDocPtr doc, xmlNode *a_node); |
216 | node_chain_t *osm_parse_osm_way_nd(osm_t *osm, xmlDocPtr doc, xmlNode *a_node); |
217 | member_t *osm_parse_osm_relation_member(osm_t *osm, xmlDocPtr doc, xmlNode *a_node); |
218 | void osm_dump(osm_t *osm); |
219 | void osm_free(struct icon_s **icon, osm_t *osm); |
220 | |
221 | char *osm_node_get_value(node_t *node, char *key); |
222 | gboolean osm_node_has_tag(node_t *node); |
223 | |
224 | void osm_node_dump(node_t *node); |
225 | |
226 | void osm_way_free(way_t *way); |
227 | void osm_way_dump(way_t *way); |
228 | char *osm_way_get_value(way_t *way, char *key); |
229 | gboolean osm_node_has_value(node_t *node, char *str); |
230 | gboolean osm_way_has_value(way_t *way, char *str); |
231 | void osm_way_append_node(way_t *way, node_t *node); |
232 | |
233 | gboolean osm_node_in_way(way_t *way, node_t *node); |
234 | |
235 | void osm_node_chain_free(node_chain_t *node_chain); |
236 | int osm_node_chain_length(node_chain_t *node_chain); |
237 | void osm_node_free(struct icon_s **icon, node_t *node); |
238 | |
239 | void osm_members_free(member_t *member); |
240 | void osm_member_free(member_t *member); |
241 | |
242 | void osm_tag_free(tag_t *tag); |
243 | void osm_tags_free(tag_t *tag); |
244 | char *osm_tag_get_by_key(tag_t *tag, char *key); |
245 | gboolean osm_is_creator_tag(tag_t *tag); |
246 | gboolean osm_tag_key_and_value_present(tag_t *haystack, tag_t *tag); |
247 | gboolean osm_tag_key_other_value_present(tag_t *haystack, tag_t *tag); |
248 | |
249 | char *osm_generate_xml_node(osm_t *osm, node_t *node); |
250 | char *osm_generate_xml_way(osm_t *osm, way_t *way); |
251 | char *osm_generate_xml_relation(osm_t *osm, relation_t *relation); |
252 | |
253 | node_t *osm_get_node_by_id(osm_t *osm, item_id_t id); |
254 | way_t *osm_get_way_by_id(osm_t *osm, item_id_t id); |
255 | relation_t *osm_get_relation_by_id(osm_t *osm, item_id_t id); |
256 | |
257 | guint osm_way_number_of_nodes(way_t *way); |
258 | relation_chain_t *osm_node_to_relation(osm_t *osm, node_t *node); |
259 | relation_chain_t *osm_way_to_relation(osm_t *osm, way_t *way); |
260 | way_chain_t *osm_node_to_way(osm_t *osm, node_t *node); |
261 | |
262 | /* ----------- edit functions ----------- */ |
263 | node_t *osm_node_new(osm_t *osm, gint x, gint y); |
264 | void osm_node_attach(osm_t *osm, node_t *node); |
265 | void osm_node_restore(osm_t *osm, node_t *node); |
266 | way_chain_t *osm_node_delete(osm_t *osm, struct icon_s **icon, node_t *node, |
267 | gboolean permanently, gboolean affect_ways); |
268 | void osm_way_delete(osm_t *osm, struct icon_s **icon, way_t *way, |
269 | gboolean permanently); |
270 | |
271 | way_t *osm_way_new(void); |
272 | void osm_way_attach(osm_t *osm, way_t *way); |
273 | |
274 | gboolean osm_position_within_bounds(osm_t *osm, gint x, gint y); |
275 | item_id_t osm_new_way_id(osm_t *osm); |
276 | gboolean osm_way_ends_with_node(way_t *way, node_t *node); |
277 | |
278 | void osm_way_reverse(way_t *way); |
279 | guint osm_way_reverse_direction_sensitive_tags(way_t *way); |
280 | guint osm_way_reverse_direction_sensitive_roles(osm_t *osm, way_t *way); |
281 | |
282 | void osm_node_remove_from_relation(osm_t *osm, node_t *node); |
283 | void osm_way_remove_from_relation(osm_t *osm, way_t *way); |
284 | |
285 | node_t *osm_way_get_last_node(way_t *way); |
286 | node_t *osm_way_get_first_node(way_t *way); |
287 | void osm_way_rotate(way_t *way, gint offset); |
288 | |
289 | tag_t *osm_tags_copy(tag_t *tag, gboolean update_creator); |
290 | |
291 | char *osm_type_string(type_t type); |
292 | char *osm_id_string(type_t type, void *object); |
293 | char *osm_object_string(type_t type, void *object); |
294 | tag_t *osm_object_get_tags(type_t type, void *object); |
295 | |
296 | relation_t *osm_relation_new(void); |
297 | void osm_relation_free(relation_t *relation); |
298 | void osm_relation_attach(osm_t *osm, relation_t *relation); |
299 | void osm_relation_delete(osm_t *osm, relation_t *relation, |
300 | gboolean permanently); |
301 | gint osm_relation_members_num(relation_t *relation); |
302 | |
303 | void osm_object_set_flags(object_t *map_item, int set, int clr); |
304 | |
305 | #endif /* OSM_H */ |
306 | |
307 | // vim:et:ts=8:sw=2:sts=2:ai |