]> git.street.me.uk Git - andy/viking.git/blame - src/vikmapsource.c
Merge branch 'new-maps'
[andy/viking.git] / src / vikmapsource.c
CommitLineData
820c59f4
GB
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2/*
3 * viking
4 * Copyright (C) Guilhem Bonnefille 2009 <guilhem.bonnefille@gmail.com>
5 *
6 * viking is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * viking is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include "vikviewport.h"
24#include "vikcoord.h"
25#include "mapcoord.h"
26
27#include "vikmapsource.h"
28
29static void vik_map_source_init (VikMapSource *object);
30static void vik_map_source_finalize (GObject *object);
31static void vik_map_source_class_init (VikMapSourceClass *klass);
32
0f08bd0d
GB
33static void _supports_if_modified_since (VikMapSource *object);
34
820c59f4
GB
35G_DEFINE_TYPE_EXTENDED (VikMapSource, vik_map_source, G_TYPE_OBJECT, (GTypeFlags)G_TYPE_FLAG_ABSTRACT,);
36
820c59f4
GB
37static void
38vik_map_source_init (VikMapSource *object)
39{
40 /* TODO: Add initialization code here */
41}
42
43static void
44vik_map_source_finalize (GObject *object)
45{
46 /* TODO: Add deinitalization code here */
47
48 G_OBJECT_CLASS (vik_map_source_parent_class)->finalize (object);
49}
50
51static void
52vik_map_source_class_init (VikMapSourceClass *klass)
53{
54 GObjectClass* object_class = G_OBJECT_CLASS (klass);
55
56 klass->get_uniq_id = NULL;
db03733a 57 klass->get_label = NULL;
820c59f4
GB
58 klass->get_tilesize_x = NULL;
59 klass->get_tilesize_y = NULL;
60 klass->get_drawmode = NULL;
0f08bd0d 61 klass->supports_if_modified_since = _supports_if_modified_since;
820c59f4
GB
62 klass->coord_to_mapcoord = NULL;
63 klass->mapcoord_to_center_coord = NULL;
64 klass->download = NULL;
65
66 object_class->finalize = vik_map_source_finalize;
67}
68
0f08bd0d
GB
69void
70_supports_if_modified_since (VikMapSource *self)
71{
72 // Default feature: does not support
73 return FALSE;
74}
820c59f4
GB
75
76guint8
77vik_map_source_get_uniq_id (VikMapSource *self)
78{
79 VikMapSourceClass *klass;
80 g_return_val_if_fail (self != NULL, (guint8 )0);
81 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint8 )0);
82 klass = VIK_MAP_SOURCE_GET_CLASS(self);
83
84 g_return_val_if_fail (klass->get_uniq_id != NULL, (guint8 )0);
85
86 return (*klass->get_uniq_id)(self);
87}
88
db03733a
GB
89const gchar *
90vik_map_source_get_label (VikMapSource *self)
91{
92 VikMapSourceClass *klass;
93 g_return_val_if_fail (self != NULL, NULL);
94 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), NULL);
95 klass = VIK_MAP_SOURCE_GET_CLASS(self);
96
97 g_return_val_if_fail (klass->get_label != NULL, NULL);
98
99 return (*klass->get_label)(self);
100}
101
820c59f4
GB
102guint16
103vik_map_source_get_tilesize_x (VikMapSource *self)
104{
105 VikMapSourceClass *klass;
106 g_return_val_if_fail (self != NULL, (guint16 )0);
107 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
108 klass = VIK_MAP_SOURCE_GET_CLASS(self);
109
110 g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0);
111
112 return (*klass->get_tilesize_x)(self);
113}
114
115guint16
116vik_map_source_get_tilesize_y (VikMapSource *self)
117{
118 VikMapSourceClass *klass;
119 g_return_val_if_fail (self != NULL, (guint16 )0);
120 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
121 klass = VIK_MAP_SOURCE_GET_CLASS(self);
122
123 g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0);
124
125 return (*klass->get_tilesize_y)(self);
126}
127
128VikViewportDrawMode
129vik_map_source_get_drawmode (VikMapSource *self)
130{
131 VikMapSourceClass *klass;
132 g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0);
133 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0);
134 klass = VIK_MAP_SOURCE_GET_CLASS(self);
135
136 g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0);
137
138 return (*klass->get_drawmode)(self);
139}
140
0f08bd0d
GB
141gboolean
142vik_map_source_supports_if_modified_since (VikMapSource * self)
143{
144 VikMapSourceClass *klass;
145 g_return_val_if_fail (self != NULL, 0);
146 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
147 klass = VIK_MAP_SOURCE_GET_CLASS(self);
148
149 g_return_val_if_fail (klass->supports_if_modified_since != NULL, 0);
150
151 return (*klass->supports_if_modified_since)(self);
152}
153
820c59f4
GB
154gboolean
155vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
156{
157 VikMapSourceClass *klass;
158 g_return_val_if_fail (self != NULL, FALSE);
159 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE);
160 klass = VIK_MAP_SOURCE_GET_CLASS(self);
161
162 g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE);
163
164 return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest);
165}
166
167void
168vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
169{
170 VikMapSourceClass *klass;
171 g_return_if_fail (self != NULL);
172 g_return_if_fail (VIK_IS_MAP_SOURCE (self));
173 klass = VIK_MAP_SOURCE_GET_CLASS(self);
174
175 g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
176
177 return (*klass->mapcoord_to_center_coord)(self, src, dest);
178}
179
180int
181vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn)
182{
183 VikMapSourceClass *klass;
184 g_return_val_if_fail (self != NULL, 0);
185 g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
186 klass = VIK_MAP_SOURCE_GET_CLASS(self);
187
188 g_return_val_if_fail (klass->download != NULL, 0);
189
190 return (*klass->download)(self, src, dest_fn);
191}