forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlightPlanner.cs
6928 lines (5815 loc) · 253 KB
/
FlightPlanner.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;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using DotSpatial.Data;
using DotSpatial.Projections;
using GeoUtility.GeoSystem;
using GeoUtility.GeoSystem.Base;
using GMap.NET;
using GMap.NET.MapProviders;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using Ionic.Zip;
using log4net;
using MissionPlanner.Controls;
using MissionPlanner.Controls.Waypoints;
using MissionPlanner.Maps;
using MissionPlanner.Properties;
using MissionPlanner.Utilities;
using ProjNet.CoordinateSystems;
using ProjNet.CoordinateSystems.Transformations;
using SharpKml.Base;
using SharpKml.Dom;
using Feature = SharpKml.Dom.Feature;
using ILog = log4net.ILog;
using Placemark = SharpKml.Dom.Placemark;
using Point = System.Drawing.Point;
using System.Text.RegularExpressions;
namespace MissionPlanner.GCSViews
{
public partial class FlightPlanner : MyUserControl, IDeactivate, IActivate
{
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
int selectedrow;
public bool quickadd;
bool isonline = true;
bool sethome;
bool polygongridmode;
Hashtable param = new Hashtable();
bool splinemode;
altmode currentaltmode = altmode.Relative;
bool grid;
public static FlightPlanner instance;
public bool autopan { get; set; }
public List<PointLatLngAlt> pointlist = new List<PointLatLngAlt>(); // used to calc distance
public List<PointLatLngAlt> fullpointlist = new List<PointLatLngAlt>();
public GMapRoute route = new GMapRoute("wp route");
public GMapRoute homeroute = new GMapRoute("home route");
static public Object thisLock = new Object();
private ComponentResourceManager rm = new ComponentResourceManager(typeof (FlightPlanner));
private Dictionary<string, string[]> cmdParamNames = new Dictionary<string, string[]>();
List<List<Locationwp>> history = new List<List<Locationwp>>();
List<int> groupmarkers = new List<int>();
public enum altmode
{
Relative = MAVLink.MAV_FRAME.GLOBAL_RELATIVE_ALT,
Absolute = MAVLink.MAV_FRAME.GLOBAL,
Terrain = MAVLink.MAV_FRAME.GLOBAL_TERRAIN_ALT
}
private void poieditToolStripMenuItem_Click(object sender, EventArgs e)
{
if (CurrentGMapMarker == null || !(CurrentGMapMarker is GMapMarkerPOI))
return;
POI.POIEdit(CurrentPOIMarker);
}
private void poideleteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (CurrentPOIMarker == null)
return;
POI.POIDelete(CurrentPOIMarker);
}
private void poiaddToolStripMenuItem_Click(object sender, EventArgs e)
{
POI.POIAdd(MouseDownStart);
}
/// <summary>
/// used to adjust existing point in the datagrid including "H"
/// </summary>
/// <param name="pointno"></param>
/// <param name="lat"></param>
/// <param name="lng"></param>
/// <param name="alt"></param>
public void callMeDrag(string pointno, double lat, double lng, int alt)
{
if (pointno == "")
{
return;
}
// dragging a WP
if (pointno == "H")
{
// auto update home alt
TXT_homealt.Text = (srtm.getAltitude(lat, lng).alt * CurrentState.multiplierdist).ToString();
TXT_homelat.Text = lat.ToString();
TXT_homelng.Text = lng.ToString();
return;
}
if (pointno == "Tracker Home")
{
MainV2.comPort.MAV.cs.TrackerLocation = new PointLatLngAlt(lat, lng, alt, "");
return;
}
try
{
selectedrow = int.Parse(pointno) - 1;
Commands.CurrentCell = Commands[1, selectedrow];
// depending on the dragged item, selectedrow can be reset
selectedrow = int.Parse(pointno) - 1;
}
catch
{
return;
}
setfromMap(lat, lng, alt);
}
/// <summary>
/// Actualy Sets the values into the datagrid and verifys height if turned on
/// </summary>
/// <param name="lat"></param>
/// <param name="lng"></param>
/// <param name="alt"></param>
public void setfromMap(double lat, double lng, int alt, double p1 = 0)
{
if (selectedrow > Commands.RowCount)
{
CustomMessageBox.Show("Invalid coord, How did you do this?");
return;
}
try
{
// get current command list
var currentlist = GetCommandList();
// add history
history.Add(currentlist);
}
catch (Exception ex)
{
CustomMessageBox.Show("A invalid entry has been detected\n" + ex.Message, Strings.ERROR);
}
// remove more than 20 revisions
if (history.Count > 20)
{
history.RemoveRange(0, history.Count - 20);
}
DataGridViewTextBoxCell cell;
if (alt == -2 && Commands.Columns[Alt.Index].HeaderText.Equals(cmdParamNames["WAYPOINT"][6] /*"Alt"*/))
{
if (CHK_verifyheight.Checked && (altmode)CMB_altmode.SelectedValue != altmode.Terrain) //Drag with verifyheight // use srtm data
{
cell = Commands.Rows[selectedrow].Cells[Alt.Index] as DataGridViewTextBoxCell;
float ans;
if (float.TryParse(cell.Value.ToString(), out ans))
{
ans = (int) ans;
DataGridViewTextBoxCell celllat =
Commands.Rows[selectedrow].Cells[Lat.Index] as DataGridViewTextBoxCell;
DataGridViewTextBoxCell celllon =
Commands.Rows[selectedrow].Cells[Lon.Index] as DataGridViewTextBoxCell;
int oldsrtm =
(int)
((srtm.getAltitude(double.Parse(celllat.Value.ToString()),
double.Parse(celllon.Value.ToString())).alt)*CurrentState.multiplierdist);
int newsrtm = (int) ((srtm.getAltitude(lat, lng).alt)*CurrentState.multiplierdist);
int newh = (int) (ans + newsrtm - oldsrtm);
cell.Value = newh;
cell.DataGridView.EndEdit();
}
}
}
if (Commands.Columns[Lat.Index].HeaderText.Equals(cmdParamNames["WAYPOINT"][4] /*"Lat"*/))
{
cell = Commands.Rows[selectedrow].Cells[Lat.Index] as DataGridViewTextBoxCell;
cell.Value = lat.ToString("0.0000000");
cell.DataGridView.EndEdit();
}
if (Commands.Columns[Lon.Index].HeaderText.Equals(cmdParamNames["WAYPOINT"][5] /*"Long"*/))
{
cell = Commands.Rows[selectedrow].Cells[Lon.Index] as DataGridViewTextBoxCell;
cell.Value = lng.ToString("0.0000000");
cell.DataGridView.EndEdit();
}
if (alt != -1 && alt != -2 &&
Commands.Columns[Alt.Index].HeaderText.Equals(cmdParamNames["WAYPOINT"][6] /*"Alt"*/))
{
cell = Commands.Rows[selectedrow].Cells[Alt.Index] as DataGridViewTextBoxCell;
{
double result;
bool pass = double.TryParse(TXT_homealt.Text, out result);
if (pass == false)
{
CustomMessageBox.Show("You must have a home altitude");
string homealt = "100";
if (DialogResult.Cancel == InputBox.Show("Home Alt", "Home Altitude", ref homealt))
return;
TXT_homealt.Text = homealt;
}
int results1;
if (!int.TryParse(TXT_DefaultAlt.Text, out results1))
{
CustomMessageBox.Show("Your default alt is not valid");
return;
}
if (results1 == 0)
{
string defalt = "100";
if (DialogResult.Cancel == InputBox.Show("Default Alt", "Default Altitude", ref defalt))
return;
TXT_DefaultAlt.Text = defalt;
}
}
cell.Value = TXT_DefaultAlt.Text;
float ans;
if (float.TryParse(cell.Value.ToString(), out ans))
{
ans = (int) ans;
if (alt != 0) // use passed in value;
cell.Value = alt.ToString();
if (ans == 0) // default
cell.Value = 50;
if (ans == 0 && (MainV2.comPort.MAV.cs.firmware == MainV2.Firmwares.ArduCopter2))
cell.Value = 15;
// not online and verify alt via srtm
if (CHK_verifyheight.Checked) // use srtm data
{
// is absolute but no verify
if ((altmode) CMB_altmode.SelectedValue == altmode.Absolute)
{
//abs
cell.Value =
((srtm.getAltitude(lat, lng).alt)*CurrentState.multiplierdist +
int.Parse(TXT_DefaultAlt.Text)).ToString();
}
else if ((altmode) CMB_altmode.SelectedValue == altmode.Terrain)
{
cell.Value = int.Parse(TXT_DefaultAlt.Text);
}
else
{
//relative and verify
cell.Value =
((int) (srtm.getAltitude(lat, lng).alt)*CurrentState.multiplierdist +
int.Parse(TXT_DefaultAlt.Text) -
(int)
srtm.getAltitude(MainV2.comPort.MAV.cs.HomeLocation.Lat,
MainV2.comPort.MAV.cs.HomeLocation.Lng).alt*CurrentState.multiplierdist)
.ToString();
}
}
cell.DataGridView.EndEdit();
}
else
{
CustomMessageBox.Show("Invalid Home or wp Alt");
cell.Style.BackColor = Color.Red;
}
}
// convert to utm
convertFromGeographic(lat, lng);
// Add more for other params
if (Commands.Columns[Param1.Index].HeaderText.Equals(cmdParamNames["WAYPOINT"][1] /*"Delay"*/))
{
cell = Commands.Rows[selectedrow].Cells[Param1.Index] as DataGridViewTextBoxCell;
cell.Value = p1;
cell.DataGridView.EndEdit();
}
writeKML();
Commands.EndEdit();
}
private void convertFromGeographic(double lat, double lng)
{
if (lat == 0 && lng == 0)
{
return;
}
// always update other systems, incase user switchs while planning
try
{
//UTM
var temp = new PointLatLngAlt(lat, lng);
int zone = temp.GetUTMZone();
var temp2 = temp.ToUTM();
Commands[coordZone.Index, selectedrow].Value = zone;
Commands[coordEasting.Index, selectedrow].Value = temp2[0].ToString("0.000");
Commands[coordNorthing.Index, selectedrow].Value = temp2[1].ToString("0.000");
}
catch (Exception ex)
{
log.Error(ex);
}
try
{
//MGRS
Commands[MGRS.Index, selectedrow].Value = ((MGRS) new Geographic(lng, lat)).ToString();
}
catch (Exception ex)
{
log.Error(ex);
}
}
void convertFromUTM(int rowindex)
{
try
{
var zone = int.Parse(Commands[coordZone.Index, rowindex].Value.ToString());
var east = double.Parse(Commands[coordEasting.Index, rowindex].Value.ToString());
var north = double.Parse(Commands[coordNorthing.Index, rowindex].Value.ToString());
if (east == 0 && north == 0)
{
return;
}
var utm = new utmpos(east, north, zone);
Commands[Lat.Index, rowindex].Value = utm.ToLLA().Lat;
Commands[Lon.Index, rowindex].Value = utm.ToLLA().Lng;
}
catch
{
return;
}
}
void convertFromMGRS(int rowindex)
{
try
{
var mgrs = Commands[MGRS.Index, rowindex].Value.ToString();
MGRS temp = new MGRS(mgrs);
var convert = temp.ConvertTo<Geographic>();
if (convert.Latitude == 0 || convert.Longitude == 0)
return;
Commands[Lat.Index, rowindex].Value = convert.Latitude.ToString();
Commands[Lon.Index, rowindex].Value = convert.Longitude.ToString();
}
catch
{
return;
}
}
PointLatLngAlt mouseposdisplay = new PointLatLngAlt(0, 0);
/// <summary>
/// Used for current mouse position
/// </summary>
/// <param name="lat"></param>
/// <param name="lng"></param>
/// <param name="alt"></param>
public void SetMouseDisplay(double lat, double lng, int alt)
{
mouseposdisplay.Lat = lat;
mouseposdisplay.Lng = lng;
mouseposdisplay.Alt = alt;
coords1.Lat = mouseposdisplay.Lat;
coords1.Lng = mouseposdisplay.Lng;
var altdata = srtm.getAltitude(mouseposdisplay.Lat, mouseposdisplay.Lng, MainMap.Zoom);
coords1.Alt = altdata.alt;
coords1.AltSource = altdata.altsource;
try
{
PointLatLng last;
if (pointlist.Count == 0 || pointlist[pointlist.Count - 1] == null)
return;
last = pointlist[pointlist.Count - 1];
double lastdist = MainMap.MapProvider.Projection.GetDistance(last, currentMarker.Position);
double lastbearing = 0;
if (pointlist.Count > 0)
{
lastbearing = MainMap.MapProvider.Projection.GetBearing(last, currentMarker.Position);
}
lbl_prevdist.Text = rm.GetString("lbl_prevdist.Text") + ": " + FormatDistance(lastdist, true) + " AZ: " +
lastbearing.ToString("0");
// 0 is home
if (pointlist[0] != null)
{
double homedist = MainMap.MapProvider.Projection.GetDistance(currentMarker.Position, pointlist[0]);
lbl_homedist.Text = rm.GetString("lbl_homedist.Text") + ": " + FormatDistance(homedist, true);
}
}
catch
{
}
}
/// <summary>
/// Used to create a new WP
/// </summary>
/// <param name="lat"></param>
/// <param name="lng"></param>
/// <param name="alt"></param>
public void AddWPToMap(double lat, double lng, int alt)
{
if (polygongridmode)
{
addPolygonPointToolStripMenuItem_Click(null, null);
return;
}
if (sethome)
{
sethome = false;
callMeDrag("H", lat, lng, alt);
return;
}
// creating a WP
selectedrow = Commands.Rows.Add();
if (splinemode)
{
Commands.Rows[selectedrow].Cells[Command.Index].Value = MAVLink.MAV_CMD.SPLINE_WAYPOINT.ToString();
ChangeColumnHeader(MAVLink.MAV_CMD.SPLINE_WAYPOINT.ToString());
}
else
{
Commands.Rows[selectedrow].Cells[Command.Index].Value = MAVLink.MAV_CMD.WAYPOINT.ToString();
ChangeColumnHeader(MAVLink.MAV_CMD.WAYPOINT.ToString());
}
setfromMap(lat, lng, alt);
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
// undo
if (keyData == (Keys.Control | Keys.Z))
{
if (history.Count > 0)
{
int no = history.Count - 1;
var pop = history[no];
history.RemoveAt(no);
WPtoScreen(pop);
}
return true;
}
// open wp file
if (keyData == (Keys.Control | Keys.O))
{
loadWPFileToolStripMenuItem_Click(null, null);
return true;
}
// save wp file
if (keyData == (Keys.Control | Keys.S))
{
saveWPFileToolStripMenuItem_Click(null, null);
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
public FlightPlanner()
{
instance = this;
InitializeComponent();
// config map
MainMap.CacheLocation = Settings.GetDataDirectory() +
"gmapcache" + Path.DirectorySeparatorChar;
// map events
MainMap.OnPositionChanged += MainMap_OnCurrentPositionChanged;
MainMap.OnTileLoadStart += MainMap_OnTileLoadStart;
MainMap.OnTileLoadComplete += MainMap_OnTileLoadComplete;
MainMap.OnMarkerClick += MainMap_OnMarkerClick;
MainMap.OnMapZoomChanged += MainMap_OnMapZoomChanged;
MainMap.OnMapTypeChanged += MainMap_OnMapTypeChanged;
MainMap.MouseMove += MainMap_MouseMove;
MainMap.MouseDown += MainMap_MouseDown;
MainMap.MouseUp += MainMap_MouseUp;
MainMap.OnMarkerEnter += MainMap_OnMarkerEnter;
MainMap.OnMarkerLeave += MainMap_OnMarkerLeave;
MainMap.MapScaleInfoEnabled = false;
MainMap.ScalePen = new Pen(Color.Red);
MainMap.DisableFocusOnMouseEnter = true;
MainMap.ForceDoubleBuffer = false;
//WebRequest.DefaultWebProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
// get map type
comboBoxMapType.ValueMember = "Name";
comboBoxMapType.DataSource = GMapProviders.List.ToArray();
comboBoxMapType.SelectedItem = MainMap.MapProvider;
comboBoxMapType.SelectedValueChanged += comboBoxMapType_SelectedValueChanged;
MainMap.RoutesEnabled = true;
//MainMap.MaxZoom = 18;
// get zoom
MainMap.MinZoom = 0;
MainMap.MaxZoom = 24;
// draw this layer first
kmlpolygonsoverlay = new GMapOverlay("kmlpolygons");
MainMap.Overlays.Add(kmlpolygonsoverlay);
geofenceoverlay = new GMapOverlay("geofence");
MainMap.Overlays.Add(geofenceoverlay);
rallypointoverlay = new GMapOverlay("rallypoints");
MainMap.Overlays.Add(rallypointoverlay);
routesoverlay = new GMapOverlay("routes");
MainMap.Overlays.Add(routesoverlay);
polygonsoverlay = new GMapOverlay("polygons");
MainMap.Overlays.Add(polygonsoverlay);
airportsoverlay = new GMapOverlay("airports");
MainMap.Overlays.Add(airportsoverlay);
objectsoverlay = new GMapOverlay("objects");
MainMap.Overlays.Add(objectsoverlay);
drawnpolygonsoverlay = new GMapOverlay("drawnpolygons");
MainMap.Overlays.Add(drawnpolygonsoverlay);
MainMap.Overlays.Add(poioverlay);
top = new GMapOverlay("top");
//MainMap.Overlays.Add(top);
objectsoverlay.Markers.Clear();
// set current marker
currentMarker = new GMarkerGoogle(MainMap.Position, GMarkerGoogleType.red);
//top.Markers.Add(currentMarker);
// map center
center = new GMarkerGoogle(MainMap.Position, GMarkerGoogleType.none);
top.Markers.Add(center);
MainMap.Zoom = 3;
CMB_altmode.DisplayMember = "Value";
CMB_altmode.ValueMember = "Key";
CMB_altmode.DataSource = EnumTranslator.EnumToList<altmode>();
//set default
CMB_altmode.SelectedItem = altmode.Relative;
RegeneratePolygon();
updateCMDParams();
Up.Image = Resources.up;
Down.Image = Resources.down;
updateMapType(null, null);
// hide the map to prevent redraws when its loaded
panelMap.Visible = false;
/*
var timer = new System.Timers.Timer();
// 2 second
timer.Interval = 2000;
timer.Elapsed += updateMapType;
timer.Start();
*/
}
void updateMapType(object sender, System.Timers.ElapsedEventArgs e)
{
log.Info("updateMapType invoke req? " + comboBoxMapType.InvokeRequired);
if (sender is System.Timers.Timer)
((System.Timers.Timer)sender).Stop();
string mapType = Settings.Instance["MapType"];
if (!string.IsNullOrEmpty(mapType))
{
try
{
var index = GMapProviders.List.FindIndex(x => (x.Name == mapType));
if (index != -1)
comboBoxMapType.SelectedIndex = index;
}
catch
{
}
}
else
{
if (L10N.ConfigLang.IsChildOf(CultureInfo.GetCultureInfo("zh-Hans")))
{
CustomMessageBox.Show(
"亲爱的中国用户,为保证地图使用正常,已为您将默认地图自动切换到具有中国特色的【谷歌中国卫星地图】!\r\n与默认【谷歌卫星地图】的区别:使用.cn服务器,加入火星坐标修正\r\n如果您所在的地区仍然无法使用,天书同时推荐必应或高德地图,其它地图由于没有加入坐标修正功能,为确保飞行安全,请谨慎选择",
"默认地图已被切换");
try
{
var index = GMapProviders.List.FindIndex(x => (x.Name == "谷歌中国卫星地图"));
if (index != -1)
comboBoxMapType.SelectedIndex = index;
}
catch
{
}
}
else
{
mapType = "GoogleSatelliteMap";
// set default
try
{
var index = GMapProviders.List.FindIndex(x => (x.Name == mapType));
if (index != -1)
comboBoxMapType.SelectedIndex = index;
}
catch
{
}
}
}
}
void updateCMDParams()
{
cmdParamNames = readCMDXML();
List<string> cmds = new List<string>();
foreach (string item in cmdParamNames.Keys)
{
cmds.Add(item);
}
cmds.Add("UNKNOWN");
Command.DataSource = cmds;
}
Dictionary<string, string[]> readCMDXML()
{
Dictionary<string, string[]> cmd = new Dictionary<string, string[]>();
// do lang stuff here
string file = Settings.GetRunningDirectory() + "mavcmd.xml";
if (!File.Exists(file))
{
CustomMessageBox.Show("Missing mavcmd.xml file");
return cmd;
}
log.Info("Reading MAV_CMD for " + MainV2.comPort.MAV.cs.firmware);
using (XmlReader reader = XmlReader.Create(file))
{
reader.Read();
reader.ReadStartElement("CMD");
if (MainV2.comPort.MAV.cs.firmware == MainV2.Firmwares.ArduPlane ||
MainV2.comPort.MAV.cs.firmware == MainV2.Firmwares.Ateryx)
{
reader.ReadToFollowing("APM");
}
else if (MainV2.comPort.MAV.cs.firmware == MainV2.Firmwares.ArduRover)
{
reader.ReadToFollowing("APRover");
}
else
{
reader.ReadToFollowing("AC2");
}
XmlReader inner = reader.ReadSubtree();
inner.Read();
inner.MoveToElement();
inner.Read();
while (inner.Read())
{
inner.MoveToElement();
if (inner.IsStartElement())
{
string cmdname = inner.Name;
string[] cmdarray = new string[7];
int b = 0;
XmlReader inner2 = inner.ReadSubtree();
inner2.Read();
while (inner2.Read())
{
inner2.MoveToElement();
if (inner2.IsStartElement())
{
cmdarray[b] = inner2.ReadString();
b++;
}
}
cmd[cmdname] = cmdarray;
}
}
}
return cmd;
}
void Commands_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
log.Info(e.Exception + " " + e.Context + " col " + e.ColumnIndex);
e.Cancel = false;
e.ThrowException = false;
//throw new NotImplementedException();
}
/// <summary>
/// Adds a new row to the datagrid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BUT_Add_Click(object sender, EventArgs e)
{
if (Commands.CurrentRow == null)
{
selectedrow = 0;
}
else
{
selectedrow = Commands.CurrentRow.Index;
}
if (Commands.RowCount <= 1)
{
selectedrow = Commands.Rows.Add();
}
else
{
if (Commands.RowCount == selectedrow + 1)
{
DataGridViewRow temp = Commands.Rows[selectedrow];
selectedrow = Commands.Rows.Add();
}
else
{
Commands.Rows.Insert(selectedrow + 1, 1);
}
}
writeKML();
}
private void FlightPlanner_Load(object sender, EventArgs e)
{
quickadd = true;
Visible = false;
config(false);
quickadd = false;
POI.POIModified += POI_POIModified;
if (Settings.Instance["WMSserver"] != null)
WMSProvider.CustomWMSURL = Settings.Instance["WMSserver"];
trackBar1.Value = (int) MainMap.Zoom;
// check for net and set offline if needed
try
{
IPAddress[] addresslist = Dns.GetHostAddresses("www.google.com");
}
catch (Exception)
{
// here if dns failed
isonline = false;
}
// setup geofence
List<PointLatLng> polygonPoints = new List<PointLatLng>();
geofencepolygon = new GMapPolygon(polygonPoints, "geofence");
geofencepolygon.Stroke = new Pen(Color.Pink, 5);
geofencepolygon.Fill = Brushes.Transparent;
//setup drawnpolgon
List<PointLatLng> polygonPoints2 = new List<PointLatLng>();
drawnpolygon = new GMapPolygon(polygonPoints2, "drawnpoly");
drawnpolygon.Stroke = new Pen(Color.Red, 2);
drawnpolygon.Fill = Brushes.Transparent;
updateCMDParams();
panelMap.Visible = false;
// mono
panelMap.Dock = DockStyle.None;
panelMap.Dock = DockStyle.Fill;
panelMap_Resize(null, null);
//set home
try
{
if (TXT_homelat.Text != "")
{
MainMap.Position = new PointLatLng(double.Parse(TXT_homelat.Text), double.Parse(TXT_homelng.Text));
MainMap.Zoom = 16;
}
}
catch (Exception)
{
}
panelMap.Refresh();
panelMap.Visible = true;
writeKML();
// switch the action and wp table
if (Settings.Instance["FP_docking"] == "Bottom")
{
switchDockingToolStripMenuItem_Click(null, null);
}
Visible = true;
timer1.Start();
}
void POI_POIModified(object sender, EventArgs e)
{
POI.UpdateOverlay(poioverlay);
}
void parser_ElementAdded(object sender, ElementEventArgs e)
{
processKML(e.Element);
}
private void processKML(Element Element)
{
try
{
// log.Info(Element.ToString() + " " + Element.Parent);
}
catch
{
}
Document doc = Element as Document;
Placemark pm = Element as Placemark;
Folder folder = Element as Folder;
Polygon polygon = Element as Polygon;
LineString ls = Element as LineString;
if (doc != null)
{
foreach (var feat in doc.Features)
{
//Console.WriteLine("feat " + feat.GetType());
//processKML((Element)feat);
}
}
else if (folder != null)
{
foreach (Feature feat in folder.Features)
{
//Console.WriteLine("feat "+feat.GetType());
//processKML(feat);
}
}
else if (pm != null)
{
}
else if (polygon != null)
{
GMapPolygon kmlpolygon = new GMapPolygon(new List<PointLatLng>(), "kmlpolygon");
kmlpolygon.Stroke.Color = Color.Purple;
kmlpolygon.Fill = Brushes.Transparent;
foreach (var loc in polygon.OuterBoundary.LinearRing.Coordinates)
{
kmlpolygon.Points.Add(new PointLatLng(loc.Latitude, loc.Longitude));
}
kmlpolygonsoverlay.Polygons.Add(kmlpolygon);
}
else if (ls != null)
{
GMapRoute kmlroute = new GMapRoute(new List<PointLatLng>(), "kmlroute");
kmlroute.Stroke.Color = Color.Purple;
foreach (var loc in ls.Coordinates)
{
kmlroute.Points.Add(new PointLatLng(loc.Latitude, loc.Longitude));
}
kmlpolygonsoverlay.Routes.Add(kmlroute);
}
}
private void ChangeColumnHeader(string command)
{
try
{
if (cmdParamNames.ContainsKey(command))
for (int i = 1; i <= 7; i++)
Commands.Columns[i].HeaderText = cmdParamNames[command][i - 1];
else
for (int i = 1; i <= 7; i++)
Commands.Columns[i].HeaderText = "setme";
}
catch (Exception ex)
{