static int street_name_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) { struct map_rect_priv *mr=priv_data; attr->type=attr_type; switch (attr_type) { case attr_street_name: attr->u.str=mr->street.name.name2; return ((attr->u.str && attr->u.str[0]) ? 1:0); case attr_street_name_systematic: attr->u.str=mr->street.name.name1; return ((attr->u.str && attr->u.str[0]) ? 1:0); case attr_town_name: case attr_district_name: case attr_postal: if (!mr->search_item_tmp) mr->search_item_tmp=map_rect_get_item_byid_mg(mr->search_mr_tmp, mr->street.name_numbers.country | (file_town_twn << 16), mr->street.name_numbers.dist); if (!mr->search_item_tmp) return 0; return item_attr_get(mr->search_item_tmp, attr_type, attr); default: dbg(0,"%p\n",mr->street.name_numbers.dist); dbg(0,"unknown attr %s\n",attr_to_name(attr_type)); return 0; } }
void phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes) { struct map_rect *mr; struct item *item; int count; struct coord ca[phase1_coord_max]; struct attr attr; struct item_bin *item_bin; while (maps) { mr=map_rect_new(maps->data, NULL); while ((item = map_rect_get_item(mr))) { count=item_coord_get(item, ca, item->type < type_line ? 1: phase1_coord_max); item_bin=init_item(item->type); item_bin_add_coord(item_bin, ca, count); while (item_attr_get(item, attr_any, &attr)) { if (attr.type >= attr_type_string_begin && attr.type <= attr_type_string_end) { attr.u.str=map_convert_string(maps->data, attr.u.str); if (attr.u.str) { item_bin_add_attr(item_bin, &attr); map_convert_free(attr.u.str); } } else item_bin_add_attr(item_bin, &attr); } if (item->type >= type_line) item_bin_write(item_bin, out_ways); else item_bin_write(item_bin, out_nodes); } map_rect_destroy(mr); maps=g_list_next(maps); } }
void phase1_map(struct map *map, FILE *out_ways, FILE *out_nodes) { struct map_rect *mr=map_rect_new(map, NULL); struct item *item; int count,max=16384; struct coord ca[max]; struct attr attr; while ((item = map_rect_get_item(mr))) { count=item_coord_get(item, ca, item->type < type_line ? 1: max); item_bin_init(item_bin, item->type); item_bin_add_coord(item_bin, ca, count); while (item_attr_get(item, attr_any, &attr)) { if (attr.type >= attr_type_string_begin && attr.type <= attr_type_string_end) { attr.u.str=map_convert_string(map, attr.u.str); item_bin_add_attr(item_bin, &attr); map_convert_free(attr.u.str); } else item_bin_add_attr(item_bin, &attr); } if (item->type >= type_line) item_bin_write(item_bin, out_ways); else item_bin_write(item_bin, out_nodes); } map_rect_destroy(mr); }
static struct search_list_country * search_list_country_new(struct item *item) { struct search_list_country *ret=g_new0(struct search_list_country, 1); struct attr attr; ret->item=*item; if (item_attr_get(item, attr_country_car, &attr)) ret->car=g_strdup(attr.u.str); if (item_attr_get(item, attr_country_iso2, &attr)) ret->iso2=g_strdup(attr.u.str); if (item_attr_get(item, attr_country_iso3, &attr)) ret->iso3=g_strdup(attr.u.str); if (item_attr_get(item, attr_country_name, &attr)) ret->name=g_strdup(attr.u.str); return ret; }
void item_dump_attr(struct item *item, struct map *map, FILE *out) { struct attr attr; fprintf(out,"type=%s", item_to_name(item->type)); while (item_attr_get(item, attr_any, &attr)) fprintf(out," %s='%s'", attr_to_name(attr.type), attr_to_text(&attr, map, 1)); }
static void popup_show_attr(void *menu, struct item *item, enum attr_type attr_type) { struct attr attr; memset(&attr, 0, sizeof(attr)); attr.type=attr_type; if (item_attr_get(item, attr_type, &attr)) popup_show_attr_val(menu, &attr); }
static void search_list_common_new(struct item *item, struct search_list_common *common) { struct attr attr; if (item_attr_get(item, attr_town_name, &attr)) common->town_name=map_convert_string(item->map, attr.u.str); else common->town_name=NULL; if (item_attr_get(item, attr_county_name, &attr)) common->county_name=map_convert_string(item->map, attr.u.str); else common->county_name=NULL; if (item_attr_get(item, attr_district_name, &attr)) common->district_name=map_convert_string(item->map, attr.u.str); else common->district_name=NULL; if (item_attr_get(item, attr_postal, &attr)) common->postal=map_convert_string(item->map, attr.u.str); else if (item_attr_get(item, attr_town_postal, &attr)) common->postal=map_convert_string(item->map, attr.u.str); else common->postal=NULL; if (item_attr_get(item, attr_postal_mask, &attr)) common->postal_mask=map_convert_string(item->map, attr.u.str); else common->postal_mask=NULL; }
static struct search_list_town * search_list_town_new(struct item *item) { struct search_list_town *ret=g_new0(struct search_list_town, 1); struct attr attr; struct coord c; ret->itemt=*item; if (item_attr_get(item, attr_town_streets_item, &attr)) { dbg(1,"town_assoc 0x%x 0x%x\n", attr.u.item->id_hi, attr.u.item->id_lo); ret->item=*attr.u.item; } else ret->item=*item; if (item_attr_get(item, attr_town_name, &attr)) ret->name=map_convert_string(item->map,attr.u.str); if (item_attr_get(item, attr_town_postal, &attr)) ret->postal=map_convert_string(item->map,attr.u.str); if (item_coord_get(item, &c, 1)) { ret->c=g_new(struct coord, 1); *(ret->c)=c; }
static struct search_list_town * search_list_town_new(struct item *item) { struct search_list_town *ret=g_new0(struct search_list_town, 1); struct attr attr; struct coord c; ret->itemt=*item; ret->common.item=ret->common.unique=*item; if (item_attr_get(item, attr_town_streets_item, &attr)) { dbg(1,"town_assoc 0x%x 0x%x\n", attr.u.item->id_hi, attr.u.item->id_lo); ret->common.unique=*attr.u.item; } search_list_common_new(item, &ret->common); if (item_attr_get(item, attr_county_name, &attr)) ret->county=map_convert_string(item->map,attr.u.str); else ret->county=NULL; if (item_coord_get(item, &c, 1)) { ret->common.c=g_new(struct pcoord, 1); ret->common.c->x=c.x; ret->common.c->y=c.y; ret->common.c->pro = map_projection(item->map); }
static struct search_list_country * search_list_country_new(struct item *item) { struct search_list_country *ret=g_new0(struct search_list_country, 1); struct attr attr; ret->common.item=ret->common.unique=*item; if (item_attr_get(item, attr_country_car, &attr)) ret->car=g_strdup(attr.u.str); if (item_attr_get(item, attr_country_iso2, &attr)) { #if HAVE_API_ANDROID ret->iso2=g_malloc(strlen(attr.u.str)+1); strtolower(ret->iso2, attr.u.str); #else ret->iso2=g_strdup(attr.u.str); #endif ret->flag=g_strdup_printf("country_%s", ret->iso2); } if (item_attr_get(item, attr_country_iso3, &attr)) ret->iso3=g_strdup(attr.u.str); if (item_attr_get(item, attr_country_name, &attr)) ret->name=g_strdup(attr.u.str); return ret; }
int tracking_get_current_attr(struct tracking *_this, enum attr_type type, struct attr *attr) { struct item *item; struct map_rect *mr; int result=0; if (! _this->curr_line || ! _this->curr_line->street) return 0; item=&_this->curr_line->street->item; mr=map_rect_new(item->map,NULL); item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); if (item_attr_get(item, type, attr)) result=1; map_rect_destroy(mr); return result; }
static void popup_show_attrs(struct map *map, void *menu, struct item *item) { #if 0 popup_show_attr(menu, item, attr_debug); popup_show_attr(menu, item, attr_address); popup_show_attr(menu, item, attr_phone); popup_show_attr(menu, item, attr_phone); popup_show_attr(menu, item, attr_entry_fee); popup_show_attr(menu, item, attr_open_hours); #else struct attr attr; for (;;) { memset(&attr, 0, sizeof(attr)); if (item_attr_get(item, attr_any, &attr)) popup_show_attr_val(map, menu, &attr); else break; } #endif }
int destination_address(struct navit *nav) { GtkWidget *window2, *keyboard, *vbox, *table; GtkWidget *label_country; GtkWidget *label_postal, *label_city, *label_district; GtkWidget *label_street, *label_number; GtkWidget *hseparator1,*hseparator2; GtkWidget *button1,*button2,*button3; int i; struct search_param *search=&search_param; struct attr search_attr, country_name, *country_attr; struct tracking *tracking; struct country_search *cs; struct item *item; GtkTreeSelection* selection; search->nav=nav; search->ms=navit_get_mapset(nav); search->sl=search_list_new(search->ms); window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window2),_("Enter Destination")); vbox = gtk_vbox_new(FALSE, 0); table = gtk_table_new(3, 8, FALSE); search->entry_country = gtk_entry_new(); label_country = gtk_label_new(_("Country")); search->entry_postal = gtk_entry_new(); label_postal = gtk_label_new(_("Zip Code")); search->entry_city = gtk_entry_new(); label_city = gtk_label_new(_("City")); search->entry_district = gtk_entry_new(); label_district = gtk_label_new(_("District/Township")); hseparator1 = gtk_vseparator_new(); search->entry_street = gtk_entry_new(); label_street = gtk_label_new(_("Street")); search->entry_number = gtk_entry_new(); label_number = gtk_label_new(_("Number")); search->listbox = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (search->listbox), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); // gtk_tree_view_set_model (GTK_TREE_VIEW (search->treeview), NULL); { GType types[COL_COUNT+2]; for(i=0;i<COL_COUNT;i++) types[i]=G_TYPE_STRING; types[i++]=G_TYPE_POINTER; types[i++]=G_TYPE_POINTER; search->liststore=gtk_list_store_newv(COL_COUNT+2,types); search->liststore2=gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(search->liststore)); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 0, GTK_SORT_ASCENDING); // gtk_tree_view_set_model (GTK_TREE_VIEW (search->treeview), GTK_TREE_MODEL(search->liststore2)); search->treeview = gtk_tree_view_new_with_model(search->liststore2); gtk_tree_view_set_search_column(GTK_TREE_VIEW (search->treeview),3); } gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(search->listbox),search->treeview); #if 1 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW (search->treeview)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); g_signal_connect(selection, "changed", G_CALLBACK(select_row), search); // g_signal_connect(search->liststore, "row-activated", G_CALLBACK(select_row), search); // g_signal_connect(search->liststore2, "row-activated", G_CALLBACK(select_row), search); // g_signal_connect(search->treeview, "select-cursor-row", G_CALLBACK(select_row), search); #endif hseparator2 = gtk_vseparator_new(); button1 = gtk_button_new_with_label(_("Map")); button2 = gtk_button_new_with_label(_("Bookmark")); button3 = gtk_button_new_with_label(_("Destination")); gtk_table_attach(GTK_TABLE(table), label_country, 0, 1, 0, 1, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), label_postal, 1, 2, 0, 1, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), label_city, 2, 3, 0, 1, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), search->entry_country, 0, 1, 1, 2, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), search->entry_postal, 1, 2, 1, 2, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), search->entry_city, 2, 3, 1, 2, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), label_district, 0, 1, 2, 3, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), label_street, 1, 2, 2, 3, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), label_number, 2, 3, 2, 3, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), search->entry_district, 0, 1, 3, 4, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), search->entry_street, 1, 2, 3, 4, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), search->entry_number, 2, 3, 3, 4, 0, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), search->listbox, 0, 3, 4, 5, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0); gtk_table_attach(GTK_TABLE(table), button1, 0, 1, 5, 6, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button2, 1, 2, 5, 6, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button3, 2, 3, 5, 6, GTK_FILL, GTK_FILL, 0, 0); g_signal_connect(G_OBJECT(search->entry_country), "changed", G_CALLBACK(changed), search); g_signal_connect(G_OBJECT(search->entry_postal), "changed", G_CALLBACK(changed), search); g_signal_connect(G_OBJECT(search->entry_city), "changed", G_CALLBACK(changed), search); g_signal_connect(G_OBJECT(search->entry_district), "changed", G_CALLBACK(changed), search); g_signal_connect(G_OBJECT(search->entry_street), "changed", G_CALLBACK(changed), search); g_signal_connect(G_OBJECT(search->entry_number), "changed", G_CALLBACK(changed), search); g_signal_connect(G_OBJECT(button1), "clicked", G_CALLBACK(button_map), search); g_signal_connect(G_OBJECT(button2), "clicked", G_CALLBACK(button_bookmark), search); g_signal_connect(G_OBJECT(button3), "clicked", G_CALLBACK(button_destination), search); gtk_widget_grab_focus(search->entry_city); gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0); keyboard=gtk_socket_new(); gtk_box_pack_end(GTK_BOX(vbox), keyboard, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(window2), vbox); gtk_widget_show_all(window2); // gtk_socket_steal(GTK_SOCKET(keyboard), spawn_xkbd("xkbd","-geometry 200x100")); country_attr=country_default(); tracking=navit_get_tracking(nav); if (tracking && tracking_get_current_attr(tracking, attr_country_id, &search_attr)) country_attr=&search_attr; cs=country_search_new(country_attr, 0); item=country_search_get_item(cs); if (item && item_attr_get(item, attr_country_name, &country_name)) gtk_entry_set_text(GTK_ENTRY(search->entry_country), country_name.u.str); country_search_destroy(cs); return 0; }
static void navit_window_items_open(struct menu *men, struct navit *this_, struct navit_window_items *nwi) { struct map_selection sel; struct coord c,*center; struct mapset_handle *h; struct map *m; struct map_rect *mr; struct item *item; struct attr attr; int idist,dist; struct param_list param[5]; char distbuf[32]; char dirbuf[32]; char coordbuf[64]; dbg(0, "distance=%d\n", nwi->distance); if (nwi->distance == -1) dist=40000000; else dist=nwi->distance*1000; param[0].name="Distance"; param[1].name="Direction"; param[2].name="Type"; param[3].name="Name"; param[4].name=NULL; sel.next=NULL; #if 0 sel.order[layer_town]=18; sel.order[layer_street]=18; sel.order[layer_poly]=18; #else sel.order[layer_town]=0; sel.order[layer_street]=0; sel.order[layer_poly]=0; #endif center=transform_center(this_->trans); sel.rect.lu.x=center->x-dist; sel.rect.lu.y=center->y+dist; sel.rect.rl.x=center->x+dist; sel.rect.rl.y=center->y-dist; dbg(2,"0x%x,0x%x - 0x%x,0x%x\n", sel.rect.lu.x, sel.rect.lu.y, sel.rect.rl.x, sel.rect.rl.y); nwi->click=callback_new_2(navit_window_items_click, this_, nwi); nwi->win=gui_datawindow_new(this_->gui, nwi->name, nwi->click, NULL); h=mapset_open(navit_get_mapset(this_)); while ((m=mapset_next(h, 1))) { dbg(2,"m=%p %s\n", m, map_get_filename(m)); mr=map_rect_new(m, &sel); dbg(2,"mr=%p\n", mr); while ((item=map_rect_get_item(mr))) { if (item_coord_get(item, &c, 1)) { if (coord_rect_contains(&sel.rect, &c) && g_hash_table_lookup(nwi->hash, &item->type)) { if (! item_attr_get(item, attr_label, &attr)) attr.u.str=""; idist=transform_distance(center, &c); if (idist < dist) { get_direction(dirbuf, transform_get_angle_delta(center, &c, 0), 1); param[0].value=distbuf; param[1].value=dirbuf; param[2].value=item_to_name(item->type); sprintf(distbuf,"%d", idist/1000); param[3].value=attr.u.str; sprintf(coordbuf, "0x%x,0x%x", c.x, c.y); param[4].value=coordbuf; datawindow_add(nwi->win, param, 5); } /* printf("gefunden %s %s %d\n",item_to_name(item->type), attr.u.str, idist/1000); */ } if (item->type >= type_line) while (item_coord_get(item, &c, 1)); } } map_rect_destroy(mr); } mapset_close(h); }
static void bookmarks_load_hash(struct bookmarks *this_) { struct bookmark_item_priv *b_item; struct item *item; struct attr attr; struct coord c; char *pos,*finder; char *copy_helper; if (this_->mr) { map_rect_destroy(this_->mr); } this_->mr=map_rect_new(this_->bookmark, NULL); this_->bookmarks_hash=g_hash_table_new(g_str_hash, g_str_equal); this_->root=g_new0(struct bookmark_item_priv,1); this_->root->type=type_none; this_->root->parent=NULL; this_->root->children=NULL; bookmarks_move_root(this_); while ((item=map_rect_get_item(this_->mr))) { if (item->type != type_bookmark && item->type != type_bookmark_folder ) continue; if (!item_attr_get(item, attr_path, &attr)) { item_attr_get(item, attr_label, &attr); } item_coord_get(item, &c, 1); b_item=g_new0(struct bookmark_item_priv,1); b_item->c.x=c.x; b_item->c.y=c.y; b_item->label=g_strdup(attr.u.str); b_item->type=item->type; b_item->item=*item; //Prepare position bookmarks_move_root(this_); finder=b_item->label; while ((pos=strchr(finder,'/'))) { *pos=0x00; dbg(1,"Found path entry: %s\n",finder); if (!bookmarks_move_down(this_,finder)) { struct bookmark_item_priv *path_item=g_new0(struct bookmark_item_priv,1); path_item->type=type_bookmark_folder; path_item->parent=this_->current; path_item->children=NULL; path_item->label=g_strdup(finder); this_->current->children=g_list_append(this_->current->children,path_item); this_->current=path_item; g_hash_table_insert(this_->bookmarks_hash,b_item->label,path_item); this_->bookmarks_list=g_list_append(this_->bookmarks_list,path_item); } finder+=strlen(finder)+1; } copy_helper=g_strdup(finder); free(b_item->label); b_item->label=copy_helper; b_item->parent=this_->current; g_hash_table_insert(this_->bookmarks_hash,b_item->label,b_item); this_->bookmarks_list=g_list_append(this_->bookmarks_list,b_item); this_->current->children=g_list_append(this_->current->children,b_item); this_->current->children=g_list_first(this_->current->children); dbg(1,"Added %s to %s and current list now %u long\n",b_item->label,this_->current->label,g_list_length(this_->current->children)); } bookmarks_move_root(this_); }