navit  0.5.3-trunk
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 
58 struct map_selection {
59  struct map_selection *next;
60  union {
61  struct coord_rect c_rect;
62  struct point_rect p_rect;
63  } u;
64  int order;
65  struct item_range range;
66 };
67 
80 struct map_methods {
81  enum projection pro;
82  char *charset;
83  void (*map_destroy)(struct map_priv *priv);
84  struct map_rect_priv * (*map_rect_new)(struct map_priv *map, struct map_selection *sel);
85  void (*map_rect_destroy)(struct map_rect_priv *mr);
86  struct item * (*map_rect_get_item)(struct map_rect_priv *mr);
87  struct item * (*map_rect_get_item_byid)(struct map_rect_priv *mr, int id_hi, int id_lo);
88  struct map_search_priv *(*map_search_new)(struct map_priv *map, struct item *item, struct attr *search, int partial);
90  struct item * (*map_search_get_item)(struct map_search_priv *ms);
91  struct item * (*map_rect_create_item)(struct map_rect_priv *mr, enum item_type type);
92  int (*map_get_attr)(struct map_priv *priv, enum attr_type type, struct attr *attr);
93  int (*map_set_attr)(struct map_priv *priv, struct attr *attr);
94 };
95 
108 static inline int
110 {
111  struct map_selection *curr=sel;
112  while (curr) {
113  struct coord_rect *r=&curr->u.c_rect;
114  if (c->x >= r->lu.x && c->x <= r->rl.x &&
115  c->y <= r->lu.y && c->y >= r->rl.y)
116  return 1;
117  curr=curr->next;
118  }
119  return sel ? 0:1;
120 }
121 
132 static inline int
133 map_selection_contains_polyline(struct map_selection *sel, struct coord *c, int count)
134 {
135  int i,x_mi,x_ma,y_mi,y_ma;
136  struct map_selection *curr;
137 
138  if (! sel)
139  return 1;
140  for (i = 0 ; i < count-1 ; i++) {
141  x_mi=c[i].x;
142  if (c[i+1].x < x_mi)
143  x_mi=c[i+1].x;
144  x_ma=c[i].x;
145  if (c[i+1].x > x_ma)
146  x_ma=c[i+1].x;
147  y_mi=c[i].y;
148  if (c[i+1].y < y_mi)
149  y_mi=c[i+1].y;
150  y_ma=c[i].y;
151  if (c[i+1].y > y_ma)
152  y_ma=c[i+1].y;
153  curr=sel;
154  while (curr) {
155  struct coord_rect *sr=&curr->u.c_rect;
156  if (x_mi <= sr->rl.x && x_ma >= sr->lu.x &&
157  y_ma >= sr->rl.y && y_mi <= sr->lu.y)
158  return 1;
159  curr=curr->next;
160  }
161  }
162  return 0;
163 }
164 
174 static inline int
176 {
177  struct map_selection *curr;
178 
179  dbg_assert(r->lu.x <= r->rl.x);
180  dbg_assert(r->lu.y >= r->rl.y);
181 
182  if (! sel)
183  return 1;
184  curr=sel;
185  while (curr) {
186  struct coord_rect *sr=&curr->u.c_rect;
187  dbg_assert(sr->lu.x <= sr->rl.x);
188  dbg_assert(sr->lu.y >= sr->rl.y);
189  if (r->lu.x <= sr->rl.x && r->rl.x >= sr->lu.x &&
190  r->lu.y >= sr->rl.y && r->rl.y <= sr->lu.y)
191  return 1;
192  curr=curr->next;
193  }
194  return 0;
195 }
196 
197 
208 static inline int
209 map_selection_contains_polygon(struct map_selection *sel, struct coord *c, int count)
210 {
211  struct coord_rect r;
212  int i;
213 
214  if (! sel)
215  return 1;
216  if (! count)
217  return 0;
218  r.lu=c[0];
219  r.rl=c[0];
220  for (i = 1 ; i < count ; i++) {
221  if (c[i].x < r.lu.x)
222  r.lu.x=c[i].x;
223  if (c[i].x > r.rl.x)
224  r.rl.x=c[i].x;
225  if (c[i].y < r.rl.y)
226  r.rl.y=c[i].y;
227  if (c[i].y > r.lu.y)
228  r.lu.y=c[i].y;
229  }
230  return map_selection_contains_rect(sel, &r);
231 }
232 
233 /* prototypes */
234 enum attr_type;
235 enum projection;
236 struct attr;
237 struct attr_iter;
238 struct callback;
239 struct item;
240 
253 struct map;
254 
260 struct map_priv;
261 
278 struct map_rect;
279 
286 struct map_search;
287 
288 struct map_selection;
289 struct pcoord;
290 struct map *map_new(struct attr *parent, struct attr **attrs);
291 struct map *map_ref(struct map* m);
292 void map_unref(struct map* m);
293 int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
294 int map_set_attr(struct map *this_, struct attr *attr);
295 void map_add_callback(struct map *this_, struct callback *cb);
296 void map_remove_callback(struct map *this_, struct callback *cb);
297 int map_requires_conversion(struct map *this_);
298 char *map_convert_string_tmp(struct map *this_, char *str);
299 char *map_convert_string(struct map *this_, char *str);
300 char *map_convert_dup(char *str);
301 void map_convert_free(char *str);
302 enum projection map_projection(struct map *this_);
303 void map_set_projection(struct map *this_, enum projection pro);
304 void map_destroy(struct map *m);
305 struct map_rect *map_rect_new(struct map *m, struct map_selection *sel);
306 struct item *map_rect_get_item(struct map_rect *mr);
307 struct item *map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo);
308 struct item *map_rect_create_item(struct map_rect *mr, enum item_type type_);
309 void map_rect_destroy(struct map_rect *mr);
310 struct map_search *map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial);
311 struct item *map_search_get_item(struct map_search *this_);
312 void map_search_destroy(struct map_search *this_);
313 struct map_selection *map_selection_rect_new(struct pcoord *center, int distance, int order);
314 struct map_selection *map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to);
315 struct map_selection *map_selection_dup(struct map_selection *sel);
316 void map_selection_destroy(struct map_selection *sel);
317 int map_selection_contains_item_rect(struct map_selection *sel, struct item *item);
318 int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count);
319 int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type);
320 int map_priv_is(struct map *map, struct map_priv *priv);
321 void map_dump_filedesc(struct map *map, FILE *out);
322 void map_dump_file(struct map *map, const char *file);
323 void map_dump(struct map *map);
324 void map_destroy_do(struct map *m);
325 struct maps * maps_new(struct attr *parent, struct attr **attrs);
326 /* end of prototypes */
327 
328 #ifdef __cplusplus
329 }
330 #endif
331 #endif
attr_type
Definition: attr.h:34
#define dbg_assert(expr)
Definition: debug.h:60
struct tcoord center
Definition: garmin_img.c:2
char type[3]
Definition: garmin_img.c:2
item_type
Definition: item.h:29
GList * maps
Definition: map.c:29
void map_unref(struct map *m)
void map_destroy(struct map *m)
Destroys an opened map.
Definition: map.c:268
void map_destroy_do(struct map *m)
void map_search_destroy(struct map_search *this_)
Destroys a map search struct.
Definition: map.c:461
void map_set_projection(struct map *this_, enum projection pro)
Sets the projection of a map.
Definition: map.c:258
char * map_convert_dup(char *str)
Definition: map.c:225
struct item * map_search_get_item(struct map_search *this_)
Returns an item from a map search.
Definition: map.c:442
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:404
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:175
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:109
struct map_selection * map_selection_dup(struct map_selection *sel)
Duplicates a map selection.
Definition: map.c:531
void map_convert_free(char *str)
Frees the memory allocated for a converted string.
Definition: map.c:238
void map_selection_destroy(struct map_selection *sel)
Destroys a map selection.
Definition: map.c:540
struct map_rect * map_rect_new(struct map *m, struct map_selection *sel)
Creates a new map rect.
Definition: map.c:290
struct item * map_rect_create_item(struct map_rect *mr, enum item_type type_)
Definition: map.c:666
int map_set_attr(struct map *this_, struct attr *attr)
Sets an attribute of a map.
Definition: map.c:144
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:199
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:638
void map_add_callback(struct map *this_, struct callback *cb)
Registers a new callback for attribute-change.
Definition: map.c:161
void map_dump_filedesc(struct map *map, FILE *out)
Definition: map.c:642
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:590
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:133
enum projection map_projection(struct map *this_)
Returns the projection of a map.
Definition: map.c:248
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:506
struct map * map_new(struct attr *parent, struct attr **attrs)
Opens a new map.
Definition: map.c:82
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:345
struct map * map_ref(struct map *m)
struct maps * maps_new(struct attr *parent, struct attr **attrs)
Definition: maps.c:31
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:209
struct map_selection * map_selection_rect_new(struct pcoord *center, int distance, int order)
Creates a new rectangular map selection.
Definition: map.c:483
int map_requires_conversion(struct map *this_)
Checks if strings from a map have to be converted.
Definition: map.c:185
struct item * map_rect_get_item(struct map_rect *mr)
Gets the next item from a map rect.
Definition: map.c:317
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:616
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:559
void map_dump_file(struct map *map, const char *file)
Definition: map.c:651
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:119
void map_dump(struct map *map)
Definition: map.c:661
char * map_convert_string(struct map *this_, char *str)
Converts a string from a map.
Definition: map.c:220
void map_remove_callback(struct map *this_, struct callback *cb)
Removes a callback from the list of attribute-change callbacks.
Definition: map.c:174
void map_rect_destroy(struct map_rect *mr)
Destroys a map rect.
Definition: map.c:361
static struct item_bin item
Definition: osm.c:52
static struct pcoord c
Definition: popup.c:375
projection
Definition: projection.h:23
Definition: config_.c:47
Definition: attr.h:157
Definition: callback.c:27
Definition: coord.h:58
struct coord rl
Definition: coord.h:60
struct coord lu
Definition: coord.h:59
Definition: coord.h:34
int y
Definition: coord.h:36
int x
Definition: coord.h:35
Definition: file.h:36
Definition: item.h:124
Represents an object on a map.
Definition: item.h:115
int id_hi
Definition: item.h:117
int id_lo
Definition: item.h:118
Holds all functions a map plugin has to implement to be usable.
Definition: map.h:80
enum projection pro
Definition: map.h:81
void(* map_destroy)(struct map_priv *priv)
Definition: map.h:83
void(* map_search_destroy)(struct map_search_priv *ms)
Definition: map.h:89
void(* map_rect_destroy)(struct map_rect_priv *mr)
Definition: map.h:85
char * charset
Definition: map.h:82
int(* map_set_attr)(struct map_priv *priv, struct attr *attr)
Definition: map.h:93
int(* map_get_attr)(struct map_priv *priv, enum attr_type type, struct attr *attr)
Definition: map.h:92
Represents the map from a single binfile.
Definition: binfile.c:105
Implementation-specific map rect data.
Definition: binfile.c:137
Definition: map.c:62
struct map * m
Definition: map.c:63
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_selection ms
Definition: binfile.c:170
Definition: map.c:368
struct map * m
Definition: map.c:369
struct attr search_attr
Definition: map.c:370
Used to select data from a map.
Definition: map.h:58
int order
Definition: map.h:64
struct map_selection * next
Definition: map.h:59
struct point_rect p_rect
Definition: map.h:62
union map_selection::@8 u
struct coord_rect c_rect
Definition: map.h:61
Definition: map.c:55
Definition: gpx2navit_txt.h:51
Definition: coord.h:52
int y
Definition: coord.h:55
int x
Definition: coord.h:54
Definition: point.h:28
Definition: attr.h:153