From 1db8637134af50c21cf76ec74c6034695821b701 Mon Sep 17 00:00:00 2001 From: Bob Long Date: Tue, 4 Jul 2023 11:52:45 -0400 Subject: [PATCH] QuickViewOptions: add more customization Can now customize - Display label - Color - Number-to-String format (including time formats) - Expected number width (for consistent font sizing) - Scale and offset The search capability of the combobox is entirely redone as well --- Controls/QuickViewOptions.Designer.cs | 273 +++++++++++++++++++-- Controls/QuickViewOptions.cs | 336 +++++++++++++++++++++++--- Controls/QuickViewOptions.resx | 3 + ExtLibs/ArduPilot/CurrentState.cs | 36 ++- ExtLibs/Controls/QuickView.cs | 33 ++- GCSViews/FlightData.cs | 86 +++---- 6 files changed, 665 insertions(+), 102 deletions(-) diff --git a/Controls/QuickViewOptions.Designer.cs b/Controls/QuickViewOptions.Designer.cs index d17fcb7a00..79c8592196 100644 --- a/Controls/QuickViewOptions.Designer.cs +++ b/Controls/QuickViewOptions.Designer.cs @@ -29,29 +29,48 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.CMB_Source = new System.Windows.Forms.ComboBox(); this.NUM_precision = new System.Windows.Forms.NumericUpDown(); this.LBL_precision = new System.Windows.Forms.Label(); this.CHK_customcolor = new System.Windows.Forms.CheckBox(); this.TXT_color = new System.Windows.Forms.TextBox(); this.BUT_colorpicker = new System.Windows.Forms.Button(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.CHK_customwidth = new System.Windows.Forms.CheckBox(); + this.NUM_customwidth = new System.Windows.Forms.NumericUpDown(); + this.CHK_customlabel = new System.Windows.Forms.CheckBox(); + this.TXT_customformat = new System.Windows.Forms.TextBox(); + this.TXT_customlabel = new System.Windows.Forms.TextBox(); + this.TXT_offset = new System.Windows.Forms.TextBox(); + this.TXT_scale = new System.Windows.Forms.TextBox(); + this.CHK_customformat = new System.Windows.Forms.CheckBox(); + this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); ((System.ComponentModel.ISupportInitialize)(this.NUM_precision)).BeginInit(); + this.groupBox1.SuspendLayout(); + this.tableLayoutPanel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.NUM_customwidth)).BeginInit(); this.SuspendLayout(); // // CMB_Source // - this.CMB_Source.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; - this.CMB_Source.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; + this.CMB_Source.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.CMB_Source.FormattingEnabled = true; this.CMB_Source.Location = new System.Drawing.Point(12, 12); this.CMB_Source.Name = "CMB_Source"; - this.CMB_Source.Size = new System.Drawing.Size(121, 21); + this.CMB_Source.Size = new System.Drawing.Size(153, 21); this.CMB_Source.TabIndex = 1; - this.CMB_Source.SelectedIndexChanged += new System.EventHandler(this.CMB_Source_SelectedIndexChanged); + this.CMB_Source.TextUpdate += new System.EventHandler(this.CMB_Source_TextUpdate); + this.CMB_Source.DropDownClosed += new System.EventHandler(this.CMB_Source_DropDownClosed); // // NUM_precision // - this.NUM_precision.Location = new System.Drawing.Point(197, 12); + this.NUM_precision.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.NUM_precision.Location = new System.Drawing.Point(229, 12); this.NUM_precision.Maximum = new decimal(new int[] { 7, 0, @@ -60,65 +79,274 @@ private void InitializeComponent() this.NUM_precision.Name = "NUM_precision"; this.NUM_precision.Size = new System.Drawing.Size(40, 20); this.NUM_precision.TabIndex = 3; + this.toolTip1.SetToolTip(this.NUM_precision, "How many decimal places to show"); + this.NUM_precision.Value = new decimal(new int[] { + 2, + 0, + 0, + 0}); this.NUM_precision.ValueChanged += new System.EventHandler(this.NUM_precision_ValueChanged); // // LBL_precision // + this.LBL_precision.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.LBL_precision.AutoSize = true; - this.LBL_precision.Location = new System.Drawing.Point(139, 15); + this.LBL_precision.Location = new System.Drawing.Point(171, 15); this.LBL_precision.Name = "LBL_precision"; this.LBL_precision.Size = new System.Drawing.Size(53, 13); this.LBL_precision.TabIndex = 4; this.LBL_precision.Text = "Precision:"; + this.toolTip1.SetToolTip(this.LBL_precision, "How many decimal places to show"); // // CHK_customcolor // + this.CHK_customcolor.Anchor = System.Windows.Forms.AnchorStyles.Left; this.CHK_customcolor.AutoSize = true; - this.CHK_customcolor.Location = new System.Drawing.Point(246, 14); + this.CHK_customcolor.Location = new System.Drawing.Point(3, 36); this.CHK_customcolor.Name = "CHK_customcolor"; this.CHK_customcolor.Size = new System.Drawing.Size(88, 17); this.CHK_customcolor.TabIndex = 5; this.CHK_customcolor.Text = "Custom Color"; + this.toolTip1.SetToolTip(this.CHK_customcolor, "Apply custom text color"); this.CHK_customcolor.UseVisualStyleBackColor = true; this.CHK_customcolor.CheckedChanged += new System.EventHandler(this.CHK_customcolor_CheckedChanged); // // TXT_color // + this.TXT_color.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.TXT_color.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.TXT_color.Location = new System.Drawing.Point(335, 15); + this.TXT_color.Location = new System.Drawing.Point(105, 38); this.TXT_color.Name = "TXT_color"; - this.TXT_color.Size = new System.Drawing.Size(54, 13); + this.TXT_color.Size = new System.Drawing.Size(118, 13); this.TXT_color.TabIndex = 6; this.TXT_color.Text = "FFFFFF"; this.TXT_color.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.toolTip1.SetToolTip(this.TXT_color, "Apply custom text color"); this.TXT_color.TextChanged += new System.EventHandler(this.TXT_color_TextChanged); // // BUT_colorpicker // + this.BUT_colorpicker.Anchor = System.Windows.Forms.AnchorStyles.Left; this.BUT_colorpicker.BackColor = System.Drawing.SystemColors.ActiveCaption; - this.BUT_colorpicker.Location = new System.Drawing.Point(400, 12); + this.BUT_colorpicker.Location = new System.Drawing.Point(229, 35); this.BUT_colorpicker.Name = "BUT_colorpicker"; - this.BUT_colorpicker.Size = new System.Drawing.Size(20, 20); + this.BUT_colorpicker.Size = new System.Drawing.Size(19, 20); this.BUT_colorpicker.TabIndex = 7; + this.toolTip1.SetToolTip(this.BUT_colorpicker, "Apply custom text color"); this.BUT_colorpicker.UseVisualStyleBackColor = false; this.BUT_colorpicker.Click += new System.EventHandler(this.BUT_colorpicker_Click); // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.tableLayoutPanel1); + this.groupBox1.Location = new System.Drawing.Point(12, 39); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(257, 200); + this.groupBox1.TabIndex = 8; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Advanced"; + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 3; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 4); + this.tableLayoutPanel1.Controls.Add(this.label2, 0, 5); + this.tableLayoutPanel1.Controls.Add(this.CHK_customwidth, 0, 3); + this.tableLayoutPanel1.Controls.Add(this.NUM_customwidth, 1, 3); + this.tableLayoutPanel1.Controls.Add(this.CHK_customcolor, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.TXT_color, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.BUT_colorpicker, 2, 1); + this.tableLayoutPanel1.Controls.Add(this.CHK_customlabel, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.TXT_customformat, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.TXT_customlabel, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.TXT_offset, 1, 5); + this.tableLayoutPanel1.Controls.Add(this.TXT_scale, 1, 4); + this.tableLayoutPanel1.Controls.Add(this.CHK_customformat, 0, 2); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 16); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 7; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(251, 181); + this.tableLayoutPanel1.TabIndex = 9; + // + // label1 + // + this.label1.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(3, 128); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(34, 13); + this.label1.TabIndex = 11; + this.label1.Text = "Scale"; + this.toolTip1.SetToolTip(this.label1, "Apply scale and offset to convert units."); + // + // label2 + // + this.label2.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(3, 158); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(35, 13); + this.label2.TabIndex = 12; + this.label2.Text = "Offset"; + this.toolTip1.SetToolTip(this.label2, "Apply scale and offset to convert units."); + // + // CHK_customwidth + // + this.CHK_customwidth.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.CHK_customwidth.AutoSize = true; + this.CHK_customwidth.Location = new System.Drawing.Point(3, 96); + this.CHK_customwidth.Name = "CHK_customwidth"; + this.CHK_customwidth.Size = new System.Drawing.Size(92, 17); + this.CHK_customwidth.TabIndex = 9; + this.CHK_customwidth.Text = "Custom Width"; + this.toolTip1.SetToolTip(this.CHK_customwidth, "Specify the maximum number of digits wide you expect the number to be. This provi" + + "des more consistent text size."); + this.CHK_customwidth.UseVisualStyleBackColor = true; + this.CHK_customwidth.CheckedChanged += new System.EventHandler(this.CHK_customwidth_CheckedChanged); + // + // NUM_customwidth + // + this.NUM_customwidth.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.NUM_customwidth.Location = new System.Drawing.Point(105, 95); + this.NUM_customwidth.Maximum = new decimal(new int[] { + 9, + 0, + 0, + 0}); + this.NUM_customwidth.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.NUM_customwidth.Name = "NUM_customwidth"; + this.NUM_customwidth.Size = new System.Drawing.Size(118, 20); + this.NUM_customwidth.TabIndex = 9; + this.NUM_customwidth.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.toolTip1.SetToolTip(this.NUM_customwidth, "Specify the maximum number of digits wide you expect the number to be. This provi" + + "des more consistent text size."); + this.NUM_customwidth.Value = new decimal(new int[] { + 4, + 0, + 0, + 0}); + this.NUM_customwidth.ValueChanged += new System.EventHandler(this.NUM_customwidth_ValueChanged); + // + // CHK_customlabel + // + this.CHK_customlabel.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.CHK_customlabel.AutoSize = true; + this.CHK_customlabel.Location = new System.Drawing.Point(3, 6); + this.CHK_customlabel.Name = "CHK_customlabel"; + this.CHK_customlabel.Size = new System.Drawing.Size(90, 17); + this.CHK_customlabel.TabIndex = 15; + this.CHK_customlabel.Text = "Custom Label"; + this.toolTip1.SetToolTip(this.CHK_customlabel, "Override the description at the top"); + this.CHK_customlabel.UseVisualStyleBackColor = true; + this.CHK_customlabel.CheckedChanged += new System.EventHandler(this.CHK_customlabel_CheckedChanged); + // + // TXT_customformat + // + this.TXT_customformat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.TXT_customformat.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.TXT_customformat.Location = new System.Drawing.Point(105, 68); + this.TXT_customformat.Name = "TXT_customformat"; + this.TXT_customformat.Size = new System.Drawing.Size(118, 13); + this.TXT_customformat.TabIndex = 10; + this.TXT_customformat.Text = "0.00"; + this.TXT_customformat.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.toolTip1.SetToolTip(this.TXT_customformat, "Custom format specifier, e.g. \"0.0\" or \"m:ss\""); + this.TXT_customformat.TextChanged += new System.EventHandler(this.TXT_customformat_TextChanged); + // + // TXT_customlabel + // + this.TXT_customlabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.TXT_customlabel.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.TXT_customlabel.Location = new System.Drawing.Point(105, 8); + this.TXT_customlabel.Name = "TXT_customlabel"; + this.TXT_customlabel.Size = new System.Drawing.Size(118, 13); + this.TXT_customlabel.TabIndex = 16; + this.TXT_customlabel.Text = "EFI Fuel Pressure (kPa)"; + this.TXT_customlabel.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.toolTip1.SetToolTip(this.TXT_customlabel, "Override the description at the top"); + this.TXT_customlabel.TextChanged += new System.EventHandler(this.TXT_customlabel_TextChanged); + // + // TXT_offset + // + this.TXT_offset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.TXT_offset.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.TXT_offset.Location = new System.Drawing.Point(105, 158); + this.TXT_offset.Name = "TXT_offset"; + this.TXT_offset.Size = new System.Drawing.Size(118, 13); + this.TXT_offset.TabIndex = 18; + this.TXT_offset.Text = "0.0"; + this.TXT_offset.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.toolTip1.SetToolTip(this.TXT_offset, "Apply scale and offset to convert units."); + this.TXT_offset.TextChanged += new System.EventHandler(this.TXT_offset_TextChanged); + this.TXT_offset.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TXT_scale_offset_KeyPress); + // + // TXT_scale + // + this.TXT_scale.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.TXT_scale.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.TXT_scale.Location = new System.Drawing.Point(105, 128); + this.TXT_scale.Name = "TXT_scale"; + this.TXT_scale.Size = new System.Drawing.Size(118, 13); + this.TXT_scale.TabIndex = 17; + this.TXT_scale.Text = "1.0"; + this.TXT_scale.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.toolTip1.SetToolTip(this.TXT_scale, "Apply scale and offset to convert units."); + this.TXT_scale.TextChanged += new System.EventHandler(this.TXT_scale_TextChanged); + this.TXT_scale.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TXT_scale_offset_KeyPress); + // + // CHK_customformat + // + this.CHK_customformat.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.CHK_customformat.AutoSize = true; + this.CHK_customformat.Location = new System.Drawing.Point(3, 66); + this.CHK_customformat.Name = "CHK_customformat"; + this.CHK_customformat.Size = new System.Drawing.Size(96, 17); + this.CHK_customformat.TabIndex = 8; + this.CHK_customformat.Text = "Custom Format"; + this.toolTip1.SetToolTip(this.CHK_customformat, "Custom format specifier, e.g. \"0.0\" or \"m:ss\""); + this.CHK_customformat.UseVisualStyleBackColor = true; + this.CHK_customformat.CheckedChanged += new System.EventHandler(this.CHK_customformat_CheckedChanged); + // // QuickViewOptions // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(428, 45); - this.Controls.Add(this.BUT_colorpicker); - this.Controls.Add(this.TXT_color); - this.Controls.Add(this.CHK_customcolor); + this.ClientSize = new System.Drawing.Size(281, 251); + this.Controls.Add(this.groupBox1); this.Controls.Add(this.LBL_precision); this.Controls.Add(this.NUM_precision); this.Controls.Add(this.CMB_Source); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MaximumSize = new System.Drawing.Size(5000, 290); + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(16, 290); this.Name = "QuickViewOptions"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "QuickViewOptions"; this.Shown += new System.EventHandler(this.QuickViewOptions_Shown); ((System.ComponentModel.ISupportInitialize)(this.NUM_precision)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.NUM_customwidth)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -132,5 +360,18 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox CHK_customcolor; private System.Windows.Forms.TextBox TXT_color; private System.Windows.Forms.Button BUT_colorpicker; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.CheckBox CHK_customformat; + private System.Windows.Forms.CheckBox CHK_customwidth; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.NumericUpDown NUM_customwidth; + private System.Windows.Forms.CheckBox CHK_customlabel; + private System.Windows.Forms.TextBox TXT_customformat; + private System.Windows.Forms.TextBox TXT_customlabel; + private System.Windows.Forms.ToolTip toolTip1; + private System.Windows.Forms.TextBox TXT_offset; + private System.Windows.Forms.TextBox TXT_scale; } } \ No newline at end of file diff --git a/Controls/QuickViewOptions.cs b/Controls/QuickViewOptions.cs index 3a098c85c6..bdc028fca3 100644 --- a/Controls/QuickViewOptions.cs +++ b/Controls/QuickViewOptions.cs @@ -21,17 +21,21 @@ public QuickViewOptions(QuickView qv) _qv = qv; } + List> all_fields = new List>(); + + // Stores the original value of the textbox background color to restore after error highlighting + private Color backup_backcolor = Color.Empty; + private void QuickViewOptions_Shown(object sender, EventArgs e) { + backup_backcolor = TXT_color.BackColor; + // Populate combobox with variables object thisBoxed = MainV2.comPort.MAV.cs; Type test = thisBoxed.GetType(); - List> fields = new List>(); - foreach (var field in test.GetProperties()) { - // field.Name has the field's name. object fieldValue = field.GetValue(thisBoxed, null); // Get value if (fieldValue == null) continue; @@ -46,81 +50,192 @@ private void QuickViewOptions_Shown(object sender, EventArgs e) if (CurrentState.custom_field_names.ContainsKey(field.Name)) { string name = CurrentState.custom_field_names[field.Name]; - fields.Add(new Tuple(field.Name, name)); + all_fields.Add(new Tuple(field.Name, name)); } } else { - fields.Add(new Tuple(field.Name, field.Name)); + all_fields.Add(new Tuple(field.Name, field.Name)); + } + } + + // Sort all_fields by display name + all_fields.Sort((x, y) => x.Item2.CompareTo(y.Item2)); + + // Fetch the selected variable name from the tag of the QuickView + string variable_name = ""; + try + { + variable_name = (string)_qv.Tag; + if (variable_name.StartsWith("customfield")) + { + variable_name = CurrentState.custom_field_names[variable_name]; } } + catch + { + ; // silently fail + } + // Initialize combobox CMB_Source.ValueMember = "Item1"; CMB_Source.DisplayMember = "Item2"; - CMB_Source.DataSource = fields; - - // Initialize combobox selection - CMB_Source.Text = (string)_qv.Tag; + CMB_Source.DataSource = all_fields; + CMB_Source.Text = variable_name; - // Initialize precision field, , assuming numberformat follows 0 to 0.0000000 format + // Initialize precision field, check if _qv.numberformat is in the form "0" or "0.00" etc. + // and count the zeros after the decimal if it is if (_qv.numberformat == "0") { NUM_precision.Value = 0; } - else if (_qv.numberformat.StartsWith("0.")) + else if (Regex.IsMatch(_qv.numberformat, @"^0\.0+$")) { - NUM_precision.Value = _qv.numberformat.Substring(2).Count(); + int precision = _qv.numberformat.Substring(_qv.numberformat.IndexOf('.') + 1).Length; + if (precision > NUM_precision.Maximum) + { + NUM_precision.Maximum = precision; + } + NUM_precision.Value = precision; } + // If it doesn't match, then we are using a custom format instead of the precision box else { - NUM_precision.Value = 2; + NUM_precision.Enabled = false; } - // Initialize custom color checkbox - CHK_customcolor.Checked = (Utilities.Settings.Instance[_qv.Name + "_color"] != null && Utilities.Settings.Instance[_qv.Name + "_color"] != "default"); + // Initialize custom label + CHK_customlabel.Checked = Settings.Instance[_qv.Name + "_label"] != null; + TXT_customlabel.Enabled = CHK_customlabel.Checked; + TXT_customlabel.Text = _qv.desc; - // Initialize custom color textbox and color picker button + // Initialize custom color + CHK_customcolor.Checked = Settings.Instance[_qv.Name + "_color"] != null; TXT_color.Enabled = CHK_customcolor.Checked; BUT_colorpicker.Enabled = CHK_customcolor.Checked; - TXT_color.Text = _qv.numberColorBackup.Name; + string colorname = _qv.numberColorBackup.Name; + if (colorname.ToLower().StartsWith("ff") && colorname.Length == 8) + { + TXT_color.Text = colorname.Substring(2); + } + else + { + TXT_color.Text = colorname; + } BUT_colorpicker.BackColor = _qv.numberColorBackup; - } - private void CMB_Source_SelectedIndexChanged(object sender, EventArgs e) - { - Utilities.Settings.Instance[_qv.Name] = (string) CMB_Source.SelectedValue; + // Initialize custom format + CHK_customformat.Checked = !NUM_precision.Enabled; + TXT_customformat.Enabled = CHK_customformat.Checked; + TXT_customformat.Text = _qv.numberformat.Replace("\\:", ":"); + + // Initialize custom width + int width = _qv.charWidth; + CHK_customwidth.Checked = width > 0; + NUM_customwidth.Enabled = CHK_customwidth.Checked; + if (width > NUM_customwidth.Maximum) + { + NUM_customwidth.Maximum = width; + } + if (CHK_customwidth.Checked) + { + NUM_customwidth.Value = width; + } + + // Initialize offset and scale + double scale = _qv.scale; + double offset = _qv.offset; + TXT_scale.Text = scale.ToString("0.0########"); + TXT_offset.Text = offset.ToString("0.0########"); } private void NUM_precision_ValueChanged(object sender, EventArgs e) { - if(NUM_precision.Value == 0) + if (NUM_precision.Value == 0) + { + Settings.Instance[_qv.Name + "_format"] = "0"; + } + else if (NUM_precision.Value == 2) { - Utilities.Settings.Instance[_qv.Name + "_format"] = "0"; + Settings.Instance.Remove(_qv.Name + "_format"); } else if (NUM_precision.Value >= 1) { - Utilities.Settings.Instance[_qv.Name + "_format"] = "0." + new string('0', (int) NUM_precision.Value); + Settings.Instance[_qv.Name + "_format"] = "0." + new string('0', (int)NUM_precision.Value); } - else // Edge case, should not happen; default to 0.00 + } + + private void CHK_customlabel_CheckedChanged(object sender, EventArgs e) + { + bool is_checked = CHK_customlabel.Checked; + string setting_name = _qv.Name + "_label"; + TXT_customlabel.Enabled = is_checked; + if(is_checked) { - Utilities.Settings.Instance[_qv.Name + "_format"] = "0.00"; + Settings.Instance[setting_name] = TXT_customlabel.Text; + } + else + { + Settings.Instance.Remove(setting_name); } } private void CHK_customcolor_CheckedChanged(object sender, EventArgs e) { - TXT_color.Enabled = CHK_customcolor.Checked; - BUT_colorpicker.Enabled = CHK_customcolor.Checked; - if (CHK_customcolor.Checked == false) + bool is_checked = CHK_customcolor.Checked; + string setting_name = _qv.Name + "_color"; + TXT_color.Enabled = is_checked; + BUT_colorpicker.Enabled = is_checked; + if (is_checked) + { + TXT_color_TextChanged(null, null); + } + else + { + Settings.Instance.Remove(setting_name); + } + } + + private void CHK_customformat_CheckedChanged(object sender, EventArgs e) + { + bool is_checked = CHK_customformat.Checked; + string setting_name = _qv.Name + "_format"; + TXT_customformat.Enabled = is_checked; + if (is_checked) + { + Settings.Instance[setting_name] = TXT_customformat.Text.Replace(":","\\:"); + NUM_precision.Enabled = false; + } + else + { + NUM_precision_ValueChanged(null, null); + NUM_precision.Enabled = true; + } + } + + private void CHK_customwidth_CheckedChanged(object sender, EventArgs e) + { + bool is_checked = CHK_customwidth.Checked; + string setting_name = _qv.Name + "_charWidth"; + NUM_customwidth.Enabled = is_checked; + if (is_checked) { - Utilities.Settings.Instance[_qv.Name + "_color"] = "default"; + Settings.Instance[setting_name] = NUM_customwidth.Text; } else { - Utilities.Settings.Instance[_qv.Name + "_color"] = TXT_color.Text; + Settings.Instance.Remove(setting_name); } } + private void TXT_customlabel_TextChanged(object sender, EventArgs e) + { + if (!CHK_customlabel.Checked) + return; + + Settings.Instance[_qv.Name + "_label"] = TXT_customlabel.Text; + } + private void TXT_color_TextChanged(object sender, EventArgs e) { if (!CHK_customcolor.Checked) @@ -131,7 +246,7 @@ private void TXT_color_TextChanged(object sender, EventArgs e) if (Regex.Match(TXT_color.Text, "^(?:[0-9a-fA-F]{2}){3,4}$").Success) { BUT_colorpicker.BackColor = System.Drawing.ColorTranslator.FromHtml("#"+TXT_color.Text); - Utilities.Settings.Instance[_qv.Name + "_color"] = "#"+TXT_color.Text; + Settings.Instance[_qv.Name + "_color"] = "#"+TXT_color.Text; return; } try @@ -143,7 +258,45 @@ private void TXT_color_TextChanged(object sender, EventArgs e) // Not a valid color string return; } - Utilities.Settings.Instance[_qv.Name + "_color"] = TXT_color.Text; + Settings.Instance[_qv.Name + "_color"] = TXT_color.Text; + } + + private void TXT_customformat_TextChanged(object sender, EventArgs e) + { + if (!CHK_customformat.Checked) + return; + + string setting_name = _qv.Name + "_format"; + + // Check if this is a valid format + string numberformat = ((Control)sender).Text.Replace(":", "\\:"); + double test_number = 125.2; + try + { + if (numberformat.Contains(":")) + { + TimeSpan.FromSeconds(test_number).ToString(numberformat); + } + else + { + test_number.ToString(numberformat); + } + ((Control)sender).BackColor = backup_backcolor; + Settings.Instance[setting_name] = numberformat; + } + catch (FormatException) + { + ((Control)sender).BackColor = Color.Red; + Settings.Instance.Remove(setting_name); + } + } + + private void NUM_customwidth_ValueChanged(object sender, EventArgs e) + { + if (!CHK_customwidth.Checked) + return; + + Settings.Instance[_qv.Name + "_charWidth"] = NUM_customwidth.Value.ToString(); } private void BUT_colorpicker_Click(object sender, EventArgs e) @@ -154,7 +307,122 @@ private void BUT_colorpicker_Click(object sender, EventArgs e) if (colorDlg.ShowDialog() == DialogResult.OK) { BUT_colorpicker.BackColor = colorDlg.Color; - TXT_color.Text = colorDlg.Color.Name; + // Get rid of opacity from name + string colorname = colorDlg.Color.Name; + if(colorname.ToLower().StartsWith("ff") && colorname.Length == 8) + { + TXT_color.Text = colorname.Substring(2); + } + else + { + TXT_color.Text = colorname; + } + } + } + + private void TXT_scale_offset_KeyPress(object sender, KeyPressEventArgs e) + { + if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.') && (e.KeyChar != '-')) + { + e.Handled = true; + } + + // only allow one decimal point + if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1)) + { + e.Handled = true; + } + + // only allow negative sign first + if ((e.KeyChar == '-') && ((sender as TextBox).SelectionStart > 0)) + { + e.Handled = true; + } + } + + private void TXT_scale_TextChanged(object sender, EventArgs e) + { + string setting_name = _qv.Name + "_scale"; + + // Try to parse the text as a number, and change background to red if invalid + double result; + if (!double.TryParse(((TextBox)sender).Text, out result)) + { + ((Control)sender).BackColor = Color.Red; + Settings.Instance.Remove(setting_name); + } + else + { + ((Control)sender).BackColor = backup_backcolor; + Settings.Instance[setting_name] = ((TextBox)sender).Text; + } + } + + private void TXT_offset_TextChanged(object sender, EventArgs e) + { + string setting_name = _qv.Name + "_offset"; + + // Try to parse the text as a number, and change background to red if invalid + double result; + if (!double.TryParse(((TextBox)sender).Text, out result)) + { + ((Control)sender).BackColor = Color.Red; + Settings.Instance.Remove(setting_name); + } + else + { + ((Control)sender).BackColor = backup_backcolor; + Settings.Instance[setting_name] = ((TextBox)sender).Text; + } + } + + // Runs when the user types in the box, but not when the text is changed programatically + private void CMB_Source_TextUpdate(object sender, EventArgs e) + { + List> filtered_fields; + + // Back up cursor position and text + int cursor_pos = CMB_Source.SelectionStart; + string searchText = CMB_Source.Text.ToLower(); + if (false)//CMB_Source.SelectedIndex > 0 || searchText == "") + { + filtered_fields = new List>(all_fields); + } + else + { + // Check all the fields in the table and see if any of them contain `searchText` as a DisplayName + filtered_fields = all_fields.Where(f => f.Item2.ToLower().Contains(searchText.ToLower())).ToList(); + CMB_Source.DroppedDown = true; + Cursor.Current = Cursors.Default; + } + + CMB_Source.DataSource = filtered_fields; + CMB_Source.Text = searchText; + CMB_Source.SelectionStart = cursor_pos; + } + + private void CMB_Source_DropDownClosed(object sender, EventArgs e) + { + if(CMB_Source.SelectedItem != null) + { + Tuple field = CMB_Source.SelectedItem as Tuple; + if (field.Item1.StartsWith("customfield")) + { + Settings.Instance[_qv.Name] = "customfield:" + field.Item2; + } + else + { + Settings.Instance[_qv.Name] = field.Item1; + } + TXT_customlabel.Text = MainV2.comPort.MAV.cs.GetNameandUnit((string)CMB_Source.SelectedValue); + + // Reset scale and offset if we select a new variable + TXT_scale.Text = "1.0"; + TXT_offset.Text = "0.0"; + + // Restore the full list + CMB_Source.DataSource = all_fields; + CMB_Source.SelectedItem = field; } } } diff --git a/Controls/QuickViewOptions.resx b/Controls/QuickViewOptions.resx index 29dcb1b3a3..65a871b69c 100644 --- a/Controls/QuickViewOptions.resx +++ b/Controls/QuickViewOptions.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/ExtLibs/ArduPilot/CurrentState.cs b/ExtLibs/ArduPilot/CurrentState.cs index b44500cc68..9fd4402bac 100644 --- a/ExtLibs/ArduPilot/CurrentState.cs +++ b/ExtLibs/ArduPilot/CurrentState.cs @@ -3836,10 +3836,10 @@ public string GetNameandUnit(string name) var desc = name; if (custom_field_names.ContainsKey(name)) - { - desc = custom_field_names[name]; - return desc; - } + { + desc = custom_field_names[name]; + return desc; + } try { var typeofthing = typeof(CurrentState).GetProperty(name); @@ -3863,6 +3863,34 @@ public string GetNameandUnit(string name) return desc; } + // Return the name of a customfield variable from its description. + // Allocate the customfield if necessary + public static string GetCustomField(string desc) + { + if(custom_field_names.ContainsValue(desc)) + { + // Find the key for this value + foreach (var pair in custom_field_names) + { + if (pair.Value == desc) + { + return pair.Key; + } + } + } + // Allocate a new custom field + for (int i = 0; i <= 19; i++) + { + string key = "customfield" + i.ToString(); + if (!custom_field_names.ContainsKey(key)) + { + custom_field_names.Add(key, desc); + return key; + } + } + // This should be unreachable, unless we run out of customfields to allocate + return ""; + } /// /// use for main serial port only diff --git a/ExtLibs/Controls/QuickView.cs b/ExtLibs/Controls/QuickView.cs index 747c8bfbcb..dbe67382ee 100644 --- a/ExtLibs/Controls/QuickView.cs +++ b/ExtLibs/Controls/QuickView.cs @@ -21,6 +21,14 @@ public string desc double _number = -9999; + // Optionally set this value to force the text size to fit this many "0" characters + // in the view. This allows for matching the text size of adjacent views. + public int charWidth = -1; + + // Optional offset and scale for unit conversions + public double offset = 0; + public double scale = 1; + [System.ComponentModel.Browsable(true)] public double number { @@ -68,6 +76,8 @@ public QuickView() InitializeComponent(); PaintSurface+= OnPaintSurface; + + DoubleBuffered = true; } private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e2) @@ -86,9 +96,28 @@ private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e2) } // { - var numb = number.ToString(numberformat); + string numb; + double scaled_number = scale * number + offset; + try + { + if (numberformat.Contains(":")) + { + numb = TimeSpan.FromSeconds(scaled_number).ToString(numberformat); + } + else + { + numb = scaled_number.ToString(numberformat); + } + } + catch(FormatException) + { + numberformat = "0.00"; + numb = scaled_number.ToString(numberformat); + } + - Size extent = e.MeasureString("0".PadLeft(numb.Length+1,'0'), new Font(this.Font.FontFamily, (float)newSize, this.Font.Style)).ToSize(); + var charWidth = Math.Max(this.charWidth, numb.Length) + 1; + Size extent = e.MeasureString("0".PadLeft(charWidth, '0'), new Font(this.Font.FontFamily, (float)newSize, this.Font.Style)).ToSize(); float hRatio = (this.Height - y) / (float)(extent.Height); float wRatio = this.Width / (float)extent.Width; diff --git a/GCSViews/FlightData.cs b/GCSViews/FlightData.cs index e9eae60bd1..94288b70d5 100644 --- a/GCSViews/FlightData.cs +++ b/GCSViews/FlightData.cs @@ -453,31 +453,58 @@ public void Activate() // set description and unit string desc = Settings.Instance["quickView" + f]; - if (QV.Tag == null) - QV.Tag = desc; - QV.desc = MainV2.comPort.MAV.cs.GetNameandUnit(desc); - // set the number format - string numberformat = Settings.Instance["quickView" + f + "_format"]; - if (numberformat != null) + // Check if customfield is specified by fieldname + if(desc.StartsWith("customfield:")) { - QV.numberformat = numberformat; + desc = CurrentState.GetCustomField(desc.Substring(12)); } + QV.Tag = desc; + if (Settings.Instance["quickView" + f + "_label"] != null) + { + QV.desc = Settings.Instance["quickView" + f + "_label"]; + } + else + { + QV.desc = MainV2.comPort.MAV.cs.GetNameandUnit(desc); + } + + // set the number format + string numberformat = Settings.Instance["quickView" + f + "_format"]; + QV.numberformat = numberformat != null ? numberformat : "0.00"; + // set the number color string numberColor = Settings.Instance["quickView" + f + "_color"]; - if (numberColor != null && numberColor != "default") + if (numberColor != null) { - QV.numberColor = System.Drawing.ColorTranslator.FromHtml(numberColor); - QV.numberColorBackup = QV.numberColor; + try + { + QV.numberColor = System.Drawing.ColorTranslator.FromHtml(numberColor); + QV.numberColorBackup = QV.numberColor; + } + catch + { + Settings.Instance.Remove("quickView" + f + "_color"); + } } + // Set character width + string charWidth = Settings.Instance["quickView" + f + "_charWidth"]; + QV.charWidth = charWidth != null ? int.Parse(charWidth) : -1; + + + // Set scale and offset + string scale = Settings.Instance["quickView" + f + "_scale"]; + QV.scale = scale != null ? double.Parse(scale) : 1; + string offset = Settings.Instance["quickView" + f + "_offset"]; + QV.offset = offset != null ? double.Parse(offset) : 0; + // set databinding for value QV.DataBindings.Clear(); try { - var b = new Binding("number", bindingSourceQuickTab, - Settings.Instance["quickView" + f], true); + var b = new Binding("number", bindingSourceQuickTab, (string)QV.Tag, true); b.Format += new ConvertEventHandler(BindingTypeToNumber); b.Parse += new ConvertEventHandler(NumberToBindingType); @@ -499,8 +526,7 @@ public void Activate() { QuickView QV = (QuickView) ctls[0]; string desc = QV.desc; - if (QV.Tag == null) - QV.Tag = desc; + QV.Tag = desc; QV.desc = MainV2.comPort.MAV.cs.GetNameandUnit(QV.Tag.ToString()); } } @@ -2341,38 +2367,6 @@ void chk_box_hud_UserItem_CheckedChanged(object sender, EventArgs e) } } - void chk_box_quickview_CheckedChanged(object sender, EventArgs e) - { - CheckBox checkbox = (CheckBox) sender; - - if (checkbox.Checked) - { - // save settings - Settings.Instance[((QuickView) checkbox.Tag).Name] = checkbox.Name; - - // set description - string desc = checkbox.Name; - ((QuickView) checkbox.Tag).Tag = desc; - - desc = MainV2.comPort.MAV.cs.GetNameandUnit(desc); - - ((QuickView) checkbox.Tag).desc = desc; - - // set databinding for value - ((QuickView) checkbox.Tag).DataBindings.Clear(); - - var b = new Binding("number", bindingSourceQuickTab, checkbox.Name, - true); - b.Format += new ConvertEventHandler(BindingTypeToNumber); - b.Parse += new ConvertEventHandler(NumberToBindingType); - - ((QuickView) checkbox.Tag).DataBindings.Add(b); - - // close selection form - ((Form) checkbox.Parent).Close(); - } - } - private void NumberToBindingType(object sender, ConvertEventArgs e) {