1 Star 0 Fork 0

mbdong/MissionPlanner

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Common.cs 35.39 KB
一键复制 编辑 原始数据 按行查看 历史
Michael Oborne 提交于 2016-03-13 13:07 . Common: rearrange code
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
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 AGaugeApp;
using System.IO.Ports;
using System.Threading;
using MissionPlanner.Attributes;
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 log4net;
using ZedGraph; // Graphs
using MissionPlanner;
using System.Reflection;
using MissionPlanner.Utilities;
using System.IO;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using ProjNet.CoordinateSystems.Transformations;
using ProjNet.CoordinateSystems;
namespace MissionPlanner
{
public class Common
{
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public enum distances
{
Meters,
Feet
}
public enum speeds
{
meters_per_second,
fps,
kph,
mph,
knots
}
/// <summary>
/// from libraries\AP_Math\rotations.h
/// </summary>
public enum Rotation
{
ROTATION_NONE = 0,
ROTATION_YAW_45,
ROTATION_YAW_90,
ROTATION_YAW_135,
ROTATION_YAW_180,
ROTATION_YAW_225,
ROTATION_YAW_270,
ROTATION_YAW_315,
ROTATION_ROLL_180,
ROTATION_ROLL_180_YAW_45,
ROTATION_ROLL_180_YAW_90,
ROTATION_ROLL_180_YAW_135,
ROTATION_PITCH_180,
ROTATION_ROLL_180_YAW_225,
ROTATION_ROLL_180_YAW_270,
ROTATION_ROLL_180_YAW_315,
ROTATION_ROLL_90,
ROTATION_ROLL_90_YAW_45,
ROTATION_ROLL_90_YAW_90,
ROTATION_ROLL_90_YAW_135,
ROTATION_ROLL_270,
ROTATION_ROLL_270_YAW_45,
ROTATION_ROLL_270_YAW_90,
ROTATION_ROLL_270_YAW_135,
ROTATION_PITCH_90,
ROTATION_PITCH_270,
ROTATION_MAX
}
public enum ap_product
{
[DisplayText("HIL")]
AP_PRODUCT_ID_NONE = 0x00, // Hardware in the loop
[DisplayText("APM1 1280")]
AP_PRODUCT_ID_APM1_1280 = 0x01, // APM1 with 1280 CPUs
[DisplayText("APM1 2560")]
AP_PRODUCT_ID_APM1_2560 = 0x02, // APM1 with 2560 CPUs
[DisplayText("SITL")]
AP_PRODUCT_ID_SITL = 0x03, // Software in the loop
[DisplayText("PX4")]
AP_PRODUCT_ID_PX4 = 0x04, // PX4 on NuttX
[DisplayText("PX4 FMU 2")]
AP_PRODUCT_ID_PX4_V2 = 0x05, // PX4 FMU2 on NuttX
[DisplayText("APM2 ES C4")]
AP_PRODUCT_ID_APM2ES_REV_C4 = 0x14, // APM2 with MPU6000ES_REV_C4
[DisplayText("APM2 ES C5")]
AP_PRODUCT_ID_APM2ES_REV_C5 = 0x15, // APM2 with MPU6000ES_REV_C5
[DisplayText("APM2 ES D6")]
AP_PRODUCT_ID_APM2ES_REV_D6 = 0x16, // APM2 with MPU6000ES_REV_D6
[DisplayText("APM2 ES D7")]
AP_PRODUCT_ID_APM2ES_REV_D7 = 0x17, // APM2 with MPU6000ES_REV_D7
[DisplayText("APM2 ES D8")]
AP_PRODUCT_ID_APM2ES_REV_D8 = 0x18, // APM2 with MPU6000ES_REV_D8
[DisplayText("APM2 C4")]
AP_PRODUCT_ID_APM2_REV_C4 = 0x54, // APM2 with MPU6000_REV_C4
[DisplayText("APM2 C5")]
AP_PRODUCT_ID_APM2_REV_C5 = 0x55, // APM2 with MPU6000_REV_C5
[DisplayText("APM2 D6")]
AP_PRODUCT_ID_APM2_REV_D6 = 0x56, // APM2 with MPU6000_REV_D6
[DisplayText("APM2 D7")]
AP_PRODUCT_ID_APM2_REV_D7 = 0x57, // APM2 with MPU6000_REV_D7
[DisplayText("APM2 D8")]
AP_PRODUCT_ID_APM2_REV_D8 = 0x58, // APM2 with MPU6000_REV_D8
[DisplayText("APM2 D9")]
AP_PRODUCT_ID_APM2_REV_D9 = 0x59, // APM2 with MPU6000_REV_D9
[DisplayText("FlyMaple")]
AP_PRODUCT_ID_FLYMAPLE = 0x100, // Flymaple with ITG3205, ADXL345, HMC5883, BMP085
[DisplayText("Linux")]
AP_PRODUCT_ID_L3G4200D = 0x101, // Linux with L3G4200D and ADXL345
}
public static bool getFilefromNet(string url, string saveto)
{
try
{
// this is for mono to a ssl server
//ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy();
ServicePointManager.ServerCertificateValidationCallback =
new System.Net.Security.RemoteCertificateValidationCallback(
(sender, certificate, chain, policyErrors) => { return true; });
log.Info(url);
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create(url);
request.Timeout = 10000;
// Set the Method property of the request to POST.
request.Method = "GET";
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
log.Info(((HttpWebResponse)response).StatusDescription);
if (((HttpWebResponse)response).StatusCode != HttpStatusCode.OK)
return false;
if (File.Exists(saveto))
{
DateTime lastfilewrite = new FileInfo(saveto).LastWriteTime;
DateTime lasthttpmod = ((HttpWebResponse)response).LastModified;
if (lasthttpmod < lastfilewrite)
{
if (((HttpWebResponse)response).ContentLength == new FileInfo(saveto).Length)
{
log.Info("got LastModified " + saveto + " " + ((HttpWebResponse)response).LastModified +
" vs " + new FileInfo(saveto).LastWriteTime);
response.Close();
return true;
}
}
}
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
long bytes = response.ContentLength;
long contlen = bytes;
byte[] buf1 = new byte[1024];
if (!Directory.Exists(Path.GetDirectoryName(saveto)))
Directory.CreateDirectory(Path.GetDirectoryName(saveto));
FileStream fs = new FileStream(saveto + ".new", FileMode.Create);
DateTime dt = DateTime.Now;
while (dataStream.CanRead && bytes > 0)
{
Application.DoEvents();
log.Debug(saveto + " " + bytes);
int len = dataStream.Read(buf1, 0, buf1.Length);
bytes -= len;
fs.Write(buf1, 0, len);
}
fs.Close();
dataStream.Close();
response.Close();
File.Delete(saveto);
File.Move(saveto + ".new", saveto);
return true;
}
catch (Exception ex)
{
log.Info("getFilefromNet(): " + ex.ToString());
return false;
}
}
//from px4firmwareplugin.cc
enum PX4_CUSTOM_MAIN_MODE
{
PX4_CUSTOM_MAIN_MODE_MANUAL = 1,
PX4_CUSTOM_MAIN_MODE_ALTCTL,
PX4_CUSTOM_MAIN_MODE_POSCTL,
PX4_CUSTOM_MAIN_MODE_AUTO,
PX4_CUSTOM_MAIN_MODE_ACRO,
PX4_CUSTOM_MAIN_MODE_OFFBOARD,
PX4_CUSTOM_MAIN_MODE_STABILIZED,
PX4_CUSTOM_MAIN_MODE_RATTITUDE
}
enum PX4_CUSTOM_SUB_MODE_AUTO
{
PX4_CUSTOM_SUB_MODE_AUTO_READY = 1,
PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF,
PX4_CUSTOM_SUB_MODE_AUTO_LOITER,
PX4_CUSTOM_SUB_MODE_AUTO_MISSION,
PX4_CUSTOM_SUB_MODE_AUTO_RTL,
PX4_CUSTOM_SUB_MODE_AUTO_LAND,
PX4_CUSTOM_SUB_MODE_AUTO_RTGS
}
public static List<KeyValuePair<int, string>> getModesList(CurrentState cs)
{
log.Info("getModesList Called");
if (cs.firmware == MainV2.Firmwares.PX4)
{
/*
union px4_custom_mode {
struct {
uint16_t reserved;
uint8_t main_mode;
uint8_t sub_mode;
};
uint32_t data;
float data_float;
};
*/
var temp = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_MANUAL << 16, "Manual"),
new KeyValuePair<int, string>((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_ACRO << 16, "Acro"),
new KeyValuePair<int, string>((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_STABILIZED << 16,
"Stabalized"),
new KeyValuePair<int, string>((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_RATTITUDE << 16,
"Rattitude"),
new KeyValuePair<int, string>((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_ALTCTL << 16,
"Altitude Control"),
new KeyValuePair<int, string>((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_POSCTL << 16,
"Position Control"),
new KeyValuePair<int, string>((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_OFFBOARD << 16,
"Offboard Control"),
new KeyValuePair<int, string>(
((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_AUTO << 16) +
(int) PX4_CUSTOM_SUB_MODE_AUTO.PX4_CUSTOM_SUB_MODE_AUTO_READY << 24, "Auto: Ready"),
new KeyValuePair<int, string>(
((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_AUTO << 16) +
(int) PX4_CUSTOM_SUB_MODE_AUTO.PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF << 24, "Auto: Takeoff"),
new KeyValuePair<int, string>(
((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_AUTO << 16) +
(int) PX4_CUSTOM_SUB_MODE_AUTO.PX4_CUSTOM_SUB_MODE_AUTO_LOITER << 24, "Loiter"),
new KeyValuePair<int, string>(
((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_AUTO << 16) +
(int) PX4_CUSTOM_SUB_MODE_AUTO.PX4_CUSTOM_SUB_MODE_AUTO_MISSION << 24, "Auto"),
new KeyValuePair<int, string>(
((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_AUTO << 16) +
(int) PX4_CUSTOM_SUB_MODE_AUTO.PX4_CUSTOM_SUB_MODE_AUTO_RTL << 24, "RTL"),
new KeyValuePair<int, string>(
((int) PX4_CUSTOM_MAIN_MODE.PX4_CUSTOM_MAIN_MODE_AUTO << 16) +
(int) PX4_CUSTOM_SUB_MODE_AUTO.PX4_CUSTOM_SUB_MODE_AUTO_LAND << 24, "Auto: Landing")
};
return temp;
}
else if (cs.firmware == MainV2.Firmwares.ArduPlane)
{
var flightModes = Utilities.ParameterMetaDataRepository.GetParameterOptionsInt("FLTMODE1",
cs.firmware.ToString());
flightModes.Add(new KeyValuePair<int, string>(16, "INITIALISING"));
flightModes.Add(new KeyValuePair<int, string>(17, "QStabilize"));
flightModes.Add(new KeyValuePair<int, string>(18, "QHover"));
flightModes.Add(new KeyValuePair<int, string>(19, "QLoiter"));
flightModes.Add(new KeyValuePair<int, string>(20, "QLand"));
return flightModes;
}
else if (cs.firmware == MainV2.Firmwares.Ateryx)
{
var flightModes = Utilities.ParameterMetaDataRepository.GetParameterOptionsInt("FLTMODE1",
cs.firmware.ToString()); //same as apm
return flightModes;
}
else if (cs.firmware == MainV2.Firmwares.ArduCopter2)
{
var flightModes = Utilities.ParameterMetaDataRepository.GetParameterOptionsInt("FLTMODE1",
cs.firmware.ToString());
return flightModes;
}
else if (cs.firmware == MainV2.Firmwares.ArduRover)
{
var flightModes = Utilities.ParameterMetaDataRepository.GetParameterOptionsInt("MODE1",
cs.firmware.ToString());
return flightModes;
}
else if (cs.firmware == MainV2.Firmwares.ArduTracker)
{
var temp = new List<KeyValuePair<int, string>>();
temp.Add(new KeyValuePair<int, string>(0, "MANUAL"));
temp.Add(new KeyValuePair<int, string>(1, "STOP"));
temp.Add(new KeyValuePair<int, string>(2, "SCAN"));
temp.Add(new KeyValuePair<int, string>(3, "SERVO_TEST"));
temp.Add(new KeyValuePair<int, string>(10, "AUTO"));
temp.Add(new KeyValuePair<int, string>(16, "INITIALISING"));
return temp;
}
return null;
}
public static Form LoadingBox(string title, string promptText)
{
Form form = new Form();
System.Windows.Forms.Label label = new System.Windows.Forms.Label();
System.ComponentModel.ComponentResourceManager resources =
new System.ComponentModel.ComponentResourceManager(typeof(MainV2));
form.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
form.Text = title;
label.Text = promptText;
label.SetBounds(9, 50, 372, 13);
label.AutoSize = true;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
ThemeManager.ApplyThemeTo(form);
form.Show();
form.Refresh();
label.Refresh();
Application.DoEvents();
return form;
}
public static DialogResult MessageShowAgain(string title, string promptText)
{
Form form = new Form();
System.Windows.Forms.Label label = new System.Windows.Forms.Label();
CheckBox chk = new CheckBox();
Controls.MyButton buttonOk = new Controls.MyButton();
System.ComponentModel.ComponentResourceManager resources =
new System.ComponentModel.ComponentResourceManager(typeof(MainV2));
form.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
form.Text = title;
label.Text = promptText;
chk.Tag = ("SHOWAGAIN_" + title.Replace(" ", "_").Replace('+', '_'));
chk.AutoSize = true;
chk.Text = Strings.ShowMeAgain;
chk.Checked = true;
chk.Location = new Point(9, 80);
if (Settings.Instance.GetBoolean((string)chk.Tag) == false)
// skip it
{
form.Dispose();
chk.Dispose();
buttonOk.Dispose();
label.Dispose();
return DialogResult.OK;
}
chk.CheckStateChanged += new EventHandler(chk_CheckStateChanged);
buttonOk.Text = Strings.OK;
buttonOk.DialogResult = DialogResult.OK;
buttonOk.Location = new Point(form.Right - 100, 80);
label.SetBounds(9, 40, 372, 13);
label.AutoSize = true;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, chk, buttonOk });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
ThemeManager.ApplyThemeTo(form);
DialogResult dialogResult = form.ShowDialog();
form.Dispose();
form = null;
return dialogResult;
}
static void chk_CheckStateChanged(object sender, EventArgs e)
{
Settings.Instance[(string)((CheckBox)(sender)).Tag] = ((CheckBox)(sender)).Checked.ToString();
}
public static string speechConversion(string input)
{
if (MainV2.comPort.MAV.cs.wpno == 0)
{
input = input.Replace("{wpn}", "Home");
}
else
{
input = input.Replace("{wpn}", MainV2.comPort.MAV.cs.wpno.ToString());
}
input = input.Replace("{asp}", MainV2.comPort.MAV.cs.airspeed.ToString("0"));
input = input.Replace("{alt}", MainV2.comPort.MAV.cs.alt.ToString("0"));
input = input.Replace("{wpa}", MainV2.comPort.MAV.cs.targetalt.ToString("0"));
input = input.Replace("{gsp}", MainV2.comPort.MAV.cs.groundspeed.ToString("0"));
input = input.Replace("{mode}", MainV2.comPort.MAV.cs.mode.ToString());
input = input.Replace("{batv}", MainV2.comPort.MAV.cs.battery_voltage.ToString("0.00"));
input = input.Replace("{batp}", (MainV2.comPort.MAV.cs.battery_remaining).ToString("0"));
input = input.Replace("{vsp}", (MainV2.comPort.MAV.cs.verticalspeed).ToString("0.0"));
input = input.Replace("{curr}", (MainV2.comPort.MAV.cs.current).ToString("0.0"));
input = input.Replace("{hdop}", (MainV2.comPort.MAV.cs.gpshdop).ToString("0.00"));
input = input.Replace("{satcount}", (MainV2.comPort.MAV.cs.satcount).ToString("0"));
input = input.Replace("{rssi}", (MainV2.comPort.MAV.cs.rssi).ToString("0"));
input = input.Replace("{disthome}", (MainV2.comPort.MAV.cs.DistToHome).ToString("0"));
input = input.Replace("{timeinair}",
(new TimeSpan(0, 0, 0, (int)MainV2.comPort.MAV.cs.timeInAir)).ToString());
return input;
}
}
/// <summary>
/// used to override the drawing of the waypoint box bounding
/// </summary>
[Serializable]
public class GMapMarkerRect : GMapMarker
{
public Pen Pen = new Pen(Brushes.White, 2);
public Color Color
{
get { return Pen.Color; }
set
{
if (!initcolor.HasValue) initcolor = value;
Pen.Color = value;
}
}
Color? initcolor = null;
public GMapMarker InnerMarker;
public int wprad = 0;
public void ResetColor()
{
if (initcolor.HasValue)
Color = initcolor.Value;
else
Color = Color.White;
}
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 || Overlay.Control == null)
return;
// if we have drawn it, then keep that color
if (!initcolor.HasValue)
Color = Color.White;
// undo autochange in mouse over
//if (Pen.Color == Color.Blue)
// Pen.Color = Color.White;
double width =
(Overlay.Control.MapProvider.Projection.GetDistance(Overlay.Control.FromLocalToLatLng(0, 0),
Overlay.Control.FromLocalToLatLng(Overlay.Control.Width, 0))*1000.0);
double height =
(Overlay.Control.MapProvider.Projection.GetDistance(Overlay.Control.FromLocalToLatLng(0, 0),
Overlay.Control.FromLocalToLatLng(Overlay.Control.Height, 0))*1000.0);
double m2pixelwidth = Overlay.Control.Width/width;
double m2pixelheight = Overlay.Control.Height/height;
GPoint loc = new GPoint((int) (LocalPosition.X - (m2pixelwidth*wprad*2)), LocalPosition.Y);
// MainMap.FromLatLngToLocal(wpradposition);
if (m2pixelheight > 0.5)
g.DrawArc(Pen,
new System.Drawing.Rectangle(
LocalPosition.X - Offset.X - (int) (Math.Abs(loc.X - LocalPosition.X)/2),
LocalPosition.Y - Offset.Y - (int) Math.Abs(loc.X - LocalPosition.X)/2,
(int) Math.Abs(loc.X - LocalPosition.X), (int) Math.Abs(loc.X - LocalPosition.X)), 0, 360);
}
}
[Serializable]
public class GMapMarkerADSBPlane : GMapMarker
{
const float rad2deg = (float) (180/Math.PI);
const float deg2rad = (float) (1.0/rad2deg);
private readonly Bitmap icon = global::MissionPlanner.Properties.Resources.FW_icons_2013_logos_01;
float heading = 0;
public GMapMarkerADSBPlane(PointLatLng p, float heading)
: base(p)
{
icon = new Bitmap(icon, new Size(40, 40));
this.heading = heading;
Size = icon.Size;
}
public override void OnRender(Graphics g)
{
Matrix temp = g.Transform;
g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
g.RotateTransform(-Overlay.Control.Bearing);
try
{
g.RotateTransform(heading);
}
catch
{
}
g.DrawImageUnscaled(icon, icon.Width/-2, icon.Height/-2);
g.Transform = temp;
}
}
[Serializable]
public class GMapMarkerWP : GMarkerGoogle
{
string wpno = "";
public bool selected = false;
SizeF txtsize = SizeF.Empty;
static Dictionary<string, Bitmap> fontBitmaps = new Dictionary<string, Bitmap>();
static Font font;
public GMapMarkerWP(PointLatLng p, string wpno)
: base(p, GMarkerGoogleType.green)
{
this.wpno = wpno;
if (font == null)
font = SystemFonts.DefaultFont;
if (!fontBitmaps.ContainsKey(wpno))
{
Bitmap temp = new Bitmap(100,40, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(temp))
{
txtsize = g.MeasureString(wpno, font);
g.DrawString(wpno, font, Brushes.Black, new PointF(0, 0));
}
fontBitmaps[wpno] = temp;
}
}
public override void OnRender(Graphics g)
{
if (selected)
{
g.FillEllipse(Brushes.Red, new Rectangle(this.LocalPosition, this.Size));
g.DrawArc(Pens.Red, new Rectangle(this.LocalPosition, this.Size), 0, 360);
}
base.OnRender(g);
var midw = LocalPosition.X + 10;
var midh = LocalPosition.Y + 3;
if (txtsize.Width > 15)
midw -= 4;
if (Overlay.Control.Zoom> 16 || IsMouseOver)
g.DrawImageUnscaled(fontBitmaps[wpno], midw,midh);
}
}
[Serializable]
public class GMapMarkerRover : 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::MissionPlanner.Properties.Resources.rover.Width,
global::MissionPlanner.Properties.Resources.rover.Height);
float heading = 0;
float cog = -1;
float target = -1;
float nav_bearing = -1;
public GMapMarkerRover(PointLatLng p, float heading, float cog, float nav_bearing, float target)
: base(p)
{
this.heading = heading;
this.cog = cog;
this.target = target;
this.nav_bearing = nav_bearing;
Size = SizeSt;
}
public override void OnRender(Graphics g)
{
Matrix temp = g.Transform;
g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
g.RotateTransform(-Overlay.Control.Bearing);
int length = 500;
// anti NaN
try
{
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);
}
catch
{
}
g.DrawLine(new Pen(Color.Green, 2), 0.0f, 0.0f, (float) Math.Cos((nav_bearing - 90)*deg2rad)*length,
(float) Math.Sin((nav_bearing - 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
try
{
g.RotateTransform(heading);
}
catch
{
}
g.DrawImageUnscaled(global::MissionPlanner.Properties.Resources.rover,
global::MissionPlanner.Properties.Resources.rover.Width/-2,
global::MissionPlanner.Properties.Resources.rover.Height/-2);
g.Transform = temp;
}
}
[Serializable]
public class GMapMarkerPlane : GMapMarker
{
const float rad2deg = (float) (180/Math.PI);
const float deg2rad = (float) (1.0/rad2deg);
private readonly Bitmap icon = global::MissionPlanner.Properties.Resources.planeicon;
float heading = 0;
float cog = -1;
float target = -1;
float nav_bearing = -1;
float radius = -1;
public GMapMarkerPlane(PointLatLng p, float heading, float cog, float nav_bearing, float target, float radius)
: base(p)
{
this.heading = heading;
this.cog = cog;
this.target = target;
this.nav_bearing = nav_bearing;
this.radius = radius;
Size = icon.Size;
}
public override void OnRender(Graphics g)
{
Matrix temp = g.Transform;
g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
g.RotateTransform(-Overlay.Control.Bearing);
int length = 500;
// anti NaN
try
{
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);
}
catch
{
}
g.DrawLine(new Pen(Color.Green, 2), 0.0f, 0.0f, (float) Math.Cos((nav_bearing - 90)*deg2rad)*length,
(float) Math.Sin((nav_bearing - 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
try
{
float desired_lead_dist = 100;
double width =
(Overlay.Control.MapProvider.Projection.GetDistance(Overlay.Control.FromLocalToLatLng(0, 0),
Overlay.Control.FromLocalToLatLng(Overlay.Control.Width, 0))*1000.0);
double m2pixelwidth = Overlay.Control.Width/width;
float alpha = ((desired_lead_dist * (float)m2pixelwidth) / radius) * rad2deg;
if (radius < -1)
{
// fixme
float p1 = (float)Math.Cos((cog) * deg2rad) * radius + radius;
float p2 = (float)Math.Sin((cog) * deg2rad) * radius + radius;
g.DrawArc(new Pen(Color.HotPink, 2), p1, p2, Math.Abs(radius) * 2, Math.Abs(radius) * 2, cog, alpha);
}
else if (radius > 1)
{
// correct
float p1 = (float)Math.Cos((cog - 180) * deg2rad) * radius + radius;
float p2 = (float)Math.Sin((cog - 180) * deg2rad) * radius + radius;
g.DrawArc(new Pen(Color.HotPink, 2), -p1, -p2, radius * 2, radius * 2, cog - 180, alpha);
}
}
catch
{
}
try
{
g.RotateTransform(heading);
}
catch
{
}
g.DrawImageUnscaled(icon, icon.Width/-2, icon.Height/-2);
g.Transform = temp;
}
}
[Serializable]
public class GMapMarkerQuad : GMapMarker
{
const float rad2deg = (float) (180/Math.PI);
const float deg2rad = (float) (1.0/rad2deg);
private readonly Bitmap icon = global::MissionPlanner.Properties.Resources.quadicon;
float heading = 0;
float cog = -1;
float target = -1;
private int sysid = -1;
public GMapMarkerQuad(PointLatLng p, float heading, float cog, float target, int sysid)
: base(p)
{
this.heading = heading;
this.cog = cog;
this.target = target;
this.sysid = sysid;
Size = icon.Size;
}
public override void OnRender(Graphics g)
{
Matrix temp = g.Transform;
g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
int length = 500;
// anti NaN
try
{
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);
}
catch
{
}
//g.DrawLine(new Pen(Color.Green, 2), 0.0f, 0.0f, (float)Math.Cos((nav_bearing - 90) * deg2rad) * length, (float)Math.Sin((nav_bearing - 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
try
{
g.RotateTransform(heading);
}
catch
{
}
g.DrawImageUnscaled(icon, icon.Width/-2 + 2, icon.Height/-2);
g.DrawString(sysid.ToString(), new Font(FontFamily.GenericMonospace, 15, FontStyle.Bold), Brushes.Red, -8,
-8);
g.Transform = temp;
}
}
[Serializable]
public class GMapMarkerHeli : GMapMarker
{
const float rad2deg = (float) (180/Math.PI);
const float deg2rad = (float) (1.0/rad2deg);
private readonly Bitmap icon = global::MissionPlanner.Properties.Resources.heli;
float heading = 0;
float cog = -1;
float target = -1;
public GMapMarkerHeli(PointLatLng p, float heading, float cog, float target)
: base(p)
{
this.heading = heading;
this.cog = cog;
this.target = target;
Size = icon.Size;
}
public override void OnRender(Graphics g)
{
Matrix temp = g.Transform;
g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
int length = 500;
// anti NaN
try
{
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);
}
catch
{
}
//g.DrawLine(new Pen(Color.Green, 2), 0.0f, 0.0f, (float)Math.Cos((nav_bearing - 90) * deg2rad) * length, (float)Math.Sin((nav_bearing - 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
try
{
g.RotateTransform(heading);
}
catch
{
}
g.DrawImageUnscaled(icon, icon.Width/-2 + 2, icon.Height/-2);
g.Transform = temp;
}
}
[Serializable]
public class GMapMarkerAntennaTracker : GMapMarker
{
const float rad2deg = (float) (180/Math.PI);
const float deg2rad = (float) (1.0/rad2deg);
private readonly Bitmap icon = global::MissionPlanner.Properties.Resources.Antenna_Tracker_01;
float heading = 0;
private float target = 0;
public GMapMarkerAntennaTracker(PointLatLng p, float heading, float target)
: base(p)
{
Size = icon.Size;
this.heading = heading;
this.target = target;
}
public override void OnRender(Graphics g)
{
Matrix temp = g.Transform;
g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
int length = 500;
try
{
// heading
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);
// target
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);
}
catch
{
}
g.DrawImage(icon, -20, -20, 40, 40);
g.Transform = temp;
}
}
class NoCheckCertificatePolicy : ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request,
int certificateProblem)
{
return true;
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mbdong/MissionPlanner.git
git@gitee.com:mbdong/MissionPlanner.git
mbdong
MissionPlanner
MissionPlanner
master

搜索帮助