diff --git a/Controls/PropagationSettings.cs b/Controls/PropagationSettings.cs index 9a482c86bc..c7e101eefa 100644 --- a/Controls/PropagationSettings.cs +++ b/Controls/PropagationSettings.cs @@ -34,6 +34,7 @@ public class PropagationSettings : Form private Label label1; private CheckBox chk_setalt; private Label label3; + private CheckBox chk_showscale; private CheckBox chk_ele; public PropagationSettings() @@ -52,6 +53,8 @@ public PropagationSettings() NUM_min.Value = (decimal)Settings.Instance.GetFloat("Propagation_Minalt", 100.0f); NUM_max.Value = (decimal)Settings.Instance.GetFloat("Propagation_Maxalt", 400.0f); + chk_showscale.Checked = Maps.Propagation.showScale; + chk_ele.Checked = Maps.Propagation.ele_run; chk_terrain.Checked = Maps.Propagation.ter_run; chk_rf.Checked = Maps.Propagation.rf_run; @@ -69,15 +72,17 @@ private void InitializeComponent() this.chk_dronedist = new System.Windows.Forms.CheckBox(); this.chk_homedist = new System.Windows.Forms.CheckBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.chk_showscale = new System.Windows.Forms.CheckBox(); + this.label3 = new System.Windows.Forms.Label(); this.NUM_max = new System.Windows.Forms.NumericUpDown(); - this.label2 = new System.Windows.Forms.Label(); - this.NUM_min = new System.Windows.Forms.NumericUpDown(); - this.label1 = new System.Windows.Forms.Label(); this.label91 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); this.label89 = new System.Windows.Forms.Label(); this.Clearance = new System.Windows.Forms.NumericUpDown(); + this.NUM_min = new System.Windows.Forms.NumericUpDown(); this.label100 = new System.Windows.Forms.Label(); this.label113 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); this.label109 = new System.Windows.Forms.Label(); this.CMB_Rotational = new System.Windows.Forms.ComboBox(); this.label90 = new System.Windows.Forms.Label(); @@ -91,63 +96,63 @@ private void InitializeComponent() this.label114 = new System.Windows.Forms.Label(); this.Tolerance = new System.Windows.Forms.NumericUpDown(); this.chk_setalt = new System.Windows.Forms.CheckBox(); - this.label3 = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.NUM_max)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.NUM_min)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.Clearance)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUM_min)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUM_range)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUM_height)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.Tolerance)).BeginInit(); this.SuspendLayout(); - // + // // chk_ele - // + // resources.ApplyResources(this.chk_ele, "chk_ele"); this.chk_ele.Checked = true; this.chk_ele.CheckState = System.Windows.Forms.CheckState.Indeterminate; this.chk_ele.Name = "chk_ele"; this.chk_ele.UseVisualStyleBackColor = true; this.chk_ele.CheckedChanged += new System.EventHandler(this.chk_ele_CheckedChanged); - // + // // chk_terrain - // + // resources.ApplyResources(this.chk_terrain, "chk_terrain"); this.chk_terrain.Checked = true; this.chk_terrain.CheckState = System.Windows.Forms.CheckState.Indeterminate; this.chk_terrain.Name = "chk_terrain"; this.chk_terrain.UseVisualStyleBackColor = true; this.chk_terrain.CheckedChanged += new System.EventHandler(this.chk_terrain_CheckedChanged); - // + // // chk_rf - // + // resources.ApplyResources(this.chk_rf, "chk_rf"); this.chk_rf.Checked = true; this.chk_rf.CheckState = System.Windows.Forms.CheckState.Indeterminate; this.chk_rf.Name = "chk_rf"; this.chk_rf.UseVisualStyleBackColor = true; this.chk_rf.CheckedChanged += new System.EventHandler(this.chk_rf_CheckedChanged); - // + // // chk_dronedist - // + // resources.ApplyResources(this.chk_dronedist, "chk_dronedist"); this.chk_dronedist.Checked = true; this.chk_dronedist.CheckState = System.Windows.Forms.CheckState.Indeterminate; this.chk_dronedist.Name = "chk_dronedist"; this.chk_dronedist.UseVisualStyleBackColor = true; this.chk_dronedist.CheckedChanged += new System.EventHandler(this.chk_dronedist_CheckedChanged); - // + // // chk_homedist - // + // resources.ApplyResources(this.chk_homedist, "chk_homedist"); this.chk_homedist.Checked = true; this.chk_homedist.CheckState = System.Windows.Forms.CheckState.Indeterminate; this.chk_homedist.Name = "chk_homedist"; this.chk_homedist.UseVisualStyleBackColor = true; this.chk_homedist.CheckedChanged += new System.EventHandler(this.chk_homedist_CheckedChanged); - // + // // groupBox1 - // + // + this.groupBox1.Controls.Add(this.chk_showscale); this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.NUM_max); this.groupBox1.Controls.Add(this.label91); @@ -173,9 +178,23 @@ private void InitializeComponent() resources.ApplyResources(this.groupBox1, "groupBox1"); this.groupBox1.Name = "groupBox1"; this.groupBox1.TabStop = false; - // + // + // cb_showscale + // + resources.ApplyResources(this.chk_showscale, "cb_showscale"); + this.chk_showscale.Checked = true; + this.chk_showscale.CheckState = System.Windows.Forms.CheckState.Indeterminate; + this.chk_showscale.Name = "cb_showscale"; + this.chk_showscale.UseVisualStyleBackColor = true; + this.chk_showscale.CheckedChanged += new System.EventHandler(this.chk_showscale_CheckedChanged); + // + // label3 + // + resources.ApplyResources(this.label3, "label3"); + this.label3.Name = "label3"; + // // NUM_max - // + // this.NUM_max.DecimalPlaces = 1; this.NUM_max.Increment = new decimal(new int[] { 1, @@ -190,46 +209,24 @@ private void InitializeComponent() 0}); this.NUM_max.Name = "NUM_max"; this.NUM_max.ValueChanged += new System.EventHandler(this.NUM_max_ValueChanged); - // - // label2 - // - resources.ApplyResources(this.label2, "label2"); - this.label2.Name = "label2"; - // - // NUM_min - // - this.NUM_min.DecimalPlaces = 1; - this.NUM_min.Increment = new decimal(new int[] { - 1, - 0, - 0, - 65536}); - resources.ApplyResources(this.NUM_min, "NUM_min"); - this.NUM_min.Maximum = new decimal(new int[] { - 2000, - 0, - 0, - 0}); - this.NUM_min.Name = "NUM_min"; - this.NUM_min.ValueChanged += new System.EventHandler(this.NUM_min_ValueChanged); - // - // label1 - // - resources.ApplyResources(this.label1, "label1"); - this.label1.Name = "label1"; - // + // // label91 - // + // resources.ApplyResources(this.label91, "label91"); this.label91.Name = "label91"; - // + // + // label2 + // + resources.ApplyResources(this.label2, "label2"); + this.label2.Name = "label2"; + // // label89 - // + // resources.ApplyResources(this.label89, "label89"); this.label89.Name = "label89"; - // + // // Clearance - // + // this.Clearance.DecimalPlaces = 1; this.Clearance.Increment = new decimal(new int[] { 1, @@ -244,24 +241,46 @@ private void InitializeComponent() 0}); this.Clearance.Name = "Clearance"; this.Clearance.ValueChanged += new System.EventHandler(this.Clearance_ValueChanged); - // + // + // NUM_min + // + this.NUM_min.DecimalPlaces = 1; + this.NUM_min.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + resources.ApplyResources(this.NUM_min, "NUM_min"); + this.NUM_min.Maximum = new decimal(new int[] { + 2000, + 0, + 0, + 0}); + this.NUM_min.Name = "NUM_min"; + this.NUM_min.ValueChanged += new System.EventHandler(this.NUM_min_ValueChanged); + // // label100 - // + // resources.ApplyResources(this.label100, "label100"); this.label100.Name = "label100"; - // + // // label113 - // + // resources.ApplyResources(this.label113, "label113"); this.label113.Name = "label113"; - // + // + // label1 + // + resources.ApplyResources(this.label1, "label1"); + this.label1.Name = "label1"; + // // label109 - // + // resources.ApplyResources(this.label109, "label109"); this.label109.Name = "label109"; - // + // // CMB_Rotational - // + // this.CMB_Rotational.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CMB_Rotational.FormattingEnabled = true; this.CMB_Rotational.Items.AddRange(new object[] { @@ -273,14 +292,14 @@ private void InitializeComponent() resources.ApplyResources(this.CMB_Rotational, "CMB_Rotational"); this.CMB_Rotational.Name = "CMB_Rotational"; this.CMB_Rotational.SelectedIndexChanged += new System.EventHandler(this.CMB_Rotational_SelectedIndexChanged); - // + // // label90 - // + // resources.ApplyResources(this.label90, "label90"); this.label90.Name = "label90"; - // + // // CMB_Resolution - // + // this.CMB_Resolution.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CMB_Resolution.FormattingEnabled = true; this.CMB_Resolution.Items.AddRange(new object[] { @@ -292,14 +311,14 @@ private void InitializeComponent() resources.ApplyResources(this.CMB_Resolution, "CMB_Resolution"); this.CMB_Resolution.Name = "CMB_Resolution"; this.CMB_Resolution.SelectedIndexChanged += new System.EventHandler(this.CMB_Resolution_SelectedIndexChanged); - // + // // label110 - // + // resources.ApplyResources(this.label110, "label110"); this.label110.Name = "label110"; - // + // // CMB_Angular - // + // this.CMB_Angular.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CMB_Angular.FormattingEnabled = true; this.CMB_Angular.Items.AddRange(new object[] { @@ -311,14 +330,14 @@ private void InitializeComponent() resources.ApplyResources(this.CMB_Angular, "CMB_Angular"); this.CMB_Angular.Name = "CMB_Angular"; this.CMB_Angular.SelectedIndexChanged += new System.EventHandler(this.CMB_Angular_SelectedIndexChanged); - // + // // label111 - // + // resources.ApplyResources(this.label111, "label111"); this.label111.Name = "label111"; - // + // // NUM_range - // + // this.NUM_range.DecimalPlaces = 1; this.NUM_range.Increment = new decimal(new int[] { 1, @@ -333,14 +352,14 @@ private void InitializeComponent() 0}); this.NUM_range.Name = "NUM_range"; this.NUM_range.ValueChanged += new System.EventHandler(this.NUM_range_ValueChanged); - // + // // label112 - // + // resources.ApplyResources(this.label112, "label112"); this.label112.Name = "label112"; - // + // // NUM_height - // + // this.NUM_height.DecimalPlaces = 1; this.NUM_height.Increment = new decimal(new int[] { 1, @@ -355,14 +374,14 @@ private void InitializeComponent() 0}); this.NUM_height.Name = "NUM_height"; this.NUM_height.ValueChanged += new System.EventHandler(this.NUM_height_ValueChanged); - // + // // label114 - // + // resources.ApplyResources(this.label114, "label114"); this.label114.Name = "label114"; - // + // // Tolerance - // + // this.Tolerance.DecimalPlaces = 1; this.Tolerance.Increment = new decimal(new int[] { 1, @@ -377,23 +396,18 @@ private void InitializeComponent() 0}); this.Tolerance.Name = "Tolerance"; this.Tolerance.ValueChanged += new System.EventHandler(this.Tolerance_ValueChanged); - // + // // chk_setalt - // + // resources.ApplyResources(this.chk_setalt, "chk_setalt"); this.chk_setalt.Checked = true; this.chk_setalt.CheckState = System.Windows.Forms.CheckState.Indeterminate; this.chk_setalt.Name = "chk_setalt"; this.chk_setalt.UseVisualStyleBackColor = true; this.chk_setalt.CheckedChanged += new System.EventHandler(this.chk_setalt_CheckedChanged); - // - // label3 - // - resources.ApplyResources(this.label3, "label3"); - this.label3.Name = "label3"; - // + // // PropagationSettings - // + // resources.ApplyResources(this, "$this"); this.Controls.Add(this.chk_setalt); this.Controls.Add(this.groupBox1); @@ -405,9 +419,10 @@ private void InitializeComponent() this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.Name = "PropagationSettings"; this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.NUM_max)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.NUM_min)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.Clearance)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUM_min)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUM_range)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUM_height)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.Tolerance)).EndInit(); @@ -416,6 +431,12 @@ private void InitializeComponent() } + private void chk_showscale_CheckedChanged(object sender, EventArgs e) + { + Maps.Propagation.showScale = chk_showscale.Checked; + Console.WriteLine("showScale: " + chk_showscale.Checked); + } + private void chk_ele_CheckedChanged(object sender, EventArgs e) { Maps.Propagation.ele_run = chk_ele.Checked; diff --git a/Controls/PropagationSettings.resx b/Controls/PropagationSettings.resx index d5bcabf01d..bec04ff170 100644 --- a/Controls/PropagationSettings.resx +++ b/Controls/PropagationSettings.resx @@ -126,7 +126,7 @@ 13, 13 - 71, 16 + 70, 17 0 @@ -153,7 +153,7 @@ 13, 36 - 60, 16 + 59, 17 1 @@ -180,7 +180,7 @@ 13, 59 - 64, 16 + 64, 17 2 @@ -207,7 +207,7 @@ 107, 36 - 103, 16 + 97, 17 3 @@ -234,7 +234,7 @@ 107, 13 - 102, 16 + 96, 17 4 @@ -254,7 +254,37 @@ 2 + + True + + + NoControl + + + 8, 22 + + + 83, 17 + + + 132 + + + Show Scale + + + cb_showscale + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 0 + NoControl @@ -280,13 +310,13 @@ groupBox1 - 0 + 1 317, 124 - 56, 19 + 56, 20 132 @@ -301,7 +331,7 @@ groupBox1 - 1 + 2 NoControl @@ -328,7 +358,7 @@ groupBox1 - 2 + 3 NoControl @@ -355,7 +385,7 @@ groupBox1 - 3 + 4 NoControl @@ -382,13 +412,13 @@ groupBox1 - 4 + 5 174, 19 - 56, 19 + 56, 20 120 @@ -403,13 +433,13 @@ groupBox1 - 5 + 6 174, 124 - 56, 19 + 56, 20 130 @@ -424,7 +454,7 @@ groupBox1 - 6 + 7 NoControl @@ -451,7 +481,7 @@ groupBox1 - 7 + 8 NoControl @@ -478,7 +508,7 @@ groupBox1 - 8 + 9 NoControl @@ -505,7 +535,7 @@ groupBox1 - 9 + 10 NoControl @@ -532,7 +562,7 @@ groupBox1 - 10 + 11 0.5 @@ -553,7 +583,7 @@ 174, 72 - 40, 20 + 40, 21 119 @@ -568,7 +598,7 @@ groupBox1 - 11 + 12 NoControl @@ -595,7 +625,7 @@ groupBox1 - 12 + 13 2 @@ -616,7 +646,7 @@ 174, 45 - 40, 20 + 40, 21 118 @@ -631,7 +661,7 @@ groupBox1 - 13 + 14 NoControl @@ -658,7 +688,7 @@ groupBox1 - 14 + 15 0 @@ -679,7 +709,7 @@ 317, 72 - 40, 20 + 40, 21 0 @@ -694,7 +724,7 @@ groupBox1 - 15 + 16 NoControl @@ -721,13 +751,13 @@ groupBox1 - 16 + 17 442, 73 - 56, 19 + 56, 20 121 @@ -742,7 +772,7 @@ groupBox1 - 17 + 18 NoControl @@ -769,13 +799,13 @@ groupBox1 - 18 + 19 601, 73 - 46, 19 + 46, 20 122 @@ -790,7 +820,7 @@ groupBox1 - 19 + 20 NoControl @@ -817,13 +847,13 @@ groupBox1 - 20 + 21 174, 99 - 56, 19 + 56, 20 123 @@ -838,7 +868,7 @@ groupBox1 - 21 + 22 13, 82 @@ -874,7 +904,7 @@ 107, 60 - 95, 16 + 86, 17 131 diff --git a/ExtLibs/Maps/GMapMarkerElevation.cs b/ExtLibs/Maps/GMapMarkerElevation.cs index 55ce173b8a..0c50b0323a 100644 --- a/ExtLibs/Maps/GMapMarkerElevation.cs +++ b/ExtLibs/Maps/GMapMarkerElevation.cs @@ -14,9 +14,13 @@ namespace MissionPlanner.Maps { public class GMapMarkerElevation : GMapMarker { - Bitmap elevation; - + Bitmap elevation; + private RectLatLng rect; + private bool showScale; + private int scaleHigh; + private int scaleLow; + private string scaleText; public GMapMarkerElevation(byte [,] imageData, int idx, int idy, RectLatLng rect, PointLatLng currentloc) : base(currentloc) @@ -27,7 +31,7 @@ public GMapMarkerElevation(byte [,] imageData, int idx, int idy, RectLatLng rect //create a new Bitmap Bitmap bmp = new Bitmap(idx,idy, PixelFormat.Format32bppArgb); - + //lock it to get the BitmapData Object BitmapData bmData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); @@ -44,7 +48,7 @@ public GMapMarkerElevation(byte [,] imageData, int idx, int idy, RectLatLng rect } //copy the bytes - System.Runtime.InteropServices.Marshal.Copy(pixels, 0, bmData.Scan0, (bmData.Stride/4) * bmData.Height); + System.Runtime.InteropServices.Marshal.Copy(pixels, 0, bmData.Scan0, (bmData.Stride/4) * bmData.Height); //never forget to unlock the bitmap bmp.UnlockBits(bmData); @@ -57,7 +61,7 @@ public GMapMarkerElevation(byte [,] imageData, int idx, int idy, RectLatLng rect static GMapMarkerElevation() { - var bmp = new Bitmap(1, 1, PixelFormat.Format8bppIndexed); + var bmp = new Bitmap(1, 1, PixelFormat.Format8bppIndexed); pal = bmp.Palette; //create grayscale palette for (int i = 0; i < 256; i++) @@ -100,17 +104,24 @@ public static Color Rainbow(float progress) int ConvertColor(byte incol) { if (incol == 0 || incol == 255) - return transparent; + return transparent; return pal.Entries[incol].ToArgb(); } + public void setScale(bool enabled, int high, int low, string text) + { + showScale = enabled; + scaleHigh = high; + scaleLow = low; + scaleText = text; + } public override void OnRender(IGraphics g) { base.OnRender(g); var tlll = Overlay.Control.FromLatLngToLocal(rect.LocationTopLeft); - var brll = Overlay.Control.FromLatLngToLocal(rect.LocationRightBottom); + var brll = Overlay.Control.FromLatLngToLocal(rect.LocationRightBottom); var old = g.Transform; @@ -119,8 +130,36 @@ public override void OnRender(IGraphics g) // maintain transperancy g.CompositingMode = CompositingMode.SourceOver; - g.DrawImage(elevation, tlll.X, tlll.Y, brll.X - tlll.X, brll.Y - tlll.Y); - + g.DrawImage(elevation, tlll.X, tlll.Y, brll.X - tlll.X, brll.Y - tlll.Y); + + if (showScale) + { + Bitmap test = new Bitmap(255, 20); + //fill the image with the rainbow palette + for (int i = 0; i < 255; i++) + { + using (Graphics g2 = Graphics.FromImage(test)) + { + + Color c = Color.FromArgb(255, Rainbow(i / 255.0f)); + g2.FillRectangle(new SolidBrush(c), i, 0, 1, 20); + } + } + //write the text "200" to the image + using (Graphics g2 = Graphics.FromImage(test)) + { + g2.DrawRectangle(new Pen(Color.Black), 0, 0, 255, 20); + g2.DrawString(scaleHigh.ToString() + "m", new Font("Arial", 8), new SolidBrush(Color.White), 1, 0); + int len = (int)g2.MeasureString(scaleLow.ToString() + "m", new Font("Arial", 8)).Width; + g2.DrawString(scaleLow.ToString() + "m", new Font("Arial", 8), new SolidBrush(Color.White), 255 - len + 2, 0); + //Write text at center + len = (int)g2.MeasureString(scaleText, new Font("Arial", 7)).Width; + g2.DrawString(scaleText, new Font("Arial", 7), new SolidBrush(Color.Black), 127 - len / 2, 0); + + } + + g.DrawImage(test, 0, 60, 300, 20); + } g.Transform = old; } } diff --git a/ExtLibs/Maps/Propagation.cs b/ExtLibs/Maps/Propagation.cs index 4b7e38b389..9b9bff1e05 100644 --- a/ExtLibs/Maps/Propagation.cs +++ b/ExtLibs/Maps/Propagation.cs @@ -82,7 +82,11 @@ public static bool set_alt_min_max get => Settings.Instance.GetBoolean("Propagation_Setalt"); set => Settings.Instance["Propagation_Setalt"] = value.ToString(); } - + public static bool showScale + { + get => Settings.Instance.GetBoolean("Propagation_ShowScale"); + set => Settings.Instance["Propagation_ShowScale"] = value.ToString(); + } //thread run public bool ele_enabled { get; set; } @@ -300,8 +304,8 @@ private async void elevation_calc() var tlfinal = gMapControl1.FromLatLngToLocal(imageDataRect.LocationTopLeft); var rbfinal = gMapControl1.FromLatLngToLocal(imageDataRect.LocationRightBottom); - - var gMapMarkerElevation = new GMapMarkerElevation(imageData, + + var gMapMarkerElevation = new GMapMarkerElevation(imageData, (int)Math.Min(rbfinal.X - tlfinal.X, imageData.GetLength(0)), (int)Math.Min(rbfinal.Y - tlfinal.Y, imageData.GetLength(1)), new RectLatLng(imageDataRect.LocationTopLeft, imageDataRect.Size), new PointLatLngAlt(imageDataCenter)); @@ -309,6 +313,9 @@ private async void elevation_calc() if (!ele_enabled) return; + if (ele_run) gMapMarkerElevation.setScale(showScale, 0, (int)Settings.Instance.GetFloat("Propagation_Clearance", 5),"Rel to Terrain"); + else if (ter_run) gMapMarkerElevation.setScale(showScale, (int)max_alt, (int)min_alt, "Elevation (AMSL)"); + try { gMapControl1.Invoke((Action) delegate @@ -409,7 +416,7 @@ private double normalize(double value) { normvalue = (value - min_alt) / (max_alt - min_alt); } - + if (normvalue < 0) normvalue = 0;