-
Notifications
You must be signed in to change notification settings - Fork 3
/
common.cs
245 lines (201 loc) · 7.82 KB
/
common.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using GMap.NET;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using System.Net.Sockets;
using System.Xml; // config file
using System.Runtime.InteropServices; // dll imports
using ZedGraph; // Graphs
using System.Reflection;
using System.IO;
using System.Drawing.Drawing2D;
namespace MultiWiiWinGUI
{
/// <summary>
/// Struct as used in Ardupilot
/// </summary>
public struct Locationwp
{
public byte id; // command id
public byte options;
public float p1; // param 1
public float p2; // param 2
public float p3; // param 3
public float p4; // param 4
public float lat; // Lattitude * 10**7
public float lng; // Longitude * 10**7
public float alt; // Altitude in centimeters (meters * 100)
};
/// <summary>
/// used to override the drawing of the waypoint box bounding
/// </summary>
public class GMapMarkerRect : GMapMarker
{
public Pen Pen = new Pen(Brushes.White, 2);
public Color Color { get { return Pen.Color; } set { Pen.Color = value; } }
public GMapMarker InnerMarker;
public int wprad = 0;
public GMapControl MainMap;
public GMapMarkerRect(PointLatLng p)
: base(p)
{
Pen.DashStyle = DashStyle.Dash;
// do not forget set Size of the marker
// if so, you shall have no event on it ;}
Size = new System.Drawing.Size(50, 50);
Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2 - 20);
}
public override void OnRender(Graphics g)
{
base.OnRender(g);
if (wprad == 0 || MainMap == null)
return;
// undo autochange in mouse over
if (Pen.Color == Color.Blue)
Pen.Color = Color.White;
double width = (MainMap.MapProvider.Projection.GetDistance(MainMap.FromLocalToLatLng(0, 0), MainMap.FromLocalToLatLng(MainMap.Width, 0)) * 1000.0);
double height = (MainMap.MapProvider.Projection.GetDistance(MainMap.FromLocalToLatLng(0, 0), MainMap.FromLocalToLatLng(MainMap.Height, 0)) * 1000.0);
double m2pixelwidth = MainMap.Width / width;
double m2pixelheight = MainMap.Height / height;
GPoint loc = new GPoint((int)(LocalPosition.X - (m2pixelwidth * wprad * 2)), LocalPosition.Y);// MainMap.FromLatLngToLocal(wpradposition);
g.DrawArc(Pen, new System.Drawing.Rectangle(LocalPosition.X - Offset.X - (Math.Abs(loc.X - LocalPosition.X) / 2), LocalPosition.Y - Offset.Y - Math.Abs(loc.X - LocalPosition.X) / 2, Math.Abs(loc.X - LocalPosition.X), Math.Abs(loc.X - LocalPosition.X)), 0, 360);
}
}
public class GMapMarkerQuad : GMapMarker
{
const float rad2deg = (float)(180 / Math.PI);
const float deg2rad = (float)(1.0 / rad2deg);
static readonly System.Drawing.Size SizeSt = new System.Drawing.Size(global::MultiWiiWinGUI.Properties.Resources.quadicon.Width, global::MultiWiiWinGUI.Properties.Resources.quadicon.Height);
float heading = 0;
float cog = -1;
float target = -1;
public GMapMarkerQuad(PointLatLng p, float heading, float cog, float target)
: base(p)
{
this.heading = heading;
this.cog = cog;
this.target = target;
Size = SizeSt;
}
public override void OnRender(Graphics g)
{
Matrix temp = g.Transform;
g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
Image pic = global::MultiWiiWinGUI.Properties.Resources.quadicon;
int length = 100;
// anti NaN
g.DrawLine(new Pen(Color.Red, 2), 0.0f, 0.0f, (float)Math.Cos((heading - 90) * deg2rad) * length, (float)Math.Sin((heading - 90) * deg2rad) * length);
//g.DrawLine(new Pen(Color.Black, 2), 0.0f, 0.0f, (float)Math.Cos((cog - 90) * deg2rad) * length, (float)Math.Sin((cog - 90) * deg2rad) * length);
//g.DrawLine(new Pen(Color.Orange, 2), 0.0f, 0.0f, (float)Math.Cos((target - 90) * deg2rad) * length, (float)Math.Sin((target - 90) * deg2rad) * length);
// anti NaN
g.RotateTransform(heading);
g.DrawImageUnscaled(pic,pic.Width / -2 -5 , pic.Height / -2 );
g.Transform = temp;
}
}
public class GMapMarkerHome : GMapMarker
{
static readonly System.Drawing.Size SizeSt = new System.Drawing.Size(global::MultiWiiWinGUI.Properties.Resources.quadicon.Width, global::MultiWiiWinGUI.Properties.Resources.quadicon.Height);
public GMapMarkerHome(PointLatLng p)
: base(p)
{
Size = SizeSt;
}
public override void OnRender(Graphics g)
{
Matrix temp = g.Transform;
g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
Image pic = global::MultiWiiWinGUI.Properties.Resources.home;
g.DrawImageUnscaled(pic, pic.Width / -2 - 7, -pic.Height-14);
g.Transform = temp;
}
}
public class PointLatLngAlt
{
public double Lat = 0;
public double Lng = 0;
public double Alt = 0;
public string Tag = "";
public Color color = Color.White;
public PointLatLngAlt(double lat, double lng, double alt, string tag)
{
this.Lat = lat;
this.Lng = lng;
this.Alt = alt;
this.Tag = tag;
}
public PointLatLngAlt()
{
}
public PointLatLngAlt(GMap.NET.PointLatLng pll)
{
this.Lat = pll.Lat;
this.Lng = pll.Lng;
}
public PointLatLngAlt(Locationwp locwp)
{
this.Lat = locwp.lat;
this.Lng = locwp.lng;
this.Alt = locwp.alt;
}
public PointLatLngAlt(PointLatLngAlt plla)
{
this.Lat = plla.Lat;
this.Lng = plla.Lng;
this.Alt = plla.Alt;
this.color = plla.color;
this.Tag = plla.Tag;
}
public PointLatLng Point()
{
return new PointLatLng(Lat, Lng);
}
public override bool Equals(Object pllaobj)
{
PointLatLngAlt plla = (PointLatLngAlt)pllaobj;
if (plla == null)
return false;
if (this.Lat == plla.Lat &&
this.Lng == plla.Lng &&
this.Alt == plla.Alt &&
this.color == plla.color &&
this.Tag == plla.Tag)
{
return true;
}
return false;
}
public override int GetHashCode()
{
return (int)((Lat + Lng + Alt) * 100);
}
/// <summary>
/// Calc Distance in M
/// </summary>
/// <param name="p2"></param>
/// <returns>Distance in M</returns>
public double GetDistance(PointLatLngAlt p2)
{
double d = Lat * 0.017453292519943295;
double num2 = Lng * 0.017453292519943295;
double num3 = p2.Lat * 0.017453292519943295;
double num4 = p2.Lng * 0.017453292519943295;
double num5 = num4 - num2;
double num6 = num3 - d;
double num7 = Math.Pow(Math.Sin(num6 / 2.0), 2.0) + ((Math.Cos(d) * Math.Cos(num3)) * Math.Pow(Math.Sin(num5 / 2.0), 2.0));
double num8 = 2.0 * Math.Atan2(Math.Sqrt(num7), Math.Sqrt(1.0 - num7));
return (6378.137 * num8) * 1000; // M
}
}
}