diff --git a/defs.h b/defs.h index 52524b93e..c6778ee7f 100644 --- a/defs.h +++ b/defs.h @@ -129,6 +129,9 @@ constexpr double KNOTS_TO_MPS(double a) {return a * kMPSPerKnot;} #define CENTI_TO_MICRO(t) ((t) * 10000) /* Centiseconds to Microseconds */ #define MICRO_TO_CENTI(t) ((t) / 10000) /* Centiseconds to Microseconds */ +constexpr int kDatumOSGB36 = 86; // GPS_Lookup_Datum_Index("OSGB36") +constexpr int kDautmWGS84 = 118; // GPS_Lookup_Datum_Index("WGS 84") + /* Pathname separator character */ #if __WIN32__ # define GB_PATHSEP '\\' @@ -1154,9 +1157,6 @@ enum grid_type { #define GRID_INDEX_MIN grid_lat_lon_ddd #define GRID_INDEX_MAX grid_swiss -#define DATUM_OSGB36 86 -#define DATUM_WGS84 118 - /* bit manipulation functions (util.c) */ char gb_getbit(const void* buf, uint32_t nr); @@ -1199,8 +1199,4 @@ int color_to_bbggrr(const char* cname); #define unknown_alt -99999999.0 #define unknown_color -1 -// TODO: this is a (probably temporary) shim for the C->QString conversion. -// It's here instead of gps to avoid C/C++ linkage issues. -int32_t GPS_Lookup_Datum_Index(const QString& n); - #endif // DEFS_H_INCLUDED_ diff --git a/exif.cc b/exif.cc index 429e50938..8c41c45fa 100644 --- a/exif.cc +++ b/exif.cc @@ -826,7 +826,7 @@ ExifFormat::exif_waypt_from_exif_app(ExifApp* app) const if (idatum < 0) { fatal(MYNAME ": Unknown GPSMapDatum \"%s\"!\n", datum); } - if (idatum != DATUM_WGS84) { + if (idatum != kDautmWGS84) { GPS_Math_WGS84_To_Known_Datum_M(wpt->latitude, wpt->longitude, 0.0, &wpt->latitude, &wpt->longitude, &alt, idatum); } diff --git a/garmin_txt.cc b/garmin_txt.cc index 256d49976..46d4cd3f1 100644 --- a/garmin_txt.cc +++ b/garmin_txt.cc @@ -206,7 +206,7 @@ convert_datum(const Waypoint* wpt, double* dest_lat, double* dest_lon) { double alt; - if (datum_index == DATUM_WGS84) { + if (datum_index == kDautmWGS84) { *dest_lat = wpt->latitude; *dest_lon = wpt->longitude; } else GPS_Math_WGS84_To_Known_Datum_M(wpt->latitude, wpt->longitude, 0.0, @@ -776,10 +776,10 @@ garmin_txt_wr_init(const QString& fname) switch (grid_index) { case grid_bng: /* force datum to "Ord Srvy Grt Britn" */ - datum_index = DATUM_OSGB36; + datum_index = kDatumOSGB36; break; case grid_swiss: /* force datum to WGS84 */ - datum_index = DATUM_WGS84; + datum_index = kDautmWGS84; break; default: datum_index = gt_lookup_datum_index(datum_str, MYNAME); diff --git a/jeeps/gpsmath.h b/jeeps/gpsmath.h index 788e3d4bc..f3915ad57 100644 --- a/jeeps/gpsmath.h +++ b/jeeps/gpsmath.h @@ -142,6 +142,7 @@ double lambda0, double E0, double N0); int32 GPS_Lookup_Datum_Index(const char* n); + int32 GPS_Lookup_Datum_Index(const QString& n); const char* GPS_Math_Get_Datum_Name(int datum_index); #endif diff --git a/main.cc b/main.cc index 02c274687..52bcb9028 100644 --- a/main.cc +++ b/main.cc @@ -17,6 +17,7 @@ */ +#include // for assert #include // for setlocale, LC_NUMERIC, LC_TIME #include // for signal, SIGINT, SIG_ERR #include // for printf, fflush, fgetc, fprintf, stderr, stdin, stdout @@ -50,6 +51,7 @@ #include "format.h" // for Format #include "gbversion.h" // for VERSION_SHA #include "inifile.h" // for inifile_done, inifile_init +#include "jeeps/gpsmath.h" // for GPS_Lookup_Datum_Index #include "session.h" // for start_session, session_exit, session_init #include "src/core/datetime.h" // for DateTime #include "src/core/file.h" // for File @@ -718,6 +720,9 @@ main(int argc, char* argv[]) global_opts.inifile = inifile_init(QString(), MYNAME); } + assert(GPS_Lookup_Datum_Index("OSGB36") == kDatumOSGB36); + assert(GPS_Lookup_Datum_Index("WGS 84") == kDautmWGS84); + Vecs::Instance().init_vecs(); FilterVecs::Instance().init_filter_vecs(); session_init(); diff --git a/nmea.cc b/nmea.cc index dcdf6c0d6..431e505bf 100644 --- a/nmea.cc +++ b/nmea.cc @@ -191,7 +191,7 @@ NmeaFormat::nmea_add_wpt(Waypoint* wpt, route_head* trk) const // This also indicates to nmea_release_wpt that ownership has been // transferred to either the global_waypoint_list or global_track_list. wpt->extra_data = nullptr; - if (datum != DATUM_WGS84) { + if (datum != kDautmWGS84) { double lat, lon, alt; GPS_Math_Known_Datum_To_WGS84_M( wpt->latitude, wpt->longitude, 0, @@ -221,7 +221,7 @@ NmeaFormat::rd_init(const QString& fname) { curr_waypt = nullptr; last_waypt = nullptr; - datum = DATUM_WGS84; + datum = kDautmWGS84; had_checksum = false; CHECK_BOOL(opt_gprmc); diff --git a/ozi.cc b/ozi.cc index a6aed2d88..658a8a26b 100644 --- a/ozi.cc +++ b/ozi.cc @@ -215,7 +215,7 @@ ozi_set_time_str(const QString& str, Waypoint* waypointp) static void ozi_convert_datum(Waypoint* wpt) { - if (datum != DATUM_WGS84) { + if (datum != kDautmWGS84) { double lat, lon, alt; GPS_Math_Known_Datum_To_WGS84_M(wpt->latitude, wpt->longitude, 0.0, &lat, &lon, &alt, datum); diff --git a/parse.cc b/parse.cc index 62b099d6d..e589e5079 100644 --- a/parse.cc +++ b/parse.cc @@ -207,7 +207,7 @@ parse_coordinates(const char* str, int datum, const grid_type grid, break; case grid_bng: - datum = DATUM_WGS84; /* fix */ + datum = kDautmWGS84; /* fix */ format = "%2s %lf %lf%n"; ct = sscanf(str, format, map, &lx, &ly, @@ -238,7 +238,7 @@ parse_coordinates(const char* str, int datum, const grid_type grid, case grid_swiss: { double east, north; - datum = DATUM_WGS84; /* fix */ + datum = kDautmWGS84; /* fix */ format = "%lf %lf%n"; ct = sscanf(str, format, &east, &north, &result); @@ -265,7 +265,7 @@ parse_coordinates(const char* str, int datum, const grid_type grid, lon = -lon; } - if (datum != DATUM_WGS84) { + if (datum != kDautmWGS84) { double alt; GPS_Math_Known_Datum_To_WGS84_M(lat, lon, 0.0, &lat, &lon, &alt, datum); diff --git a/unicsv.cc b/unicsv.cc index 5ed30e6c6..0f710b666 100644 --- a/unicsv.cc +++ b/unicsv.cc @@ -596,15 +596,15 @@ UnicsvFormat::unicsv_parse_one_line(const QString& ibuf) &wpt->latitude, &wpt->longitude, MYNAME); /* coordinates from parse_coordinates are in WGS84 don't convert a second time */ - src_datum = DATUM_WGS84; + src_datum = kDautmWGS84; break; case fld_bng: - parse_coordinates(value, DATUM_OSGB36, grid_bng, + parse_coordinates(value, kDatumOSGB36, grid_bng, &wpt->latitude, &wpt->longitude, MYNAME); /* coordinates from parse_coordinates are in WGS84 don't convert a second time */ - src_datum = DATUM_WGS84; + src_datum = kDautmWGS84; break; case fld_bng_zone: @@ -621,11 +621,11 @@ UnicsvFormat::unicsv_parse_one_line(const QString& ibuf) break; case fld_swiss: - parse_coordinates(value, DATUM_WGS84, grid_swiss, + parse_coordinates(value, kDautmWGS84, grid_swiss, &wpt->latitude, &wpt->longitude, MYNAME); /* coordinates from parse_coordinates are in WGS84 don't convert a second time */ - src_datum = DATUM_WGS84; + src_datum = kDautmWGS84; break; case fld_swiss_easting: @@ -1051,15 +1051,15 @@ UnicsvFormat::unicsv_parse_one_line(const QString& ibuf) fatal(MYNAME ": Unable to convert BNG coordinates (%s %.f %.f)!\n", bng_zone, bng_easting, bng_northing); } - src_datum = DATUM_WGS84; /* don't convert afterwards */ + src_datum = kDautmWGS84; /* don't convert afterwards */ } else if ((swiss_easting != kUnicsvUnknown) && (swiss_northing != kUnicsvUnknown)) { GPS_Math_Swiss_EN_To_WGS84(swiss_easting, swiss_northing, &wpt->latitude, &wpt->longitude); - src_datum = DATUM_WGS84; /* don't convert afterwards */ + src_datum = kDautmWGS84; /* don't convert afterwards */ } } - if ((src_datum != DATUM_WGS84) && + if ((src_datum != kDautmWGS84) && (wpt->latitude != kUnicsvUnknown) && (wpt->longitude != kUnicsvUnknown)) { double alt; GPS_Math_Known_Datum_To_WGS84_M(wpt->latitude, wpt->longitude, 0.0, @@ -1311,7 +1311,7 @@ UnicsvFormat::unicsv_waypt_disp_cb(const Waypoint* wpt) QString shortname = wpt->shortname; garmin_fs_t* gmsd = garmin_fs_t::find(wpt); - if (unicsv_datum_idx == DATUM_WGS84) { + if (unicsv_datum_idx == kDautmWGS84) { lat = wpt->latitude; lon = wpt->longitude; alt = wpt->altitude; @@ -1712,7 +1712,7 @@ UnicsvFormat::wr_init(const QString& fname) memset(&unicsv_outp_flags, 0, sizeof(unicsv_outp_flags)); unicsv_grid_idx = grid_unknown; - unicsv_datum_idx = DATUM_WGS84; + unicsv_datum_idx = kDautmWGS84; unicsv_fieldsep = kUnicsvFieldSep; unicsv_waypt_ct = 0; @@ -1733,11 +1733,11 @@ UnicsvFormat::wr_init(const QString& fname) /* force datum to "Ord Srvy Grt Britn" / OSGB36 */ /* ! ignore parameter "Datum" ! */ { - unicsv_datum_idx = DATUM_OSGB36; + unicsv_datum_idx = kDatumOSGB36; } else if (unicsv_grid_idx == grid_swiss) /* ! ignore parameter "Datum" ! */ { - unicsv_datum_idx = DATUM_WGS84; /* internal, becomes CH1903 */ + unicsv_datum_idx = kDautmWGS84; /* internal, becomes CH1903 */ } else { unicsv_datum_idx = gt_lookup_datum_index(opt_datum, MYNAME); } diff --git a/xcsv.cc b/xcsv.cc index c4f21ca94..f062444a4 100644 --- a/xcsv.cc +++ b/xcsv.cc @@ -515,7 +515,7 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle: break; /* SPECIAL COORDINATES/GRID */ case XcsvStyle::XT_MAP_EN_BNG: - parse_coordinates(s, DATUM_OSGB36, grid_bng, + parse_coordinates(s, kDatumOSGB36, grid_bng, &wpt->latitude, &wpt->longitude, MYNAME); break; case XcsvStyle::XT_UTM_ZONE: @@ -891,7 +891,7 @@ XcsvFormat::read() wpt_tmp->longitude = -wpt_tmp->longitude; } - if ((xcsv_file->gps_datum_idx > -1) && (xcsv_file->gps_datum_idx != gps_datum_wgs84)) { + if ((xcsv_file->gps_datum_idx > -1) && (xcsv_file->gps_datum_idx != kDautmWGS84)) { double alt; GPS_Math_Known_Datum_To_WGS84_M(wpt_tmp->latitude, wpt_tmp->longitude, 0.0, &wpt_tmp->latitude, &wpt_tmp->longitude, &alt, xcsv_file->gps_datum_idx); @@ -902,7 +902,7 @@ XcsvFormat::read() &wpt_tmp->longitude, parse_data.utm_easting, parse_data.utm_northing, parse_data.utm_zone, parse_data.utm_zonec, - DATUM_WGS84); + kDautmWGS84); } if (parse_data.link_) { @@ -1018,7 +1018,7 @@ XcsvFormat::xcsv_waypt_pr(const Waypoint* wpt) description = shortname; } - if ((xcsv_file->gps_datum_idx > -1) && (xcsv_file->gps_datum_idx != gps_datum_wgs84)) { + if ((xcsv_file->gps_datum_idx > -1) && (xcsv_file->gps_datum_idx != kDautmWGS84)) { double alt; GPS_Math_WGS84_To_Known_Datum_M(latitude, longitude, 0.0, &latitude, &longitude, &alt, xcsv_file->gps_datum_idx); @@ -1863,7 +1863,6 @@ XcsvFormat::rd_init(const QString& fname) if (xcsv_file->gps_datum_idx < 0) { fatal(MYNAME ": datum \"%s\" is not supported.", qPrintable(datum_name)); } - assert(gps_datum_wgs84 == GPS_Lookup_Datum_Index("WGS 84")); } void @@ -1944,7 +1943,6 @@ XcsvFormat::wr_init(const QString& fname) if (xcsv_file->gps_datum_idx < 0) { fatal(MYNAME ": datum \"%s\" is not supported.", qPrintable(datum_name)); } - assert(gps_datum_wgs84 == GPS_Lookup_Datum_Index("WGS 84")); } void diff --git a/xcsv.h b/xcsv.h index 32cd13c66..e4bc620b7 100644 --- a/xcsv.h +++ b/xcsv.h @@ -364,8 +364,6 @@ class XcsvFormat : public Format return (a / 86400.0) + 25569.0; } - static constexpr int gps_datum_wgs84 = 118; // GPS_Lookup_Datum_Index("WGS 84") - /* Member Functions */ static QDateTime yyyymmdd_to_time(const QString& s);