Add:Core:Made it possible to specify profile name at vehicle definition
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 13 Apr 2009 20:06:45 +0000 (20:06 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 13 Apr 2009 20:06:45 +0000 (20:06 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2209 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/attr_def.h
navit/navit/navit.c
navit/navit/navit.xml

index 0421f1b..95952bf 100644 (file)
@@ -229,6 +229,7 @@ ATTR(enable_expression)
 ATTR(fax)
 ATTR(email)
 ATTR(url)
+ATTR(profilename)
 ATTR2(0x0003ffff,type_string_end)
 ATTR2(0x00040000,type_special_begin)
 ATTR(order)
index c8bbc44..8cfb875 100644 (file)
@@ -135,6 +135,7 @@ struct navit {
        struct messagelist *messages;
        struct callback *resize_callback,*button_callback,*motion_callback;
        struct vehicleprofile *vehicleprofile;
+       GList *vehicleprofiles;
        int pitch;
 };
 
@@ -154,6 +155,7 @@ static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
 static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int *dir);
 static void navit_cmd_zoom_to_route(struct navit *this);
 static void navit_cmd_set_center_cursor(struct navit *this_);
+static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
 
 void
 navit_add_mapset(struct navit *this_, struct mapset *ms)
@@ -1271,6 +1273,8 @@ navit_init(struct navit *this_)
                return;
        }
        graphics_init(this_->gra);
+       if (this_->vehicle)
+               navit_set_vehicle(this_, this_->vehicle);
        if (this_->mapsets) {
                ms=this_->mapsets->data;
                if (this_->route) {
@@ -1282,7 +1286,6 @@ navit_init(struct navit *this_)
                        }
                        route_set_mapset(this_->route, ms);
                        route_set_projection(this_->route, transform_get_projection(this_->trans));
-                       route_set_profile(this_->route, this_->vehicleprofile);
                }
                if (this_->tracking) {
                        tracking_set_mapset(this_->tracking, ms);
@@ -1625,7 +1628,7 @@ navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
                                                vehicle_set_attr(this_->vehicle->vehicle, &active, NULL);
                                        active.u.num=1;
                                        vehicle_set_attr(nv->vehicle, &active, NULL);
-                                       this_->vehicle=nv;
+                                       navit_set_vehicle(this_, nv);
                                        attr_updated=1;
                                }
                                l=g_list_next(l);
@@ -1870,7 +1873,7 @@ navit_add_attr(struct navit *this_, struct attr *attr)
                ret=navit_add_vehicle(this_, attr->u.vehicle);
                break;
        case attr_vehicleprofile:
-               this_->vehicleprofile=attr->u.vehicleprofile;
+               this_->vehicleprofiles=g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile);
                break;
        case attr_autozoom_min:
                this_->autozoom_min = attr->u.num;
@@ -2081,10 +2084,36 @@ navit_set_position(struct navit *this_, struct pcoord *c)
                navit_draw(this_);
 }
 
+static int
+navit_set_vehicleprofile(struct navit *this_, char *name)
+{
+       struct attr attr;
+       GList *l;
+       l=this_->vehicleprofiles;
+       while (l) {
+               if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) {
+                       if (!strcmp(attr.u.str, name)) {
+                               this_->vehicleprofile=l->data;
+                               if (this_->route)
+                                       route_set_profile(this_->route, this_->vehicleprofile);
+                               return 1;
+                       }
+               }
+               l=g_list_next(l);
+       }
+       return 0;
+}
+
 static void
 navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
 {
+       struct attr attr;
        this_->vehicle=nv;
+       if (vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
+               if (navit_set_vehicleprofile(this_, attr.u.str))
+                       return;
+       }
+       navit_set_vehicleprofile(this_,"car");
 }
 
 /**
index 2e214c9..ea1ae43 100644 (file)
@@ -53,7 +53,7 @@
         <osd enabled="no" type="button" x="-96" y="-96" command="zoom_in()" src="zoom_in.xpm"/>
         <osd enabled="no" type="button" x="0" y="-96" command="zoom_out()" src="zoom_out.xpm"/> 
 
-        <vehicle name="Local GPS" enabled="yes" active="1" source="gpsd://localhost" gpsd_query="w+xj" color="#0000ff">
+        <vehicle name="Local GPS" profilename="car" enabled="yes" active="1" source="gpsd://localhost" gpsd_query="w+xj" color="#0000ff">
             <!-- Navit can write a tracklog in several formats (gpx, nmea or textfile): -->
             <!-- <log type="gpx" data="track_%Y%m%d-%i.gpx" flush_size="1000" flush_time="30"/> -->
             <cursor w="26" h="26">
@@ -81,7 +81,7 @@
         <!-- For SDL, you should add follow="1" to have the view centered on your position -->
         <!-- <vehicle name="Meins" enabled="yes" source="gpsd://localhost" color="#0000ff" follow="1"/> -->
 
-        <vehicle name="Demo" enabled="no" active="yes" source="demo://">
+        <vehicle name="Demo" profilename="car" enabled="no" active="yes" source="demo://">
             <cursor w="26" h="26">
                 <itemgra>
                     <circle color="#0000ff" radius="24" width="2">
                                <!-- For the cumulative displacement filter to be enabled, set cdf_hist="x" here, with x being an integer somewhere around 4 -->
         <tracking cdf_histsize="0"/>
 
-       <vehicleprofile enabled="yes" name="car" flags="0x4000000" flags_forward_mask="0x4000002" flags_reverse_mask="0x4000001" maxspeed_handling="0" route_mode="0">
+       <vehicleprofile name="car" flags="0x4000000" flags_forward_mask="0x4000002" flags_reverse_mask="0x4000001" maxspeed_handling="0" route_mode="0">
            <roadprofile item_types="street_0,street_1_city" speed="10" route_weight="10">
                <announcement level="0" distance_metric="25"/>
                <announcement level="1" distance_metric="100"/>
             <roadprofile item_types="roundabout" speed="10" route_weight="10"/>
             <roadprofile item_types="ferry" speed="40" route_weight="40"/>
        </vehicleprofile>
-       <vehicleprofile enabled="no" name="bike" flags="0x40000000" flags_forward_mask="0x40000000" flags_reverse_mask="0x40000000" maxspeed_handling="0" route_mode="0">
+       <vehicleprofile name="bike" flags="0x40000000" flags_forward_mask="0x40000000" flags_reverse_mask="0x40000000" maxspeed_handling="0" route_mode="0">
            <roadprofile item_types="track_gravelled" speed="17" route_weight="17">
                <announcement level="0" distance_metric="25"/>
                <announcement level="1" distance_metric="100"/>