]> git.itanic.dy.fi Git - maemo-mapper/blob - src/defines.h
42fd470f6d3ee023690835536a457ed4a5af22e8
[maemo-mapper] / src / defines.h
1 /*
2  * Copyright (C) 2006, 2007 John Costigan.
3  *
4  * POI and GPS-Info code originally written by Cezary Jackiewicz.
5  *
6  * Default map data provided by http://www.openstreetmap.org/
7  *
8  * This file is part of Maemo Mapper.
9  *
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.
14  *
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.
19  *
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/>.
22  */
23
24 #ifndef MAEMO_MAPPER_DEFINES
25 #define MAEMO_MAPPER_DEFINES
26
27 #include <libintl.h>
28
29 #define _(String) gettext(String)
30
31 #ifndef DEBUG
32 #define printf(...)
33 #endif
34
35 /* Set the below if to determine whether to get verbose output. */
36 #if 1
37 #define vprintf printf
38 #else
39 #define vprintf(...)
40 #endif
41
42 #define BOUND(x, a, b) { \
43     if((x) < (a)) \
44         (x) = (a); \
45     else if((x) > (b)) \
46         (x) = (b); \
47 }
48
49 #define PI   (3.14159265358979323846)
50
51 #define EARTH_RADIUS (3443.91847)
52
53 /* BT dbus service location */
54 #define BASE_PATH                "/org/bluez"
55 #define BASE_INTERFACE           "org.bluez"
56 //#define ADAPTER_PATH             BASE_PATH
57 #define ADAPTER_INTERFACE        BASE_INTERFACE ".Adapter"
58 #define MANAGER_PATH             BASE_PATH
59 #define MANAGER_INTERFACE        BASE_INTERFACE ".Manager"
60 #define ERROR_INTERFACE          BASE_INTERFACE ".Error"
61 #define SECURITY_INTERFACE       BASE_INTERFACE ".Security"
62 #define RFCOMM_INTERFACE         BASE_INTERFACE ".RFCOMM"
63 #define BLUEZ_DBUS               BASE_INTERFACE
64
65 #define LIST_ADAPTERS            "ListAdapters"
66 #define LIST_BONDINGS            "ListBondings"
67 //#define CREATE_BONDING           "CreateBonding"
68 #define GET_REMOTE_NAME          "GetRemoteName"
69 #define GET_REMOTE_SERVICE_CLASSES "GetRemoteServiceClasses"
70
71 #define BTCOND_PATH              "/com/nokia/btcond/request"
72 #define BTCOND_BASE              "com.nokia.btcond"
73 #define BTCOND_INTERFACE         BTCOND_BASE ".request"
74 #define BTCOND_REQUEST           BTCOND_INTERFACE
75 #define BTCOND_CONNECT           "rfcomm_connect"
76 #define BTCOND_DISCONNECT        "rfcomm_disconnect"
77 #define BTCOND_DBUS              BTCOND_BASE
78
79
80 /** MAX_ZOOM defines the largest map zoom level we will download.
81  * (MAX_ZOOM - 1) is the largest map zoom level that the user can zoom to.
82  */
83 #define MIN_ZOOM (0)
84 #define MAX_ZOOM (20)
85
86 #define TILE_SIZE_PIXELS (256)
87 #define TILE_HALFDIAG_PIXELS (181)
88 #define TILE_SIZE_P2 (8)
89
90 #define ARRAY_CHUNK_SIZE (1024)
91
92 #define BUFFER_SIZE (2048)
93 #define APRS_BUFFER_SIZE (4096)
94 #define APRS_MAX_COMMENT  80
95 #define APRS_CONVERSE_MODE "k"
96
97 #define GPSD_PORT_DEFAULT (2947)
98
99 #define NUM_DOWNLOAD_THREADS (4)
100 #define MAX_PIXBUF_DUP_SIZE (137)
101 #define WORLD_SIZE_UNITS (2 << (MAX_ZOOM + TILE_SIZE_P2))
102
103 #define HOURGLASS_SEPARATION (7)
104
105 #define deg2rad(deg) ((deg) * (PI / 180.0))
106 #define rad2deg(rad) ((rad) * (180.0 / PI))
107
108 #define tile2pixel(TILE) ((TILE) << TILE_SIZE_P2)
109 #define pixel2tile(PIXEL) ((PIXEL) >> TILE_SIZE_P2)
110 #define tile2unit(TILE) ((TILE) << (TILE_SIZE_P2 + _zoom))
111 #define unit2tile(unit) ((unit) >> (TILE_SIZE_P2 + _zoom))
112 #define tile2zunit(TILE, ZOOM) ((TILE) << (TILE_SIZE_P2 + (ZOOM)))
113 #define unit2ztile(unit, ZOOM) ((unit) >> (TILE_SIZE_P2 + (ZOOM)))
114
115 #define pixel2unit(PIXEL) ((PIXEL) << _zoom)
116 #define unit2pixel(PIXEL) ((PIXEL) >> _zoom)
117 #define pixel2zunit(PIXEL, ZOOM) ((PIXEL) << (ZOOM))
118 #define unit2zpixel(PIXEL, ZOOM) ((PIXEL) >> (ZOOM))
119
120 #define unit2buf_full(UNITX, UNITY, BUFX, BUFY, CENTER, MATRIX) { \
121     gfloat fdevx, fdevy; \
122     gdk_pixbuf_rotate_vector(&fdevx, &fdevy, (MATRIX), \
123             (gint)((UNITX) - (CENTER).unitx), \
124             (gint)((UNITY) - (CENTER).unity)); \
125     (BUFX) = unit2pixel((gint)(fdevx)) + _view_halfwidth_pixels; \
126     (BUFY) = unit2pixel((gint)(fdevy)) + _view_halfheight_pixels; \
127 }
128
129 #define unit2buf(UNITX, UNITY, BUFX, BUFY) \
130     (unit2buf_full(UNITX, UNITY, BUFX, BUFY, _center, _map_rotate_matrix))
131
132 #define pixel2buf_full(PIXELX, PIXELY, BUFX, BUFY, CENTER, ZOOM, MATRIX) { \
133     gfloat fdevx, fdevy; \
134     gdk_pixbuf_rotate_vector(&fdevx, &fdevy, MATRIX, \
135             (gint)((PIXELX) - unit2zpixel((CENTER).unitx, (ZOOM))), \
136             (gint)((PIXELY) - unit2zpixel((CENTER).unity, (ZOOM)))); \
137     (BUFX) = fdevx + _view_halfwidth_pixels; \
138     (BUFY) = fdevy + _view_halfheight_pixels; \
139 }
140
141 #define pixel2buf(PIXELX, PIXELY, BUFX, BUFY) \
142     (pixel2buf_full(PIXELX, PIXELY, BUFX, BUFY, _center, _zoom, \
143                     _map_rotate_matrix))
144
145
146 #define unit2screen_full(UNITX, UNITY, SCREENX, SCREENY, CENTER, MATRIX) { \
147     unit2buf_full(UNITX, UNITY, SCREENX, SCREENY, CENTER, MATRIX); \
148     (SCREENX) = (SCREENX) + _map_offset_devx; \
149     (SCREENY) = (SCREENY) + _map_offset_devy; \
150 }
151
152 #define unit2screen(UNITX, UNITY, SCREENX, SCREENY) \
153     (unit2screen_full(UNITX, UNITY, SCREENX, SCREENY, _center, \
154                       _map_rotate_matrix))
155
156 #define pixel2screen_full(PIXELX, PIXELY, SCREENX, SCREENY, CENTER, MATRIX) { \
157     pixel2buf_full(PIXELX, PIXELY, SCREENX, SCREENY, CENTER, ZOOM, MATRIX); \
158     (SCREENX) = (SCREENX) + _map_offset_devx; \
159     (SCREENY) = (SCREENY) + _map_offset_devy; \
160 }
161
162 #define pixel2screen(PIXELX, PIXELY, SCREENX, SCREENY) \
163     (pixel2screen_full(PIXELX, PIXELY, SCREENX, SCREENY, _center, \
164                        _map_rotate_matrix))
165
166 #define buf2unit_full(BUFX, BUFY, UNITX, UNITY, CENTER, MATRIX) { \
167     gfloat funitx, funity; \
168     gdk_pixbuf_rotate_vector(&funitx, &funity, MATRIX, \
169             pixel2unit((gint)((BUFX) - _view_halfwidth_pixels)), \
170             pixel2unit((gint)((BUFY) - _view_halfheight_pixels))); \
171     (UNITX) = (CENTER).unitx + (gint)funitx; \
172     (UNITY) = (CENTER).unity + (gint)funity; \
173 }
174
175 #define buf2unit(BUFX, BUFY, UNITX, UNITY) \
176     (buf2unit_full(BUFX, BUFY, UNITX, UNITY, _center, _map_reverse_matrix))
177
178 #define buf2pixel_full(BUFX, BUFY, PIXELX, PIXELY, CENTER, MATRIX) { \
179     gfloat fpixelx, fpixely; \
180     gdk_pixbuf_rotate_vector(&fpixelx, &fpixely, MATRIX, \
181             (gint)(BUFX) - _view_halfwidth_pixels, \
182             (gint)(BUFY) - _view_halfheight_pixels); \
183     (PIXELX) = unit2pixel((CENTER).unitx) + (gint)fpixelx; \
184     (PIXELY) = unit2pixel((CENTER).unity) + (gint)fpixely; \
185 }
186
187 #define buf2pixel(BUFX, BUFY, PIXELX, PIXELY) \
188     (buf2pixel_full(BUFX, BUFY, PIXELX, PIXELY, _center, _map_reverse_matrix))
189
190 #define screen2unit_full(SCREENX, SCREENY, UNITX, UNITY, CENTER, MATRIX) ( \
191     buf2unit_full((SCREENX) - _map_offset_devx, (SCREENY) - _map_offset_devy, \
192         UNITX, UNITY, CENTER, MATRIX))
193
194 #define screen2unit(SCREENX, SCREENY, UNITX, UNITY) \
195     (screen2unit_full(SCREENX, SCREENY, UNITX, UNITY, _center, \
196                       _map_reverse_matrix))
197
198 #define screen2pixel_full(SCREENX, SCREENY, PIXELX, PIXELY, CENTER, MATRIX) ( \
199     buf2pixel_full((SCREENX) - _map_offset_devx, (SCREENY) - _map_offset_devy,\
200         PIXELX, PIXELY, CENTER, MATRIX))
201
202 #define screen2pixel(SCREENX, SCREENY, PIXELX, PIXELY) ( \
203     screen2pixel_full(SCREENX, SCREENY, PIXELX, PIXELY, \
204         _center,_map_reverse_matrix))
205
206 /* Pans are done 64 pixels at a time. */
207 #define PAN_PIXELS (64)
208 #define ROTATE_DEGREES (30)
209
210 #define INITIAL_DOWNLOAD_RETRIES (3)
211
212 #define CONFIG_DIR_NAME "~/.maemo-mapper/"
213 #define CONFIG_PATH_DB_FILE "paths.db"
214
215 #define REPO_DEFAULT_NAME "OpenStreet"
216 #define REPO_DEFAULT_CACHE_BASE "~/MyDocs/.documents/Maps/"
217 #define REPO_DEFAULT_CACHE_DIR REPO_DEFAULT_CACHE_BASE"OpenStreet.db"
218 #define REPO_DEFAULT_MAP_URI "http://tile.openstreetmap.org/%0d/%d/%d.png"
219 #define REPO_DEFAULT_DL_ZOOM_STEPS (2)
220 #define REPO_DEFAULT_VIEW_ZOOM_STEPS (1)
221 #define REPO_DEFAULT_MIN_ZOOM (4)
222 #define REPO_DEFAULT_MAX_ZOOM (20)
223
224 #define XML_DATE_FORMAT "%FT%T"
225
226 #define HELP_ID_PREFIX "help_maemomapper_"
227 #define HELP_ID_INTRO HELP_ID_PREFIX"intro"
228 #define HELP_ID_GETSTARTED HELP_ID_PREFIX"getstarted"
229 #define HELP_ID_ABOUT HELP_ID_PREFIX"about"
230 #define HELP_ID_SETTINGS HELP_ID_PREFIX"settings"
231 #define HELP_ID_REPOMAN HELP_ID_PREFIX"repoman"
232 #define HELP_ID_MAPMAN HELP_ID_PREFIX"mapman"
233 #define HELP_ID_DOWNROUTE HELP_ID_PREFIX"downroute"
234 #define HELP_ID_DOWNPOI HELP_ID_PREFIX"downpoi"
235 #define HELP_ID_BROWSEPOI HELP_ID_PREFIX"browsepoi"
236 #define HELP_ID_POILIST HELP_ID_PREFIX"poilist"
237 #define HELP_ID_POICAT HELP_ID_PREFIX"poicat"
238
239 #define MERCATOR_SPAN (-6.28318377773622)
240 #define MERCATOR_TOP (3.14159188886811)
241 #define latlon2unit(lat, lon, unitx, unity) { \
242     gdouble tmp; \
243     unitx = (lon + 180.0) * (WORLD_SIZE_UNITS / 360.0) + 0.5; \
244     tmp = sin(deg2rad(lat)); \
245     unity = 0.5 + (WORLD_SIZE_UNITS / MERCATOR_SPAN) \
246         * (log((1.0 + tmp) / (1.0 - tmp)) * 0.5 - MERCATOR_TOP); \
247 }
248
249 #define unit2latlon(unitx, unity, lat, lon) { \
250     (lon) = ((unitx) * (360.0 / WORLD_SIZE_UNITS)) - 180.0; \
251     (lat) = (360.0 * (atan(exp(((unity) * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) \
252                      + MERCATOR_TOP)))) * (1.0 / PI) - 90.0; \
253 }
254
255 #define MACRO_PATH_INIT(path) { \
256     (path).head = (path).tail = g_new(Point, ARRAY_CHUNK_SIZE); \
257     *((path).tail) = _point_null; \
258     (path).cap = (path).head + ARRAY_CHUNK_SIZE; \
259     (path).whead = g_new(WayPoint, ARRAY_CHUNK_SIZE); \
260     (path).wtail = (path).whead - 1; \
261     (path).wcap = (path).whead + ARRAY_CHUNK_SIZE; \
262 }
263
264 #define MACRO_PATH_FREE(path) if((path).head) { \
265     WayPoint *curr; \
266     g_free((path).head); \
267     (path).head = (path).tail = (path).cap = NULL; \
268     for(curr = (path).whead - 1; curr++ != (path).wtail; ) \
269         g_free(curr->desc); \
270     g_free((path).whead); \
271     (path).whead = (path).wtail = (path).wcap = NULL; \
272 }
273
274 #define MACRO_PATH_INCREMENT_TAIL(route) { \
275     if(++(route).tail == (route).cap) \
276         path_resize(&(route), (route).cap - (route).head + ARRAY_CHUNK_SIZE);\
277 }
278
279 #define MACRO_PATH_INCREMENT_WTAIL(route) { \
280     if(++(route).wtail == (route).wcap) \
281         path_wresize(&(route), \
282                 (route).wcap - (route).whead + ARRAY_CHUNK_SIZE); \
283 }
284
285 #define DISTANCE_SQUARED(a, b) \
286    ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\
287   + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity)))
288
289 #define MACRO_QUEUE_DRAW_AREA() \
290     gtk_widget_queue_draw_area( \
291             _map_widget, \
292             0, 0, \
293             _view_width_pixels, \
294             _view_height_pixels)
295
296 /* Render all on-map metadata an annotations, including POI and paths. */
297 #ifdef INCLUDE_APRS
298 #define MACRO_MAP_RENDER_DATA() { \
299     if(_show_poi) \
300         map_render_poi(); \
301     if(_show_paths > 0) \
302         map_render_paths(); \
303     if(_aprs_enable) \
304         map_render_aprs(); \
305 }
306 #else
307 #define MACRO_MAP_RENDER_DATA() { \
308     if(_show_poi) \
309         map_render_poi(); \
310     if(_show_paths > 0) \
311         map_render_paths(); \
312 }
313 #endif //INCLUDE_APRS
314
315 #define UNBLANK_SCREEN(MOVING, APPROACHING_WAYPOINT) { \
316     /* Check if we need to unblank the screen. */ \
317     switch(_unblank_option) \
318     { \
319         case UNBLANK_NEVER: \
320             break; \
321         case UNBLANK_WAYPOINT: \
322             if(APPROACHING_WAYPOINT) \
323             { \
324                 printf("Unblanking screen...\n"); \
325                 osso_display_state_on(_osso); \
326                 osso_display_blanking_pause(_osso); \
327             } \
328             break; \
329         default: \
330         case UNBLANK_FULLSCREEN: \
331             if(!_fullscreen) \
332                 break; \
333         case UNBLANK_WHEN_MOVING: \
334             if(!(MOVING)) \
335                 break; \
336         case UNBLANK_WITH_GPS: \
337             printf("Unblanking screen...\n"); \
338             osso_display_state_on(_osso); \
339             osso_display_blanking_pause(_osso); \
340     } \
341 }
342
343 #define LL_FMT_LEN 20
344 #define lat_format(A, B) deg_format((A), (B), 'S', 'N')
345 #define lon_format(A, B) deg_format((A), (B), 'W', 'E')
346
347 #define TRACKS_MASK 0x00000001
348 #define ROUTES_MASK 0x00000002
349
350 #define MACRO_BANNER_SHOW_INFO(A, S) { \
351     gchar *my_macro_buffer = g_markup_printf_escaped( \
352             "<span size='%s'>%s</span>", \
353             INFO_FONT_ENUM_TEXT[_info_font_size], (S)); \
354     hildon_banner_show_information_with_markup(A, NULL, my_macro_buffer); \
355     g_free(my_macro_buffer); \
356 }
357
358 #define _voice_synth_path "/usr/bin/flite"
359
360 #endif /* ifndef MAEMO_MAPPER_DEFINES */