Exemple #1
0
NavitAdapter::NavitAdapter()
{
    QAction* loadFile = new QAction(tr("Load Navit file..."), this);
    loadFile->setData(theUid.toString());
    connect(loadFile, SIGNAL(triggered()), SLOT(onLoadFile()));
    theMenu = new QMenu();
    theMenu->addAction(loadFile);

    loaded = false;

//    loaded = navit.setFilename("C:/home/cbro/Merkaartor/osm_bbox_11.3,47.9,11.7,48.2.bin");
//    loaded = navit.setFilename("C:/home/cbro/Merkaartor/osm_bbox_4.2,50.7,4.6,50.9.bin");
//    loaded = navit.setFilename("C:/home/cbro/Merkaartor/belgium.navit.bin");

    MasPaintStyle theStyle;
    theStyle.loadPainters(":/Styles/Mapnik.mas");
    for (int i=0; i<theStyle.painterSize(); ++i) {
        thePrimitivePainters.append(PrimitivePainter(*theStyle.getPainter(i)));
    }

    QStringList osmAttr = attrmap.split("\n", QString::SkipEmptyParts);
    foreach (QString l, osmAttr) {
        QStringList flds = l.split("\t", QString::SkipEmptyParts);
        item_type typ = item_from_name(flds[2].toLatin1().data());
        if (typ == type_none)
            continue;
        NavitFeature f;
        QStringList sl = flds[1].split(",");
        foreach(QString t, sl) {
            QStringList kv = t.split("=");
            f.Tags.append(qMakePair(kv[0], kv[1]));
        }
Exemple #2
0
struct attr *
attr_new_from_text(const char *name, const char *value)
{
	enum attr_type attr;
	struct attr *ret;

	ret=g_new0(struct attr, 1);
	dbg(1,"enter name='%s' value='%s'\n", name, value);
	attr=attr_from_name(name);
	ret->type=attr;
	switch (attr) {
	case attr_item_type:
		ret->u.item_type=item_from_name(value);
		break;
	default:
		if (attr >= attr_type_string_begin && attr <= attr_type_string_end) {
			ret->u.str=value;
			break;
		}
		if (attr >= attr_type_int_begin && attr <= attr_type_int_end) {
			ret->u.num=atoi(value);
			break;
		}
		dbg(1,"default\n");
		g_free(ret);
		ret=NULL;
	}
	return ret;
}
Exemple #3
0
struct attr *
attr_new_from_text(const char *name, const char *value)
{
	enum attr_type attr;
	struct attr *ret;
	struct coord_geo *g;
	struct coord c;

	ret=g_new0(struct attr, 1);
	dbg(1,"enter name='%s' value='%s'\n", name, value);
	attr=attr_from_name(name);
	ret->type=attr;
	switch (attr) {
	case attr_item_type:
		ret->u.item_type=item_from_name(value);
		break;
	default:
		if (attr >= attr_type_string_begin && attr <= attr_type_string_end) {
			ret->u.str=(char *)value;
			break;
		}
		if (attr >= attr_type_int_begin && attr <= attr_type_int_end) {
			ret->u.num=atoi(value);
			break;
		}
		if (attr >= attr_type_color_begin && attr <= attr_type_color_end) {
			struct color *color=g_new0(struct color, 1);
			int r,g,b,a;
			ret->u.color=color;
			if(strlen(value)==7){
				sscanf(value,"#%02x%02x%02x", &r, &g, &b);
				color->r = (r << 8) | r;
				color->g = (g << 8) | g;
				color->b = (b << 8) | b;
				color->a = (65535);
			} else if(strlen(value)==9){
				sscanf(value,"#%02x%02x%02x%02x", &r, &g, &b, &a);
				color->r = (r << 8) | r;
				color->g = (g << 8) | g;
				color->b = (b << 8) | b;
				color->a = (a << 8) | a;
			} else {
				dbg(0,"color %s has unknown format\n",value);
			}
			break;
		}
		if (attr >= attr_type_coord_geo_start && attr <= attr_type_coord_geo_end) {
			g=g_new(struct coord_geo, 1);
			ret->u.coord_geo=g;
			coord_parse(value, projection_mg, &c);
			transform_to_geo(projection_mg, &c, g);
			break;
		}
		dbg(1,"default\n");
		g_free(ret);
		ret=NULL;
	}
Exemple #4
0
struct attr *
attr_new_from_text(const char *name, const char *value)
{
	enum attr_type attr;
	struct attr *ret;
	struct coord_geo *g;
	struct coord c;
	char *pos,*type_str,*str,*tok;
	int min,max,count;

	ret=g_new0(struct attr, 1);
	dbg(1,"enter name='%s' value='%s'\n", name, value);
	attr=attr_from_name(name);
	ret->type=attr;
	switch (attr) {
	case attr_item_type:
		ret->u.item_type=item_from_name(value);
		break;
	case attr_item_types:
		count=0;
		type_str=g_strdup(value);
		str=type_str;
		while ((tok=strtok(str, ","))) {
			ret->u.item_types=g_realloc(ret->u.item_types, (count+2)*sizeof(enum item_type));
			ret->u.item_types[count++]=item_from_name(tok);
			ret->u.item_types[count]=type_none;
        	        str=NULL;
        	}
		g_free(type_str);
		break;
	case attr_attr_types:
		count=0;
		type_str=g_strdup(value);
		str=type_str;
		while ((tok=strtok(str, ","))) {
			ret->u.attr_types=g_realloc(ret->u.attr_types, (count+2)*sizeof(enum attr_type));
			ret->u.attr_types[count++]=attr_from_name(tok);
			ret->u.attr_types[count]=attr_none;
        	        str=NULL;
        	}
		g_free(type_str);
		break;
	case attr_dash:
		count=0;
		type_str=g_strdup(value);
		str=type_str;
		while ((tok=strtok(str, ","))) {
			ret->u.dash=g_realloc(ret->u.dash, (count+2)*sizeof(int));
			ret->u.dash[count++]=g_ascii_strtoull(tok,NULL,0);
			ret->u.dash[count]=0;
        	        str=NULL;
        	}
		g_free(type_str);
		break;
	case attr_order:
	case attr_sequence_range:
	case attr_angle_range:
	case attr_speed_range:
		pos=strchr(value, '-');
		min=0;
		max=32767;
		if (! pos) {
                	sscanf(value,"%d",&min);
                	max=min;
		} else if (pos == value)
			sscanf(value,"-%d",&max);
		else
                	sscanf(value,"%d-%d",&min, &max);
		ret->u.range.min=min;
		ret->u.range.max=max;
		break;
	default:
		if (attr >= attr_type_string_begin && attr <= attr_type_string_end) {
			ret->u.str=g_strdup(value);
			break;
		}
		if (attr >= attr_type_int_begin && attr <= attr_type_int_end) {
			if (value[0] == '0' && value[1] == 'x')
				ret->u.num=strtoul(value, NULL, 0);
			else
				ret->u.num=strtol(value, NULL, 0);
			
			if ((attr >= attr_type_rel_abs_begin) && (attr < attr_type_boolean_begin)) {
				/* Absolute values are from -0x40000000 - 0x40000000, with 0x0 being 0 (who would have thought that?)
					 Relative values are from 0x40000001 - 0x80000000, with 0x60000000 being 0 */
				if (strchr(value, '%')) {
					if ((ret->u.num > 0x20000000) || (ret->u.num < -0x1FFFFFFF)) {
						dbg(0, "Relative possibly-relative attribute with invalid value %i\n", ret->u.num);
					}

					ret->u.num += 0x60000000;
				} else {
					if ((ret->u.num > 0x40000000) || (ret->u.num < -0x40000000)) {
						dbg(0, "Non-relative possibly-relative attribute with invalid value %i\n", ret->u.num);
					}
				}
			} else 	if (attr >= attr_type_boolean_begin) { // also check for yes and no
				if (g_ascii_strcasecmp(value,"no") && g_ascii_strcasecmp(value,"0") && g_ascii_strcasecmp(value,"false")) 
					ret->u.num=1;
				else
					ret->u.num=0;
			}
			break;
		}
		if (attr >= attr_type_color_begin && attr <= attr_type_color_end) {
			struct color *color=g_new0(struct color, 1);
			int r,g,b,a;
			ret->u.color=color;
			if(strlen(value)==7){
				sscanf(value,"#%02x%02x%02x", &r, &g, &b);
				color->r = (r << 8) | r;
				color->g = (g << 8) | g;
				color->b = (b << 8) | b;
				color->a = (65535);
			} else if(strlen(value)==9){
				sscanf(value,"#%02x%02x%02x%02x", &r, &g, &b, &a);
				color->r = (r << 8) | r;
				color->g = (g << 8) | g;
				color->b = (b << 8) | b;
				color->a = (a << 8) | a;
			} else {
				dbg(0,"color %s has unknown format\n",value);
			}
			break;
		}
		if (attr >= attr_type_coord_geo_begin && attr <= attr_type_coord_geo_end) {
			g=g_new(struct coord_geo, 1);
			ret->u.coord_geo=g;
			coord_parse(value, projection_mg, &c);
			transform_to_geo(projection_mg, &c, g);
			break;
		}
		dbg(1,"default\n");
		g_free(ret);
		ret=NULL;
	}
Exemple #5
0
static struct item *
map_rect_get_item_textfile(struct map_rect_priv *mr)
{
	char *p,type[SIZE];
	if (debug)
		printf("map_rect_get_item_textfile id_hi=%d line=%s", mr->item.id_hi, mr->line);
	if (!mr->f) {
		return NULL;
	}
	for(;;) {
		if (feof(mr->f)) {
			if (debug)
				printf("map_rect_get_item_textfile: eof\n");
			if (mr->item.id_hi) {
				return NULL;
			}
			mr->item.id_hi++;
			fseek(mr->f, 0, SEEK_SET);
			get_line(mr);
		}
		if (mr->item.id_hi) {
			if (!contains_coord(mr->line)) {
				get_line(mr);
				continue;
			}
			if ((p=index(mr->line,'\n'))) 
				*p='\0';
			if (debug)
				printf("map_rect_get_item_textfile: point found\n");
			mr->attrs[0]='\0';
			parse_line(mr);
			mr->eoc=0;
			mr->item.id_lo=mr->pos;
		} else {
			if (contains_coord(mr->line)) {
				get_line(mr);
				continue;
			}
			if ((p=index(mr->line,'\n'))) 
				*p='\0';
			if (debug)
				printf("map_rect_get_item_textfile: line found\n");
			if (! mr->line[0]) {
				get_line(mr);
				continue;
			}
			mr->item.id_lo=mr->pos;
			strcpy(mr->attrs, mr->line);
			get_line(mr);
			if (debug)
				printf("mr=%p attrs=%s\n", mr, mr->attrs);
		}
		if (debug)
			printf("get_attrs %s\n", mr->attrs);
		if (get_tag(mr->attrs,"type",NULL,type,NULL)) {
			if (debug)
				printf("type='%s'\n", type);
			mr->item.type=item_from_name(type);
			if (mr->item.type == type_none) 
				printf("Warning: type '%s' unknown\n", type);
		} else {
			get_line(mr);
			continue;
		}
		mr->attr_last=attr_none;
		if (debug)
			printf("return attr='%s'\n", mr->attrs);
		return &mr->item;
	}
}
Exemple #6
0
static struct item *
map_rect_get_item_textfile(struct map_rect_priv *mr)
{
	char *p,type[SIZE];
	dbg(1,"map_rect_get_item_textfile id_hi=%d line=%s", mr->item.id_hi, mr->line);
	if (!mr->f) {
		return NULL;
	}
	while (mr->more) {
		struct coord c;
		textfile_coord_get(mr, &c, 1);
	}
	for(;;) {
		if (feof(mr->f)) {
			dbg(1,"map_rect_get_item_textfile: eof\n");
			if (mr->item.id_hi) {
				return NULL;
			}
			mr->item.id_hi++;
			if (mr->m->is_pipe) {
				pclose(mr->f);
				mr->f=popen(mr->args, "r");
			} else
				fseek(mr->f, 0, SEEK_SET);
			get_line(mr);
		}
		if ((p=strchr(mr->line,'\n'))) 
			*p='\0';
		if (mr->item.id_hi) {
			mr->attrs[0]='\0';
			if (!parse_line(mr, 1)) {
				get_line(mr);
				continue;
			}
			dbg(1,"map_rect_get_item_textfile: point found\n");
			mr->eoc=0;
			mr->item.id_lo=mr->pos;
		} else {
			if (parse_line(mr, 1)) {
				get_line(mr);
				continue;
			}
			dbg(1,"map_rect_get_item_textfile: line found\n");
			if (! mr->line[0]) {
				get_line(mr);
				continue;
			}
			mr->item.id_lo=mr->pos;
			strcpy(mr->attrs, mr->line);
			get_line(mr);
			dbg(1,"mr=%p attrs=%s\n", mr, mr->attrs);
		}
		dbg(1,"get_attrs %s\n", mr->attrs);
		if (get_tag(mr->attrs,"type",NULL,type,NULL)) {
			dbg(1,"type='%s'\n", type);
			mr->item.type=item_from_name(type);
			if (mr->item.type == type_none) 
				printf("Warning: type '%s' unknown\n", type);
		} else {
			get_line(mr);
			continue;
		}
		mr->attr_last=attr_none;
		mr->more=1;
		dbg(1,"return attr='%s'\n", mr->attrs);
		return &mr->item;
	}
}
Exemple #7
0
static struct item *
map_rect_get_item_textfile(struct map_rect_priv *mr)
{
    char *p,type[TEXTFILE_LINE_SIZE];
    dbg(lvl_debug,"map_rect_get_item_textfile id_hi=%d line=%s", mr->item.id_hi, mr->line);
    if (!mr->f) {
        return NULL;
    }
    while (mr->more) {
        struct coord c;
        textfile_coord_get(mr, &c, 1);
    }
    for(;;) {
        if (feof(mr->f)) {
            dbg(lvl_debug,"map_rect_get_item_textfile: eof %d\n",mr->item.id_hi);
            if (mr->m->flags & 1) {
                if (!mr->item.id_hi)
                    return NULL;
                mr->item.id_hi=0;
            } else {
                if (mr->item.id_hi)
                    return NULL;
                mr->item.id_hi=1;
            }
            if (mr->m->is_pipe) {
#ifdef HAVE_POPEN
                pclose(mr->f);
                mr->f=popen(mr->args, "r");
                mr->pos=0;
                mr->lastlen=0;
#endif
            } else {
                fseek(mr->f, 0, SEEK_SET);
                clearerr(mr->f);
            }
            get_line(mr);
        }
        if ((p=strchr(mr->line,'\n')))
            *p='\0';
        if (mr->item.id_hi) {
            mr->attrs[0]='\0';
            if (!parse_line(mr, 1)) {
                get_line(mr);
                continue;
            }
            dbg(lvl_debug,"map_rect_get_item_textfile: point found\n");
            mr->eoc=0;
            mr->item.id_lo=mr->pos;
        } else {
            if (parse_line(mr, 1)) {
                get_line(mr);
                continue;
            }
            dbg(lvl_debug,"map_rect_get_item_textfile: line found\n");
            if (! mr->line[0]) {
                get_line(mr);
                continue;
            }
            mr->item.id_lo=mr->pos;
            strcpy(mr->attrs, mr->line);
            get_line(mr);
            dbg(lvl_debug,"mr=%p attrs=%s\n", mr, mr->attrs);
        }
        dbg(lvl_debug,"get_attrs %s\n", mr->attrs);
        if (attr_from_line(mr->attrs,"type",NULL,type,NULL)) {
            dbg(lvl_debug,"type='%s'\n", type);
            mr->item.type=item_from_name(type);
            if (mr->item.type == type_none)
                dbg(lvl_error, "Warning: type '%s' unknown\n", type);
        } else {
            get_line(mr);
            continue;
        }
        mr->attr_last=attr_none;
        mr->more=1;
        dbg(lvl_debug,"return attr='%s'\n", mr->attrs);
        return &mr->item;
    }
}