private void ProcessItem(configitem item) { try { if (!MainV2.comPort.MAV.param.ContainsKey(item.paramname)) { return; } var value = (float)MainV2.comPort.MAV.param[item.paramname]; if (value < item.min) { item.min = value; } if (value > item.max) { item.max = value; } var range = ParameterMetaDataRepository.GetParameterMetaData(item.paramname, ParameterMetaDataConstants.Range, MainV2.comPort.MAV.cs.firmware.ToString()); var increment = ParameterMetaDataRepository.GetParameterMetaData(item.paramname, ParameterMetaDataConstants.Increment, MainV2.comPort.MAV.cs.firmware.ToString()); var rangeopt = range.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (rangeopt.Length > 1) { item.min = float.Parse(rangeopt[0], CultureInfo.InvariantCulture); item.max = float.Parse(rangeopt[1], CultureInfo.InvariantCulture); } var incrementf = 0.01f; if (increment.Length > 0) { float.TryParse(increment, NumberStyles.Float, CultureInfo.InvariantCulture, out incrementf); } var RNG = new RangeControl(item.paramname, item.desc, item.title, incrementf, 1, item.min, item.max, value.ToString()); RNG.Tag = item; RNG.Location = new Point(10, y); RNG.AttachEvents(); RNG.ValueChanged += RNG_ValueChanged; ThemeManager.ApplyThemeTo(RNG); panel1.Controls.Add(RNG); y += RNG.Height; } catch (Exception ex) { CustomMessageBox.Show("Failed to process " + item.paramname + "\n" + ex); } }
private void AddControl(KeyValuePair <string, string> x, List <Control> toadd) //, ref int ypos) { if (!string.IsNullOrEmpty(x.Key)) { try { var controlAdded = false; var value = (MainV2.comPort.MAV.param[x.Key].Value).ToString("0.###"); var items = Controls.Find(x.Key, true); if (items.Length > 0) { if (items[0].GetType() == typeof(RangeControl)) { ((RangeControl)items[0]).ValueChanged -= Control_ValueChanged; ((RangeControl)items[0]).DeAttachEvents(); ((RangeControl)items[0]).Value = value; ThemeManager.ApplyThemeTo(((RangeControl)items[0])); ((RangeControl)items[0]).AttachEvents(); ((RangeControl)items[0]).ValueChanged += Control_ValueChanged; return; } if (items[0].GetType() == typeof(ValuesControl)) { ((ValuesControl)items[0]).ValueChanged -= Control_ValueChanged; ((ValuesControl)items[0]).Value = value; ((ValuesControl)items[0]).ValueChanged += Control_ValueChanged; return; } if (items[0].GetType() == typeof(MavlinkCheckBoxBitMask)) { ((MavlinkCheckBoxBitMask)items[0]).ValueChanged -= Control_ValueChanged; ((MavlinkCheckBoxBitMask)items[0]).Value = Convert.ToSingle(value); ((MavlinkCheckBoxBitMask)items[0]).ValueChanged += Control_ValueChanged; return; } } var description = ParameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Description, MainV2.comPort.MAV.cs.firmware.ToString()); var displayName = x.Value + " (" + x.Key + ")"; var units = ParameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Units, MainV2.comPort.MAV.cs.firmware.ToString()); // If this is a range var rangeRaw = ParameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Range, MainV2.comPort.MAV.cs.firmware.ToString()); var incrementRaw = ParameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Increment, MainV2.comPort.MAV.cs.firmware.ToString()); if (!string.IsNullOrEmpty(rangeRaw) && !string.IsNullOrEmpty(incrementRaw)) { float increment, intValue; float.TryParse(incrementRaw, NumberStyles.Float, CultureInfo.InvariantCulture, out increment); // this is in local culture float.TryParse(value, out intValue); var rangeParts = rangeRaw.Split(' '); if (rangeParts.Count() == 2 && increment > 0) { float lowerRange; float.TryParse(rangeParts[0], NumberStyles.Float, CultureInfo.InvariantCulture, out lowerRange); float upperRange; float.TryParse(rangeParts[1], NumberStyles.Float, CultureInfo.InvariantCulture, out upperRange); float displayscale = 1; // var rangeControl = new RangeControl(); if (units.ToLower() == "centi-degrees") { //Console.WriteLine(x.Key + " scale"); displayscale = 100; units = "Degrees (Scaled)"; increment /= 100; } else if (units.ToLower() == "centimeters") { //Console.WriteLine(x.Key + " scale"); // displayscale = 100; // units = "Meters (Scaled)"; // increment /= 100; } var desc = FitDescriptionText(units, description, tableLayoutPanel1.Width); var rangeControl = new RangeControl(x.Key, desc, displayName, increment, displayscale, lowerRange, upperRange, value); rangeControl.Width = tableLayoutPanel1.Width - 50; //Console.WriteLine("{0} {1} {2} {3} {4}", x.Key, increment, lowerRange, upperRange, value); ThemeManager.ApplyThemeTo(rangeControl); if (intValue < lowerRange) { rangeControl.NumericUpDownControl.BackColor = Color.Orange; } if (intValue > upperRange) { rangeControl.NumericUpDownControl.BackColor = Color.Orange; } rangeControl.AttachEvents(); rangeControl.ValueChanged += Control_ValueChanged; // set pos rangeControl.Location = new Point(0, y); // add control - let it autosize height toadd.Add(rangeControl); // add height for next control y += rangeControl.Height; controlAdded = true; } } // try bitmask next if (!controlAdded) { var availableBitMask = ParameterMetaDataRepository.GetParameterBitMaskInt(x.Key, MainV2.comPort.MAV.cs.firmware.ToString()); if (availableBitMask.Count > 0) { var bitmask = new MavlinkCheckBoxBitMask(); bitmask.Name = x.Key; bitmask.setup(x.Key, MainV2.comPort.MAV.param); bitmask.myLabel1.Text = displayName; bitmask.label1.Text = FitDescriptionText(units, description, tableLayoutPanel1.Width - 50); bitmask.Width = tableLayoutPanel1.Width - 50; ThemeManager.ApplyThemeTo(bitmask); // set pos bitmask.Location = new Point(0, y); // add control - let it autosize height toadd.Add(bitmask); // add height for next control y += bitmask.Height; bitmask.ValueChanged += Control_ValueChanged; controlAdded = true; } } if (!controlAdded) { // If this is a subset of values var availableValuesRaw = ParameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Values, MainV2.comPort.MAV.cs.firmware.ToString()); if (!string.IsNullOrEmpty(availableValuesRaw)) { var availableValues = availableValuesRaw.Split(','); if (availableValues.Any()) { var valueControl = new ValuesControl(); valueControl.Width = tableLayoutPanel1.Width - 50; valueControl.Name = x.Key; valueControl.DescriptionText = FitDescriptionText(units, description, tableLayoutPanel1.Width); valueControl.LabelText = displayName; ThemeManager.ApplyThemeTo(valueControl); var splitValues = new List <KeyValuePair <string, string> >(); // Add the values to the ddl foreach (var val in availableValues) { var valParts = val.Split(':'); splitValues.Add(new KeyValuePair <string, string>(valParts[0].Trim(), (valParts.Length > 1) ? valParts[1].Trim() : valParts[0].Trim())); } ; valueControl.ComboBoxControl.DisplayMember = "Value"; valueControl.ComboBoxControl.ValueMember = "Key"; valueControl.ComboBoxControl.DataSource = splitValues; valueControl.ComboBoxControl.SelectedValue = value; valueControl.ValueChanged += Control_ValueChanged; // set pos valueControl.Location = new Point(0, y); // add control - let it autosize height toadd.Add(valueControl); // add height for next control y += valueControl.Height; } } } } // if there is an error simply dont show it, ie bad pde file, bad scale etc catch (Exception ex) { log.Error(ex); } } }
/// <summary> /// Binds the param list. /// </summary> private void BindParamList() { tableLayoutPanel1.Controls.Clear(); if (_params == null || _params.Count == 0) { SortParamList(); } // get the params if nothing exists already if (_params != null && _params.Count == 0) { try { Utilities.ParameterMetaDataParser.GetParameterInformation(); _parameterMetaDataRepository.Reload(); SortParamList(); } catch (Exception exp) { log.Error(exp); } // just to cleanup any errors } this.SuspendLayout(); _params.OrderBy(x => x.Key).ForEach(x => { if (!String.IsNullOrEmpty(x.Key)) { try { bool controlAdded = false; string value = ((float)MainV2.comPort.param[x.Key]).ToString("0.###", CultureInfo.InvariantCulture); string description = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Description); string displayName = x.Value + " (" + x.Key + ")"; string units = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Units); // If this is a range string rangeRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Range); string incrementRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Increment); // modify for scaling float test = 1; MAVLink.modifyParamForDisplay(true, x.Key, ref test); if (test != 1) { if (units.ToLower() == "centi-degrees") { units = "Degrees"; incrementRaw = "0.1"; string[] rangeParts = rangeRaw.Split(new[] { ' ' }); if (rangeParts.Count() == 2) { float lowerRange; float.TryParse(rangeParts[0], out lowerRange); float upperRange; float.TryParse(rangeParts[1], out upperRange); rangeRaw = (lowerRange / 100) + " " + (upperRange / 100); } } else if (units.ToLower() == "centimeters") { units = "Meters"; incrementRaw = "0.1"; string[] rangeParts = rangeRaw.Split(new[] { ' ' }); if (rangeParts.Count() == 2) { float lowerRange; float.TryParse(rangeParts[0], out lowerRange); float upperRange; float.TryParse(rangeParts[1], out upperRange); rangeRaw = (lowerRange / 100) + " " + (upperRange / 100); } } else { units += " / " + (int)(1 / test); } } if (!String.IsNullOrEmpty(rangeRaw) && !String.IsNullOrEmpty(incrementRaw)) { float increment, intValue; float.TryParse(incrementRaw, out increment); float.TryParse(value, out intValue); string[] rangeParts = rangeRaw.Split(new[] { ' ' }); if (rangeParts.Count() == 2 && increment > 0) { float lowerRange; float.TryParse(rangeParts[0], out lowerRange); float upperRange; float.TryParse(rangeParts[1], out upperRange); int scaler = (int)float.Parse((1 / increment).ToString(CultureInfo.InvariantCulture)); int scaledLowerRange = 0, scaledUpperRange = 0; int scaledIncrement = (int)increment; if (scaler > 0) { scaledLowerRange = (int)(lowerRange * scaler); scaledUpperRange = (int)(upperRange * scaler); scaledIncrement = (int)float.Parse((increment * scaler).ToString(CultureInfo.InvariantCulture)); intValue *= scaler; } var rangeControl = new RangeControl(); rangeControl.Name = x.Key; rangeControl.Scaler = scaler; rangeControl.DescriptionText = FitDescriptionText(units, description); rangeControl.LabelText = displayName; rangeControl.TrackBarControl.Minimum = Math.Min(scaledLowerRange, (int)intValue); rangeControl.TrackBarControl.Maximum = Math.Max(scaledUpperRange, (int)intValue); rangeControl.TrackBarControl.TickFrequency = scaledIncrement; rangeControl.TrackBarControl.Value = (int)intValue; rangeControl.NumericUpDownControl.Increment = (decimal)increment; rangeControl.NumericUpDownControl.DecimalPlaces = scaler.ToString(CultureInfo.InvariantCulture).Length - 1; rangeControl.NumericUpDownControl.Minimum = (decimal)Math.Min(lowerRange, ((float)MainV2.comPort.param[x.Key])); rangeControl.NumericUpDownControl.Maximum = (decimal)Math.Max(upperRange, ((float)MainV2.comPort.param[x.Key])); rangeControl.NumericUpDownControl.Value = (decimal)((float)MainV2.comPort.param[x.Key]); rangeControl.AttachEvents(); tableLayoutPanel1.Controls.Add(rangeControl); controlAdded = true; } } if (!controlAdded) { // If this is a subset of values string availableValuesRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Values); if (!String.IsNullOrEmpty(availableValuesRaw)) { string[] availableValues = availableValuesRaw.Split(new[] { ',' }); if (availableValues.Any()) { var valueControl = new ValuesControl(); valueControl.Name = x.Key; valueControl.DescriptionText = FitDescriptionText(units, description); valueControl.LabelText = displayName; var splitValues = new List <KeyValuePair <string, string> >(); // Add the values to the ddl availableValues.ForEach(val => { string[] valParts = val.Split(new[] { ':' }); splitValues.Add(new KeyValuePair <string, string>(valParts[0], (valParts.Length > 1) ? valParts[1] : valParts[0])); }); valueControl.ComboBoxControl.DisplayMember = "Value"; valueControl.ComboBoxControl.ValueMember = "Key"; valueControl.ComboBoxControl.DataSource = splitValues; valueControl.ComboBoxControl.SelectedValue = value; tableLayoutPanel1.Controls.Add(valueControl); } } } } // if there is an error simply dont show it, ie bad pde file, bad scale etc catch (Exception ex) { log.Error(ex); } } }); ThemeManager.ApplyThemeTo(this); this.ResumeLayout(); }
/// <summary> /// Binds the param list. /// </summary> private void BindParamList() { tableLayoutPanel1.Controls.Clear(); if (_params == null || _params.Count == 0) { SortParamList(); } // get the params if nothing exists already if (_params != null && _params.Count == 0) { Utilities.ParameterMetaDataParser.GetParameterInformation(); } _params.ForEach(x => { if (!String.IsNullOrEmpty(x.Key)) { try { bool controlAdded = false; string value = ((float)MainV2.comPort.param[x.Key]).ToString("0.###"); string description = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Description); string displayName = x.Value; string units = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Units); // If this is a range string rangeRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Range); string incrementRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Increment); if (!String.IsNullOrEmpty(rangeRaw) && !String.IsNullOrEmpty(incrementRaw)) { float increment, intValue; float.TryParse(incrementRaw, out increment); float.TryParse(value, out intValue); string[] rangeParts = rangeRaw.Split(new[] { ' ' }); if (rangeParts.Count() == 2 && increment > 0) { float lowerRange; float.TryParse(rangeParts[0], out lowerRange); float upperRange; float.TryParse(rangeParts[1], out upperRange); int scaler = (int)float.Parse((1 / increment).ToString(CultureInfo.InvariantCulture)); int scaledLowerRange = 0, scaledUpperRange = 0; int scaledIncrement = (int)increment; if (scaler > 0) { scaledLowerRange = (int)(lowerRange * scaler); scaledUpperRange = (int)(upperRange * scaler); scaledIncrement = (int)float.Parse((increment * scaler).ToString(CultureInfo.InvariantCulture)); intValue *= scaler; } var rangeControl = new RangeControl(); rangeControl.Name = x.Key; rangeControl.Scaler = scaler; rangeControl.DescriptionText = FitDescriptionText(units, description); rangeControl.LabelText = displayName; rangeControl.TrackBarControl.Minimum = scaledLowerRange; rangeControl.TrackBarControl.Maximum = scaledUpperRange; rangeControl.TrackBarControl.TickFrequency = scaledIncrement; rangeControl.TrackBarControl.Value = (int)intValue; rangeControl.NumericUpDownControl.Increment = (decimal)increment; rangeControl.NumericUpDownControl.DecimalPlaces = scaler.ToString(CultureInfo.InvariantCulture).Length - 1; rangeControl.NumericUpDownControl.Minimum = (decimal)lowerRange; rangeControl.NumericUpDownControl.Maximum = (decimal)upperRange; rangeControl.NumericUpDownControl.Value = (decimal)((float)MainV2.comPort.param[x.Key]); rangeControl.AttachEvents(); tableLayoutPanel1.Controls.Add(rangeControl); controlAdded = true; } } if (!controlAdded) { // If this is a subset of values string availableValuesRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Values); if (!String.IsNullOrEmpty(availableValuesRaw)) { string[] availableValues = availableValuesRaw.Split(new[] { ',' }); if (availableValues.Any()) { var valueControl = new ValuesControl(); valueControl.Name = x.Key; valueControl.DescriptionText = FitDescriptionText(units, description); valueControl.LabelText = displayName; var splitValues = new List <KeyValuePair <string, string> >(); // Add the values to the ddl availableValues.ForEach(val => { string[] valParts = val.Split(new[] { ':' }); splitValues.Add(new KeyValuePair <string, string>(valParts[0], (valParts.Length > 1) ? valParts[1] : valParts[0])); }); valueControl.ComboBoxControl.DisplayMember = "Value"; valueControl.ComboBoxControl.ValueMember = "Key"; valueControl.ComboBoxControl.DataSource = splitValues; valueControl.ComboBoxControl.SelectedValue = value; tableLayoutPanel1.Controls.Add(valueControl); } } } } // if there is an error simply dont show it, ie bad pde file, bad scale etc catch (Exception ex) { log.Error(ex); } } }); }
void AddControl(KeyValuePair <string, string> x) { if (!String.IsNullOrEmpty(x.Key)) { try { bool controlAdded = false; string value = ((float)MainV2.comPort.param[x.Key]).ToString("0.###", CultureInfo.InvariantCulture); string description = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Description); string displayName = x.Value + " (" + x.Key + ")"; string units = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Units); // If this is a range string rangeRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Range); string incrementRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Increment); if (!String.IsNullOrEmpty(rangeRaw) && !String.IsNullOrEmpty(incrementRaw)) { float increment, intValue; float.TryParse(incrementRaw, out increment); float.TryParse(value, out intValue); string[] rangeParts = rangeRaw.Split(new[] { ' ' }); if (rangeParts.Count() == 2 && increment > 0) { float lowerRange; float.TryParse(rangeParts[0], out lowerRange); float upperRange; float.TryParse(rangeParts[1], out upperRange); float displayscale = 1; // var rangeControl = new RangeControl(); if (units.ToLower() == "centi-degrees") { Console.WriteLine(x.Key + " scale"); displayscale = 100; units = "Degrees (Scaled)"; increment /= 100; } else if (units.ToLower() == "centimeters") { Console.WriteLine(x.Key + " scale"); displayscale = 100; units = "Meters (Scaled)"; increment /= 100; } var rangeControl = new RangeControl(x.Key, FitDescriptionText(units, description), displayName, increment, displayscale, lowerRange, upperRange, value); /* * rangeControl.Name = x.Key; * rangeControl.Increment = increment; * rangeControl.DescriptionText = FitDescriptionText(units, description); * rangeControl.LabelText = displayName; * rangeControl.MinRange = lowerRange; * rangeControl.MaxRange = upperRange; * rangeControl.Value = value; */ Console.WriteLine("{0} {1} {2} {3} {4}", x.Key, increment, lowerRange, upperRange, value); ThemeManager.ApplyThemeTo(rangeControl); if (intValue < lowerRange) { rangeControl.NumericUpDownControl.BackColor = Color.Orange; } if (intValue > upperRange) { rangeControl.NumericUpDownControl.BackColor = Color.Orange; } /* * rangeControl.TrackBarControl.Minimum = Math.Min(scaledLowerRange, (int)intValue); * rangeControl.TrackBarControl.Maximum = Math.Max(scaledUpperRange, (int)intValue); * rangeControl.TrackBarControl.TickFrequency = scaledIncrement; * rangeControl.TrackBarControl.Value = (int)intValue; * * rangeControl.NumericUpDownControl.Increment = (decimal)increment; * rangeControl.NumericUpDownControl.DecimalPlaces = scaler.ToString(CultureInfo.InvariantCulture).Length - 1; * rangeControl.NumericUpDownControl.Minimum = (decimal)Math.Min(lowerRange, intValue); * rangeControl.NumericUpDownControl.Maximum = (decimal)Math.Max(upperRange, intValue); * rangeControl.NumericUpDownControl.Value = (decimal)(intValue); */ rangeControl.AttachEvents(); tableLayoutPanel1.Controls.Add(rangeControl); controlAdded = true; } } if (!controlAdded) { // If this is a subset of values string availableValuesRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Values); if (!String.IsNullOrEmpty(availableValuesRaw)) { string[] availableValues = availableValuesRaw.Split(new[] { ',' }); if (availableValues.Any()) { var valueControl = new ValuesControl(); valueControl.Name = x.Key; valueControl.DescriptionText = FitDescriptionText(units, description); valueControl.LabelText = displayName; ThemeManager.ApplyThemeTo(valueControl); var splitValues = new List <KeyValuePair <string, string> >(); // Add the values to the ddl foreach (string val in availableValues) { string[] valParts = val.Split(new[] { ':' }); splitValues.Add(new KeyValuePair <string, string>(valParts[0].Trim(), (valParts.Length > 1) ? valParts[1].Trim() : valParts[0].Trim())); } ; valueControl.ComboBoxControl.DisplayMember = "Value"; valueControl.ComboBoxControl.ValueMember = "Key"; valueControl.ComboBoxControl.DataSource = splitValues; valueControl.ComboBoxControl.SelectedValue = value; tableLayoutPanel1.Controls.Add(valueControl); } } } } // if there is an error simply dont show it, ie bad pde file, bad scale etc catch (Exception ex) { log.Error(ex); } } }
void AddControl(KeyValuePair <string, string> x) //, ref int ypos) { if (!String.IsNullOrEmpty(x.Key)) { try { bool controlAdded = false; string value = ((float)MainV2.comPort.MAV.param[x.Key]).ToString("0.###", CultureInfo.InvariantCulture); string description = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Description); string displayName = x.Value + " (" + x.Key + ")"; string units = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Units); var items = this.Controls.Find(x.Key, true); if (items.Length > 0) { if (items[0].GetType() == typeof(RangeControl)) { ((RangeControl)items[0]).ValueChanged -= Control_ValueChanged; ((RangeControl)items[0]).DeAttachEvents(); ((RangeControl)items[0]).Value = value; ThemeManager.ApplyThemeTo(((RangeControl)items[0])); ((RangeControl)items[0]).AttachEvents(); ((RangeControl)items[0]).ValueChanged += Control_ValueChanged; return; } else if (items[0].GetType() == typeof(ValuesControl)) { ((ValuesControl)items[0]).ValueChanged -= Control_ValueChanged; ((ValuesControl)items[0]).Value = value; ((ValuesControl)items[0]).ValueChanged += Control_ValueChanged; return; } } // If this is a range string rangeRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Range); string incrementRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Increment); if (!String.IsNullOrEmpty(rangeRaw) && !String.IsNullOrEmpty(incrementRaw)) { float increment, intValue; float.TryParse(incrementRaw, out increment); float.TryParse(value, out intValue); string[] rangeParts = rangeRaw.Split(new[] { ' ' }); if (rangeParts.Count() == 2 && increment > 0) { float lowerRange; float.TryParse(rangeParts[0], out lowerRange); float upperRange; float.TryParse(rangeParts[1], out upperRange); float displayscale = 1; // var rangeControl = new RangeControl(); if (units.ToLower() == "centi-degrees") { //Console.WriteLine(x.Key + " scale"); displayscale = 100; units = "Degrees (Scaled)"; increment /= 100; } else if (units.ToLower() == "centimeters") { //Console.WriteLine(x.Key + " scale"); displayscale = 100; units = "Meters (Scaled)"; increment /= 100; } var rangeControl = new RangeControl(x.Key, FitDescriptionText(units, description), displayName, increment, displayscale, lowerRange, upperRange, value); //Console.WriteLine("{0} {1} {2} {3} {4}", x.Key, increment, lowerRange, upperRange, value); ThemeManager.ApplyThemeTo(rangeControl); if (intValue < lowerRange) { rangeControl.NumericUpDownControl.BackColor = Color.Orange; } if (intValue > upperRange) { rangeControl.NumericUpDownControl.BackColor = Color.Orange; } rangeControl.AttachEvents(); rangeControl.ValueChanged += Control_ValueChanged; // set pos // rangeControl.Location = new Point(0, ypos); // add control - let it autosize height tableLayoutPanel1.Controls.Add(rangeControl); // add height for next control // ypos += rangeControl.Height; controlAdded = true; } } if (!controlAdded) { // If this is a subset of values string availableValuesRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Values); if (!String.IsNullOrEmpty(availableValuesRaw)) { string[] availableValues = availableValuesRaw.Split(new[] { ',' }); if (availableValues.Any()) { var valueControl = new ValuesControl(); valueControl.Name = x.Key; valueControl.DescriptionText = FitDescriptionText(units, description); valueControl.LabelText = displayName; ThemeManager.ApplyThemeTo(valueControl); var splitValues = new List <KeyValuePair <string, string> >(); // Add the values to the ddl foreach (string val in availableValues) { string[] valParts = val.Split(new[] { ':' }); splitValues.Add(new KeyValuePair <string, string>(valParts[0].Trim(), (valParts.Length > 1) ? valParts[1].Trim() : valParts[0].Trim())); } ; valueControl.ComboBoxControl.DisplayMember = "Value"; valueControl.ComboBoxControl.ValueMember = "Key"; valueControl.ComboBoxControl.DataSource = splitValues; valueControl.ComboBoxControl.SelectedValue = value; valueControl.ValueChanged += Control_ValueChanged; // set pos // valueControl.Location = new Point(0, ypos); // add control - let it autosize height tableLayoutPanel1.Controls.Add(valueControl); // add height for next control // ypos += valueControl.Height; } } } } // if there is an error simply dont show it, ie bad pde file, bad scale etc catch (Exception ex) { log.Error(ex); } } }
//, ref int ypos) void AddControl(KeyValuePair<string,string> x) { if (!String.IsNullOrEmpty(x.Key)) { try { bool controlAdded = false; string value = ((float)MainV2.comPort.MAV.param[x.Key]).ToString("0.###", CultureInfo.InvariantCulture); string description = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Description); string displayName = x.Value + " (" + x.Key + ")"; string units = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Units); var items = this.Controls.Find(x.Key,true); if (items.Length > 0) { if (items[0].GetType() == typeof(RangeControl)) { ((RangeControl)items[0]).ValueChanged -= Control_ValueChanged; ((RangeControl)items[0]).DeAttachEvents(); ((RangeControl)items[0]).Value = value; ThemeManager.ApplyThemeTo(((RangeControl)items[0])); ((RangeControl)items[0]).AttachEvents(); ((RangeControl)items[0]).ValueChanged += Control_ValueChanged; return; } else if (items[0].GetType() == typeof(ValuesControl)) { ((ValuesControl)items[0]).ValueChanged -= Control_ValueChanged; ((ValuesControl)items[0]).Value = value; ((ValuesControl)items[0]).ValueChanged += Control_ValueChanged; return; } } // If this is a range string rangeRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Range); string incrementRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Increment); if (!String.IsNullOrEmpty(rangeRaw) && !String.IsNullOrEmpty(incrementRaw)) { float increment, intValue; float.TryParse(incrementRaw, out increment); float.TryParse(value, out intValue); string[] rangeParts = rangeRaw.Split(new[] { ' ' }); if (rangeParts.Count() == 2 && increment > 0) { float lowerRange; float.TryParse(rangeParts[0], out lowerRange); float upperRange; float.TryParse(rangeParts[1], out upperRange); float displayscale = 1; // var rangeControl = new RangeControl(); if (units.ToLower() == "centi-degrees") { //Console.WriteLine(x.Key + " scale"); displayscale = 100; units = "Degrees (Scaled)"; increment /= 100; } else if (units.ToLower() == "centimeters") { //Console.WriteLine(x.Key + " scale"); // displayscale = 100; // units = "Meters (Scaled)"; // increment /= 100; } var rangeControl = new RangeControl(x.Key, FitDescriptionText(units, description), displayName, increment, displayscale, lowerRange, upperRange, value); //Console.WriteLine("{0} {1} {2} {3} {4}", x.Key, increment, lowerRange, upperRange, value); ThemeManager.ApplyThemeTo(rangeControl); if (intValue < lowerRange) rangeControl.NumericUpDownControl.BackColor = Color.Orange; if (intValue > upperRange) rangeControl.NumericUpDownControl.BackColor = Color.Orange; rangeControl.AttachEvents(); rangeControl.ValueChanged += Control_ValueChanged; // set pos rangeControl.Location = new Point(0, y); // add control - let it autosize height tableLayoutPanel1.Controls.Add(rangeControl); // add height for next control y += rangeControl.Height; controlAdded = true; } } if (!controlAdded) { // If this is a subset of values string availableValuesRaw = _parameterMetaDataRepository.GetParameterMetaData(x.Key, ParameterMetaDataConstants.Values); if (!String.IsNullOrEmpty(availableValuesRaw)) { string[] availableValues = availableValuesRaw.Split(new[] { ',' }); if (availableValues.Any()) { var valueControl = new ValuesControl(); valueControl.Name = x.Key; valueControl.DescriptionText = FitDescriptionText(units, description); valueControl.LabelText = displayName; ThemeManager.ApplyThemeTo(valueControl); var splitValues = new List<KeyValuePair<string, string>>(); // Add the values to the ddl foreach (string val in availableValues) { string[] valParts = val.Split(new[] { ':' }); splitValues.Add(new KeyValuePair<string, string>(valParts[0].Trim(), (valParts.Length > 1) ? valParts[1].Trim() : valParts[0].Trim())); }; valueControl.ComboBoxControl.DisplayMember = "Value"; valueControl.ComboBoxControl.ValueMember = "Key"; valueControl.ComboBoxControl.DataSource = splitValues; valueControl.ComboBoxControl.SelectedValue = value; valueControl.ValueChanged += Control_ValueChanged; // set pos valueControl.Location = new Point(0, y); // add control - let it autosize height tableLayoutPanel1.Controls.Add(valueControl); // add height for next control y += valueControl.Height; } } } } // if there is an error simply dont show it, ie bad pde file, bad scale etc catch (Exception ex) { log.Error(ex); } } }