---------
0.1 - Working
* Fix all memory leaks
- * Asynchronous IO and data loading
* Pre-load textures and polys in OpenGL
0.x - Volume scans
GTK_DOC_CHECK(1.9)
# Check for required packages
-PKG_CHECK_MODULES(GTK, gtk+-2.0 gtkglext-1.0 gmodule-export-2.0 gobject-2.0)
+PKG_CHECK_MODULES(GTK, gtk+-2.0 gtkglext-1.0 gmodule-export-2.0 gobject-2.0 gthread-2.0)
# Define odd RSL install location
#AC_SUBST(RSL_CFLAGS, "-I/usr/local/trmm/GVBOX/include/")
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Sun May 24 00:31:16 2009 -->
+<!--Generated with glade3 3.4.5 on Mon May 25 01:31:13 2009 -->
<glade-interface>
<widget class="GtkWindow" id="window">
<signal name="key_press_event" handler="on_key_press"/>
<signal name="delete_event" handler="gtk_main_quit"/>
<child>
- <widget class="GtkVBox" id="vbox1">
+ <widget class="GtkVBox" id="body">
<property name="visible">True</property>
<child>
<widget class="GtkMenuBar" id="menu">
/****************
* GObject code *
****************/
-G_DEFINE_TYPE(AWeatherGui, aweather_gui, G_TYPE_OBJECT);
+G_DEFINE_TYPE(AWeatherGui, aweather_gui, GTK_TYPE_WINDOW);
static void aweather_gui_init(AWeatherGui *gui)
{
gui->plugins = NULL;
- //g_message("aweather_gui_init");
+ g_debug("AWeatherGui: init");
}
static GObject *aweather_gui_constructor(GType gtype, guint n_properties,
GObjectConstructParam *properties)
{
- //g_message("aweather_gui_constructor");
+ g_debug("aweather_gui: constructor");
GObjectClass *parent_class = G_OBJECT_CLASS(aweather_gui_parent_class);
return parent_class->constructor(gtype, n_properties, properties);
}
-static void aweather_gui_dispose (GObject *gobject)
+static void aweather_gui_dispose(GObject *gobject)
{
- //g_message("aweather_gui_dispose");
+ g_debug("AWeatherGui: dispose");
AWeatherGui *gui = AWEATHER_GUI(gobject);
g_object_unref(gui->view );
g_object_unref(gui->builder);
- g_object_unref(gui->window );
- g_object_unref(gui->tabs );
- g_object_unref(gui->drawing);
G_OBJECT_CLASS(aweather_gui_parent_class)->dispose(gobject);
}
static void aweather_gui_finalize(GObject *gobject)
{
- //g_message("aweather_gui_finalize");
+ g_debug("AWeatherGui: finalize");
G_OBJECT_CLASS(aweather_gui_parent_class)->finalize(gobject);
}
static void aweather_gui_class_init(AWeatherGuiClass *klass)
{
- //g_message("aweather_gui_class_init");
+ g_debug("AWeatherGui: class_init");
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->constructor = aweather_gui_constructor;
gobject_class->dispose = aweather_gui_dispose;
*************/
gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, AWeatherGui *gui)
{
- g_message("key_press: key=%x, state=%x", event->keyval, event->state);
+ g_debug("AWeatherGui: on_key_press - key=%x, state=%x", event->keyval, event->state);
AWeatherView *view = aweather_gui_get_view(gui);
double x,y,z;
aweather_view_get_location(view, &x, &y, &z);
gboolean on_map(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
{
- g_message("on_map");
+ g_debug("AWeatherGui: on_map");
AWeatherView *view = aweather_gui_get_view(gui);
- aweather_view_set_site(view, "IND");
/* Misc */
glEnable(GL_BLEND);
gboolean on_configure(GtkWidget *da, GdkEventConfigure *event, AWeatherGui *gui)
{
- //g_message("on_confiure");
+ g_debug("AWeatherGui: on_confiure");
aweather_gui_gl_begin(gui);
double x, y, z;
gboolean on_expose(GtkWidget *da, GdkEventExpose *event, AWeatherGui *gui)
{
- g_message("aweather:expose - begin");
+ g_debug("AWeatherGui: on_expose - begin");
aweather_gui_gl_begin(gui);
double x, y, z;
aweather_gui_gl_end(gui);
aweather_gui_gl_flush(gui);
- g_message("aweather:expose - end\n");
+ g_debug("AWeatherGui: on_expose - end\n");
return FALSE;
}
/* TODO: replace the code in these with `gtk_tree_model_find' utility */
static void update_time_widget(AWeatherView *view, char *time, AWeatherGui *gui)
{
- g_message("updating time widget");
+ g_debug("AWeatherGui: update_time_widget");
GtkTreeView *tview = GTK_TREE_VIEW(aweather_gui_get_widget(gui, "time"));
GtkTreeModel *model = GTK_TREE_MODEL(gtk_tree_view_get_model(tview));
for (int i = 0; i < gtk_tree_model_iter_n_children(model, NULL); i++) {
}
static void update_site_widget(AWeatherView *view, char *site, AWeatherGui *gui)
{
- g_message("updating site widget to %s", site);
+ g_debug("AWeatherGui: updat_site_widget - site=%s", site);
GtkComboBox *combo = GTK_COMBO_BOX(aweather_gui_get_widget(gui, "site"));
GtkTreeModel *model = GTK_TREE_MODEL(gtk_combo_box_get_model(combo));
for (int i = 0; i < gtk_tree_model_iter_n_children(model, NULL); i++) {
***********/
AWeatherGui *aweather_gui_new()
{
- //g_message("aweather_gui_new");
+ g_debug("AWeatherGui: new");
GError *error = NULL;
- AWeatherGui *gui = g_object_new(AWEATHER_TYPE_GUI, NULL);
+ AWeatherGui *self = g_object_new(AWEATHER_TYPE_GUI, NULL);
+ self->view = aweather_view_new();
+ self->builder = gtk_builder_new();
- gui->builder = gtk_builder_new();
- if (!gtk_builder_add_from_file(gui->builder, DATADIR "/aweather/main.xml", &error))
+ if (!gtk_builder_add_from_file(self->builder, DATADIR "/aweather/main.xml", &error))
g_error("Failed to create gtk builder: %s", error->message);
- gui->view = aweather_view_new();
- gui->window = GTK_WINDOW (gtk_builder_get_object(gui->builder, "main"));
- gui->tabs = GTK_NOTEBOOK (gtk_builder_get_object(gui->builder, "tabs"));
- gui->drawing = GTK_DRAWING_AREA(gtk_builder_get_object(gui->builder, "drawing"));
- gtk_builder_connect_signals(gui->builder, gui);
-
+ gtk_builder_connect_signals(self->builder, self);
+ g_signal_connect(self, "delete-event", G_CALLBACK(gtk_main_quit), self);
+ g_signal_connect(self, "key-press-event", G_CALLBACK(on_key_press), self);
+ gtk_widget_reparent(aweather_gui_get_widget(self, "body"), GTK_WIDGET(self));
/* Load components */
- aweather_view_set_location(gui->view, 0, 0, -300*1000);
- g_signal_connect(gui->view, "location-changed", G_CALLBACK(on_location_changed), gui);
- site_setup(gui);
- time_setup(gui);
- opengl_setup(gui);
- return gui;
+ aweather_view_set_location(self->view, 0, 0, -300*1000);
+ g_signal_connect(self->view, "location-changed", G_CALLBACK(on_location_changed), self);
+ site_setup(self);
+ time_setup(self);
+ opengl_setup(self);
+ return self;
}
AWeatherView *aweather_gui_get_view(AWeatherGui *gui)
{
}
void aweather_gui_register_plugin(AWeatherGui *gui, AWeatherPlugin *plugin)
{
- g_message("registering plugin");
+ g_debug("AWeatherGui: register_plugin");
gui->plugins = g_list_append(gui->plugins, plugin);
}
void aweather_gui_gl_redraw(AWeatherGui *gui)
{
- g_message("redraw");
+ g_debug("AWeatherGui: gl_redraw");
GtkWidget *drawing = aweather_gui_get_widget(gui, "drawing");
gtk_widget_queue_draw(drawing);
}
typedef struct _AWeatherGuiClass AWeatherGuiClass;
struct _AWeatherGui {
- GObject parent_instance;
+ GtkWindow parent_instance;
/* instance members */
AWeatherView *view;
GtkBuilder *builder;
- GtkWindow *window;
- GtkNotebook *tabs;
- GtkDrawingArea *drawing;
GList *plugins;
};
struct _AWeatherGuiClass {
- GObjectClass parent_class;
+ GtkWindowClass parent_class;
/* class members */
};
static void aweather_view_init(AWeatherView *self)
{
- //g_message("aweather_view_init");
+ g_debug("AWeatherView: init");
/* Default values */
self->time = g_strdup("");
self->site = g_strdup("");
static GObject *aweather_view_constructor(GType gtype, guint n_properties,
GObjectConstructParam *properties)
{
- //g_message("aweather_view_constructor");
+ g_debug("AWeatherView: constructor");
GObjectClass *parent_class = G_OBJECT_CLASS(aweather_view_parent_class);
return parent_class->constructor(gtype, n_properties, properties);
}
-static void aweather_view_dispose (GObject *gobject)
+static void aweather_view_dispose(GObject *gobject)
{
- //g_message("aweather_view_dispose");
+ g_debug("AWeatherView: dispose");
/* Drop references to other GObjects */
G_OBJECT_CLASS(aweather_view_parent_class)->dispose(gobject);
}
static void aweather_view_finalize(GObject *gobject)
{
- //g_message("aweather_view_finalize");
+ g_debug("AWeatherView: finalize");
AWeatherView *self = AWEATHER_VIEW(gobject);
g_free(self->site);
G_OBJECT_CLASS(aweather_view_parent_class)->finalize(gobject);
static void aweather_view_set_property(GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
- //g_message("aweather_view_set_property");
+ g_debug("AWeatherView: set_property");
AWeatherView *self = AWEATHER_VIEW(object);
switch (property_id) {
case PROP_TIME: aweather_view_set_time(self, g_value_get_string(value)); break;
static void aweather_view_get_property(GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
- //g_message("aweather_view_get_property");
+ g_debug("AWeatherView: get_property");
AWeatherView *self = AWEATHER_VIEW(object);
switch (property_id) {
case PROP_TIME: g_value_set_string(value, aweather_view_get_time(self)); break;
static void aweather_view_class_init(AWeatherViewClass *klass)
{
- //g_message("aweather_view_class_init");
+ g_debug("AWeatherView: class_init");
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->constructor = aweather_view_constructor;
gobject_class->dispose = aweather_view_dispose;
***********/
AWeatherView *aweather_view_new()
{
- //g_message("aweather_view_new");
+ g_debug("AWeatherView: new");
return g_object_new(AWEATHER_TYPE_VIEW, NULL);
}
void aweather_view_set_time(AWeatherView *view, const char *time)
{
g_assert(AWEATHER_IS_VIEW(view));
- //g_message("aweather_view:set_time: setting time to %s", time);
+ g_debug("AWeatherView: set_time - time=%s", time);
g_free(view->time);
view->time = g_strdup(time);
_aweather_view_emit_time_changed(view);
gchar *aweather_view_get_time(AWeatherView *view)
{
g_assert(AWEATHER_IS_VIEW(view));
- //g_message("aweather_view_get_time");
+ g_debug("AWeatherView: get_time");
return view->time;
}
void aweather_view_get_location(AWeatherView *view, gdouble *x, gdouble *y, gdouble *z)
{
g_assert(AWEATHER_IS_VIEW(view));
- //g_message("aweather_view_get_location");
+ g_debug("AWeatherView: get_location");
*x = view->location[0];
*y = view->location[1];
*z = view->location[2];
void aweather_view_set_location(AWeatherView *view, gdouble x, gdouble y, gdouble z)
{
g_assert(AWEATHER_IS_VIEW(view));
- //g_message("aweather_view_set_location");
+ g_debug("AWeatherView: set_location");
view->location[0] = x;
view->location[1] = y;
view->location[2] = z;
void aweather_view_pan(AWeatherView *view, gdouble x, gdouble y, gdouble z)
{
g_assert(AWEATHER_IS_VIEW(view));
- g_message("aweather_view_pan: %f, %f, %f", x, y, z);
+ g_debug("AWeatherView: pan - x=%.0f, y=%.0f, z=%.0f", x, y, z);
view->location[0] += x;
view->location[1] += y;
view->location[2] += z;
void aweather_view_zoom(AWeatherView *view, gdouble scale)
{
g_assert(AWEATHER_IS_VIEW(view));
+ g_debug("AWeatherView: zoom");
view->location[2] *= scale;
_aweather_view_emit_location_changed(view);
}
void aweather_view_refresh(AWeatherView *view)
{
- g_message("aweather_view_refresh: ..");
+ g_debug("AWeatherView: refresh");
_aweather_view_emit_refresh(view);
}
void aweather_view_set_site(AWeatherView *view, const gchar *site)
{
g_assert(AWEATHER_IS_VIEW(view));
- //g_message("aweather_view_set_site");
+ g_debug("AWeatherView: set_site");
g_free(view->site);
view->site = g_strdup(site);
_aweather_view_emit_site_changed(view);
gchar *aweather_view_get_site(AWeatherView *view)
{
g_assert(AWEATHER_IS_VIEW(view));
- //g_message("aweather_view_get_site");
+ g_debug("AWeatherView: get_site");
return view->site;
}
GError *error = NULL;
g_file_copy_finish(G_FILE(source_object), res, &error);
if (error) {
- g_message("error copying file ([%s]->[%s]): %s",
+ g_warning("error copying file ([%s]->[%s]): %s",
url, local, error->message);
g_error_free(error);
} else {
AWeatherCacheDoneCallback callback, gpointer user_data)
{
char *name = g_file_get_basename(dst);
- g_message("Caching file %s: %s", name, reason);
+ g_debug("data: do_cache - Caching file %s: %s", name, reason);
g_free(name);
GFile *parent = g_file_get_parent(dst);
info->dst = dst;
info->user_data = user_data;
g_file_copy_async(src, dst,
- G_FILE_COPY_OVERWRITE, // GFileCopyFlags flags,
- 0, // int io_priority,
- NULL, // GCancellable *cancellable,
- NULL, // GFileProgressCallback progress_callback,
- NULL, // gpointer progress_callback_data,
- cache_file_cb, // GAsyncReadyCallback callback,
- info); // gpointer user_data
+ G_FILE_COPY_OVERWRITE, // GFileCopyFlags flags,
+ G_PRIORITY_DEFAULT_IDLE, // int io_priority,
+ NULL, // GCancellable *cancellable,
+ NULL, // GFileProgressCallback progress_callback,
+ NULL, // gpointer progress_callback_data,
+ cache_file_cb, // GAsyncReadyCallback callback,
+ info); // gpointer user_data
return;
}
#include "plugin-ridge.h"
#include "plugin-example.h"
+static gint log_levels = 0;
+
+static void log_func(const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer udata)
+{
+ if (log_level & log_levels)
+ g_log_default_handler(log_domain, log_level, message, udata);
+}
+
+static gboolean on_map(AWeatherGui *gui, GdkEvent *event, gchar *site)
+{
+ AWeatherView *view = aweather_gui_get_view(gui);
+ aweather_view_set_site(view, site);
+ return FALSE;
+}
+
/********
* Main *
********/
int main(int argc, char *argv[])
{
- gtk_init(&argc, &argv);
+ /* Arguments */
+ gint opt_debug = 6;
+ gchar *opt_site = "IND";
+ gboolean opt_auto = FALSE;
+ GOptionEntry entries[] = {
+ //long short flg type location description arg desc
+ {"debug", 'd', 0, G_OPTION_ARG_INT, &opt_debug, "Change default log level", "[1-7]"},
+ {"site", 's', 0, G_OPTION_ARG_STRING, &opt_site, "Set initial site", NULL},
+ {"auto", 'a', 0, G_OPTION_ARG_NONE, &opt_auto, "Auto update radar (todo)", NULL},
+ {NULL}
+ };
+
+ /* Init */
+ GError *error = NULL;
+ g_thread_init(NULL);
+ if (!gtk_init_with_args(&argc, &argv, "aweather", entries, NULL, &error)) {
+ g_print("%s\n", error->message);
+ g_error_free(error);
+ return -1;
+ }
gtk_gl_init(&argc, &argv);
+ /* Finish arguments */
+ log_levels = 1 << opt_debug;
+
+ /* Logging */
+ g_log_set_handler(NULL, G_LOG_LEVEL_MASK, log_func, NULL);
+
/* Set up AWeather */
AWeatherGui *gui = aweather_gui_new();
- //AWeatherView *view = aweather_gui_get_view(gui);
+ AWeatherView *view = aweather_gui_get_view(gui);
+ g_signal_connect(gui, "map-event", G_CALLBACK(on_map), opt_site);
/* Load plugins */
aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_example_new(gui)));
aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_ridge_new(gui)));
aweather_gui_register_plugin(gui, AWEATHER_PLUGIN(aweather_radar_new(gui)));
- gtk_widget_show_all(aweather_gui_get_widget(gui, "window"));
+ gtk_widget_show_all(GTK_WIDGET(gui));
gtk_main();
return 0;
***********/
AWeatherExample *aweather_example_new(AWeatherGui *gui)
{
- //g_message("aweather_view_new");
+ g_debug("AWeatherExample: new");
AWeatherExample *example = g_object_new(AWEATHER_TYPE_EXAMPLE, NULL);
example->gui = gui;
static void aweather_example_expose(AWeatherPlugin *_example)
{
AWeatherExample *example = AWEATHER_EXAMPLE(_example);
- g_message("aweather_example_expose");
+ g_debug("AWeatherExample: expose");
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity();
glOrtho(-1,1,-1,1,-10,10);
Sweep *sweep = vol->sweep[si];
if (sweep == NULL || sweep->h.elev == 0) continue;
if (sweep->h.elev != elev) {
- g_message("adding elev");
cols++;
elev = sweep->h.elev;
g_free(dir);
RSL_read_these_sweeps("all", NULL);
if (self->cur_radar) {
- g_message("Freeing radar");
+ g_debug("AWeatherRadar: load_radar - Freeing old radar");
RSL_free_radar(self->cur_radar);
}
- g_message("Allocating radar");
+ g_debug("AWeatherRadar: load_radar - Loading new radar");
Radar *radar = self->cur_radar = RSL_wsr88d_to_radar(radar_file, site);
if (radar == NULL) {
g_warning("fail to load radar: path=%s, site=%s", radar_file, site);
decompressed_t *udata = g_malloc(sizeof(decompressed_t));
udata->self = self;
udata->radar_file = decompressed;
- g_message("File updated, decompressing..");
+ g_debug("AWeatherRadar: cached_cb - File updated, decompressing..");
char *argv[] = {"wsr88ddec", path, decompressed, NULL};
GPid pid;
GError *error = NULL;
static void on_time_changed(AWeatherView *view, char *time, gpointer _self)
{
AWeatherRadar *self = AWEATHER_RADAR(_self);
- g_message("radar:setting time");
+ g_debug("AWeatherRadar: on_time_changed - setting time");
// format: http://mesonet.agron.iastate.edu/data/nexrd2/raw/KABR/KABR_20090510_0323
char *site = aweather_view_get_site(view);
char *base = "http://mesonet.agron.iastate.edu/data/";
static void on_site_changed(AWeatherView *view, char *site, gpointer _self)
{
AWeatherRadar *self = AWEATHER_RADAR(_self);
- g_message("Loading wsr88d list for %s", site);
+ g_debug("AWeatherRadar: on_site_changed - Loading wsr88d list for %s", site);
char *time = NULL;
update_times(self, site, &time);
aweather_view_set_time(view, time);
***********/
AWeatherRadar *aweather_radar_new(AWeatherGui *gui)
{
- //g_message("aweather_view_new");
+ g_debug("AWeatherRadar: new");
AWeatherRadar *self = g_object_new(AWEATHER_TYPE_RADAR, NULL);
self->gui = gui;
static void _aweather_radar_expose(AWeatherPlugin *_self)
{
AWeatherRadar *self = AWEATHER_RADAR(_self);
- g_message("radar:expose");
+ g_debug("AWeatherRadar: expose");
if (self->cur_sweep == NULL)
return;
Sweep *sweep = self->cur_sweep;
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
char *base = g_path_get_basename(filename);
- g_message("loaded image: w=%-3d h=%-3d fmt=%x px=(%02x,%02x,%02x,%02x) img=%s",
+ g_debug("AWeatherRidge: load_texture - "
+ "w=%-3d h=%-3d fmt=%x px=(%02x,%02x,%02x,%02x) img=%s",
width, height, format, pixels[0], pixels[1], pixels[2], pixels[3],
base);
g_free(base);
*************/
static void on_site_changed(AWeatherView *view, gchar *site, AWeatherRidge *self)
{
- g_message("site changed to %s", site);
+ g_debug("AWeatherRidge: on_site_changed - site=%s", site);
for (int i = 0; i < LAYER_COUNT; i++) {
gchar *base = "http://radar.weather.gov/ridge/";
gchar *path = g_strdup_printf(layers[i].fmt, site);
{
AWeatherRidge *ridge = AWEATHER_RIDGE(_ridge);
- g_message("ridge:expose");
+ g_debug("AWeatherRidge: expose");
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glColor4f(1,1,1,1);