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
83 /* Stuff from the parents */
91 RadarSiteStatus status; // Loading status for the site
93 AWeatherLevel2 *level2; // The Level2 structure for the current volume
96 time_t time; // Current timestamp of the level2
97 gchar *message; // Error message set while updating
98 guint time_id; // "time-changed" callback ID
99 guint refresh_id; // "refresh" callback ID
100 guint location_id; // "locaiton-changed" callback ID
103 /* format: http://mesonet.agron.iastate.edu/data/nexrd2/raw/KABR/KABR_20090510_0323 */
104 void _site_update_loading(gchar *file, goffset cur,
105 goffset total, gpointer _site)
107 RadarSite *site = _site;
108 GtkWidget *progress_bar = gtk_bin_get_child(GTK_BIN(site->config));
109 double percent = (double)cur/total;
110 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), MIN(percent, 1.0));
111 gchar *msg = g_strdup_printf("Loading... %5.1f%% (%.2f/%.2f MB)",
112 percent*100, (double)cur/1000000, (double)total/1000000);
113 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), msg);
116 gboolean _site_update_end(gpointer _site)
118 RadarSite *site = _site;
120 g_warning("RadarSite: update_end - %s", site->message);
121 _gtk_bin_set_child(GTK_BIN(site->config),
122 gtk_label_new(site->message));
124 _gtk_bin_set_child(GTK_BIN(site->config),
125 aweather_level2_get_config(site->level2));
127 site->status = STATUS_LOADED;
130 gpointer _site_update_thread(gpointer _site)
132 RadarSite *site = _site;
133 g_debug("RadarSite: update_thread - %s", site->city->code);
134 site->message = NULL;
136 gboolean offline = grits_viewer_get_offline(site->viewer);
137 gchar *nexrad_url = grits_prefs_get_string(site->prefs,
138 "aweather/nexrad_url", NULL);
140 /* Find nearest volume (temporally) */
141 g_debug("RadarSite: update_thread - find nearest - %s", site->city->code);
142 gchar *dir_list = g_strconcat(nexrad_url, "/", site->city->code,
143 "/", "dir.list", NULL);
144 GList *files = grits_http_available(site->http,
145 "^K\\w{3}_\\d{8}_\\d{4}$", site->city->code,
146 "\\d+ (.*)", (offline ? NULL : dir_list));
148 gchar *nearest = _find_nearest(site->time, files, 5, "%Y%m%d_%H%M");
149 g_list_foreach(files, (GFunc)g_free, NULL);
152 site->message = "No suitable files found";
156 /* Fetch new volume */
157 g_debug("RadarSite: update_thread - fetch");
158 gchar *local = g_strconcat(site->city->code, "/", nearest, NULL);
159 gchar *uri = g_strconcat(nexrad_url, "/", local, NULL);
160 gchar *file = grits_http_fetch(site->http, uri, local,
161 offline ? GRITS_LOCAL : GRITS_UPDATE,
162 _site_update_loading, site);
168 site->message = "Fetch failed";
172 /* Load and add new volume */
173 g_debug("RadarSite: update_thread - load - %s", site->city->code);
174 site->level2 = aweather_level2_new_from_file(
175 file, site->city->code, colormaps);
178 site->message = "Load failed";
181 grits_object_hide(GRITS_OBJECT(site->level2), site->hidden);
182 grits_viewer_add(site->viewer, GRITS_OBJECT(site->level2),
183 GRITS_LEVEL_WORLD, TRUE);
186 g_idle_add(_site_update_end, site);
189 void _site_update(RadarSite *site)
191 if (site->status == STATUS_LOADING)
193 site->status = STATUS_LOADING;
195 site->time = grits_viewer_get_time(site->viewer);
196 g_debug("RadarSite: update %s - %d",
197 site->city->code, (gint)site->time);
199 /* Add a progress bar */
200 GtkWidget *progress = gtk_progress_bar_new();
201 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "Loading...");
202 _gtk_bin_set_child(GTK_BIN(site->config), progress);
204 /* Remove old volume */
205 g_debug("RadarSite: update - remove - %s", site->city->code);
207 grits_viewer_remove(site->viewer, site->level2);
211 /* Fork loading right away so updating the
212 * list of times doesn't take too long */
213 g_thread_create(_site_update_thread, site, FALSE, NULL);
216 /* RadarSite methods */
217 void radar_site_unload(RadarSite *site)
219 if (site->status != STATUS_LOADED)
220 return; // Abort if it's still loading
222 g_debug("RadarSite: unload %s", site->city->code);
225 g_signal_handler_disconnect(site->viewer, site->time_id);
226 if (site->refresh_id)
227 g_signal_handler_disconnect(site->viewer, site->refresh_id);
231 gtk_widget_destroy(site->config);
235 grits_viewer_remove(site->viewer, site->level2);
239 site->status = STATUS_UNLOADED;
242 void radar_site_load(RadarSite *site)
244 g_debug("RadarSite: load %s", site->city->code);
247 site->config = gtk_alignment_new(0, 0, 1, 1);
248 g_object_set_data(G_OBJECT(site->config), "site", site);
249 gtk_notebook_append_page(GTK_NOTEBOOK(site->pconfig), site->config,
250 gtk_label_new(site->city->name));
251 gtk_widget_show_all(site->config);
253 /* Set up radar loading */
254 site->time_id = g_signal_connect_swapped(site->viewer, "time-changed",
255 G_CALLBACK(_site_update), site);
256 site->refresh_id = g_signal_connect_swapped(site->viewer, "refresh",
257 G_CALLBACK(_site_update), site);
261 void _site_on_location_changed(GritsViewer *viewer,
262 gdouble lat, gdouble lon, gdouble elev,
265 static gdouble min_dist = EARTH_R / 30;
266 RadarSite *site = _site;
268 /* Calculate distance, could cache xyz values */
269 gdouble eye_xyz[3], site_xyz[3];
270 lle2xyz(lat, lon, elev, &eye_xyz[0], &eye_xyz[1], &eye_xyz[2]);
271 lle2xyz(site->city->pos.lat, site->city->pos.lon, site->city->pos.elev,
272 &site_xyz[0], &site_xyz[1], &site_xyz[2]);
273 gdouble dist = distd(site_xyz, eye_xyz);
275 /* Load or unload the site if necessasairy */
276 if (dist <= min_dist && dist < elev*1.25 && site->status == STATUS_UNLOADED)
277 radar_site_load(site);
278 else if (dist > 2*min_dist && site->status != STATUS_UNLOADED)
279 radar_site_unload(site);
282 gboolean _site_add_marker(gpointer _site)
284 RadarSite *site = _site;
285 site->marker = grits_marker_new(site->city->name);
286 GRITS_OBJECT(site->marker)->center = site->city->pos;
287 GRITS_OBJECT(site->marker)->lod = EARTH_R*site->city->lod;
288 grits_viewer_add(site->viewer, GRITS_OBJECT(site->marker),
289 GRITS_LEVEL_OVERLAY, FALSE);
292 RadarSite *radar_site_new(city_t *city, GtkWidget *pconfig,
293 GritsViewer *viewer, GritsPrefs *prefs, GritsHttp *http)
295 RadarSite *site = g_new0(RadarSite, 1);
296 site->viewer = g_object_ref(viewer);
297 site->prefs = g_object_ref(prefs);
299 site->http = grits_http_new(G_DIR_SEPARATOR_S
300 "nexrad" G_DIR_SEPARATOR_S
301 "level2" G_DIR_SEPARATOR_S);
303 site->pconfig = pconfig;
306 g_idle_add_full(G_PRIORITY_LOW, _site_add_marker, site, NULL);
308 /* Connect signals */
309 site->location_id = g_signal_connect(viewer, "location-changed",
310 G_CALLBACK(_site_on_location_changed), site);
314 void radar_site_free(RadarSite *site)
316 radar_site_unload(site);
317 grits_viewer_remove(site->viewer, site->marker);
318 if (site->location_id)
319 g_signal_handler_disconnect(site->viewer, site->location_id);
320 grits_http_free(site->http);
321 g_object_unref(site->viewer);
322 g_object_unref(site->prefs);
330 #define CONUS_NORTH 50.406626367301044
331 #define CONUS_WEST -127.620375523875420
332 #define CONUS_WIDTH 3400.0
333 #define CONUS_HEIGHT 1600.0
334 #define CONUS_DEG_PER_PX 0.017971305190311
341 const gchar *message;
342 GStaticMutex loading;
347 guint time_id; // "time-changed" callback ID
348 guint refresh_id; // "refresh" callback ID
351 void _conus_update_loading(gchar *file, goffset cur,
352 goffset total, gpointer _conus)
354 RadarConus *conus = _conus;
355 GtkWidget *progress_bar = gtk_bin_get_child(GTK_BIN(conus->config));
356 double percent = (double)cur/total;
357 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), MIN(percent, 1.0));
358 gchar *msg = g_strdup_printf("Loading... %5.1f%% (%.2f/%.2f MB)",
359 percent*100, (double)cur/1000000, (double)total/1000000);
360 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), msg);
364 /* Copy images to graphics memory */
365 static void _conus_update_end_copy(GritsTile *tile, guchar *pixels)
368 tile->data = g_new0(guint, 1);
369 glGenTextures(1, tile->data);
372 guint *tex = tile->data;
373 glBindTexture(GL_TEXTURE_2D, *tex);
375 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
376 glPixelStorei(GL_PACK_ALIGNMENT, 1);
377 glTexImage2D(GL_TEXTURE_2D, 0, 4, 2048, 2048, 0,
378 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
379 glTexSubImage2D(GL_TEXTURE_2D, 0, 1,1, CONUS_WIDTH/2,CONUS_HEIGHT,
380 GL_RGBA, GL_UNSIGNED_BYTE, pixels);
381 tile->coords.n = 1.0/(CONUS_WIDTH/2);
382 tile->coords.w = 1.0/ CONUS_HEIGHT;
383 tile->coords.s = tile->coords.n + CONUS_HEIGHT / 2048.0;
384 tile->coords.e = tile->coords.w + (CONUS_WIDTH/2) / 2048.0;
385 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
386 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
387 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
388 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
392 /* Split the pixbuf into east and west halves (with 2K sides)
393 * Also map the pixbuf's alpha values */
394 static void _conus_update_end_split(guchar *pixels, guchar *west, guchar *east,
395 gint width, gint height, gint pxsize)
397 g_debug("Conus: update_end_split");
398 guchar *out[] = {west,east};
399 const guchar alphamap[][4] = {
400 {0x04, 0xe9, 0xe7, 0x30},
401 {0x01, 0x9f, 0xf4, 0x60},
402 {0x03, 0x00, 0xf4, 0x90},
404 for (int y = 0; y < height; y++)
405 for (int x = 0; x < width; x++) {
406 gint subx = x % (width/2);
407 gint idx = x / (width/2);
408 guchar *src = &pixels[(y*width+x)*pxsize];
409 guchar *dst = &out[idx][(y*(width/2)+subx)*4];
419 for (int j = 0; j < G_N_ELEMENTS(alphamap); j++)
420 if (src[0] == alphamap[j][0] &&
421 src[1] == alphamap[j][1] &&
422 src[2] == alphamap[j][2])
423 dst[3] = alphamap[j][3];
428 gboolean _conus_update_end(gpointer _conus)
430 RadarConus *conus = _conus;
431 g_debug("Conus: update_end");
433 /* Check error status */
434 if (conus->message) {
435 g_warning("Conus: update_end - %s", conus->message);
436 _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new(conus->message));
440 /* Load and pixbuf */
441 GError *error = NULL;
442 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(conus->path, &error);
443 if (!pixbuf || error) {
444 g_warning("Conus: update_end - error loading pixbuf");
445 _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new("Error loading pixbuf"));
446 g_remove(conus->path);
450 /* Split pixels into east/west parts */
451 guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
452 gint width = gdk_pixbuf_get_width(pixbuf);
453 gint height = gdk_pixbuf_get_height(pixbuf);
454 gint pxsize = gdk_pixbuf_get_has_alpha(pixbuf) ? 4 : 3;
455 guchar *pixels_west = g_malloc(4*(width/2)*height);
456 guchar *pixels_east = g_malloc(4*(width/2)*height);
457 _conus_update_end_split(pixels, pixels_west, pixels_east,
458 width, height, pxsize);
459 g_object_unref(pixbuf);
461 /* Copy pixels to graphics memory */
462 _conus_update_end_copy(conus->tile[0], pixels_west);
463 _conus_update_end_copy(conus->tile[1], pixels_east);
468 gchar *label = g_path_get_basename(conus->path);
469 _gtk_bin_set_child(GTK_BIN(conus->config), gtk_label_new(label));
470 gtk_widget_queue_draw(GTK_WIDGET(conus->viewer));
475 g_static_mutex_unlock(&conus->loading);
479 gpointer _conus_update_thread(gpointer _conus)
481 RadarConus *conus = _conus;
482 conus->message = NULL;
485 g_debug("Conus: update_thread - nearest");
486 gboolean offline = grits_viewer_get_offline(conus->viewer);
487 gchar *conus_url = "http://radar.weather.gov/Conus/RadarImg/";
488 GList *files = grits_http_available(conus->http,
489 "^Conus_[^\"]*_N0Ronly.gif$", "",
490 NULL, (offline ? NULL : conus_url));
491 gchar *nearest = _find_nearest(conus->time, files, 6, "%Y%m%d_%H%M");
492 g_list_foreach(files, (GFunc)g_free, NULL);
495 conus->message = "No suitable files";
499 /* Fetch the image */
500 g_debug("Conus: update_thread - fetch");
501 gchar *uri = g_strconcat(conus_url, nearest, NULL);
502 conus->path = grits_http_fetch(conus->http, uri, nearest, GRITS_ONCE,
503 _conus_update_loading, conus);
507 conus->message = "Fetch failed";
512 g_debug("Conus: update_thread - done");
513 g_idle_add(_conus_update_end, conus);
517 void _conus_update(RadarConus *conus)
519 if (!g_static_mutex_trylock(&conus->loading))
521 conus->time = grits_viewer_get_time(conus->viewer);
522 g_debug("Conus: update - %d",
525 /* Add a progress bar */
526 GtkWidget *progress = gtk_progress_bar_new();
527 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress), "Loading...");
528 _gtk_bin_set_child(GTK_BIN(conus->config), progress);
530 g_thread_create(_conus_update_thread, conus, FALSE, NULL);
533 RadarConus *radar_conus_new(GtkWidget *pconfig,
534 GritsViewer *viewer, GritsHttp *http)
536 RadarConus *conus = g_new0(RadarConus, 1);
537 conus->viewer = g_object_ref(viewer);
539 conus->config = gtk_alignment_new(0, 0, 1, 1);
540 g_static_mutex_init(&conus->loading);
542 gdouble south = CONUS_NORTH - CONUS_DEG_PER_PX*CONUS_HEIGHT;
543 gdouble east = CONUS_WEST + CONUS_DEG_PER_PX*CONUS_WIDTH;
544 gdouble mid = CONUS_WEST + CONUS_DEG_PER_PX*CONUS_WIDTH/2;
545 conus->tile[0] = grits_tile_new(NULL, CONUS_NORTH, south, mid, CONUS_WEST);
546 conus->tile[1] = grits_tile_new(NULL, CONUS_NORTH, south, east, mid);
547 conus->tile[0]->zindex = 2;
548 conus->tile[1]->zindex = 1;
549 grits_viewer_add(viewer, GRITS_OBJECT(conus->tile[0]), GRITS_LEVEL_WORLD, TRUE);
550 grits_viewer_add(viewer, GRITS_OBJECT(conus->tile[1]), GRITS_LEVEL_WORLD, TRUE);
552 conus->time_id = g_signal_connect_swapped(viewer, "time-changed",
553 G_CALLBACK(_conus_update), conus);
554 conus->refresh_id = g_signal_connect_swapped(viewer, "refresh",
555 G_CALLBACK(_conus_update), conus);
557 g_object_set_data(G_OBJECT(conus->config), "conus", conus);
558 gtk_notebook_append_page(GTK_NOTEBOOK(pconfig), conus->config,
559 gtk_label_new("Conus"));
561 _conus_update(conus);
565 void radar_conus_free(RadarConus *conus)
567 g_signal_handler_disconnect(conus->viewer, conus->time_id);
568 g_signal_handler_disconnect(conus->viewer, conus->refresh_id);
570 for (int i = 0; i < 2; i++) {
571 GritsTile *tile = conus->tile[i];
573 glDeleteTextures(1, tile->data);
576 grits_viewer_remove(conus->viewer, tile);
579 g_object_unref(conus->viewer);
584 /********************
586 ********************/
587 static void _draw_hud(GritsCallback *callback, GritsOpenGL *opengl, gpointer _self)
589 g_debug("GritsPluginRadar: _draw_hud");
591 glMatrixMode(GL_MODELVIEW ); glLoadIdentity();
592 glMatrixMode(GL_PROJECTION); glLoadIdentity();
593 glDisable(GL_TEXTURE_2D);
594 glDisable(GL_ALPHA_TEST);
595 glDisable(GL_CULL_FACE);
596 glDisable(GL_LIGHTING);
597 glEnable(GL_COLOR_MATERIAL);
600 gpointer name, _site;
601 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(_self);
602 g_hash_table_iter_init(&iter, self->sites);
603 while (g_hash_table_iter_next(&iter, &name, &_site)) {
604 /* Pick correct colormaps */
605 RadarSite *site = _site;
606 if (site->hidden || !site->level2)
608 AWeatherColormap *colormap = site->level2->sweep_colors;
610 /* Print the color table */
612 int len = colormap->len;
613 for (int i = 0; i < len; i++) {
614 glColor4ubv(colormap->data[i]);
615 glVertex3f(-1.0, (float)((i ) - len/2)/(len/2), 0.0); // bot left
616 glVertex3f(-1.0, (float)((i+1) - len/2)/(len/2), 0.0); // top left
617 glVertex3f(-0.9, (float)((i+1) - len/2)/(len/2), 0.0); // top right
618 glVertex3f(-0.9, (float)((i ) - len/2)/(len/2), 0.0); // bot right
624 static void _load_colormap(gchar *filename, AWeatherColormap *cm)
626 g_debug("GritsPluginRadar: _load_colormap - %s", filename);
627 FILE *file = g_fopen(filename, "r");
629 g_error("GritsPluginRadar: open failed");
631 GArray *array = g_array_sized_new(FALSE, TRUE, sizeof(color), 256);
632 fgets(cm->name, sizeof(cm->name), file);
633 fscanf(file, "%f\n", &cm->scale);
634 fscanf(file, "%f\n", &cm->shift);
635 while (fscanf(file, "%hhd %hhd %hhd %hhd\n",
636 &color[0], &color[1], &color[2], &color[3]) == 4)
637 g_array_append_val(array, color);
638 cm->len = (gint )array->len;
639 cm->data = (void*)array->data;
640 g_array_free(array, FALSE);
643 static void _update_hidden(GtkNotebook *notebook,
644 GtkNotebookPage *page, guint page_num, gpointer viewer)
646 g_debug("GritsPluginRadar: _update_hidden - 0..%d = %d",
647 gtk_notebook_get_n_pages(notebook), page_num);
649 for (gint i = 0; i < gtk_notebook_get_n_pages(notebook); i++) {
650 gboolean is_hidden = (i != page_num);
651 GtkWidget *config = gtk_notebook_get_nth_page(notebook, i);
652 RadarConus *conus = g_object_get_data(G_OBJECT(config), "conus");
653 RadarSite *site = g_object_get_data(G_OBJECT(config), "site");
657 grits_object_hide(GRITS_OBJECT(conus->tile[0]), is_hidden);
658 grits_object_hide(GRITS_OBJECT(conus->tile[1]), is_hidden);
660 site->hidden = is_hidden;
662 grits_object_hide(GRITS_OBJECT(site->level2), is_hidden);
664 g_warning("GritsPluginRadar: _update_hidden - no site or counus found");
667 gtk_widget_queue_draw(GTK_WIDGET(viewer));
671 GritsPluginRadar *grits_plugin_radar_new(GritsViewer *viewer, GritsPrefs *prefs)
673 /* TODO: move to constructor if possible */
674 g_debug("GritsPluginRadar: new");
675 GritsPluginRadar *self = g_object_new(GRITS_TYPE_PLUGIN_RADAR, NULL);
676 self->viewer = viewer;
679 /* Setup page switching */
680 self->tab_id = g_signal_connect(self->config, "switch-page",
681 G_CALLBACK(_update_hidden), viewer);
684 self->hud = grits_callback_new(_draw_hud, self);
685 grits_viewer_add(viewer, GRITS_OBJECT(self->hud), GRITS_LEVEL_HUD, FALSE);
688 self->conus = radar_conus_new(self->config, self->viewer, self->conus_http);
690 /* Load radar sites */
691 for (city_t *city = cities; city->type; city++) {
692 if (city->type != LOCATION_CITY)
694 RadarSite *site = radar_site_new(city, self->config,
695 self->viewer, self->prefs, self->sites_http);
696 g_hash_table_insert(self->sites, city->code, site);
702 static GtkWidget *grits_plugin_radar_get_config(GritsPlugin *_self)
704 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(_self);
709 static void grits_plugin_radar_plugin_init(GritsPluginInterface *iface);
710 G_DEFINE_TYPE_WITH_CODE(GritsPluginRadar, grits_plugin_radar, G_TYPE_OBJECT,
711 G_IMPLEMENT_INTERFACE(GRITS_TYPE_PLUGIN,
712 grits_plugin_radar_plugin_init));
713 static void grits_plugin_radar_plugin_init(GritsPluginInterface *iface)
715 g_debug("GritsPluginRadar: plugin_init");
716 /* Add methods to the interface */
717 iface->get_config = grits_plugin_radar_get_config;
719 static void grits_plugin_radar_init(GritsPluginRadar *self)
721 g_debug("GritsPluginRadar: class_init");
723 self->sites_http = grits_http_new(G_DIR_SEPARATOR_S
724 "nexrad" G_DIR_SEPARATOR_S
725 "level2" G_DIR_SEPARATOR_S);
726 self->conus_http = grits_http_new(G_DIR_SEPARATOR_S
727 "nexrad" G_DIR_SEPARATOR_S
728 "conus" G_DIR_SEPARATOR_S);
729 self->sites = g_hash_table_new_full(g_str_hash, g_str_equal,
730 NULL, (GDestroyNotify)radar_site_free);
731 self->config = gtk_notebook_new();
734 for (int i = 0; colormaps[i].file; i++) {
735 gchar *file = g_build_filename(PKGDATADIR,
736 "colors", colormaps[i].file, NULL);
737 _load_colormap(file, &colormaps[i]);
741 /* Need to position on the top because of Win32 bug */
742 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(self->config), GTK_POS_LEFT);
744 static void grits_plugin_radar_dispose(GObject *gobject)
746 g_debug("GritsPluginRadar: dispose");
747 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(gobject);
748 g_signal_handler_disconnect(self->config, self->tab_id);
749 grits_viewer_remove(self->viewer, self->hud);
750 radar_conus_free(self->conus);
751 /* Drop references */
752 G_OBJECT_CLASS(grits_plugin_radar_parent_class)->dispose(gobject);
754 static void grits_plugin_radar_finalize(GObject *gobject)
756 g_debug("GritsPluginRadar: finalize");
757 GritsPluginRadar *self = GRITS_PLUGIN_RADAR(gobject);
759 grits_http_free(self->conus_http);
760 grits_http_free(self->sites_http);
761 g_hash_table_destroy(self->sites);
762 gtk_widget_destroy(self->config);
763 G_OBJECT_CLASS(grits_plugin_radar_parent_class)->finalize(gobject);
766 static void grits_plugin_radar_class_init(GritsPluginRadarClass *klass)
768 g_debug("GritsPluginRadar: class_init");
769 GObjectClass *gobject_class = (GObjectClass*)klass;
770 gobject_class->dispose = grits_plugin_radar_dispose;
771 gobject_class->finalize = grits_plugin_radar_finalize;