Parent Directory | Revision Log
Initial import
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 | |
99 | union { |
100 | struct { |
101 | gulong color; |
102 | gint width; |
103 | } bg; |
104 | |
105 | struct { |
106 | gulong color; |
107 | } area; |
108 | }; |
109 | } draw; |
110 | |
111 | /* a link to the visual representation on screen */ |
112 | struct map_item_chain_s *map_item_chain; |
113 | |
114 | struct way_s *next; |
115 | } way_t; |
116 | |
117 | typedef struct way_chain { |
118 | way_t *way; |
119 | struct way_chain *next; |
120 | } way_chain_t; |
121 | |
122 | typedef struct relation_s { |
123 | item_id_t id; |
124 | user_t *user; |
125 | gboolean visible; |
126 | time_t time; |
127 | tag_t *tag; |
128 | struct member_s *member; |
129 | int flags; |
130 | |
131 | struct relation_s *next; |
132 | } relation_t; |
133 | |
134 | typedef struct relation_chain_s { |
135 | relation_t *relation; |
136 | struct relation_chain_s *next; |
137 | } relation_chain_t; |
138 | |
139 | typedef enum { |
140 | ILLEGAL=0, NODE, WAY, RELATION, NODE_ID, WAY_ID, RELATION_ID |
141 | } type_t; |
142 | |
143 | typedef struct member_s { |
144 | type_t type; |
145 | char *role; |
146 | |
147 | union { |
148 | node_t *node; |
149 | way_t *way; |
150 | relation_t *relation; |
151 | item_id_t id; |
152 | }; |
153 | |
154 | struct member_s *next; |
155 | } member_t; |
156 | |
157 | typedef struct osm_s { |
158 | bounds_t *bounds; // original bounds as they appear in the file |
159 | user_t *user; |
160 | node_t *node; |
161 | way_t *way; |
162 | relation_t *relation; |
163 | } osm_t; |
164 | |
165 | #include <libxml/parser.h> |
166 | #include <libxml/tree.h> |
167 | |
168 | osm_t *osm_parse(char *filename); |
169 | gboolean osm_sanity_check(GtkWidget *parent, osm_t *osm); |
170 | tag_t *osm_parse_osm_tag(osm_t *osm, xmlDocPtr doc, xmlNode *a_node); |
171 | node_chain_t *osm_parse_osm_way_nd(osm_t *osm, xmlDocPtr doc, xmlNode *a_node); |
172 | member_t *osm_parse_osm_relation_member(osm_t *osm, xmlDocPtr doc, xmlNode *a_node); |
173 | void osm_dump(osm_t *osm); |
174 | void osm_free(struct icon_s **icon, osm_t *osm); |
175 | |
176 | char *osm_node_get_value(node_t *node, char *key); |
177 | gboolean osm_node_has_tag(node_t *node); |
178 | |
179 | void osm_node_dump(node_t *node); |
180 | |
181 | void osm_way_free(way_t *way); |
182 | void osm_way_dump(way_t *way); |
183 | char *osm_way_get_value(way_t *way, char *key); |
184 | gboolean osm_node_has_value(node_t *node, char *str); |
185 | gboolean osm_way_has_value(way_t *way, char *str); |
186 | void osm_way_append_node(way_t *way, node_t *node); |
187 | |
188 | gboolean osm_node_in_way(way_t *way, node_t *node); |
189 | |
190 | void osm_node_chain_free(node_chain_t *node_chain); |
191 | int osm_node_chain_length(node_chain_t *node_chain); |
192 | void osm_node_free(struct icon_s **icon, node_t *node); |
193 | |
194 | void osm_members_free(member_t *member); |
195 | void osm_member_free(member_t *member); |
196 | |
197 | void osm_tag_free(tag_t *tag); |
198 | void osm_tags_free(tag_t *tag); |
199 | char *osm_tag_get_by_key(tag_t *tag, char *key); |
200 | gboolean osm_is_creator_tag(tag_t *tag); |
201 | gboolean osm_tag_key_and_value_present(tag_t *haystack, tag_t *tag); |
202 | gboolean osm_tag_key_other_value_present(tag_t *haystack, tag_t *tag); |
203 | |
204 | char *osm_generate_xml_node(osm_t *osm, node_t *node); |
205 | char *osm_generate_xml_way(osm_t *osm, way_t *way); |
206 | char *osm_generate_xml_relation(osm_t *osm, relation_t *relation); |
207 | |
208 | node_t *osm_get_node_by_id(osm_t *osm, item_id_t id); |
209 | way_t *osm_get_way_by_id(osm_t *osm, item_id_t id); |
210 | relation_t *osm_get_relation_by_id(osm_t *osm, item_id_t id); |
211 | |
212 | guint osm_way_number_of_nodes(way_t *way); |
213 | relation_chain_t *osm_node_to_relation(osm_t *osm, node_t *node); |
214 | relation_chain_t *osm_way_to_relation(osm_t *osm, way_t *way); |
215 | way_chain_t *osm_node_to_way(osm_t *osm, node_t *node); |
216 | |
217 | /* ----------- edit functions ----------- */ |
218 | node_t *osm_node_new(osm_t *osm, gint x, gint y); |
219 | void osm_node_attach(osm_t *osm, node_t *node); |
220 | way_chain_t *osm_node_delete(osm_t *osm, struct icon_s **icon, node_t *node, |
221 | gboolean permanently, gboolean affect_ways); |
222 | void osm_way_delete(osm_t *osm, struct icon_s **icon, way_t *way, |
223 | gboolean permanently); |
224 | |
225 | way_t *osm_way_new(void); |
226 | void osm_way_attach(osm_t *osm, way_t *way); |
227 | |
228 | gboolean osm_position_within_bounds(osm_t *osm, gint x, gint y); |
229 | item_id_t osm_new_way_id(osm_t *osm); |
230 | gboolean osm_way_ends_with_node(way_t *way, node_t *node); |
231 | |
232 | void osm_way_revert(way_t *way); |
233 | |
234 | void osm_node_remove_from_relation(osm_t *osm, node_t *node); |
235 | void osm_way_remove_from_relation(osm_t *osm, way_t *way); |
236 | |
237 | node_t *osm_way_get_last_node(way_t *way); |
238 | node_t *osm_way_get_first_node(way_t *way); |
239 | void osm_way_rotate(way_t *way, gint offset); |
240 | |
241 | tag_t *osm_tags_copy(tag_t *tag, gboolean update_creator); |
242 | |
243 | #endif /* OSM_H */ |