[Gpredict-svn] SF.net SVN: gpredict:[953] trunk
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
|
From: <aa...@us...> - 2011-11-13 01:28:16
|
Revision: 953
http://gpredict.svn.sourceforge.net/gpredict/?rev=953&view=rev
Author: aa1vs
Date: 2011-11-13 01:28:10 +0000 (Sun, 13 Nov 2011)
Log Message:
-----------
Eliminate duplicate code in polar view and the popup.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/gtk-polar-view-popup.c
trunk/src/gtk-polar-view.c
trunk/src/gtk-polar-view.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-11-12 19:49:28 UTC (rev 952)
+++ trunk/ChangeLog 2011-11-13 01:28:10 UTC (rev 953)
@@ -15,7 +15,12 @@
* src/gtk-sat-map.c
Add comments.
+ * src/gtk-polar-view.c
+ * src/gtk-polar-view.h
+ * src/gtk-polar-view-popup.c
+ Eliminate duplicate code in polar view and the popup.
+
2011-11-05 Charles Suprin <hamaa1vs at gmail.com>
* src/gtk-polar-view.c
Modified: trunk/src/gtk-polar-view-popup.c
===================================================================
--- trunk/src/gtk-polar-view-popup.c 2011-11-12 19:49:28 UTC (rev 952)
+++ trunk/src/gtk-polar-view-popup.c 2011-11-13 01:28:10 UTC (rev 953)
@@ -49,7 +49,6 @@
static void track_toggled (GtkCheckMenuItem *item, gpointer data);
/* static void target_toggled (GtkCheckMenuItem *item, gpointer data); */
-static GooCanvasItemModel *create_time_tick (GtkPolarView *pv, gdouble time, gfloat x, gfloat y);
/** \brief Show satellite popup menu.
@@ -161,15 +160,6 @@
sat_obj_t *obj = NULL;
sat_t *sat;
/* qth_t *qth; Unused */
- gint idx;
- guint i;
- GooCanvasItemModel *root;
- pass_detail_t *detail;
- guint num;
- GooCanvasPoints *points;
- gfloat x,y;
- guint32 col;
- guint tres,ttidx;
gint *catnum;
@@ -189,8 +179,6 @@
obj->showtrack = !obj->showtrack;
gtk_check_menu_item_set_active (item, obj->showtrack);
- root = goo_canvas_get_root_item_model (GOO_CANVAS (pv->canvas));
-
catnum = g_new0 (gint, 1);
*catnum = sat->tle.catnr;
@@ -205,69 +193,7 @@
g_hash_table_remove (pv->showtracks_off,
catnum);
-
- /* create points */
- num = g_slist_length (obj->pass->details);
- if (num == 0) {
- sat_log_log (SAT_LOG_LEVEL_BUG,
- _("%s:%d: Pass has no details."),
- __FILE__, __LINE__);
- return;
- }
-
- /* time resolution for time ticks; we need
- 3 additional points to AOS and LOS ticks.
- */
- tres = (num-2) / (TRACK_TICK_NUM-1);
-
- points = goo_canvas_points_new (num);
-
- /* first point should be (aos_az,0.0) */
- azel_to_xy (pv, obj->pass->aos_az, 0.0, &x, &y);
- points->coords[0] = (double) x;
- points->coords[1] = (double) y;
- obj->trtick[0] = create_time_tick (pv, obj->pass->aos, x, y);
-
- ttidx = 1;
-
- for (i = 1; i < num-1; i++) {
- detail = PASS_DETAIL(g_slist_nth_data (obj->pass->details, i));
- if (detail->el >=0.0)
- azel_to_xy (pv, detail->az, detail->el, &x, &y);
- points->coords[2*i] = (double) x;
- points->coords[2*i+1] = (double) y;
-
- if (!(i % tres)) {
- /* create a time tick */
- if (ttidx<TRACK_TICK_NUM)
- obj->trtick[ttidx] = create_time_tick (pv, detail->time, x, y);
- ttidx++;
- }
- }
-
- /* last point should be (los_az, 0.0) */
- azel_to_xy (pv, obj->pass->los_az, 0.0, &x, &y);
- points->coords[2*(num-1)] = (double) x;
- points->coords[2*(num-1)+1] = (double) y;
-
- /* create poly-line */
- col = mod_cfg_get_int (pv->cfgdata,
- MOD_CFG_POLAR_SECTION,
- MOD_CFG_POLAR_TRACK_COL,
- SAT_CFG_INT_POLAR_TRACK_COL);
-
- obj->track = goo_canvas_polyline_model_new (root, FALSE, 0,
- "points", points,
- "line-width", 1.0,
- "stroke-color-rgba", col,
- "line-cap", CAIRO_LINE_CAP_SQUARE,
- "line-join", CAIRO_LINE_JOIN_MITER,
- NULL);
- goo_canvas_points_unref (points);
-
- /* put track on the bottom of the sack */
- goo_canvas_item_model_lower (obj->track, NULL);
-
+ gtk_polar_view_create_track (pv, obj, sat);
}
else {
/* add it to the hide */
@@ -277,20 +203,9 @@
/* remove it from the show */
g_hash_table_remove (pv->showtracks_on,
catnum);
- /* delete sky track */
- idx = goo_canvas_item_model_find_child (root, obj->track);
- if (idx != -1) {
- goo_canvas_item_model_remove_child (root, idx);
- }
-
- for (i = 0; i < TRACK_TICK_NUM; i++) {
- idx = goo_canvas_item_model_find_child (root, obj->trtick[i]);
-
- if (idx != -1) {
- goo_canvas_item_model_remove_child (root, idx);
- }
- }
+ /* delete sky track */
+ gtk_polar_view_delete_track (pv, obj, sat);
}
}
@@ -324,43 +239,3 @@
gtk_check_menu_item_set_active (item, obj->istarget);
}
#endif
-
-
-static GooCanvasItemModel *
- create_time_tick (GtkPolarView *pv, gdouble time, gfloat x, gfloat y)
-{
- GooCanvasItemModel *item;
- gchar buff[7];
- GtkAnchorType anchor;
- GooCanvasItemModel *root;
- guint32 col;
-
- root = goo_canvas_get_root_item_model (GOO_CANVAS (pv->canvas));
-
- col = mod_cfg_get_int (pv->cfgdata,
- MOD_CFG_POLAR_SECTION,
- MOD_CFG_POLAR_TRACK_COL,
- SAT_CFG_INT_POLAR_TRACK_COL);
-
- daynum_to_str (buff, 8, "%H:%M", time);
-
- if (x > pv->cx) {
- anchor = GTK_ANCHOR_EAST;
- x -= 5;
- }
- else {
- anchor = GTK_ANCHOR_WEST;
- x += 5;
- }
-
- item = goo_canvas_text_model_new (root, buff,
- (gdouble) x, (gdouble) y,
- -1, anchor,
- "font", "Sans 7",
- "fill-color-rgba", col,
- NULL);
-
- goo_canvas_item_model_lower (item, NULL);
-
- return item;
-}
Modified: trunk/src/gtk-polar-view.c
===================================================================
--- trunk/src/gtk-polar-view.c 2011-11-12 19:49:28 UTC (rev 952)
+++ trunk/src/gtk-polar-view.c 2011-11-13 01:28:10 UTC (rev 953)
@@ -68,7 +68,6 @@
gpointer data);
static void update_sat (gpointer key, gpointer value, gpointer data);
static void update_track (gpointer key, gpointer value, gpointer data);
-static void create_track (GtkPolarView *pv, sat_obj_t *obj, sat_t *sat);
static void correct_pole_coor (GtkPolarView *polv, polar_view_pole_t pole,
gfloat *x, gfloat *y, GtkAnchorType *anch);
static gboolean on_motion_notify (GooCanvasItem *item,
@@ -94,7 +93,12 @@
static gchar *los_time_to_str (GtkPolarView *polv, sat_t *sat);
static void gtk_polar_view_store_showtracks (GtkPolarView *pv);
static void gtk_polar_view_load_showtracks (GtkPolarView *pv);
+static GooCanvasItemModel *create_time_tick (GtkPolarView *pv, gdouble time, gfloat x, gfloat y);
+static void azel_to_xy (GtkPolarView *p, gdouble az, gdouble el, gfloat *x, gfloat *y);
+static void xy_to_azel (GtkPolarView *p, gfloat x, gfloat y, gfloat *az, gfloat *el);
+
+
static GtkVBoxClass *parent_class = NULL;
@@ -833,17 +837,9 @@
/* remove sky track */
if (obj->showtrack) {
- idx = goo_canvas_item_model_find_child (root, obj->track);
- if (idx != -1)
- goo_canvas_item_model_remove_child (root, idx);
+ gtk_polar_view_delete_track(polv,obj,sat);
+ }
- for (i = 0; i < TRACK_TICK_NUM; i++) {
- idx = goo_canvas_item_model_find_child (root, obj->trtick[i]);
- if (idx != -1)
- goo_canvas_item_model_remove_child (root, idx);
- }
- }
-
/* free pass info */
free_pass (obj->pass);
obj->pass=NULL;
@@ -946,7 +942,7 @@
/* Finally, create the sky track if necessary */
if (obj->showtrack)
- create_track (polv, obj, sat);
+ gtk_polar_view_create_track (polv, obj, sat);
}
}
@@ -1033,7 +1029,7 @@
/* Finally, create the sky track if necessary */
if (obj->showtrack)
- create_track (polv, obj, sat);
+ gtk_polar_view_create_track (polv, obj, sat);
} else {
/* obj == NULL */
@@ -1128,7 +1124,6 @@
}
-/**** FIXME: DUPLICATE from gtk-polar-view-popup.c - needed by create_track ******/
static GooCanvasItemModel *create_time_tick (GtkPolarView *pv, gdouble time, gfloat x, gfloat y)
{
GooCanvasItemModel *item;
@@ -1175,7 +1170,7 @@
* Note: This function is only used when the the satellite comes within range
* and the ALWAYS_SHOW_SKY_TRACK option is TRUE.
*/
-static void create_track (GtkPolarView *pv, sat_obj_t *obj, sat_t *sat)
+void gtk_polar_view_create_track (GtkPolarView *pv, sat_obj_t *obj, sat_t *sat)
{
guint i;
GooCanvasItemModel *root;
@@ -1277,12 +1272,29 @@
}
+void gtk_polar_view_delete_track (GtkPolarView *pv, sat_obj_t *obj, sat_t *sat)
+{
+ gint idx,i;
+ GooCanvasItemModel *root;
+
+ root = goo_canvas_get_root_item_model (GOO_CANVAS (pv->canvas));
+ idx = goo_canvas_item_model_find_child (root, obj->track);
+
+ if (idx != -1) {
+ goo_canvas_item_model_remove_child (root, idx);
+ }
+
+ for (i = 0; i < TRACK_TICK_NUM; i++) {
+ idx = goo_canvas_item_model_find_child (root, obj->trtick[i]);
+
+ if (idx != -1) {
+ goo_canvas_item_model_remove_child (root, idx);
+ }
+ }
+}
-
-
-
/** \brief Convert Az/El to canvas based XY coordinates. */
-void
+static void
azel_to_xy (GtkPolarView *p, gdouble az, gdouble el, gfloat *x, gfloat *y)
{
gdouble rel;
@@ -1328,7 +1340,7 @@
/** \brief Convert canvas based coordinates to Az/El. */
-void
+static void
xy_to_azel (GtkPolarView *p, gfloat x, gfloat y, gfloat *az, gfloat *el)
{
gfloat rel;
Modified: trunk/src/gtk-polar-view.h
===================================================================
--- trunk/src/gtk-polar-view.h 2011-11-12 19:49:28 UTC (rev 952)
+++ trunk/src/gtk-polar-view.h 2011-11-13 01:28:10 UTC (rev 953)
@@ -152,12 +152,12 @@
void gtk_polar_view_update (GtkWidget *widget);
void gtk_polar_view_reconf (GtkWidget *widget, GKeyFile *cfgdat);
-void azel_to_xy (GtkPolarView *p, gdouble az, gdouble el, gfloat *x, gfloat *y);
-void xy_to_azel (GtkPolarView *p, gfloat x, gfloat y, gfloat *az, gfloat *el);
-
void gtk_polar_view_reload_sats (GtkWidget *polv, GHashTable *sats);
void gtk_polar_view_select_sat (GtkWidget *widget, gint catnum);
+void gtk_polar_view_create_track (GtkPolarView *pv, sat_obj_t *obj, sat_t *sat);
+void gtk_polar_view_delete_track (GtkPolarView *pv, sat_obj_t *obj, sat_t *sat);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|