Contents of /trunk/src/osm.h

Parent Directory Parent Directory | Revision Log Revision Log


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