/
chart1.cpp
12606 lines (10087 loc) · 398 KB
/
chart1.cpp
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
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
*
* Project: OpenCPN
* Purpose: OpenCPN Main wxWidgets Program
* Author: David Register
*
***************************************************************************
* Copyright (C) 2010 by David S. Register *
* *
* 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 <memory>
#ifdef __MINGW32__
#undef IPV6STRICT // mingw FTBS fix: missing struct ip_mreq
#include <windows.h>
#endif
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif //precompiled headers
#ifdef __WXMSW__
//#include "c:\\Program Files\\visual leak detector\\include\\vld.h"
#endif
#include <wx/settings.h>
#include <wx/print.h>
#include <wx/printdlg.h>
#include <wx/artprov.h>
#include <wx/stdpaths.h>
#include <wx/intl.h>
#include <wx/listctrl.h>
#include <wx/aui/aui.h>
#include <wx/dialog.h>
#include <wx/progdlg.h>
#include <wx/clrpicker.h>
#include <wx/tokenzr.h>
#include <wx/dir.h>
#include <wx/dialog.h>
#include "dychart.h"
#include <limits.h>
#include <algorithm>
#ifdef __WXMSW__
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <psapi.h>
#endif
#ifndef __WXMSW__
#include <signal.h>
#include <setjmp.h>
#endif
#ifdef OCPN_HAVE_X11
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#endif
#include "config.h"
#include "chart1.h"
#include "chcanv.h"
#include "chartdb.h"
#include "logger.h"
#include "navutil.h"
#include "styles.h"
#include "routeman.h"
#include "piano.h"
#include "concanv.h"
#include "options.h"
#include "AboutFrameImpl.h"
#include "about.h"
#include "safe_mode.h"
#include "thumbwin.h"
#include "tcmgr.h"
#include "ais.h"
#include "chartimg.h" // for ChartBaseBSB
#include "MarkInfo.h"
#include "RoutePropDlgImpl.h"
#include "toolbar.h"
#include "compass.h"
#include "datastream.h"
#ifdef __WXMSW__
#include "GarminProtocolHandler.h" // Used for port probing on Windows
#endif
#include "OCPN_DataStreamEvent.h"
#include "OCPN_SignalKEvent.h"
#include "multiplexer.h"
#include "routeprintout.h"
#include "Select.h"
#include "FontMgr.h"
#include "NMEALogWindow.h"
#include "Layer.h"
#include "NavObjectCollection.h"
#include "AISTargetListDialog.h"
#include "AISTargetAlertDialog.h"
#include "AIS_Decoder.h"
#include "OCP_DataStreamInput_Thread.h"
#include "TrackPropDlg.h"
#include "gshhs.h"
#include "cutil.h"
#include "routemanagerdialog.h"
#include "pluginmanager.h"
#include "AIS_Target_Data.h"
#include "OCPNPlatform.h"
#include "AISTargetQueryDialog.h"
#include "S57QueryDialog.h"
#include "glTexCache.h"
#include "Track.h"
#include "iENCToolbar.h"
#include "Quilt.h"
#include "Route.h"
#include "OCPN_AUIManager.h"
#include "CanvasConfig.h"
#include "ConfigMgr.h"
#include "MUIBar.h"
#include "OCPN_Sound.h"
#include "SoundFactory.h"
#include "PluginHandler.h"
#include "SignalKEventHandler.h"
#ifdef ocpnUSE_GL
#include "glChartCanvas.h"
#endif
#include <wx/image.h>
#include "wx/apptrait.h"
#ifdef __WXOSX__
#include "macutils.h"
#endif
#include "cm93.h"
#include "s52plib.h"
#include "s57chart.h"
#include "gdal/cpl_csv.h"
#include "s52utils.h"
#ifdef __WXMSW__
//#define __MSVC__LEAK
#ifdef __MSVC__LEAK
#include "Stackwalker.h"
#endif
#endif
#include <wx/jsonreader.h>
#ifdef __OCPN__ANDROID__
#include "androidUTIL.h"
#endif
#ifdef LINUX_CRASHRPT
#include "crashprint.h"
#endif
#ifdef __WXOSX__
#include "DarkMode.h"
#endif
#ifdef OCPN_USE_NEWSERIAL
#include "serial/serial.h"
#endif
#include <wx/arrimpl.cpp>
WX_DEFINE_OBJARRAY( ArrayOfCDI );
#ifdef __WXMSW__
void RedirectIOToConsole();
#endif
#include "wx/ipc.h"
//------------------------------------------------------------------------------
// Fwd Declarations
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Static variable definition
//------------------------------------------------------------------------------
OCPNPlatform *g_Platform;
wxString g_vs;
bool g_bFirstRun;
bool g_bUpgradeInProcess;
bool g_bPauseTest;
wxString g_compatOS;
wxString g_compatOsVersion;
int g_unit_test_1;
int g_unit_test_2;
bool g_start_fullscreen;
bool g_rebuild_gl_cache;
bool g_parse_all_enc;
// Files specified on the command line, if any.
wxVector<wxString> g_params;
MyFrame *gFrame;
ConsoleCanvas *console;
MyConfig *pConfig;
ChartBase *Current_Vector_Ch;
ChartDB *ChartData;
wxString *pdir_list[20];
int g_restore_stackindex;
int g_restore_dbindex;
double g_ChartNotRenderScaleFactor;
int g_nDepthUnitDisplay;
RouteList *pRouteList;
TrackList *pTrackList;
LayerList *pLayerList;
bool g_bIsNewLayer;
int g_LayerIdx;
bool g_bLayerViz;
Select *pSelect;
Select *pSelectTC;
Select *pSelectAIS;
Routeman *g_pRouteMan;
WayPointman *pWayPointMan;
MarkInfoDlg *g_pMarkInfoDialog;
RoutePropDlgImpl *pRoutePropDialog;
TrackPropDlg *pTrackPropDialog;
RouteManagerDialog *pRouteManagerDialog;
GoToPositionDialog *pGoToPositionDialog;
double gLat, gLon, gCog, gSog, gHdt, gHdm, gVar;
wxString gRmcDate, gRmcTime;
double vLat, vLon;
double initial_scale_ppm, initial_rotation;
int g_nbrightness = 100;
bool bDBUpdateInProgress;
ThumbWin *pthumbwin;
TCMgr *ptcmgr;
bool g_bshowToolbar = true;
bool g_bexpert = true;
bool g_bBasicMenus = false;;
bool bDrawCurrentValues;
wxString ChartListFileName;
wxString AISTargetNameFileName;
wxString gWorldMapLocation, gDefaultWorldMapLocation;
wxString *pInit_Chart_Dir;
wxString g_winPluginDir; // Base plugin directory on Windows.
wxString g_csv_locn;
wxString g_SENCPrefix;
wxString g_UserPresLibData;
wxString g_VisibleLayers;
wxString g_InvisibleLayers;
wxString g_VisiNameinLayers;
wxString g_InVisiNameinLayers;
bool g_bcompression_wait;
bool g_FlushNavobjChanges;
int g_FlushNavobjChangesTimeout;
wxString g_uploadConnection;
int user_user_id;
int file_user_id;
int quitflag;
int g_tick = 0;
int g_mem_total, g_mem_used, g_mem_initial;
bool s_bSetSystemTime;
wxString *phost_name;
static unsigned int malloc_max;
wxArrayOfConnPrm *g_pConnectionParams;
wxDateTime g_start_time;
wxDateTime g_loglast_time;
static OcpnSound* _bells_sounds[] = {SoundFactory(), SoundFactory()};
std::vector<OcpnSound*> bells_sound(_bells_sounds, _bells_sounds + 2 );
OcpnSound* g_anchorwatch_sound = SoundFactory();
RoutePoint *pAnchorWatchPoint1;
RoutePoint *pAnchorWatchPoint2;
double AnchorPointMinDist;
bool AnchorAlertOn1, AnchorAlertOn2;
bool g_bCruising;
ChartDummy *pDummyChart;
ocpnStyle::StyleManager* g_StyleManager;
// Global print data, to remember settings during the session
wxPrintData *g_printData = (wxPrintData*) NULL ;
// Global page setup data
wxPageSetupData* g_pageSetupData = (wxPageSetupData*) NULL;
bool g_bShowOutlines;
bool g_bShowDepthUnits;
bool g_bDisplayGrid; // Flag indicating weather the lat/lon grid should be displayed
bool g_bShowChartBar;
bool g_bShowActiveRouteHighway;
int g_nNMEADebug;
int g_nAWDefault;
int g_nAWMax;
bool g_bPlayShipsBells;
bool g_bFullscreenToolbar;
bool g_bShowLayers;
bool g_bTransparentToolbar;
bool g_bTransparentToolbarInOpenGLOK;
int g_nAutoHideToolbar;
bool g_bAutoHideToolbar;
bool g_bPermanentMOBIcon;
bool g_bTempShowMenuBar;
int g_iSDMMFormat;
int g_iDistanceFormat;
int g_iSpeedFormat;
int g_iNavAidRadarRingsNumberVisible;
float g_fNavAidRadarRingsStep;
int g_pNavAidRadarRingsStepUnits;
int g_iWaypointRangeRingsNumber;
float g_fWaypointRangeRingsStep;
int g_iWaypointRangeRingsStepUnits;
wxColour g_colourWaypointRangeRingsColour;
bool g_bWayPointPreventDragging;
bool g_bConfirmObjectDelete;
wxColour g_colourOwnshipRangeRingsColour;
int g_iWpt_ScaMin;
bool g_bUseWptScaMin;
bool g_bShowWptName;
// Set default color scheme
ColorScheme global_color_scheme = GLOBAL_COLOR_SCHEME_DAY;
static int Usercolortable_index;
static wxArrayPtrVoid *UserColorTableArray;
static wxArrayPtrVoid *UserColourHashTableArray;
static wxColorHashMap *pcurrent_user_color_hash;
int gps_watchdog_timeout_ticks;
int sat_watchdog_timeout_ticks;
int gGPS_Watchdog;
bool bGPSValid;
int gHDx_Watchdog;
int gHDT_Watchdog;
int gVAR_Watchdog;
bool g_bHDT_Rx;
bool g_bVAR_Rx;
int gSAT_Watchdog;
int g_SatsInView;
bool g_bSatValid;
bool g_bDebugCM93;
bool g_bDebugS57;
bool g_bfilter_cogsog;
int g_COGFilterSec = 1;
int g_SOGFilterSec;
int g_ChartUpdatePeriod;
int g_SkewCompUpdatePeriod;
int g_lastClientRectx;
int g_lastClientRecty;
int g_lastClientRectw;
int g_lastClientRecth;
double g_display_size_mm;
double g_config_display_size_mm;
bool g_config_display_size_manual;
float g_selection_radius_mm = 2.0;
float g_selection_radius_touch_mm = 10.0;
int g_GUIScaleFactor;
int g_ChartScaleFactor;
float g_ChartScaleFactorExp;
int g_last_ChartScaleFactor;
int g_ShipScaleFactor;
float g_ShipScaleFactorExp;
int g_ENCSoundingScaleFactor;
bool g_bShowTide;
bool g_bShowCurrent;
s52plib *ps52plib;
S57ClassRegistrar *g_poRegistrar;
s57RegistrarMgr *m_pRegistrarMan;
CM93OffsetDialog *g_pCM93OffsetDialog;
#ifdef __WXOSX__
#include "macutils.h"
#endif
// begin rms
#ifdef __WXOSX__
#ifdef __WXMSW__
#ifdef USE_GLU_TESS
#ifdef USE_GLU_DLL
// end rms
extern bool s_glu_dll_ready;
extern HINSTANCE s_hGLU_DLL; // Handle to DLL
#endif
#endif
#endif
#endif
double g_ownship_predictor_minutes;
double g_ownship_HDTpredictor_miles;
bool g_own_ship_sog_cog_calc;
int g_own_ship_sog_cog_calc_damp_sec;
wxDateTime last_own_ship_sog_cog_calc_ts;
double last_own_ship_sog_cog_calc_lat, last_own_ship_sog_cog_calc_lon;
Multiplexer *g_pMUX;
AIS_Decoder *g_pAIS;
bool g_bAIS_CPA_Alert;
bool g_bAIS_CPA_Alert_Audio;
AISTargetAlertDialog *g_pais_alert_dialog_active;
AISTargetQueryDialog *g_pais_query_dialog_active;
int g_iSoundDeviceIndex;
int g_ais_alert_dialog_x, g_ais_alert_dialog_y;
int g_ais_alert_dialog_sx, g_ais_alert_dialog_sy;
int g_ais_query_dialog_x, g_ais_query_dialog_y;
int g_S57_dialog_sx, g_S57_dialog_sy;
int g_nframewin_x;
int g_nframewin_y;
int g_nframewin_posx;
int g_nframewin_posy;
bool g_bframemax;
bool g_bAutoAnchorMark;
wxRect g_blink_rect;
double g_PlanSpeed;
wxDateTime g_StartTime;
int g_StartTimeTZ;
IDX_entry *gpIDX;
int gpIDXn;
long gStart_LMT_Offset;
wxArrayString *pMessageOnceArray;
FILE *s_fpdebug;
bool bAutoOpen;
bool g_bUseGLL = true;
int g_nCacheLimit;
int g_memCacheLimit;
bool g_bGDAL_Debug;
double g_VPRotate; // Viewport rotation angle, used on "Course Up" mode
bool g_bCourseUp;
int g_COGAvgSec = 15; // COG average period (sec.) for Course Up Mode
double g_COGAvg;
bool g_bLookAhead;
bool g_bskew_comp;
bool g_bopengl;
bool g_bSoftwareGL;
bool g_bShowFPS;
bool g_bsmoothpanzoom;
bool g_fog_overzoom;
double g_overzoom_emphasis_base;
bool g_oz_vector_scale;
double g_plus_minus_zoom_factor;
int g_nCOMPortCheck = 32;
bool g_b_legacy_input_filter_behaviour; // Support original input filter process or new process
bool g_bbigred;
PlugInManager *g_pi_manager;
bool g_bAISRolloverShowClass;
bool g_bAISRolloverShowCOG;
bool g_bAISRolloverShowCPA;
bool g_bDebugGPSD;
bool g_bFullScreenQuilt = true;
bool g_bQuiltEnable;
bool g_bQuiltStart;
bool g_bportable;
bool g_bdisable_opengl;
ChartGroupArray *g_pGroupArray;
wxString g_GPS_Ident;
S57QueryDialog *g_pObjectQueryDialog;
wxArrayString TideCurrentDataSet;
wxString g_TCData_Dir;
bool g_boptionsactive;
options *g_options;
bool g_bDeferredInitDone;
int options_lastPage = 0;
int options_subpage = 0;
wxPoint options_lastWindowPos( 0,0 );
wxSize options_lastWindowSize( 0,0 );
bool g_bSleep;
bool g_bsimplifiedScalebar;
int g_grad_default;
wxColour g_border_color_default;
int g_border_size_default;
int g_sash_size_default;
wxColour g_caption_color_default;
wxColour g_sash_color_default;
wxColour g_background_color_default;
int osMajor, osMinor;
bool GetMemoryStatus(int *mem_total, int *mem_used);
#ifdef __WXMSW__
// System color control support
typedef DWORD (WINAPI *SetSysColors_t)(DWORD, DWORD *, DWORD *);
typedef DWORD (WINAPI *GetSysColor_t)(DWORD);
SetSysColors_t pSetSysColors;
GetSysColor_t pGetSysColor;
void SaveSystemColors(void);
void RestoreSystemColors(void);
DWORD color_3dface;
DWORD color_3dhilite;
DWORD color_3dshadow;
DWORD color_3ddkshadow;
DWORD color_3dlight;
DWORD color_activecaption;
DWORD color_gradientactivecaption;
DWORD color_captiontext;
DWORD color_windowframe;
DWORD color_inactiveborder;
#endif
// AIS Global configuration
bool g_bShowAIS;
bool g_bCPAMax;
double g_CPAMax_NM;
bool g_bCPAWarn;
double g_CPAWarn_NM;
bool g_bTCPA_Max;
double g_TCPA_Max;
bool g_bMarkLost;
double g_MarkLost_Mins;
bool g_bRemoveLost;
double g_RemoveLost_Mins;
bool g_bShowCOG;
double g_ShowCOG_Mins;
bool g_bAISShowTracks;
double g_AISShowTracks_Mins;
double g_AISShowTracks_Limit;
bool g_bHideMoored;
bool g_bAllowShowScaled;
double g_ShowMoored_Kts;
wxString g_sAIS_Alert_Sound_File;
bool g_bAIS_CPA_Alert_Suppress_Moored;
bool g_bAIS_ACK_Timeout;
double g_AckTimeout_Mins;
bool g_bShowScaled;
bool g_bShowAreaNotices;
bool g_bDrawAISSize;
bool g_bDrawAISRealtime;
double g_AIS_RealtPred_Kts;
bool g_bShowAISName;
int g_Show_Target_Name_Scale;
bool g_bWplIsAprsPosition;
int g_nAIS_activity_timer;
DummyTextCtrl *g_pDummyTextCtrl;
bool g_bEnableZoomToCursor;
bool g_bTrackActive;
bool g_bTrackCarryOver;
bool g_bDeferredStartTrack;
bool g_bTrackDaily;
int g_track_rotate_time;
int g_track_rotate_time_type;
bool g_bHighliteTracks;
int g_route_line_width;
int g_track_line_width;
wxColour g_colourTrackLineColour;
wxString g_default_wp_icon;
wxString g_default_routepoint_icon;
ActiveTrack *g_pActiveTrack;
double g_TrackIntervalSeconds;
double g_TrackDeltaDistance;
int g_nTrackPrecision;
int g_total_NMEAerror_messages;
int g_cm93_zoom_factor;
PopUpDSlide *pPopupDetailSlider;
bool g_bShowDetailSlider;
int g_detailslider_dialog_x, g_detailslider_dialog_y;
bool g_bUseGreenShip;
wxString g_AW1GUID;
wxString g_AW2GUID;
bool g_b_overzoom_x = true; // Allow high overzoom
int g_OwnShipIconType;
double g_n_ownship_length_meters;
double g_n_ownship_beam_meters;
double g_n_gps_antenna_offset_y;
double g_n_gps_antenna_offset_x;
int g_n_ownship_min_mm;
double g_n_arrival_circle_radius;
bool g_bNeedDBUpdate;
bool g_bPreserveScaleOnX;
AboutFrameImpl *g_pAboutDlg;
about *g_pAboutDlgLegacy;
#if wxUSE_XLOCALE || !wxCHECK_VERSION(3,0,0)
wxLocale *plocale_def_lang;
#endif
wxString g_locale;
wxString g_localeOverride;
bool g_b_assume_azerty;
bool g_bUseRaster;
bool g_bUseVector;
bool g_bUseCM93;
int g_click_stop;
int g_MemFootSec;
int g_MemFootMB;
wxStaticBitmap *g_pStatBoxTool;
bool g_bShowStatusBar;
bool g_bquiting;
int g_BSBImgDebug;
AISTargetListDialog *g_pAISTargetList;
wxString g_AisTargetList_perspective;
int g_AisTargetList_range;
int g_AisTargetList_sortColumn;
bool g_bAisTargetList_sortReverse;
wxString g_AisTargetList_column_spec;
wxString g_AisTargetList_column_order;
int g_AisTargetList_count;
bool g_bAisTargetList_autosort;
bool g_bGarminHostUpload;
bool g_bFullscreen;
OCPN_AUIManager *g_pauimgr;
wxAuiDefaultDockArt *g_pauidockart;
wxString g_toolbarConfig = _T("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
wxString g_toolbarConfigSecondary = _T("....XX..X........XXXXXXXXXXXX");
ocpnFloatingToolbarDialog *g_MainToolbar;
int g_maintoolbar_x;
int g_maintoolbar_y;
long g_maintoolbar_orient;
float g_toolbar_scalefactor;
float g_compass_scalefactor;
bool g_bShowMenuBar;
bool g_bShowCompassWin;
bool g_benable_rotate;
bool g_bShowTrue = true;
bool g_bShowMag;
double g_UserVar;
bool g_bMagneticAPB;
bool g_bInlandEcdis;
bool g_bDarkDecorations;
// OpenGL Globals
int g_GPU_MemSize;
bool g_bserial_access_checked;
wxString g_uiStyle;
// Values returned from WMM_PI for variation computation request
// Initialize to invalid value so we don't use if if WMM hasn't updated yet
double gQueryVar = 361.0;
char bells_sound_file_name[2][12] = { "1bells.wav", "2bells.wav" };
int portaudio_initialized;
static char nmea_tick_chars[] = { '|', '/', '-', '\\', '|', '/', '-', '\\' };
static int tick_idx;
int g_sticky_chart;
int g_sticky_projection;
bool g_benableUDPNullHeader;
extern options *g_pOptions;
int n_NavMessageShown;
wxString g_config_version_string;
wxString g_CmdSoundString;
bool g_btouch;
bool g_bresponsive;
bool g_bRollover;
bool b_inCompressAllCharts;
bool g_bGLexpert;
bool g_bUIexpert;
int g_chart_zoom_modifier;
int g_chart_zoom_modifier_vector;
int g_NMEAAPBPrecision;
wxString g_TalkerIdText;
int g_maxWPNameLength;
bool g_bAdvanceRouteWaypointOnArrivalOnly;
bool g_bSpaceDropMark;
wxArrayString g_locale_catalog_array;
bool b_reloadForPlugins;
bool g_btrackContinuous;
unsigned int g_canvasConfig;
bool g_useMUI;
bool g_bmasterToolbarFull = true;
int g_AndroidVersionCode;
int g_memUsed;
SENCThreadManager *g_SencThreadManager;
WX_DEFINE_ARRAY_PTR(ChartCanvas*, arrayofCanvasPtr);
arrayofCanvasPtr g_canvasArray;
arrayofCanvasConfigPtr g_canvasConfigArray;
wxString g_lastAppliedTemplateGUID;
ChartCanvas *g_focusCanvas;
ChartCanvas *g_overlayCanvas;
bool b_inCloseWindow;
#ifdef LINUX_CRASHRPT
wxCrashPrint g_crashprint;
#endif
#ifndef __WXMSW__
sigjmp_buf env; // the context saved by sigsetjmp();
#endif
// {2C9C45C2-8E7D-4C08-A12D-816BBAE722C0}
#ifdef __WXMSW__
DEFINE_GUID( GARMIN_DETECT_GUID, 0x2c9c45c2L, 0x8e7d, 0x4c08, 0xa1, 0x2d, 0x81, 0x6b, 0xba, 0xe7,
0x22, 0xc0 );
#endif
#ifdef __MSVC__
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__ )
#define new DEBUG_NEW
#endif
#if !defined(NAN)
static const long long lNaN = 0xfff8000000000000;
#define NAN (*(double*)&lNaN)
#endif
// Some static helpers
void appendOSDirSlash( wxString* pString );
static void InitializeUserColors( void );
static void DeInitializeUserColors( void );
static void SetSystemColors( ColorScheme cs );
extern "C" bool CheckSerialAccess( void );
#if 0
// Refresh the Piano Bar
static void refresh_Piano()
{
// int idx = pCurrentStack->GetCurrentEntrydbIndex();
// if (idx < 0)
// return;
//
// std::vector<int> piano_active_chart_index_array;
// piano_active_chart_index_array.push_back( pCurrentStack->GetCurrentEntrydbIndex() );
// g_Piano->SetActiveKeyArray( piano_active_chart_index_array );
}
#endif
#ifndef __OCPN__ANDROID__
// Connection class, for use by both communicating instances
class stConnection : public wxConnection
{
public:
stConnection() {}
~stConnection() {}
bool OnExec(const wxString& topic, const wxString& data);
};
// Opens a file passed from another instance
bool stConnection::OnExec(const wxString& topic, const wxString& data)
{
// not setup yet
if (!gFrame)
return false;
wxString path(data);
if (path.IsEmpty()) {
gFrame->InvalidateAllGL();
gFrame->RefreshAllCanvas( false );
gFrame->Raise();
}
else {
NavObjectCollection1 *pSet = new NavObjectCollection1;
pSet->load_file(path.fn_str());
int wpt_dups;
pSet->LoadAllGPXObjects( !pSet->IsOpenCPN(), wpt_dups, true ); // Import with full vizibility of names and objects
if( pRouteManagerDialog && pRouteManagerDialog->IsShown() )
pRouteManagerDialog->UpdateLists();
LLBBox box = pSet->GetBBox();
if (box.GetValid()) {
gFrame->CenterView(gFrame->GetPrimaryCanvas(), box);
}
delete pSet;
return true;
}
return true;
}
// Server class, for listening to connection requests
class stServer: public wxServer
{
public:
wxConnectionBase *OnAcceptConnection(const wxString& topic);
};
// Accepts a connection from another instance
wxConnectionBase *stServer::OnAcceptConnection(const wxString& topic)
{
if (topic.Lower() == wxT("opencpn"))
{
// Check that there are no modal dialogs active
wxWindowList::Node* node = wxTopLevelWindows.GetFirst();
while (node) {
wxDialog* dialog = wxDynamicCast(node->GetData(), wxDialog);
if (dialog && dialog->IsModal()) {
return 0;
}
node = node->GetNext();
}
return new stConnection();
}
return 0;
}
// Client class, to be used by subsequent instances in OnInit
class stClient: public wxClient
{
public:
stClient() {};
wxConnectionBase *OnMakeConnection() { return new stConnection; }
};
#endif
//------------------------------------------------------------------------------
// PNG Icon resources
//------------------------------------------------------------------------------
#if defined(__WXGTK__) || defined(__WXQT__)
#include "bitmaps/opencpn.xpm"
#endif
//------------------------------------------------------------------------------
// Local constants
//------------------------------------------------------------------------------
// enum {
// ID_PIANO_DISABLE_QUILT_CHART = 32000, ID_PIANO_ENABLE_QUILT_CHART
// };
//------------------------------------------------------------------------------
// Fwd Refs
//------------------------------------------------------------------------------
iENCToolbar *g_iENCToolbar;
int g_iENCToolbarPosX;
int g_iENCToolbarPosY;
void BuildiENCToolbar( bool bnew )
{
if(g_bInlandEcdis){
if(bnew){
if(g_iENCToolbar){
wxPoint locn = g_iENCToolbar->GetPosition();
wxPoint tbp_incanvas = gFrame->GetPrimaryCanvas()->ScreenToClient( locn );
g_iENCToolbarPosY = tbp_incanvas.y;
g_iENCToolbarPosX = tbp_incanvas.x;
delete g_iENCToolbar;
g_iENCToolbar = 0;
}
}
if( !g_iENCToolbar ) {
wxPoint posn(g_iENCToolbarPosX, g_iENCToolbarPosY);
// Overlapping main toolbar?
if(g_MainToolbar){
if((g_iENCToolbarPosY > g_maintoolbar_y) && (g_iENCToolbarPosY < g_maintoolbar_y + g_MainToolbar->GetSize().y) )
g_iENCToolbarPosY = -1; // force a reposition
}
if((g_iENCToolbarPosX < 0) || (g_iENCToolbarPosY < 0)){
posn.x = 0;
posn.y = 100;
if(g_MainToolbar)
posn = wxPoint(g_maintoolbar_x + g_MainToolbar->GetSize().x + 4, g_maintoolbar_y );