static VikLayerParamData dem_layer_get_param ( VikDEMLayer *vdl, guint16 id, gboolean is_file_operation )
{
  VikLayerParamData rv;
  switch ( id )
  {
    case PARAM_FILES:
      rv.sl = vdl->files;
      if ( is_file_operation )
        // Save in relative format if necessary
        if ( a_vik_get_file_ref_format() == VIK_FILE_REF_FORMAT_RELATIVE )
          rv.sl = dem_layer_convert_to_relative_filenaming ( rv.sl );
      break;
    case PARAM_SOURCE: rv.u = vdl->source; break;
    case PARAM_TYPE: rv.u = vdl->type; break;
    case PARAM_COLOR: rv.c = vdl->color; break;
    case PARAM_MIN_ELEV:
      /* Convert for display in desired units
         NB file operation always in internal units (metres) */
      if (!is_file_operation && a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET )
        rv.d = VIK_METERS_TO_FEET(vdl->min_elev);
      else
        rv.d = vdl->min_elev;
      break;
    case PARAM_MAX_ELEV:
      /* Convert for display in desired units
         NB file operation always in internal units (metres) */
      if (!is_file_operation && a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET )
        rv.d = VIK_METERS_TO_FEET(vdl->max_elev);
      else
        rv.d = vdl->max_elev;
      break;
    default: break;
  }
  return rv;
}
Exemplo n.º 2
0
static VikLayerParamData georef_layer_get_param ( VikGeorefLayer *vgl, guint16 id, gboolean is_file_operation )
{
  VikLayerParamData rv;
  switch ( id )
  {
    case PARAM_IMAGE: {
      gboolean set = FALSE;
      if ( is_file_operation ) {
        if ( vgl->pixbuf && !vgl->image ) {
          // Force creation of image file
          create_image_file ( vgl );
        }
        if ( a_vik_get_file_ref_format() == VIK_FILE_REF_FORMAT_RELATIVE ) {
          gchar *cwd = g_get_current_dir();
          if ( cwd ) {
            rv.s = file_GetRelativeFilename ( cwd, vgl->image );
            if ( !rv.s ) rv.s = "";
              set = TRUE;
          }
        }
      }
      if ( !set )
        rv.s = vgl->image ? vgl->image : "";
      break;
    }
    case PARAM_CN: rv.d = vgl->corner.northing; break;
    case PARAM_CE: rv.d = vgl->corner.easting; break;
    case PARAM_MN: rv.d = vgl->mpp_northing; break;
    case PARAM_ME: rv.d = vgl->mpp_easting; break;
    case PARAM_CZ: rv.u = vgl->corner.zone; break;
    case PARAM_CL: rv.u = vgl->corner.letter; break;
    case PARAM_AA: rv.u = vgl->alpha; break;
    default: break;
  }
  return rv;
}
Exemplo n.º 3
0
static void a_gpspoint_write_waypoint ( const gpointer id, const VikWaypoint *wp, FILE *f )
{
  struct LatLon ll;
  gchar s_lat[COORDS_STR_BUFFER_SIZE];
  gchar s_lon[COORDS_STR_BUFFER_SIZE];
  // Sanity clauses
  if ( !wp )
    return;
  if ( !(wp->name) )
    return;

  vik_coord_to_latlon ( &(wp->coord), &ll );
  a_coords_dtostr_buffer ( ll.lat, s_lat );
  a_coords_dtostr_buffer ( ll.lon, s_lon );
  gchar *tmp_name = slashdup(wp->name);
  fprintf ( f, "type=\"waypoint\" latitude=\"%s\" longitude=\"%s\" name=\"%s\"", s_lat, s_lon, tmp_name );
  g_free ( tmp_name );

  if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) {
    gchar s_alt[COORDS_STR_BUFFER_SIZE];
    a_coords_dtostr_buffer ( wp->altitude, s_alt );
    fprintf ( f, " altitude=\"%s\"", s_alt );
  }
  if ( wp->has_timestamp )
    fprintf ( f, " unixtime=\"%ld\"", wp->timestamp );
  if ( wp->comment )
  {
    gchar *tmp_comment = slashdup(wp->comment);
    fprintf ( f, " comment=\"%s\"", tmp_comment );
    g_free ( tmp_comment );
  }
  if ( wp->description )
  {
    gchar *tmp_description = slashdup(wp->description);
    fprintf ( f, " description=\"%s\"", tmp_description );
    g_free ( tmp_description );
  }
  if ( wp->source )
  {
    gchar *tmp_source = slashdup(wp->source);
    fprintf ( f, " source=\"%s\"", tmp_source );
    g_free ( tmp_source );
  }
  if ( wp->type )
  {
    gchar *tmp_type = slashdup(wp->type);
    fprintf ( f, " xtype=\"%s\"", tmp_type );
    g_free ( tmp_type );
  }
  if ( wp->image )
  {
    gchar *tmp_image = NULL;
    gchar *cwd = NULL;
    if ( a_vik_get_file_ref_format() == VIK_FILE_REF_FORMAT_RELATIVE ) {
      cwd = g_get_current_dir();
      if ( cwd )
        tmp_image = g_strdup ( file_GetRelativeFilename ( cwd, wp->image ) );
    }

    // if cwd not available - use image filename as is
    // this should be an absolute path as set in thumbnails
    if ( !cwd )
      tmp_image = slashdup(wp->image);

    if ( tmp_image )
      fprintf ( f, " image=\"%s\"", tmp_image );

    g_free ( cwd );
    g_free ( tmp_image );
  }
  if ( wp->symbol )
  {
    // Due to changes in garminsymbols - the symbol name is now in Title Case
    // However to keep newly generated .vik files better compatible with older Viking versions
    //   The symbol names will always be lowercase
    gchar *tmp_symbol = g_utf8_strdown(wp->symbol, -1);
    fprintf ( f, " symbol=\"%s\"", tmp_symbol );
    g_free ( tmp_symbol );
  }
  if ( ! wp->visible )
    fprintf ( f, " visible=\"n\"" );
  fprintf ( f, "\n" );
}