2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <glib/gstdio.h>
23 #include <gtk/gtkgl.h>
33 #include "../aweather-location.h"
35 static void _gtk_bin_set_child(GtkBin *bin, GtkWidget *new)
37 GtkWidget *old = gtk_bin_get_child(bin);
39 gtk_widget_destroy(old);
40 gtk_container_add(GTK_CONTAINER(bin), new);
41 gtk_widget_show_all(new);
44 static gchar *_find_nearest(time_t time, GList *files,
45 gsize offset, gchar *format)
47 g_debug("RadarSite: find_nearest ...");
48 time_t nearest_time = 0;
49 char *nearest_file = NULL;
52 for (GList *cur = files; cur; cur = cur->next) {
53 gchar *file = cur->data;
54 strptime(file+offset, format, &tm);
55 if (ABS(time - mktime(&tm)) <
56 ABS(time - nearest_time)) {
58 nearest_time = mktime(&tm);
62 g_debug("RadarSite: find_nearest = %s", nearest_file);
64 return g_strdup(nearest_file);
81 GritsMarker *marker; // Map marker for grits
82 gpointer *marker_ref; // Reference to maker
84 /* Stuff from the parents */
92 RadarSiteStatus status; // Loading status for the site
94 AWeatherLevel2 *level2; // The Level2 structure for the current volume
95 gpointer level2_ref; // GritsViewer reference to the added radar
98 time_t time; // Current timestamp of the level2
99 gchar *message; // Error message set while updating
100 guint time_id; // "time-changed" callback ID
101 guint refresh_id; // "refresh" callback ID
102 guint location_id; // "locaiton-changed" callback ID
105 /* format: http://mesonet.agron.iastate.edu/data/nexrd2/raw/KABR/KABR_20090510_0323 */
106 void _site_update_loading(gchar *file, goffset cur,
107 goffset total, gpointer _site)
109 RadarSite *site = _site;
110 GtkWidget *progress_bar = gtk_bin_get_child(GTK_BIN(site->config));
111 double percent = (double)cur/total;
112 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), MIN(percent, 1.0));
113 gchar *msg = g_strdup_printf("Loading... %5.1f%% (%.2f/%.2f MB)",
114 percent*100, (double)cur/1000000, (double)total/1000000);
115 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), msg);
118 gboolean _site_update_end(gpointer _site)
120 RadarSite *site = _site;
122 g_warning("RadarSite: update_end - %s", site->message);
123 _gtk_bin_set_child(GTK_BIN(site->config),
124 gtk_label_new(site->message));
126 _gtk_bin_set_child(GTK_BIN(site->config),
127 aweather_level2_get_config(site->level2));
129 site->status = STATUS_LOADED;
132 gpointer _site_update_thread(gpointer _site)
134 RadarSite *site = _site;
135 g_debug("RadarSite: update_thread - %s", site->city->code);
136 site->message = NULL;
138 gboolean offline = grits_viewer_get_offline(site->viewer);
139 gchar *nexrad_url = grits_prefs_get_string(site->prefs,
140 "aweather/nexrad_url", NULL);
142 /* Find nearest volume (temporally) */
143 g_debug("RadarSite: update_thread - find nearest - %s", site->city->code);
144 gchar *dir_list = g_strconcat(nexrad_url, "/", site->city->code,
145 "/", "dir.list", NULL);
146 GList *files = grits_http_available(site->http,
147 "^K\\w{3}_\\d{8}_\\d{4}$", site->city->code,
148 "\\d+ (.*)", (offline ? NULL : dir_list));
150 gchar *nearest = _find_nearest(site->time, files, 5, "%Y%m%d_%H%M");
151 g_list_foreach(files, (GFunc)g_free, NULL);
154 site->message = "No suitable files found";
158 /* Fetch new volume */
159 g_debug("RadarSite: update_thread - fetch");
160 gchar *local = g_strconcat(site->city->code, "/", nearest, NULL);
161 gchar *uri = g_strconcat(nexrad_url, "/", local, NULL);
162 gchar *file = grits_http_fetch(site->http, uri, local,
163 offline ? GRITS_LOCAL : GRITS_UPDATE,
164 _site_update_loading, site);
170 site->message = "Fetch failed";
174 /* Load and add new volume */
175 g_debug("RadarSite: update_thread - load - %s", site->city->code);
176 site->level2 = aweather_level2_new_from_file(
177 file, site->city->code, colormaps);
180 site->message = "Load failed";
183 GRITS_OBJECT(site->level2)->hidden = site->hidden;
184 site->level2_ref = grits_viewer_add(site->viewer,
185 GRITS_OBJECT(site->level2), GRITS_LEVEL_WORLD, TRUE);
188 g_idle_add(_site_update_end, site);
191 void _site_update(RadarSite *site)
193 if (site->status == STATUS_LOADING)
195 site->status = STATUS_LOADING;
197 site->time = grits_viewer_get_time(site->viewer);
198 g_debug("RadarSite: update %s - %d",
199 site->city->code, (gint)site->time);
201 /* Add a progress bar */
202 GtkWidget *progress = gtk_progress_bar_new();
203 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "Loading...");
204 _gtk_bin_set_child(GTK_BIN(site->config), progress);
206 /* Remove old volume */
207 g_debug("RadarSite: update - remove - %s", site->city->code);
208 if (site->level2_ref) {
210 grits_viewer_remove(site->viewer, site->level2_ref);
211 site->level2_ref = NULL;
214 /* Fork loading right away so updating the
215 * list of times doesn't take too long */
216 g_thread_create(_site_update_thread, site, FALSE, NULL);
219 /* RadarSite methods */
220 void radar_site_unload(RadarSite *site)
222 if (site->status != STATUS_LOADED)
223 return; // Abort if it's still loading
225 g_debug("RadarSite: unload %s", site->city->code);
228 g_signal_handler_disconnect(site->viewer, site->time_id);
229 if (site->refresh_id)
230 g_signal_handler_disconnect(site->viewer, site->refresh_id);
234 gtk_widget_destroy(site->config);
237 if (site->level2_ref) {
239 grits_viewer_remove(site->viewer, site->level2_ref);
240 site->level2_ref = NULL;
243 site->status = STATUS_UNLOADED;
246 void radar_site_load(RadarSite *site)
248 g_debug("RadarSite: load %s", site->city->code);
251 site->config = gtk_alignment_new(0, 0, 1, 1);
252 g_object_set_data(G_OBJECT(site->config), "site", site);
253 gtk_notebook_append_page(GTK_NOTEBOOK(site->pconfig), site->config,
254 gtk_label_new(site->city->name));
255 gtk_widget_show_all(site->config);
257 /* Set up radar loading */
258 site->time_id = g_signal_connect_swapped(site->viewer, "time-changed",
259 G_CALLBACK(_site_update), site);
260 site->refresh_id = g_signal_connect_swapped(site->viewer, "refresh",
261 G_CALLBACK(_site_update), site);
265 void _site_on_location_changed(GritsViewer *viewer,
266 gdouble lat, gdouble lon, gdouble elev,
269 static gdouble min_dist = EARTH_R / 30;
270 RadarSite *site = _site;
272 /* Calculate distance, could cache xyz values */
273 gdouble eye_xyz[3], site_xyz[3];
274 lle2xyz(lat, lon, elev, &eye_xyz[0], &eye_xyz[1], &eye_xyz[2]);
275 lle2xyz(site->city->pos.lat, site->city->pos.lon, site->city->pos.elev,
276 &site_xyz[0], &site_xyz[1], &site_xyz[2]);
277 gdouble dist = distd(site_xyz, eye_xyz);
279 /* Load or unload the site if necessasairy */
280 if (dist <= min_dist && dist < elev*1.25 && site->status == STATUS_UNLOADED)
281 radar_site_load(site);
282 else if (dist > 2*min_dist && site->status != STATUS_UNLOADED)
283 radar_site_unload(site);
286 gboolean _site_add_marker(gpointer _site)
288 RadarSite *site = _site;
289 site->marker = grits_marker_new(site->city->name);
290 GRITS_OBJECT(site->marker)->center = site->city->pos;
291 GRITS_OBJECT(site->marker)->lod = EARTH_R*site->city->lod;
292 site->marker_ref = grits_viewer_add(site->viewer,
293 GRITS_OBJECT(site->marker), GRITS_LEVEL_OVERLAY, FALSE);
296 RadarSite *radar_site_new(city_t *city, GtkWidget *pconfig,
297 GritsViewer *viewer, GritsPrefs *prefs, GritsHttp *http)
299 RadarSite *site = g_new0(RadarSite, 1);
300 site->viewer = g_object_ref(viewer);
301 site->prefs = g_object_ref(prefs);
303 site->http = grits_http_new(G_DIR_SEPARATOR_S
304 "nexrad" G_DIR_SEPARATOR_S
305 "level2" G_DIR_SEPARATOR_S);
307 site->pconfig = pconfig;
310 g_idle_add_full(G_PRIORITY_LOW, _site_add_marker, site, NULL);
312 /* Connect signals */
313 site->location_id = g_signal_connect(viewer, "location-changed",
314 G_CALLBACK(_site_on_location_changed), site);
318 void radar_site_free(RadarSite *site)
320 radar_site_unload(site);
321 grits_viewer_remove(site->viewer, site->marker_ref);
322 if (site->location_id)
323 g_signal_handler_disconnect(site->viewer, site->location_id);
324 grits_http_free(site->http);
325 g_object_unref(site->viewer);
326 g_object_unref(site->prefs);
334 #define CONUS_NORTH 50.406626367301044
335 #define CONUS_WEST -127.620375523875420
336 #define CONUS_WIDTH 3400.0
337 #define CONUS_HEIGHT 1600.0
338 #define CONUS_DEG_PER_PX 0.017971305190311
345 const gchar *message;
346 GStaticMutex loading;
350 gpointer *tile_ref[2];
352 guint time_id; // "time-changed" callback ID
353 guint refresh_id; // "refresh" callback ID
356 void _conus_update_loading(gchar *file, goffset cur,
357 goffset total, gpointer _conus)
359 RadarConus *conus = _conus;
360 GtkWidget *progress_bar = gtk_bin_get_child(GTK_BIN(conus->config));
361 double percent = (double)cur/total;
362 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), MIN(percent, 1.0));
363 gchar *msg = g_strdup_printf("Loading... %5.1f%% (%.2f/%.2f MB)",
364 percent*100, (double)cur/1000000, (double)total/1000000);
365 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), msg);
369 /* Copy images to graphics memory */
370 static void _conus_update_end_copy(GritsTile *tile, guchar *pixels)
373 tile->data = g_new0(guint, 1);
374 glGenTextures(1, tile->data);
377 guint *tex = tile->data;
378 glBindTexture(GL_TEXTURE_2D, *tex);
380 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
381 glPixelStorei(GL_PACK_ALIGNMENT, 1);
382 glTexImage2D(GL_TEXTURE_2D, 0, 4, 2048, 2048, 0,
383 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
384 glTexSubImage2D(GL_TEXTURE_2D, 0, 1,1, CONUS_WIDTH/2,CONUS_HEIGHT,
385 GL_RGBA, GL_UNSIGNED_BYTE, pixels);
386 tile->coords.n = 1.0/(CONUS_WIDTH/2);
387 tile->coords.w = 1.0/ CONUS_HEIGHT;
388 tile->coords.s = tile->coords.n + CONUS_HEIGHT / 2048.0;
389 tile->coords.e = tile->coords.w + (CONUS_WIDTH/2) / 2048.0;
390 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
391 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
392 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
393 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
397 /* Split the pixbuf into east and west halves (with 2K sides)
398 * Also map the pixbuf's alpha values */
399 static void _conus_update_end_split(guchar *pixels, guchar *west, guchar *east,
400 gint width, gint height, gint pxsize)
402 g_debug("Conus: update_end_split");
403 guchar *out[] = {west,east};
404 const guchar alphamap[][4] = {
405 {0x04, 0xe9, 0xe7, 0x30},
406 {0x01, 0x9f, 0xf4, 0x60},
407 {0x03, 0x00, 0xf4, 0x90},
409 for (int y = 0; y < height; y++)
410 for (int x = 0; x < width; x++) {
411 gint subx = x % (width/2);
412 gint idx = x / (width/2);
413 guchar *src = &pixels[(y*width+x)*pxsize];
414 guchar *dst = &out[idx][(y*(width/2)+subx)*4];
424 for (int j = 0; j < G_N_ELEMENTS(alphamap); j++)
425 if (src[0] == alphamap[j][0] &&
426 src[1] == alphamap[j][1] &&
427 src[2] == alphamap[j][2])
428 dst[3] = alphamap[j][3];
433 gboolean _conus_update_end(gpointer _conus)
435 RadarConus *conus = _conus;
436 g_debug("Conus: update_end");
438 /* Check error status */
439 if (conus->message) {
440 g_warning("Conus: update_end - %s", conus->message);
441 _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new(conus->message));
445 /* Load and pixbuf */
446 GError *error = NULL;
447 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(conus->path, &error);
448 if (!pixbuf || error) {
449 g_warning("Conus: update_end - error loading pixbuf");
450 _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new("Error loading pixbuf"));
451 g_remove(conus->path);
455 /* Split pixels into east/west parts */
456 guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
457 gint width = gdk_pixbuf_get_width(pixbuf);
458 gint height = gdk_pixbuf_get_height(pixbuf);
459 gint pxsize = gdk_pixbuf_get_has_alpha(pixbuf) ? 4 : 3;
460 guchar *pixels_west = g_malloc(4*(width/2)*height);
461 guchar *pixels_east = g_malloc(4*(width/2)*height);
462 _conus_update_end_split(pixels, pixels_west, pixels_east,
463 width, height, pxsize);
464 g_object_unref(pixbuf);
466 /* Copy pixels to graphics memory */
467 _conus_update_end_copy(conus->tile[0], pixels_west);
468 _conus_update_end_copy(conus->tile[1], pixels_east);
473 gchar *label = g_path_get_basename(conus->path);
474 _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new(label));
475 gtk_widget_queue_draw(GTK_WIDGET(conus->viewer));
480 g_static_mutex_unlock(&conus->loading);
484 gpointer _conus_update_thread(gpointer _conus)
486 RadarConus *conus = _conus;
487 conus->message = NULL;
490 g_debug("Conus: update_thread - nearest");
491 gboolean offline = grits_viewer_get_offline(conus->viewer);
492 gchar *conus_url = "http://radar.weather.gov/Conus/RadarImg/";
493 GList *files = grits_http_available(conus->http,
494 "^Conus_[^\"]*_N0Ronly.gif$", "",
495 NULL, (offline ? NULL : conus_url));
496 gchar *nearest = _find_nearest(conus->time, files, 6, "%Y%m%d_%H%M");
497 g_list_foreach(files, (GFunc)g_free, NULL);
500 conus->message = "No suitable files";
504 /* Fetch the image */
505 g_debug("Conus: update_thread - fetch");
506 gchar *uri = g_strconcat(conus_url, nearest, NULL);
507 conus->path = grits_http_fetch(conus->http, uri, nearest, GRITS_ONCE,
508 _conus_update_loading, conus);
512 conus->message = "Fetch failed";
517 g_debug("Conus: update_thread - done");
518 g_idle_add(_conus_update_end, conus);
522 void _conus_update(RadarConus *conus)
524 if (!g_static_mutex_trylock(&conus->loading))
526 conus->time = grits_viewer_get_time(conus->viewer);
527 g_debug("Conus: update - %d",
530 /* Add a progress bar */
531 GtkWidget *progress = gtk_progress_bar_new();
532 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "Loading...");
533 _gtk_bin_set_child(GTK_BIN(conus->config), progress);
535 g_thread_create(_conus_update_thread, conus, FALSE, NULL);
538 RadarConus *radar_conus_new(GtkWidget *pconfig,
539 GritsViewer *viewer, GritsHttp *http)
541 RadarConus *conus = g_new0(RadarConus, 1);
542 conus->viewer = g_object_ref(viewer);
544 conus->config = gtk_alignment_new(0, 0, 1, 1);
545 g_static_mutex_init(&conus->loading);
547 gdouble south = CONUS_NORTH - CONUS_DEG_PER_PX*CONUS_HEIGHT;
548 gdouble east = CONUS_WEST + CONUS_DEG_PER_PX*CONUS_WIDTH;
549 gdouble mid = CONUS_WEST + CONUS_DEG_PER_PX*CONUS_WIDTH/2;
550 conus->tile[0] = grits_tile_new(NULL, CONUS_NORTH, south, mid, CONUS_WEST);
551 conus->tile[1] = grits_tile_new(NULL, CONUS_NORTH, south, east, mid);
552 conus->tile[0]->zindex = 2;
553 conus->tile[1]->zindex = 1;
554 conus->tile_ref[0] = grits_viewer_add(viewer,
555 GRITS_OBJECT(conus->tile[0]), GRITS_LEVEL_WORLD, TRUE);
556 conus->tile_ref[1] = grits_viewer_add(viewer,
557 GRITS_OBJECT(conus->tile[1]), GRITS_LEVEL_WORLD, TRUE);
559 conus->time_id = g_signal_connect_swapped(viewer, "time-changed",
560 G_CALLBACK(_conus_update), conus);
561 conus->refresh_id = g_signal_connect_swapped(viewer, "refresh",
562 G_CALLBACK(_conus_update), conus);
564 g_object_set_data(G_OBJECT(conus->config), "conus", conus);
565 gtk_notebook_append_page(GTK_NOTEBOOK(pconfig), conus->config,
566 gtk_label_new("Conus"));
568 _conus_update(conus);
572 void radar_conus_free(RadarConus *conus)
574 g_signal_handler_disconnect(conus->viewer, conus->time_id);
575 g_signal_handler_disconnect(conus->viewer, conus->refresh_id);
577 for (int i = 0; i < 2; i++) {
578 GritsTile *tile = conus->tile[i];
579 gpointer ref = conus->tile_ref[i];
581 glDeleteTextures(1, tile->data);
584 grits_viewer_remove(conus->viewer, ref);
587 g_object_unref(conus->viewer);
592 /********************
594 ********************/
595 static void _draw_hud(GritsCallback *callback, GritsOpenGL *opengl, gpointer _self)
597 g_debug("GritsPluginRadar: _draw_hud");
599 glMatrixMode(GL_MODELVIEW ); glLoadIdentity();
600 glMatrixMode(GL_PROJECTION); glLoadIdentity();
601 glDisable(GL_TEXTURE_2D);
602 glDisable(GL_ALPHA_TEST);
603 glDisable(GL_CULL_FACE);
604 glDisable(GL_LIGHTING);
605 glEnable(GL_COLOR_MATERIAL);
608 gpointer name, _site;
609 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(_self);
610 g_hash_table_iter_init(&iter, self->sites);
611 while (g_hash_table_iter_next(&iter, &name, &_site)) {
612 /* Pick correct colormaps */
613 RadarSite *site = _site;
614 if (site->hidden || !site->level2)
616 AWeatherColormap *colormap = site->level2->sweep_colors;
618 /* Print the color table */
620 int len = colormap->len;
621 for (int i = 0; i < len; i++) {
622 glColor4ubv(colormap->data[i]);
623 glVertex3f(-1.0, (float)((i ) - len/2)/(len/2), 0.0); // bot left
624 glVertex3f(-1.0, (float)((i+1) - len/2)/(len/2), 0.0); // top left
625 glVertex3f(-0.9, (float)((i+1) - len/2)/(len/2), 0.0); // top right
626 glVertex3f(-0.9, (float)((i ) - len/2)/(len/2), 0.0); // bot right
632 static void _load_colormap(gchar *filename, AWeatherColormap *cm)
634 g_debug("GritsPluginRadar: _load_colormap - %s", filename);
635 FILE *file = g_fopen(filename, "r");
637 g_error("GritsPluginRadar: open failed");
639 GArray *array = g_array_sized_new(FALSE, TRUE, sizeof(color), 256);
640 fgets(cm->name, sizeof(cm->name), file);
641 fscanf(file, "%f\n", &cm->scale);
642 fscanf(file, "%f\n", &cm->shift);
643 while (fscanf(file, "%hhd %hhd %hhd %hhd\n",
644 &color[0], &color[1], &color[2], &color[3]) == 4)
645 g_array_append_val(array, color);
646 cm->len = (gint )array->len;
647 cm->data = (void*)array->data;
648 g_array_free(array, FALSE);
651 static void _update_hidden(GtkNotebook *notebook,
652 GtkNotebookPage *page, guint page_num, gpointer viewer)
654 g_debug("GritsPluginRadar: _update_hidden - 0..%d = %d",
655 gtk_notebook_get_n_pages(notebook), page_num);
657 for (gint i = 0; i < gtk_notebook_get_n_pages(notebook); i++) {
658 gboolean is_hidden = (i != page_num);
659 GtkWidget *config = gtk_notebook_get_nth_page(notebook, i);
660 RadarConus *conus = g_object_get_data(G_OBJECT(config), "conus");
661 RadarSite *site = g_object_get_data(G_OBJECT(config), "site");
665 GRITS_OBJECT(conus->tile[0])->hidden = is_hidden;
666 GRITS_OBJECT(conus->tile[1])->hidden = is_hidden;
668 site->hidden = is_hidden;
670 GRITS_OBJECT(site->level2)->hidden = is_hidden;
672 g_warning("GritsPluginRadar: _update_hidden - no site or counus found");
675 gtk_widget_queue_draw(GTK_WIDGET(viewer));
679 GritsPluginRadar *grits_plugin_radar_new(GritsViewer *viewer, GritsPrefs *prefs)
681 /* TODO: move to constructor if possible */
682 g_debug("GritsPluginRadar: new");
683 GritsPluginRadar *self = g_object_new(GRITS_TYPE_PLUGIN_RADAR, NULL);
684 self->viewer = viewer;
687 /* Setup page switching */
688 g_signal_connect(self->config, "switch-page",
689 G_CALLBACK(_update_hidden), viewer);
692 GritsCallback *hud_cb = grits_callback_new(_draw_hud, self);
693 self->hud_ref = grits_viewer_add(viewer, GRITS_OBJECT(hud_cb), GRITS_LEVEL_HUD, FALSE);
696 self->conus = radar_conus_new(self->config, self->viewer, self->conus_http);
698 /* Load radar sites */
699 for (city_t *city = cities; city->type; city++) {
700 if (city->type != LOCATION_CITY)
702 RadarSite *site = radar_site_new(city, self->config,
703 self->viewer, self->prefs, self->sites_http);
704 g_hash_table_insert(self->sites, city->code, site);
710 static GtkWidget *grits_plugin_radar_get_config(GritsPlugin *_self)
712 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(_self);
717 static void grits_plugin_radar_plugin_init(GritsPluginInterface *iface);
718 G_DEFINE_TYPE_WITH_CODE(GritsPluginRadar, grits_plugin_radar, G_TYPE_OBJECT,
719 G_IMPLEMENT_INTERFACE(GRITS_TYPE_PLUGIN,
720 grits_plugin_radar_plugin_init));
721 static void grits_plugin_radar_plugin_init(GritsPluginInterface *iface)
723 g_debug("GritsPluginRadar: plugin_init");
724 /* Add methods to the interface */
725 iface->get_config = grits_plugin_radar_get_config;
727 static void grits_plugin_radar_init(GritsPluginRadar *self)
729 g_debug("GritsPluginRadar: class_init");
731 self->sites_http = grits_http_new(G_DIR_SEPARATOR_S
732 "nexrad" G_DIR_SEPARATOR_S
733 "level2" G_DIR_SEPARATOR_S);
734 self->conus_http = grits_http_new(G_DIR_SEPARATOR_S
735 "nexrad" G_DIR_SEPARATOR_S
736 "conus" G_DIR_SEPARATOR_S);
737 self->sites = g_hash_table_new_full(g_str_hash, g_str_equal,
738 NULL, (GDestroyNotify)radar_site_free);
739 self->config = gtk_notebook_new();
742 for (int i = 0; colormaps[i].file; i++) {
743 gchar *file = g_build_filename(PKGDATADIR,
744 "colors", colormaps[i].file, NULL);
745 _load_colormap(file, &colormaps[i]);
749 /* Need to position on the top because of Win32 bug */
750 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(self->config), GTK_POS_BOTTOM);
752 static void grits_plugin_radar_dispose(GObject *gobject)
754 g_debug("GritsPluginRadar: dispose");
755 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(gobject);
756 grits_viewer_remove(self->viewer, self->hud_ref);
757 radar_conus_free(self->conus);
758 /* Drop references */
759 G_OBJECT_CLASS(grits_plugin_radar_parent_class)->dispose(gobject);
761 static void grits_plugin_radar_finalize(GObject *gobject)
763 g_debug("GritsPluginRadar: finalize");
764 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(gobject);
766 grits_http_free(self->conus_http);
767 grits_http_free(self->sites_http);
768 g_hash_table_destroy(self->sites);
769 gtk_widget_destroy(self->config);
770 G_OBJECT_CLASS(grits_plugin_radar_parent_class)->finalize(gobject);
773 static void grits_plugin_radar_class_init(GritsPluginRadarClass *klass)
775 g_debug("GritsPluginRadar: class_init");
776 GObjectClass *gobject_class = (GObjectClass*)klass;
777 gobject_class->dispose = grits_plugin_radar_dispose;
778 gobject_class->finalize = grits_plugin_radar_finalize;