2 * Copyright (C) 2006, 2007 John Costigan.
4 * POI and GPS-Info code originally written by Cezary Jackiewicz.
6 * Default map data provided by http://www.openstreetmap.org/
8 * This file is part of Maemo Mapper.
10 * Maemo Mapper is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * Maemo Mapper is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Maemo Mapper. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef MAEMO_MAPPER_DEFINES
25 #define MAEMO_MAPPER_DEFINES
29 #define _(String) gettext(String)
35 /* Set the below if to determine whether to get verbose output. */
37 #define vprintf printf
42 #define BOUND(x, a, b) { \
49 #define PI (3.14159265358979323846)
51 #define EARTH_RADIUS (3443.91847)
53 /** MAX_ZOOM defines the largest map zoom level we will download.
54 * (MAX_ZOOM - 1) is the largest map zoom level that the user can zoom to.
59 #define TILE_SIZE_PIXELS (256)
60 #define TILE_HALFDIAG_PIXELS (181)
61 #define TILE_SIZE_P2 (8)
63 #define ARRAY_CHUNK_SIZE (1024)
65 #define BUFFER_SIZE (2048)
67 #define GPSD_PORT_DEFAULT (2947)
69 #define NUM_DOWNLOAD_THREADS (4)
70 #define MAX_PIXBUF_DUP_SIZE (137)
71 #define WORLD_SIZE_UNITS (2 << (MAX_ZOOM + TILE_SIZE_P2))
73 #define HOURGLASS_SEPARATION (7)
75 #define deg2rad(deg) ((deg) * (PI / 180.0))
76 #define rad2deg(rad) ((rad) * (180.0 / PI))
78 #define tile2pixel(TILE) ((TILE) << TILE_SIZE_P2)
79 #define pixel2tile(PIXEL) ((PIXEL) >> TILE_SIZE_P2)
80 #define tile2unit(TILE) ((TILE) << (TILE_SIZE_P2 + _zoom))
81 #define unit2tile(unit) ((unit) >> (TILE_SIZE_P2 + _zoom))
82 #define tile2zunit(TILE, ZOOM) ((TILE) << (TILE_SIZE_P2 + (ZOOM)))
83 #define unit2ztile(unit, ZOOM) ((unit) >> (TILE_SIZE_P2 + (ZOOM)))
85 #define pixel2unit(PIXEL) ((PIXEL) << _zoom)
86 #define unit2pixel(PIXEL) ((PIXEL) >> _zoom)
87 #define pixel2zunit(PIXEL, ZOOM) ((PIXEL) << (ZOOM))
88 #define unit2zpixel(PIXEL, ZOOM) ((PIXEL) >> (ZOOM))
90 #define unit2buf_full(UNITX, UNITY, BUFX, BUFY, CENTER, MATRIX) { \
91 gfloat fdevx, fdevy; \
92 gdk_pixbuf_rotate_vector(&fdevx, &fdevy, (MATRIX), \
93 (gint)((UNITX) - (CENTER).unitx), \
94 (gint)((UNITY) - (CENTER).unity)); \
95 (BUFX) = unit2pixel((gint)(fdevx)) + _view_halfwidth_pixels; \
96 (BUFY) = unit2pixel((gint)(fdevy)) + _view_halfheight_pixels; \
99 #define unit2buf(UNITX, UNITY, BUFX, BUFY) \
100 (unit2buf_full(UNITX, UNITY, BUFX, BUFY, _center, _map_rotate_matrix))
102 #define pixel2buf_full(PIXELX, PIXELY, BUFX, BUFY, CENTER, ZOOM, MATRIX) { \
103 gfloat fdevx, fdevy; \
104 gdk_pixbuf_rotate_vector(&fdevx, &fdevy, MATRIX, \
105 (gint)((PIXELX) - unit2zpixel((CENTER).unitx, (ZOOM))), \
106 (gint)((PIXELY) - unit2zpixel((CENTER).unity, (ZOOM)))); \
107 (BUFX) = fdevx + _view_halfwidth_pixels; \
108 (BUFY) = fdevy + _view_halfheight_pixels; \
111 #define pixel2buf(PIXELX, PIXELY, BUFX, BUFY) \
112 (pixel2buf_full(PIXELX, PIXELY, BUFX, BUFY, _center, _zoom, \
116 #define unit2screen_full(UNITX, UNITY, SCREENX, SCREENY, CENTER, MATRIX) { \
117 unit2buf_full(UNITX, UNITY, SCREENX, SCREENY, CENTER, MATRIX); \
118 (SCREENX) = (SCREENX) + _map_offset_devx; \
119 (SCREENY) = (SCREENY) + _map_offset_devy; \
122 #define unit2screen(UNITX, UNITY, SCREENX, SCREENY) \
123 (unit2screen_full(UNITX, UNITY, SCREENX, SCREENY, _center, \
126 #define pixel2screen_full(PIXELX, PIXELY, SCREENX, SCREENY, CENTER, MATRIX) { \
127 pixel2buf_full(PIXELX, PIXELY, SCREENX, SCREENY, CENTER, ZOOM, MATRIX); \
128 (SCREENX) = (SCREENX) + _map_offset_devx; \
129 (SCREENY) = (SCREENY) + _map_offset_devy; \
132 #define pixel2screen(PIXELX, PIXELY, SCREENX, SCREENY) \
133 (pixel2screen_full(PIXELX, PIXELY, SCREENX, SCREENY, _center, \
136 #define buf2unit_full(BUFX, BUFY, UNITX, UNITY, CENTER, MATRIX) { \
137 gfloat funitx, funity; \
138 gdk_pixbuf_rotate_vector(&funitx, &funity, MATRIX, \
139 pixel2unit((gint)((BUFX) - _view_halfwidth_pixels)), \
140 pixel2unit((gint)((BUFY) - _view_halfheight_pixels))); \
141 (UNITX) = (CENTER).unitx + (gint)funitx; \
142 (UNITY) = (CENTER).unity + (gint)funity; \
145 #define buf2unit(BUFX, BUFY, UNITX, UNITY) \
146 (buf2unit_full(BUFX, BUFY, UNITX, UNITY, _center, _map_reverse_matrix))
148 #define buf2pixel_full(BUFX, BUFY, PIXELX, PIXELY, CENTER, MATRIX) { \
149 gfloat fpixelx, fpixely; \
150 gdk_pixbuf_rotate_vector(&fpixelx, &fpixely, MATRIX, \
151 (gint)(BUFX) - _view_halfwidth_pixels, \
152 (gint)(BUFY) - _view_halfheight_pixels); \
153 (PIXELX) = unit2pixel((CENTER).unitx) + (gint)fpixelx; \
154 (PIXELY) = unit2pixel((CENTER).unity) + (gint)fpixely; \
157 #define buf2pixel(BUFX, BUFY, PIXELX, PIXELY) \
158 (buf2pixel_full(BUFX, BUFY, PIXELX, PIXELY, _center, _map_reverse_matrix))
160 #define screen2unit_full(SCREENX, SCREENY, UNITX, UNITY, CENTER, MATRIX) ( \
161 buf2unit_full((SCREENX) - _map_offset_devx, (SCREENY) - _map_offset_devy, \
162 UNITX, UNITY, CENTER, MATRIX))
164 #define screen2unit(SCREENX, SCREENY, UNITX, UNITY) \
165 (screen2unit_full(SCREENX, SCREENY, UNITX, UNITY, _center, \
166 _map_reverse_matrix))
168 #define screen2pixel_full(SCREENX, SCREENY, PIXELX, PIXELY, CENTER, MATRIX) ( \
169 buf2pixel_full((SCREENX) - _map_offset_devx, (SCREENY) - _map_offset_devy,\
170 PIXELX, PIXELY, CENTER, MATRIX))
172 #define screen2pixel(SCREENX, SCREENY, PIXELX, PIXELY) ( \
173 screen2pixel_full(SCREENX, SCREENY, PIXELX, PIXELY, \
174 _center,_map_reverse_matrix))
176 /* Pans are done 64 pixels at a time. */
177 #define PAN_PIXELS (64)
178 #define ROTATE_DEGREES (30)
180 #define INITIAL_DOWNLOAD_RETRIES (3)
182 #define CONFIG_DIR_NAME "~/.maemo-mapper/"
183 #define CONFIG_PATH_DB_FILE "paths.db"
185 #define REPO_DEFAULT_NAME "OpenStreet"
186 #define REPO_DEFAULT_CACHE_BASE "~/MyDocs/.documents/Maps/"
187 #define REPO_DEFAULT_CACHE_DIR REPO_DEFAULT_CACHE_BASE"OpenStreet.db"
188 #define REPO_DEFAULT_MAP_URI "http://tile.openstreetmap.org/%0d/%d/%d.png"
189 #define REPO_DEFAULT_DL_ZOOM_STEPS (2)
190 #define REPO_DEFAULT_VIEW_ZOOM_STEPS (1)
191 #define REPO_DEFAULT_MIN_ZOOM (4)
192 #define REPO_DEFAULT_MAX_ZOOM (20)
194 #define XML_DATE_FORMAT "%FT%T"
196 #define HELP_ID_PREFIX "help_maemomapper_"
197 #define HELP_ID_INTRO HELP_ID_PREFIX"intro"
198 #define HELP_ID_GETSTARTED HELP_ID_PREFIX"getstarted"
199 #define HELP_ID_ABOUT HELP_ID_PREFIX"about"
200 #define HELP_ID_SETTINGS HELP_ID_PREFIX"settings"
201 #define HELP_ID_REPOMAN HELP_ID_PREFIX"repoman"
202 #define HELP_ID_MAPMAN HELP_ID_PREFIX"mapman"
203 #define HELP_ID_DOWNROUTE HELP_ID_PREFIX"downroute"
204 #define HELP_ID_DOWNPOI HELP_ID_PREFIX"downpoi"
205 #define HELP_ID_BROWSEPOI HELP_ID_PREFIX"browsepoi"
206 #define HELP_ID_POILIST HELP_ID_PREFIX"poilist"
207 #define HELP_ID_POICAT HELP_ID_PREFIX"poicat"
209 #define MERCATOR_SPAN (-6.28318377773622)
210 #define MERCATOR_TOP (3.14159188886811)
211 #define latlon2unit(lat, lon, unitx, unity) { \
213 unitx = (lon + 180.0) * (WORLD_SIZE_UNITS / 360.0) + 0.5; \
214 tmp = sin(deg2rad(lat)); \
215 unity = 0.5 + (WORLD_SIZE_UNITS / MERCATOR_SPAN) \
216 * (log((1.0 + tmp) / (1.0 - tmp)) * 0.5 - MERCATOR_TOP); \
219 #define unit2latlon(unitx, unity, lat, lon) { \
220 (lon) = ((unitx) * (360.0 / WORLD_SIZE_UNITS)) - 180.0; \
221 (lat) = (360.0 * (atan(exp(((unity) * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) \
222 + MERCATOR_TOP)))) * (1.0 / PI) - 90.0; \
225 #define MACRO_PATH_INIT(path) { \
226 (path).head = (path).tail = g_new(Point, ARRAY_CHUNK_SIZE); \
227 *((path).tail) = _point_null; \
228 (path).cap = (path).head + ARRAY_CHUNK_SIZE; \
229 (path).whead = g_new(WayPoint, ARRAY_CHUNK_SIZE); \
230 (path).wtail = (path).whead - 1; \
231 (path).wcap = (path).whead + ARRAY_CHUNK_SIZE; \
234 #define MACRO_PATH_FREE(path) if((path).head) { \
236 g_free((path).head); \
237 (path).head = (path).tail = (path).cap = NULL; \
238 for(curr = (path).whead - 1; curr++ != (path).wtail; ) \
239 g_free(curr->desc); \
240 g_free((path).whead); \
241 (path).whead = (path).wtail = (path).wcap = NULL; \
244 #define MACRO_PATH_INCREMENT_TAIL(route) { \
245 if(++(route).tail == (route).cap) \
246 path_resize(&(route), (route).cap - (route).head + ARRAY_CHUNK_SIZE);\
249 #define MACRO_PATH_INCREMENT_WTAIL(route) { \
250 if(++(route).wtail == (route).wcap) \
251 path_wresize(&(route), \
252 (route).wcap - (route).whead + ARRAY_CHUNK_SIZE); \
255 #define DISTANCE_SQUARED(a, b) \
256 ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\
257 + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity)))
259 #define MACRO_QUEUE_DRAW_AREA() \
260 gtk_widget_queue_draw_area( \
263 _view_width_pixels, \
266 /* Render all on-map metadata an annotations, including POI and paths. */
267 #define MACRO_MAP_RENDER_DATA() { \
270 if(_show_paths > 0) \
271 map_render_paths(); \
274 #define UNBLANK_SCREEN(MOVING, APPROACHING_WAYPOINT) { \
275 /* Check if we need to unblank the screen. */ \
276 switch(_unblank_option) \
278 case UNBLANK_NEVER: \
280 case UNBLANK_WAYPOINT: \
281 if(APPROACHING_WAYPOINT) \
283 printf("Unblanking screen...\n"); \
284 osso_display_state_on(_osso); \
285 osso_display_blanking_pause(_osso); \
289 case UNBLANK_FULLSCREEN: \
292 case UNBLANK_WHEN_MOVING: \
295 case UNBLANK_WITH_GPS: \
296 printf("Unblanking screen...\n"); \
297 osso_display_state_on(_osso); \
298 osso_display_blanking_pause(_osso); \
302 #define LL_FMT_LEN 20
303 #define lat_format(A, B) deg_format((A), (B), 'S', 'N')
304 #define lon_format(A, B) deg_format((A), (B), 'W', 'E')
306 #define TRACKS_MASK 0x00000001
307 #define ROUTES_MASK 0x00000002
309 #define MACRO_BANNER_SHOW_INFO(A, S) { \
310 gchar *my_macro_buffer = g_markup_printf_escaped( \
311 "<span size='%s'>%s</span>", \
312 INFO_FONT_ENUM_TEXT[_info_font_size], (S)); \
313 hildon_banner_show_information_with_markup(A, NULL, my_macro_buffer); \
314 g_free(my_macro_buffer); \
317 #endif /* ifndef MAEMO_MAPPER_DEFINES */