}
static gchar * params_degree_formats[] = {"DDD", "DMM", "DMS", N_("Raw"), NULL};
-static gchar * params_units_distance[] = {"Kilometres", "Miles", NULL};
+static gchar * params_units_distance[] = {N_("Kilometres"), N_("Miles"), N_("Nautical Miles"), NULL};
static gchar * params_units_speed[] = {"km/h", "mph", "m/s", "knots", NULL};
static gchar * params_units_height[] = {"Metres", "Feet", NULL};
static VikLayerParamScale params_scales_lat[] = { {-90.0, 90.0, 0.05, 2} };
#define VIK_METERS_TO_MILES(X) ((X)*VIK_MILES_IN_METER)
#define VIK_MILES_TO_METERS(X) ((X)/VIK_MILES_IN_METER)
+#define VIK_NAUTICAL_MILES_IN_METER 0.000539957
+#define VIK_METERS_TO_NAUTICAL_MILES(X) ((X)*VIK_NAUTICAL_MILES_IN_METER)
+#define VIK_NAUTICAL_MILES_TO_METERS(X) ((X)/VIK_NAUTICAL_MILES_IN_METER)
+
/* MPS - Metres Per Second */
/* MPH - Metres Per Hour */
#define VIK_MPH_IN_MPS 2.23693629
typedef enum {
VIK_UNITS_DISTANCE_KILOMETRES,
VIK_UNITS_DISTANCE_MILES,
+ VIK_UNITS_DISTANCE_NAUTICAL_MILES,
} vik_units_distance_t;
vik_units_distance_t a_vik_get_units_distance ( );
case VIK_UNITS_DISTANCE_MILES:
mydist = VIK_METERS_TO_MILES(dist);
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ mydist = VIK_METERS_TO_NAUTICAL_MILES(dist);
+ break;
// VIK_UNITS_DISTANCE_KILOMETRES:
default:
mydist = dist/1000.0;
case VIK_UNITS_DISTANCE_MILES:
dist_i = VIK_MILES_TO_METERS(dist_i);
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ dist_i = VIK_NAUTICAL_MILES_TO_METERS(dist_i);
+ break;
// VIK_UNITS_DISTANCE_KILOMETRES:
default:
dist_i = dist_i*1000.0;
gdouble len_in_units;
// Setup info dependent on distance units
- if ( a_vik_get_units_distance() == VIK_UNITS_DISTANCE_MILES ) {
- g_snprintf (tbuf4, sizeof(tbuf4), "miles");
- len_in_units = VIK_METERS_TO_MILES(tt.length);
- }
- else {
- g_snprintf (tbuf4, sizeof(tbuf4), "kms");
- len_in_units = tt.length/1000.0;
+ switch ( a_vik_get_units_distance() ) {
+ case VIK_UNITS_DISTANCE_MILES:
+ g_snprintf (tbuf4, sizeof(tbuf4), "miles");
+ len_in_units = VIK_METERS_TO_MILES(tt.length);
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ g_snprintf (tbuf4, sizeof(tbuf4), "NM");
+ len_in_units = VIK_METERS_TO_NAUTICAL_MILES(tt.length);
+ break;
+ default:
+ g_snprintf (tbuf4, sizeof(tbuf4), "kms");
+ len_in_units = tt.length/1000.0;
+ break;
}
// Timing information if available
case VIK_UNITS_DISTANCE_MILES:
g_snprintf (tmp_buf, sizeof(tmp_buf), _("%s%.1f miles %s"), time_buf1, VIK_METERS_TO_MILES(tr_len), time_buf2);
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ g_snprintf (tmp_buf, sizeof(tmp_buf), _("%s%.1f NM %s"), time_buf1, VIK_METERS_TO_NAUTICAL_MILES(tr_len), time_buf2);
+ break;
default:
break;
}
g_sprintf(str, "%d miles", (int)VIK_METERS_TO_MILES(distance));
}
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ if (distance >= VIK_NAUTICAL_MILES_TO_METERS(1) && distance < VIK_NAUTICAL_MILES_TO_METERS(100)) {
+ g_sprintf(str, "%3.2f NM", VIK_METERS_TO_NAUTICAL_MILES(distance));
+ } else if (distance < VIK_NAUTICAL_MILES_TO_METERS(1)) {
+ g_sprintf(str, "%d yards", (int)(distance*1.0936133));
+ } else {
+ g_sprintf(str, "%d NM", (int)VIK_METERS_TO_NAUTICAL_MILES(distance));
+ }
+ break;
default:
// VIK_UNITS_DISTANCE_KILOMETRES
if (distance >= 1000 && distance < 100000) {
case VIK_UNITS_DISTANCE_MILES:
g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(meters_from_start) );
+ break;
default:
g_critical("Houston, we've had a problem. distance=%d", dist_units);
}
case VIK_UNITS_DISTANCE_MILES:
g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(meters_from_start) );
+ break;
default:
g_critical("Houston, we've had a problem. distance=%d", dist_units);
}
if (trackpoint && widgets->w_cur_dist_dist) {
static gchar tmp_buf[20];
- if ( a_vik_get_units_distance () == VIK_UNITS_DISTANCE_MILES )
+ switch ( a_vik_get_units_distance () ) {
+ case VIK_UNITS_DISTANCE_MILES:
g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", widgets->distances[ix]);
- else
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", widgets->distances[ix]);
+ break;
+ default:
g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", widgets->distances[ix]);
+ break;
+ }
gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_dist), tmp_buf);
}
case VIK_UNITS_DISTANCE_MILES:
g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(meters_from_start) );
+ break;
default:
g_critical("Houston, we've had a problem. distance=%d", dist_units);
}
static void draw_grid_x_distance ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, guint ii, gdouble dd, guint xx, vik_units_distance_t dist_units )
{
gchar *label_markup = NULL;
- if ( dist_units == VIK_UNITS_DISTANCE_MILES )
+ switch ( dist_units ) {
+ case VIK_UNITS_DISTANCE_MILES:
if ( ii > 4 )
label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("miles") );
else
label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("miles") );
- else
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ if ( ii > 4 )
+ label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("NM") );
+ else
+ label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("NM") );
+ break;
+ default:
+ // VIK_UNITS_DISTANCE_KILOMETRES:
if ( ii > 4 )
label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("km") );
else
label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("km") );
+ break;
+ }
if ( label_markup ) {
PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
{
// Set to display units from length in metres.
gdouble length = widgets->track_length_inc_gaps;
- if ( dist_units == VIK_UNITS_DISTANCE_MILES )
- length = VIK_METERS_TO_MILES(length);
- else
- // KM
- length = length/1000.0;
-
+ switch (dist_units) {
+ case VIK_UNITS_DISTANCE_MILES:
+ length = VIK_METERS_TO_MILES(length);
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ length = VIK_METERS_TO_NAUTICAL_MILES(length);
+ break;
+ default:
+ // KM
+ length = length/1000.0;
+ break;
+ }
guint index = get_distance_chunk_index ( length );
gdouble dist_per_pixel = length/widgets->profile_width;
// Convert into appropriate units
vik_units_distance_t dist_units = a_vik_get_units_distance ();
- if ( dist_units == VIK_UNITS_DISTANCE_MILES ) {
- for ( i = 0; i < widgets->profile_width; i++ ) {
- widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
- }
- }
- else {
- // Metres - but want in kms
- for ( i = 0; i < widgets->profile_width; i++ ) {
- widgets->distances[i] = widgets->distances[i]/1000.0;
- }
+ switch ( dist_units ) {
+ case VIK_UNITS_DISTANCE_MILES:
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
+ }
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->distances[i] = VIK_METERS_TO_NAUTICAL_MILES(widgets->distances[i]);
+ }
+ break;
+ default:
+ // Metres - but want in kms
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->distances[i] = widgets->distances[i]/1000.0;
+ }
+ break;
}
widgets->duration = vik_track_get_duration ( widgets->tr );
// Assign locally
// mind = 0.0; - Thus not used
gdouble maxd;
- if ( dist_units == VIK_UNITS_DISTANCE_MILES )
+ switch ( dist_units ) {
+ case VIK_UNITS_DISTANCE_MILES:
maxd = VIK_METERS_TO_MILES(vik_track_get_length_including_gaps (tr));
- else
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ maxd = VIK_METERS_TO_NAUTICAL_MILES(vik_track_get_length_including_gaps (tr));
+ break;
+ default:
maxd = vik_track_get_length_including_gaps (tr) / 1000.0;
+ break;
+ }
/* Find suitable chunk index */
gdouble dummy = 0.0; // expect this to remain the same! (not that it's used)
for (i=0; i<=LINES; i++) {
gchar s[32];
- if ( dist_units == VIK_UNITS_DISTANCE_MILES )
+ switch ( dist_units ) {
+ case VIK_UNITS_DISTANCE_MILES:
sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
- else
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ sprintf(s, _("%.1f NM"), ((LINES-i)*chunksd[widgets->cid]));
+ break;
+ default:
sprintf(s, _("%.1f km"), ((LINES-i)*chunksd[widgets->cid]));
+ break;
+ }
draw_grid_y ( window, image, widgets, pix, s, i );
}
case VIK_UNITS_DISTANCE_MILES:
g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(tr_len) );
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(tr_len) );
+ break;
default:
g_critical("Houston, we've had a problem. distance=%d", dist_units);
}
case VIK_UNITS_DISTANCE_MILES:
g_snprintf(tmp_buf, sizeof(tmp_buf), "%.3f miles", (tp_count - seg_count) == 0 ? 0 : VIK_METERS_TO_MILES(tr_len / ( tp_count - seg_count )) );
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.3f NM", (tp_count - seg_count) == 0 ? 0 : VIK_METERS_TO_NAUTICAL_MILES(tr_len / ( tp_count - seg_count )) );
+ break;
default:
g_critical("Houston, we've had a problem. distance=%d", dist_units);
}
g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f m", vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)));
break;
case VIK_UNITS_DISTANCE_MILES:
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f yards", vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord))*1.0936133);
break;
default:
// expect the difference between track points to be small hence use metres or yards
switch (dist_units) {
case VIK_UNITS_DISTANCE_MILES:
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
dist_units_str = g_strdup ( _("yards") );
break;
default:
gdouble distd = vik_track_get_length_to_trackpoint (trk, trkpt);
gchar *dist_units_str = NULL;
vik_units_distance_t dist_units = a_vik_get_units_distance ();
- // expect the difference between track points to be small hence use metres or yards
switch (dist_units) {
case VIK_UNITS_DISTANCE_MILES:
dist_units_str = g_strdup ( _("miles") );
distd = VIK_METERS_TO_MILES(distd);
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ dist_units_str = g_strdup ( _("NM") );
+ distd = VIK_METERS_TO_NAUTICAL_MILES(distd);
+ break;
default:
// VIK_UNITS_DISTANCE_KILOMETRES:
dist_units_str = g_strdup ( _("km") );
// in 0.1 miles (copes better when zoomed in as 1 mile can be too big)
base = VIK_METERS_TO_MILES(vik_coord_diff ( &left, &right )) * 10.0;
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ // in 0.1 NM (copes better when zoomed in as 1 NM can be too big)
+ base = VIK_METERS_TO_NAUTICAL_MILES(vik_coord_diff ( &left, &right )) * 10.0;
+ break;
default:
base = 1; // Keep the compiler happy
g_critical("Houston, we've had a problem. distance=%d", dist_units);
switch (dist_units) {
case VIK_UNITS_DISTANCE_KILOMETRES:
if (unit >= 1000) {
- sprintf(s, "%d km", (int)unit/1000);
+ sprintf(s, "%d km", (int)unit/1000);
} else {
- sprintf(s, "%d m", (int)unit);
+ sprintf(s, "%d m", (int)unit);
}
break;
case VIK_UNITS_DISTANCE_MILES:
// Handle units in 0.1 miles
if (unit < 10.0) {
- sprintf(s, "%0.1f miles", unit/10.0);
+ sprintf(s, "%0.1f miles", unit/10.0);
+ }
+ else if ((int)unit == 10.0) {
+ sprintf(s, "1 mile");
+ }
+ else {
+ sprintf(s, "%d miles", (int)(unit/10.0));
+ }
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ // Handle units in 0.1 NM
+ if (unit < 10.0) {
+ sprintf(s, "%0.1f NM", unit/10.0);
}
else if ((int)unit == 10.0) {
- sprintf(s, "1 mile");
+ sprintf(s, "1 NM");
}
else {
- sprintf(s, "%d miles", (int)(unit/10.0));
+ sprintf(s, "%d NMs", (int)(unit/10.0));
}
break;
default:
switch (dist_units) {
case VIK_UNITS_DISTANCE_KILOMETRES:
if (distance >= 1000 && distance < 100000) {
- g_sprintf(str, "%3.2f km", distance/1000.0);
+ g_sprintf(str, "%3.2f km", distance/1000.0);
} else if (distance < 1000) {
- g_sprintf(str, "%d m", (int)distance);
+ g_sprintf(str, "%d m", (int)distance);
} else {
- g_sprintf(str, "%d km", (int)distance/1000);
+ g_sprintf(str, "%d km", (int)distance/1000);
}
break;
case VIK_UNITS_DISTANCE_MILES:
if (distance >= VIK_MILES_TO_METERS(1) && distance < VIK_MILES_TO_METERS(100)) {
- g_sprintf(str, "%3.2f miles", VIK_METERS_TO_MILES(distance));
+ g_sprintf(str, "%3.2f miles", VIK_METERS_TO_MILES(distance));
} else if (distance < VIK_MILES_TO_METERS(1)) {
- g_sprintf(str, "%d yards", (int)(distance*1.0936133));
+ g_sprintf(str, "%d yards", (int)(distance*1.0936133));
} else {
- g_sprintf(str, "%d miles", (int)VIK_METERS_TO_MILES(distance));
+ g_sprintf(str, "%d miles", (int)VIK_METERS_TO_MILES(distance));
+ }
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ if (distance >= VIK_NAUTICAL_MILES_TO_METERS(1) && distance < VIK_NAUTICAL_MILES_TO_METERS(100)) {
+ g_sprintf(str, "%3.2f NM", VIK_METERS_TO_NAUTICAL_MILES(distance));
+ } else if (distance < VIK_NAUTICAL_MILES_TO_METERS(1)) {
+ g_sprintf(str, "%d yards", (int)(distance*1.0936133));
+ } else {
+ g_sprintf(str, "%d NM", (int)VIK_METERS_TO_NAUTICAL_MILES(distance));
}
break;
default:
vik_units_distance_t dist_units = a_vik_get_units_distance ();
switch (dist_units) {
case VIK_UNITS_DISTANCE_KILOMETRES:
- temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
- break;
+ temp = g_strdup_printf ( "%s %s DIFF %f meters", lat, lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
+ break;
case VIK_UNITS_DISTANCE_MILES:
- temp = g_strdup_printf ( "%s %s DIFF %f miles", lat, lon, VIK_METERS_TO_MILES(vik_coord_diff( &coord, &(s->oldcoord) )) );
- break;
+ temp = g_strdup_printf ( "%s %s DIFF %f miles", lat, lon, VIK_METERS_TO_MILES(vik_coord_diff( &coord, &(s->oldcoord) )) );
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ temp = g_strdup_printf ( "%s %s DIFF %f NM", lat, lon, VIK_METERS_TO_NAUTICAL_MILES(vik_coord_diff( &coord, &(s->oldcoord) )) );
+ break;
default:
- temp = g_strdup_printf ("Just to keep the compiler happy");
- g_critical("Houston, we've had a problem. distance=%d", dist_units);
+ temp = g_strdup_printf ("Just to keep the compiler happy");
+ g_critical("Houston, we've had a problem. distance=%d", dist_units);
}
s->has_oldcoord = FALSE;
case VIK_UNITS_DISTANCE_MILES:
temp = g_strdup_printf ( "%s %s DIFF %f miles", lat, lon, VIK_METERS_TO_MILES (vik_coord_diff( &coord, &(s->oldcoord) )) );
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ temp = g_strdup_printf ( "%s %s DIFF %f NM", lat, lon, VIK_METERS_TO_NAUTICAL_MILES (vik_coord_diff( &coord, &(s->oldcoord) )) );
+ break;
default:
temp = g_strdup_printf ("Just to keep the compiler happy");
g_critical("Houston, we've had a problem. distance=%d", dist_units);
case VIK_UNITS_DISTANCE_MILES:
label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. miles)"), (glong)w, (glong)h, (w*h/2589988.11));
break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. NM)"), (glong)w, (glong)h, (w*h/(1852.0*1852.0)));
+ break;
default:
label_text = g_strdup_printf ("Just to keep the compiler happy");
g_critical("Houston, we've had a problem. distance=%d", dist_units);