Пример #1
0
static int editor_override_find (int line, editor_db_override **data, int *create) {

   int id;
   int count;
   int square = roadmap_square_active ();
   editor_db_override *rec;
   
   count = editor_db_get_item_count (ActiveOverridesDB);

	for (id = 0; id < count; id++) {
		
		rec = (editor_db_override *)editor_db_get_item (ActiveOverridesDB, id, 0, NULL);
		if (rec->square == square && rec->line == line) {
			if (create) *create = 0;
			break;
		}
	}
	
	if (id == count) {
		if (!create) return -1;
		
		id = editor_db_add_item (ActiveOverridesDB, NULL, 0); 
		if (id >= 0) {
			rec = (editor_db_override *)editor_db_get_item (ActiveOverridesDB, id, 0, NULL);
			rec->square = square;
			rec->line = line;
			rec->flags = 0;
			rec->direction = roadmap_line_route_get_direction (line, ROUTE_CAR_ALLOWED);
			*create = 1;
		}
	}
	
	if (data) *data = rec;
	return id;
}
Пример #2
0
int roadmap_plugin_get_direction (PluginLine *line, int who) {
   
   if (line->plugin_id == ROADMAP_PLUGIN_ID) {

		roadmap_square_set_current (line->square);
      return roadmap_line_route_get_direction (line->line_id, who);

   } else {
      RoadMapPluginHooks *hooks = get_hooks (line->plugin_id);

      if (hooks == NULL) {
         roadmap_log (ROADMAP_ERROR, "plugin id:%d is missing.",
               line->plugin_id);

         return 0;
      }

      if (hooks->route_direction != NULL) {
         return (*hooks->route_direction) (line, who);
      }

      return 0;
   }

}
Пример #3
0
int get_connected_segments (int square,
									 int seg_line_id, int is_seg_reversed,
                            int node_id, struct successor *successors,
                            int max, int use_restrictions, int use_directions) {

   static int res_bits[8];
   int i;

   int count = 0;
   //int index = 0;
   int res_index = 0;
   int line;
   int line_reversed;
   int seg_res_bits = 0;
   struct SquareGraphItem *cache;

	if (max > 0 && 
		 find_segment_extension (square, seg_line_id, is_seg_reversed, successors)) {
		
		return 1;
	} 
	
   /* Init turn restrictions bits */
   if (!res_bits[0]) for (i=0; i<8; i++) res_bits[i] = 1<<i;

   roadmap_square_set_current (square);

   cache = get_square_graph (square);

   node_id &= 0xffff;

   i = cache->nodes_index[node_id];
   assert (i > 0);

   if (use_restrictions) {
      if (is_seg_reversed) {
         seg_res_bits = roadmap_line_route_get_restrictions (seg_line_id, 1);
      } else {
         seg_res_bits = roadmap_line_route_get_restrictions (seg_line_id, 0);
      }
   }

   while (i && count < max) {

      int to_point_id;
      int line_direction_allowed;

      line = cache->lines[i - 1];
      i = cache->lines_index[i - 1];
      line_reversed = line & REVERSED;
      if (line_reversed) line = line & ~REVERSED;

      if (line == seg_line_id) {
         
         if (roadmap_line_route_get_direction
               (seg_line_id, ROUTE_CAR_ALLOWED) == ROUTE_DIRECTION_ANY) {
            res_index++;
         }
         continue;
      }

		if (use_directions) {
	      if (!line_reversed) {
	         roadmap_line_to_point (line, &to_point_id);
	         line_direction_allowed =
	            roadmap_line_route_get_direction (line, ROUTE_CAR_ALLOWED) &
	                  ROUTE_DIRECTION_WITH_LINE;
	      } else {
	         roadmap_line_from_point (line, &to_point_id);
	         line_direction_allowed =
	            roadmap_line_route_get_direction (line, ROUTE_CAR_ALLOWED) &
	                  ROUTE_DIRECTION_AGAINST_LINE;
	      }
	
	      if (!line_direction_allowed) {
	         continue;
	      }
		}

      if (!use_restrictions || (res_index >= 8) ||
          !(seg_res_bits & res_bits[res_index])) {
          	  successors[count].square_id = square;
              successors[count].line_id = line;
              successors[count].reversed = (line_reversed != 0);
              successors[count].to_point = to_point_id;
              count++;
      }
      res_index++;
   }

   return count;
}
Пример #4
0
/**
 * [IN] alert_position - the position of the alert
 * [IN] alert_location_info - The old location_info of the alert. Will be updated if necessary
 * [OUT] pNew_Info - the location_info of this alert, to be calculated.
 * returns TRUE iff successful in finding relevant location info for this alert
 * - D.F.
 */
BOOL get_alert_location_info(const RoadMapPosition *alert_position, int alert_streering, roadmap_alerter_location_info *pNew_Info,
      roadmap_alerter_location_info *alert_location_info){

   int alert_square_time_stamp;
   int layers_count;
   int count;
   int layers[128];
   RoadMapNeighbour neighbours[2];
   int square;
   zoom_t context_save_zoom;
   RoadMapPosition context_save_pos;

   if (alert_location_info){

      // check if this alert was tagged as invalid in the past - Could locate a street next to it, eventhough
      // its tile already exists.
      if (alert_location_info->square_id == ALERTER_SQUARE_ID_INVALID)
         return FALSE;

      // if alert info is already initialized and has an up to date timestamp, use its info.
      if(alert_location_info->square_id!=ALERTER_SQUARE_ID_UNINITIALIZED){
         alert_square_time_stamp = roadmap_square_version(alert_location_info->square_id);
         if(alert_square_time_stamp==alert_location_info->time_stamp){
            pNew_Info->line_id = alert_location_info->line_id;
            pNew_Info->square_id = alert_location_info->square_id;
            pNew_Info->time_stamp = alert_location_info->time_stamp;
            return TRUE;
         }
      }
   }

   // did not return so far - so no cached valid location info was found, need to cacluate it.
   layers_count =  roadmap_layer_all_roads (layers, 128);
   if (layers_count > 0) {
      square = roadmap_tile_get_id_from_position(0,alert_position);
      if(!roadmap_square_set_current(square)){
         return FALSE; // do no have this alert's tile, return FALSE;
      }

      roadmap_math_get_context(&context_save_pos, &context_save_zoom);
      roadmap_math_set_context((RoadMapPosition *)alert_position, 2);
      count = roadmap_street_get_closest(alert_position, 0, layers, layers_count, 1, &neighbours[0], 2);
      roadmap_math_set_context(&context_save_pos, context_save_zoom);
      if(count>0&&neighbours[0].distance <= MAX_DISTANCE_FROM_ROAD){
         if (count > 1){
            int direction;
            roadmap_square_set_current(neighbours[0].line.line_id);
            direction = roadmap_line_route_get_direction (neighbours[0].line.line_id, ROUTE_CAR_ALLOWED);
            if (direction == ROUTE_DIRECTION_WITH_LINE || direction == ROUTE_DIRECTION_AGAINST_LINE){
               int line_azymuth;
               int delta;
               if (direction == ROUTE_DIRECTION_WITH_LINE)
                  line_azymuth = roadmap_math_azymuth (&neighbours[0].from, &neighbours[0].to);
               else
                  line_azymuth = roadmap_math_azymuth (&neighbours[0].to, &neighbours[0].from);

               delta = azymuth_delta(line_azymuth, alert_streering);
               if (delta > AZYMUTH_DELTA || delta < (0-AZYMUTH_DELTA)) {
                  pNew_Info->line_id = neighbours[1].line.line_id;
                  pNew_Info->square_id = neighbours[1].line.square;
                  pNew_Info->time_stamp  = roadmap_square_version(pNew_Info->square_id);
               }
               else{
                  pNew_Info->line_id = neighbours[0].line.line_id;
                  pNew_Info->square_id = neighbours[0].line.square;
                  pNew_Info->time_stamp  = roadmap_square_version(pNew_Info->square_id);
               }
            }
            else{
               pNew_Info->line_id = neighbours[0].line.line_id;
               pNew_Info->square_id = neighbours[0].line.square;
               pNew_Info->time_stamp  = roadmap_square_version(pNew_Info->square_id);
            }
         }
         else{
            // found valid information
            pNew_Info->line_id = neighbours[0].line.line_id;
            pNew_Info->square_id = neighbours[0].line.square;
            pNew_Info->time_stamp  = roadmap_square_version(pNew_Info->square_id);
         }

      }else{
         // We have the alert's tile, yet still we could not locate it satisfactorily on
         // a street. Tag this alert so it will not be checked in the future.
         if(alert_location_info){
            alert_location_info->square_id = ALERTER_SQUARE_ID_INVALID;
         }

         return FALSE;
      }
   }

   if(alert_location_info){ // update the information of the alert, for future calls.
      alert_location_info->line_id = pNew_Info->line_id;
      alert_location_info->square_id = pNew_Info->square_id;
      alert_location_info->time_stamp = pNew_Info->time_stamp;
   }
   return TRUE;
}