]> git.street.me.uk Git - andy/viking.git/blame - src/vikroutingengine.c
[QA] Rename routing engine function as it gives URLs
[andy/viking.git] / src / vikroutingengine.c
CommitLineData
9f30939a
GB
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (C) 2012-2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/**
22 * SECTION:vikroutingengine
23 * @short_description: the base class to describe routing engine
24 *
25 * The #VikRoutingEngine class is both the interface and the base class
26 * for the hierarchie of routing engines.
27 */
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <glib.h>
34#include <glib/gstdio.h>
35#include <glib/gi18n.h>
36
9f30939a
GB
37#include "babel.h"
38
39#include "vikroutingengine.h"
40
41static void vik_routing_engine_finalize ( GObject *gob );
9f30939a
GB
42static GObjectClass *parent_class;
43
44typedef struct _VikRoutingPrivate VikRoutingPrivate;
45struct _VikRoutingPrivate
46{
47 gchar *id;
48 gchar *label;
49 gchar *format;
50};
51
52#define VIK_ROUTING_ENGINE_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIK_ROUTING_ENGINE_TYPE, VikRoutingPrivate))
53
54/* properties */
55enum
56{
57 PROP_0,
58
59 PROP_ID,
60 PROP_LABEL,
61 PROP_FORMAT,
62};
63
64G_DEFINE_ABSTRACT_TYPE (VikRoutingEngine, vik_routing_engine, G_TYPE_OBJECT)
65
66static void
67vik_routing_engine_set_property (GObject *object,
68 guint property_id,
69 const GValue *value,
70 GParamSpec *pspec)
71{
72 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE ( object );
73
74 switch (property_id)
75 {
76 case PROP_ID:
77 g_free (priv->id);
78 priv->id = g_strdup(g_value_get_string (value));
79 break;
80
81 case PROP_LABEL:
82 g_free (priv->label);
83 priv->label = g_strdup(g_value_get_string (value));
84 break;
85
86 case PROP_FORMAT:
87 g_free (priv->format);
88 priv->format = g_strdup(g_value_get_string (value));
89 break;
90
91 default:
92 /* We don't have any other property... */
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
94 break;
95 }
96}
97
98static void
99vik_routing_engine_get_property (GObject *object,
100 guint property_id,
101 GValue *value,
102 GParamSpec *pspec)
103{
104 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE ( object );
105
106 switch (property_id)
107 {
108 case PROP_ID:
109 g_value_set_string (value, priv->id);
110 break;
111
112 case PROP_LABEL:
113 g_value_set_string (value, priv->label);
114 break;
115
116 case PROP_FORMAT:
117 g_value_set_string (value, priv->format);
118 break;
119
120 default:
121 /* We don't have any other property... */
122 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
123 break;
124 }
125}
126
127static void
128vik_routing_engine_class_init ( VikRoutingEngineClass *klass )
129{
130 GObjectClass *object_class;
131 VikRoutingEngineClass *routing_class;
132 GParamSpec *pspec = NULL;
133
134 object_class = G_OBJECT_CLASS (klass);
135
136 object_class->set_property = vik_routing_engine_set_property;
137 object_class->get_property = vik_routing_engine_get_property;
138 object_class->finalize = vik_routing_engine_finalize;
139
140 parent_class = g_type_class_peek_parent (klass);
141
142 routing_class = VIK_ROUTING_ENGINE_CLASS ( klass );
143 routing_class->find = NULL;
1a3be6a8 144
7f95fd54 145 routing_class->supports_direction = NULL;
09f04587 146 routing_class->get_url_from_directions = NULL;
9f30939a 147
1a3be6a8
GB
148 routing_class->refine = NULL;
149 routing_class->supports_refine = NULL;
150
9f30939a
GB
151 pspec = g_param_spec_string ("id",
152 "Identifier",
153 "The identifier of the routing engine",
154 "<no-set>" /* default value */,
155 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
156 g_object_class_install_property (object_class, PROP_ID, pspec);
157
158 pspec = g_param_spec_string ("label",
159 "Label",
160 "The label of the routing engine",
161 "<no-set>" /* default value */,
162 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
163 g_object_class_install_property (object_class, PROP_LABEL, pspec);
164
165 pspec = g_param_spec_string ("format",
166 "Format",
167 "The format of the output (see gpsbabel)",
168 "<no-set>" /* default value */,
169 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
170 g_object_class_install_property (object_class, PROP_FORMAT, pspec);
171
172 g_type_class_add_private (klass, sizeof (VikRoutingPrivate));
173}
174
175static void
176vik_routing_engine_init ( VikRoutingEngine *self )
177{
178 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
179
180 priv->id = NULL;
181 priv->label = NULL;
182 priv->format = NULL;
183}
184
185static void
186vik_routing_engine_finalize ( GObject *self )
187{
188 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
189
190 g_free (priv->id);
191 priv->id = NULL;
192
193 g_free (priv->label);
194 priv->label = NULL;
195
196 g_free (priv->format);
197 priv->format = NULL;
198
199 G_OBJECT_CLASS(parent_class)->finalize(self);
200}
201
75ee0e75
GB
202/**
203 * vik_routing_engine_find:
204 * @self: self object
205 * @vtl:
206 * @start: starting point
207 * @end: ending point
208 *
209 * Retrieve a route between two coordinates.
210 *
211 * Returns: indicates success or not.
212 */
41e48655 213gboolean
bc048a9c 214vik_routing_engine_find ( VikRoutingEngine *self, VikTrwLayer *vtl, struct LatLon start, struct LatLon end )
9f30939a
GB
215{
216 VikRoutingEngineClass *klass;
217
bc048a9c 218 g_return_val_if_fail ( VIK_IS_ROUTING_ENGINE (self), 0 );
9f30939a 219 klass = VIK_ROUTING_ENGINE_GET_CLASS( self );
bc048a9c 220 g_return_val_if_fail ( klass->find != NULL, 0 );
9f30939a 221
bc048a9c 222 return klass->find( self, vtl, start, end );
9f30939a
GB
223}
224
225/**
226 * vik_routing_engine_get_id:
227 *
228 * Returns: the id of self
229 */
230gchar *
231vik_routing_engine_get_id ( VikRoutingEngine *self )
232{
233 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
234
235 return priv->id;
236}
237
238/**
239 * vik_routing_engine_get_label:
240 *
241 * Returns: the label of self
242 */
243gchar *
244vik_routing_engine_get_label ( VikRoutingEngine *self )
245{
246 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
247
248 return priv->label;
249}
250
251/**
252 * vik_routing_engine_get_format:
d2e33e78
GB
253 *
254 * GPSbabel's Format of result.
255 *
9f30939a
GB
256 * Returns: the format of self
257 */
258gchar *
259vik_routing_engine_get_format ( VikRoutingEngine *self )
260{
261 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
262
263 return priv->format;
264}
7f95fd54
GB
265
266/**
267 * vik_routing_engine_supports_direction:
268 *
269 * Returns: %TRUE if this engine supports the route finding based on directions
270 */
271gboolean
272vik_routing_engine_supports_direction ( VikRoutingEngine *self )
273{
274 VikRoutingEngineClass *klass;
275
276 g_return_val_if_fail ( VIK_IS_ROUTING_ENGINE (self), FALSE );
277 klass = VIK_ROUTING_ENGINE_GET_CLASS( self );
278 g_return_val_if_fail ( klass->supports_direction != NULL, FALSE );
279
280 return klass->supports_direction( self );
281}
282
283/**
09f04587 284 * vik_routing_engine_get_url_from_directions:
7f95fd54
GB
285 * @self: routing engine
286 * @start: the start direction
287 * @end: the end direction
288 *
09f04587 289 * Compute the URL used with the acquire framework.
7f95fd54 290 *
09f04587 291 * Returns: the computed URL
7f95fd54
GB
292 */
293gchar *
09f04587 294vik_routing_engine_get_url_from_directions ( VikRoutingEngine *self, const gchar *start, const gchar *end )
7f95fd54
GB
295{
296 VikRoutingEngineClass *klass;
297
298 g_return_val_if_fail ( VIK_IS_ROUTING_ENGINE (self), NULL );
299 klass = VIK_ROUTING_ENGINE_GET_CLASS( self );
09f04587 300 g_return_val_if_fail ( klass->get_url_from_directions != NULL, NULL );
7f95fd54 301
09f04587 302 return klass->get_url_from_directions( self, start, end );
7f95fd54 303}
1a3be6a8
GB
304
305/**
306 * vik_routing_engine_refine:
307 * @self: self object
308 * @vtl: layer where to create new track
309 * @vt: the simple route to refine
310 *
311 * Retrieve a route refining the @vt track/route.
312 *
313 * A refined route is computed from @vt.
314 * The route is computed from first trackpoint to last trackpoint,
315 * and going via all intermediate trackpoints.
316 *
317 * Returns: indicates success or not.
318 */
41e48655 319gboolean
1a3be6a8
GB
320vik_routing_engine_refine ( VikRoutingEngine *self, VikTrwLayer *vtl, VikTrack *vt )
321{
322 VikRoutingEngineClass *klass;
323
324 g_return_val_if_fail ( VIK_IS_ROUTING_ENGINE (self), 0 );
325 klass = VIK_ROUTING_ENGINE_GET_CLASS ( self );
326 g_return_val_if_fail ( klass->refine != NULL, 0 );
327
328 return klass->refine ( self, vtl, vt );
329}
330
331/**
332 * vik_routing_engine_supports_refine:
333 * @self: routing engine
334 *
335 * Returns: %TRUE if this engine supports the refine of track
336 */
337gboolean
338vik_routing_engine_supports_refine ( VikRoutingEngine *self )
339{
340 VikRoutingEngineClass *klass;
341
342 g_return_val_if_fail ( VIK_IS_ROUTING_ENGINE (self), FALSE );
343 klass = VIK_ROUTING_ENGINE_GET_CLASS ( self );
344 g_return_val_if_fail ( klass->supports_refine != NULL, FALSE );
345
346 return klass->supports_refine ( self );
347}