-
Notifications
You must be signed in to change notification settings - Fork 128
/
garmin_tables.cc
772 lines (705 loc) · 19.7 KB
/
garmin_tables.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
/*
Garmin icon tables
Based on information provided by Ian Cowley, Sigurd Humerfelt,
and Garmin MapSource
Copyright (C) 2003-2007 Robert Lipe, [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <cstdint> // for int32_t
#include <cstring> // for strncpy, strchr, strlen, strncmp
#include <QChar> // for operator==, QChar
#include <QDebug> // for QDebug
#include <QVector> // for QVector
#include <Qt> // for CaseInsensitive
#include "defs.h"
#include "garmin_tables.h"
#include "jeeps/gpsmath.h" // for GPS_Lookup_Datum_Index, GPS_Math_Get_Datum_Name
#include "src/core/logging.h" // for Fatal
// these tables are in an include file so they can be shared with mkicondoc.
#include "garmin_icon_tables.h" // for garmin_icon_table, garmin_smart_icon_table
#define DEFAULT_ICON_DESCR "Waypoint"
#define DEFAULT_ICON_VALUE 18
/* ICAO country code table */
/* source: https://en.wikipedia.org/wiki/ICAO_airport_code */
struct gt_country_code_t {
const char* cc;
const char* country;
};
static const gt_country_code_t gt_country_codes[] = {
{ "ZM,", "Mongolia" },
{ "ZK,", "North Korea" },
{ "Z*,", "China" },
{ "Y*,", "Australia" },
{ "WS,", "Singapore" },
{ "WP,", "Timor-Leste" },
{ "WM,", "Malaysia (Peninsular Malaysia)" },
{ "WB,", "Brunei, Malaysia (East Malaysia)" },
{ "WA,WI,WQ,WR,", "Indonesia" },
{ "VY,", "Myanmar" },
{ "VV,", "Vietnam" },
{ "VT,", "Thailand" },
{ "VR,", "Maldives" },
{ "VQ,", "Bhutan" },
{ "VN,", "Nepal" },
{ "VM,", "Macau" },
{ "VL,", "Laos" },
{ "VH,", "Hong Kong" },
{ "VG,", "Bangladesh" },
{ "VD,", "Cambodia" },
{ "VC,", "Sri Lanka" },
{ "VA,VE,VI,VO,", "India" },
{ "UT,", "Tajikistan, Turkmenistan, Uzbekistan" },
{ "UM,", "Belarus and Russia (Kaliningrad Oblast)" },
{ "UK,", "Ukraine" },
{ "UG,", "Georgia" },
{ "UD,", "Armenia" },
{ "UC,", "Kyrgyzstan" },
{ "UB,", "Azerbaijan" },
{ "UA,", "Kazakhstan" },
{ "U*,", "Russia" },
{ "TX,", "UK (Bermuda)" },
{ "TV,", "Saint Vincent and the Grenadines" },
{ "TU,", "UK (British Virgin Islands)" },
{ "TT,", "Trinidad and Tobago" },
{ "TR,", "UK (Montserrat)" },
{ "TQ,", "UK (Anguilla)" },
{ "TN,", "Caribbean Netherlands, Aruba, Curaçao, Sint Maarten" },
{ "TL,", "Saint Lucia" },
{ "TK,", "Saint Kitts and Nevis" },
{ "TJ,", "USA (Puerto Rico)" },
{ "TI,", "USA (U.S. Virgin Islands)" },
{ "TG,", "Grenada" },
{ "TF,", "France (Guadeloupe, Martinique, Saint Barthélemy, Saint Martin)" },
{ "TD,", "Dominica" },
{ "TB,", "Barbados" },
{ "TA,", "Antigua and Barbuda" },
{ "SY,", "Guyana" },
{ "SV,", "Venezuela" },
{ "SU,", "Uruguay" },
{ "SP,", "Peru" },
{ "SO,", "France (French Guiana)" },
{ "SM,", "Suriname" },
{ "SL,", "Bolivia" },
{ "SK,", "Colombia" },
{ "SH,", "Chile" },
{ "SG,", "Paraguay" },
{ "SF,", "United Kingdom (Falkland Islands)" },
{ "SE,", "Ecuador" },
{ "SC,", "Chile (including Easter Island)" },
{ "SB,SI,SJ,", "Brazil" },
{ "SA,", "Argentina" },
{ "RP,", "Philippines" },
{ "RO,", "Japan (Okinawa)" },
{ "RK,", "South Korea" },
{ "RJ,", "Japan (Mainland)" },
{ "RC,", "Taiwan" },
{ "PW,", "USA (Wake Island)" },
{ "PT,", "Federated States of Micronesia, Palau" },
{ "PM,", "USA (Midway Island)" },
{ "PL,", "Kiribati (Line Islands)" },
{ "PK,", "Marshall Islands" },
{ "PJ,", "USA (Johnston Atoll)" },
{ "PH,", "USA (Hawaii)" },
{ "PG,", "USA (Guam, Northern Mariana Islands)" },
{ "PC,", "Kiribati (Canton Airfield, Phoenix Islands)" },
{ "PB,", "USA (Baker Island)" },
{ "PA,PF,PO,PP,", "USA (Alaska)" },
{ "OY,", "Yemen" },
{ "OT,", "Qatar" },
{ "OS,", "Syria" },
{ "OR,", "Iraq" },
{ "OP,", "Pakistan" },
{ "OO,", "Oman" },
{ "OM,", "United Arab Emirates" },
{ "OL,", "Lebanon" },
{ "OK,", "Kuwait" },
{ "OJ,", "Jordan and the West Bank" },
{ "OI,", "Iran" },
{ "OE,", "Saudi Arabia" },
{ "OB,", "Bahrain" },
{ "OA,", "Afghanistan" },
{ "NZ,", "New Zealand, Antarctica" },
{ "NW,", "France (New Caledonia)" },
{ "NV,", "Vanuatu" },
{ "NT,", "France (French Polynesia)" },
{ "NS,", "Samoa, United States (American Samoa)" },
{ "NL,", "France (Wallis and Futuna)" },
{ "NI,", "Niue" },
{ "NG,", "Kiribati (Gilbert Islands), Tuvalu" },
{ "NF,", "Fiji, Tonga" },
{ "NC,", "Cook Islands" },
{ "MZ,", "Belize" },
{ "MY,", "Bahamas" },
{ "MW,", "Cayman Islands" },
{ "MU,", "Cuba" },
{ "MT,", "Haiti" },
{ "MS,", "El Salvador" },
{ "MR,", "Costa Rica" },
{ "MP,", "Panama" },
{ "MN,", "Nicaragua" },
{ "MM,", "Mexico" },
{ "MK,", "Jamaica" },
{ "MH,", "Honduras" },
{ "MG,", "Guatemala" },
{ "MD,", "Dominican Republic" },
{ "MB,", "Turks and Caicos Islands" },
{ "LZ,", "Slovakia" },
{ "LY,", "Serbia and Montenegro" },
{ "LX,", "Gibraltar" },
{ "LW,", "Macedonia" },
{ "LV,", "Palestinian Territories" },
{ "LU,", "Moldova" },
{ "LT,", "Turkey" },
{ "LS,", "Switzerland" },
{ "LR,", "Romania" },
{ "LQ,", "Bosnia and Herzegovina" },
{ "LP,", "Portugal (including the Azores and Madeira)" },
{ "LO,", "Austria" },
{ "LN,", "Monaco" },
{ "LM,", "Malta" },
{ "LL,", "Israel" },
{ "LK,", "Czech Republic" },
{ "LJ,", "Slovenia" },
{ "LI,", "Italy" },
{ "LH,", "Hungary" },
{ "LG,", "Greece" },
{ "LF,", "France (Metropolitan France; including Saint-Pierre and Miquelon)" },
{ "LE,", "Spain (mainland section and Balearic Islands)" },
{ "LD,", "Croatia" },
{ "LC,", "Cyprus" },
{ "LB,", "Bulgaria" },
{ "LA,", "Albania" },
{ "K*,", "United States of America" },
{ "HU,", "Uganda" },
{ "HT,", "Tanzania" },
{ "HS,", "Sudan and South Sudan" },
{ "HR,", "Rwanda" },
{ "HL,", "Libya" },
{ "HK,", "Kenya" },
{ "HH,", "Eritrea" },
{ "HE,", "Egypt" },
{ "HD,", "Djibouti" },
{ "HC,", "Somalia (including Somaliland)" },
{ "HB,", "Burundi" },
{ "HA,", "Ethiopia" },
{ "GV,", "Cape Verde" },
{ "GU,", "Guinea" },
{ "GS,", "Western Sahara" },
{ "GQ,", "Mauritania" },
{ "GO,", "Senegal" },
{ "GM,", "Morocco" },
{ "GL,", "Liberia" },
{ "GG,", "Guinea-Bissau" },
{ "GF,", "Sierra Leone" },
{ "GE,", "Spain (Ceuta and Melilla)" },
{ "GC,", "Spain (Canary Islands)" },
{ "GB,", "The Gambia" },
{ "GA,", "Mali" },
{ "FZ,", "Democratic Republic of the Congo" },
{ "FY,", "Namibia" },
{ "FX,", "Lesotho" },
{ "FW,", "Malawi" },
{ "FV,", "Zimbabwe" },
{ "FT,", "Chad" },
{ "FS,", "Seychelles" },
{ "FQ,", "Mozambique" },
{ "FP,", "São Tomé and Príncipe" },
{ "FO,", "Gabon" },
{ "FN,", "Angola" },
{ "FM,", "Comoros, France (Mayotte and Réunion), and Madagascar" },
{ "FL,", "Zambia" },
{ "FK,", "Cameroon" },
{ "FJ,", "British Indian Ocean Territory" },
{ "FI,", "Mauritius" },
{ "FH,", "Saint Helena, Ascension and Tristan da Cunha" },
{ "FG,", "Equatorial Guinea" },
{ "FE,", "Central African Republic" },
{ "FD,", "Swaziland" },
{ "FC,", "Republic of the Congo" },
{ "FB,", "Botswana" },
{ "FA,", "South Africa" },
{ "EY,", "Lithuania" },
{ "EV,", "Latvia" },
{ "ET,", "Germany (military)" },
{ "ES,", "Sweden" },
{ "EP,", "Poland" },
{ "EN,", "Norway" },
{ "EL,", "Luxembourg" },
{ "EK,", "Denmark and the Faroe Islands" },
{ "EI,", "Ireland" },
{ "EH,", "Netherlands" },
{ "EG,", "United Kingdom (and Crown dependencies)" },
{ "EF,", "Finland" },
{ "EE,", "Estonia" },
{ "ED,", "Germany (civil)" },
{ "EB,", "Belgium" },
{ "DX,", "Togo" },
{ "DT,", "Tunisia" },
{ "DR,", "Niger" },
{ "DN,", "Nigeria" },
{ "DI,", "Côte d'Ivoire" },
{ "DG,", "Ghana" },
{ "DF,", "Burkina Faso" },
{ "DB,", "Benin" },
{ "DA,", "Algeria" },
{ "C*,", "Canada" },
{ "BK,", "Kosovo" },
{ "BI,", "Iceland" },
{ "BG,", "Greenland" },
{ "AY,", "Papua New Guinea" },
{ "AN,", "Nauru" },
{ "AG,", "Solomon Islands" },
{ nullptr, nullptr }
};
/* gt_waypt_classes: gdb internal order */
const QStringList gt_waypt_class_names = {
"User Waypoint",
"Airport",
"Intersection",
"NDB",
"VOR",
"Runway Threshold",
"Airport Intersection",
"Airport NDB",
"Map Point",
"Map Area",
"Map Intersection",
"Map Address",
"Map Line",
};
/* gt_display_mode_names: this order is used by most devices */
const QStringList gt_display_mode_names = {
"Symbol & Name",
"Symbol",
"Symbol & Description"
};
struct grid_mapping_t {
QString shortname;
QString longname;
grid_type grid;
};
/* gt_mps_grid_names: !!! degree sign substituted with '*' !!! */
static const QVector<grid_mapping_t> gt_mps_grid_names = {
{ "ddd", "Lat/Lon hddd.ddddd*", grid_lat_lon_ddd },
{ "dmm", "Lat/Lon hddd*mm.mmm'", grid_lat_lon_dmm },
{ "dms", "Lat/Lon hddd*mm'ss.s\"", grid_lat_lon_dms },
{ "bng", "British National Grid", grid_bng },
{ "utm", "UTM", grid_utm },
{ "swiss", "Swiss grid", grid_swiss },
};
/* gt_mps_datum_names: */
struct datum_mapping_t {
QString jeeps_name;
QString mps_name;
};
/* will be continued (when requested) */
static const QVector<datum_mapping_t> gt_mps_datum_names = {
{ "Alaska-NAD27", "NAD27 Alaska" },
{ "Bahamas NAD27", "NAD27 Bahamas" },
{ "Canada_Mean(NAD27)", "NAD27 Canada" },
{ "Canal_Zone_(NAD27)", "NAD27 Canal Zone" },
{ "Carribean NAD27", "NAD27 Caribbean" },
{ "Cent America NAD27", "NAD27 Central" },
{ "Cuba NAD27", "NAD27 Cuba" },
{ "Geodetic Datum 49", "Geodetic Datum '49" },
{ "Greenland NAD27", "NAD27 Greenland" },
{ "Mexico NAD27", "NAD27 Mexico" },
{ "North America 83", "NAD83" },
{ "OSGB36", "Ord Srvy Grt Britn" },
};
struct garmin_color_t {
QString name;
int32_t rgb;
};
static const QVector<garmin_color_t> gt_colors = {
{ "Unknown", unknown_color },
{ "Black", 0x000000 },
{ "DarkRed", 0x00008B },
{ "DarkGreen", 0x006400 },
{ "DarkYellow", 0x008B8B },
{ "DarkBlue", 0x8B0000 },
{ "DarkMagenta", 0x8B008B },
{ "DarkCyan", 0x8B8B00 },
{ "LightGray", 0xD3D3D3 },
{ "DarkGray", 0xA9A9A9 },
{ "Red", 0x0000FF },
{ "Green", 0x008000 },
{ "Yellow", 0x00FFFF },
{ "Blue", 0xFF0000 },
{ "Magenta", 0xFF00FF },
{ "Cyan", 0xFFFF00 },
{ "White", 0xFFFFFF },
{ "Transparent", unknown_color }, /* Currently not handled */
};
unsigned char
gt_switch_display_mode_value(const unsigned char display_mode, const int protoid, const char device)
{
if (device) {
switch (protoid) {
case 103:
case 107:
case 108:
case 109:
case 110:
return display_mode & 3;
break;
case 104:
switch (display_mode) {
case 0:
case 1:
return gt_display_mode_symbol;
case 3:
return gt_display_mode_symbol_and_name;
case 5:
return gt_display_mode_symbol_and_comment;
}
case 155:
switch (display_mode) {
case 1:
return gt_display_mode_symbol;
case 3:
return gt_display_mode_symbol_and_name;
case 5:
return gt_display_mode_symbol_and_comment;
}
}
return gt_display_mode_symbol_and_name;
} else {
switch (protoid) {
case 103:
case 107:
case 108:
case 109:
case 110:
return display_mode & 3;
case 104:
case 155:
switch (display_mode) {
case gt_display_mode_symbol:
return 1;
case gt_display_mode_symbol_and_name:
return 3;
case gt_display_mode_symbol_and_comment:
return 5;
}
}
return 0;
}
}
QString
gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format)
{
if ((garmin_format == GDB) && (icon >= 500) && (icon <= 563)) {
return QStringLiteral("Custom %1").arg(icon - 500);
}
if ((garmin_format == PCX) && (icon >= 7680) && (icon <= 8191)) {
return QStringLiteral("Custom %1").arg(icon - 7680);
}
for (const auto& icon_mapping : garmin_icon_table) {
switch (garmin_format) {
case MAPSOURCE:
case GDB:
if (icon == icon_mapping.mpssymnum) {
return icon_mapping.icon;
}
break;
case PCX:
case GARMIN_SERIAL:
if (icon == icon_mapping.pcxsymnum) {
return icon_mapping.icon;
}
break;
default:
gbFatal("unknown garmin format.\n");
}
}
return DEFAULT_ICON_DESCR;
}
int gt_find_icon_number_from_desc(const QString& desc, garmin_formats_e garmin_format)
{
static int find_flag = 0;
int def_icon = DEFAULT_ICON_VALUE;
if (desc.isNull()) {
return def_icon;
}
/*
* If we were given a numeric icon number as a description
* (i.e. 8255), just return that.
*/
int n = desc.toInt();
if (n) {
return n;
}
if (desc.startsWith("Custom ", Qt::CaseInsensitive)) {
int base = 0;
if (garmin_format == GDB) {
base = 500;
}
if (garmin_format == PCX) {
base = 7680;
}
if (base) {
n = desc.mid(7).toInt();
return n + base;
}
}
if (global_opts.smart_icons) {
for (const auto& icon_mapping : garmin_smart_icon_table) {
if (desc.compare(icon_mapping.icon, Qt::CaseInsensitive) == 0) {
switch (garmin_format) {
case MAPSOURCE:
case GDB:
return icon_mapping.mpssymnum;
case PCX:
case GARMIN_SERIAL:
return icon_mapping.pcxsymnum;
default:
gbFatal("unknown garmin format.\n");
}
}
}
}
for (const auto& icon_mapping : garmin_icon_table) {
if (desc.compare(icon_mapping.icon, Qt::CaseInsensitive) == 0) {
switch (garmin_format) {
case MAPSOURCE:
case GDB:
return icon_mapping.mpssymnum;
case PCX:
case GARMIN_SERIAL:
return icon_mapping.pcxsymnum;
default:
gbFatal("unknown garmin format.\n");
}
}
}
/*
* try to handle some complex icon names: i.e. "Blue Diamond" and "Diamond, Blue"
* "find_flag" prevents us from a possible endless loop
*/
if (find_flag == 0) {
static const QStringList prefixes = {
"White ", "Red ", "Green ", "Blue ", "Black ",
};
// Rewrite "Green Square" to "Square, Green".
for (const auto& prefix : prefixes) {
if (desc.startsWith(prefix, Qt::CaseInsensitive)) {
QString buff = desc;
buff.replace(prefix, "");
buff.append(", ");
buff.append(prefix);
buff = buff.trimmed();
find_flag = 1;
int result = gt_find_icon_number_from_desc(buff, garmin_format);
find_flag = 0;
return result;
}
}
}
return def_icon;
}
const char*
gt_get_icao_country(const QString& cc)
{
const gt_country_code_t* x = >_country_codes[0];
if (cc.isEmpty()) {
return nullptr;
}
do {
const char* ccx = x->cc;
const QString qccx = x->cc;
while (ccx != nullptr) {
if (qccx.left(2) == cc) {
return x->country;
}
if ((ccx[0] == cc[0]) && (ccx[1] == '*')) {
return x->country;
}
ccx = strchr(ccx, ',');
if (ccx == nullptr) {
break;
}
ccx++;
}
x++;
} while (x->cc != nullptr);
return nullptr;
}
const char*
gt_get_icao_cc(const QString& country, const QString& shortname)
{
static char res[3];
const gt_country_code_t* x = >_country_codes[0];
if (country.isEmpty()) {
if (shortname == nullptr) {
return nullptr;
}
switch (shortname.length()) {
case 3:
strncpy(res, CSTR(shortname), 1);
break;
case 4:
strncpy(res, CSTR(shortname), 2);
break;
default:
return nullptr;
}
const char* test = gt_get_icao_country(res);
if (test != nullptr) {
return res;
} else {
return nullptr;
}
}
do {
if (country.compare(x->country, Qt::CaseInsensitive) != 0) {
x++;
continue;
}
if (strlen(x->cc) <= 3) {
strncpy(res, x->cc, 3);
if (res[1] == '*') {
res[1] = '\0';
} else {
res[2] = '\0';
}
return res;
}
if (shortname.length() == 4) {
const char* ccx = x->cc;
strncpy(res, CSTR(shortname), 2);
res[2] = '\0';
while (ccx != nullptr) {
if (strncmp(ccx, res, 2) == 0) {
return res;
}
if ((ccx[0] == res[0]) && (ccx[1] == '*')) {
return res;
}
ccx = strchr(ccx, ',');
if (ccx == nullptr) {
break;
}
ccx++;
}
}
return nullptr;
} while (x->country != nullptr);
return nullptr;
}
grid_type
gt_lookup_grid_type(const QString& grid_name)
{
for (const auto& grid_mapping : gt_mps_grid_names) {
if (QString::compare(grid_name, grid_mapping.shortname, Qt::CaseInsensitive) == 0 ||
QString::compare(grid_name, grid_mapping.longname,Qt::CaseInsensitive) == 0) {
return grid_mapping.grid;
}
}
gbFatal(FatalMsg().nospace().noquote() <<
"Unsupported grid (" << grid_name <<
"). See GPSBabel help for supported grids.");
return grid_unknown; /* (warnings) */
}
QString
gt_get_mps_grid_longname(const grid_type grid)
{
if ((grid < GRID_INDEX_MIN) || (grid > GRID_INDEX_MAX)) {
gbFatal(FatalMsg().nospace().noquote() <<
"Grid index out of range " << grid <<
" (" << GRID_INDEX_MIN << ".." << GRID_INDEX_MAX << ")!");
}
return gt_mps_grid_names[grid].longname;
}
QString
gt_get_mps_datum_name(const int datum_index)
{
QString result = GPS_Math_Get_Datum_Name(datum_index);
for (const auto& datum_mapping : gt_mps_datum_names) {
if (QString::compare(result, datum_mapping.jeeps_name, Qt::CaseInsensitive) == 0) {
return datum_mapping.mps_name;
}
}
return result;
}
int
gt_lookup_datum_index(const QString& datum_str)
{
QString name = datum_str;
for (const auto& datum_mapping : gt_mps_datum_names) {
if (QString::compare(name, datum_mapping.mps_name, Qt::CaseInsensitive) == 0) {
name = datum_mapping.jeeps_name;
break;
}
}
int result = GPS_Lookup_Datum_Index(name);
// Didn't get a hit? Try again after modifying the lookup.
if (result < 0) {
QString tmp = datum_str + " mean";
result = GPS_Lookup_Datum_Index(tmp);
}
if (result < 0) {
gbFatal(FatalMsg().nospace().noquote() <<
"Unsupported datum (" << datum_str <<
"). See GPSBabel help for supported datums.");
}
return result;
}
uint32_t
gt_color_value(const unsigned int garmin_index)
{
if ((garmin_index < gt_colors.size())) {
return gt_colors[garmin_index].rgb;
} else {
return unknown_color; /* -1 */
}
}
uint32_t
gt_color_value_by_name(const QString& name)
{
for (const auto& gt_color : gt_colors) {
if (QString::compare(gt_color.name, name, Qt::CaseInsensitive) == 0) {
return gt_color.rgb;
}
}
return gt_colors[0].rgb;
}
int
gt_color_index_by_name(const QString& name)
{
for (int i = 0; i < gt_colors.size(); ++i) {
if (QString::compare(gt_colors[i].name, name, Qt::CaseInsensitive) == 0) {
return i;
}
}
return 0; /* unknown */
}
int
gt_color_index_by_rgb(const int rgb)
{
for (int i = 0; i < gt_colors.size(); ++i) {
if (rgb == gt_colors[i].rgb) {
return i;
}
}
return 0; /* unknown */
}
QString
gt_color_name(const unsigned int garmin_index)
{
if ((garmin_index < gt_colors.size())) {
return gt_colors[garmin_index].name;
} else {
return gt_colors[0].name;
}
}