Contents of /trunk/src/osm.h

Parent Directory Parent Directory | Revision Log Revision Log


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