示例#1
0
文件: misc.c 项目: Jalakas/navit
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);
	}
}
示例#2
0
文件: misc.c 项目: justinzane/navit
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);
}
示例#3
0
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(..) */
示例#4
0
int
item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection to)
{
	int ret=item_coord_get(it, c, count);
	int i;
	enum projection from=map_projection(it->map);
	if (from != to) 
		for (i = 0 ; i < count ; i++) 
			transform_from_to(c+i, from, c+i, to);
	return ret;
}
示例#5
0
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"));
				}
			}
		}
示例#6
0
文件: popup.c 项目: justinzane/navit
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);
}
示例#7
0
void
item_dump_filedesc(struct item *item, struct map *map, FILE *out)
{

	int i,count,max=16384;
	struct coord *ca=g_alloca(sizeof(struct coord)*max);

	count=item_coord_get(item, ca, item->type < type_line ? 1: max);
	if (item->type < type_line) 
		fprintf(out,"mg:0x%x 0x%x ", ca[0].x, ca[0].y);
	item_dump_attr(item, map, out);
	fprintf(out,"\n");
	if (item->type >= type_line)
		for (i = 0 ; i < count ; i++)
			fprintf(out,"mg:0x%x 0x%x\n", ca[i].x, ca[i].y);
}
示例#8
0
文件: track.c 项目: justinzane/navit
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);
		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;
			} else 
				while (item_coord_get(item, &c, 1));
                }  
		map_rect_destroy(mr);
        }
        mapset_close(h);
	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
}
示例#9
0
文件: search.c 项目: justinzane/navit
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;
	}
示例#10
0
文件: popup.c 项目: justinzane/navit
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"));
				}
			}
		}
示例#11
0
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);
	}
示例#12
0
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);
}
示例#13
0
static struct map_search_priv *
binmap_search_new(struct map_priv *map, struct item *item, struct attr *search, int partial)
{
	struct map_rect_priv *map_rec;
	struct map_search_priv *msp;
	struct map_selection *ms;
	struct item *town;
	int i;
	
	/*
     * NOTE: If you implement search for other attributes than attr_town_name and attr_street_name,
     * please update this comment and the documentation for map_search_new() in map.c
     */
	switch (search->type) {
		case attr_country_name:
			break;
		case attr_town_name:
			msp = g_new(struct map_search_priv, 1);
			msp->search_results = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
			map_rec = map_rect_new_binfile(map, NULL);
			map_rec->country_id = item->id_lo;
			msp->mr = map_rec;
			msp->search = search;
			msp->partial = partial;
			return msp;
			break;
		case attr_town_postal:
			break;
		case attr_street_name:
			if (! item->map)
				break;
			if (!map_priv_is(item->map, map))
				break;
			ms = g_new(struct map_selection, 1);
			ms->next = NULL;
			for (i = 0; i < layer_end; i++)
			{
				ms->order[i] = 18;
			}
			map_rec = map_rect_new_binfile(map, ms);
			town = map_rect_get_item_byid_binfile(map_rec, item->id_hi, item->id_lo);
			if (town) {
				struct map_search_priv *msp = g_new(struct map_search_priv, 1);
				struct coord *c = g_new(struct coord, 1);
				int size = 10000;
				switch (town->type) {
					case type_town_label_2e5:
						size = 10000;
						break;
					case type_town_label_2e4:
						size = 5000;
						break;
					case type_town_label_2e3:
						size = 2500;
						break;
					case type_town_label_2e2:
						size = 1000;
						break;
					default:
						break;
				}
				item_coord_get(town, c, 1);
				ms->u.c_rect.lu.x = c->x-size;
				ms->u.c_rect.lu.y = c->y+size;
				ms->u.c_rect.rl.x = c->x+size;
				ms->u.c_rect.rl.y = c->y-size;
				
				map_rect_destroy_binfile(map_rec);
				map_rec = map_rect_new_binfile(map, ms);
				msp->mr = map_rec;
				msp->search = search;
				msp->partial = partial;
				msp->search_results = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
				return msp;
			}
			map_rect_destroy_binfile(map_rec);
			g_free(ms);
			break;
		default:
			break;
	}
	return NULL;
}
示例#14
0
文件: navit.c 项目: justinzane/navit
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);
}
示例#15
0
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_);
}