Contents of /trunk/src/osm.h

Parent Directory Parent Directory | Revision Log Revision Log


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