Navit SVN

/work/compile/navit/src/navit/map.h

Go to the documentation of this file.
00001 
00028 #ifndef NAVIT_MAP_H
00029 #define NAVIT_MAP_H
00030 
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034 
00035 struct map_priv;
00036 struct attr;
00037 #include "coord.h"
00038 #include "point.h"
00039 #include "layer.h"
00040 #include "debug.h"
00041 
00052 struct map_selection {
00053         struct map_selection *next;     
00054         union {
00055                 struct coord_rect c_rect;   
00056                 struct point_rect p_rect;   
00057         } u;
00058         int order;                      
00059         struct item_range range;        
00060 };
00061 
00070 struct map_methods {
00071         enum projection pro;        
00072         char *charset;              
00073         void                    (*map_destroy)(struct map_priv *priv);  
00074         struct map_rect_priv *  (*map_rect_new)(struct map_priv *map, struct map_selection *sel); 
00075         void                    (*map_rect_destroy)(struct map_rect_priv *mr); 
00076         struct item *           (*map_rect_get_item)(struct map_rect_priv *mr); 
00077         struct item *           (*map_rect_get_item_byid)(struct map_rect_priv *mr, int id_hi, int id_lo); 
00078         struct map_search_priv *(*map_search_new)(struct map_priv *map, struct item *item, struct attr *search, int partial); 
00079         void                    (*map_search_destroy)(struct map_search_priv *ms); 
00080         struct item *           (*map_search_get_item)(struct map_search_priv *ms); 
00081         struct item *           (*map_rect_create_item)(struct map_rect_priv *mr, enum item_type type); 
00082         int                     (*map_get_attr)(struct map_priv *priv, enum attr_type type, struct attr *attr);
00083         int                     (*map_set_attr)(struct map_priv *priv, struct attr *attr);
00084 
00085 };
00086 
00099 static inline int
00100 map_selection_contains_point(struct map_selection *sel, struct coord *c)
00101 {
00102         struct map_selection *curr=sel;
00103         while (curr) {
00104                 struct coord_rect *r=&curr->u.c_rect;
00105                 if (c->x >= r->lu.x && c->x <= r->rl.x &&
00106                     c->y <= r->lu.y && c->y >= r->rl.y)
00107                         return 1;
00108                 curr=curr->next;
00109         }
00110         return sel ? 0:1;
00111 }
00112 
00123 static inline int
00124 map_selection_contains_polyline(struct map_selection *sel, struct coord *c, int count)
00125 {
00126         int i,x_mi,x_ma,y_mi,y_ma;
00127         struct map_selection *curr;
00128 
00129         if (! sel)
00130                 return 1;
00131         for (i = 0 ; i < count-1 ; i++) {
00132                 x_mi=c[i].x;
00133                 if (c[i+1].x < x_mi)
00134                         x_mi=c[i+1].x;
00135                 x_ma=c[i].x;
00136                 if (c[i+1].x > x_ma)
00137                         x_ma=c[i+1].x;
00138                 y_mi=c[i].y;
00139                 if (c[i+1].y < y_mi)
00140                         y_mi=c[i+1].y;
00141                 y_ma=c[i].y;
00142                 if (c[i+1].y > y_ma)
00143                         y_ma=c[i+1].y;
00144                 curr=sel;
00145                 while (curr) {
00146                         struct coord_rect *sr=&curr->u.c_rect;
00147                         if (x_mi <= sr->rl.x && x_ma >= sr->lu.x &&
00148                             y_ma >= sr->rl.y && y_mi <= sr->lu.y)
00149                                 return 1;
00150                         curr=curr->next;
00151                 }
00152         }
00153         return 0;
00154 }
00155 
00165 static inline int
00166 map_selection_contains_rect(struct map_selection *sel, struct coord_rect *r)
00167 {
00168         struct map_selection *curr;
00169 
00170         dbg_assert(r->lu.x <= r->rl.x);
00171         dbg_assert(r->lu.y >= r->rl.y);
00172 
00173         if (! sel)
00174                 return 1;
00175         curr=sel;
00176         while (curr) {
00177                 struct coord_rect *sr=&curr->u.c_rect;
00178                 dbg_assert(sr->lu.x <= sr->rl.x);
00179                 dbg_assert(sr->lu.y >= sr->rl.y);
00180                 if (r->lu.x <= sr->rl.x && r->rl.x >= sr->lu.x &&
00181                     r->lu.y >= sr->rl.y && r->rl.y <= sr->lu.y)
00182                         return 1;
00183                 curr=curr->next;
00184         }
00185         return 0;
00186 }
00187 
00188 
00199 static inline int
00200 map_selection_contains_polygon(struct map_selection *sel, struct coord *c, int count)
00201 {
00202         struct coord_rect r;
00203         int i;
00204 
00205         if (! sel)
00206                 return 1;
00207         if (! count)
00208                 return 0;
00209         r.lu=c[0];
00210         r.rl=c[0];
00211         for (i = 1 ; i < count ; i++) {
00212                 if (c[i].x < r.lu.x)
00213                         r.lu.x=c[i].x;
00214                 if (c[i].x > r.rl.x)
00215                         r.rl.x=c[i].x;
00216                 if (c[i].y < r.rl.y)
00217                         r.rl.y=c[i].y;
00218                 if (c[i].y > r.lu.y)
00219                         r.lu.y=c[i].y;
00220         }
00221         return map_selection_contains_rect(sel, &r);
00222 }
00223 
00224 /* prototypes */
00225 enum attr_type;
00226 enum projection;
00227 struct attr;
00228 struct attr_iter;
00229 struct callback;
00230 struct item;
00231 struct map;
00232 struct map_priv;
00233 struct map_rect;
00234 struct map_search;
00235 struct map_selection;
00236 struct pcoord;
00237 struct map *map_new(struct attr *parent, struct attr **attrs);
00238 struct map *map_ref(struct map* m);
00239 void map_unref(struct map* m);
00240 int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
00241 int map_set_attr(struct map *this_, struct attr *attr);
00242 void map_add_callback(struct map *this_, struct callback *cb);
00243 void map_remove_callback(struct map *this_, struct callback *cb);
00244 int map_requires_conversion(struct map *this_);
00245 char *map_convert_string(struct map *this_, char *str);
00246 void map_convert_free(char *str);
00247 enum projection map_projection(struct map *this_);
00248 void map_set_projection(struct map *this_, enum projection pro);
00249 void map_destroy(struct map *m);
00250 struct map_rect *map_rect_new(struct map *m, struct map_selection *sel);
00251 struct item *map_rect_get_item(struct map_rect *mr);
00252 struct item *map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo);
00253 struct item *map_rect_create_item(struct map_rect *mr, enum item_type type_);
00254 void map_rect_destroy(struct map_rect *mr);
00255 struct map_search *map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial);
00256 struct item *map_search_get_item(struct map_search *this_);
00257 void map_search_destroy(struct map_search *this_);
00258 struct map_selection *map_selection_rect_new(struct pcoord *center, int distance, int order);
00259 struct map_selection *map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to);
00260 struct map_selection *map_selection_dup(struct map_selection *sel);
00261 void map_selection_destroy(struct map_selection *sel);
00262 int map_selection_contains_item_rect(struct map_selection *sel, struct item *item);
00263 int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count);
00264 int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type);
00265 int map_priv_is(struct map *map, struct map_priv *priv);
00266 void map_dump_filedesc(struct map *map, FILE *out);
00267 void map_dump_file(struct map *map, const char *file);
00268 void map_dump(struct map *map);
00269 void map_destroy_do(struct map *m);
00270 /* end of prototypes */
00271 
00272 #ifdef __cplusplus
00273 }
00274 #endif
00275 #endif