]> Pileus Git - grits/blob - src/aweather-view.c
8b7eade4b90b45da8036807d0c18e5780108ee27
[grits] / 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 G_DEFINE_TYPE(AWeatherView, aweather_view, G_TYPE_OBJECT);
24
25 enum {
26         PROP_0,
27         PROP_TIME,
28         PROP_SITE,
29 };
30
31 enum {
32         SIG_TIME_CHANGED,
33         SIG_SITE_CHANGED,
34         SIG_LOCATION_CHANGED,
35         SIG_REFRESH,
36         NUM_SIGNALS,
37 };
38
39 static guint signals[NUM_SIGNALS];
40
41 /* Constructor / destructors */
42 static void aweather_view_init(AWeatherView *self)
43 {
44         //g_message("aweather_view_init");
45         /* Default values */
46         self->time     = g_strdup(""); //g_strdup("LATEST");
47         self->site     = g_strdup(""); //g_strdup("IND");
48 }
49
50 static GObject *aweather_view_constructor(GType gtype, guint n_properties,
51                 GObjectConstructParam *properties)
52 {
53         //g_message("aweather_view_constructor");
54         GObjectClass *parent_class = G_OBJECT_CLASS(aweather_view_parent_class);
55         return  parent_class->constructor(gtype, n_properties, properties);
56 }
57
58 static void aweather_view_dispose (GObject *gobject)
59 {
60         //g_message("aweather_view_dispose");
61         /* Drop references to other GObjects */
62         G_OBJECT_CLASS(aweather_view_parent_class)->dispose(gobject);
63 }
64
65 static void aweather_view_finalize(GObject *gobject)
66 {
67         //g_message("aweather_view_finalize");
68         AWeatherView *self = AWEATHER_VIEW(gobject);
69         g_free(self->site);
70         G_OBJECT_CLASS(aweather_view_parent_class)->finalize(gobject);
71 }
72
73 static void aweather_view_set_property(GObject *object, guint property_id,
74                 const GValue *value, GParamSpec *pspec)
75 {
76         //g_message("aweather_view_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
85 static void aweather_view_get_property(GObject *object, guint property_id,
86                 GValue *value, GParamSpec *pspec)
87 {
88         //g_message("aweather_view_get_property");
89         AWeatherView *self = AWEATHER_VIEW(object);
90         switch (property_id) {
91         case PROP_TIME:     g_value_set_string(value, aweather_view_get_time(self)); break;
92         case PROP_SITE:     g_value_set_string(value, aweather_view_get_site(self)); break;
93         default:            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
94         }
95 }
96
97 static void aweather_view_class_init(AWeatherViewClass *klass)
98 {
99         //g_message("aweather_view_class_init");
100         GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
101         gobject_class->constructor  = aweather_view_constructor;
102         gobject_class->dispose      = aweather_view_dispose;
103         gobject_class->finalize     = aweather_view_finalize;
104         gobject_class->get_property = aweather_view_get_property;
105         gobject_class->set_property = aweather_view_set_property;
106         g_object_class_install_property(gobject_class, PROP_TIME,
107                 g_param_spec_pointer(
108                         "time",
109                         "time of the current frame",
110                         "(format unknown)", 
111                         G_PARAM_READWRITE));
112         g_object_class_install_property(gobject_class, PROP_SITE,
113                 g_param_spec_pointer(
114                         "site",
115                         "site seen by the viewport",
116                         "Site of the viewport. Currently this is the name of the radar site.", 
117                         G_PARAM_READWRITE));
118         signals[SIG_TIME_CHANGED] = g_signal_new(
119                         "time-changed",
120                         G_TYPE_FROM_CLASS(gobject_class),
121                         G_SIGNAL_RUN_LAST,
122                         0,
123                         NULL,
124                         NULL,
125                         g_cclosure_marshal_VOID__INT,
126                         G_TYPE_NONE,
127                         1,
128                         G_TYPE_STRING);
129         signals[SIG_SITE_CHANGED] = g_signal_new(
130                         "site-changed",
131                         G_TYPE_FROM_CLASS(gobject_class),
132                         G_SIGNAL_RUN_LAST,
133                         0,
134                         NULL,
135                         NULL,
136                         g_cclosure_marshal_VOID__STRING,
137                         G_TYPE_NONE,
138                         1,
139                         G_TYPE_STRING);
140         signals[SIG_LOCATION_CHANGED] = g_signal_new(
141                         "location-changed",
142                         G_TYPE_FROM_CLASS(gobject_class),
143                         G_SIGNAL_RUN_LAST,
144                         0,
145                         NULL,
146                         NULL,
147                         aweather_cclosure_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,
148                         G_TYPE_NONE,
149                         3,
150                         G_TYPE_DOUBLE,
151                         G_TYPE_DOUBLE,
152                         G_TYPE_DOUBLE);
153         signals[SIG_REFRESH] = g_signal_new(
154                         "refresh",
155                         G_TYPE_FROM_CLASS(gobject_class),
156                         G_SIGNAL_RUN_LAST,
157                         0,
158                         NULL,
159                         NULL,
160                         g_cclosure_marshal_VOID__VOID,
161                         G_TYPE_NONE,
162                         0);
163
164 }
165
166 /* Signal helpers */
167 static void _aweather_view_emit_location_changed(AWeatherView *view)
168 {
169         g_signal_emit(view, signals[SIG_LOCATION_CHANGED], 0, 
170                         view->location[0],
171                         view->location[1],
172                         view->location[2]);
173 }
174 static void _aweather_view_emit_time_changed(AWeatherView *view)
175 {
176         g_signal_emit(view, signals[SIG_TIME_CHANGED], 0,
177                         view->time);
178 }
179 static void _aweather_view_emit_site_changed(AWeatherView *view)
180 {
181         g_signal_emit(view, signals[SIG_SITE_CHANGED], 0,
182                         view->site);
183 }
184 static void _aweather_view_emit_refresh(AWeatherView *view)
185 {
186         g_signal_emit(view, signals[SIG_REFRESH], 0);
187 }
188
189
190 /* Methods */
191 AWeatherView *aweather_view_new()
192 {
193         //g_message("aweather_view_new");
194         return g_object_new(AWEATHER_TYPE_VIEW, NULL);
195 }
196
197 void aweather_view_set_time(AWeatherView *view, const char *time)
198 {
199         g_assert(AWEATHER_IS_VIEW(view));
200         //g_message("aweather_view:set_time: setting time to %s", time);
201         g_free(view->time);
202         view->time = g_strdup(time);
203         _aweather_view_emit_time_changed(view);
204 }
205
206 gchar *aweather_view_get_time(AWeatherView *view)
207 {
208         g_assert(AWEATHER_IS_VIEW(view));
209         //g_message("aweather_view_get_time");
210         return view->time;
211 }
212
213 void aweather_view_get_location(AWeatherView *view, gdouble *x, gdouble *y, gdouble *z)
214 {
215         g_assert(AWEATHER_IS_VIEW(view));
216         //g_message("aweather_view_get_location");
217         *x = view->location[0];
218         *y = view->location[1];
219         *z = view->location[2];
220 }
221
222 void aweather_view_set_location(AWeatherView *view, gdouble x, gdouble y, gdouble z)
223 {
224         g_assert(AWEATHER_IS_VIEW(view));
225         //g_message("aweather_view_set_location");
226         view->location[0] = x;
227         view->location[1] = y;
228         view->location[2] = z;
229         _aweather_view_emit_location_changed(view);
230 }
231
232 void aweather_view_pan(AWeatherView *view, gdouble x, gdouble y, gdouble z)
233 {
234         g_assert(AWEATHER_IS_VIEW(view));
235         g_message("aweather_view_pan: %f, %f, %f", x, y, z);
236         view->location[0] += x;
237         view->location[1] += y;
238         view->location[2] += z;
239         _aweather_view_emit_location_changed(view);
240 }
241
242 void aweather_view_zoom(AWeatherView *view, gdouble scale)
243 {
244         g_assert(AWEATHER_IS_VIEW(view));
245         view->location[2] *= scale;
246         _aweather_view_emit_location_changed(view);
247 }
248
249 void aweather_view_refresh(AWeatherView *view)
250 {
251         g_message("aweather_view_refresh: ..");
252         _aweather_view_emit_refresh(view);
253 }
254
255 void aweather_view_set_site(AWeatherView *view, const gchar *site)
256 {
257         g_assert(AWEATHER_IS_VIEW(view));
258         //g_message("aweather_view_set_site");
259         g_free(view->site);
260         view->site = g_strdup(site);
261         _aweather_view_emit_site_changed(view);
262 }
263
264 gchar *aweather_view_get_site(AWeatherView *view)
265 {
266         g_assert(AWEATHER_IS_VIEW(view));
267         //g_message("aweather_view_get_site");
268         return view->site;
269 }
270