Contents of /trunk/src/osm.h

Parent Directory Parent Directory | Revision Log Revision Log


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