Fix:Core:Cleanup of vehicle handling
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 25 Oct 2008 11:32:37 +0000 (11:32 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 25 Oct 2008 11:32:37 +0000 (11:32 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1559 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/gui/cegui/gui_sdl_window.cpp
navit/navit/gui/gtk/gui_gtk_statusbar.c
navit/navit/gui/gtk/gui_gtk_window.c
navit/navit/gui/internal/gui_internal.c
navit/navit/navit.c
navit/navit/navit.h
navit/navit/osd/core/osd_core.c
navit/navit/vehicle.c
navit/navit/vehicle.h
navit/navit/xmlconfig.c

index 339e327..40416f4 100644 (file)
@@ -757,21 +757,21 @@ static void vehicle_callback_handler( struct navit *nav, struct vehicle *v){
        struct attr attr;
        int sats=0, sats_used=0;
 
-       if (vehicle_get_attr(v, attr_position_speed, &attr))
+       if (vehicle_get_attr(v, attr_position_speed, &attr, NULL))
                sprintf (buffer, "%02.02f km/h", *attr.u.numd);
        else
                strcpy (buffer, "N/A");
        CEGUI::WindowManager::getSingleton().getWindow("OSD/SpeedoMeter")->setText(buffer);
 
-       if (vehicle_get_attr(v, attr_position_height, &attr))
+       if (vehicle_get_attr(v, attr_position_height, &attr, NULL))
                sprintf (buffer, "%.f m", *attr.u.numd);
        else
                strcpy (buffer, "N/A");
        CEGUI::WindowManager::getSingleton().getWindow("OSD/Altimeter")->setText(buffer);
 
-       if (vehicle_get_attr(v, attr_position_sats, &attr))
+       if (vehicle_get_attr(v, attr_position_sats, &attr, NULL))
                sats=attr.u.num;
-       if (vehicle_get_attr(v, attr_position_sats_used, &attr))
+       if (vehicle_get_attr(v, attr_position_sats_used, &attr, NULL))
                sats_used=attr.u.num;
 //     printf(" sats : %i, used %i: \n",sats,sats_used);
        // Sat image hardcoded for now. may break the TaharezSkin
index 46f46fd..c8269a5 100644 (file)
@@ -124,7 +124,7 @@ statusbar_route_update(struct statusbar_priv *this, struct navit *navit, struct
                strcpy(this->route_text, buffer);
                gtk_label_set_text(GTK_LABEL(this->route), this->route_text);
        }
-       if (!vehicle_get_attr(v, attr_position_coord_geo, &attr))
+       if (!vehicle_get_attr(v, attr_position_coord_geo, &attr, NULL))
                return;
        lng=attr.u.coord_geo->lng;
        lat=attr.u.coord_geo->lat;
@@ -136,20 +136,20 @@ statusbar_route_update(struct statusbar_priv *this, struct navit *navit, struct
                lat=-lat;
                lat_c='S';
        }
-       if (vehicle_get_attr(v, attr_position_direction, &attr))
+       if (vehicle_get_attr(v, attr_position_direction, &attr, NULL))
                direction=*(attr.u.numd);
        direction=fmod(direction,360);
        if (direction < 0)
                direction+=360;
        dir_idx=(direction+22.5)/45;
        dir=dirs[dir_idx];
-       if (vehicle_get_attr(v, attr_position_height, &attr))
+       if (vehicle_get_attr(v, attr_position_height, &attr, NULL))
                height=*(attr.u.numd);
-       if (vehicle_get_attr(v, attr_position_speed, &attr))
+       if (vehicle_get_attr(v, attr_position_speed, &attr, NULL))
                speed=*(attr.u.numd);
-       if (vehicle_get_attr(v, attr_position_sats_used, &attr))
+       if (vehicle_get_attr(v, attr_position_sats_used, &attr, NULL))
                sats=attr.u.num;
-       if (vehicle_get_attr(v, attr_position_qual, &attr))
+       if (vehicle_get_attr(v, attr_position_qual, &attr, NULL))
                qual=attr.u.num;
        sprintf(this->gps_text,"GPS %2d/%1d %02.0f%07.4f%c %03.0f%07.4f%c %4.0fm %3.0f°%-2s %3.0fkm/h", sats, qual, floor(lat), fmod(lat*60,60), lat_c, floor(lng), fmod(lng*60,60), lng_c, height, direction, dir, speed);
        gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
index d45ebe3..1186939 100644 (file)
@@ -380,7 +380,7 @@ gui_gtk_vehicles_init(struct gui_priv *this)
 
        iter=navit_attr_iter_new();
        while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
-               vehicle_get_attr(attr.u.vehicle, attr_name, &vattr);
+               vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
                name=g_strdup_printf("Vehicle %d", count++);
                data=g_new(struct action_cb_data, 1);
                data->gui=this;
index d47dc71..5fa382b 100644 (file)
@@ -2435,7 +2435,7 @@ gui_internal_cmd_vehicle(struct gui_priv *this, struct widget *wm)
        gui_internal_widget_append(wb, w);
        iter=navit_attr_iter_new();
        while(navit_get_attr(this->nav, attr_vehicle, &attr, iter)) {
-               vehicle_get_attr(attr.u.vehicle, attr_name, &vattr);
+               vehicle_get_attr(attr.u.vehicle, attr_name, &vattr, NULL);
                wl=gui_internal_button_navit_attr_new(this, vattr.u.str, gravity_left_center|orientation_horizontal|flags_fill,
                        &attr, NULL);
                gui_internal_widget_append(w, wl);
@@ -2567,7 +2567,7 @@ gui_internal_cmd_menu(struct gui_priv *this, struct point *p, int ignore)
                this->clickp_valid=1;
        }
        if (navit_get_attr(this->nav, attr_vehicle, &attr, NULL) && attr.u.vehicle
-               && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp)) {
+               && vehicle_get_attr(attr.u.vehicle, attr_position_coord_geo, &attrp, NULL)) {
                this->vehiclep.pro=transform_get_projection(trans);
                transform_from_geo(this->vehiclep.pro, attrp.u.coord_geo, &c);
                this->vehiclep.x=c.x;
index 97cef71..a74c97d 100644 (file)
@@ -139,6 +139,7 @@ struct attr_iter {
 
 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
+static int navit_add_vehicle(struct navit *this_, struct vehicle *v);
 
 void
 navit_add_mapset(struct navit *this_, struct mapset *ms)
@@ -1510,6 +1511,8 @@ navit_add_attr(struct navit *this_, struct attr *attr)
        case attr_recent_dest:
                this_->recentdest_count = attr->u.num;
                break;
+       case attr_vehicle:
+               return navit_add_vehicle(this_, attr->u.vehicle);
        default:
                return 0;
        }
@@ -1580,9 +1583,9 @@ navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
        if (this_->ready != 3)
                return;
 
-       if (! vehicle_get_attr(nv->vehicle, attr_position_direction, &attr_dir) ||
-           ! vehicle_get_attr(nv->vehicle, attr_position_speed, &attr_speed) ||
-           ! vehicle_get_attr(nv->vehicle, attr_position_coord_geo, &attr_pos))
+       if (! vehicle_get_attr(nv->vehicle, attr_position_direction, &attr_dir, NULL) ||
+           ! vehicle_get_attr(nv->vehicle, attr_position_speed, &attr_speed, NULL) ||
+           ! vehicle_get_attr(nv->vehicle, attr_position_coord_geo, &attr_pos, NULL))
                return;
        nv->dir=*attr_dir.u.numd;
        nv->speed=*attr_speed.u.numd;
@@ -1673,50 +1676,46 @@ navit_set_position(struct navit *this_, struct pcoord *c)
        navit_draw(this_);
 }
 
+static void
+navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
+{
+       this_->vehicle=nv;
+}
+
 /**
  * Register a new vehicle
  *
  * @param navit The navit instance
  * @param v The vehicle instance
- * @param name Guess? :)
- * @param c The color to use for the cursor, currently only used in GTK
- * @param update Wether to refresh the map each time this vehicle position changes (instead of only when it reaches a border)
- * @param follow Wether to center the map on this vehicle position
- * @returns a vehicle instance
+ * @returns 1 for success
  */
-struct navit_vehicle *
-navit_add_vehicle(struct navit *this_, struct vehicle *v, struct attr **attrs)
+static int
+navit_add_vehicle(struct navit *this_, struct vehicle *v)
 {
        struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
-       struct attr *update,*follow,*color,*active, *color2, *animate;
+       struct attr update,follow,color,active, color2, animate;
        nv->vehicle=v;
        nv->update=1;
        nv->follow=0;
        nv->animate_cursor=0;
-       if ((update=attr_search(attrs, NULL, attr_update)))
-               nv->update=nv->update=update->u.num;
-       if ((follow=attr_search(attrs, NULL, attr_follow)))
-               nv->follow=nv->follow=follow->u.num;
-       if ((color=attr_search(attrs, NULL, attr_color)))
-               nv->c=*(color->u.color);
-       if ((color2=attr_search(attrs, NULL, attr_color2)))
-               nv->c2=color2->u.color;
+       if ((vehicle_get_attr(v, attr_update, &update, NULL)))
+               nv->update=nv->update=update.u.num;
+       if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
+               nv->follow=nv->follow=follow.u.num;
+       if ((vehicle_get_attr(v, attr_color, &color, NULL)))
+               nv->c=*(color.u.color);
+       if ((vehicle_get_attr(v, attr_color2, &color2, NULL)))
+               nv->c2=color2.u.color;
        else
                nv->c2=NULL;
        nv->update_curr=nv->update;
        nv->follow_curr=nv->follow;
        this_->vehicles=g_list_append(this_->vehicles, nv);
-       if ((active=attr_search(attrs, NULL, attr_active)) && active->u.num)
+       if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
                navit_set_vehicle(this_, nv);
-       if ((animate=attr_search(attrs, NULL, attr_animate)))
-               nv->animate_cursor=animate->u.num;
-       return nv;
-}
-
-void
-navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
-{
-       this_->vehicle=nv;
+       if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
+               nv->animate_cursor=animate.u.num;
+       return 1;
 }
 
 void
index a79b791..f99a82e 100644 (file)
@@ -80,8 +80,6 @@ void navit_attr_iter_destroy(struct attr_iter *iter);
 void navit_add_callback(struct navit *this_, struct callback *cb);
 void navit_remove_callback(struct navit *this_, struct callback *cb);
 void navit_set_position(struct navit *this_, struct pcoord *c);
-struct navit_vehicle *navit_add_vehicle(struct navit *this_, struct vehicle *v, struct attr **attrs);
-void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
 void navit_tracking_add(struct navit *this_, struct tracking *tracking);
 void navit_set_speech(struct navit *this_, struct speech *speech);
 struct gui *navit_get_gui(struct navit *this_);
index 9ba0151..c33ff3a 100644 (file)
@@ -125,11 +125,11 @@ osd_compass_draw(struct compass *this, struct navit *nav, struct vehicle *v)
        p.x=30;
        p.y=30;
        graphics_draw_circle(this->gr, this->white, &p, 50);
-       if (v && vehicle_get_attr(v, attr_position_direction, &attr_dir)) {
+       if (v && vehicle_get_attr(v, attr_position_direction, &attr_dir, NULL)) {
                vdir=*attr_dir.u.numd;
                handle(this->gr, this->white, &p, 20, -vdir);
        }
-       if (navit_get_attr(nav, attr_destination, &destination_attr, NULL) && v && vehicle_get_attr(v, attr_position_coord_geo, &position_attr)) {
+       if (navit_get_attr(nav, attr_destination, &destination_attr, NULL) && v && vehicle_get_attr(v, attr_position_coord_geo, &position_attr, NULL)) {
                pro=destination_attr.u.pcoord->pro;
                transform_from_geo(pro, position_attr.u.coord_geo, &c1);
                c2.x=destination_attr.u.pcoord->x;
index 2dc21ed..a97ac95 100644 (file)
@@ -114,7 +114,7 @@ vehicle_add_log(struct vehicle *this_, struct log *log)
 }
 
 struct vehicle *
-vehicle_new(struct attr **attrs)
+vehicle_new(struct attr *parent, struct attr **attrs)
 {
        struct vehicle *this_;
        struct attr *source;
@@ -164,7 +164,7 @@ vehicle_new(struct attr **attrs)
 }
 
 int
-vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr)
+vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
 {
        switch (type) {
        case attr_name:
index 0fadf62..455e2d6 100644 (file)
@@ -36,8 +36,8 @@ struct vehicle_methods {
 };
 
 /* prototypes */
-struct vehicle *vehicle_new(struct attr **attrs);
-int vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr);
+struct vehicle *vehicle_new(struct attr *parent, struct attr **attrs);
+int vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
 int vehicle_set_attr(struct vehicle *this_, struct attr *attr, struct attr **attrs);
 int vehicle_add_attr(struct vehicle *this_, struct attr *attr);
 int vehicle_remove_attr(struct vehicle *this_, struct attr *attr);
index 591682b..36ee0c0 100644 (file)
@@ -261,52 +261,6 @@ xmlconfig_debug(struct xmlstate *state)
 }
 
 static int
-xmlconfig_vehicle(struct xmlstate *state)
-{
-       struct attr **attrs;
-       attrs=convert_to_attrs(state);
-
-       state->element_attr.u.data = vehicle_new(attrs);
-       if (! state->element_attr.u.data)
-               return 0;
-       navit_add_vehicle(state->parent->element_attr.u.data, state->element_attr.u.data, attrs);
-       return 1;
-}
-
-static int
-xmlconfig_log_vehicle(struct xmlstate *state)
-{
-       struct attr attr;
-       struct attr **attrs;
-       attrs=convert_to_attrs(state);
-       state->element_attr.u.data = log_new(attrs);
-       if (! state->element_attr.u.data)
-               return 0;
-       attr.type=attr_log;
-       attr.u.log=state->element_attr.u.data;
-       if (vehicle_add_attr(state->parent->element_attr.u.data, &attr))
-               return 0;
-       return 1;
-}
-
-static int
-xmlconfig_log_navit(struct xmlstate *state)
-{
-       struct attr attr;
-       struct attr **attrs;
-       attrs=convert_to_attrs(state);
-       state->element_attr.u.data = log_new(attrs);
-       if (! state->element_attr.u.data)
-               return 0;
-       attr.type=attr_log;
-       attr.u.log=state->element_attr.u.data;
-       if (navit_add_attr(state->parent->element_attr.u.data, &attr))
-               return 0;
-       return 1;
-}
-
-
-static int
 xmlconfig_window_items(struct xmlstate *state)
 {
        int distance=-1;
@@ -677,9 +631,9 @@ struct element_func {
        { "tracking", "navit", xmlconfig_tracking},
        { "route", "navit", xmlconfig_route},
        { "speed", "route", xmlconfig_speed},
-       { "vehicle", "navit", xmlconfig_vehicle},
-       { "log", "vehicle", xmlconfig_log_vehicle},
-       { "log", "navit", xmlconfig_log_navit},
+       { "vehicle", "navit", NULL, NEW(vehicle_new)},
+       { "log", "vehicle", NULL, NEW(log_new)},
+       { "log", "navit", NULL, NEW(log_new)},
        { "window_items", "navit", xmlconfig_window_items},
        { "plugins", "config", NULL, NEW(plugins_new), NULL, INIT(plugins_init), NULL},
        { "plugin", "plugins", xmlconfig_plugin},