2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2012-2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
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.
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.
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
22 * SECTION:vikroutingengine
23 * @short_description: the base class to describe routing engine
25 * The #VikRoutingEngine class is both the interface and the base class
26 * for the hierarchie of routing engines.
34 #include <glib/gstdio.h>
35 #include <glib/gi18n.h>
39 #include "vikroutingengine.h"
41 static void vik_routing_engine_finalize ( GObject *gob );
42 static GObjectClass *parent_class;
44 typedef struct _VikRoutingPrivate VikRoutingPrivate;
45 struct _VikRoutingPrivate
52 #define VIK_ROUTING_ENGINE_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIK_ROUTING_ENGINE_TYPE, VikRoutingPrivate))
64 G_DEFINE_ABSTRACT_TYPE (VikRoutingEngine, vik_routing_engine, G_TYPE_OBJECT)
67 vik_routing_engine_set_property (GObject *object,
72 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE ( object );
78 priv->id = g_strdup(g_value_get_string (value));
83 priv->label = g_strdup(g_value_get_string (value));
87 g_free (priv->format);
88 priv->format = g_strdup(g_value_get_string (value));
92 /* We don't have any other property... */
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
99 vik_routing_engine_get_property (GObject *object,
104 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE ( object );
109 g_value_set_string (value, priv->id);
113 g_value_set_string (value, priv->label);
117 g_value_set_string (value, priv->format);
121 /* We don't have any other property... */
122 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
128 vik_routing_engine_class_init ( VikRoutingEngineClass *klass )
130 GObjectClass *object_class;
131 VikRoutingEngineClass *routing_class;
132 GParamSpec *pspec = NULL;
134 object_class = G_OBJECT_CLASS (klass);
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;
140 parent_class = g_type_class_peek_parent (klass);
142 routing_class = VIK_ROUTING_ENGINE_CLASS ( klass );
143 routing_class->find = NULL;
145 routing_class->supports_direction = NULL;
146 routing_class->get_cmd_from_directions = NULL;
148 routing_class->refine = NULL;
149 routing_class->supports_refine = NULL;
151 pspec = g_param_spec_string ("id",
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);
158 pspec = g_param_spec_string ("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);
165 pspec = g_param_spec_string ("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);
172 g_type_class_add_private (klass, sizeof (VikRoutingPrivate));
176 vik_routing_engine_init ( VikRoutingEngine *self )
178 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
186 vik_routing_engine_finalize ( GObject *self )
188 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
193 g_free (priv->label);
196 g_free (priv->format);
199 G_OBJECT_CLASS(parent_class)->finalize(self);
203 * vik_routing_engine_find:
206 * @start: starting point
209 * Retrieve a route between two coordinates.
211 * Returns: indicates success or not.
214 vik_routing_engine_find ( VikRoutingEngine *self, VikTrwLayer *vtl, struct LatLon start, struct LatLon end )
216 VikRoutingEngineClass *klass;
218 g_return_val_if_fail ( VIK_IS_ROUTING_ENGINE (self), 0 );
219 klass = VIK_ROUTING_ENGINE_GET_CLASS( self );
220 g_return_val_if_fail ( klass->find != NULL, 0 );
222 return klass->find( self, vtl, start, end );
226 * vik_routing_engine_get_id:
228 * Returns: the id of self
231 vik_routing_engine_get_id ( VikRoutingEngine *self )
233 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
239 * vik_routing_engine_get_label:
241 * Returns: the label of self
244 vik_routing_engine_get_label ( VikRoutingEngine *self )
246 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
252 * vik_routing_engine_get_format:
254 * GPSbabel's Format of result.
256 * Returns: the format of self
259 vik_routing_engine_get_format ( VikRoutingEngine *self )
261 VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
267 * vik_routing_engine_supports_direction:
269 * Returns: %TRUE if this engine supports the route finding based on directions
272 vik_routing_engine_supports_direction ( VikRoutingEngine *self )
274 VikRoutingEngineClass *klass;
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 );
280 return klass->supports_direction( self );
284 * vik_routing_engine_get_cmd_from_directions:
285 * @self: routing engine
286 * @start: the start direction
287 * @end: the end direction
289 * Compute a "cmd" for acquire framework.
291 * Returns: the computed cmd
294 vik_routing_engine_get_cmd_from_directions ( VikRoutingEngine *self, const gchar *start, const gchar *end )
296 VikRoutingEngineClass *klass;
298 g_return_val_if_fail ( VIK_IS_ROUTING_ENGINE (self), NULL );
299 klass = VIK_ROUTING_ENGINE_GET_CLASS( self );
300 g_return_val_if_fail ( klass->get_cmd_from_directions != NULL, NULL );
302 return klass->get_cmd_from_directions( self, start, end );
306 * vik_routing_engine_refine:
308 * @vtl: layer where to create new track
309 * @vt: the simple route to refine
311 * Retrieve a route refining the @vt track/route.
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.
317 * Returns: indicates success or not.
320 vik_routing_engine_refine ( VikRoutingEngine *self, VikTrwLayer *vtl, VikTrack *vt )
322 VikRoutingEngineClass *klass;
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 );
328 return klass->refine ( self, vtl, vt );
332 * vik_routing_engine_supports_refine:
333 * @self: routing engine
335 * Returns: %TRUE if this engine supports the refine of track
338 vik_routing_engine_supports_refine ( VikRoutingEngine *self )
340 VikRoutingEngineClass *klass;
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 );
346 return klass->supports_refine ( self );