void headingUpdate(char * heading,struct navigation * nav) { struct map * map=NULL; map_rect * mr=NULL; map = navigation_get_map(nav); if(map) mr = map_rect_new(map,NULL); struct map_rect_priv *nice= mr->priv; if(&mr != NULL && mr->priv->itm_next != NULL) { navigation_itm * current_item = mr->priv->itm_next; getToNextNode(mr); char * nodeName = current_item->way.name1; if(nodeName == NULL) { nodeName = current_item->way.name2; } //printf("\tNext Road Angle: %d\n",current_item->angle_end); char * turn_dir; int prev_angle = 0; if(current_item->prev != NULL) { prev_angle = current_item->prev->way.angle2; } int turn_num; int choice=nav->cmd_first->delta; if( choice > 0) { turn_dir = "Right"; turn_num = 100; } else { turn_dir = "Left"; turn_num = -100; } //printf("\tNext Turn Direction: %s\n",turn_dir); int length = current_item->dest_length-mr->priv->cmd_next->itm->dest_length; //printf("\tDistance to Next Road: %d Meters\n",length); printf("\tCurrent Speed Limit: %d MPH\n",current_item->speed); sprintf(heading,"Next Node %s Distance: %d Turn %s\n",nodeName,length,turn_dir); //updateRouteData(int velocity, int road_angle, int distance, int turn_angle, int x1, int y1, int x2, int y2) int a = updateRouteData(nav->navit->vehicle->speed, 0, length, turn_num,0, 0, 0, 0); if(jons_data == NULL) { jons_data = fopen("jons_data","w+"); } if(jons_data == NULL) { printf("Unable to Write Jon's Data\n"); } else { fprintf(jons_data,"%d,%d,%d,%d",nav->navit->vehicle->speed, 0, length, turn_num); } printf(" Number %d", current_item->angle_end); processImageData(); } }
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 popup_show_item(void *popup, struct displayitem *di) { struct map_rect *mr; void *menu, *menu_map, *menu_item; char *label; struct item *item; label=graphics_displayitem_get_label(di); item=graphics_displayitem_get_item(di); if (label) menu=popup_printf(popup, menu_type_submenu, "%s '%s'", item_to_name(item->type), label); else menu=popup_printf(popup, menu_type_submenu, "%s", item_to_name(item->type)); menu_item=popup_printf(menu, menu_type_submenu, "Item"); popup_printf(menu_item, menu_type_menu, "type: 0x%x", item->type); popup_printf(menu_item, menu_type_menu, "id: 0x%x 0x%x", item->id_hi, item->id_lo); if (item->map) { mr=map_rect_new(item->map,NULL); item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); dbg(1,"item=%p\n", item); if (item) { popup_show_attrs(item->map, menu_item, item); } map_rect_destroy(mr); menu_map=popup_printf(menu, menu_type_submenu, "Map"); } else { popup_printf(menu, menu_type_menu, "(No map)"); } }
static void popup_traffic_distortion(struct item *item, char *attr) { /* add the configuration directory to the name of the file to use */ char *dist_filename = g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/distortion.txt", NULL); if (dist_filename) /* if we built the filename */ { FILE *map=fopen(dist_filename,"a"); if (map) /* if the file was opened */ { struct coord c; struct map_rect *mr; fprintf(map,"type=traffic_distortion %s\n",attr); mr=map_rect_new(item->map,NULL); item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); while (item_coord_get(item, &c, 1)) { fprintf(map,"0x%x 0x%x\n",c.x,c.y); } fclose(map); } else { dbg(0,"could not open file for distortions !!", item); } /* else - if (map) */ g_free(dist_filename); /* free the file name */ } /* if (dist_filename) */ } /* end: popup_traffic_distortion(..) */
static void popup_item_dump(struct item *item) { struct map_rect *mr; mr=map_rect_new(item->map,NULL); item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); dbg(0,"item=%p\n",item); item_dump_filedesc(item,item->map,stdout); map_rect_destroy(mr); }
static void popup_show_item(struct navit *nav, void *popup, struct displayitem *di) { struct map_rect *mr; void *menu, *menu_map, *menu_item, *menu_dist; char *label; struct item *item,*diitem; int count; label=graphics_displayitem_get_label(di); diitem=graphics_displayitem_get_item(di); count=graphics_displayitem_get_coord_count(di); dbg_assert(diitem); if (label) menu=popup_printf(popup, menu_type_submenu, "%s '%s' (%d coords)", item_to_name(diitem->type), label, count); else menu=popup_printf(popup, menu_type_submenu, "%s (%d coords)", item_to_name(diitem->type), count); menu_item=popup_printf(menu, menu_type_submenu, "Item"); popup_printf(menu_item, menu_type_menu, "type: 0x%x", diitem->type); popup_printf(menu_item, menu_type_menu, "id: 0x%x 0x%x", diitem->id_hi, diitem->id_lo); if (diitem->map) { struct attr type,data; if (!map_get_attr(diitem->map, attr_type, &type, NULL)) type.u.str=""; if (!map_get_attr(diitem->map, attr_data, &data, NULL)) data.u.str=""; popup_printf(menu_item, menu_type_menu, "map: %s:%s", type.u.str, data.u.str); } if (diitem->map) { mr=map_rect_new(diitem->map,NULL); item=map_rect_get_item_byid(mr, diitem->id_hi, diitem->id_lo); dbg(1,"item=%p\n", item); if (item) { popup_show_attrs(item->map, menu_item, item); popup_printf_cb(menu_item, menu_type_menu, callback_new_1(callback_cast(popup_item_dump), diitem), "Dump"); if (item->type < type_line) { struct coord co; struct pcoord *c; if (item_coord_get(item, &co, 1)) { c=g_new(struct pcoord, 1); c->pro = transform_get_projection(navit_get_trans(nav)); c->x = co.x; c->y = co.y; popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_position), nav, c), _("Set as position")); popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_destination), nav, c), _("Set as destination")); popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_bookmark), nav, c), _("Add as bookmark")); } } }
static void popup_traffic_distortion(struct item *item, char *attr) { FILE *map=fopen("distortion.txt","a"); struct coord c; struct map_rect *mr; fprintf(map,"type=traffic_distortion %s\n",attr); mr=map_rect_new(item->map,NULL); item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); while (item_coord_get(item, &c, 1)) { fprintf(map,"0x%x 0x%x\n",c.x,c.y); } fclose(map); }
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 }
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_item(struct navit *nav, void *popup, struct displayitem *di) { struct map_rect *mr; void *menu, *menu_map, *menu_item; char *label; struct item *item; label=graphics_displayitem_get_label(di); item=graphics_displayitem_get_item(di); if (label) menu=popup_printf(popup, menu_type_submenu, "%s '%s'", item_to_name(item->type), label); else menu=popup_printf(popup, menu_type_submenu, "%s", item_to_name(item->type)); menu_item=popup_printf(menu, menu_type_submenu, "Item"); popup_printf(menu_item, menu_type_menu, "type: 0x%x", item->type); popup_printf(menu_item, menu_type_menu, "id: 0x%x 0x%x", item->id_hi, item->id_lo); if (item->map) { mr=map_rect_new(item->map,NULL); item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); dbg(1,"item=%p\n", item); if (item) { popup_show_attrs(item->map, menu_item, item); if (item->type < type_line) { struct coord co; struct pcoord *c; if (item_coord_get(item, &co, 1)) { c=g_new(struct pcoord, 1); c->pro = transform_get_projection(navit_get_trans(nav)); c->x = co.x; c->y = co.y; popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_position), nav, c), _("Set as position")); popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_destination), nav, c), _("Set as destination")); popup_printf_cb(menu_item, menu_type_menu, callback_new_2(callback_cast(popup_set_bookmark), nav, c), _("Add as bookmark")); } } }
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_); }