From: William J B. <wj...@us...> - 2007-01-28 17:34:31
|
Update of /cvsroot/groundstation/gpredict2/src In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv6727 Modified Files: gtk-sat-map.c Log Message: Added support for remapping satellite labels. Index: gtk-sat-map.c =================================================================== RCS file: /cvsroot/groundstation/gpredict2/src/gtk-sat-map.c,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** gtk-sat-map.c 18 Dec 2006 22:23:07 -0000 1.29 --- gtk-sat-map.c 28 Jan 2007 17:34:28 -0000 1.30 *************** *** 4,11 **** Copyright (C) 2001-2006 Alexandru Csete, OZ9AEC. ! Copyright (C) 2006 William J Beksi, KC2EXL. Authors: Alexandru Csete <cs...@us...> ! William J Beksi <wj...@us...> Comments, questions and bugreports should be submitted via --- 4,11 ---- Copyright (C) 2001-2006 Alexandru Csete, OZ9AEC. ! Copyright (C) 2006-2007 William J Beksi, KC2EXL. Authors: Alexandru Csete <cs...@us...> ! William J Beksi <wj...@us...> Comments, questions and bugreports should be submitted via *************** *** 31,36 **** /** \brief Satellite Map Widget. * ! * More info... ! * * */ --- 31,39 ---- /** \brief Satellite Map Widget. * ! * The satellite map widget is responsible for plotting and updating information ! * relevent to each satellite. This information includes the satellite position, ! * label, and footprint. Satellites are stored in a hash table by their catalog ! * number. The satellite map widget is also responsible for loading and resizing ! * the map. * */ *************** *** 58,65 **** #include <goocanvas.h> - #define MARKER_SIZE_HALF 1 - static void gtk_sat_map_class_init (GtkSatMapClass *class); static void gtk_sat_map_init (GtkSatMap *polview); --- 61,66 ---- *************** *** 109,113 **** ! GtkType gtk_sat_map_get_type () --- 110,114 ---- ! /** \brief Register the satellite map widget. */ GtkType gtk_sat_map_get_type () *************** *** 138,141 **** --- 139,143 ---- + /** \brief Initialize a GtkSatMapClass object. */ static void gtk_sat_map_class_init (GtkSatMapClass *class) *************** *** 182,185 **** --- 184,188 ---- + /** \brief Destroy a GtkSatMap widget. */ static void gtk_sat_map_destroy (GtkObject *object) *************** *** 191,194 **** --- 194,203 ---- + /** \brief Initialize and plot each satellite on a canvas model. + * + * This function creates a canvas model and loads the background map + * onto the canvas. Each satellite is then plotted on the map. + * + */ GtkWidget* gtk_sat_map_new (GKeyFile *cfgdata, GHashTable *sats, qth_t *qth) *************** *** 198,202 **** guint32 col; - satmap = g_object_new (GTK_TYPE_SAT_MAP, NULL); --- 207,210 ---- *************** *** 252,263 **** load_map_file (GTK_SAT_MAP (satmap)); ! /* initial size request should be based on map size but if we do this we can not shrink the canvas below this size even though the map shrinks => better to set default size of ! main container window */ /* gtk_widget_set_size_request (GTK_SAT_MAP (satmap)->canvas, */ ! /* gdk_pixbuf_get_width (GTK_SAT_MAP (satmap)->origmap), */ ! /* gdk_pixbuf_get_height (GTK_SAT_MAP (satmap)->origmap)); */ goo_canvas_view_set_bounds (GOO_CANVAS_VIEW (GTK_SAT_MAP (satmap)->canvas), 0, 0, --- 260,271 ---- load_map_file (GTK_SAT_MAP (satmap)); ! /* Initial size request should be based on map size but if we do this we can not shrink the canvas below this size even though the map shrinks => better to set default size of ! main container window. */ /* gtk_widget_set_size_request (GTK_SAT_MAP (satmap)->canvas, */ ! /* gdk_pixbuf_get_width (GTK_SAT_MAP (satmap)->origmap), */ ! /* gdk_pixbuf_get_height (GTK_SAT_MAP (satmap)->origmap)); */ goo_canvas_view_set_bounds (GOO_CANVAS_VIEW (GTK_SAT_MAP (satmap)->canvas), 0, 0, *************** *** 284,288 **** g_hash_table_foreach (GTK_SAT_MAP (satmap)->sats, plot_sat, GTK_SAT_MAP (satmap)); ! //gtk_box_pack_start (GTK_BOX (satmap), GTK_SAT_MAP (satmap)->swin, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER (satmap), GTK_SAT_MAP (satmap)->canvas); --- 292,296 ---- g_hash_table_foreach (GTK_SAT_MAP (satmap)->sats, plot_sat, GTK_SAT_MAP (satmap)); ! /* gtk_box_pack_start (GTK_BOX (satmap), GTK_SAT_MAP (satmap)->swin, TRUE, TRUE, 0); */ gtk_container_add (GTK_CONTAINER (satmap), GTK_SAT_MAP (satmap)->canvas); *************** *** 291,295 **** ! /* create canvas model and various items */ static GooCanvasModelSimple * create_canvas_model (GtkSatMap *satmap) --- 299,309 ---- ! /** \brief Create the map items on the canvas. ! * ! * This function intializes the map dimensions and sets up the cursor track. ! * It creates and sets all of the static map items (QTH, grid lines, etc.) ! * on the canvas. ! * ! */ static GooCanvasModelSimple * create_canvas_model (GtkSatMap *satmap) *************** *** 311,316 **** satmap->y0 = 0; - /* create static items (eg bgd map, grid lines, qth) as done in GtkPolarView */ - /* background map */ satmap->map = goo_canvas_image_new (root, --- 325,328 ---- *************** *** 365,373 **** /* For now only QTH name and location. It would be nice with coordinates (remember NWSE setting) ! and Maidenhead locator, when using hamlib ! */ ! /* Note: I used pango markup to set the background color, I didn't find any other obvious ways to get the text height in pixels to draw rectangle. ! */ buff = g_strdup_printf ("<span background=\"#%s\"> %s \302\267 %s </span>", satmap->infobgd, --- 377,385 ---- /* For now only QTH name and location. It would be nice with coordinates (remember NWSE setting) ! and Maidenhead locator, when using hamlib. ! ! Note: I used pango markup to set the background color, I didn't find any other obvious ways to get the text height in pixels to draw rectangle. ! */ buff = g_strdup_printf ("<span background=\"#%s\"> %s \302\267 %s </span>", satmap->infobgd, *************** *** 576,580 **** goo_canvas_item_raise (satmap->next, NULL); goo_canvas_item_raise (satmap->curs, NULL); - } --- 588,591 ---- *************** *** 698,704 **** NULL); } - } - } --- 709,713 ---- *************** *** 832,836 **** switch (event->button) { ! /* pop-up menu */ case 3: catpoint = g_try_new0 (gint, 1); --- 841,845 ---- switch (event->button) { ! /* pop-up menu */ case 3: catpoint = g_try_new0 (gint, 1); *************** *** 844,848 **** } else { ! /* clicked on map -> map pop-up in the future */ } --- 853,857 ---- } else { ! /* clicked on map -> map pop-up in the future */ } *************** *** 880,890 **** guint32 col; - - catpoint = g_try_new0 (gint, 1); *catpoint = catnum; switch (event->button) { - /* Select / de-select satellite */ case 1: --- 889,896 ---- *************** *** 898,902 **** obj->selected = !obj->selected; - if (obj->selected) { col = mod_cfg_get_int (satmap->cfgdata, --- 904,907 ---- *************** *** 935,941 **** g_hash_table_foreach (satmap->obj, clear_selection, catpoint); } - break; - default: break; --- 940,944 ---- *************** *** 943,947 **** g_free (catpoint); - return TRUE; --- 946,949 ---- *************** *** 1084,1088 **** ! /* Arccosine implementation. * Returns a value between zero and two pi. * Borrowed from gsat 0.9 by Xavier Crehueras, EB3CZS. --- 1086,1091 ---- ! /** \brief Arccosine implementation. ! * * Returns a value between zero and two pi. * Borrowed from gsat 0.9 by Xavier Crehueras, EB3CZS. *************** *** 1103,1107 **** ! /** \brief Check whether footprint covers North or South pole. */ static gboolean pole_is_covered (sat_t *sat) --- 1106,1110 ---- ! /** \brief Check whether the footprint covers the North or South pole. */ static gboolean pole_is_covered (sat_t *sat) *************** *** 1120,1124 **** ! /** \brief Mirror footprint longitude */ static gboolean mirror_lon (sat_t *sat, gdouble rangelon, gdouble *mlon) --- 1123,1127 ---- ! /** \brief Mirror the footprint longitude. */ static gboolean mirror_lon (sat_t *sat, gdouble rangelon, gdouble *mlon) *************** *** 1127,1134 **** gboolean warped = FALSE; - if (sat->ssplon < 0.0) { /* western longitude */ - if (rangelon < 0.0) { /* rangelon has not been warped over */ --- 1130,1135 ---- *************** *** 1198,1202 **** guint numrc = 1; - /* Range circle calculations. * Borrowed from gsat 0.9.0 by Xavier Crehueras, EB3CZS --- 1199,1202 ---- *************** *** 1253,1262 **** points1->coords[718-2*azi] = msx; points1->coords[719-2*azi] = msy; - } /* points1 ow contains 360 pairs of map-based XY coordinates. ! Check whether action 1, 2 or 3 has to be performed ! */ /* pole is covered => sort points1 and add additional points */ --- 1253,1261 ---- points1->coords[718-2*azi] = msx; points1->coords[719-2*azi] = msy; } /* points1 ow contains 360 pairs of map-based XY coordinates. ! Check whether actions 1, 2 or 3 have to be performed. ! */ /* pole is covered => sort points1 and add additional points */ *************** *** 1307,1311 **** gint n,n1,n2,ns,i,j,k; ! /* initialise parameters */ n = points1->num_points; n1 = 0; --- 1306,1310 ---- gint n,n1,n2,ns,i,j,k; ! /* initialize parameters */ n = points1->num_points; n1 = 0; *************** *** 1318,1322 **** tps2 = goo_canvas_points_new (n); - //if ((sspx >= (satmap->x0 + satmap->width - 0.6)) || // (sspx >= (satmap->x0 - 0.6))) { --- 1317,1320 ---- *************** *** 1324,1328 **** // (sspx == (satmap->x0))) { if ((sat->ssplon >= 179.4) || (sat->ssplon <= -179.4)) { - /* sslon = +/-180 deg. - copy points with (x > satmap->x0+satmap->width/2) to tps1 --- 1322,1325 ---- *************** *** 1349,1353 **** else if (sspx < (satmap->x0 + satmap->width / 2)) { - /* We are on the left side of the map. Scan through points1 until we get to x > sspx (i=ns): --- 1346,1349 ---- *************** *** 1386,1390 **** n1++; } - } else { --- 1382,1385 ---- *************** *** 1490,1496 **** sort_points_x (GtkSatMap *satmap, sat_t *sat, GooCanvasPoints *points, gint num) { ! gsize size; ! ! size = 2*sizeof(double); /* call g_qsort_with_data, which warps the qsort function --- 1485,1489 ---- sort_points_x (GtkSatMap *satmap, sat_t *sat, GooCanvasPoints *points, gint num) { ! gsize size = 2*sizeof(double); /* call g_qsort_with_data, which warps the qsort function *************** *** 1544,1548 **** gsize size; - size = 2*sizeof(double); --- 1537,1540 ---- *************** *** 1551,1555 **** g_qsort_with_data (points->coords, num, size, compare_coordinates_y, NULL); - } --- 1543,1546 ---- *************** *** 1576,1580 **** double *ea = (double *)a; double *eb = (double *)b; - if (ea[0] < eb[0]) { --- 1567,1570 ---- *************** *** 1586,1590 **** } - return 0; } --- 1576,1579 ---- *************** *** 1621,1635 **** } - return 0; } ! /** \brief Plot Satellite. * \param key The hash table key. * \param value Pointer to the satellite. * \param data Pointer to the GtkSatMap widget. * ! * This function creates and initialises the canvas objects (rectangle, label, * footprint) for a satellite. The function is called as a g_hash_table_foreach * callback. --- 1610,1623 ---- } return 0; } ! /** \brief Plot a satellite. * \param key The hash table key. * \param value Pointer to the satellite. * \param data Pointer to the GtkSatMap widget. * ! * This function creates and initializes the canvas objects (rectangle, label, * footprint) for a satellite. The function is called as a g_hash_table_foreach * callback. *************** *** 1653,1657 **** lonlat_to_xy (satmap, sat->ssplon, sat->ssplat, &x, &y); ! /* create and initialise a sat object */ obj = g_try_new (sat_map_obj_t, 1); --- 1641,1645 ---- lonlat_to_xy (satmap, sat->ssplon, sat->ssplat, &x, &y); ! /* create and initialize a sat object */ obj = g_try_new (sat_map_obj_t, 1); *************** *** 1669,1673 **** root = goo_canvas_model_get_root_item (model); ! /* satellite colour */ col = mod_cfg_get_int (satmap->cfgdata, MOD_CFG_MAP_SECTION, --- 1657,1661 ---- root = goo_canvas_model_get_root_item (model); ! /* satellite color */ col = mod_cfg_get_int (satmap->cfgdata, MOD_CFG_MAP_SECTION, *************** *** 1707,1711 **** g_object_set_data (G_OBJECT (obj->label), "catnum", GINT_TO_POINTER (*catnum)); ! /* initialise points for footprint */ points1 = goo_canvas_points_new (360); points2 = goo_canvas_points_new (360); --- 1695,1699 ---- g_object_set_data (G_OBJECT (obj->label), "catnum", GINT_TO_POINTER (*catnum)); ! /* initialize points for footprint */ points1 = goo_canvas_points_new (360); points2 = goo_canvas_points_new (360); *************** *** 1745,1775 **** goo_canvas_points_unref (points2); - /* add sat to hash table */ g_hash_table_insert (satmap->obj, catnum, obj); - } ! /** \brief Update a given satellite */ static void update_sat (gpointer key, gpointer value, gpointer data) { ! gint *catnum; ! GtkSatMap *satmap = GTK_SAT_MAP (data); ! sat_map_obj_t *obj = NULL; ! sat_t *sat = SAT(value); ! gfloat x, y; ! gdouble oldx, oldy; ! gdouble now = get_current_daynum (); ! GooCanvasModel *model; ! GooCanvasItem *root; ! gint idx; ! guint32 col,covcol; //gdouble sspla,ssplo; - model = goo_canvas_view_get_model (GOO_CANVAS_VIEW (satmap->canvas)); root = goo_canvas_model_get_root_item (model); --- 1733,1760 ---- goo_canvas_points_unref (points2); /* add sat to hash table */ g_hash_table_insert (satmap->obj, catnum, obj); } ! /** \brief Update a given satellite. */ static void update_sat (gpointer key, gpointer value, gpointer data) { ! gint *catnum; ! GtkSatMap *satmap = GTK_SAT_MAP (data); ! sat_map_obj_t *obj = NULL; ! sat_t *sat = SAT(value); ! gfloat x, y; ! gdouble oldx, oldy; ! gdouble now = get_current_daynum (); ! GooCanvasModel *model; ! GooCanvasItem *root; ! gint idx; ! guint32 col,covcol; //gdouble sspla,ssplo; model = goo_canvas_view_get_model (GOO_CANVAS_VIEW (satmap->canvas)); root = goo_canvas_model_get_root_item (model); *************** *** 1778,1782 **** *catnum = sat->tle.catnr; - /* update next AOS */ if ((sat->aos > now) && (sat->aos < satmap->naos)) { --- 1763,1766 ---- *************** *** 1815,1825 **** NULL); ! g_object_set (obj->label, ! "x", (gdouble) (x), ! "y", (gdouble) (y+2), ! NULL); ! ! /* initialise points for footprint */ points1 = goo_canvas_points_new (360); points2 = goo_canvas_points_new (360); --- 1799,1830 ---- NULL); ! /* update sat label */ ! if (x < 50) { ! g_object_set (obj->label, ! "x", (gdouble) (x+3), ! "y", (gdouble) (y), ! "anchor", GTK_ANCHOR_WEST, ! NULL); ! } else if ((satmap->width - x ) < 50) { ! g_object_set (obj->label, ! "x", (gdouble) (x), ! "y", (gdouble) (y), ! "anchor", GTK_ANCHOR_EAST, ! NULL); ! } else if ((satmap->height - y) < 25) { ! g_object_set (obj->label, ! "x", (gdouble) (x), ! "y", (gdouble) (y-2), ! "anchor", GTK_ANCHOR_SOUTH, ! NULL); ! } else { ! g_object_set (obj->label, ! "x", (gdouble) (x), ! "y", (gdouble) (y+2), ! "anchor", GTK_ANCHOR_NORTH, ! NULL); ! } ! /* initialize points for footprint */ points1 = goo_canvas_points_new (360); points2 = goo_canvas_points_new (360); *************** *** 1834,1840 **** if (obj->newrcnum == 2) { - if (obj->oldrcnum == 1) { - /* we need to create the second part */ if (obj->selected) { --- 1839,1843 ---- *************** *** 1850,1855 **** SAT_CFG_INT_MAP_SAT_COL); } ! ! /* are coverage colour */ if (obj->showcov) { covcol = mod_cfg_get_int (satmap->cfgdata, --- 1853,1857 ---- SAT_CFG_INT_MAP_SAT_COL); } ! /* coverage color */ if (obj->showcov) { covcol = mod_cfg_get_int (satmap->cfgdata, *************** *** 1861,1865 **** covcol = 0x00000000; } - obj->range2 = goo_canvas_item_new (root, GOO_TYPE_CANVAS_POLYLINE, "points", points2, --- 1863,1866 ---- *************** *** 1883,1887 **** if (obj->oldrcnum == 2) { /* remove second part */ - idx = goo_canvas_item_find_child (root, obj->range2); if (idx != -1) { --- 1884,1887 ---- *************** *** 1900,1904 **** /* if ground track is visible check whether we have passed into a new orbit, in which case we need to recalculate the ground track ! */ if (obj->showtrack) { if (obj->track_orbit != sat->orbit) { --- 1900,1904 ---- /* if ground track is visible check whether we have passed into a new orbit, in which case we need to recalculate the ground track ! */ if (obj->showtrack) { if (obj->track_orbit != sat->orbit) { *************** *** 1915,1919 **** ! /** \brief Update info about selected satellite. */ static void update_selected (GtkSatMap *satmap, sat_t *sat) --- 1915,1919 ---- ! /** \brief Update information about the selected satellite. */ static void update_selected (GtkSatMap *satmap, sat_t *sat) *************** *** 1935,1939 **** } - /* convert julian date to seconds */ s = (guint) (number * 86400); --- 1935,1938 ---- *************** *** 1988,1992 **** ! /** \brief Add grid lines and labels to map. */ static void draw_grid_lines (GtkSatMap *satmap, GooCanvasItem *root) --- 1987,1991 ---- ! /** \brief Add grid lines and labels to the map. */ static void draw_grid_lines (GtkSatMap *satmap, GooCanvasItem *root) *************** *** 1996,2001 **** guint i; ! ! /* initialise algo parameters */ col = mod_cfg_get_int (satmap->cfgdata, MOD_CFG_MAP_SECTION, --- 1995,1999 ---- guint i; ! /* initialize algo parameters */ col = mod_cfg_get_int (satmap->cfgdata, MOD_CFG_MAP_SECTION, *************** *** 2006,2013 **** ystep = (gdouble) (30.0 * satmap->height / 180.0); - /* horizontal grid */ for (i = 0; i < 5; i++) { - /* line */ satmap->gridh[i] = goo_canvas_polyline_new_line (root, --- 2004,2009 ---- *************** *** 2036,2040 **** /* vertical grid */ for (i = 0; i < 11; i++) { - /* line */ satmap->gridv[i] = goo_canvas_polyline_new_line (root, --- 2032,2035 ---- *************** *** 2058,2064 **** else goo_canvas_item_lower (satmap->gridv[i], satmap->map); - } - } --- 2053,2057 ---- *************** *** 2071,2075 **** guint i; - xstep = (gdouble) 30.0 * ((gdouble) satmap->width) / 360.0; ystep = (gdouble) 30.0 * ((gdouble) satmap->height) / 180.0; --- 2064,2067 ---- *************** *** 2100,2104 **** /* vertical grid */ for (i = 0; i < 11; i++) { - /* update line */ line = goo_canvas_points_new (2); --- 2092,2095 ---- *************** *** 2119,2136 **** else goo_canvas_item_lower (satmap->gridv[i], satmap->map); - } } ! ! /* public wrapper for private conversion function */ ! void gtk_sat_map_lonlat_to_xy (GtkSatMap *m, ! gdouble lon, gdouble lat, ! gdouble *x, gdouble *y) { gfloat fx,fy; - fx = (gfloat) *x; fy = (gfloat) *y; --- 2110,2124 ---- else goo_canvas_item_lower (satmap->gridv[i], satmap->map); } } ! /** \brief Public wrapper for private conversion function. */ ! void gtk_sat_map_lonlat_to_xy (GtkSatMap *m, ! gdouble lon, gdouble lat, ! gdouble *x, gdouble *y) { gfloat fx,fy; fx = (gfloat) *x; fy = (gfloat) *y; |