]> git.street.me.uk Git - andy/viking.git/blob - src/vikmapsource.c
Remove dependencies to gob2
[andy/viking.git] / src / vikmapsource.c
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
29 static void vik_map_source_init (VikMapSource *object);
30 static void vik_map_source_finalize (GObject *object);
31 static void vik_map_source_class_init (VikMapSourceClass *klass);
32
33 G_DEFINE_TYPE_EXTENDED (VikMapSource, vik_map_source, G_TYPE_OBJECT, (GTypeFlags)G_TYPE_FLAG_ABSTRACT,);
34
35 /*
36 GType
37 vik_map_source_get_type (void)
38 {
39         static GType type = 0;
40
41         if (!type) {
42                 static const GTypeInfo info = {
43                         sizeof (VikMapSourceClass),
44                         (GBaseInitFunc) NULL,
45                         (GBaseFinalizeFunc) NULL,
46                         (GClassInitFunc) vik_map_source_class_init,
47                         (GClassFinalizeFunc) NULL,
48                         NULL /* class_data * /,
49                         sizeof (VikMapSource),
50                         0 /* n_preallocs * /,
51                         (GInstanceInitFunc) vik_map_source_init,
52                         NULL
53                 };
54
55                 type = g_type_register_static (G_TYPE_OBJECT, "VikMapSource", &info, (GTypeFlags)G_TYPE_FLAG_ABSTRACT);
56         }
57
58         return type;
59 }
60 */
61
62 static void
63 vik_map_source_init (VikMapSource *object)
64 {
65         /* TODO: Add initialization code here */
66 }
67
68 static void
69 vik_map_source_finalize (GObject *object)
70 {
71         /* TODO: Add deinitalization code here */
72
73         G_OBJECT_CLASS (vik_map_source_parent_class)->finalize (object);
74 }
75
76 static void
77 vik_map_source_class_init (VikMapSourceClass *klass)
78 {
79         GObjectClass* object_class = G_OBJECT_CLASS (klass);
80
81         klass->get_uniq_id = NULL;
82         klass->get_tilesize_x = NULL;
83         klass->get_tilesize_y = NULL;
84         klass->get_drawmode = NULL;
85         klass->coord_to_mapcoord = NULL;
86         klass->mapcoord_to_center_coord = NULL;
87         klass->download = NULL;
88         
89         object_class->finalize = vik_map_source_finalize;
90 }
91
92
93 guint8
94 vik_map_source_get_uniq_id (VikMapSource *self)
95 {
96         VikMapSourceClass *klass;
97         g_return_val_if_fail (self != NULL, (guint8 )0);
98         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint8 )0);
99         klass = VIK_MAP_SOURCE_GET_CLASS(self);
100
101         g_return_val_if_fail (klass->get_uniq_id != NULL, (guint8 )0);
102
103         return (*klass->get_uniq_id)(self);
104 }
105
106 guint16
107 vik_map_source_get_tilesize_x (VikMapSource *self)
108 {
109         VikMapSourceClass *klass;
110         g_return_val_if_fail (self != NULL, (guint16 )0);
111         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
112         klass = VIK_MAP_SOURCE_GET_CLASS(self);
113
114         g_return_val_if_fail (klass->get_tilesize_x != NULL, (guint16 )0);
115
116         return (*klass->get_tilesize_x)(self);
117 }
118
119 guint16
120 vik_map_source_get_tilesize_y (VikMapSource *self)
121 {
122         VikMapSourceClass *klass;
123         g_return_val_if_fail (self != NULL, (guint16 )0);
124         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (guint16 )0);
125         klass = VIK_MAP_SOURCE_GET_CLASS(self);
126
127         g_return_val_if_fail (klass->get_tilesize_y != NULL, (guint16 )0);
128
129         return (*klass->get_tilesize_y)(self);
130 }
131
132 VikViewportDrawMode
133 vik_map_source_get_drawmode (VikMapSource *self)
134 {
135         VikMapSourceClass *klass;
136         g_return_val_if_fail (self != NULL, (VikViewportDrawMode )0);
137         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), (VikViewportDrawMode )0);
138         klass = VIK_MAP_SOURCE_GET_CLASS(self);
139
140         g_return_val_if_fail (klass->get_drawmode != NULL, (VikViewportDrawMode )0);
141
142         return (*klass->get_drawmode)(self);
143 }
144
145 gboolean
146 vik_map_source_coord_to_mapcoord (VikMapSource *self, const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest )
147 {
148         VikMapSourceClass *klass;
149         g_return_val_if_fail (self != NULL, FALSE);
150         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), FALSE);
151         klass = VIK_MAP_SOURCE_GET_CLASS(self);
152
153         g_return_val_if_fail (klass->coord_to_mapcoord != NULL, FALSE);
154
155         return (*klass->coord_to_mapcoord)(self, src, xzoom, yzoom, dest);
156 }
157
158 void
159 vik_map_source_mapcoord_to_center_coord (VikMapSource *self, MapCoord *src, VikCoord *dest)
160 {
161         VikMapSourceClass *klass;
162         g_return_if_fail (self != NULL);
163         g_return_if_fail (VIK_IS_MAP_SOURCE (self));
164         klass = VIK_MAP_SOURCE_GET_CLASS(self);
165
166         g_return_if_fail (klass->mapcoord_to_center_coord != NULL);
167
168         return (*klass->mapcoord_to_center_coord)(self, src, dest);
169 }
170
171 int
172 vik_map_source_download (VikMapSource * self, MapCoord * src, const gchar * dest_fn)
173 {
174         VikMapSourceClass *klass;
175         g_return_val_if_fail (self != NULL, 0);
176         g_return_val_if_fail (VIK_IS_MAP_SOURCE (self), 0);
177         klass = VIK_MAP_SOURCE_GET_CLASS(self);
178
179         g_return_val_if_fail (klass->download != NULL, 0);
180
181         return (*klass->download)(self, src, dest_fn);
182 }