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 |
#ifdef __cplusplus
|
32 |
extern "C" {
|
33 |
#endif
|
34 |
|
35 |
struct map_priv;
|
36 |
struct attr;
|
37 |
#include "coord.h"
|
38 |
#include "point.h"
|
39 |
#include "layer.h"
|
40 |
#include "debug.h"
|
41 |
|
42 |
/**
|
43 |
* @brief Used to select data from a map
|
44 |
*
|
45 |
* This struct is used to select data from a map. This one the one hand builds a
|
46 |
* rectangle on the map and on the other hand selects an order for items of each
|
47 |
* layer. Note that passing NULL instead of a pointer to such a struct often means
|
48 |
* "get me everything".
|
49 |
*
|
50 |
* It's possible to link multiple selections in a linked list, see below.
|
51 |
*/
|
52 |
struct map_selection {
|
53 |
struct map_selection *next; /**< Linked-List pointer */
|
54 |
union {
|
55 |
struct coord_rect c_rect; /**< For building the rectangle based on coordinates */
|
56 |
struct point_rect p_rect; /**< For building the rectangle based on points */
|
57 |
} u;
|
58 |
int order; /**< Holds the order */
|
59 |
struct item_range range; /**< Range of items which should be delivered */
|
60 |
};
|
61 |
|
62 |
/**
|
63 |
* @brief Holds all functions a map plugin has to implement to be useable
|
64 |
*
|
65 |
* This structure holds pointers to a map plugin's functions navit's core will call
|
66 |
* to communicate with the plugin. For further information look into map.c - there exist
|
67 |
* functions with the same names acting more or less as "wrappers" around the functions here.
|
68 |
* Especially the arguments (and their meaning) of each function will be described there.
|
69 |
*/
|
70 |
struct map_methods {
|
71 |
enum projection pro; /**< The projection used for that type of map */
|
72 |
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. */
|
73 |
void (*map_destroy)(struct map_priv *priv); /**< Function used to destroy ("close") a map. */
|
74 |
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. */
|
75 |
void (*map_rect_destroy)(struct map_rect_priv *mr); /**< Function to destroy a map rect */
|
76 |
struct item * (*map_rect_get_item)(struct map_rect_priv *mr); /**< Function to return the next item from a map rect */
|
77 |
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 */
|
78 |
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 */
|
79 |
void (*map_search_destroy)(struct map_search_priv *ms); /**< Function to destroy a map search struct */
|
80 |
struct item * (*map_search_get_item)(struct map_search_priv *ms); /**< Function to get the next item of a search on the map */
|
81 |
struct item * (*map_rect_create_item)(struct map_rect_priv *mr, enum item_type type); /**< Function to create a new item in the map */
|
82 |
int (*map_get_attr)(struct map_priv *priv, enum attr_type type, struct attr *attr);
|
83 |
int (*map_set_attr)(struct map_priv *priv, struct attr *attr);
|
84 |
|
85 |
};
|
86 |
|
87 |
/**
|
88 |
* @brief Checks if a coordinate is within a map selection
|
89 |
*
|
90 |
* Checks if a coordinate is within a map selection. Note that since a selection of NULL
|
91 |
* means "select everything", with sel = NULL this will always return true. If there are
|
92 |
* more than one selection in a linked-list, it is sufficient if only one of the selections
|
93 |
* contains the coordinate.
|
94 |
*
|
95 |
* @param sel The selection to check if the point is within
|
96 |
* @param c Coordinate to check if it is within the selection
|
97 |
* @return True if the coordinate is within one of the selections, False otherwise
|
98 |
*/
|
99 |
static inline int
|
100 |
map_selection_contains_point(struct map_selection *sel, struct coord *c)
|
101 |
{
|
102 |
struct map_selection *curr=sel;
|
103 |
while (curr) {
|
104 |
struct coord_rect *r=&curr->u.c_rect;
|
105 |
if (c->x >= r->lu.x && c->x <= r->rl.x &&
|
106 |
c->y <= r->lu.y && c->y >= r->rl.y)
|
107 |
return 1;
|
108 |
curr=curr->next;
|
109 |
}
|
110 |
return sel ? 0:1;
|
111 |
}
|
112 |
|
113 |
/**
|
114 |
* @brief Checks if a polyline is within a map selection
|
115 |
*
|
116 |
* @sa Please refer to map_selection_contains_point()
|
117 |
*
|
118 |
* @param sel The selection to check if the polyline is within
|
119 |
* @param c Coordinates of the polyline to check if it is within the selection
|
120 |
* @param count Number of coordinates in c
|
121 |
* @return True if the polyline is within one of the selections, False otherwise
|
122 |
*/
|
123 |
static inline int
|
124 |
map_selection_contains_polyline(struct map_selection *sel, struct coord *c, int count)
|
125 |
{
|
126 |
int i,x_mi,x_ma,y_mi,y_ma;
|
127 |
struct map_selection *curr;
|
128 |
|
129 |
if (! sel)
|
130 |
return 1;
|
131 |
for (i = 0 ; i < count-1 ; i++) {
|
132 |
x_mi=c[i].x;
|
133 |
if (c[i+1].x < x_mi)
|
134 |
x_mi=c[i+1].x;
|
135 |
x_ma=c[i].x;
|
136 |
if (c[i+1].x > x_ma)
|
137 |
x_ma=c[i+1].x;
|
138 |
y_mi=c[i].y;
|
139 |
if (c[i+1].y < y_mi)
|
140 |
y_mi=c[i+1].y;
|
141 |
y_ma=c[i].y;
|
142 |
if (c[i+1].y > y_ma)
|
143 |
y_ma=c[i+1].y;
|
144 |
curr=sel;
|
145 |
while (curr) {
|
146 |
struct coord_rect *sr=&curr->u.c_rect;
|
147 |
if (x_mi <= sr->rl.x && x_ma >= sr->lu.x &&
|
148 |
y_ma >= sr->rl.y && y_mi <= sr->lu.y)
|
149 |
return 1;
|
150 |
curr=curr->next;
|
151 |
}
|
152 |
}
|
153 |
return 0;
|
154 |
}
|
155 |
|
156 |
/**
|
157 |
* @brief Checks if a rectangle is within a map selection
|
158 |
*
|
159 |
* @sa Please refer to map_selection_contains_point()
|
160 |
*
|
161 |
* @param sel The selection to check if the rectangle is within
|
162 |
* @param r Rectangle to be checked for
|
163 |
* @return True if the rectangle is within one of the selections, False otherwise
|
164 |
*/
|
165 |
static inline int
|
166 |
map_selection_contains_rect(struct map_selection *sel, struct coord_rect *r)
|
167 |
{
|
168 |
struct map_selection *curr;
|
169 |
|
170 |
dbg_assert(r->lu.x <= r->rl.x);
|
171 |
dbg_assert(r->lu.y >= r->rl.y);
|
172 |
|
173 |
if (! sel)
|
174 |
return 1;
|
175 |
curr=sel;
|
176 |
while (curr) {
|
177 |
struct coord_rect *sr=&curr->u.c_rect;
|
178 |
dbg_assert(sr->lu.x <= sr->rl.x);
|
179 |
dbg_assert(sr->lu.y >= sr->rl.y);
|
180 |
if (r->lu.x <= sr->rl.x && r->rl.x >= sr->lu.x &&
|
181 |
r->lu.y >= sr->rl.y && r->rl.y <= sr->lu.y)
|
182 |
return 1;
|
183 |
curr=curr->next;
|
184 |
}
|
185 |
return 0;
|
186 |
}
|
187 |
|
188 |
|
189 |
/**
|
190 |
* @brief Checks if a polygon is within a map selection
|
191 |
*
|
192 |
* @sa Please refer to map_selection_contains_point()
|
193 |
*
|
194 |
* @param sel The selection to check if the polygon is within
|
195 |
* @param c Pointer to coordinates of the polygon
|
196 |
* @param count Number of coordinates in c
|
197 |
* @return True if the polygon is within one of the selections, False otherwise
|
198 |
*/
|
199 |
static inline int
|
200 |
map_selection_contains_polygon(struct map_selection *sel, struct coord *c, int count)
|
201 |
{
|
202 |
struct coord_rect r;
|
203 |
int i;
|
204 |
|
205 |
if (! sel)
|
206 |
return 1;
|
207 |
if (! count)
|
208 |
return 0;
|
209 |
r.lu=c[0];
|
210 |
r.rl=c[0];
|
211 |
for (i = 1 ; i < count ; i++) {
|
212 |
if (c[i].x < r.lu.x)
|
213 |
r.lu.x=c[i].x;
|
214 |
if (c[i].x > r.rl.x)
|
215 |
r.rl.x=c[i].x;
|
216 |
if (c[i].y < r.rl.y)
|
217 |
r.rl.y=c[i].y;
|
218 |
if (c[i].y > r.lu.y)
|
219 |
r.lu.y=c[i].y;
|
220 |
}
|
221 |
return map_selection_contains_rect(sel, &r);
|
222 |
}
|
223 |
|
224 |
/* prototypes */
|
225 |
enum attr_type;
|
226 |
enum projection;
|
227 |
struct attr;
|
228 |
struct attr_iter;
|
229 |
struct callback;
|
230 |
struct item;
|
231 |
struct map;
|
232 |
struct map_priv;
|
233 |
struct map_rect;
|
234 |
struct map_search;
|
235 |
struct map_selection;
|
236 |
struct pcoord;
|
237 |
struct map *map_new(struct attr *parent, struct attr **attrs);
|
238 |
void map_ref(struct map* m);
|
239 |
int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
|
240 |
int map_set_attr(struct map *this_, struct attr *attr);
|
241 |
void map_add_callback(struct map *this_, struct callback *cb);
|
242 |
void map_remove_callback(struct map *this_, struct callback *cb);
|
243 |
int map_requires_conversion(struct map *this_);
|
244 |
char *map_convert_string(struct map *this_, char *str);
|
245 |
void map_convert_free(char *str);
|
246 |
enum projection map_projection(struct map *this_);
|
247 |
void map_set_projection(struct map *this_, enum projection pro);
|
248 |
void map_destroy(struct map *m);
|
249 |
struct map_rect *map_rect_new(struct map *m, struct map_selection *sel);
|
250 |
struct item *map_rect_get_item(struct map_rect *mr);
|
251 |
struct item *map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo);
|
252 |
struct item *map_rect_create_item(struct map_rect *mr, enum item_type type_);
|
253 |
void map_rect_destroy(struct map_rect *mr);
|
254 |
struct map_search *map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial);
|
255 |
struct item *map_search_get_item(struct map_search *this_);
|
256 |
void map_search_destroy(struct map_search *this_);
|
257 |
struct map_selection *map_selection_rect_new(struct pcoord *center, int distance, int order);
|
258 |
struct map_selection *map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to);
|
259 |
struct map_selection *map_selection_dup(struct map_selection *sel);
|
260 |
void map_selection_destroy(struct map_selection *sel);
|
261 |
int map_selection_contains_item_rect(struct map_selection *sel, struct item *item);
|
262 |
int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count);
|
263 |
int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type);
|
264 |
int map_priv_is(struct map *map, struct map_priv *priv);
|
265 |
void map_dump_filedesc(struct map *map, FILE *out);
|
266 |
void map_dump_file(struct map *map, const char *file);
|
267 |
void map_dump(struct map *map);
|
268 |
void map_destroy_do(struct map *m);
|
269 |
/* end of prototypes */
|
270 |
|
271 |
#ifdef __cplusplus
|
272 |
}
|
273 |
#endif
|
274 |
#endif
|