forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainV2.cs
3917 lines (3375 loc) · 152 KB
/
MainV2.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Collections;
using System.Runtime.InteropServices;
using System.Globalization;
using System.Linq;
using System.Threading;
using MissionPlanner.Utilities;
using IronPython.Hosting;
using log4net;
using MissionPlanner.Controls;
using MissionPlanner.Comms;
using MissionPlanner.Log;
using Transitions;
using MissionPlanner.Warnings;
using System.Collections.Concurrent;
using MissionPlanner.GCSViews.ConfigurationView;
using WebCamService;
using System.Net.Sockets;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace MissionPlanner
{
public partial class MainV2 : Form
{
private static readonly ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static class NativeMethods
{
// used to hide/show console window
[DllImport("user32.dll")]
public static extern int FindWindow(string szClass, string szTitle);
[DllImport("user32.dll")]
public static extern int ShowWindow(int Handle, int showState);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern IntPtr RegisterDeviceNotification
(IntPtr hRecipient,
IntPtr NotificationFilter,
Int32 Flags);
// Import SetThreadExecutionState Win32 API and necessary flags
[DllImport("kernel32.dll")]
public static extern uint SetThreadExecutionState(uint esFlags);
public const uint ES_CONTINUOUS = 0x80000000;
public const uint ES_SYSTEM_REQUIRED = 0x00000001;
static public int SW_SHOWNORMAL = 1;
static public int SW_HIDE = 0;
}
public static menuicons displayicons = new burntkermitmenuicons();
public abstract class menuicons
{
public abstract Image fd { get; }
public abstract Image fp { get; }
public abstract Image initsetup { get; }
public abstract Image config_tuning { get; }
public abstract Image sim { get; }
public abstract Image terminal { get; }
public abstract Image help { get; }
public abstract Image donate { get; }
public abstract Image connect { get; }
public abstract Image disconnect { get; }
public abstract Image bg { get; }
public abstract Image wizard { get; }
}
public class burntkermitmenuicons : menuicons
{
public override Image fd
{
get { return global::MissionPlanner.Properties.Resources.light_flightdata_icon; }
}
public override Image fp
{
get { return global::MissionPlanner.Properties.Resources.light_flightplan_icon; }
}
public override Image initsetup
{
get { return global::MissionPlanner.Properties.Resources.light_initialsetup_icon; }
}
public override Image config_tuning
{
get { return global::MissionPlanner.Properties.Resources.light_tuningconfig_icon; }
}
public override Image sim
{
get { return global::MissionPlanner.Properties.Resources.light_simulation_icon; }
}
public override Image terminal
{
get { return global::MissionPlanner.Properties.Resources.light_terminal_icon; }
}
public override Image help
{
get { return global::MissionPlanner.Properties.Resources.light_help_icon; }
}
public override Image donate
{
get { return global::MissionPlanner.Properties.Resources.donate; }
}
public override Image connect
{
get { return global::MissionPlanner.Properties.Resources.light_connect_icon; }
}
public override Image disconnect
{
get { return global::MissionPlanner.Properties.Resources.light_disconnect_icon; }
}
public override Image bg
{
get { return global::MissionPlanner.Properties.Resources.bgdark; }
}
public override Image wizard
{
get { return global::MissionPlanner.Properties.Resources.wizardicon; }
}
}
public class highcontrastmenuicons : menuicons
{
public override Image fd
{
get { return global::MissionPlanner.Properties.Resources.dark_flightdata_icon; }
}
public override Image fp
{
get { return global::MissionPlanner.Properties.Resources.dark_flightplan_icon; }
}
public override Image initsetup
{
get { return global::MissionPlanner.Properties.Resources.dark_initialsetup_icon; }
}
public override Image config_tuning
{
get { return global::MissionPlanner.Properties.Resources.dark_tuningconfig_icon; }
}
public override Image sim
{
get { return global::MissionPlanner.Properties.Resources.dark_simulation_icon; }
}
public override Image terminal
{
get { return global::MissionPlanner.Properties.Resources.dark_terminal_icon; }
}
public override Image help
{
get { return global::MissionPlanner.Properties.Resources.dark_help_icon; }
}
public override Image donate
{
get { return global::MissionPlanner.Properties.Resources.donate; }
}
public override Image connect
{
get { return global::MissionPlanner.Properties.Resources.dark_connect_icon; }
}
public override Image disconnect
{
get { return global::MissionPlanner.Properties.Resources.dark_disconnect_icon; }
}
public override Image bg
{
get { return null; }
}
public override Image wizard
{
get { return global::MissionPlanner.Properties.Resources.wizardicon; }
}
}
Controls.MainSwitcher MyView;
private static DisplayView _displayConfiguration = new DisplayView().Advanced();
public static event EventHandler LayoutChanged;
public static DisplayView DisplayConfiguration
{
get { return _displayConfiguration; }
set
{
_displayConfiguration = value;
Settings.Instance["displayview"] = _displayConfiguration.ConvertToString();
if (LayoutChanged != null)
LayoutChanged(null, EventArgs.Empty);
}
}
public static bool ShowAirports { get; set; }
public static bool ShowTFR { get; set; }
private Utilities.adsb _adsb;
public bool EnableADSB
{
get { return _adsb != null; }
set
{
if (value == true)
{
_adsb = new Utilities.adsb();
if (Settings.Instance["adsbserver"] != null)
Utilities.adsb.server = Settings.Instance["adsbserver"];
if (Settings.Instance["adsbport"] != null)
Utilities.adsb.serverport = int.Parse(Settings.Instance["adsbport"].ToString());
}
else
{
Utilities.adsb.Stop();
_adsb = null;
}
}
}
//public static event EventHandler LayoutChanged;
/// <summary>
/// Active Comport interface
/// </summary>
public static MAVLinkInterface comPort
{
get
{
return _comPort;
}
set {
if (_comPort == value)
return;
_comPort = value;
_comPort.MavChanged -= instance.comPort_MavChanged;
_comPort.MavChanged += instance.comPort_MavChanged;
instance.comPort_MavChanged(null, null);
}
}
static MAVLinkInterface _comPort = new MAVLinkInterface();
/// <summary>
/// passive comports
/// </summary>
public static List<MAVLinkInterface> Comports = new List<MAVLinkInterface>();
public delegate void WMDeviceChangeEventHandler(WM_DEVICECHANGE_enum cause);
public event WMDeviceChangeEventHandler DeviceChanged;
/// <summary>
/// other planes in the area from adsb
/// </summary>
public object adsblock = new object();
public ConcurrentDictionary<string,adsb.PointLatLngAltHdg> adsbPlanes = new ConcurrentDictionary<string, adsb.PointLatLngAltHdg>();
string titlebar;
/// <summary>
/// Comport name
/// </summary>
public static string comPortName = "";
public static int comPortBaud = 115200;
/// <summary>
/// mono detection
/// </summary>
public static bool MONO = false;
/// <summary>
/// speech engine enable
/// </summary>
public static bool speechEnable = false;
/// <summary>
/// spech engine static class
/// </summary>
public static ISpeech speechEngine { get; set; }
/// <summary>
/// joystick static class
/// </summary>
public static Joystick.Joystick joystick { get; set; }
/// <summary>
/// track last joystick packet sent. used to control rate
/// </summary>
DateTime lastjoystick = DateTime.Now;
/// <summary>
/// determine if we are running sitl
/// </summary>
public static bool sitl
{
get
{
if (MissionPlanner.Controls.SITL.SITLSEND == null) return false;
if (MissionPlanner.Controls.SITL.SITLSEND.Client.Connected) return true;
return false;
}
}
/// <summary>
/// hud background image grabber from a video stream - not realy that efficent. ie no hardware overlays etc.
/// </summary>
public static WebCamService.Capture cam { get; set; }
/// <summary>
/// controls the main serial reader thread
/// </summary>
bool serialThread = false;
bool pluginthreadrun = false;
bool joystickthreadrun = false;
Thread httpthread;
Thread joystickthread;
Thread serialreaderthread;
Thread pluginthread;
/// <summary>
/// track the last heartbeat sent
/// </summary>
private DateTime heatbeatSend = DateTime.Now;
/// <summary>
/// used to call anything as needed.
/// </summary>
public static MainV2 instance = null;
public static MainSwitcher View;
/// <summary>
/// store the time we first connect
/// </summary>
DateTime connecttime = DateTime.Now;
DateTime nodatawarning = DateTime.Now;
DateTime OpenTime = DateTime.Now;
/// <summary>
/// enum of firmwares
/// </summary>
public enum Firmwares
{
ArduPlane,
ArduCopter2,
ArduRover,
ArduSub,
Ateryx,
ArduTracker,
Gymbal,
PX4
}
DateTime connectButtonUpdate = DateTime.Now;
/// <summary>
/// declared here if i want a "single" instance of the form
/// ie configuration gets reloaded on every click
/// </summary>
public GCSViews.FlightData FlightData;
public GCSViews.FlightPlanner FlightPlanner;
Controls.SITL Simulation;
private Form connectionStatsForm;
private ConnectionStats _connectionStats;
/// <summary>
/// This 'Control' is the toolstrip control that holds the comport combo, baudrate combo etc
/// Otiginally seperate controls, each hosted in a toolstip sqaure, combined into this custom
/// control for layout reasons.
/// </summary>
public static ConnectionControl _connectionControl;
public static bool TerminalTheming = true;
public void updateLayout(object sender, EventArgs e)
{
MenuSimulation.Visible = DisplayConfiguration.displaySimulation;
MenuTerminal.Visible = DisplayConfiguration.displayTerminal;
MenuHelp.Visible = DisplayConfiguration.displayHelp;
MenuDonate.Visible = DisplayConfiguration.displayDonate;
MissionPlanner.Controls.BackstageView.BackstageView.Advanced = DisplayConfiguration.isAdvancedMode;
if (Settings.Instance.GetBoolean("menu_autohide") != DisplayConfiguration.autoHideMenuForce)
{
AutoHideMenu(DisplayConfiguration.autoHideMenuForce);
Settings.Instance["menu_autohide"] = DisplayConfiguration.autoHideMenuForce.ToString();
}
autoHideToolStripMenuItem.Visible = !DisplayConfiguration.autoHideMenuForce;
//Flight data page
if (MainV2.instance.FlightData != null)
{
TabControl t = MainV2.instance.FlightData.tabControlactions;
if (DisplayConfiguration.displayQuickTab && !t.TabPages.Contains(FlightData.tabQuick))
{
t.TabPages.Add(FlightData.tabQuick);
}
else if (!DisplayConfiguration.displayQuickTab && t.TabPages.Contains(FlightData.tabQuick))
{
t.TabPages.Remove(FlightData.tabQuick);
}
if (DisplayConfiguration.displayPreFlightTab && !t.TabPages.Contains(FlightData.tabPagePreFlight))
{
t.TabPages.Add(FlightData.tabPagePreFlight);
}
else if (!DisplayConfiguration.displayPreFlightTab && t.TabPages.Contains(FlightData.tabPagePreFlight))
{
t.TabPages.Remove(FlightData.tabPagePreFlight);
}
if (DisplayConfiguration.displayAdvActionsTab && !t.TabPages.Contains(FlightData.tabActions))
{
t.TabPages.Add(FlightData.tabActions);
}
else if (!DisplayConfiguration.displayAdvActionsTab && t.TabPages.Contains(FlightData.tabActions))
{
t.TabPages.Remove(FlightData.tabActions);
}
if (DisplayConfiguration.displaySimpleActionsTab && !t.TabPages.Contains(FlightData.tabActionsSimple))
{
t.TabPages.Add(FlightData.tabActionsSimple);
}
else if (!DisplayConfiguration.displaySimpleActionsTab && t.TabPages.Contains(FlightData.tabActionsSimple))
{
t.TabPages.Remove(FlightData.tabActionsSimple);
}
if (DisplayConfiguration.displayGaugesTab && !t.TabPages.Contains(FlightData.tabGauges))
{
t.TabPages.Add(FlightData.tabGauges);
}
else if (!DisplayConfiguration.displayGaugesTab && t.TabPages.Contains(FlightData.tabGauges))
{
t.TabPages.Remove(FlightData.tabGauges);
}
if (DisplayConfiguration.displayStatusTab && !t.TabPages.Contains(FlightData.tabStatus))
{
t.TabPages.Add(FlightData.tabStatus);
}
else if (!DisplayConfiguration.displayStatusTab && t.TabPages.Contains(FlightData.tabStatus))
{
t.TabPages.Remove(FlightData.tabStatus);
}
if (DisplayConfiguration.displayServoTab && !t.TabPages.Contains(FlightData.tabServo))
{
t.TabPages.Add(FlightData.tabServo);
}
else if (!DisplayConfiguration.displayServoTab && t.TabPages.Contains(FlightData.tabServo))
{
t.TabPages.Remove(FlightData.tabServo);
}
if (DisplayConfiguration.displayScriptsTab && !t.TabPages.Contains(FlightData.tabScripts))
{
t.TabPages.Add(FlightData.tabScripts);
}
else if (!DisplayConfiguration.displayScriptsTab && t.TabPages.Contains(FlightData.tabScripts))
{
t.TabPages.Remove(FlightData.tabScripts);
}
if (DisplayConfiguration.displayTelemetryTab && !t.TabPages.Contains(FlightData.tabTLogs))
{
t.TabPages.Add(FlightData.tabTLogs);
}
else if (!DisplayConfiguration.displayTelemetryTab && t.TabPages.Contains(FlightData.tabTLogs))
{
t.TabPages.Remove(FlightData.tabTLogs);
}
if (DisplayConfiguration.displayDataflashTab && !t.TabPages.Contains(FlightData.tablogbrowse))
{
t.TabPages.Add(FlightData.tablogbrowse);
}
else if (!DisplayConfiguration.displayDataflashTab && t.TabPages.Contains(FlightData.tablogbrowse))
{
t.TabPages.Remove(FlightData.tablogbrowse);
}
if (DisplayConfiguration.displayMessagesTab && !t.TabPages.Contains(FlightData.tabPagemessages))
{
t.TabPages.Add(FlightData.tabPagemessages);
}
else if (!DisplayConfiguration.displayMessagesTab && t.TabPages.Contains(FlightData.tabPagemessages))
{
t.TabPages.Remove(FlightData.tabPagemessages);
}
t.SelectedIndex = 0;
}
if (MainV2.instance.FlightPlanner != null)
{
//hide menu items
MainV2.instance.FlightPlanner.updateDisplayView();
}
}
public MainV2()
{
log.Info("Mainv2 ctor");
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
// set this before we reset it
Settings.Instance["NUM_tracklength"] = "200";
// create one here - but override on load
Settings.Instance["guid"] = Guid.NewGuid().ToString();
// load config
LoadConfig();
// force language to be loaded
L10N.GetConfigLang();
ShowAirports = true;
// setup adsb
Utilities.adsb.UpdatePlanePosition += adsb_UpdatePlanePosition;
Form splash = Program.Splash;
splash.Refresh();
Application.DoEvents();
instance = this;
//disable dpi scaling
if (Font.Name != "宋体")
{
//Chinese displayed normally when scaling. But would be too small or large using this line of code.
using (var g = CreateGraphics())
{
Font = new Font(Font.Name, 8.25f*96f/g.DpiX, Font.Style, Font.Unit, Font.GdiCharSet,
Font.GdiVerticalFont);
}
}
InitializeComponent();
try
{
if(Settings.Instance["theme"] != null)
ThemeManager.SetTheme((ThemeManager.Themes)Enum.Parse(typeof(ThemeManager.Themes), Settings.Instance["theme"]));
}
catch
{
}
Utilities.ThemeManager.ApplyThemeTo(this);
MyView = new MainSwitcher(this);
View = MyView;
//startup console
TCPConsole.Write((byte) 'S');
_connectionControl = toolStripConnectionControl.ConnectionControl;
_connectionControl.CMB_baudrate.TextChanged += this.CMB_baudrate_TextChanged;
_connectionControl.CMB_serialport.SelectedIndexChanged += this.CMB_serialport_SelectedIndexChanged;
_connectionControl.CMB_serialport.Click += this.CMB_serialport_Click;
_connectionControl.cmb_sysid.Click += cmb_sysid_Click;
_connectionControl.ShowLinkStats += (sender, e) => ShowConnectionStatsForm();
srtm.datadirectory = Settings.GetDataDirectory() +
"srtm";
var t = Type.GetType("Mono.Runtime");
MONO = (t != null);
speechEngine = new Speech();
Warnings.CustomWarning.defaultsrc = comPort.MAV.cs;
Warnings.WarningEngine.Start();
// proxy loader - dll load now instead of on config form load
new Transition(new TransitionType_EaseInEaseOut(2000));
foreach (object obj in Enum.GetValues(typeof (Firmwares)))
{
_connectionControl.TOOL_APMFirmware.Items.Add(obj);
}
if (_connectionControl.TOOL_APMFirmware.Items.Count > 0)
_connectionControl.TOOL_APMFirmware.SelectedIndex = 0;
comPort.BaseStream.BaudRate = 115200;
PopulateSerialportList();
if (_connectionControl.CMB_serialport.Items.Count > 0)
{
_connectionControl.CMB_baudrate.SelectedIndex = 8;
_connectionControl.CMB_serialport.SelectedIndex = 0;
}
// ** Done
splash.Refresh();
Application.DoEvents();
// load last saved connection settings
string temp = Settings.Instance.ComPort;
if (!string.IsNullOrEmpty(temp))
{
_connectionControl.CMB_serialport.SelectedIndex = _connectionControl.CMB_serialport.FindString(temp);
if (_connectionControl.CMB_serialport.SelectedIndex == -1)
{
_connectionControl.CMB_serialport.Text = temp; // allows ports that dont exist - yet
}
comPort.BaseStream.PortName = temp;
comPortName = temp;
}
string temp2 = Settings.Instance.BaudRate;
if (!string.IsNullOrEmpty(temp2))
{
var idx = _connectionControl.CMB_baudrate.FindString(temp2);
if (idx == -1)
{
_connectionControl.CMB_baudrate.Text = temp2;
}
else
{
_connectionControl.CMB_baudrate.SelectedIndex = idx;
}
comPortBaud = int.Parse(temp2);
}
string temp3 = Settings.Instance.APMFirmware;
if (!string.IsNullOrEmpty(temp3))
{
_connectionControl.TOOL_APMFirmware.SelectedIndex =
_connectionControl.TOOL_APMFirmware.FindStringExact(temp3);
if (_connectionControl.TOOL_APMFirmware.SelectedIndex == -1)
_connectionControl.TOOL_APMFirmware.SelectedIndex = 0;
MainV2.comPort.MAV.cs.firmware =
(MainV2.Firmwares) Enum.Parse(typeof (MainV2.Firmwares), _connectionControl.TOOL_APMFirmware.Text);
}
MissionPlanner.Utilities.Tracking.cid = new Guid(Settings.Instance["guid"].ToString());
// setup guids for droneshare
if (!Settings.Instance.ContainsKey("plane_guid"))
Settings.Instance["plane_guid"] = Guid.NewGuid().ToString();
if (!Settings.Instance.ContainsKey("copter_guid"))
Settings.Instance["copter_guid"] = Guid.NewGuid().ToString();
if (!Settings.Instance.ContainsKey("rover_guid"))
Settings.Instance["rover_guid"] = Guid.NewGuid().ToString();
if (Settings.Instance.ContainsKey("language") && !string.IsNullOrEmpty(Settings.Instance["language"]))
{
changelanguage(CultureInfoEx.GetCultureInfo(Settings.Instance["language"]));
}
this.Text = splash.Text;
titlebar = splash.Text;
if (!MONO) // windows only
{
if (Settings.Instance["showconsole"] != null && Settings.Instance["showconsole"].ToString() == "True")
{
}
else
{
int win = NativeMethods.FindWindow("ConsoleWindowClass", null);
NativeMethods.ShowWindow(win, NativeMethods.SW_HIDE); // hide window
}
// prevent system from sleeping while mp open
var previousExecutionState =
NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED);
}
ChangeUnits();
if (Settings.Instance["theme"] != null)
{
try
{
ThemeManager.SetTheme(
(ThemeManager.Themes)
Enum.Parse(typeof (ThemeManager.Themes), Settings.Instance["theme"].ToString()));
}
catch (Exception exception)
{
log.Error(exception);
}
if (ThemeManager.CurrentTheme == ThemeManager.Themes.Custom)
{
try
{
ThemeManager.BGColor = Color.FromArgb(int.Parse(Settings.Instance["theme_bg"].ToString()));
ThemeManager.ControlBGColor = Color.FromArgb(int.Parse(Settings.Instance["theme_ctlbg"].ToString()));
ThemeManager.TextColor = Color.FromArgb(int.Parse(Settings.Instance["theme_text"].ToString()));
ThemeManager.ButBG = Color.FromArgb(int.Parse(Settings.Instance["theme_butbg"].ToString()));
ThemeManager.ButBorder = Color.FromArgb(int.Parse(Settings.Instance["theme_butbord"].ToString()));
}
catch
{
log.Error("Bad Custom theme - reset to standard");
ThemeManager.SetTheme(ThemeManager.Themes.BurntKermit);
}
}
if (ThemeManager.CurrentTheme == ThemeManager.Themes.HighContrast)
{
switchicons(new highcontrastmenuicons());
}
}
if (Settings.Instance["showairports"] != null)
{
MainV2.ShowAirports = bool.Parse(Settings.Instance["showairports"]);
}
// set default
ShowTFR = true;
// load saved
if (Settings.Instance["showtfr"] != null)
{
MainV2.ShowTFR = Settings.Instance.GetBoolean("showtfr");
}
if (Settings.Instance["enableadsb"] != null)
{
MainV2.instance.EnableADSB = Settings.Instance.GetBoolean("enableadsb");
}
try
{
log.Info("Create FD");
FlightData = new GCSViews.FlightData();
log.Info("Create FP");
FlightPlanner = new GCSViews.FlightPlanner();
//Configuration = new GCSViews.ConfigurationView.Setup();
log.Info("Create SIM");
Simulation = new SITL();
//Firmware = new GCSViews.Firmware();
//Terminal = new GCSViews.Terminal();
FlightData.Width = MyView.Width;
FlightPlanner.Width = MyView.Width;
Simulation.Width = MyView.Width;
}
catch (ArgumentException e)
{
//http://www.microsoft.com/en-us/download/details.aspx?id=16083
//System.ArgumentException: Font 'Arial' does not support style 'Regular'.
log.Fatal(e);
CustomMessageBox.Show(e.ToString() +
"\n\n Font Issues? Please install this http://www.microsoft.com/en-us/download/details.aspx?id=16083");
//splash.Close();
//this.Close();
Application.Exit();
}
catch (Exception e)
{
log.Fatal(e);
CustomMessageBox.Show("A Major error has occured : " + e.ToString());
Application.Exit();
}
//set first instance display configuration
if (DisplayConfiguration == null)
{
DisplayConfiguration = DisplayConfiguration.Advanced();
}
// load old config
if (Settings.Instance["advancedview"] != null)
{
if (Settings.Instance.GetBoolean("advancedview") == true)
{
DisplayConfiguration = new DisplayView().Advanced();
}
// remove old config
Settings.Instance.Remove("advancedview");
} //// load this before the other screens get loaded
if (Settings.Instance["displayview"] != null)
{
try
{
DisplayConfiguration = Settings.Instance.GetDisplayView("displayview");
}
catch
{
DisplayConfiguration = DisplayConfiguration.Advanced();
}
}
LayoutChanged += updateLayout;
LayoutChanged(null, EventArgs.Empty);
if (Settings.Instance["CHK_GDIPlus"] != null)
GCSViews.FlightData.myhud.opengl = !bool.Parse(Settings.Instance["CHK_GDIPlus"].ToString());
if (Settings.Instance["CHK_hudshow"] != null)
GCSViews.FlightData.myhud.hudon = bool.Parse(Settings.Instance["CHK_hudshow"].ToString());
try
{
if (Settings.Instance["MainLocX"] != null && Settings.Instance["MainLocY"] != null)
{
this.StartPosition = FormStartPosition.Manual;
Point startpos = new Point(Settings.Instance.GetInt32("MainLocX"),
Settings.Instance.GetInt32("MainLocY"));
// fix common bug which happens when user removes a monitor, the app shows up
// offscreen and it is very hard to move it onscreen. Also happens with
// remote desktop a lot. So this only restores position if the position
// is visible.
foreach (Screen s in Screen.AllScreens)
{
if (s.WorkingArea.Contains(startpos))
{
this.Location = startpos;
break;
}
}
}
if (Settings.Instance["MainMaximised"] != null)
{
this.WindowState =
(FormWindowState) Enum.Parse(typeof (FormWindowState), Settings.Instance["MainMaximised"]);
// dont allow minimised start state
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
this.Location = new Point(100, 100);
}
}
if (Settings.Instance["MainHeight"] != null)
this.Height = Settings.Instance.GetInt32("MainHeight");
if (Settings.Instance["MainWidth"] != null)
this.Width = Settings.Instance.GetInt32("MainWidth");
if (Settings.Instance["CMB_rateattitude"] != null)
CurrentState.rateattitudebackup = Settings.Instance.GetByte("CMB_rateattitude");
if (Settings.Instance["CMB_rateposition"] != null)
CurrentState.ratepositionbackup = Settings.Instance.GetByte("CMB_rateposition");
if (Settings.Instance["CMB_ratestatus"] != null)
CurrentState.ratestatusbackup = Settings.Instance.GetByte("CMB_ratestatus");
if (Settings.Instance["CMB_raterc"] != null)
CurrentState.ratercbackup = Settings.Instance.GetByte("CMB_raterc");
if (Settings.Instance["CMB_ratesensors"] != null)
CurrentState.ratesensorsbackup = Settings.Instance.GetByte("CMB_ratesensors");
// make sure rates propogate
MainV2.comPort.MAV.cs.ResetInternals();
if (Settings.Instance["speechenable"] != null)
MainV2.speechEnable = Settings.Instance.GetBoolean("speechenable");
if (Settings.Instance["analyticsoptout"] != null)
MissionPlanner.Utilities.Tracking.OptOut = Settings.Instance.GetBoolean("analyticsoptout");
try
{
if (Settings.Instance["TXT_homelat"] != null)
MainV2.comPort.MAV.cs.HomeLocation.Lat = Settings.Instance.GetDouble("TXT_homelat");
if (Settings.Instance["TXT_homelng"] != null)
MainV2.comPort.MAV.cs.HomeLocation.Lng = Settings.Instance.GetDouble("TXT_homelng");
if (Settings.Instance["TXT_homealt"] != null)
MainV2.comPort.MAV.cs.HomeLocation.Alt = Settings.Instance.GetDouble("TXT_homealt");
// remove invalid entrys
if (Math.Abs(MainV2.comPort.MAV.cs.HomeLocation.Lat) > 90 ||
Math.Abs(MainV2.comPort.MAV.cs.HomeLocation.Lng) > 180)
MainV2.comPort.MAV.cs.HomeLocation = new PointLatLngAlt();
}
catch
{
}
}
catch
{
}
if (CurrentState.rateattitudebackup == 0) // initilised to 10, configured above from save
{
CustomMessageBox.Show(
"NOTE: your attitude rate is 0, the hud will not work\nChange in Configuration > Planner > Telemetry Rates");
}
// create log dir if it doesnt exist
try
{
if (!Directory.Exists(Settings.Instance.LogDir))
Directory.CreateDirectory(Settings.Instance.LogDir);
}
catch (Exception ex) { log.Error(ex); }
Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
// make sure new enough .net framework is installed
if (!MONO)
{
Microsoft.Win32.RegistryKey installed_versions =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP");
string[] version_names = installed_versions.GetSubKeyNames();
//version names start with 'v', eg, 'v3.5' which needs to be trimmed off before conversion
double Framework = Convert.ToDouble(version_names[version_names.Length - 1].Remove(0, 1),
CultureInfo.InvariantCulture);
int SP =
Convert.ToInt32(installed_versions.OpenSubKey(version_names[version_names.Length - 1])
.GetValue("SP", 0));
if (Framework < 4.0)
{
CustomMessageBox.Show("This program requires .NET Framework 4.0. You currently have " + Framework);
}
}
if (Program.IconFile != null)
{
this.Icon = Icon.FromHandle(((Bitmap)Program.IconFile).GetHicon());
}
if (Program.Logo != null && Program.name == "VVVVZ")
{
MenuDonate.Click -= this.toolStripMenuItem1_Click;
MenuDonate.Text = "";
MenuDonate.Image = Program.Logo;
MenuDonate.Click += MenuCustom_Click;
MenuFlightData.Visible = false;
MenuFlightPlanner.Visible = true;
MenuConfigTune.Visible = false;
MenuHelp.Visible = false;
MenuInitConfig.Visible = false;
MenuSimulation.Visible = false;
MenuTerminal.Visible = false;
}
else if (Program.Logo != null && Program.names.Contains(Program.name))
{
MenuDonate.Click -= this.toolStripMenuItem1_Click;
MenuDonate.Text = "";
MenuDonate.Image = Program.Logo;
}
Application.DoEvents();
Comports.Add(comPort);
MainV2.comPort.MavChanged += comPort_MavChanged;
// save config to test we have write access
SaveConfig();
}
void cmb_sysid_Click(object sender, EventArgs e)
{
MainV2._connectionControl.UpdateSysIDS();
}
void comPort_MavChanged(object sender, EventArgs e)
{