]> Pileus Git - aweather/blob - src/aweather-view.c
Adding some (commented out) support for generating iso surfaces.
[aweather] / src / aweather-view.c
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
3  * 
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.
8  * 
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.
13  * 
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/>.
16  */
17
18 #include <glib.h>
19
20 #include "marshal.h"
21 #include "aweather-view.h"
22
23 /****************
24  * GObject code *
25  ****************/
26 /* Constants */
27 enum {
28         PROP_0,
29         PROP_TIME,
30         PROP_SITE,
31 };
32 enum {
33         SIG_TIME_CHANGED,
34         SIG_SITE_CHANGED,
35         SIG_LOCATION_CHANGED,
36         SIG_ROTATION_CHANGED,
37         SIG_REFRESH,
38         SIG_OFFLINE,
39         NUM_SIGNALS,
40 };
41 static guint signals[NUM_SIGNALS];
42
43 /* Class/Object init */
44 G_DEFINE_TYPE(AWeatherView, aweather_view, G_TYPE_OBJECT);
45 static void aweather_view_init(AWeatherView *self)
46 {
47         g_debug("AWeatherView: init");
48         /* Default values */
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;
58 }
59 static void aweather_view_dispose(GObject *gobject)
60 {
61         g_debug("AWeatherView: dispose");
62         /* Drop references to other GObjects */
63         G_OBJECT_CLASS(aweather_view_parent_class)->dispose(gobject);
64 }
65 static void aweather_view_finalize(GObject *gobject)
66 {
67         g_debug("AWeatherView: finalize");
68         AWeatherView *self = AWEATHER_VIEW(gobject);
69         g_free(self->time);
70         g_free(self->site);
71         G_OBJECT_CLASS(aweather_view_parent_class)->finalize(gobject);
72 }
73 static void aweather_view_set_property(GObject *object, guint property_id,
74                 const GValue *value, GParamSpec *pspec)
75 {
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);
82         }
83 }
84 static void aweather_view_get_property(GObject *object, guint property_id,
85                 GValue *value, GParamSpec *pspec)
86 {
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);
93         }
94 }
95 static void aweather_view_class_init(AWeatherViewClass *klass)
96 {
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(
105                         "time",
106                         "time of the current frame",
107                         "(format unknown)", 
108                         G_PARAM_READWRITE));
109         g_object_class_install_property(gobject_class, PROP_SITE,
110                 g_param_spec_pointer(
111                         "site",
112                         "site seen by the viewport",
113                         "Site of the viewport. Currently this is the name of the radar site.", 
114                         G_PARAM_READWRITE));
115         signals[SIG_TIME_CHANGED] = g_signal_new(
116                         "time-changed",
117                         G_TYPE_FROM_CLASS(gobject_class),
118                         G_SIGNAL_RUN_LAST,
119                         0,
120                         NULL,
121                         NULL,
122                         g_cclosure_marshal_VOID__STRING,
123                         G_TYPE_NONE,
124                         1,
125                         G_TYPE_STRING);
126         signals[SIG_SITE_CHANGED] = g_signal_new(
127                         "site-changed",
128                         G_TYPE_FROM_CLASS(gobject_class),
129                         G_SIGNAL_RUN_LAST,
130                         0,
131                         NULL,
132                         NULL,
133                         g_cclosure_marshal_VOID__STRING,
134                         G_TYPE_NONE,
135                         1,
136                         G_TYPE_STRING);
137         signals[SIG_LOCATION_CHANGED] = g_signal_new(
138                         "location-changed",
139                         G_TYPE_FROM_CLASS(gobject_class),
140                         G_SIGNAL_RUN_LAST,
141                         0,
142                         NULL,
143                         NULL,
144                         aweather_cclosure_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,
145                         G_TYPE_NONE,
146                         3,
147                         G_TYPE_DOUBLE,
148                         G_TYPE_DOUBLE,
149                         G_TYPE_DOUBLE);
150         signals[SIG_ROTATION_CHANGED] = g_signal_new(
151                         "rotation-changed",
152                         G_TYPE_FROM_CLASS(gobject_class),
153                         G_SIGNAL_RUN_LAST,
154                         0,
155                         NULL,
156                         NULL,
157                         aweather_cclosure_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,
158                         G_TYPE_NONE,
159                         3,
160                         G_TYPE_DOUBLE,
161                         G_TYPE_DOUBLE,
162                         G_TYPE_DOUBLE);
163         signals[SIG_REFRESH] = g_signal_new(
164                         "refresh",
165                         G_TYPE_FROM_CLASS(gobject_class),
166                         G_SIGNAL_RUN_LAST,
167                         0,
168                         NULL,
169                         NULL,
170                         g_cclosure_marshal_VOID__VOID,
171                         G_TYPE_NONE,
172                         0);
173         signals[SIG_OFFLINE] = g_signal_new(
174                         "offline",
175                         G_TYPE_FROM_CLASS(gobject_class),
176                         G_SIGNAL_RUN_LAST,
177                         0,
178                         NULL,
179                         NULL,
180                         g_cclosure_marshal_VOID__BOOLEAN,
181                         G_TYPE_NONE,
182                         1,
183                         G_TYPE_BOOLEAN);
184 }
185
186 /* Signal helpers */
187 static void _aweather_view_emit_location_changed(AWeatherView *view)
188 {
189         g_signal_emit(view, signals[SIG_LOCATION_CHANGED], 0, 
190                         view->location[0],
191                         view->location[1],
192                         view->location[2]);
193 }
194 static void _aweather_view_emit_rotation_changed(AWeatherView *view)
195 {
196         g_signal_emit(view, signals[SIG_ROTATION_CHANGED], 0, 
197                         view->rotation[0],
198                         view->rotation[1],
199                         view->rotation[2]);
200 }
201 static void _aweather_view_emit_time_changed(AWeatherView *view)
202 {
203         g_signal_emit(view, signals[SIG_TIME_CHANGED], 0,
204                         view->time);
205 }
206 static void _aweather_view_emit_site_changed(AWeatherView *view)
207 {
208         g_signal_emit(view, signals[SIG_SITE_CHANGED], 0,
209                         view->site);
210 }
211 static void _aweather_view_emit_refresh(AWeatherView *view)
212 {
213         g_signal_emit(view, signals[SIG_REFRESH], 0);
214 }
215 static void _aweather_view_emit_offline(AWeatherView *view)
216 {
217         g_signal_emit(view, signals[SIG_OFFLINE], 0,
218                         view->offline);
219 }
220
221
222 /***********
223  * Methods *
224  ***********/
225 AWeatherView *aweather_view_new()
226 {
227         g_debug("AWeatherView: new");
228         return g_object_new(AWEATHER_TYPE_VIEW, NULL);
229 }
230
231 void aweather_view_set_time(AWeatherView *view, const char *time)
232 {
233         g_assert(AWEATHER_IS_VIEW(view));
234         g_debug("AWeatherView: set_time - time=%s", time);
235         g_free(view->time);
236         view->time = g_strdup(time);
237         _aweather_view_emit_time_changed(view);
238 }
239
240 gchar *aweather_view_get_time(AWeatherView *view)
241 {
242         g_assert(AWEATHER_IS_VIEW(view));
243         g_debug("AWeatherView: get_time");
244         return view->time;
245 }
246
247 void aweather_view_set_location(AWeatherView *view, gdouble x, gdouble y, gdouble z)
248 {
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);
255 }
256
257 void aweather_view_get_location(AWeatherView *view, gdouble *x, gdouble *y, gdouble *z)
258 {
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];
264 }
265
266 void aweather_view_pan(AWeatherView *view, gdouble x, gdouble y, gdouble z)
267 {
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);
274 }
275
276 void aweather_view_zoom(AWeatherView *view, gdouble scale)
277 {
278         g_assert(AWEATHER_IS_VIEW(view));
279         g_debug("AWeatherView: zoom");
280         view->location[2] *= scale;
281         _aweather_view_emit_location_changed(view);
282 }
283
284 void aweather_view_set_rotation(AWeatherView *view, gdouble x, gdouble y, gdouble z)
285 {
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);
292 }
293
294 void aweather_view_get_rotation(AWeatherView *view, gdouble *x, gdouble *y, gdouble *z)
295 {
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];
301 }
302
303 void aweather_view_rotate(AWeatherView *view, gdouble x, gdouble y, gdouble z)
304 {
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);
311 }
312
313 void aweather_view_refresh(AWeatherView *view)
314 {
315         g_debug("AWeatherView: refresh");
316         _aweather_view_emit_refresh(view);
317 }
318
319 void aweather_view_set_offline(AWeatherView *view, gboolean offline)
320 {
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);
325 }
326
327 gboolean aweather_view_get_offline(AWeatherView *view)
328 {
329         g_assert(AWEATHER_IS_VIEW(view));
330         g_debug("AWeatherView: get_offline - %d", view->offline);
331         return view->offline;
332 }
333
334 /* To be deprecated, use {get,set}_location */
335 void aweather_view_set_site(AWeatherView *view, const gchar *site)
336 {
337         g_assert(AWEATHER_IS_VIEW(view));
338         g_debug("AWeatherView: set_site");
339         g_free(view->site);
340         view->site = g_strdup(site);
341         _aweather_view_emit_site_changed(view);
342 }
343
344 gchar *aweather_view_get_site(AWeatherView *view)
345 {
346         g_assert(AWEATHER_IS_VIEW(view));
347         g_debug("AWeatherView: get_site");
348         return view->site;
349 }