Parent Directory | Revision Log
Canvas code cleanups
1 | harbaum | 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 | typedef gulong item_id_t; | ||
31 | achadwick | 99 | #define G_TYPE_ITEM_ID_T G_TYPE_ULONG |
32 | harbaum | 1 | |
33 | #define ID_ILLEGAL ((item_id_t)0) | ||
34 | |||
35 | /* icon stuff is required since nodes may held a icon reference */ | ||
36 | struct icon_s; | ||
37 | |||
38 | typedef struct bounds_s { | ||
39 | pos_t ll_min, ll_max; | ||
40 | lpos_t min, max; | ||
41 | lpos_t center; | ||
42 | float scale; | ||
43 | } bounds_t; | ||
44 | |||
45 | typedef struct user_s { | ||
46 | char *name; | ||
47 | struct user_s *next; | ||
48 | } user_t; | ||
49 | |||
50 | typedef struct tag_s { | ||
51 | char *key, *value; | ||
52 | struct tag_s *next; | ||
53 | } tag_t; | ||
54 | |||
55 | typedef struct node_s { | ||
56 | item_id_t id; | ||
57 | pos_t pos; | ||
58 | lpos_t lpos; | ||
59 | user_t *user; | ||
60 | gboolean visible; | ||
61 | time_t time; | ||
62 | tag_t *tag; | ||
63 | int ways; | ||
64 | int flags; | ||
65 | float zoom_max; | ||
66 | |||
67 | /* icon */ | ||
68 | GdkPixbuf *icon_buf; | ||
69 | |||
70 | /* a link to the visual representation on screen */ | ||
71 | struct map_item_chain_s *map_item_chain; | ||
72 | |||
73 | struct node_s *next; | ||
74 | } node_t; | ||
75 | |||
76 | typedef struct node_chain { | ||
77 | node_t *node; | ||
78 | struct node_chain *next; | ||
79 | } node_chain_t; | ||
80 | |||
81 | #define OSM_DRAW_FLAG_AREA (1<<0) | ||
82 | #define OSM_DRAW_FLAG_BG (1<<1) | ||
83 | |||
84 | typedef struct way_s { | ||
85 | item_id_t id; | ||
86 | user_t *user; | ||
87 | gboolean visible; | ||
88 | time_t time; | ||
89 | tag_t *tag; | ||
90 | node_chain_t *node_chain; | ||
91 | int flags; | ||
92 | |||
93 | /* visual representation from elemstyle */ | ||
94 | struct { | ||
95 | guint flags; | ||
96 | gulong color; | ||
97 | gint width; | ||
98 | float zoom_max; | ||
99 | achadwick | 13 | gboolean dashed; |
100 | achadwick | 46 | guint dash_length; |
101 | harbaum | 1 | |
102 | union { | ||
103 | struct { | ||
104 | gulong color; | ||
105 | gint width; | ||
106 | } bg; | ||
107 | |||
108 | struct { | ||
109 | gulong color; | ||
110 | } area; | ||
111 | }; | ||
112 | } draw; | ||
113 | |||
114 | /* a link to the visual representation on screen */ | ||
115 | struct map_item_chain_s *map_item_chain; | ||
116 | |||
117 | struct way_s *next; | ||
118 | } way_t; | ||
119 | |||
120 | typedef struct way_chain { | ||
121 | way_t *way; | ||
122 | struct way_chain *next; | ||
123 | } way_chain_t; | ||
124 | |||
125 | typedef struct relation_s { | ||
126 | item_id_t id; | ||
127 | user_t *user; | ||
128 | gboolean visible; | ||
129 | time_t time; | ||
130 | tag_t *tag; | ||
131 | struct member_s *member; | ||
132 | int flags; | ||
133 | |||
134 | struct relation_s *next; | ||
135 | } relation_t; | ||
136 | |||
137 | typedef struct relation_chain_s { | ||
138 | relation_t *relation; | ||
139 | struct relation_chain_s *next; | ||
140 | } relation_chain_t; | ||
141 | |||
142 | harbaum | 42 | /* two of these hash tables are used, one for nodes and one for ways */ |
143 | /* currently relations aren't used often enough to justify the use */ | ||
144 | /* of a hash table */ | ||
145 | |||
146 | /* the current hash table uses 16 bits. each table thus is */ | ||
147 | /* 256 kbytes (2^16 * sizeof(void*)) in size */ | ||
148 | #define ID2HASH(a) ((unsigned short)(a) ^ (unsigned short)((a)>>16)) | ||
149 | |||
150 | typedef struct hash_item_s { | ||
151 | union { | ||
152 | node_t *node; | ||
153 | way_t *way; | ||
154 | relation_t *relation; | ||
155 | } data; | ||
156 | |||
157 | struct hash_item_s *next; | ||
158 | } hash_item_t; | ||
159 | |||
160 | typedef struct { | ||
161 | hash_item_t *hash[65536]; | ||
162 | } hash_table_t; | ||
163 | |||
164 | harbaum | 1 | typedef enum { |
165 | ILLEGAL=0, NODE, WAY, RELATION, NODE_ID, WAY_ID, RELATION_ID | ||
166 | } type_t; | ||
167 | |||
168 | typedef struct member_s { | ||
169 | type_t type; | ||
170 | char *role; | ||
171 | |||
172 | union { | ||
173 | node_t *node; | ||
174 | way_t *way; | ||
175 | relation_t *relation; | ||
176 | harbaum | 76 | void *ptr; |
177 | harbaum | 1 | item_id_t id; |
178 | }; | ||
179 | |||
180 | struct member_s *next; | ||
181 | } member_t; | ||
182 | |||
183 | typedef struct osm_s { | ||
184 | bounds_t *bounds; // original bounds as they appear in the file | ||
185 | user_t *user; | ||
186 | harbaum | 42 | |
187 | harbaum | 1 | node_t *node; |
188 | harbaum | 42 | hash_table_t *node_hash; |
189 | |||
190 | harbaum | 1 | way_t *way; |
191 | harbaum | 42 | hash_table_t *way_hash; |
192 | |||
193 | // hashing relations doesn't yet make much sense as relations are quite rare | ||
194 | harbaum | 1 | relation_t *relation; |
195 | harbaum | 42 | |
196 | harbaum | 1 | } osm_t; |
197 | |||
198 | #include <libxml/parser.h> | ||
199 | #include <libxml/tree.h> | ||
200 | |||
201 | osm_t *osm_parse(char *filename); | ||
202 | gboolean osm_sanity_check(GtkWidget *parent, osm_t *osm); | ||
203 | tag_t *osm_parse_osm_tag(osm_t *osm, xmlDocPtr doc, xmlNode *a_node); | ||
204 | node_chain_t *osm_parse_osm_way_nd(osm_t *osm, xmlDocPtr doc, xmlNode *a_node); | ||
205 | member_t *osm_parse_osm_relation_member(osm_t *osm, xmlDocPtr doc, xmlNode *a_node); | ||
206 | void osm_dump(osm_t *osm); | ||
207 | void osm_free(struct icon_s **icon, osm_t *osm); | ||
208 | |||
209 | char *osm_node_get_value(node_t *node, char *key); | ||
210 | gboolean osm_node_has_tag(node_t *node); | ||
211 | |||
212 | void osm_node_dump(node_t *node); | ||
213 | |||
214 | void osm_way_free(way_t *way); | ||
215 | void osm_way_dump(way_t *way); | ||
216 | char *osm_way_get_value(way_t *way, char *key); | ||
217 | gboolean osm_node_has_value(node_t *node, char *str); | ||
218 | gboolean osm_way_has_value(way_t *way, char *str); | ||
219 | void osm_way_append_node(way_t *way, node_t *node); | ||
220 | |||
221 | gboolean osm_node_in_way(way_t *way, node_t *node); | ||
222 | |||
223 | void osm_node_chain_free(node_chain_t *node_chain); | ||
224 | int osm_node_chain_length(node_chain_t *node_chain); | ||
225 | void osm_node_free(struct icon_s **icon, node_t *node); | ||
226 | |||
227 | void osm_members_free(member_t *member); | ||
228 | void osm_member_free(member_t *member); | ||
229 | |||
230 | void osm_tag_free(tag_t *tag); | ||
231 | void osm_tags_free(tag_t *tag); | ||
232 | char *osm_tag_get_by_key(tag_t *tag, char *key); | ||
233 | gboolean osm_is_creator_tag(tag_t *tag); | ||
234 | gboolean osm_tag_key_and_value_present(tag_t *haystack, tag_t *tag); | ||
235 | gboolean osm_tag_key_other_value_present(tag_t *haystack, tag_t *tag); | ||
236 | |||
237 | char *osm_generate_xml_node(osm_t *osm, node_t *node); | ||
238 | char *osm_generate_xml_way(osm_t *osm, way_t *way); | ||
239 | char *osm_generate_xml_relation(osm_t *osm, relation_t *relation); | ||
240 | |||
241 | node_t *osm_get_node_by_id(osm_t *osm, item_id_t id); | ||
242 | way_t *osm_get_way_by_id(osm_t *osm, item_id_t id); | ||
243 | relation_t *osm_get_relation_by_id(osm_t *osm, item_id_t id); | ||
244 | |||
245 | guint osm_way_number_of_nodes(way_t *way); | ||
246 | relation_chain_t *osm_node_to_relation(osm_t *osm, node_t *node); | ||
247 | relation_chain_t *osm_way_to_relation(osm_t *osm, way_t *way); | ||
248 | way_chain_t *osm_node_to_way(osm_t *osm, node_t *node); | ||
249 | |||
250 | /* ----------- edit functions ----------- */ | ||
251 | node_t *osm_node_new(osm_t *osm, gint x, gint y); | ||
252 | void osm_node_attach(osm_t *osm, node_t *node); | ||
253 | harbaum | 64 | void osm_node_restore(osm_t *osm, node_t *node); |
254 | harbaum | 1 | way_chain_t *osm_node_delete(osm_t *osm, struct icon_s **icon, node_t *node, |
255 | gboolean permanently, gboolean affect_ways); | ||
256 | void osm_way_delete(osm_t *osm, struct icon_s **icon, way_t *way, | ||
257 | gboolean permanently); | ||
258 | |||
259 | way_t *osm_way_new(void); | ||
260 | void osm_way_attach(osm_t *osm, way_t *way); | ||
261 | |||
262 | gboolean osm_position_within_bounds(osm_t *osm, gint x, gint y); | ||
263 | item_id_t osm_new_way_id(osm_t *osm); | ||
264 | gboolean osm_way_ends_with_node(way_t *way, node_t *node); | ||
265 | |||
266 | achadwick | 98 | void osm_way_reverse(way_t *way); |
267 | guint osm_way_reverse_direction_sensitive_tags(way_t *way); | ||
268 | harbaum | 103 | guint osm_way_reverse_direction_sensitive_roles(osm_t *osm, way_t *way); |
269 | harbaum | 1 | |
270 | void osm_node_remove_from_relation(osm_t *osm, node_t *node); | ||
271 | void osm_way_remove_from_relation(osm_t *osm, way_t *way); | ||
272 | |||
273 | node_t *osm_way_get_last_node(way_t *way); | ||
274 | node_t *osm_way_get_first_node(way_t *way); | ||
275 | void osm_way_rotate(way_t *way, gint offset); | ||
276 | |||
277 | tag_t *osm_tags_copy(tag_t *tag, gboolean update_creator); | ||
278 | |||
279 | harbaum | 54 | char *osm_type_string(type_t type); |
280 | harbaum | 76 | char *osm_id_string(type_t type, void *object); |
281 | harbaum | 64 | char *osm_object_string(type_t type, void *object); |
282 | harbaum | 76 | tag_t *osm_object_get_tags(type_t type, void *object); |
283 | harbaum | 54 | |
284 | harbaum | 73 | relation_t *osm_relation_new(void); |
285 | void osm_relation_free(relation_t *relation); | ||
286 | void osm_relation_attach(osm_t *osm, relation_t *relation); | ||
287 | harbaum | 75 | void osm_relation_delete(osm_t *osm, relation_t *relation, |
288 | gboolean permanently); | ||
289 | harbaum | 76 | gint osm_relation_members_num(relation_t *relation); |
290 | harbaum | 73 | |
291 | harbaum | 1 | #endif /* OSM_H */ |
292 | achadwick | 13 | |
293 | // vim:et:ts=8:sw=2:sts=2:ai |