2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
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.
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.
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.
22 * @brief Contains exported functions / structures for map.c
24 * This file contains code that works together with map.c and that is exported
39 * @brief Used to select data from a map
41 * This struct is used to select data from a map. This one the one hand builds a
42 * rectangle on the map and on the other hand selects an order for items of each
43 * layer. Note that passing NULL instead of a pointer to such a struct often means
44 * "get me everything".
46 * It's possible to link multiple selections in a linked list, see below.
48 struct map_selection {
49 struct map_selection *next; /**< Linked-List pointer */
51 struct coord_rect c_rect; /**< For building the rectangle based on coordinates */
52 struct point_rect p_rect; /**< For building the rectangle based on points */
54 int order; /**< Holds the order */
55 struct item_range range; /**< Range of items which should be delivered */
59 * @brief Holds all functions a map plugin has to implement to be useable
61 * This structure holds pointers to a map plugin's functions navit's core will call
62 * to communicate with the plugin. For further information look into map.c - there exist
63 * functions with the same names acting more or less as "wrappers" around the functions here.
64 * Especially the arguments (and their meaning) of each function will be described there.
67 enum projection pro; /**< The projection used for that type of map */
68 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. */
69 void (*map_destroy)(struct map_priv *priv); /**< Function used to destroy ("close") a map. */
70 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. */
71 void (*map_rect_destroy)(struct map_rect_priv *mr); /**< Function to destroy a map rect */
72 struct item * (*map_rect_get_item)(struct map_rect_priv *mr); /**< Function to return the next item from a map rect */
73 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 */
74 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 */
75 void (*map_search_destroy)(struct map_search_priv *ms); /**< Function to destroy a map search struct */
76 struct item * (*map_search_get_item)(struct map_search_priv *ms); /**< Function to get the next item of a search on the map */
77 struct item * (*map_rect_create_item)(struct map_rect_priv *mr, enum item_type type); /**< Function to create a new item in the map */
78 int (*map_get_attr)(struct map_priv *priv, enum attr_type type, struct attr *attr);
79 int (*map_set_attr)(struct map_priv *priv, struct attr *attr);
84 * @brief Checks if a coordinate is within a map selection
86 * Checks if a coordinate is within a map selection. Note that since a selection of NULL
87 * means "select everything", with sel = NULL this will always return true. If there are
88 * more than one selection in a linked-list, it is sufficient if only one of the selections
89 * contains the coordinate.
91 * @param sel The selection to check if the point is within
92 * @param c Coordinate to check if it is within the selection
93 * @return True if the coordinate is within one of the selections, False otherwise
96 map_selection_contains_point(struct map_selection *sel, struct coord *c)
98 struct map_selection *curr=sel;
100 struct coord_rect *r=&curr->u.c_rect;
101 if (c->x >= r->lu.x && c->x <= r->rl.x &&
102 c->y <= r->lu.y && c->y >= r->rl.y)
110 * @brief Checks if a polyline is within a map selection
112 * @sa Please refer to map_selection_contains_point()
114 * @param sel The selection to check if the polyline is within
115 * @param c Coordinates of the polyline to check if it is within the selection
116 * @param count Number of coordinates in c
117 * @return True if the polyline is within one of the selections, False otherwise
120 map_selection_contains_polyline(struct map_selection *sel, struct coord *c, int count)
122 int i,x_mi,x_ma,y_mi,y_ma;
123 struct map_selection *curr;
127 for (i = 0 ; i < count-1 ; i++) {
142 struct coord_rect *sr=&curr->u.c_rect;
143 if (x_mi <= sr->rl.x && x_ma >= sr->lu.x &&
144 y_ma >= sr->rl.y && y_mi <= sr->lu.y)
153 * @brief Checks if a rectangle is within a map selection
155 * @sa Please refer to map_selection_contains_point()
157 * @param sel The selection to check if the rectangle is within
158 * @param r Rectangle to be checked for
159 * @return True if the rectangle is within one of the selections, False otherwise
162 map_selection_contains_rect(struct map_selection *sel, struct coord_rect *r)
164 struct map_selection *curr;
166 dbg_assert(r->lu.x <= r->rl.x);
167 dbg_assert(r->lu.y >= r->rl.y);
173 struct coord_rect *sr=&curr->u.c_rect;
174 dbg_assert(sr->lu.x <= sr->rl.x);
175 dbg_assert(sr->lu.y >= sr->rl.y);
176 if (r->lu.x <= sr->rl.x && r->rl.x >= sr->lu.x &&
177 r->lu.y >= sr->rl.y && r->rl.y <= sr->lu.y)
186 * @brief Checks if a polygon is within a map selection
188 * @sa Please refer to map_selection_contains_point()
190 * @param sel The selection to check if the polygon is within
191 * @param c Pointer to coordinates of the polygon
192 * @param count Number of coordinates in c
193 * @return True if the polygon is within one of the selections, False otherwise
196 map_selection_contains_polygon(struct map_selection *sel, struct coord *c, int count)
207 for (i = 1 ; i < count ; i++) {
217 return map_selection_contains_rect(sel, &r);
231 struct map_selection;
233 struct map *map_new(struct attr *parent, struct attr **attrs);
234 int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
235 int map_set_attr(struct map *this_, struct attr *attr);
236 void map_add_callback(struct map *this_, struct callback *cb);
237 void map_remove_callback(struct map *this_, struct callback *cb);
238 int map_requires_conversion(struct map *this_);
239 char *map_convert_string(struct map *this_, char *str);
240 void map_convert_free(char *str);
241 enum projection map_projection(struct map *this_);
242 void map_set_projection(struct map *this_, enum projection pro);
243 void map_destroy(struct map *m);
244 struct map_rect *map_rect_new(struct map *m, struct map_selection *sel);
245 struct item *map_rect_get_item(struct map_rect *mr);
246 struct item *map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo);
247 void map_rect_destroy(struct map_rect *mr);
248 struct map_search *map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial);
249 struct item *map_search_get_item(struct map_search *this_);
250 void map_search_destroy(struct map_search *this_);
251 struct map_selection *map_selection_rect_new(struct pcoord *center, int distance, int order);
252 struct map_selection *map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to);
253 struct map_selection *map_selection_dup(struct map_selection *sel);
254 void map_selection_destroy(struct map_selection *sel);
255 int map_selection_contains_item_rect(struct map_selection *sel, struct item *item);
256 int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count);
257 int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type);
258 int map_priv_is(struct map *map, struct map_priv *priv);
259 void map_dump_filedesc(struct map *map, FILE *out);
260 void map_dump_file(struct map *map, const char *file);
261 void map_dump(struct map *map);
262 /* end of prototypes */