Navit SVN

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

00001 
00020 #include <glib.h>
00021 #include "item.h"
00022 #include "attr.h"
00023 #include "coord.h"
00024 #include "data.h"
00025 #include "projection.h"
00026 #include "map.h"
00027 #include "file.h"
00028 
00029 struct block_data {
00030         struct file *file;
00031 };
00032 
00033 struct block {
00034 /*      int blocks;
00035         int size;
00036         int next;
00037         struct coord_rect r;
00038         int count;*/
00039         unsigned char p[32];
00040 };
00041 static inline int block_get_blocks(struct block * blk) { unsigned char *p = blk->p; return get_u32(&p); }
00042 static inline int block_get_size(struct block * blk) { unsigned char *p = blk->p+4; return get_u32(&p); }
00043 static inline int block_get_next(struct block * blk) { unsigned char *p = blk->p+8; return get_u32(&p); }
00044 static inline int block_get_count(struct block * blk) { unsigned char *p = blk->p+28; return get_u32(&p); }
00045 static inline void block_get_r(struct block * blk, struct coord_rect * r) { unsigned char *p = blk->p+12; r ->lu.x = get_u32(&p); r ->lu.y = get_u32(&p); r ->rl.x = get_u32(&p); r ->rl.y = get_u32(&p); }
00046 
00047 struct item_priv {
00048         int cidx;
00049         int aidx;
00050         unsigned char *cstart,*cp,*cend;
00051         unsigned char *astart,*ap,*aend;
00052         enum attr_type attr_last;
00053         enum attr_type attr_next;
00054         struct item item;
00055 };
00056 
00057 struct town_priv {
00058         unsigned int id; 
00059         struct coord c; 
00060         char *name; 
00061         char *district; 
00062         char *postal_code1; 
00063         unsigned char order; 
00064         unsigned char type; 
00065         unsigned short country; 
00066         unsigned int unknown2; 
00067         unsigned char size; 
00068         unsigned int street_assoc; 
00069         unsigned char unknown3; 
00070         char *postal_code2; 
00071         unsigned int unknown4; 
00073         int cidx;
00074         int aidx;
00075         enum attr_type attr_next;
00076         char debug[256];
00077         char postal[32];
00078         struct item town_attr_item;
00079 };
00080 
00081 struct poly_priv {
00082         int poly_num;
00083         unsigned char *poly_next;
00084         int subpoly_num;
00085         int subpoly_num_all;
00086         unsigned char *subpoly_next;
00087         unsigned char *subpoly_start;
00088         unsigned char *p;
00089         struct coord c[2];
00090         char *name;
00091         unsigned char order;
00092         unsigned char type;
00093         unsigned int polys;
00094         unsigned int *count;
00095         unsigned int count_sum;
00096 
00097         int aidx;
00098         enum attr_type attr_next;
00099 };
00100 
00101 struct street_header {
00102         /*unsigned char order;
00103         int count;*/
00104         unsigned char p[5];
00105 } __attribute__((packed));
00106 static inline unsigned char street_header_get_order(struct street_header * str) { return *str->p; }
00107 static inline int street_header_get_count(struct street_header * str) { unsigned char *p = str->p+1; return get_u32_unal(&p); }
00108 
00109 struct street_type {
00110         /*unsigned char order;
00111         unsigned short country;*/
00112         unsigned char p[3];
00113 } __attribute__((packed));
00114 static inline unsigned char street_type_get_order(struct street_type * str) { return *str->p; }
00115 static inline unsigned short street_type_get_country(struct street_type * str) { unsigned char *p = str->p+1; return get_u16_unal(&p); }
00116 
00117 struct street_header_type {
00118         struct street_header *header;
00119         int type_count;
00120         struct street_type *type;
00121 };
00122 
00123 struct street_str {
00124         /*int segid;
00125         unsigned char limit;*/            /* 0x03,0x30=One Way,0x33=No Passing */
00126         /*unsigned char unknown2;
00127         unsigned char unknown3;
00128         unsigned char type;
00129         unsigned int nameid;*/
00130         unsigned char p[12];
00131 };
00132 static inline int street_str_get_segid(struct street_str * str) { unsigned char *p = str->p; return get_u32_unal(&p); }
00133 static inline unsigned char street_str_get_limit(struct street_str * str) { return str->p[4]; }
00134 static inline unsigned char street_str_get_unknown2(struct street_str * str) { return str->p[5]; }
00135 static inline unsigned char street_str_get_unknown3(struct street_str * str) { return str->p[6]; }
00136 static inline unsigned char street_str_get_type(struct street_str * str) { return str->p[7]; }
00137 static inline unsigned int street_str_get_nameid(struct street_str * str) { unsigned char *p = str->p+8; return get_u32_unal(&p); }
00138 
00139 struct street_name_segment {
00140         int segid;
00141         int country;
00142 };
00143 
00144 struct street_name {
00145         int len;
00146         int country;
00147         int townassoc;
00148         char *name1;
00149         char *name2;
00150         int segment_count;
00151         struct street_name_segment *segments;
00152         int aux_len;
00153         unsigned char *aux_data;
00154         int tmp_len;
00155         unsigned char *tmp_data;
00156 };
00157 
00158 struct housenumber {
00159         int number;
00160         char *suffix;
00161 };
00162 
00163 struct street_name_numbers {
00164         int len;
00165         int tag;
00166         int dist;
00167         int country;
00168         struct coord *c;
00169         struct housenumber first;
00170         struct housenumber last;
00171         int segment_count;
00172         struct street_name_segment *segments;
00173         int aux_len;
00174         unsigned char *aux_data;
00175         int tmp_len;
00176         unsigned char *tmp_data;
00177 };
00178 static inline void street_name_numbers_get_coord(struct street_name_numbers * str, struct coord * c) {
00179         unsigned char *p=(unsigned char *)str->c;
00180         c->x=get_u32_unal(&p);
00181         c->y=get_u32_unal(&p);
00182 }
00183 
00184 struct street_name_number {
00185         int len;
00186         int tag;
00187         struct coord *c;
00188         struct housenumber first;
00189         struct housenumber last;
00190         struct street_name_segment *segment;
00191 };
00192 
00193 
00194 
00195 struct street_priv {
00196         struct file *name_file;
00197         struct street_header *header;
00198         int type_count;
00199         struct street_type *type;
00200         struct street_str *str;
00201         struct street_str *str_start;
00202         unsigned char *coord_begin;
00203         unsigned char *p;
00204         unsigned char *p_rewind;
00205         unsigned char *end;
00206         unsigned char *next;
00207         int status;
00208         int status_rewind;
00209         struct coord_rect ref;
00210         int bytes;
00211         int more;
00212         int flags;
00213         int housenumber;
00214         int cidx;
00215         struct coord hnc[100];
00216         struct housenumber hn[100];
00217         int hn_count;
00218         struct street_name name;
00219         struct street_name_numbers name_numbers;
00220         struct street_name_number name_number;
00221         enum attr_type attr_next;
00222         char debug[256];
00223         char first_number[32];
00224         char last_number[32];
00225         char current_number[32];
00226         GHashTable *streetname_hash;
00227 };
00228 
00229 enum file_index {
00230         file_border_ply=0,
00231         file_bridge_ply,
00232         file_build_ply,
00233         file_golf_ply,
00234         file_height_ply,
00235         file_natpark_ply,
00236         file_nature_ply,
00237         file_other_ply,
00238         file_rail_ply,
00239         file_sea_ply,
00240         file_street_bti,
00241         file_street_str,
00242         file_strname_stn,
00243         file_town_twn,
00244         file_tunnel_ply,
00245         file_water_ply,
00246         file_woodland_ply,
00247         file_end,
00248         file_town_twn_alt1,
00249         file_town_twn_alt2,
00250         file_street_str_alt1,
00251         file_street_str_alt2,
00252         file_street_str_alt3,
00253         file_street_str_alt4,
00254 };
00255 
00256 struct map_priv {
00257         int id;
00258         struct file *file[file_end];
00259         char *dirname;
00260 };
00261 
00262 #define BT_STACK_SIZE 32
00263 
00264 struct block_bt_priv {
00265         struct block *b;
00266         struct coord_rect r, r_curr;
00267         int next;
00268         int block_count;
00269         struct coord_rect stack[BT_STACK_SIZE];
00270         int stackp;
00271         int order;
00272         unsigned char *p;
00273         unsigned char *end;
00274 };
00275 
00276 struct block_priv {
00277         int block_num;
00278         struct coord_rect b_rect;
00279         unsigned char *block_start;
00280         struct block *b;
00281         unsigned char *p;
00282         unsigned char *end;
00283         unsigned char *p_start;
00284         int binarytree;
00285         struct block_bt_priv bt;
00286 };
00287 
00288 struct block_offset {
00289 /*      unsigned short offset;
00290         unsigned short block;*/
00291         unsigned char p[4];
00292 };
00293 static inline unsigned short block_offset_get_offset(struct block_offset * blk) { unsigned char *p = blk->p; return get_u16_unal(&p); }
00294 static inline unsigned short block_offset_get_block(struct block_offset * blk) { unsigned char *p = blk->p+2; return get_u16_unal(&p); }
00295 
00296 struct tree_search_node {
00297         struct tree_hdr *hdr;
00298         unsigned char *p;
00299         unsigned char *last;
00300         unsigned char *end;
00301         int low;
00302         int high;
00303         int last_low;
00304         int last_high;
00305         };
00306 
00307 struct tree_search {
00308         struct file *f;
00309         int last_node;
00310         int curr_node;
00311         struct tree_search_node nodes[5];
00312 };
00313 
00314 
00315 struct map_rect_priv {
00316         struct map_selection *xsel;
00317         struct map_selection *cur_sel;
00318 
00319         struct map_priv *m;
00320         enum file_index current_file;
00321         struct file *file;
00322         struct block_priv b;
00323         struct item item;
00324         struct town_priv town;
00325         struct poly_priv poly;
00326         struct street_priv street;
00327         struct tree_search ts;
00328         int search_country;
00329         struct item search_item;
00330         struct attr *search_attr;
00331         char *search_str;
00332         int search_partial;
00333         int search_linear;
00334         unsigned char *search_p;
00335         int search_blk_count;
00336         enum attr_type search_type,search_type_next;
00337         struct map_rect_priv *search_mr_tmp;
00338         struct item *search_item_tmp;
00339         struct block_offset *search_blk_off;
00340         int search_block;
00341         GHashTable *block_hash[file_end];
00342         struct item_priv item3;
00343 };
00344 
00345 int mg_country_from_isonum(int isonum);
00346 int mg_country_to_isonum(int country);
00347 int mg_country_postal_len(int country);
00348 
00349 int block_init(struct map_rect_priv *mr);
00350 int block_next(struct map_rect_priv *mr);
00351 int block_get_byindex(struct file *file, int idx, struct block_priv *blk);
00352 int block_next_lin(struct map_rect_priv *mr);
00353 
00354 int tree_search_hv(char *dirname, char *filename, unsigned int search1, unsigned int search2, int *result);
00355 int town_get(struct map_rect_priv *mr, struct town_priv *poly, struct item *item);
00356 int town_get_byid(struct map_rect_priv *mr, struct town_priv *twn, int id_hi, int id_lo, struct item *item);
00357 struct item * town_search_get_item(struct map_rect_priv *mr);
00358 int poly_get(struct map_rect_priv *mr, struct poly_priv *poly, struct item *item);
00359 int poly_get_byid(struct map_rect_priv *mr, struct poly_priv *poly, int id_hi, int id_lo, struct item *item);
00360 int street_get(struct map_rect_priv *mr, struct street_priv *street, struct item *item);
00361 int street_get_byid(struct map_rect_priv *mr, struct street_priv *street, int id_hi, int id_lo, struct item *item);
00362 int street_name_get_byid(struct map_rect_priv *mr, struct street_priv *street, int id_hi, int id_lo, struct item *item);
00363 struct item * street_search_get_item(struct map_rect_priv *mr);
00364 void tree_search_init(char *dirname, char *filename, struct tree_search *ts, int offset);
00365 void tree_search_free(struct tree_search *ts);
00366 int tree_search_next(struct tree_search *ts, unsigned char **p, int dir);
00367 int tree_search_next_lin(struct tree_search *ts, unsigned char **p);
00368 struct item * housenumber_search_get_item(struct map_rect_priv *mr);
00369 struct map_rect_priv * map_rect_new_mg(struct map_priv *map, struct map_selection *sel);
00370 void map_rect_destroy_mg(struct map_rect_priv *mr);
00371 struct item *map_rect_get_item_byid_mg(struct map_rect_priv *mr, int id_hi, int id_lo);
00372 int housenumber_search_setup(struct map_rect_priv *mr);