navit  0.5.1-trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups
map.h
Go to the documentation of this file.
1 
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 #define WORLD_BOUNDINGBOX_MIN_X -20000000
43 #define WORLD_BOUNDINGBOX_MAX_X 20000000
44 #define WORLD_BOUNDINGBOX_MIN_Y -20000000
45 #define WORLD_BOUNDINGBOX_MAX_Y 20000000
46 
57 struct map_selection {
58  struct map_selection *next;
59  union {
60  struct coord_rect c_rect;
61  struct point_rect p_rect;
62  } u;
63  int order;
64  struct item_range range;
65 };
66 
75 struct map_methods {
76  enum projection pro;
77  char *charset;
78  void (*map_destroy)(struct map_priv *priv);
79  struct map_rect_priv * (*map_rect_new)(struct map_priv *map, struct map_selection *sel);
80  void (*map_rect_destroy)(struct map_rect_priv *mr);
81  struct item * (*map_rect_get_item)(struct map_rect_priv *mr);
82  struct item * (*map_rect_get_item_byid)(struct map_rect_priv *mr, int id_hi, int id_lo);
83  struct map_search_priv *(*map_search_new)(struct map_priv *map, struct item *item, struct attr *search, int partial);
85  struct item * (*map_search_get_item)(struct map_search_priv *ms);
86  struct item * (*map_rect_create_item)(struct map_rect_priv *mr, enum item_type type);
87  int (*map_get_attr)(struct map_priv *priv, enum attr_type type, struct attr *attr);
88  int (*map_set_attr)(struct map_priv *priv, struct attr *attr);
90 };
91 
104 static inline int
106 {
107  struct map_selection *curr=sel;
108  while (curr) {
109  struct coord_rect *r=&curr->u.c_rect;
110  if (c->x >= r->lu.x && c->x <= r->rl.x &&
111  c->y <= r->lu.y && c->y >= r->rl.y)
112  return 1;
113  curr=curr->next;
114  }
115  return sel ? 0:1;
116 }
117 
128 static inline int
129 map_selection_contains_polyline(struct map_selection *sel, struct coord *c, int count)
130 {
131  int i,x_mi,x_ma,y_mi,y_ma;
132  struct map_selection *curr;
133 
134  if (! sel)
135  return 1;
136  for (i = 0 ; i < count-1 ; i++) {
137  x_mi=c[i].x;
138  if (c[i+1].x < x_mi)
139  x_mi=c[i+1].x;
140  x_ma=c[i].x;
141  if (c[i+1].x > x_ma)
142  x_ma=c[i+1].x;
143  y_mi=c[i].y;
144  if (c[i+1].y < y_mi)
145  y_mi=c[i+1].y;
146  y_ma=c[i].y;
147  if (c[i+1].y > y_ma)
148  y_ma=c[i+1].y;
149  curr=sel;
150  while (curr) {
151  struct coord_rect *sr=&curr->u.c_rect;
152  if (x_mi <= sr->rl.x && x_ma >= sr->lu.x &&
153  y_ma >= sr->rl.y && y_mi <= sr->lu.y)
154  return 1;
155  curr=curr->next;
156  }
157  }
158  return 0;
159 }
160 
170 static inline int
172 {
173  struct map_selection *curr;
174 
175  dbg_assert(r->lu.x <= r->rl.x);
176  dbg_assert(r->lu.y >= r->rl.y);
177 
178  if (! sel)
179  return 1;
180  curr=sel;
181  while (curr) {
182  struct coord_rect *sr=&curr->u.c_rect;
183  dbg_assert(sr->lu.x <= sr->rl.x);
184  dbg_assert(sr->lu.y >= sr->rl.y);
185  if (r->lu.x <= sr->rl.x && r->rl.x >= sr->lu.x &&
186  r->lu.y >= sr->rl.y && r->rl.y <= sr->lu.y)
187  return 1;
188  curr=curr->next;
189  }
190  return 0;
191 }
192 
193 
204 static inline int
205 map_selection_contains_polygon(struct map_selection *sel, struct coord *c, int count)
206 {
207  struct coord_rect r;
208  int i;
209 
210  if (! sel)
211  return 1;
212  if (! count)
213  return 0;
214  r.lu=c[0];
215  r.rl=c[0];
216  for (i = 1 ; i < count ; i++) {
217  if (c[i].x < r.lu.x)
218  r.lu.x=c[i].x;
219  if (c[i].x > r.rl.x)
220  r.rl.x=c[i].x;
221  if (c[i].y < r.rl.y)
222  r.rl.y=c[i].y;
223  if (c[i].y > r.lu.y)
224  r.lu.y=c[i].y;
225  }
226  return map_selection_contains_rect(sel, &r);
227 }
228 
229 /* prototypes */
230 enum attr_type;
231 enum projection;
232 struct attr;
233 struct attr_iter;
234 struct callback;
235 struct item;
236 struct map;
237 struct map_priv;
238 struct map_rect;
239 struct map_search;
240 struct map_selection;
241 struct pcoord;
242 struct map *map_new(struct attr *parent, struct attr **attrs);
243 struct map *map_ref(struct map* m);
244 void map_unref(struct map* m);
245 int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
246 int map_set_attr(struct map *this_, struct attr *attr);
247 void map_add_callback(struct map *this_, struct callback *cb);
248 void map_remove_callback(struct map *this_, struct callback *cb);
249 int map_requires_conversion(struct map *this_);
250 char *map_convert_string_tmp(struct map *this_, char *str);
251 char *map_convert_string(struct map *this_, char *str);
252 char *map_convert_dup(char *str);
253 void map_convert_free(char *str);
254 enum projection map_projection(struct map *this_);
255 void map_set_projection(struct map *this_, enum projection pro);
256 void map_destroy(struct map *m);
257 struct map_rect *map_rect_new(struct map *m, struct map_selection *sel);
258 struct item *map_rect_get_item(struct map_rect *mr);
259 struct item *map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo);
260 struct item *map_rect_create_item(struct map_rect *mr, enum item_type type_);
261 void map_rect_destroy(struct map_rect *mr);
262 struct map_search *map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial);
263 struct item *map_search_get_item(struct map_search *this_);
264 void map_search_destroy(struct map_search *this_);
265 struct map_selection *map_selection_rect_new(struct pcoord *center, int distance, int order);
266 struct map_selection *map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to);
267 struct map_selection *map_selection_dup(struct map_selection *sel);
268 void map_selection_destroy(struct map_selection *sel);
269 int map_selection_contains_item_rect(struct map_selection *sel, struct item *item);
270 int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count);
271 int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type);
272 int map_priv_is(struct map *map, struct map_priv *priv);
273 void map_dump_filedesc(struct map *map, FILE *out);
274 void map_dump_file(struct map *map, const char *file);
275 void map_dump(struct map *map);
276 void map_destroy_do(struct map *m);
277 struct maps * maps_new(struct attr *parent, struct attr **attrs);
278 /* end of prototypes */
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 #endif
struct item * map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo)
Returns the item specified by the ID.
Definition: map.c:374
struct item * map_rect_create_item(struct map_rect *mr, enum item_type type_)
Definition: map.c:725
int map_priv_is(struct map *map, struct map_priv *priv)
Checks if a pointer points to the private data of a map.
Definition: map.c:690
attr_type
Definition: attr.h:34
GList * maps
Definition: map.c:29
Represents a search on a map. This struct represents a search on a map; it is created when starting a...
Definition: binfile.c:164
struct map * m
Definition: map.c:407
int(* map_get_attr)(struct map_priv *priv, enum attr_type type, struct attr *attr)
Definition: map.h:87
void map_rect_destroy(struct map_rect *mr)
Destroys a map rect.
Definition: map.c:392
void(* map_rect_destroy)(struct map_rect_priv *mr)
Definition: map.h:80
void map_set_projection(struct map *this_, enum projection pro)
Sets the projection of a map.
Definition: map.c:290
tuple iter
Definition: eval.py:8
Definition: gpx2navit_txt.h:51
int y
Definition: coord.h:36
int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type)
Checks if a selection contains a item.
Definition: map.c:666
void map_unref(struct map *m)
void(* map_search_destroy)(struct map_search_priv *ms)
Definition: map.h:84
int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count)
Checks if a selection contains a item range.
Definition: map.c:638
struct coord_rect c_rect
Definition: map.h:60
Definition: item.h:99
char * map_convert_string(struct map *this_, char *str)
Converts a string from a map.
Definition: map.c:244
void map_dump_file(struct map *map, const char *file)
Definition: map.c:707
struct map * map_new(struct attr *parent, struct attr **attrs)
Opens a new map.
Definition: map.c:92
struct item * map_rect_get_item(struct map_rect *mr)
Gets the next item from a map rect.
Definition: map.c:353
struct map * map_ref(struct map *m)
union map_selection::@8 u
item_type
Definition: item.h:29
void map_add_callback(struct map *this_, struct callback *cb)
Registers a new callback for attribute-change.
Definition: map.c:177
void map_dump_filedesc(struct map *map, FILE *out)
Definition: map.c:696
static int map_selection_contains_rect(struct map_selection *sel, struct coord_rect *r)
Checks if a rectangle is within a map selection.
Definition: map.h:171
void map_dump(struct map *map)
Definition: map.c:719
Definition: item.h:108
struct coord lu
Definition: coord.h:47
int map_set_attr(struct map *this_, struct attr *attr)
Sets an attribute of a map.
Definition: map.c:158
Represents the map from a single binfile.
Definition: binfile.c:105
struct maps * maps_new(struct attr *parent, struct attr **attrs)
Definition: maps.c:31
Definition: binfile.c:137
static int map_selection_contains_polyline(struct map_selection *sel, struct coord *c, int count)
Checks if a polyline is within a map selection.
Definition: map.h:129
projection
Definition: projection.h:23
struct tcoord center
Definition: garmin_img.c:523
enum projection pro
Definition: map.h:76
struct map_selection * next
Definition: map.h:58
Definition: config_.c:48
struct map_selection * map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to)
Duplicates a map selection, transforming coordinates.
Definition: map.c:547
struct map_rect * map_rect_new(struct map *m, struct map_selection *sel)
Creates a new map rect.
Definition: map.c:325
Holds all functions a map plugin has to implement to be useable.
Definition: map.h:75
char * map_convert_string_tmp(struct map *this_, char *str)
Converts a string from a map into a temporary allocated buffer. Conversion is not performed and origi...
Definition: map.c:221
Describes a rectangular extract of a map.
Definition: map.c:72
int id_lo
Definition: item.h:102
void map_destroy(struct map *m)
Destroys an opened map.
Definition: map.c:302
enum projection map_projection(struct map *this_)
Returns the projection of a map.
Definition: map.c:278
static int map_selection_contains_point(struct map_selection *sel, struct coord *c)
Checks if a coordinate is within a map selection.
Definition: map.h:105
Definition: attr.h:152
Definition: attr.h:156
static struct item_bin item
Definition: osm.c:52
Used to select data from a map.
Definition: map.h:57
int map_selection_contains_item_rect(struct map_selection *sel, struct item *item)
Checks if a selection contains a rectangle containing an item.
Definition: map.c:605
struct point_rect p_rect
Definition: map.h:61
static int map_selection_contains_polygon(struct map_selection *sel, struct coord *c, int count)
Checks if a polygon is within a map selection.
Definition: map.h:205
int(* map_set_attr)(struct map_priv *priv, struct attr *attr)
Definition: map.h:88
Definition: callback.c:26
struct map_selection ms
Definition: binfile.c:170
void map_search_destroy(struct map_search *this_)
Destroys a map search struct.
Definition: map.c:500
struct map_selection * map_selection_dup(struct map_selection *sel)
Duplicates a map selection.
Definition: map.c:573
struct map_search * map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial)
Starts a search on a map.
Definition: map.c:442
void map_destroy_do(struct map *m)
int order
Definition: map.h:63
Holds information about a map.
Definition: map.c:60
struct map_selection * map_selection_rect_new(struct pcoord *center, int distance, int order)
Creates a new rectangular map selection.
Definition: map.c:523
Definition: point.h:28
void map_selection_destroy(struct map_selection *sel)
Destroys a map selection.
Definition: map.c:584
void(* map_destroy)(struct map_priv *priv)
Definition: map.h:78
struct item * map_search_get_item(struct map_search *this_)
Returns an item from a map search.
Definition: map.c:480
char * charset
Definition: map.h:77
char * map_convert_dup(char *str)
Definition: map.c:251
struct coord rl
Definition: coord.h:48
Definition: coord.h:46
typedef int(WINAPI *FP_SetStretchBltMode)(HDC dc
char type[3]
Definition: garmin_img.c:130
Definition: coord.h:34
#define dbg_assert(expr)
Definition: debug.h:60
void map_remove_callback(struct map *this_, struct callback *cb)
Removes a callback from the list of attribute-change callbacks.
Definition: map.c:192
Definition: coord.h:40
struct map * m
Definition: map.c:73
int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Gets an attribute from a map.
Definition: map.c:131
int map_requires_conversion(struct map *this_)
Checks if strings from a map have to be converted.
Definition: map.c:205
void map_convert_free(char *str)
Frees the memory allocated for a converted string.
Definition: map.c:266
struct attr search_attr
Definition: map.c:408
Holds information about a search on a map.
Definition: map.c:406
int id_hi
Definition: item.h:101
int x
Definition: coord.h:35
Definition: file.h:36