Contents of /trunk/src/osm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 155 - (show annotations)
Tue Mar 31 10:19:50 2009 UTC (15 years, 2 months ago) by harbaum
File MIME type: text/plain
File size: 7910 byte(s)
More 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 item_id_t id;
177 void *ptr;
178 };
179 } object_t;
180
181 typedef struct member_s {
182 object_t object;
183 char *role;
184 struct member_s *next;
185 } member_t;
186
187 typedef struct osm_s {
188 bounds_t *bounds; // original bounds as they appear in the file
189 user_t *user;
190
191 node_t *node;
192 hash_table_t *node_hash;
193
194 way_t *way;
195 hash_table_t *way_hash;
196
197 // hashing relations doesn't yet make much sense as relations are quite rare
198 relation_t *relation;
199
200 } osm_t;
201
202 #include <libxml/parser.h>
203 #include <libxml/tree.h>
204
205 osm_t *osm_parse(char *filename);
206 gboolean osm_sanity_check(GtkWidget *parent, osm_t *osm);
207 tag_t *osm_parse_osm_tag(osm_t *osm, xmlDocPtr doc, xmlNode *a_node);
208 node_chain_t *osm_parse_osm_way_nd(osm_t *osm, xmlDocPtr doc, xmlNode *a_node);
209 member_t *osm_parse_osm_relation_member(osm_t *osm, xmlDocPtr doc, xmlNode *a_node);
210 void osm_dump(osm_t *osm);
211 void osm_free(struct icon_s **icon, osm_t *osm);
212
213 char *osm_node_get_value(node_t *node, char *key);
214 gboolean osm_node_has_tag(node_t *node);
215
216 void osm_node_dump(node_t *node);
217
218 void osm_way_free(way_t *way);
219 void osm_way_dump(way_t *way);
220 char *osm_way_get_value(way_t *way, char *key);
221 gboolean osm_node_has_value(node_t *node, char *str);
222 gboolean osm_way_has_value(way_t *way, char *str);
223 void osm_way_append_node(way_t *way, node_t *node);
224
225 gboolean osm_node_in_way(way_t *way, node_t *node);
226
227 void osm_node_chain_free(node_chain_t *node_chain);
228 int osm_node_chain_length(node_chain_t *node_chain);
229 void osm_node_free(struct icon_s **icon, node_t *node);
230
231 void osm_members_free(member_t *member);
232 void osm_member_free(member_t *member);
233
234 void osm_tag_free(tag_t *tag);
235 void osm_tags_free(tag_t *tag);
236 char *osm_tag_get_by_key(tag_t *tag, char *key);
237 gboolean osm_is_creator_tag(tag_t *tag);
238 gboolean osm_tag_key_and_value_present(tag_t *haystack, tag_t *tag);
239 gboolean osm_tag_key_other_value_present(tag_t *haystack, tag_t *tag);
240
241 char *osm_generate_xml_node(osm_t *osm, node_t *node);
242 char *osm_generate_xml_way(osm_t *osm, way_t *way);
243 char *osm_generate_xml_relation(osm_t *osm, relation_t *relation);
244
245 node_t *osm_get_node_by_id(osm_t *osm, item_id_t id);
246 way_t *osm_get_way_by_id(osm_t *osm, item_id_t id);
247 relation_t *osm_get_relation_by_id(osm_t *osm, item_id_t id);
248
249 guint osm_way_number_of_nodes(way_t *way);
250 relation_chain_t *osm_node_to_relation(osm_t *osm, node_t *node);
251 relation_chain_t *osm_way_to_relation(osm_t *osm, way_t *way);
252 way_chain_t *osm_node_to_way(osm_t *osm, node_t *node);
253
254 /* ----------- edit functions ----------- */
255 node_t *osm_node_new(osm_t *osm, gint x, gint y);
256 void osm_node_attach(osm_t *osm, node_t *node);
257 void osm_node_restore(osm_t *osm, node_t *node);
258 way_chain_t *osm_node_delete(osm_t *osm, struct icon_s **icon, node_t *node,
259 gboolean permanently, gboolean affect_ways);
260 void osm_way_delete(osm_t *osm, struct icon_s **icon, way_t *way,
261 gboolean permanently);
262
263 way_t *osm_way_new(void);
264 void osm_way_attach(osm_t *osm, way_t *way);
265
266 gboolean osm_position_within_bounds(osm_t *osm, gint x, gint y);
267 item_id_t osm_new_way_id(osm_t *osm);
268 gboolean osm_way_ends_with_node(way_t *way, node_t *node);
269
270 void osm_way_reverse(way_t *way);
271 guint osm_way_reverse_direction_sensitive_tags(way_t *way);
272 guint osm_way_reverse_direction_sensitive_roles(osm_t *osm, way_t *way);
273
274 void osm_node_remove_from_relation(osm_t *osm, node_t *node);
275 void osm_way_remove_from_relation(osm_t *osm, way_t *way);
276
277 node_t *osm_way_get_last_node(way_t *way);
278 node_t *osm_way_get_first_node(way_t *way);
279 void osm_way_rotate(way_t *way, gint offset);
280
281 tag_t *osm_tags_copy(tag_t *tag, gboolean update_creator);
282
283 relation_t *osm_relation_new(void);
284 void osm_relation_free(relation_t *relation);
285 void osm_relation_attach(osm_t *osm, relation_t *relation);
286 void osm_relation_delete(osm_t *osm, relation_t *relation,
287 gboolean permanently);
288 gint osm_relation_members_num(relation_t *relation);
289
290 char *osm_object_type_string(object_t *object);
291 char *osm_object_id_string(object_t *object);
292 char *osm_object_string(object_t *object);
293 tag_t *osm_object_get_tags(object_t *object);
294 void osm_object_set_flags(object_t *map_item, int set, int clr);
295
296 #endif /* OSM_H */
297
298 // vim:et:ts=8:sw=2:sts=2:ai