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/>.
20 #include "gis-marshal.h"
22 #include "gis-world.h"
37 static guint signals[NUM_SIGNALS];
41 static void _gis_view_emit_location_changed(GisView *view)
43 g_signal_emit(view, signals[SIG_LOCATION_CHANGED], 0,
48 static void _gis_view_emit_rotation_changed(GisView *view)
50 g_signal_emit(view, signals[SIG_ROTATION_CHANGED], 0,
55 static void _gis_view_emit_time_changed(GisView *view)
57 g_signal_emit(view, signals[SIG_TIME_CHANGED], 0,
60 static void _gis_view_emit_site_changed(GisView *view)
62 g_signal_emit(view, signals[SIG_SITE_CHANGED], 0,
70 GisView *gis_view_new()
72 g_debug("GisView: new");
73 return g_object_new(GIS_TYPE_VIEW, NULL);
76 void gis_view_set_time(GisView *view, const char *time)
78 g_assert(GIS_IS_VIEW(view));
79 g_debug("GisView: set_time - time=%s", time);
81 view->time = g_strdup(time);
82 _gis_view_emit_time_changed(view);
85 gchar *gis_view_get_time(GisView *view)
87 g_assert(GIS_IS_VIEW(view));
88 g_debug("GisView: get_time");
92 void gis_view_set_location(GisView *view, gdouble lat, gdouble lon, gdouble elev)
94 g_assert(GIS_IS_VIEW(view));
95 g_debug("GisView: set_location");
96 view->location[0] = lat;
97 view->location[1] = lon;
98 view->location[2] = elev;
99 _gis_view_emit_location_changed(view);
102 void gis_view_get_location(GisView *view, gdouble *lat, gdouble *lon, gdouble *elev)
104 g_assert(GIS_IS_VIEW(view));
105 //g_debug("GisView: get_location");
106 *lat = view->location[0];
107 *lon = view->location[1];
108 *elev = view->location[2];
111 void gis_view_pan(GisView *view, gdouble lat, gdouble lon, gdouble elev)
113 g_assert(GIS_IS_VIEW(view));
114 g_debug("GisView: pan - lat=%8.3f, lon=%8.3f, elev=%8.3f", lat, lon, elev);
115 view->location[0] += lat;
116 view->location[1] += lon;
117 view->location[2] += elev;
118 _gis_view_emit_location_changed(view);
121 void gis_view_zoom(GisView *view, gdouble scale)
123 g_assert(GIS_IS_VIEW(view));
124 g_debug("GisView: zoom");
125 view->location[2] *= scale;
126 _gis_view_emit_location_changed(view);
129 void gis_view_set_rotation(GisView *view, gdouble x, gdouble y, gdouble z)
131 g_assert(GIS_IS_VIEW(view));
132 g_debug("GisView: set_rotation");
133 view->rotation[0] = x;
134 view->rotation[1] = y;
135 view->rotation[2] = z;
136 _gis_view_emit_rotation_changed(view);
139 void gis_view_get_rotation(GisView *view, gdouble *x, gdouble *y, gdouble *z)
141 g_assert(GIS_IS_VIEW(view));
142 g_debug("GisView: get_rotation");
143 *x = view->rotation[0];
144 *y = view->rotation[1];
145 *z = view->rotation[2];
148 void gis_view_rotate(GisView *view, gdouble x, gdouble y, gdouble z)
150 g_assert(GIS_IS_VIEW(view));
151 g_debug("GisView: rotate - x=%.0f, y=%.0f, z=%.0f", x, y, z);
152 view->rotation[0] += x;
153 view->rotation[1] += y;
154 view->rotation[2] += z;
155 _gis_view_emit_rotation_changed(view);
158 /* To be deprecated, use {get,set}_location */
159 void gis_view_set_site(GisView *view, const gchar *site)
161 g_assert(GIS_IS_VIEW(view));
162 g_debug("GisView: set_site");
164 view->site = g_strdup(site);
165 _gis_view_emit_site_changed(view);
168 gchar *gis_view_get_site(GisView *view)
170 g_assert(GIS_IS_VIEW(view));
171 g_debug("GisView: get_site - %s", view->site);
179 G_DEFINE_TYPE(GisView, gis_view, G_TYPE_OBJECT);
180 static void gis_view_init(GisView *self)
182 g_debug("GisView: init");
184 self->time = g_strdup("");
185 self->site = g_strdup("");
186 self->location[0] = 40;
187 self->location[1] = -100;
188 self->location[2] = 1.5*EARTH_R;
189 self->rotation[0] = 0;
190 self->rotation[1] = 0;
191 self->rotation[2] = 0;
193 static void gis_view_dispose(GObject *gobject)
195 g_debug("GisView: dispose");
196 /* Drop references to other GObjects */
197 G_OBJECT_CLASS(gis_view_parent_class)->dispose(gobject);
199 static void gis_view_finalize(GObject *gobject)
201 g_debug("GisView: finalize");
202 GisView *self = GIS_VIEW(gobject);
205 G_OBJECT_CLASS(gis_view_parent_class)->finalize(gobject);
207 static void gis_view_set_property(GObject *object, guint property_id,
208 const GValue *value, GParamSpec *pspec)
210 g_debug("GisView: set_property");
211 GisView *self = GIS_VIEW(object);
212 switch (property_id) {
213 case PROP_TIME: gis_view_set_time(self, g_value_get_string(value)); break;
214 case PROP_SITE: gis_view_set_site(self, g_value_get_string(value)); break;
215 default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
218 static void gis_view_get_property(GObject *object, guint property_id,
219 GValue *value, GParamSpec *pspec)
221 g_debug("GisView: get_property");
222 GisView *self = GIS_VIEW(object);
223 switch (property_id) {
224 case PROP_TIME: g_value_set_string(value, gis_view_get_time(self)); break;
225 case PROP_SITE: g_value_set_string(value, gis_view_get_site(self)); break;
226 default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
229 static void gis_view_class_init(GisViewClass *klass)
231 g_debug("GisView: class_init");
232 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
233 gobject_class->dispose = gis_view_dispose;
234 gobject_class->finalize = gis_view_finalize;
235 gobject_class->get_property = gis_view_get_property;
236 gobject_class->set_property = gis_view_set_property;
237 g_object_class_install_property(gobject_class, PROP_TIME,
238 g_param_spec_pointer(
240 "time of the current frame",
243 g_object_class_install_property(gobject_class, PROP_SITE,
244 g_param_spec_pointer(
246 "site seen by the viewport",
247 "Site of the viewport. Currently this is the name of the radar site.",
249 signals[SIG_TIME_CHANGED] = g_signal_new(
251 G_TYPE_FROM_CLASS(gobject_class),
256 g_cclosure_marshal_VOID__STRING,
260 signals[SIG_SITE_CHANGED] = g_signal_new(
262 G_TYPE_FROM_CLASS(gobject_class),
267 g_cclosure_marshal_VOID__STRING,
271 signals[SIG_LOCATION_CHANGED] = g_signal_new(
273 G_TYPE_FROM_CLASS(gobject_class),
278 gis_cclosure_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,
284 signals[SIG_ROTATION_CHANGED] = g_signal_new(
286 G_TYPE_FROM_CLASS(gobject_class),
291 gis_cclosure_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,