/* Path point add sensitivity */
static gint sensitivity=3;
+enum {
+ NEW_POINT, /* A new point was appended to track track */
+ NEW_BREAK, /* A break was appended to the track */
+ NEW_WAYPOINT, /* A new waypoint/marker has been added */
+ NEAR_WAYPOINT, /* We are near the next route waypoint */
+ REACHED_WAYPOINT, /* We have reached the next route waypoint */
+ REACHED_DESTINATION, /* We have reached the last route waypoint */
+ LAST_SIGNAL
+};
+static guint32 signals[LAST_SIGNAL] = {0};
+
+G_DEFINE_TYPE(Path, path, G_TYPE_OBJECT);
+
+/* #define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PATH_TYPE, PathPrivate)) */
+
+static void
+path_dispose(GObject *object)
+{
+g_debug("path_dispose");
+
+G_OBJECT_CLASS(path_parent_class)->dispose(object);
+}
+
+static void
+path_finalize(GObject *object)
+{
+Path *path=PATH(object);
+
+g_debug("path_finalize");
+MACRO_PATH_FREE(*path);
+
+if (path->name)
+ g_free(path->name);
+if (path->desc)
+ g_free(path->desc);
+if (path->author)
+ g_free(path->author);
+if (path->keywords)
+ g_free(path->keywords);
+if (path->copyright)
+ g_free(path->copyright);
+if (path->src)
+ g_free(path->src);
+}
+
+static void
+path_class_init(PathClass *klass)
+{
+GObjectClass *object_class=G_OBJECT_CLASS(klass);
+
+g_debug("path_class_init");
+
+object_class->dispose=path_dispose;
+object_class->finalize=path_finalize;
+/* g_type_class_add_private (klass, sizeof(PathPrivate)); */
+
+signals[NEW_POINT]=g_signal_new("new-point", G_OBJECT_CLASS_TYPE(object_class),
+ G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(PathClass, new_point),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL);
+signals[NEW_BREAK]=g_signal_new("new-break", G_OBJECT_CLASS_TYPE(object_class),
+ G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(PathClass, new_break),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL);
+signals[NEW_WAYPOINT]=g_signal_new("new-waypoint", G_OBJECT_CLASS_TYPE(object_class),
+ G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(PathClass, new_waypoint),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, NULL);
+}
+
+static void
+path_init(Path *path)
+{
+g_debug("path_init");
+MACRO_PATH_INIT(*path);
+}
+
Path *
path_new(PathType type, guint id)
{
Path *p;
-p=g_slice_new0(Path);
-MACRO_PATH_INIT(*p);
+p=g_object_new(PATH_TYPE, NULL);
p->type=type;
p->id=id;
return p;
}
void
-path_free(Path *p)
+path_free(Path *path)
{
-g_return_if_fail(p);
-MACRO_PATH_FREE(*p);
-g_slice_free(Path, p);
+g_return_if_fail(path);
+g_debug("path_free");
+g_object_unref(path);
}
void
-path_clear(Path *p)
+path_clear(Path *path)
{
-g_return_if_fail(p);
-MACRO_PATH_FREE(*p);
-p->length=p->avgspeed=0.0;
-p->points=0;
+g_return_if_fail(path);
+MACRO_PATH_FREE(*path);
+path->length=path->avgspeed=0.0;
+path->points=0;
}
-gboolean
+gboolean
path_resize(Path *path, guint size)
{
g_return_val_if_fail(path, FALSE);
path->avgspeed=(path->points>0) ? path->tspeed/path->points : 0.0;
path->points++;
g_debug("TRACK: %f %f (%d)", path->length, path->avgspeed, path->points);
+
+ g_signal_emit(G_OBJECT(path), signals[NEW_POINT], 0, NULL);
}
return TRUE;
g_return_val_if_fail(path, FALSE);
g_return_val_if_fail(path->tail, FALSE);
-if (path->tail->unity) {
+if (path->tail->unity && path->tail->unitx) {
guint x1, y1;
- /* To mark a "waypoint" in a track, we'll add a (0, 0) point and then
- * another instance of the most recent track point. */
+ /* To mark a "break" in a track, we'll add a (0, 0) point and then
+ another instance of the most recent track point. */
+
MACRO_PATH_INCREMENT_TAIL(*path);
*path->tail=_point_null;
MACRO_PATH_INCREMENT_TAIL(*path);
*path->tail=path->tail[-2];
-#if 0
- /* Instead of calling map_render_paths(), we'll just draw the waypoint ourselves. */
- x1 = unit2bufx(path->tail->unitx);
- y1 = unit2bufy(path->tail->unity);
- map_render_waypoint(x1, y1, _gc[COLORABLE_TRACK_BREAK]);
-#endif
+ g_signal_emit(G_OBJECT(path), signals[NEW_BREAK], 0, NULL);
+
return TRUE;
}
return FALSE;
path->wpcnt++;
path->wtail->desc=g_strdup_printf("WP: %u", path->wpcnt);
}
+g_signal_emit(G_OBJECT(path), signals[NEW_WAYPOINT], 0, NULL);
+}
+
+#if 0
+static void
+path_store_append_waypoint(GtkListStore *, WayPoint *w)
+{
+gchar tmp1[16], tmp2[16];
+gdouble lat2, lon2;
+
+unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat2, lon2);
+lat_format(_degformat, lat2, tmp1);
+lon_format(_degformat, lon2, tmp2);
+
+g_snprintf(buffer1, sizeof(buffer1), "%s,%s", tmp1, tmp2);
+sum += calculate_distance(lat1, lon1, lat2, lon2);
+g_snprintf(buffer2, sizeof(buffer2), "%.02f %s", sum * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
+
+gtk_list_store_append(store, &iter);
+gtk_list_store_set(store, &iter,
+ ROUTE_LATLON, buffer1,
+ ROUTE_DISTANCE, buffer2,
+ ROUTE_WAYPOINT, wcurr->desc,
+ ROUTE_LAT, lat2,
+ ROUTE_LON, lon2,
+ -1);
+
+lat1=lat2;
+lon1=lon2;
}
+#endif
/**
* Generate a GtkListStore with information about path waypoints (location, distance)
gdouble lat1, lon1, lat2, lon2;
gdouble sum=0.0;
-g_return_val_if_fail(path, NULL);
+g_return_val_if_fail(path!=NULL, NULL);
wcurr=path->whead;
-g_return_val_if_fail(wcurr, NULL);
-g_return_val_if_fail(wcurr->point, NULL);
+g_return_val_if_fail(wcurr!=NULL, NULL);
+g_return_val_if_fail(wcurr->point!=NULL, NULL);
if (!path_has_waypoints(path))
return NULL;