/
options.cpp
8852 lines (7231 loc) · 311 KB
/
options.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: Options Dialog
* 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. *
**************************************************************************/
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/progdlg.h>
#include <wx/sound.h>
#include <wx/radiobox.h>
#include <wx/listbox.h>
#include <wx/imaglist.h>
#include <wx/display.h>
#include <wx/choice.h>
#include <wx/dirdlg.h>
#include <wx/clrpicker.h>
#include <wx/stdpaths.h>
#include "wx/tokenzr.h"
#include "wx/dir.h"
#if wxCHECK_VERSION(2, 9, \
4) /* does this work in 2.8 too.. do we need a test? */
#include <wx/renderer.h>
#endif
#if defined(__WXGTK__) || defined(__WXQT__)
#include <wx/colordlg.h>
#endif
#include "dychart.h"
#include "chart1.h"
#ifdef ocpnUSE_GL
#include "glChartCanvas.h"
extern GLuint g_raster_format;
#endif
#include "chartdbs.h"
#include "options.h"
#include "styles.h"
#include "datastream.h"
#include "multiplexer.h"
#include "FontMgr.h"
#include "OCPN_Sound.h"
#include "NMEALogWindow.h"
#include "wx28compat.h"
#include "routeman.h"
#include "ais.h"
#include "AIS_Decoder.h"
#include "AIS_Target_Data.h"
#include "navutil.h"
#ifdef USE_S57
#include "s52plib.h"
#include "s52utils.h"
#include "cm93.h"
#endif
#ifdef __OCPN__ANDROID__
#include "androidUTIL.h"
#endif
#ifdef __WXOSX__
#include "DarkMode.h"
#endif
#include "OCPNPlatform.h"
#if !defined(__WXOSX__) || wxCHECK_VERSION(3, 1, 0)
#define SLIDER_STYLE wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS
#else
#define SLIDER_STYLE wxSL_HORIZONTAL | wxSL_AUTOTICKS
#endif
wxString GetOCPNKnownLanguage(const wxString lang_canonical,
wxString& lang_dir);
wxString GetOCPNKnownLanguage(const wxString lang_canonical);
extern OCPNPlatform* g_Platform;
extern MyFrame* gFrame;
extern WayPointman *pWayPointMan;
extern ChartCanvas* cc1;
extern wxString g_PrivateDataDir;
extern bool g_bSoftwareGL;
extern bool g_bShowFPS;
extern bool g_bShowOutlines;
extern bool g_bShowChartBar;
extern bool g_bShowDepthUnits;
extern bool g_bskew_comp;
extern bool g_bopengl;
extern bool g_bsmoothpanzoom;
extern bool g_bShowTrue, g_bShowMag;
extern double g_UserVar;
extern double gVar;
extern int g_chart_zoom_modifier;
extern int g_chart_zoom_modifier_vector;
extern int g_NMEAAPBPrecision;
extern wxString g_TalkerIdText;
extern int g_nDepthUnitDisplay;
extern wxString* pInit_Chart_Dir;
extern wxArrayOfConnPrm* g_pConnectionParams;
extern Multiplexer* g_pMUX;
extern bool g_bfilter_cogsog;
extern int g_COGFilterSec;
extern int g_SOGFilterSec;
extern PlugInManager* g_pi_manager;
extern ocpnStyle::StyleManager* g_StyleManager;
extern bool g_bDisplayGrid;
// LIVE ETA OPTION
extern bool g_bShowLiveETA;
extern double g_defaultBoatSpeed;
extern double g_defaultBoatSpeedUserUnit;
// AIS Global configuration
extern bool g_bCPAMax;
extern double g_CPAMax_NM;
extern bool g_bCPAWarn;
extern double g_CPAWarn_NM;
extern bool g_bTCPA_Max;
extern double g_TCPA_Max;
extern bool g_bMarkLost;
extern double g_MarkLost_Mins;
extern bool g_bRemoveLost;
extern double g_RemoveLost_Mins;
extern bool g_bShowCOG;
extern double g_ShowCOG_Mins;
extern bool g_bAISShowTracks;
extern double g_AISShowTracks_Mins;
extern double g_ShowMoored_Kts;
extern bool g_bHideMoored;
extern bool g_bAllowShowScaled;
extern int g_ShowScaled_Num;
extern bool g_bAIS_CPA_Alert;
extern bool g_bAIS_CPA_Alert_Audio;
extern wxString g_sAIS_Alert_Sound_File;
extern bool g_bAIS_CPA_Alert_Suppress_Moored;
extern bool g_bShowAreaNotices;
extern bool g_bDrawAISSize;
extern bool g_bShowAISName;
extern int g_Show_Target_Name_Scale;
extern bool g_bWplIsAprsPosition;
extern int g_iNavAidRadarRingsNumberVisible;
extern float g_fNavAidRadarRingsStep;
extern int g_pNavAidRadarRingsStepUnits;
extern int g_iWaypointRangeRingsNumber;
extern float g_fWaypointRangeRingsStep;
extern int g_iWaypointRangeRingsStepUnits;
extern wxColour g_colourWaypointRangeRingsColour;
extern bool g_bWayPointPreventDragging;
extern wxColour g_colourOwnshipRangeRingsColour;
extern bool g_own_ship_sog_cog_calc;
extern int g_own_ship_sog_cog_calc_damp_sec;
extern bool g_bPreserveScaleOnX;
extern bool g_bPlayShipsBells;
extern int g_iSoundDeviceIndex;
extern bool g_bFullscreenToolbar;
extern bool g_bTransparentToolbar;
extern bool g_bTransparentToolbarInOpenGLOK;
extern int g_OwnShipIconType;
extern double g_n_ownship_length_meters;
extern double g_n_ownship_beam_meters;
extern double g_n_gps_antenna_offset_y;
extern double g_n_gps_antenna_offset_x;
extern int g_n_ownship_min_mm;
extern double g_n_arrival_circle_radius;
extern bool g_bEnableZoomToCursor;
extern bool g_bTrackDaily;
extern int g_track_rotate_time;
extern int g_track_rotate_time_type;
extern bool g_bHighliteTracks;
extern double g_TrackIntervalSeconds;
extern double g_TrackDeltaDistance;
extern double g_TrackDeltaDistance;
extern int g_nTrackPrecision;
extern wxColour g_colourTrackLineColour;
extern int g_iSDMMFormat;
extern int g_iDistanceFormat;
extern int g_iSpeedFormat;
extern bool g_bAdvanceRouteWaypointOnArrivalOnly;
extern int g_cm93_zoom_factor;
extern int g_COGAvgSec;
extern bool g_bCourseUp;
extern bool g_bLookAhead;
extern double g_ownship_predictor_minutes;
extern double g_ownship_HDTpredictor_miles;
extern bool g_bAISRolloverShowClass;
extern bool g_bAISRolloverShowCOG;
extern bool g_bAISRolloverShowCPA;
extern bool g_bAIS_ACK_Timeout;
extern double g_AckTimeout_Mins;
extern bool g_bQuiltEnable;
extern bool g_bFullScreenQuilt;
extern bool g_bConfirmObjectDelete;
extern wxString g_GPS_Ident;
extern bool g_bGarminHostUpload;
#if wxUSE_XLOCALE || !wxCHECK_VERSION(3, 0, 0)
extern wxLocale* plocale_def_lang;
#endif
extern OCPN_Sound g_anchorwatch_sound;
extern bool g_bMagneticAPB;
extern bool g_fog_overzoom;
extern double g_overzoom_emphasis_base;
extern bool g_oz_vector_scale;
extern bool g_bShowStatusBar;
#ifdef USE_S57
extern s52plib* ps52plib;
#endif
extern wxString g_locale;
extern bool g_bportable;
extern bool g_bdisable_opengl;
extern wxString* pHome_Locn;
extern ChartGroupArray* g_pGroupArray;
extern ocpnStyle::StyleManager* g_StyleManager;
#ifdef ocpnUSE_GL
extern ocpnGLOptions g_GLOptions;
#endif
extern bool g_bGLexpert;
// Some constants
#define ID_CHOICE_NMEA wxID_HIGHEST + 1
extern wxArrayString* EnumerateSerialPorts(void); // in chart1.cpp
extern wxArrayString TideCurrentDataSet;
extern wxString g_TCData_Dir;
extern AIS_Decoder* g_pAIS;
extern bool g_bserial_access_checked;
options* g_pOptions;
extern bool g_btouch;
extern bool g_bresponsive;
extern bool g_bAutoHideToolbar;
extern int g_nAutoHideToolbar;
extern int g_GUIScaleFactor;
extern int g_ChartScaleFactor;
extern float g_ChartScaleFactorExp;
extern int g_ShipScaleFactor;
extern float g_ShipScaleFactorExp;
extern double g_config_display_size_mm;
extern bool g_config_display_size_manual;
extern bool g_bInlandEcdis;
extern bool g_bDarkDecorations;
extern bool g_bSpaceDropMark;
extern "C" bool CheckSerialAccess(void);
// sort callback for Connections list Sort by priority.
#if wxCHECK_VERSION(2, 9, 0)
int wxCALLBACK SortConnectionOnPriority(long item1, long item2, wxIntPtr list)
#else
int wxCALLBACK SortConnectionOnPriority(long item1, long item2, long list)
#endif
{
wxListCtrl* lc = reinterpret_cast<wxListCtrl*>(list);
wxListItem it1, it2;
it1.SetId(lc->FindItem(-1, item1));
it1.SetColumn(3);
it1.SetMask(it1.GetMask() | wxLIST_MASK_TEXT);
it2.SetId(lc->FindItem(-1, item2));
it2.SetColumn(3);
it2.SetMask(it2.GetMask() | wxLIST_MASK_TEXT);
lc->GetItem(it1);
lc->GetItem(it2);
#ifdef __WXOSX__
return it1.GetText().CmpNoCase(it2.GetText());
#else
return it2.GetText().CmpNoCase(it1.GetText());
#endif
}
WX_DECLARE_LIST(wxCheckBox, CBList);
class OCPNCheckedListCtrl : public wxScrolledWindow {
public:
OCPNCheckedListCtrl() {}
OCPNCheckedListCtrl(wxWindow* parent, wxWindowID id = -1,
const wxPoint& pt = wxDefaultPosition,
const wxSize& sz = wxDefaultSize,
long style = wxHSCROLL | wxVSCROLL,
const wxString& name = _T("scrolledWindow")) {
Create(parent, id, pt, sz, style, name);
}
bool Create(wxWindow* parent, wxWindowID id = -1,
const wxPoint& pt = wxDefaultPosition,
const wxSize& sz = wxDefaultSize,
long style = wxHSCROLL | wxVSCROLL,
const wxString& name = _T("scrolledWindow"));
virtual ~OCPNCheckedListCtrl() {}
unsigned int Append(wxString& label, bool benable = true);
unsigned int GetCount() { return m_list.GetCount(); }
void Clear();
void Check(int index, bool val);
bool IsChecked(int index);
private:
wxBoxSizer* m_sizer;
CBList m_list;
};
#include <wx/listimpl.cpp>
WX_DEFINE_LIST(CBList);
bool OCPNCheckedListCtrl::Create(wxWindow* parent, wxWindowID id,
const wxPoint& pt, const wxSize& sz,
long style, const wxString& name) {
if (!wxScrolledWindow::Create(parent, id, pt, sz, style, name)) return FALSE;
#ifdef __OCPN__ANDROID__
GetHandle()->setObjectName("OCPNCheckedListCtrl");
GetHandle()->setStyleSheet(getQtStyleSheet());
#endif
SetScrollRate(0, 2);
m_sizer = new wxBoxSizer(wxVERTICAL);
SetSizer(m_sizer);
return TRUE;
}
unsigned int OCPNCheckedListCtrl::Append(wxString& label, bool benable) {
wxCheckBox* cb = new wxCheckBox(this, wxID_ANY, label);
cb->Enable(benable);
cb->SetValue(!benable);
m_sizer->Add(cb);
m_sizer->Layout();
m_list.Append(cb);
return m_list.GetCount() - 1;
}
void OCPNCheckedListCtrl::Check(int index, bool val) {
CBList::Node* node = m_list.Item(index);
wxCheckBox* cb = node->GetData();
if (cb) cb->SetValue(val);
}
bool OCPNCheckedListCtrl::IsChecked(int index) {
CBList::Node* node = m_list.Item(index);
wxCheckBox* cb = node->GetData();
if (cb)
return cb->GetValue();
else
return false;
}
void OCPNCheckedListCtrl::Clear() {
for(unsigned int i=0 ; i < m_list.GetCount() ; i++){
wxCheckBox* cb = m_list[i];
delete cb;
}
m_list.Clear();
Scroll(0,0);
}
extern ArrayOfMMSIProperties g_MMSI_Props_Array;
///////////////////////////////////////////////////////////////////////////////
/// Class MMSIEditDialog
///////////////////////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE(MMSIEditDialog, wxDialog)
EVT_BUTTON(ID_MMSIEDIT_CANCEL, MMSIEditDialog::OnMMSIEditCancelClick)
EVT_BUTTON(ID_MMSIEDIT_OK, MMSIEditDialog::OnMMSIEditOKClick)
END_EVENT_TABLE()
MMSIEditDialog::MMSIEditDialog(MMSIProperties* props, wxWindow* parent,
wxWindowID id, const wxString& caption,
const wxPoint& pos, const wxSize& size,
long style)
: wxDialog(parent, id, caption, pos, size,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
m_props(props) {
CreateControls();
GetSizer()->SetSizeHints(this);
Centre();
}
MMSIEditDialog::~MMSIEditDialog(void) { delete m_MMSICtl; }
void MMSIEditDialog::CreateControls(void) {
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
SetSizer(mainSizer);
wxStaticBox* mmsiBox =
new wxStaticBox(this, wxID_ANY, _("MMSI Extended Properties"));
wxStaticBoxSizer* mmsiSizer = new wxStaticBoxSizer(mmsiBox, wxVERTICAL);
mainSizer->Add(mmsiSizer, 0, wxEXPAND | wxALL, 5);
mmsiSizer->Add(new wxStaticText(this, wxID_STATIC, _("MMSI")), 0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
m_MMSICtl = new wxTextCtrl(this, ID_MMSI_CTL, wxEmptyString,
wxDefaultPosition, wxSize(180, -1), 0);
mmsiSizer->Add(m_MMSICtl, 0,
wxALIGN_LEFT | wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5);
wxStaticBoxSizer* trackSizer = new wxStaticBoxSizer(
new wxStaticBox(this, wxID_ANY, _("Tracking")), wxVERTICAL);
wxGridSizer* gridSizer = new wxGridSizer(0, 3, 0, 0);
m_rbTypeTrackDefault =
new wxRadioButton(this, wxID_ANY, _("Default tracking"),
wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
m_rbTypeTrackDefault->SetValue(TRUE);
gridSizer->Add(m_rbTypeTrackDefault, 0, wxALL, 5);
m_rbTypeTrackAlways = new wxRadioButton(this, wxID_ANY, _("Always track"));
gridSizer->Add(m_rbTypeTrackAlways, 0, wxALL, 5);
m_rbTypeTrackNever = new wxRadioButton(this, wxID_ANY, _(" Never track"));
gridSizer->Add(m_rbTypeTrackNever, 0, wxALL, 5);
m_cbTrackPersist = new wxCheckBox(this, wxID_ANY, _("Persistent"));
gridSizer->Add(m_cbTrackPersist, 0, wxALL, 5);
trackSizer->Add(gridSizer, 0, wxEXPAND, 0);
mmsiSizer->Add(trackSizer, 0, wxEXPAND, 0);
m_IgnoreButton = new wxCheckBox(this, wxID_ANY, _("Ignore this MMSI"));
mmsiSizer->Add(m_IgnoreButton, 0, wxEXPAND, 5);
m_MOBButton = new wxCheckBox(this, wxID_ANY,
_("Handle this MMSI as SART/PLB(AIS) MOB."));
mmsiSizer->Add(m_MOBButton, 0, wxEXPAND, 5);
m_VDMButton = new wxCheckBox(this, wxID_ANY, _("Convert AIVDM to AIVDO for this MMSI"));
mmsiSizer->Add(m_VDMButton, 0, wxEXPAND, 5);
m_FollowerButton = new wxCheckBox(this, wxID_ANY, _("This MMSI is my Follower - No CPA Alert"));
mmsiSizer->Add(m_FollowerButton, 0, wxEXPAND, 5);
wxBoxSizer* btnSizer = new wxBoxSizer(wxHORIZONTAL);
mainSizer->Add(btnSizer, 0, wxALIGN_RIGHT | wxALL, 5);
m_CancelButton = new wxButton(this, ID_MMSIEDIT_CANCEL, _("Cancel"));
btnSizer->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
m_OKButton = new wxButton(this, ID_MMSIEDIT_OK, _("OK"));
btnSizer->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
m_OKButton->SetDefault();
// Set initial values...
wxString sMMSI;
if (m_props->MMSI > 0)
sMMSI.Printf(_T("%d"), m_props->MMSI);
else
sMMSI = _T("");
m_MMSICtl->AppendText(sMMSI);
switch (m_props->TrackType) {
case TRACKTYPE_ALWAYS:
m_rbTypeTrackAlways->SetValue(TRUE);
break;
case TRACKTYPE_NEVER:
m_rbTypeTrackNever->SetValue(TRUE);
break;
default:
break;
}
m_cbTrackPersist->SetValue(m_props->m_bPersistentTrack);
m_IgnoreButton->SetValue(m_props->m_bignore);
m_MOBButton->SetValue(m_props->m_bMOB);
m_VDMButton->SetValue(m_props->m_bVDM);
m_FollowerButton->SetValue(m_props->m_bFollower);
SetColorScheme(GLOBAL_COLOR_SCHEME_RGB);
}
void MMSIEditDialog::SetColorScheme(ColorScheme cs) { DimeControl(this); }
void MMSIEditDialog::OnMMSIEditCancelClick(wxCommandEvent& event) {
EndModal(wxID_CANCEL);
}
void MMSIEditDialog::OnMMSIEditOKClick(wxCommandEvent& event) {
// Update the MMSIProperties by the passed pointer
if (m_props) {
long nmmsi;
m_MMSICtl->GetValue().ToLong(&nmmsi);
m_props->MMSI = nmmsi;
if (m_MMSICtl->GetValue().Length() != 9)
{
if (wxID_CANCEL == OCPNMessageBox(this,
_("An MMSI Id is generally a number of nine digits.\nPlease check your entries and cancel if necessary."),
_("OpenCPN Info"),
wxOK | wxCANCEL))
{
return;
}
}
if (m_rbTypeTrackDefault->GetValue())
m_props->TrackType = TRACKTYPE_DEFAULT;
else if (m_rbTypeTrackAlways->GetValue())
m_props->TrackType = TRACKTYPE_ALWAYS;
else
m_props->TrackType = TRACKTYPE_NEVER;
m_props->m_bignore = m_IgnoreButton->GetValue();
m_props->m_bMOB = m_MOBButton->GetValue();
m_props->m_bVDM = m_VDMButton->GetValue();
m_props->m_bFollower = m_FollowerButton->GetValue();
m_props->m_bPersistentTrack = m_cbTrackPersist->GetValue();
if (m_props->m_ShipName == wxEmptyString) {
AIS_Target_Data *proptarget = g_pAIS->Get_Target_Data_From_MMSI(nmmsi);
if (proptarget) {
wxString s = proptarget->GetFullName();
m_props->m_ShipName = s;
}
else {
wxString GetShipNameFromFile(int);
m_props->m_ShipName = GetShipNameFromFile(nmmsi);
}
}
}
EndModal(wxID_OK);
}
void MMSIEditDialog::OnCtlUpdated(wxCommandEvent& event) {}
BEGIN_EVENT_TABLE(MMSIListCtrl, wxListCtrl)
EVT_LIST_ITEM_SELECTED(ID_MMSI_PROPS_LIST, MMSIListCtrl::OnListItemClick)
EVT_LIST_ITEM_ACTIVATED(ID_MMSI_PROPS_LIST, MMSIListCtrl::OnListItemActivated)
EVT_LIST_ITEM_RIGHT_CLICK(ID_MMSI_PROPS_LIST,
MMSIListCtrl::OnListItemRightClick)
EVT_MENU(ID_DEF_MENU_MMSI_EDIT, MMSIListCtrl::PopupMenuHandler)
EVT_MENU(ID_DEF_MENU_MMSI_DELETE, MMSIListCtrl::PopupMenuHandler)
END_EVENT_TABLE()
MMSIListCtrl::MMSIListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style)
: wxListCtrl(parent, id, pos, size, style) {
m_parent = parent;
}
MMSIListCtrl::~MMSIListCtrl(void) {}
wxString MMSIListCtrl::OnGetItemText(long item, long column) const {
wxString ret;
MMSIProperties* props = g_MMSI_Props_Array[item];
if (!props) return ret;
switch (column) {
case mlMMSI:
if (props->MMSI > 0) ret = wxString::Format(_T( "%d" ), props->MMSI);
break;
case mlTrackMode:
switch (props->TrackType) {
case TRACKTYPE_DEFAULT:
ret = _("Default");
break;
case TRACKTYPE_ALWAYS:
ret = _("Always");
break;
case TRACKTYPE_NEVER:
ret = _("Never");
break;
default:
ret = _T( "???" );
}
if (props->m_bPersistentTrack)
ret.Append(_T( ", " )).Append(_("Persistent"));
break;
case mlIgnore:
if (props->m_bignore) ret = _T( "X" );
break;
case mlMOB:
if (props->m_bMOB) ret = _T( "X" );
break;
case mlVDM:
if (props->m_bVDM) ret = _T( "X" );
break;
case mlFollower:
if (props->m_bFollower) ret = _T("X");
break;
case mlShipName:
ret = props->m_ShipName;
break;
default:
ret = _T( "??" );
break;
}
return ret;
}
void MMSIListCtrl::OnListItemClick(wxListEvent& event) {}
void MMSIListCtrl::OnListItemActivated(wxListEvent& event) {
MMSIProperties* props = g_MMSI_Props_Array.Item(event.GetIndex());
MMSIProperties* props_new = new MMSIProperties(*props);
MMSIEditDialog* pd =
new MMSIEditDialog(props_new, m_parent, -1, _("Edit MMSI Properties"),
wxDefaultPosition, wxSize(200, 200));
if (pd->ShowModal() == wxID_OK) {
g_MMSI_Props_Array.RemoveAt(event.GetIndex());
delete props;
g_MMSI_Props_Array.Insert(props_new, event.GetIndex());
}
else
delete props_new;
pd->Destroy();
}
void MMSIListCtrl::OnListItemRightClick(wxListEvent& event) {
m_context_item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (m_context_item == wxNOT_FOUND) return;
wxMenu* menu = new wxMenu(_("MMSI Properties"));
wxMenuItem* item_edit =
new wxMenuItem(menu, ID_DEF_MENU_MMSI_EDIT, _("Edit") + _T("..."));
menu->Append(item_edit);
wxMenuItem* item_delete =
new wxMenuItem(menu, ID_DEF_MENU_MMSI_DELETE, _("Delete"));
menu->Append(item_delete);
#ifdef __WXMSW__
wxFont* qFont = GetOCPNScaledFont(_("Menu"));
item_edit->SetFont(*qFont);
item_delete->SetFont(*qFont);
#endif
wxPoint p = ScreenToClient(wxGetMousePosition());
PopupMenu(menu, p.x, p.y);
SetItemCount(g_MMSI_Props_Array.GetCount());
Refresh(TRUE);
}
void MMSIListCtrl::PopupMenuHandler(wxCommandEvent& event) {
int context_item = m_context_item;
MMSIProperties* props = g_MMSI_Props_Array[context_item];
if (!props)
return;
switch (event.GetId()) {
case ID_DEF_MENU_MMSI_EDIT: {
MMSIProperties* props_new = new MMSIProperties(*props);
MMSIEditDialog* pd = new MMSIEditDialog(props_new, m_parent, -1, _("Edit MMSI Properties"),
wxDefaultPosition, wxSize(200, 200));
if (pd->ShowModal() == wxID_OK) {
g_MMSI_Props_Array.RemoveAt(context_item);
delete props;
g_MMSI_Props_Array.Insert(props_new, context_item);
}
else {
delete props_new;
}
pd->Destroy();
break;
}
case ID_DEF_MENU_MMSI_DELETE:
g_MMSI_Props_Array.RemoveAt(context_item);
delete props;
break;
}
}
MMSI_Props_Panel::MMSI_Props_Panel(wxWindow* parent)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxBORDER_NONE) {
m_pparent = parent;
wxFont* qFont = GetOCPNScaledFont(_("Dialog"));
SetFont(*qFont);
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
SetSizer(topSizer);
wxString MMSI_props_column_spec = _T("120;120;100;100;100;100;100;100");
// Parse the global column width string as read from config file
wxStringTokenizer tkz(MMSI_props_column_spec, _T(";"));
wxString s_width = tkz.GetNextToken();
int width;
long lwidth;
m_pListCtrlMMSI = new MMSIListCtrl(
this, ID_MMSI_PROPS_LIST, wxDefaultPosition, wxSize(-1, -1),
wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_HRULES | wxLC_VRULES |
wxBORDER_SUNKEN | wxLC_VIRTUAL);
//wxImageList* imglist = new wxImageList(16, 16, TRUE, 2);
ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle();
//imglist->Add(style->GetIcon(_T( "sort_asc" )));
//imglist->Add(style->GetIcon(_T( "sort_desc" )));
// m_pListCtrlMMSI->AssignImageList( imglist, wxIMAGE_LIST_SMALL );
int dx = GetCharWidth();
width = dx * 5;
if (s_width.ToLong(&lwidth)) {
width = wxMax(dx * 2, lwidth);
width = wxMin(width, dx * 13);
}
m_pListCtrlMMSI->InsertColumn(tlMMSI, _("MMSI"), wxLIST_FORMAT_LEFT, width);
s_width = tkz.GetNextToken();
width = dx * 12;
if (s_width.ToLong(&lwidth)) {
width = wxMax(dx * 2, lwidth);
width = wxMin(width, dx * 25);
}
m_pListCtrlMMSI->InsertColumn(tlCLASS, _("Track Mode"), wxLIST_FORMAT_CENTER, width);
s_width = tkz.GetNextToken();
width = dx * 8;
if (s_width.ToLong(&lwidth)) {
width = wxMax(dx * 2, lwidth);
width = wxMin(width, dx * 10);
}
m_pListCtrlMMSI->InsertColumn(tlTYPE, _("Ignore"), wxLIST_FORMAT_CENTER,
width);
s_width = tkz.GetNextToken();
width = dx * 8;
if (s_width.ToLong(&lwidth)) {
width = wxMax(dx * 2, lwidth);
width = wxMin(width, dx * 10);
}
m_pListCtrlMMSI->InsertColumn(tlTYPE, _("MOB"), wxLIST_FORMAT_CENTER, width);
s_width = tkz.GetNextToken();
width = dx * 8;
if (s_width.ToLong(&lwidth)) {
width = wxMax(dx * 2, lwidth);
width = wxMin(width, dx * 15);
}
m_pListCtrlMMSI->InsertColumn(tlTYPE, _("VDM->VDO"), wxLIST_FORMAT_CENTER, width);
s_width = tkz.GetNextToken();
width = dx * 8;
if (s_width.ToLong(&lwidth)) {
width = wxMax(dx * 2, lwidth);
width = wxMin(width, dx * 30);
}
m_pListCtrlMMSI->InsertColumn(tlTYPE, _("Ship name"), wxLIST_FORMAT_CENTER, width);
s_width = tkz.GetNextToken();
width = dx * 8;
if (s_width.ToLong(&lwidth)) {
width = wxMax(dx * 2, lwidth);
width = wxMin(width, dx * 10);
}
m_pListCtrlMMSI->InsertColumn(tlTYPE, _("Follower"), wxLIST_FORMAT_CENTER, width); //Has
topSizer->Add(m_pListCtrlMMSI, 1, wxEXPAND | wxALL, 0);
m_pButtonNew = new wxButton(this, wxID_ANY, _("New..."), wxDefaultPosition,
wxSize(200, -1));
m_pButtonNew->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(MMSI_Props_Panel::OnNewButton),
NULL, this);
topSizer->Add(m_pButtonNew, 0, wxALIGN_RIGHT | wxALL, 0);
topSizer->Layout();
// This is silly, but seems to be required for __WXMSW__ build
// If not done, the SECOND invocation of the panel fails to expand the list
// to the full wxSizer size....
SetSize(GetSize().x, GetSize().y - 1);
SetColorScheme(GLOBAL_COLOR_SCHEME_RGB);
}
MMSI_Props_Panel::~MMSI_Props_Panel(void) {}
void MMSI_Props_Panel::OnNewButton(wxCommandEvent& event) {
MMSIProperties* props = new MMSIProperties(-1);
MMSIEditDialog* pd =
new MMSIEditDialog(props, m_parent, -1, _("Add MMSI Properties"),
wxDefaultPosition, wxSize(200, 200));
if (pd->ShowModal() == wxID_OK)
g_MMSI_Props_Array.Add(props);
else
delete props;
pd->Destroy();
UpdateMMSIList();
}
void MMSI_Props_Panel::UpdateMMSIList(void) {
// Capture the MMSI of the curently selected list item
long selItemID = wxNOT_FOUND;
m_pListCtrlMMSI->GetNextItem(selItemID, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
int selMMSI = wxNOT_FOUND;
if (selItemID != wxNOT_FOUND)
selMMSI = g_MMSI_Props_Array[selItemID]->MMSI;
m_pListCtrlMMSI->SetItemCount(g_MMSI_Props_Array.GetCount());
// Restore selected item
long item_sel = wxNOT_FOUND;
if (selItemID != wxNOT_FOUND && selMMSI != wxNOT_FOUND) {
for (unsigned int i = 0; i < g_MMSI_Props_Array.GetCount(); i++) {
if (g_MMSI_Props_Array[i]->MMSI == selMMSI) {
item_sel = i;
break;
}
}
}
if (g_MMSI_Props_Array.GetCount() > 0)
m_pListCtrlMMSI->SetItemState(item_sel,
wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
#ifdef __WXMSW__
m_pListCtrlMMSI->Refresh(FALSE);
#endif
}
void MMSI_Props_Panel::SetColorScheme(ColorScheme cs) { DimeControl(this); }
BEGIN_EVENT_TABLE(options, wxDialog)
EVT_CHECKBOX(ID_DEBUGCHECKBOX1, options::OnDebugcheckbox1Click)
EVT_BUTTON(ID_BUTTONADD, options::OnButtonaddClick)
EVT_BUTTON(ID_BUTTONDELETE, options::OnButtondeleteClick)
EVT_BUTTON(ID_PARSEENCBUTTON, options::OnButtonParseENC)
EVT_BUTTON(ID_BUTTONCOMPRESS, options::OnButtoncompressClick)
EVT_BUTTON(ID_TCDATAADD, options::OnInsertTideDataLocation)
EVT_BUTTON(ID_TCDATADEL, options::OnRemoveTideDataLocation)
EVT_BUTTON(ID_APPLY, options::OnApplyClick)
EVT_BUTTON(xID_OK, options::OnXidOkClick)
EVT_BUTTON(wxID_CANCEL, options::OnCancelClick)
EVT_BUTTON(ID_BUTTONFONTCHOOSE, options::OnChooseFont)
EVT_CHOICE(ID_CHOICE_FONTELEMENT, options::OnFontChoice)
EVT_CLOSE(options::OnClose)
#if defined(__WXGTK__) || defined(__WXQT__)
EVT_BUTTON(ID_BUTTONFONTCOLOR, options::OnChooseFontColor)
#endif
#ifdef ocpnUSE_GL
EVT_BUTTON(ID_OPENGLOPTIONS, options::OnOpenGLOptions)
#endif
EVT_CHOICE(ID_RADARDISTUNIT, options::OnDisplayCategoryRadioButton)
EVT_CHOICE(ID_DEPTHUNITSCHOICE, options::OnUnitsChoice)
EVT_BUTTON(ID_CLEARLIST, options::OnButtonClearClick)
EVT_BUTTON(ID_SELECTLIST, options::OnButtonSelectClick)
EVT_BUTTON(ID_SETSTDLIST, options::OnButtonSetStd)
EVT_BUTTON(ID_AISALERTSELECTSOUND, options::OnButtonSelectSound)
EVT_BUTTON(ID_AISALERTTESTSOUND, options::OnButtonTestSound)
EVT_CHECKBOX(ID_SHOWGPSWINDOW, options::OnShowGpsWindowCheckboxClick)
EVT_CHOICE(ID_SHIPICONTYPE, options::OnShipTypeSelect)
EVT_CHOICE(ID_RADARRINGS, options::OnRadarringSelect)
EVT_CHOICE(ID_OPWAYPOINTRANGERINGS, options::OnWaypointRangeRingSelect)
EVT_CHAR_HOOK(options::OnCharHook)
EVT_TIMER(ID_BT_SCANTIMER, options::onBTScanTimer)
END_EVENT_TABLE()
options::options(MyFrame* parent, wxWindowID id, const wxString& caption,
const wxPoint& pos, const wxSize& size, long style) {
Init();
pParent = parent;
long wstyle = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER;
SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
wxDialog::Create(parent, id, caption, pos, size, wstyle);
SetFont(*dialogFont);
CreateControls();
RecalculateSize();
Center();
}
options::~options(void) {
wxNotebook* nb = dynamic_cast<wxNotebook*>(m_pListbook->GetPage(m_pageCharts));
if (nb)
nb->Disconnect(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
wxListbookEventHandler(options::OnChartsPageChange),
NULL, this);
groupsPanel->EmptyChartGroupArray(m_pGroupArray);
delete m_pSerialArray;
delete m_pGroupArray;
delete m_topImgList;
}
// with AIS it's called very often
#if wxCHECK_VERSION(3,0,0)
bool options::SendIdleEvents(wxIdleEvent &event ) {
if (IsShown())
return wxDialog::SendIdleEvents(event);
return false;
}
#endif
void options::RecalculateSize(void) {
if (!g_bresponsive) {
wxSize canvas_size = cc1->GetSize();
wxSize fitted_size = GetSize();
fitted_size.x = wxMin(fitted_size.x, canvas_size.x);
fitted_size.y = wxMin(fitted_size.y, canvas_size.y);
SetSize(fitted_size);
Fit();
m_nCharWidthMax = GetSize().x / GetCharWidth();
return;
}
wxSize esize;
esize.x = GetCharWidth() * 110;
esize.y = GetCharHeight() * 40;
wxSize dsize = GetParent()->GetSize(); // GetClientSize();
esize.y = wxMin(esize.y, dsize.y - 0 /*(2 * GetCharHeight())*/);
esize.x = wxMin(esize.x, dsize.x - 0 /*(2 * GetCharHeight())*/);
SetSize(esize);
wxSize fsize = GetSize();
wxSize canvas_size = GetParent()->GetSize();