2 * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
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 "aweather-view.h"
41 static guint signals[NUM_SIGNALS];
43 /* Class/Object init */
44 G_DEFINE_TYPE(AWeatherView, aweather_view, G_TYPE_OBJECT);
45 static void aweather_view_init(AWeatherView *self)
47 g_debug("AWeatherView: init");
49 self->time = g_strdup("");
50 self->site = g_strdup("");
51 self->location[0] = 0;
52 self->location[1] = 0;
53 self->location[2] = -300*1000;
54 self->rotation[0] = 0;
55 self->rotation[1] = 0;
56 self->rotation[2] = 0;
57 self->offline = FALSE;
59 static void aweather_view_dispose(GObject *gobject)
61 g_debug("AWeatherView: dispose");
62 /* Drop references to other GObjects */
63 G_OBJECT_CLASS(aweather_view_parent_class)->dispose(gobject);
65 static void aweather_view_finalize(GObject *gobject)
67 g_debug("AWeatherView: finalize");
68 AWeatherView *self = AWEATHER_VIEW(gobject);
71 G_OBJECT_CLASS(aweather_view_parent_class)->finalize(gobject);
73 static void aweather_view_set_property(GObject *object, guint property_id,
74 const GValue *value, GParamSpec *pspec)
76 g_debug("AWeatherView: set_property");
77 AWeatherView *self = AWEATHER_VIEW(object);
78 switch (property_id) {
79 case PROP_TIME: aweather_view_set_time(self, g_value_get_string(value)); break;
80 case PROP_SITE: aweather_view_set_site(self, g_value_get_string(value)); break;
81 default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
84 static void aweather_view_get_property(GObject *object, guint property_id,
85 GValue *value, GParamSpec *pspec)
87 g_debug("AWeatherView: get_property");
88 AWeatherView *self = AWEATHER_VIEW(object);
89 switch (property_id) {
90 case PROP_TIME: g_value_set_string(value, aweather_view_get_time(self)); break;
91 case PROP_SITE: g_value_set_string(value, aweather_view_get_site(self)); break;
92 default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
95 static void aweather_view_class_init(AWeatherViewClass *klass)
97 g_debug("AWeatherView: class_init");
98 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
99 gobject_class->dispose = aweather_view_dispose;
100 gobject_class->finalize = aweather_view_finalize;
101 gobject_class->get_property = aweather_view_get_property;
102 gobject_class->set_property = aweather_view_set_property;
103 g_object_class_install_property(gobject_class, PROP_TIME,
104 g_param_spec_pointer(
106 "time of the current frame",
109 g_object_class_install_property(gobject_class, PROP_SITE,
110 g_param_spec_pointer(
112 "site seen by the viewport",
113 "Site of the viewport. Currently this is the name of the radar site.",
115 signals[SIG_TIME_CHANGED] = g_signal_new(
117 G_TYPE_FROM_CLASS(gobject_class),
122 g_cclosure_marshal_VOID__STRING,
126 signals[SIG_SITE_CHANGED] = g_signal_new(
128 G_TYPE_FROM_CLASS(gobject_class),
133 g_cclosure_marshal_VOID__STRING,
137 signals[SIG_LOCATION_CHANGED] = g_signal_new(
139 G_TYPE_FROM_CLASS(gobject_class),
144 aweather_cclosure_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,
150 signals[SIG_ROTATION_CHANGED] = g_signal_new(
152 G_TYPE_FROM_CLASS(gobject_class),
157 aweather_cclosure_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,
163 signals[SIG_REFRESH] = g_signal_new(
165 G_TYPE_FROM_CLASS(gobject_class),
170 g_cclosure_marshal_VOID__VOID,
173 signals[SIG_OFFLINE] = g_signal_new(
175 G_TYPE_FROM_CLASS(gobject_class),
180 g_cclosure_marshal_VOID__BOOLEAN,
187 static void _aweather_view_emit_location_changed(AWeatherView *view)
189 g_signal_emit(view, signals[SIG_LOCATION_CHANGED], 0,
194 static void _aweather_view_emit_rotation_changed(AWeatherView *view)
196 g_signal_emit(view, signals[SIG_ROTATION_CHANGED], 0,
201 static void _aweather_view_emit_time_changed(AWeatherView *view)
203 g_signal_emit(view, signals[SIG_TIME_CHANGED], 0,
206 static void _aweather_view_emit_site_changed(AWeatherView *view)
208 g_signal_emit(view, signals[SIG_SITE_CHANGED], 0,
211 static void _aweather_view_emit_refresh(AWeatherView *view)
213 g_signal_emit(view, signals[SIG_REFRESH], 0);
215 static void _aweather_view_emit_offline(AWeatherView *view)
217 g_signal_emit(view, signals[SIG_OFFLINE], 0,
225 AWeatherView *aweather_view_new()
227 g_debug("AWeatherView: new");
228 return g_object_new(AWEATHER_TYPE_VIEW, NULL);
231 void aweather_view_set_time(AWeatherView *view, const char *time)
233 g_assert(AWEATHER_IS_VIEW(view));
234 g_debug("AWeatherView: set_time - time=%s", time);
236 view->time = g_strdup(time);
237 _aweather_view_emit_time_changed(view);
240 gchar *aweather_view_get_time(AWeatherView *view)
242 g_assert(AWEATHER_IS_VIEW(view));
243 g_debug("AWeatherView: get_time");
247 void aweather_view_set_location(AWeatherView *view, gdouble x, gdouble y, gdouble z)
249 g_assert(AWEATHER_IS_VIEW(view));
250 g_debug("AWeatherView: set_location");
251 view->location[0] = x;
252 view->location[1] = y;
253 view->location[2] = z;
254 _aweather_view_emit_location_changed(view);
257 void aweather_view_get_location(AWeatherView *view, gdouble *x, gdouble *y, gdouble *z)
259 g_assert(AWEATHER_IS_VIEW(view));
260 g_debug("AWeatherView: get_location");
261 *x = view->location[0];
262 *y = view->location[1];
263 *z = view->location[2];
266 void aweather_view_pan(AWeatherView *view, gdouble x, gdouble y, gdouble z)
268 g_assert(AWEATHER_IS_VIEW(view));
269 g_debug("AWeatherView: pan - x=%.0f, y=%.0f, z=%.0f", x, y, z);
270 view->location[0] += x;
271 view->location[1] += y;
272 view->location[2] += z;
273 _aweather_view_emit_location_changed(view);
276 void aweather_view_zoom(AWeatherView *view, gdouble scale)
278 g_assert(AWEATHER_IS_VIEW(view));
279 g_debug("AWeatherView: zoom");
280 view->location[2] *= scale;
281 _aweather_view_emit_location_changed(view);
284 void aweather_view_set_rotation(AWeatherView *view, gdouble x, gdouble y, gdouble z)
286 g_assert(AWEATHER_IS_VIEW(view));
287 g_debug("AWeatherView: set_rotation");
288 view->rotation[0] = x;
289 view->rotation[1] = y;
290 view->rotation[2] = z;
291 _aweather_view_emit_rotation_changed(view);
294 void aweather_view_get_rotation(AWeatherView *view, gdouble *x, gdouble *y, gdouble *z)
296 g_assert(AWEATHER_IS_VIEW(view));
297 g_debug("AWeatherView: get_rotation");
298 *x = view->rotation[0];
299 *y = view->rotation[1];
300 *z = view->rotation[2];
303 void aweather_view_rotate(AWeatherView *view, gdouble x, gdouble y, gdouble z)
305 g_assert(AWEATHER_IS_VIEW(view));
306 g_debug("AWeatherView: rotate - x=%.0f, y=%.0f, z=%.0f", x, y, z);
307 view->rotation[0] += x;
308 view->rotation[1] += y;
309 view->rotation[2] += z;
310 _aweather_view_emit_rotation_changed(view);
313 void aweather_view_refresh(AWeatherView *view)
315 g_debug("AWeatherView: refresh");
316 _aweather_view_emit_refresh(view);
319 void aweather_view_set_offline(AWeatherView *view, gboolean offline)
321 g_assert(AWEATHER_IS_VIEW(view));
322 g_debug("AWeatherView: set_offline - %d", offline);
323 view->offline = offline;
324 _aweather_view_emit_offline(view);
327 gboolean aweather_view_get_offline(AWeatherView *view)
329 g_assert(AWEATHER_IS_VIEW(view));
330 g_debug("AWeatherView: get_offline - %d", view->offline);
331 return view->offline;
334 /* To be deprecated, use {get,set}_location */
335 void aweather_view_set_site(AWeatherView *view, const gchar *site)
337 g_assert(AWEATHER_IS_VIEW(view));
338 g_debug("AWeatherView: set_site");
340 view->site = g_strdup(site);
341 _aweather_view_emit_site_changed(view);
344 gchar *aweather_view_get_site(AWeatherView *view)
346 g_assert(AWEATHER_IS_VIEW(view));
347 g_debug("AWeatherView: get_site");