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