Example #1
0
// Checks if there are alerts to be displayed
void roadmap_alerter_check(const RoadMapGpsPosition *gps_position, const PluginLine *line) {

    //check that alerts are enabled
    if (!config_alerts_enabled()) {
        return;
    }

    // check minimum speed
    if (roadmap_math_to_speed_unit(gps_position->speed) < config_alerts_min_speed()) {
        // If there is any active alert turn it off.
        the_active_alert.active_alert_id = -1;
        alert_should_be_visible = FALSE;
        return;
    }

    // check if there is a alert in range
    if (is_alert_in_range(gps_position, line) > 0) {
        alert_should_be_visible = TRUE;
    } else {
        alert_should_be_visible = FALSE;
    }
}
Example #2
0
static void roadmap_speedometer_after_refresh (void){
   RoadMapGuiPoint image_position;
   RoadMapGuiPoint text_position;
   RoadMapGuiPoint units_position;
   RoadMapGpsPosition pos;
   RoadMapPen speedometer_pen;
   char str[30];
   char unit_str[30];
   int font_size = 20;
   int font_size_units = 10;
   int speed_offset = 6;
   int units_offset = 6;
   int speed;

#ifdef IPHONE_NATIVE
	font_size = 18;
	font_size_units = 8;
#else
   if ( roadmap_lang_rtl() )
      font_size_units--;     // Longer text for units
#endif


   if (SpeedometerImage == NULL){
      return;
   }

   if (gHideSpeedometer){
         after_refresh_callback();
         return;
   }

   if (!roadmap_map_settings_isShowSpeedometer()){
      after_refresh_callback();
      return;
   }

   if (roadmap_screen_is_hd_screen()){
      speed_offset *= 1.5;
      units_offset *= 1.5;
   }
   roadmap_navigate_get_current (&pos, NULL, NULL);
   speed = pos.speed;
   if ((speed == -1) || !roadmap_gps_have_reception()){
      after_refresh_callback();
      return;
   }


   speedometer_pen = roadmap_canvas_create_pen ("speedometer_pen");
   if (roadmap_skin_state() == 1)
      roadmap_canvas_set_foreground(SPEEDOMETER_SPEED_COLOR_NIGHT);
   else
      roadmap_canvas_set_foreground(SPEEDOMETER_SPEED_COLOR_DAY);

   image_position.x = roadmap_canvas_width() - roadmap_canvas_image_width(SpeedometerImage);
   image_position.y = roadmap_canvas_height() - roadmap_canvas_image_height(SpeedometerImage) - roadmap_bar_bottom_height() - gOffset;
   roadmap_canvas_draw_image (SpeedometerImage, &image_position,  0, IMAGE_NORMAL);

   text_position.y = image_position.y + roadmap_canvas_image_height(SpeedometerImage) *.8;
   units_position.y = image_position.y + roadmap_canvas_image_height(SpeedometerImage)*.8;

   if (speed != -1){
      if (!roadmap_gps_is_show_raw()) {
         snprintf (str, sizeof(str), "%3d", roadmap_math_to_speed_unit(speed));
         snprintf (unit_str, sizeof(unit_str), "%s",  roadmap_lang_get(roadmap_math_speed_unit()));
      } else {
         snprintf (str, sizeof(str), "%3d", pos.accuracy);
         snprintf (unit_str, sizeof(unit_str), "%s",  "ac");
      }

      if (ssd_widget_rtl(NULL)){
         text_position.x = roadmap_canvas_width() -speed_offset;
         roadmap_canvas_draw_string_size(&text_position, ROADMAP_CANVAS_BOTTOMRIGHT, font_size, str);

         units_position.x = image_position.x + units_offset;
         roadmap_canvas_draw_string_size(&units_position, ROADMAP_CANVAS_BOTTOMLEFT, font_size_units, unit_str);
      }
      else{
         text_position.x = image_position.x + speed_offset;
         roadmap_canvas_draw_string_size(&text_position, ROADMAP_CANVAS_BOTTOMLEFT, font_size, str);

         units_position.x = roadmap_canvas_width() -units_offset;
         roadmap_canvas_draw_string_size(&units_position, ROADMAP_CANVAS_BOTTOMRIGHT, font_size_units, unit_str);
      }
   }

   after_refresh_callback();
}
void editor_segments_properties (SelectedLine *lines, int lines_count) {

   char str[100];
   int total_length = 0;
   int total_time = 0;
   int i;
   DialogSelectedLines *selected_lines = malloc (sizeof(*selected_lines));

   selected_lines->lines = lines;
   selected_lines->count = lines_count;

   activate_dialog("Segment Properties", selected_lines);
   editor_segments_fill_dialog (lines, lines_count);

   /* Collect info data */
   for (i=0; i<selected_lines->count; i++) {
      int line_length;
      int time;

      SelectedLine *line = &selected_lines->lines[i];

      if (line->line.plugin_id == EditorPluginID) {

         line_length = editor_line_length (line->line.line_id);
         time = editor_line_get_cross_time (line->line.line_id, 1);
         
      } else  {
         LineRouteTime from_cross_time;
         LineRouteTime to_cross_time;

	      roadmap_square_set_current (line->line.square);
         line_length = roadmap_line_length (line->line.line_id);
         if (roadmap_line_speed_get_cross_times
               (line->line.line_id, &from_cross_time, &to_cross_time) == -1) {
            time = -1; //TODO get real speed
         } else {
            time = from_cross_time;
         }
      }

      if (time > 0) {
         total_time += time;
      } else {

         if ((total_time == 0) || (total_length == 0)) {
            total_time += (int)(1.0 *line_length / 10);
         } else {
            total_time +=
               (int)(1.0 * line_length / (total_length/total_time)) + 1;
         }
      }

      total_length += line_length;
   }

#ifdef SSD
   if (selected_lines->lines[0].line.plugin_id == ROADMAP_PLUGIN_ID) {
      int line = selected_lines->lines[0].line.line_id;
      int avg_speed = roadmap_line_speed_get_avg_speed (line, 0);
      int cur_speed = roadmap_line_speed_get_speed (line, 0);

      snprintf (str, sizeof(str), " : %d (%d)",
               roadmap_math_to_speed_unit(avg_speed), roadmap_math_to_speed_unit(cur_speed));
      ssd_dialog_set_value ("Speed", str);
   } else {
      ssd_dialog_set_value ("Speed", "");
   }
#endif   

   snprintf (str, sizeof(str), "  : %d %s",
            roadmap_math_distance_to_current(total_length), roadmap_lang_get(roadmap_math_distance_unit()));
#ifdef SSD
   ssd_dialog_set_value ("Length", str);
#else   
   roadmap_dialog_set_data ("Info", "Length", str);
#endif   

   snprintf (str, sizeof(str), "  : %d %s",
             total_time, roadmap_lang_get("seconds"));

#ifdef SSD
   ssd_dialog_set_value ("Time", str);
   ssd_dialog_draw ();
#else   
   roadmap_dialog_set_data ("Info", "Time", str);
#endif   
}
Example #4
0
//checks whether an alert is within range
static int is_alert_in_range(const RoadMapGpsPosition *gps_position, const PluginLine *line) {

    int count;
    int i;
    int distance ;
    int steering;
    RoadMapPosition pos;
    int azymuth;
    int delta;
    int j;
    unsigned int speed;
    RoadMapPosition gps_pos;
    int square;
    int squares[9];
    int count_squares;

    gps_pos.latitude = gps_position->latitude;
    gps_pos.longitude = gps_position->longitude;
    count_squares = roadmap_square_find_neighbours (&gps_pos, 0, squares);

    for (square = 0; square < count_squares; square++) {

        roadmap_square_set_current(squares[square]);

        // loop alll prvidor for an alert
        for (j = 0 ; j < RoadMapAlertProvidors.count; j++) {

            count =  (* (RoadMapAlertProvidors.providor[j]->count)) ();


            // no alerts for this providor
            if (count == 0) {
                continue;
            }

            for (i=0; i<count; i++) {

                // if the alert is not alertable, continue. (dummy speed cams, etc.)
                if (!(* (RoadMapAlertProvidors.providor[j]->is_alertable))(i)) {
                    continue;
                }

                (* (RoadMapAlertProvidors.providor[j]->get_position)) (i, &pos, &steering);

                // check that the alert is within alert distance
                distance = roadmap_math_distance(&pos, &gps_pos);

                if (distance > (*(RoadMapAlertProvidors.providor[j]->get_distance))(i)) {
                    continue;
                }


                // check if the alert is on the navigation route
                if (!alert_is_on_route (&pos, steering)) {

                    // check that the alert is in the direction of driving
                    delta = azymuth_delta(gps_position->steering, steering);
                    if (delta > AZYMUTH_DELTA || delta < (0-AZYMUTH_DELTA)) {
                        continue;
                    }

                    // check that we didnt pass the alert
                    azymuth = roadmap_math_azymuth (&gps_pos, &pos);
                    delta = azymuth_delta(azymuth, steering);
                    if (delta > 90|| delta < (-90)) {
                        continue;

                    }

                    // check that the alert is on the same street
                    if (!check_same_street(line, &pos)) {
                        continue;
                    }
                }

                speed = (* (RoadMapAlertProvidors.providor[j]->get_speed))(i);
                // check that the driving speed is over the allowed speed for that alert
                if ((unsigned int)roadmap_math_to_speed_unit(gps_position->speed) < speed) {
                    the_active_alert.alert_type = WARN;
                    the_active_alert.distance_to_alert 	= distance;
                    the_active_alert.active_alert_id 	=  (* (RoadMapAlertProvidors.providor[j]->get_id))(i);
                    the_active_alert.alert_providor = j;
                    return TRUE;
                }
                else {
                    the_active_alert.alert_type = ALERT;
                    the_active_alert.alert_providor = j;
                    the_active_alert.distance_to_alert 	= distance;
                    the_active_alert.active_alert_id 	= (* (RoadMapAlertProvidors.providor[j]->get_id))(i);
                    return TRUE;
                }
            }
        }
    }

    return FALSE;
}
Example #5
0
//checks whether an alert is within range
static int is_alert_in_range(const RoadMapGpsPosition *gps_position, const PluginLine *line){
   int i;
   int j;
   unsigned int speed;
   int distance; // will hold the distance of the alert
   RoadMapPosition gps_pos;
   int square;
   int squares[9];
   int count_squares;
   const char * street_name; // the current street name.
   char current_street_name[512];
   RoadMapPosition context_save_pos;
   int context_save_zoom;
   int alert_index; // will hold the index in the provider of the alert
   int priorities [] = {ALERTER_PRIORITY_HIGH,ALERTER_PRIORITY_MEDIUM,ALERTER_PRIORITY_LOW};
   int num_priorities = sizeof(priorities)/sizeof(int);
   int alert_providor_ind;
   int square_ind;
   BOOL found_alert = FALSE;
   gps_pos.latitude = gps_position->latitude;
   gps_pos.longitude = gps_position->longitude;

   roadmap_math_get_context(&context_save_pos, &context_save_zoom);
   roadmap_math_set_context((RoadMapPosition *)&gps_pos, 20);

   count_squares = roadmap_square_find_neighbours (&gps_pos, 0, squares);
   // get the street infromation of the current position.
   get_street_from_line(line->square,line->line_id, &street_name);
   strncpy_safe (current_street_name, street_name, sizeof (current_street_name));
   // go over priorities one by one from highest to lowest.
   for (j=0; (j< num_priorities); j++){

      if ( found_alert )   // Removed from the "for" condition due to some problem in android gcc AGA
         break;

		// loop all the providers for an alert
		for (i = 0 ; ((i < RoadMapAlertProviders.count)&&(!found_alert)); i++){

		   // if provider doesn't have a high enough priority skip him, we'll get to him later.
	      if(RoadMapAlertProviders.provider[i]->get_priority()!=priorities[j])
	  	       continue;

			/*
		    * If not enough distance has been passed from last check, provider can order to ignore
		    * if alert is active, always perform check, so distance will be updated
		    */
	  	   if(!alert_should_be_visible){
		       if(!(* (RoadMapAlertProviders.provider[i]->distance_check))(gps_pos))
		          continue;
		   }

			if ((* (RoadMapAlertProviders.provider[i]->is_square_dependent))()){
			/*
			* This provider has different alerts for each square, so we need to loop over all
			* these squares and check. (Speed cams in tiles for example, as opposed to RealTimeAlerts).
			*/
	         for (square = 0; ((square < count_squares)&&(!found_alert)); square++) {
	            roadmap_square_set_current(squares[square]);
	            if(is_alert_in_range_provider(RoadMapAlertProviders.provider[i],
	                     gps_position, line, &alert_index,&distance, current_street_name))
	            {
	               square_ind = square;
	               alert_providor_ind = i;
	               found_alert = TRUE;
	            }
	         }

	      } else {
	           if(is_alert_in_range_provider(RoadMapAlertProviders.provider[i],
	                   gps_position, line, &alert_index,&distance,current_street_name))
	           {
	             	square_ind = square;
	             	alert_providor_ind = i;
	             	found_alert = TRUE;
	           }
	      }
		}
   }

   if(found_alert){
      speed = (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_speed))(alert_index);
      // if driving speed is over the speed limit - it's an ALERT, otherwise it's a WARNING
      if ((unsigned int)roadmap_math_to_speed_unit(gps_position->speed) < speed) {
         the_active_alert.alert_type = WARN;
         the_active_alert.distance_to_alert 	= distance;
         the_active_alert.active_alert_id 	=  (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_id))(alert_index);
         the_active_alert.alert_provider = alert_providor_ind;
         the_active_alert.square = squares[square_ind];
         roadmap_math_set_context(&context_save_pos, context_save_zoom);
         return TRUE;
      }
      else{
         the_active_alert.alert_type = ALERT;
         the_active_alert.distance_to_alert 	= distance;
         the_active_alert.active_alert_id 	= (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_id))(alert_index);
         the_active_alert.alert_provider = alert_providor_ind;
         the_active_alert.square = squares[square_ind];
         roadmap_math_set_context(&context_save_pos, context_save_zoom);
         return TRUE;
      }
   }

   roadmap_math_set_context(&context_save_pos, context_save_zoom);
   return FALSE;
}