Fix:Core:Removed no longer existing function call
[navit-package] / navit / map.h
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19
20 /** @file
21  * 
22  * @brief Contains exported functions / structures for map.c
23  *
24  * This file contains code that works together with map.c and that is exported
25  * to other modules.
26  */
27
28 #ifndef NAVIT_MAP_H
29 #define NAVIT_MAP_H
30
31 struct map_priv;
32 struct attr;
33 #include "coord.h"
34 #include "point.h"
35 #include "layer.h"
36
37 /**
38  * @brief Used to select data from a map
39  *
40  * This struct is used to select data from a map. This one the one hand builds a
41  * rectangle on the map and on the other hand selects an order for items of each
42  * layer. Note that passing NULL instead of a pointer to such a struct often means
43  * "get me everything".
44  *
45  * It's possible to link multiple selections in a linked list, see below.
46  */
47 struct map_selection {
48         struct map_selection *next;     /**< Linked-List pointer */
49         union {
50                 struct coord_rect c_rect;   /**< For building the rectangle based on coordinates */
51                 struct point_rect p_rect;   /**< For building the rectangle based on points */
52         } u;
53         int order[layer_end];               /**< Holds the order to be selected for each layer of items */
54 };
55
56 /**
57  * @brief Holds all functions a map plugin has to implement to be useable
58  *
59  * This structure holds pointers to a map plugin's functions navit's core will call
60  * to communicate with the plugin. For further information look into map.c - there exist
61  * functions with the same names acting more or less as "wrappers" around the functions here.
62  * Especially the arguments (and their meaning) of each function will be described there.
63  */
64 struct map_methods {
65         enum projection pro;        /**< The projection used for that type of map */
66         char *charset;              /**< The charset this map uses - e.g. "iso8859-1" or "utf-8". Please specify this in a form so that g_convert() can handle it. */
67         void                    (*map_destroy)(struct map_priv *priv);  /**< Function used to destroy ("close") a map. */
68         struct map_rect_priv *  (*map_rect_new)(struct map_priv *map, struct map_selection *sel); /**< Function to create a new map rect on the map. */
69         void                    (*map_rect_destroy)(struct map_rect_priv *mr); /**< Function to destroy a map rect */
70         struct item *           (*map_rect_get_item)(struct map_rect_priv *mr); /**< Function to return the next item from a map rect */
71         struct item *           (*map_rect_get_item_byid)(struct map_rect_priv *mr, int id_hi, int id_lo); /**< Function to get an item with a specific ID from a map rect */
72         struct map_search_priv *(*map_search_new)(struct map_priv *map, struct item *item, struct attr *search, int partial); /**< Function to start a new search on the map */
73         void                    (*map_search_destroy)(struct map_search_priv *ms); /**< Function to destroy a map search struct */
74         struct item *           (*map_search_get_item)(struct map_search_priv *ms); /**< Function to get the next item of a search on the map */
75 };
76
77 /**
78  * @brief Checks if a coordinate is within a map selection
79  *
80  * Checks if a coordinate is within a map selection. Note that since a selection of NULL
81  * means "select everything", with sel = NULL this will always return true. If there are
82  * more than one selection in a linked-list, it is sufficient if only one of the selections
83  * contains the coordinate.
84  *
85  * @param sel The selection to check if the point is within
86  * @param c Coordinate to check if it is within the selection
87  * @return True if the coordinate is within one of the selections, False otherwise
88  */
89 static inline int
90 map_selection_contains_point(struct map_selection *sel, struct coord *c)
91 {
92         struct map_selection *curr=sel;
93         while (curr) {
94                 struct coord_rect *r=&curr->u.c_rect;
95                 if (c->x >= r->lu.x && c->x <= r->rl.x &&
96                     c->y <= r->lu.y && c->y >= r->rl.y)
97                         return 1;
98                 curr=curr->next;
99         }
100         return sel ? 0:1;
101 }
102
103 /**
104  * @brief Checks if a polyline is within a map selection
105  *
106  * @sa Please refer to map_selection_contains_point()
107  *
108  * @param sel The selection to check if the polyline is within
109  * @param c Coordinates of the polyline to check if it is within the selection
110  * @param count Number of coordinates in c
111  * @return True if the polyline is within one of the selections, False otherwise
112  */
113 static inline int
114 map_selection_contains_polyline(struct map_selection *sel, struct coord *c, int count)
115 {
116         int i,x_mi,x_ma,y_mi,y_ma;
117         struct map_selection *curr;
118
119         if (! sel)
120                 return 1;
121         for (i = 0 ; i < count-1 ; i++) {
122                 x_mi=c[i].x;
123                 if (c[i+1].x < x_mi)
124                         x_mi=c[i+1].x;
125                 x_ma=c[i].x;
126                 if (c[i+1].x > x_ma)
127                         x_ma=c[i+1].x;
128                 y_mi=c[i].y;
129                 if (c[i+1].y < y_mi)
130                         y_mi=c[i+1].y;
131                 y_ma=c[i].y;
132                 if (c[i+1].y > y_ma)
133                         y_ma=c[i+1].y;
134                 curr=sel;
135                 while (curr) {
136                         struct coord_rect *sr=&curr->u.c_rect;
137                         if (x_mi <= sr->rl.x && x_ma >= sr->lu.x &&
138                             y_ma >= sr->rl.y && y_mi <= sr->lu.y)
139                                 return 1;
140                         curr=curr->next;
141                 }
142         }
143         return 0;
144 }
145
146 /**
147  * @brief Checks if a rectangle is within a map selection
148  *
149  * @sa Please refer to map_selection_contains_point()
150  *
151  * @param sel The selection to check if the rectangle is within
152  * @param r Rectangle to be checked for
153  * @return True if the rectangle is within one of the selections, False otherwise
154  */
155 static inline int
156 map_selection_contains_rect(struct map_selection *sel, struct coord_rect *r)
157 {
158         struct map_selection *curr;
159
160         g_assert(r->lu.x <= r->rl.x);
161         g_assert(r->lu.y >= r->rl.y);
162
163         if (! sel)
164                 return 1;
165         curr=sel;
166         while (curr) {
167                 struct coord_rect *sr=&curr->u.c_rect;
168                 g_assert(sr->lu.x <= sr->rl.x);
169                 g_assert(sr->lu.y >= sr->rl.y);
170                 if (r->lu.x <= sr->rl.x && r->rl.x >= sr->lu.x &&
171                     r->lu.y >= sr->rl.y && r->rl.y <= sr->lu.y)
172                         return 1;
173                 curr=curr->next;
174         }
175         return 0;
176 }
177
178
179 /**
180  * @brief Checks if a polygon is within a map selection
181  *
182  * @sa Please refer to map_selection_contains_point()
183  *
184  * @param sel The selection to check if the polygon  is within
185  * @param c Pointer to coordinates of the polygon
186  * @param count Number of coordinates in c
187  * @return True if the polygon is within one of the selections, False otherwise
188  */
189 static inline int
190 map_selection_contains_polygon(struct map_selection *sel, struct coord *c, int count)
191 {
192         struct coord_rect r;
193         int i;
194
195         if (! sel)
196                 return 1;
197         if (! count)
198                 return 0;
199         r.lu=c[0];
200         r.rl=c[0];
201         for (i = 1 ; i < count ; i++) {
202                 if (c[i].x < r.lu.x)
203                         r.lu.x=c[i].x;
204                 if (c[i].x > r.rl.x)
205                         r.rl.x=c[i].x;
206                 if (c[i].y < r.rl.y)
207                         r.rl.y=c[i].y;
208                 if (c[i].y > r.lu.y)
209                         r.lu.y=c[i].y;
210         }
211         return map_selection_contains_rect(sel, &r);
212 }
213
214 /* prototypes */
215 enum attr_type;
216 enum projection;
217 struct attr;
218 struct attr_iter;
219 struct callback;
220 struct item;
221 struct map;
222 struct map_priv;
223 struct map_rect;
224 struct map_search;
225 struct map_selection;
226 struct pcoord;
227 struct map *map_new(struct attr **attrs);
228 int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
229 int map_set_attr(struct map *this_, struct attr *attr);
230 void map_add_callback(struct map *this_, struct callback *cb);
231 void map_remove_callback(struct map *this_, struct callback *cb);
232 int map_requires_conversion(struct map *this_);
233 char *map_convert_string(struct map *this_, char *str);
234 void map_convert_free(char *str);
235 enum projection map_projection(struct map *this_);
236 void map_set_projection(struct map *this_, enum projection pro);
237 void map_destroy(struct map *m);
238 struct map_rect *map_rect_new(struct map *m, struct map_selection *sel);
239 struct item *map_rect_get_item(struct map_rect *mr);
240 struct item *map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo);
241 void map_rect_destroy(struct map_rect *mr);
242 struct map_search *map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial);
243 struct item *map_search_get_item(struct map_search *this_);
244 void map_search_destroy(struct map_search *this_);
245 struct map_selection *map_selection_rect_new(struct pcoord *center, int distance, int order);
246 struct map_selection *map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to);
247 struct map_selection *map_selection_dup(struct map_selection *sel);
248 void map_selection_destroy(struct map_selection *sel);
249 int map_selection_contains_item_rect(struct map_selection *sel, struct item *item);
250 int map_priv_is(struct map *map, struct map_priv *priv);
251 void map_dump(struct map *map);
252 /* end of prototypes */
253
254 #endif