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/>.
39 static guint signals[NUM_SIGNALS];
41 /* Class/Object init */
42 G_DEFINE_TYPE(GisView, gis_view, G_TYPE_OBJECT);
43 static void gis_view_init(GisView *self)
45 g_debug("GisView: init");
47 self->time = g_strdup("");
48 self->site = g_strdup("");
49 self->location[0] = 0;
50 self->location[1] = 0;
51 self->location[2] = -300*1000;
52 self->rotation[0] = 0;
53 self->rotation[1] = 0;
54 self->rotation[2] = 0;
56 static void gis_view_dispose(GObject *gobject)
58 g_debug("GisView: dispose");
59 /* Drop references to other GObjects */
60 G_OBJECT_CLASS(gis_view_parent_class)->dispose(gobject);
62 static void gis_view_finalize(GObject *gobject)
64 g_debug("GisView: finalize");
65 GisView *self = GIS_VIEW(gobject);
68 G_OBJECT_CLASS(gis_view_parent_class)->finalize(gobject);
70 static void gis_view_set_property(GObject *object, guint property_id,
71 const GValue *value, GParamSpec *pspec)
73 g_debug("GisView: set_property");
74 GisView *self = GIS_VIEW(object);
75 switch (property_id) {
76 case PROP_TIME: gis_view_set_time(self, g_value_get_string(value)); break;
77 case PROP_SITE: gis_view_set_site(self, g_value_get_string(value)); break;
78 default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
81 static void gis_view_get_property(GObject *object, guint property_id,
82 GValue *value, GParamSpec *pspec)
84 g_debug("GisView: get_property");
85 GisView *self = GIS_VIEW(object);
86 switch (property_id) {
87 case PROP_TIME: g_value_set_string(value, gis_view_get_time(self)); break;
88 case PROP_SITE: g_value_set_string(value, gis_view_get_site(self)); break;
89 default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
92 static void gis_view_class_init(GisViewClass *klass)
94 g_debug("GisView: class_init");
95 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
96 gobject_class->dispose = gis_view_dispose;
97 gobject_class->finalize = gis_view_finalize;
98 gobject_class->get_property = gis_view_get_property;
99 gobject_class->set_property = gis_view_set_property;
100 g_object_class_install_property(gobject_class, PROP_TIME,
101 g_param_spec_pointer(
103 "time of the current frame",
106 g_object_class_install_property(gobject_class, PROP_SITE,
107 g_param_spec_pointer(
109 "site seen by the viewport",
110 "Site of the viewport. Currently this is the name of the radar site.",
112 signals[SIG_TIME_CHANGED] = g_signal_new(
114 G_TYPE_FROM_CLASS(gobject_class),
119 g_cclosure_marshal_VOID__STRING,
123 signals[SIG_SITE_CHANGED] = g_signal_new(
125 G_TYPE_FROM_CLASS(gobject_class),
130 g_cclosure_marshal_VOID__STRING,
134 signals[SIG_LOCATION_CHANGED] = g_signal_new(
136 G_TYPE_FROM_CLASS(gobject_class),
141 aweather_cclosure_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,
147 signals[SIG_ROTATION_CHANGED] = g_signal_new(
149 G_TYPE_FROM_CLASS(gobject_class),
154 aweather_cclosure_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,
163 static void _gis_view_emit_location_changed(GisView *view)
165 g_signal_emit(view, signals[SIG_LOCATION_CHANGED], 0,
170 static void _gis_view_emit_rotation_changed(GisView *view)
172 g_signal_emit(view, signals[SIG_ROTATION_CHANGED], 0,
177 static void _gis_view_emit_time_changed(GisView *view)
179 g_signal_emit(view, signals[SIG_TIME_CHANGED], 0,
182 static void _gis_view_emit_site_changed(GisView *view)
184 g_signal_emit(view, signals[SIG_SITE_CHANGED], 0,
192 GisView *gis_view_new()
194 g_debug("GisView: new");
195 return g_object_new(GIS_TYPE_VIEW, NULL);
198 void gis_view_set_time(GisView *view, const char *time)
200 g_assert(GIS_IS_VIEW(view));
201 g_debug("GisView: set_time - time=%s", time);
203 view->time = g_strdup(time);
204 _gis_view_emit_time_changed(view);
207 gchar *gis_view_get_time(GisView *view)
209 g_assert(GIS_IS_VIEW(view));
210 g_debug("GisView: get_time");
214 void gis_view_set_location(GisView *view, gdouble x, gdouble y, gdouble z)
216 g_assert(GIS_IS_VIEW(view));
217 g_debug("GisView: set_location");
218 view->location[0] = x;
219 view->location[1] = y;
220 view->location[2] = z;
221 _gis_view_emit_location_changed(view);
224 void gis_view_get_location(GisView *view, gdouble *x, gdouble *y, gdouble *z)
226 g_assert(GIS_IS_VIEW(view));
227 g_debug("GisView: get_location");
228 *x = view->location[0];
229 *y = view->location[1];
230 *z = view->location[2];
233 void gis_view_pan(GisView *view, gdouble x, gdouble y, gdouble z)
235 g_assert(GIS_IS_VIEW(view));
236 g_debug("GisView: pan - x=%.0f, y=%.0f, z=%.0f", x, y, z);
237 view->location[0] += x;
238 view->location[1] += y;
239 view->location[2] += z;
240 _gis_view_emit_location_changed(view);
243 void gis_view_zoom(GisView *view, gdouble scale)
245 g_assert(GIS_IS_VIEW(view));
246 g_debug("GisView: zoom");
247 view->location[2] *= scale;
248 _gis_view_emit_location_changed(view);
251 void gis_view_set_rotation(GisView *view, gdouble x, gdouble y, gdouble z)
253 g_assert(GIS_IS_VIEW(view));
254 g_debug("GisView: set_rotation");
255 view->rotation[0] = x;
256 view->rotation[1] = y;
257 view->rotation[2] = z;
258 _gis_view_emit_rotation_changed(view);
261 void gis_view_get_rotation(GisView *view, gdouble *x, gdouble *y, gdouble *z)
263 g_assert(GIS_IS_VIEW(view));
264 g_debug("GisView: get_rotation");
265 *x = view->rotation[0];
266 *y = view->rotation[1];
267 *z = view->rotation[2];
270 void gis_view_rotate(GisView *view, gdouble x, gdouble y, gdouble z)
272 g_assert(GIS_IS_VIEW(view));
273 g_debug("GisView: rotate - x=%.0f, y=%.0f, z=%.0f", x, y, z);
274 view->rotation[0] += x;
275 view->rotation[1] += y;
276 view->rotation[2] += z;
277 _gis_view_emit_rotation_changed(view);
280 /* To be deprecated, use {get,set}_location */
281 void gis_view_set_site(GisView *view, const gchar *site)
283 g_assert(GIS_IS_VIEW(view));
284 g_debug("GisView: set_site");
286 view->site = g_strdup(site);
287 _gis_view_emit_site_changed(view);
290 gchar *gis_view_get_site(GisView *view)
292 g_assert(GIS_IS_VIEW(view));
293 g_debug("GisView: get_site");