/[zanavi_public1]/navit/navit/navit.c
ZANavi

Diff of /navit/navit/navit.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 28 Revision 29
108 GList *list; 108 GList *list;
109 struct mapset_handle *mapset_handle; 109 struct mapset_handle *mapset_handle;
110 } u; 110 } u;
111}; 111};
112 112
113static int dist_to_street = 100000;
114
113static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv); 115static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
114static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt); 116static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
115static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init); 117static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
116static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir); 118static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir);
117static void navit_cmd_zoom_to_route(struct navit *this); 119static void navit_cmd_zoom_to_route(struct navit *this);
4649 callback_list_call_attr_0(global_navit->attr_cbl, attr_unsuspend); 4651 callback_list_call_attr_0(global_navit->attr_cbl, attr_unsuspend);
4650} 4652}
4651 4653
4652 4654
4653/** 4655/**
4656 * @brief Dumps item attrs to string
4657 *
4658 * @param item item
4659 * @param pretty 0 -> normal, 1 -> pretty output
4660 * @return string with attrs separated by '\n'
4661 */
4662char* navit_item_dump(struct item *item, int pretty)
4663{
4664 char *temp_str = NULL;
4665 char *ret_value = NULL;
4666 struct attr attr;
4667 struct attr attr2;
4668 int had_flags = 0;
4669 int *f;
4670 int flags;
4671
4672 if (item == NULL)
4673 {
4674 ret_value = g_strdup_printf("");
4675 return ret_value;
4676 }
4677
4678 if (pretty == 1)
4679 {
4680 ret_value = g_strdup_printf("+*TYPE*+:%s", item_to_name(item->type));
4681 }
4682 else
4683 {
4684 ret_value = g_strdup_printf("type=%s", item_to_name(item->type));
4685 }
4686
4687 while (item_attr_get(item, attr_any, &attr))
4688 {
4689 if (attr.type == attr_flags)
4690 {
4691 had_flags = 1;
4692
4693 flags = attr.u.num;
4694 if (flags == 0)
4695 {
4696 f = item_get_default_flags(item->type);
4697 if (f)
4698 {
4699 flags = *f;
4700 }
4701 else
4702 {
4703 flags = 0;
4704 }
4705 }
4706
4707 if (pretty == 1)
4708 {
4709 temp_str = g_strdup_printf("%s\n%s=%s", ret_value, attr_to_name(attr.type), flags_to_text(flags));
4710 }
4711 else
4712 {
4713 temp_str = g_strdup_printf("%s\n%s='%s'", ret_value, attr_to_name(attr.type), flags_to_text(flags));
4714 }
4715 }
4716 else
4717 {
4718 if (pretty == 1)
4719 {
4720 temp_str = g_strdup_printf("%s\n%s=%s", ret_value, attr_to_name(attr.type), attr_to_text(&attr, NULL, 1));
4721 }
4722 else
4723 {
4724 temp_str = g_strdup_printf("%s\n%s='%s'", ret_value, attr_to_name(attr.type), attr_to_text(&attr, NULL, 1));
4725 }
4726 }
4727 g_free(ret_value);
4728 ret_value = g_strdup(temp_str);
4729 g_free(temp_str);
4730 }
4731
4732 if (had_flags == 0)
4733 {
4734 f = item_get_default_flags(item->type);
4735 if (f)
4736 {
4737 flags = *f;
4738
4739 if (pretty == 1)
4740 {
4741 temp_str = g_strdup_printf("%s\n%s=%s", ret_value, attr_to_name(attr_flags), flags_to_text(flags));
4742 }
4743 else
4744 {
4745 temp_str = g_strdup_printf("%s\n%s='%s'", ret_value, attr_to_name(attr_flags), flags_to_text(flags));
4746 }
4747
4748 g_free(ret_value);
4749 ret_value = g_strdup(temp_str);
4750 g_free(temp_str);
4751 }
4752 }
4753
4754 // g_free(item);
4755
4756 return ret_value;
4757}
4758
4759
4760int navit_normal_item(enum item_type type)
4761{
4762 if ((type > type_none)&&(type < type_waypoint))
4763 {
4764 return 1;
4765 }
4766 else if ((type >= type_poi_land_feature)&&(type <= type_poi_zoo))
4767 {
4768 return 1;
4769 }
4770 else if ((type >= type_traffic_signals)&&(type <= type_poi_cafe))
4771 {
4772 return 1;
4773 }
4774 else if ((type >= type_poi_peak)&&(type <= type_poi_ruins))
4775 {
4776 return 1;
4777 }
4778 else if ((type >= type_poi_post_box)&&(type <= type_house_number))
4779 {
4780 return 1;
4781 }
4782 else if ((type >= type_poi_playground)&&(type <= type_poi_shop_photo))
4783 {
4784 return 1;
4785 }
4786 else if (type == type_place_label)
4787 {
4788 return 1;
4789 }
4790 else if ((type >= type_line)&&(type <= type_ferry))
4791 {
4792 return 1;
4793 }
4794 else if (type == type_street_unkn)
4795 {
4796 return 1;
4797 }
4798 else if ((type >= type_aeroway_runway)&&(type <= type_footway_and_piste_nordic))
4799 {
4800 return 1;
4801 }
4802 else if ((type >= type_house_number_interpolation_even)&&(type <= type_city_wall))
4803 {
4804 return 1;
4805 }
4806 else if ((type >= type_border_city)&&(type <= type_border_county))
4807 {
4808 return 1;
4809 }
4810 else if ((type >= type_forest_way_1)&&(type <= type_forest_way_4))
4811 {
4812 return 1;
4813 }
4814 else if ((type >= type_area)&&(type <= type_poly_museum))
4815 {
4816 return 1;
4817 }
4818 else if ((type >= type_poly_commercial_center)&&(type <= type_tundra))
4819 {
4820 return 1;
4821 }
4822 else if ((type >= type_poly_building)&&(type <= type_poly_terminal))
4823 {
4824 return 1;
4825 }
4826 else if ((type >= type_poly_sports_centre)&&(type <= type_poly_aeroway_runway))
4827 {
4828 return 1;
4829 }
4830
4831 return 0;
4832}
4833
4834char* navit_find_nearest_item_dump(struct mapset *ms, struct pcoord *pc, int pretty)
4835{
4836 int max_dist = 0; // smallest rectangle possible
4837 int dist, mindist = 0, pos;
4838 int mindist_hn = 0;
4839 struct mapset_handle *h;
4840 struct map *m;
4841 struct map_rect *mr;
4842 struct item *item;
4843 struct coord lp;
4844 struct street_data *sd;
4845 struct coord c;
4846 struct coord_geo g;
4847 struct map_selection sel;
4848 struct attr street_name_attr;
4849 struct attr hn_attr;
4850 char *ret_str = NULL;
4851
4852#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4853 dbg(0,"+#+:enter\n");
4854#endif
4855
4856 mindist = 1000;
4857
4858 h = mapset_open(ms);
4859 if (!h)
4860 {
4861 // dbg(0,"return 1\n");
4862 ret_str = g_strdup_printf("");
4863 return ret_str;
4864 }
4865
4866 while ((m = mapset_next(h, 0)))
4867 {
4868 c.x = pc->x;
4869 c.y = pc->y;
4870 if (map_projection(m) != pc->pro)
4871 {
4872 transform_to_geo(pc->pro, &c, &g);
4873 transform_from_geo(map_projection(m), &g, &c);
4874 }
4875
4876 sel.next = NULL;
4877 sel.order = 18;
4878 sel.range.min = type_none;
4879 sel.range.max = type_last;
4880 sel.u.c_rect.lu.x = c.x - max_dist;
4881 sel.u.c_rect.lu.y = c.y + max_dist;
4882 sel.u.c_rect.rl.x = c.x + max_dist;
4883 sel.u.c_rect.rl.y = c.y - max_dist;
4884
4885 mr = map_rect_new(m, &sel);
4886 if (!mr)
4887 {
4888 continue;
4889 }
4890
4891 while ((item = map_rect_get_item(mr)))
4892 {
4893 if (navit_normal_item(item->type) == 1)
4894 {
4895 //dbg(0,"*type=%s\n", item_to_name(item->type));
4896
4897 struct coord c2[101];
4898 int count22 = item_coord_get(item, c2, 100);
4899 if (count22 == 0)
4900 {
4901 continue;
4902 }
4903 else if (count22 > 1)
4904 {
4905 dist = transform_distance_polyline_sq__v2(c2, count22, &c);
4906 if (dist < mindist)
4907 {
4908 mindist = dist;
4909 if (ret_str != NULL)
4910 {
4911 g_free(ret_str);
4912 }
4913 ret_str=navit_item_dump(item, pretty);
4914 }
4915 }
4916 else
4917 {
4918 dist = transform_distance_sq(&c, &c2);
4919 if (dist <= (mindist + 4))
4920 {
4921 mindist = dist;
4922 if (ret_str != NULL)
4923 {
4924 g_free(ret_str);
4925 }
4926 ret_str=navit_item_dump(item, pretty);
4927 }
4928 }
4929 // dbg(0,"*end\n");
4930 }
4931 }
4932
4933 if (mr)
4934 {
4935 map_rect_destroy(mr);
4936 }
4937 }
4938 mapset_close(h);
4939
4940 if (ret_str == NULL)
4941 {
4942 // dbg(0,"was NULL\n");
4943 ret_str = g_strdup_printf("");
4944 }
4945
4946 return ret_str;
4947}
4948
4949
4950
4951
4952
4953/**
4654 * @brief Finds the nearest street to a given coordinate 4954 * @brief Finds the nearest street to a given coordinate
4655 * 4955 *
4656 * @param ms The mapset to search in for the street 4956 * @param ms The mapset to search in for the street
4657 * @param pc The coordinate to find a street nearby [ input in pcoord(x,y) ] 4957 * @param pc The coordinate to find a street nearby [ input in pcoord(x,y) ]
4658 * @return The nearest street 4958 * @return The nearest street
4659 */ 4959 */
4660char* 4960char*
4661navit_find_nearest_street(struct mapset *ms, struct pcoord *pc) 4961navit_find_nearest_street(struct mapset *ms, struct pcoord *pc)
4662{ 4962{
4663 int max_dist = 1; // smallest rectangle possible 4963 int max_dist = 0; // smallest rectangle possible
4664 int dist, mindist = 0, pos; 4964 int dist, mindist = 0, pos;
4665 struct mapset_handle *h; 4965 struct mapset_handle *h;
4666 struct map *m; 4966 struct map *m;
4667 struct map_rect *mr; 4967 struct map_rect *mr;
4668 struct item *item; 4968 struct item *item;
4683 4983
4684 h = mapset_open(ms); 4984 h = mapset_open(ms);
4685 4985
4686 if (!h) 4986 if (!h)
4687 { 4987 {
4988 // set global value :-(
4989 dist_to_street = mindist;
4688 return street_name; 4990 return street_name;
4689 } 4991 }
4690 4992
4691 while ((m = mapset_next(h, 0))) 4993 while ((m = mapset_next(h, 0)))
4692 { 4994 {
4722 { 5024 {
4723 continue; 5025 continue;
4724 } 5026 }
4725 //dbg(0,"6 sd x:%d sd y:%d count:%d\n", sd->c->x, sd->c->y, sd->count); 5027 //dbg(0,"6 sd x:%d sd y:%d count:%d\n", sd->c->x, sd->c->y, sd->count);
4726 //dbg(0,"6 c x:%d c y:%d\n", c.x, c.y); 5028 //dbg(0,"6 c x:%d c y:%d\n", c.x, c.y);
4727 dist = transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos); 5029 dist = transform_distance_polyline_sq__v2(sd->c, sd->count, &c);
4728 //dbg(0,"mindist:%d dist:%d\n", mindist, dist); 5030 //dbg(0,"mindist:%d dist:%d\n", mindist, dist);
4729 if (dist < mindist) 5031 if (dist < mindist)
4730 { 5032 {
4731 //dbg(0,"6.a\n"); 5033 //dbg(0,"6.a\n");
4732 mindist = dist; 5034 mindist = dist;
4733 5035
5036 if (item_attr_get(item, attr_street_name, &street_name_attr))
5037 {
5038 if (street_name)
5039 {
5040 g_free(street_name);
5041 street_name = NULL;
5042 }
5043 street_name = g_strdup_printf("%s", street_name_attr.u.str);
5044 //dbg(0,"r3 %s\n", street_name);
5045 }
4734 if (item_attr_get(item, attr_label, &street_name_attr)) 5046 else if (item_attr_get(item, attr_label, &street_name_attr))
4735 { 5047 {
4736 if (street_name) 5048 if (street_name)
4737 { 5049 {
4738 g_free(street_name); 5050 g_free(street_name);
4739 street_name = NULL; 5051 street_name = NULL;
4740 } 5052 }
4741 street_name = g_strdup_printf("%s", street_name_attr.u.str); 5053 street_name = g_strdup_printf("%s", street_name_attr.u.str);
4742 //dbg(0,"r1 %s\n", street_name); 5054 //dbg(0,"r1 %s\n", street_name);
4743 }
4744 /*
4745 else if (item_attr_get(&sd->item, attr_street_name, &street_name_attr))
4746 {
4747 if (street_name)
4748 {
4749 dbg(0,"6.b\n");
4750 g_free(street_name);
4751 street_name = NULL;
4752 dbg(0,"6.c\n");
4753 }
4754 street_name = g_strdup_printf("%s", street_name_attr.u.str);
4755 dbg(0,"r2 %s\n", street_name);
4756 }
4757 */
4758 else if (item_attr_get(item, attr_street_name, &street_name_attr))
4759 {
4760 if (street_name)
4761 {
4762 g_free(street_name);
4763 street_name = NULL;
4764 }
4765 street_name = g_strdup_printf("%s", street_name_attr.u.str);
4766 //dbg(0,"r3 %s\n", street_name);
4767 } 5055 }
4768 else if (item_attr_get(item, attr_street_name_systematic, &street_name_attr)) 5056 else if (item_attr_get(item, attr_street_name_systematic, &street_name_attr))
4769 { 5057 {
4770 if (street_name) 5058 if (street_name)
4771 { 5059 {
4793 { 5081 {
4794 map_rect_destroy(mr); 5082 map_rect_destroy(mr);
4795 } 5083 }
4796 } 5084 }
4797 mapset_close(h); 5085 mapset_close(h);
5086 // set global value :-(
5087 dist_to_street = mindist;
5088 return street_name;
5089}
5090
5091
5092
5093/**
5094 * @brief Finds the nearest street or housenumber to a given coordinate
5095 *
5096 * @param ms The mapset to search in for the street
5097 * @param pc The coordinate to find a street nearby [ input in pcoord(x,y) ]
5098 * @return The nearest street or housenumber
5099 */
5100char*
5101navit_find_nearest_street_hn(struct mapset *ms, struct pcoord *pc)
5102{
5103 int max_dist = 0; // smallest rectangle possible
5104 int dist, mindist = 0, pos;
5105 int mindist_hn = 0;
5106 struct mapset_handle *h;
5107 struct map *m;
5108 struct map_rect *mr;
5109 struct item *item;
5110 struct coord lp;
5111 struct street_data *sd;
5112 struct coord c;
5113 struct coord_geo g;
5114 struct map_selection sel;
5115 struct attr street_name_attr;
5116 struct attr hn_attr;
5117 char *street_name = NULL;
5118 char *street_name_saved = NULL;
5119
5120#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
5121 dbg(0,"+#+:enter\n");
5122#endif
5123
5124 // first find a street
5125 street_name_saved = navit_find_nearest_street(ms, pc);
5126 // street_name = g_strdup_printf(" ");
5127 street_name = g_strdup(street_name_saved);
5128 // first find a street
5129
5130 mindist = dist_to_street; // start with small radius at the beginning! (only use housenumber of different street, if we are really close to it!!)
5131 // global value -> this is naughty :-)
5132
5133 if (mindist < 8)
5134 {
5135 // so we can find other housenumbers if we are very close
5136 mindist = 8;
5137 }
5138
5139 mindist_hn = 10000;
5140
5141 //dbg(0,"given streetname %s %s dist %d\n", street_name, street_name_saved, dist_to_street);
5142
5143
5144 h = mapset_open(ms);
5145
5146 if (!h)
5147 {
5148 if (street_name_saved)
5149 {
5150 g_free(street_name_saved);
5151 street_name_saved = NULL;
5152 }
5153 return street_name;
5154 }
5155
5156 while ((m = mapset_next(h, 0)))
5157 {
5158 c.x = pc->x;
5159 c.y = pc->y;
5160 if (map_projection(m) != pc->pro)
5161 {
5162 transform_to_geo(pc->pro, &c, &g);
5163 transform_from_geo(map_projection(m), &g, &c);
5164 }
5165
5166 sel.next = NULL;
5167 sel.order = 18;
5168 sel.range.min = type_none;
5169 sel.range.max = type_area;
5170 sel.u.c_rect.lu.x = c.x - max_dist;
5171 sel.u.c_rect.lu.y = c.y + max_dist;
5172 sel.u.c_rect.rl.x = c.x + max_dist;
5173 sel.u.c_rect.rl.y = c.y - max_dist;
5174
5175 mr = map_rect_new(m, &sel);
5176 if (!mr)
5177 {
5178 continue;
5179 }
5180
5181 while ((item = map_rect_get_item(mr)))
5182 {
5183 if (item->type == type_house_number)
5184 {
5185 //dbg(0,"hn found\n");
5186 struct coord c2;
5187 int rrr = item_coord_get(item, &c2, 1);
5188 if (rrr)
5189 {
5190 dist = transform_distance_sq(&c, &c2);
5191 //dbg(0,"dist=%d\n", dist);
5192 if (dist < mindist)
5193 {
5194 if (item_attr_get(item, attr_street_name, &street_name_attr))
5195 {
5196 if (item_attr_get(item, attr_house_number, &hn_attr))
5197 {
5198 if (street_name)
5199 {
5200 g_free(street_name);
5201 street_name = NULL;
5202 }
5203 street_name = g_strdup_printf("%s %s", street_name_attr.u.str, hn_attr.u.str);
5204 //dbg(0,"sn 1\n");
5205 mindist = dist;
5206 mindist_hn = dist;
5207 }
5208 }
5209 }
5210 // else try to find housenumbers for our current street
5211 // just take the nearest housenumber for our current street
5212 else if (dist < mindist_hn)
5213 {
5214 //dbg(0,"sn 2.1\n");
5215 if (item_attr_get(item, attr_street_name, &street_name_attr))
5216 {
5217 //dbg(0,"sn 2.2\n");
5218 if (item_attr_get(item, attr_house_number, &hn_attr))
5219 {
5220 //dbg(0,"sn 2.3\n");
5221 if ((street_name != NULL) && (street_name_saved != NULL))
5222 {
5223 // dbg(0,"sn 2.4 -%s- -%s-\n", street_name_saved, street_name_attr.u.str);
5224 if (!strcmp(street_name_saved, street_name_attr.u.str))
5225 {
5226 g_free(street_name);
5227 street_name = NULL;
5228
5229 // dbg(0,"sn 2.99\n");
5230
5231 street_name = g_strdup_printf("%s %s", street_name_attr.u.str, hn_attr.u.str);
5232 mindist_hn = dist;
5233 }
5234 }
5235 }
5236 }
5237 }
5238 }
5239 }
5240
5241
5242#if 0
5243 //else if (item->type > type_line)
5244 if (1 == 0) // DISABLED !!!!!!
5245 {
5246 if (item_get_default_flags(item->type))
5247 {
5248 sd = street_get_data(item);
5249 if (!sd)
5250 {
5251 continue;
5252 }
5253 dist = transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos);
5254 if (dist < mindist)
5255 {
5256 mindist = dist;
5257
5258 if (item_attr_get(item, attr_label, &street_name_attr))
5259 {
5260 if (street_name)
5261 {
5262 g_free(street_name);
5263 street_name = NULL;
5264 }
5265 if (street_name_saved)
5266 {
5267 g_free(street_name_saved);
5268 street_name_saved = NULL;
5269 }
5270 street_name = g_strdup_printf("%s", street_name_attr.u.str);
5271 street_name_saved = g_strdup(street_name);
5272 }
5273 else if (item_attr_get(item, attr_street_name, &street_name_attr))
5274 {
5275 if (street_name)
5276 {
5277 g_free(street_name);
5278 street_name = NULL;
5279 }
5280 if (street_name_saved)
5281 {
5282 g_free(street_name_saved);
5283 street_name_saved = NULL;
5284 }
5285 street_name = g_strdup_printf("%s", street_name_attr.u.str);
5286 street_name_saved = g_strdup(street_name);
5287 }
5288 else if (item_attr_get(item, attr_street_name_systematic, &street_name_attr))
5289 {
5290 if (street_name)
5291 {
5292 g_free(street_name);
5293 street_name = NULL;
5294 }
5295 if (street_name_saved)
5296 {
5297 g_free(street_name_saved);
5298 street_name_saved = NULL;
5299 }
5300 street_name = g_strdup_printf("%s", street_name_attr.u.str);
5301 street_name_saved = g_strdup(street_name);
5302 }
5303 }
5304 street_data_free(sd);
5305 }
5306 }
5307#endif
5308 }
5309
5310 if (mr)
5311 {
5312 map_rect_destroy(mr);
5313 }
5314 }
5315
5316 if (street_name_saved)
5317 {
5318 g_free(street_name_saved);
5319 street_name_saved = NULL;
5320 }
5321
5322 mapset_close(h);
4798 return street_name; 5323 return street_name;
4799} 5324}
4800 5325
4801 5326
4802/** 5327/**
4807 * @return The nearest street (as a string of coords "0xFFF 0xFFF\n..." seperated by "\n") 5332 * @return The nearest street (as a string of coords "0xFFF 0xFFF\n..." seperated by "\n")
4808 */ 5333 */
4809char* 5334char*
4810navit_find_nearest_street_coords(struct mapset *ms, struct pcoord *pc) 5335navit_find_nearest_street_coords(struct mapset *ms, struct pcoord *pc)
4811{ 5336{
4812 int max_dist = 1; // smallest rectangle possible 5337 int max_dist = 0; // smallest rectangle possible
4813 int dist, mindist = 0, pos; 5338 int dist, mindist = 0, pos;
4814 struct mapset_handle *h; 5339 struct mapset_handle *h;
4815 struct map *m; 5340 struct map *m;
4816 struct map_rect *mr; 5341 struct map_rect *mr;
4817 struct item *item; 5342 struct item *item;
4874 if (!sd) 5399 if (!sd)
4875 { 5400 {
4876 continue; 5401 continue;
4877 } 5402 }
4878 found_good = 0; 5403 found_good = 0;
4879 dist = transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos); 5404 // OLD // dist = transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos);
5405 dist = transform_distance_polyline_sq__v2(sd->c, sd->count, &c);
4880 if (dist < mindist) 5406 if (dist < mindist)
4881 { 5407 {
4882 mindist = dist; 5408 mindist = dist;
4883 5409
4884 /* 5410 /*

Legend:
Removed from v.28  
changed lines
  Added in v.29

   
Visit the ZANavi Wiki