Contents of /trunk/src/osm.h

Parent Directory Parent Directory | Revision Log Revision Log


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