static GooCanvasItemModel * create_time_tick (GtkPolarView *pv, gdouble time, gfloat x, gfloat y) { GooCanvasItemModel *item; time_t t; 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); /* convert julian date to struct tm */ t = (time - 2440587.5)*86400.; /* format either local time or UTC depending on check box */ if (sat_cfg_get_bool (SAT_CFG_BOOL_USE_LOCAL_TIME)) strftime (buff, 8, "%H:%M", localtime (&t)); else strftime (buff, 8, "%H:%M", gmtime (&t)); buff[6]='\0'; 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; }
/** \brief Create polylines. */ static void create_polylines (GtkSatMap *satmap, sat_t *sat, qth_t *qth, sat_map_obj_t *obj) { ssp_t *ssp,*buff; /* map coordinates */ double lastx,lasty; GSList *points = NULL; GooCanvasItemModel *root; GooCanvasItemModel *line; GooCanvasPoints *gpoints; guint start; guint i,j,n,num_points; guint32 col; (void) sat; /* prevent unused parameter compiler warning */ (void) qth; /* prevent unused parameter compiler warning */ /* initialise parameters */ lastx = -50.0; lasty = -50.0; start = 0; num_points = 0; n = g_slist_length (obj->track_data.latlon); col = mod_cfg_get_int (satmap->cfgdata, MOD_CFG_MAP_SECTION, MOD_CFG_MAP_TRACK_COL, SAT_CFG_INT_MAP_TRACK_COL); /* loop over each SSP */ for (i = 0; i < n; i++) { buff = (ssp_t *) g_slist_nth_data (obj->track_data.latlon, i); ssp = g_try_new (ssp_t, 1); gtk_sat_map_lonlat_to_xy (satmap, buff->lon, buff->lat, &ssp->lon, &ssp->lat); /* if this is the first point, just add it to the list */ if (i == start) { points = g_slist_prepend (points, ssp); lastx = ssp->lon; lasty = ssp->lat; } else { /* if SSP is on the other side of the map */ if (ssp_wrap_detected (satmap, lastx, ssp->lon)) { points = g_slist_reverse (points); num_points = g_slist_length (points); /* we need at least 2 points to draw a line */ if (num_points > 1) { /* convert SSPs to GooCanvasPoints */ gpoints = goo_canvas_points_new (num_points); for (j = 0; j < num_points; j++) { buff = (ssp_t *) g_slist_nth_data (points, j); gpoints->coords[2*j] = buff->lon; gpoints->coords[2*j+1] = buff->lat; } /* create a new polyline using the current set of points */ root = goo_canvas_get_root_item_model (GOO_CANVAS (satmap->canvas)); line = goo_canvas_polyline_model_new (root, FALSE, 0, "points", gpoints, "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 (gpoints); goo_canvas_item_model_lower (line, obj->marker); /* store line in sat object */ obj->track_data.lines = g_slist_append (obj->track_data.lines, line); } /* reset parameters and continue with a new set */ g_slist_foreach (points, free_ssp, NULL); g_slist_free (points); points = NULL; start = i; lastx = ssp->lon; lasty = ssp->lat; num_points = 0; /* Add current SSP to the new list */ points = g_slist_prepend (points, ssp); lastx = ssp->lon; lasty = ssp->lat; } /* else if this SSP is separable from the previous */ else if ((fabs (lastx - ssp->lon) > 1.0 ) || (fabs(lasty - ssp->lat)>1.0)){ /* add SSP to list */ points = g_slist_prepend (points, ssp); lastx = ssp->lon; lasty = ssp->lon; } /* else if do nothing */ } } /* create (last) line if we have at least two points */ points = g_slist_reverse (points); num_points = g_slist_length (points); if (num_points > 1) { /* convert SSPs to GooCanvasPoints */ gpoints = goo_canvas_points_new (num_points); for (j = 0; j < num_points; j++) { buff = (ssp_t *) g_slist_nth_data (points, j); gpoints->coords[2*j] = buff->lon; gpoints->coords[2*j+1] = buff->lat; } /* create a new polyline using the current set of points */ root = goo_canvas_get_root_item_model (GOO_CANVAS (satmap->canvas)); line = goo_canvas_polyline_model_new (root, FALSE, 0, "points", gpoints, "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 (gpoints); goo_canvas_item_model_lower (line, obj->marker); /* store line in sat object */ obj->track_data.lines = g_slist_append (obj->track_data.lines, line); /* reset parameters and continue with a new set */ g_slist_foreach (points, free_ssp, NULL); g_slist_free (points); } }
/** \brief Manage toggling of Ground Track. * \param item The menu item that was toggled. * \param data Pointer to the GtkPolarView structure. * */ static void track_toggled (GtkCheckMenuItem *item, gpointer data) { GtkPolarView *pv = GTK_POLAR_VIEW (data); sat_obj_t *obj = NULL; sat_t *sat; qth_t *qth; gint idx,i; GooCanvasItemModel *root; pass_detail_t *detail; guint num; GooCanvasPoints *points; gfloat x,y; guint32 col; guint tres,ttidx; /* get satellite object */ obj = SAT_OBJ(g_object_get_data (G_OBJECT (item), "obj")); sat = SAT(g_object_get_data (G_OBJECT (item), "sat")); qth = (qth_t *)(g_object_get_data (G_OBJECT (item), "qth")); if (obj == NULL) { sat_log_log (SAT_LOG_LEVEL_BUG, _("%s:%d: Failed to get satellite object."), __FILE__, __LINE__); return; } /* toggle flag */ obj->showtrack = !obj->showtrack; gtk_check_menu_item_set_active (item, obj->showtrack); root = goo_canvas_get_root_item_model (GOO_CANVAS (pv->canvas)); if (obj->showtrack) { /* add sky track */ /* 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); } else { /* 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); } } } }