diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2013-03-10 21:48:13 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2013-03-10 21:48:13 +0000 |
commit | 594989b31be5a6b4b8e333948c326311bdbfc709 (patch) | |
tree | 0792455e09b3d6235a604ee90d2fe7c53b7092f6 /navit/vehicleprofile.c | |
parent | 1b97cd37c1edcdb41fd1f0fce8e3a9c90b743a13 (diff) | |
download | navit-594989b31be5a6b4b8e333948c326311bdbfc709.tar.gz |
Add:Core:Further work on vehicleprofile_options
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@5407 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/vehicleprofile.c')
-rw-r--r-- | navit/vehicleprofile.c | 120 |
1 files changed, 104 insertions, 16 deletions
diff --git a/navit/vehicleprofile.c b/navit/vehicleprofile.c index 6bfbfbbf4..b7cc4b053 100644 --- a/navit/vehicleprofile.c +++ b/navit/vehicleprofile.c @@ -86,23 +86,122 @@ vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr) } static void -vehicleprofile_clear(struct vehicleprofile *this_) +vehicleprofile_free_hash_item(gpointer key, gpointer value, gpointer user_data) +{ + struct navit_object *obj=value; + obj->func->unref(obj); +} + +static void +vehicleprofile_free_hash(struct vehicleprofile *this_) { - if (this_->roadprofile_hash) + if (this_->roadprofile_hash) { + g_hash_table_foreach(this_->roadprofile_hash, vehicleprofile_free_hash_item, NULL); g_hash_table_destroy(this_->roadprofile_hash); - this_->roadprofile_hash=g_hash_table_new(NULL, NULL); + } +} + +static void +vehicleprofile_clear(struct vehicleprofile *this_) +{ + this_->mode=0; + this_->flags_forward_mask=0; + this_->flags_reverse_mask=0; + this_->flags=0; + this_->maxspeed_handling=0; + this_->static_speed=0; + this_->static_distance=0; + g_free(this_->name); + this_->name=NULL; + this_->dangerous_goods=0; this_->length=-1; this_->width=-1; this_->height=-1; this_->weight=-1; this_->axle_weight=-1; this_->through_traffic_penalty=9000; + vehicleprofile_free_hash(this_); + this_->roadprofile_hash=g_hash_table_new(NULL, NULL); +} + +static void +vehicleprofile_apply_roadprofile(struct vehicleprofile *this_, struct navit_object *rp, int is_option) +{ + struct attr item_types_attr; + if (rp->func->get_attr(rp, attr_item_types, &item_types_attr, NULL)) { + enum item_type *types=item_types_attr.u.item_types; + while (*types != type_none) { + struct navit_object *oldrp; + /* Maptool won't place any access flags for roads which don't have default access flags set. Warn user. */ + if(!item_get_default_flags(*types)) + dbg(0,"On '%s' roads used in '%s' vehicleprofile access restrictions are ignored. You might even be directed to drive in wrong direction on a one-way road. " + "Please define default access flags for above road type to item.c and rebuild the map.\n", item_to_name(*types), this_->name); + oldrp=g_hash_table_lookup(this_->roadprofile_hash, (void *)(long)(*types)); + if (is_option && oldrp) { + struct navit_object *newrp; + struct attr_iter *iter=rp->func->iter_new(NULL); + struct attr attr; + dbg(1,"patching roadprofile\n"); + newrp=oldrp->func->dup(oldrp); + while (rp->func->get_attr(rp, attr_any, &attr, iter)) + newrp->func->set_attr(newrp, &attr); + oldrp->func->iter_destroy(iter); + oldrp->func->unref(oldrp); + g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), newrp); + } else { + if (oldrp) + oldrp->func->unref(oldrp); + g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), rp->func->ref(rp)); + } + types++; + } + } +} + +static void +vehicleprofile_apply_attrs(struct vehicleprofile *this_, struct navit_object *obj, int is_option) +{ + struct attr attr; + struct attr_iter *iter=obj->func->iter_new(NULL); + while (obj->func->get_attr(obj, attr_any, &attr, iter)) { + dbg(1,"%s\n",attr_to_name(attr.type)); + if (attr.type == attr_roadprofile) + vehicleprofile_apply_roadprofile(this_, attr.u.navit_object, is_option); + else if (attr.type != attr_profile_option) + vehicleprofile_set_attr_do(this_, &attr); + } + obj->func->iter_destroy(iter); +} + +static void +vehicleprofile_debug_roadprofile(gpointer key, gpointer value, gpointer user_data) +{ + struct roadprofile *rp=value; + dbg(0,"type %s avg %d weight %d max %d\n",item_to_name((int)(long)key),rp->speed,rp->route_weight,rp->maxspeed); } static void vehicleprofile_update(struct vehicleprofile *this_) { + struct attr_iter *iter=vehicleprofile_attr_iter_new(); + struct attr profile_option; dbg(0,"enter\n"); + vehicleprofile_clear(this_); + vehicleprofile_apply_attrs(this_, (struct navit_object *)this_, 0); + while (vehicleprofile_get_attr(this_, attr_profile_option, &profile_option, iter)) { + struct attr active, name; + if (!profile_option.u.navit_object->func->get_attr(profile_option.u.navit_object, attr_active, &active, NULL)) + active.u.num=0; + if (profile_option.u.navit_object->func->get_attr(profile_option.u.navit_object, attr_name, &name, NULL)) + dbg(0,"%p %s %d\n",profile_option.u.navit_object,name.u.str,active.u.num); + if (active.u.num) + vehicleprofile_apply_attrs(this_, profile_option.u.navit_object, 1); + } + vehicleprofile_attr_iter_destroy(iter); + dbg(0,"result l %d w %d h %d wg %d awg %d pen %d\n",this_->length,this_->width,this_->height,this_->weight,this_->axle_weight,this_->through_traffic_penalty); + dbg(0,"m %d fwd 0x%x rev 0x%x flags 0x%x max %d stsp %d stdst %d dg %d\n",this_->mode,this_->flags_forward_mask,this_->flags_reverse_mask, this_->flags, this_->maxspeed_handling, this_->static_speed, this_->static_distance, this_->dangerous_goods); + g_hash_table_foreach(this_->roadprofile_hash, vehicleprofile_debug_roadprofile, NULL); + } @@ -156,21 +255,10 @@ vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr) int vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr) { - struct attr item_types_attr; this_->attrs=attr_generic_add_attr(this_->attrs, attr); switch (attr->type) { case attr_roadprofile: - if (roadprofile_get_attr(attr->u.roadprofile, attr_item_types, &item_types_attr, NULL)) { - enum item_type *types=item_types_attr.u.item_types; - while (*types != type_none) { - /* Maptool won't place any access flags for roads which don't have default access flags set. Warn user. */ - if(!item_get_default_flags(*types)) - dbg(0,"On '%s' roads used in '%s' vehicleprofile access restrictions are ignored. You might even be directed to drive in wrong direction on a one-way road. " - "Please define default access flags for above road type to item.c and rebuild the map.\n", item_to_name(*types), this_->name); - g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), attr->u.roadprofile); - types++; - } - } + vehicleprofile_apply_roadprofile(this_, attr->u.navit_object, 0); break; case attr_profile_option: attr->u.navit_object->func->add_attr(attr->u.navit_object, &this_->active_callback); @@ -197,7 +285,7 @@ vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type char * vehicleprofile_get_name(struct vehicleprofile *this_) { - return this_->name; + return this_->name; } struct object_func vehicleprofile_func = { |