Add:Core:Script Command to set destination
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 22 Feb 2010 09:02:21 +0000 (09:02 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 22 Feb 2010 09:02:21 +0000 (09:02 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2958 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/attr.h
navit/navit/navit.c

index 6c357d9..b433fe8 100644 (file)
@@ -85,6 +85,7 @@ enum attr_position_valid {
 #define ATTR_IS_NUMERIC(x) (ATTR_IS_INT(x) || ATTR_IS_DOUBLE(x))
 #define ATTR_IS_COLOR(x) ((x) >= attr_type_color_begin && (x) <= attr_type_color_end)
 #define ATTR_IS_PCOORD(x) ((x) >= attr_type_pcoord_begin && (x) <= attr_type_pcoord_end)
+#define ATTR_IS_COORD(x) ((x) >= attr_type_coord_begin && (x) <= attr_type_coord_end)
 
 struct attr {
        enum attr_type type;
index 49cf60a..d4bfbc7 100644 (file)
@@ -632,6 +632,7 @@ navit_cmd_zoom_out(struct navit *this_)
        return 0;
 }
 
+
 static void
 navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
 {
@@ -639,12 +640,46 @@ navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr
                navit_say(this, in[0]->u.str);
 }
 
+static void
+navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
+{
+       struct pcoord pc;
+       char *description=NULL;
+       if (!in)
+               return;
+       if (!in[0])
+               return;
+       pc.pro = transform_get_projection(this->trans);
+       if (ATTR_IS_COORD(in[0]->type)) {
+               pc.x=in[0]->u.coord->x;
+               pc.y=in[0]->u.coord->y;
+               in++;
+       } else if (ATTR_IS_PCOORD(in[0]->type)) {
+               pc=*in[0]->u.pcoord;
+               in++;
+       } else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type)) {
+               pc.pro=in[0]->u.num;
+               pc.x=in[1]->u.num;
+               pc.y=in[2]->u.num;
+               in+=3;
+       } else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type)) {
+               pc.x=in[0]->u.num;
+               pc.y=in[1]->u.num;
+               in+=2;
+       } else
+               return;
+       if (in[0] && ATTR_IS_STRING(in[0]->type))
+               description=in[0]->u.str;
+       navit_set_destination(this, &pc, description, 1);
+}
+
 static struct command_table commands[] = {
        {"zoom_in",command_cast(navit_cmd_zoom_in)},
        {"zoom_out",command_cast(navit_cmd_zoom_out)},
        {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
        {"say",command_cast(navit_cmd_say)},
        {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
+       {"set_destination",command_cast(navit_cmd_set_destination)},
        {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)},
 };