From ae348d13fdefe668e2b2ee465b362953e18bc3c6 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Thu, 23 Jun 2022 15:30:06 +0200 Subject: [PATCH] Custom units in MetrologyDlg tabs : Bug fixes : 1. Test after adding a value, 2. test of FlowMeter+rangeIx, ver. 2.29.1927 --- Config/Entities/MeasurementCorrection.cs | 11 ++++++++++- TBF/Properties/AssemblyInfo.cs | 4 ++-- TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs | 8 +++++--- TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs | 9 +++++---- TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs | 8 +++++--- TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs | 8 +++++--- 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Config/Entities/MeasurementCorrection.cs b/Config/Entities/MeasurementCorrection.cs index a43a58f12..d41cb5241 100644 --- a/Config/Entities/MeasurementCorrection.cs +++ b/Config/Entities/MeasurementCorrection.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; namespace Config.Entities { - public class MeasurementCorrection : Common.IMeasurementCorrection + public class MeasurementCorrection : Common.IMeasurementCorrection, IComparable { public virtual int Id { get; protected set; } public virtual int RangeIx { get; set; } /// 0..5 @@ -23,6 +23,10 @@ namespace Config.Entities RangeIx = rangeIx; } + public virtual int CompareTo(MeasurementCorrection other) + { + return (Measurement > other.Measurement) ? 1 : ((Measurement == other.Measurement) ? 0 : -1); + } /// /// Calculates corrected value from a list of corrections by interpolation. @@ -76,5 +80,10 @@ namespace Config.Entities /// rawValue is above the highest value in the correction table return corrections[corrections.Count - 1].Correction; } + + public override string ToString() + { + return string.Format("{0} {1} ({2})", Measurement, Correction, RangeIx); + } } } diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 6b1ec7de8..594202627 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.29.1926.0")] -[assembly: AssemblyFileVersion("2.29.1926.0")] +[assembly: AssemblyVersion("2.29.1927.0")] +[assembly: AssemblyFileVersion("2.29.1927.0")] diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs index 7c111c673..0baf69d43 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs @@ -18,7 +18,6 @@ namespace TBF.UI.Bench.Metrology { static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgBalanceTab)); - public const Unit DefaultUnit = Unit.kg; public const int SignifDigits = 5; /// @@ -86,7 +85,7 @@ namespace TBF.UI.Bench.Metrology this.Controls.Add(correctionTextBox = new TextBox()); this.Controls.Add(errorTextBox = new TextBox()); - currentUnit = DefaultUnit; + currentUnit = TBF.Rig.Sequences.ProcessData.MassUnit; unitComboBox.Text = currentUnit.ToDescription(); InitializeColumns(listViewEx, currentUnit); RefreshAll(); @@ -418,7 +417,10 @@ namespace TBF.UI.Bench.Metrology CultureInfo.InvariantCulture, out measured)) { - double corrected = MeasurementCorrection.CorrectedValue(Units.ConvertFrom(currentUnit, measured), meterEntity.Corrections); + var corrections = new List(); + foreach (var c in meterEntity.Corrections) corrections.Add(c); + corrections.Sort(); + double corrected = MeasurementCorrection.CorrectedValue(Units.ConvertFrom(currentUnit, measured), corrections); correctedTextBox.Text = Units.ConvertTo(currentUnit, corrected).ToString(); } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs index a72e01e06..116f0f435 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs @@ -18,7 +18,6 @@ namespace TBF.UI.Bench.Metrology { static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgFlowMeterTab)); - public const Unit DefaultUnit = Unit.m3ph; public const int SignifDigits = 5; /// @@ -101,7 +100,7 @@ namespace TBF.UI.Bench.Metrology this.Controls.Add(correctionTextBox = new TextBox()); this.Controls.Add(errorTextBox = new TextBox()); - currentUnit = DefaultUnit; + currentUnit = TBF.Rig.Sequences.ProcessData.FlowUnit; unitComboBox.Text = currentUnit.ToDescription(); InitializeColumns(listViewEx, currentUnit); RefreshAll(rangeIx); @@ -410,8 +409,10 @@ namespace TBF.UI.Bench.Metrology CultureInfo.InvariantCulture, out measured)) { - double raw = Units.ConvertFrom(currentUnit, measured); - double corrected = raw + MeasurementCorrection.GetCorrection(raw, MeterEntity.Corrections); /// !!! rangeIx is ignored + var corrections = new List(); + foreach (var c in meterEntity.Corrections) if (c.RangeIx == rangeIx) corrections.Add(c); + corrections.Sort(); + double corrected = MeasurementCorrection.CorrectedValue(Units.ConvertFrom(currentUnit, measured), corrections); correctedTextBox.Text = Units.ConvertTo(currentUnit, corrected).ToString(); } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs index 993b71dd9..de41809f2 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs @@ -18,7 +18,6 @@ namespace TBF.UI.Bench.Metrology { static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgPressMeterTab)); - public const Unit DefaultUnit = Unit.bar; public const int SignifDigits = 5; /// @@ -86,7 +85,7 @@ namespace TBF.UI.Bench.Metrology this.Controls.Add(correctionTextBox = new TextBox()); this.Controls.Add(errorTextBox = new TextBox()); - currentUnit = DefaultUnit; + currentUnit = TBF.Rig.Sequences.ProcessData.PressUnit; unitComboBox.Text = currentUnit.ToDescription(); InitializeColumns(listViewEx, currentUnit); RefreshAll(); @@ -395,7 +394,10 @@ namespace TBF.UI.Bench.Metrology CultureInfo.InvariantCulture, out measured)) { - double corrected = MeasurementCorrection.CorrectedValue(Units.ConvertFrom(currentUnit, measured), meterEntity.Corrections); + var corrections = new List(); + foreach (var c in meterEntity.Corrections) corrections.Add(c); + corrections.Sort(); + double corrected = MeasurementCorrection.CorrectedValue(Units.ConvertFrom(currentUnit, measured), corrections); correctedTextBox.Text = Units.ConvertTo(currentUnit, corrected).ToString(); } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs index 1eaef544d..19040b3fa 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs @@ -18,7 +18,6 @@ namespace TBF.UI.Bench.Metrology { static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgTempMeterTab)); - public const Unit DefaultUnit = Unit.C; public const int SignifDigits = 5; /// @@ -86,7 +85,7 @@ namespace TBF.UI.Bench.Metrology this.Controls.Add(correctionTextBox = new TextBox()); this.Controls.Add(errorTextBox = new TextBox()); - currentUnit = DefaultUnit; + currentUnit = TBF.Rig.Sequences.ProcessData.TempUnit; unitComboBox.Text = currentUnit.ToDescription(); InitializeColumns(listViewEx, currentUnit); RefreshAll(); @@ -395,7 +394,10 @@ namespace TBF.UI.Bench.Metrology CultureInfo.InvariantCulture, out measured)) { - double corrected = MeasurementCorrection.CorrectedValue(Units.ConvertFrom(currentUnit, measured), meterEntity.Corrections); + var corrections = new List(); + foreach (var c in meterEntity.Corrections) corrections.Add(c); + corrections.Sort(); + double corrected = MeasurementCorrection.CorrectedValue(Units.ConvertFrom(currentUnit, measured), corrections); correctedTextBox.Text = Units.ConvertTo(currentUnit, corrected).ToString(); } }