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 void tracking_doupdate_lines(struct tracking *tr, struct coord *cc) { int max_dist=1000; struct map_selection *sel=route_rect(18, cc, cc, 0, max_dist); struct mapset_handle *h; struct map *m; struct map_rect *mr; struct item *item; struct street_data *street; struct tracking_line *tl; struct coord c; dbg(1,"enter\n"); h=mapset_open(tr->ms); while ((m=mapset_next(h,1))) { mr=map_rect_new(m, sel); if (! mr) continue; while ((item=map_rect_get_item(mr))) { if (item->type >= type_street_0 && item->type <= type_ferry) { street=street_get_data(item); tl=g_malloc(sizeof(struct tracking_line)+(street->count-1)*sizeof(int)); tl->street=street; tracking_get_angles(tl); tl->next=tr->lines; tr->lines=tl; } } map_rect_destroy(mr); } mapset_close(h); map_selection_destroy(sel); dbg(1, "exit\n"); #if 0 struct transformation t; tr->last_ptr=&tr->lines; transform_setup_source_rect_limit(&t,c,1000); transform_setup_source_rect_limit(&tr->t,c,1000); profile_timer(NULL); street_get_block(tr->ma,&t,tst_callback,tr); profile_timer("end"); #endif }
static void vehicle_demo_timer(struct vehicle_priv *priv) { struct coord c, c2, pos, ci; int slen, len, dx, dy; struct route *route=NULL; struct map *route_map=NULL; struct map_rect *mr=NULL; struct item *item=NULL; len = (priv->config_speed * priv->interval / 1000)/ 3.6; dbg(1, "###### Entering simulation loop\n"); if (!priv->config_speed) return; if (priv->route) route=priv->route; else if (priv->navit) route=navit_get_route(priv->navit); if (route) route_map=route_get_map(route); if (route_map) mr=map_rect_new(route_map, NULL); if (mr) item=map_rect_get_item(mr); if (item && item->type == type_route_start) item=map_rect_get_item(mr); while(item && item->type!=type_street_route) item=map_rect_get_item(mr); if (item && item_coord_get(item, &pos, 1)) { priv->position_set=0; dbg(1, "current pos=0x%x,0x%x\n", pos.x, pos.y); dbg(1, "last pos=0x%x,0x%x\n", priv->last.x, priv->last.y); if (priv->last.x == pos.x && priv->last.y == pos.y) { dbg(1, "endless loop\n"); } priv->last = pos; while (item && priv->config_speed) { if (!item_coord_get(item, &c, 1)) { item=map_rect_get_item(mr); continue; } dbg(1, "next pos=0x%x,0x%x\n", c.x, c.y); slen = transform_distance(projection_mg, &pos, &c); dbg(1, "len=%d slen=%d\n", len, slen); if (slen < len) { len -= slen; pos = c; } else { if (item_coord_get(item, &c2, 1) || map_rect_get_item(mr)) { dx = c.x - pos.x; dy = c.y - pos.y; ci.x = pos.x + dx * len / slen; ci.y = pos.y + dy * len / slen; priv->direction = transform_get_angle_delta(&pos, &c, 0); priv->speed=priv->config_speed; } else { ci.x = pos.x; ci.y = pos.y; priv->speed=0; dbg(0,"destination reached\n"); } dbg(1, "ci=0x%x,0x%x\n", ci.x, ci.y); transform_to_geo(projection_mg, &ci, &priv->geo); callback_list_call_attr_0(priv->cbl, attr_position_coord_geo); break; } } } else { if (priv->position_set) callback_list_call_attr_0(priv->cbl, attr_position_coord_geo); } if (mr) map_rect_destroy(mr); }
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_); }