diff --git a/Common/IMeasurementCorrection.cs b/Common/IMeasurementCorrection.cs index 41c92da54..14d22e492 100644 --- a/Common/IMeasurementCorrection.cs +++ b/Common/IMeasurementCorrection.cs @@ -5,7 +5,7 @@ namespace Common public interface IMeasurementCorrection { int RangeIx { get; set; } - float Measurement { get; set; } - float Correction { get; set; } + double Measurement { get; set; } + double Correction { get; set; } } } diff --git a/Common/Utils.cs b/Common/Utils.cs index a187b3099..ba5dc0566 100644 --- a/Common/Utils.cs +++ b/Common/Utils.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2021 Sensus Slovensko a.s. +/// Copyright (c) 2021-2022 Sensus Slovensko a.s. /// using System; @@ -14,6 +14,12 @@ namespace Common return string.Format("{0} ({1}/{2})", name, repetitionNr, repeats); } + public static string ToNiceString(double value, int sigDigits) + { + string format = SignificantDigitsToFmt(value, sigDigits); + return (format == "F0") ? value.ToString("F0") : value.ToString(format).TrimEnd(new char[] { '0' }); + } + public static string SignificantDigitsToFmt(double value, int sigDigits) { if (sigDigits == 6) diff --git a/Config/Entities/MeasurementCorrection.cs b/Config/Entities/MeasurementCorrection.cs index 11ea46195..8ff1abc62 100644 --- a/Config/Entities/MeasurementCorrection.cs +++ b/Config/Entities/MeasurementCorrection.cs @@ -1,17 +1,17 @@ /// -/// Copyright (c) 2013-2021 Sensus Slovensko a.s. +/// Copyright (c) 2013-2022 Sensus Slovensko a.s. /// using System; 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 - public virtual float Measurement { get; set; } - public virtual float Correction { get; set; } + public virtual double Measurement { get; set; } + public virtual double Correction { get; set; } public MeasurementCorrection() { @@ -23,6 +23,11 @@ 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 +81,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 d3adaa5a4..82365b70e 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("3.2.1913.0")] -[assembly: AssemblyFileVersion("3.2.1913.0")] +[assembly: AssemblyVersion("3.3.1928.0")] +[assembly: AssemblyFileVersion("3.3.1928.0")] diff --git a/TBF/UI/Bench/Metrology/IMetrologyDlgTab.cs b/TBF/UI/Bench/Metrology/IMetrologyDlgTab.cs index 088de0a04..c39d8ea69 100644 --- a/TBF/UI/Bench/Metrology/IMetrologyDlgTab.cs +++ b/TBF/UI/Bench/Metrology/IMetrologyDlgTab.cs @@ -3,7 +3,6 @@ /// using System.Collections.Generic; using NHibernate; -using Common; using Config.Entities; namespace TBF.UI.Bench.Metrology diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.Designer.cs b/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.Designer.cs index af7a12eb0..b493833b1 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.Designer.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.Designer.cs @@ -33,6 +33,8 @@ namespace TBF.UI.Bench.Metrology { this.cmpntNameLabel = new System.Windows.Forms.Label(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.unitLabel = new System.Windows.Forms.Label(); + this.unitComboBox = new System.Windows.Forms.ComboBox(); this.calibrationGroupBox = new System.Windows.Forms.GroupBox(); this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker(); this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker(); @@ -87,6 +89,8 @@ namespace TBF.UI.Bench.Metrology // // splitContainer1.Panel1 // + this.splitContainer1.Panel1.Controls.Add(this.unitLabel); + this.splitContainer1.Panel1.Controls.Add(this.unitComboBox); this.splitContainer1.Panel1.Controls.Add(this.calibrationGroupBox); this.splitContainer1.Panel1.Controls.Add(this.buoancyGroupBox); this.splitContainer1.Panel1.Controls.Add(this.nameGroupBox); @@ -99,6 +103,24 @@ namespace TBF.UI.Bench.Metrology this.splitContainer1.SplitterDistance = 150; this.splitContainer1.TabIndex = 1; // + // unitLabel + // + this.unitLabel.AutoSize = true; + this.unitLabel.Location = new System.Drawing.Point(507, 116); + this.unitLabel.Name = "unitLabel"; + this.unitLabel.Size = new System.Drawing.Size(68, 13); + this.unitLabel.TabIndex = 12; + this.unitLabel.Text = "Unit of mass:"; + // + // unitComboBox + // + this.unitComboBox.FormattingEnabled = true; + this.unitComboBox.Location = new System.Drawing.Point(592, 113); + this.unitComboBox.Name = "unitComboBox"; + this.unitComboBox.Size = new System.Drawing.Size(62, 21); + this.unitComboBox.TabIndex = 11; + this.unitComboBox.SelectedIndexChanged += new System.EventHandler(this.unitComboBox_SelectedIndexChanged); + // // calibrationGroupBox // this.calibrationGroupBox.Controls.Add(this.calibExpirationDateTimePicker); @@ -315,7 +337,7 @@ namespace TBF.UI.Bench.Metrology // correctedLabel // this.correctedLabel.AutoSize = true; - this.correctedLabel.Location = new System.Drawing.Point(17, 40); + this.correctedLabel.Location = new System.Drawing.Point(11, 40); this.correctedLabel.Name = "correctedLabel"; this.correctedLabel.Size = new System.Drawing.Size(53, 13); this.correctedLabel.TabIndex = 3; @@ -324,7 +346,7 @@ namespace TBF.UI.Bench.Metrology // measuredLabel // this.measuredLabel.AutoSize = true; - this.measuredLabel.Location = new System.Drawing.Point(17, 18); + this.measuredLabel.Location = new System.Drawing.Point(11, 18); this.measuredLabel.Name = "measuredLabel"; this.measuredLabel.Size = new System.Drawing.Size(54, 13); this.measuredLabel.TabIndex = 2; @@ -354,6 +376,7 @@ namespace TBF.UI.Bench.Metrology this.Size = new System.Drawing.Size(668, 400); this.Load += new System.EventHandler(this.MetrologyDlgBalanceTab_Load); this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel1.PerformLayout(); this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); @@ -398,5 +421,7 @@ namespace TBF.UI.Bench.Metrology private System.Windows.Forms.Label calibCertificateNrLabel; private System.Windows.Forms.DateTimePicker calibExpirationDateTimePicker; private System.Windows.Forms.DateTimePicker calibDateTimePicker; + private System.Windows.Forms.Label unitLabel; + private System.Windows.Forms.ComboBox unitComboBox; } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs index 7d3a236f0..2e2233e86 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgBalanceTab.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2020 Sensus Slovensko a.s. +/// Copyright (c) 2013-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -18,16 +18,18 @@ namespace TBF.UI.Bench.Metrology { static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgBalanceTab)); + public const int SignifDigits = 5; + /// /// Component entity that has a list of 'measurement-correction' pairs /// to be updated in the database on OK. /// + Component meterEntity; public Component MeterEntity { get { return meterEntity; } set { meterEntity = value; } } - Component meterEntity; /// /// Balance configuration (with buoyancy parameters) @@ -50,6 +52,8 @@ namespace TBF.UI.Bench.Metrology Control correctionTextBox; Control errorTextBox; + Unit currentUnit; + public MetrologyDlgBalanceTab() { InitializeComponent(); @@ -69,26 +73,41 @@ namespace TBF.UI.Bench.Metrology Localize(); - /// Panel1 + /// Panel1 cmpntNameLabel.Text = meterEntity.Name; - measuredTextBox.Text = string.Empty; - correctedTextBox.Text = string.Empty; + + for (Unit u = 0; u < Unit.Count; u++) + if (Units.IsMass(u)) + unitComboBox.Items.Add(u.ToDescription()); /// Panel2 this.Controls.Add(measurementTextBox = new TextBox()); this.Controls.Add(correctionTextBox = new TextBox()); this.Controls.Add(errorTextBox = new TextBox()); + currentUnit = TBF.Rig.Sequences.ProcessData.MassUnit; + unitComboBox.Text = currentUnit.ToDescription(); + InitializeColumns(listViewEx, currentUnit); + RefreshAll(); + listViewEx.SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked); listViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing); + unitComboBox.SelectedIndexChanged += new System.EventHandler(unitComboBox_SelectedIndexChanged); + } - listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 60 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [kg]", Strings.Mass), Width = 100 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [g]", Strings.Correction), Width = 100 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 }); + void InitializeColumns(ListView lv, Unit unit) + { + lv.Columns.Clear(); + lv.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 40 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Mass, unit.ToDescription()), Width = 120 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Correction, unit.ToDescription()), Width = 150 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 }); - RefreshAll(); - } + measuredLabel.Text = string.Format("{0} [{1}]:", Strings.Measured, unit.ToDescription()); + correctedLabel.Text = string.Format("{0} [{1}]:", Strings.Corrected, unit.ToDescription()); + measuredTextBox.Text = string.Empty; + correctedTextBox.Text = string.Empty; + } void Localize() { @@ -104,10 +123,7 @@ namespace TBF.UI.Bench.Metrology buoyancyHumiLabel.Text = string.Format("{0} [%]", Strings.Ambient_humidity); airDensityLabel.Text = Strings.Air_density_kg_m3; weightStandardDensityLabel.Text = Strings.Ref_mass_dens_kg_m3; - testGroupBox.Text = Strings.Test_measured_corrected; - measuredLabel.Text = Strings.Measured; - correctedLabel.Text = Strings.Corrected; } void RefreshAll() @@ -134,8 +150,12 @@ namespace TBF.UI.Bench.Metrology int nr = listViewEx.Items.Count + 1; ListViewItem lvi = new ListViewItem(nr.ToString()); lvi.Tag = corr; - lvi.SubItems.Add(corr.Measurement.ToString()); - lvi.SubItems.Add((1000 * corr.Correction).ToString()); + lvi.SubItems.Add(Units.ConvertTo(currentUnit, corr.Measurement).ToString()); + double trueValue = corr.Measurement + corr.Correction; + double difference = Units.IsDefaultUnit(currentUnit) + ? corr.Correction + : Units.ConvertTo(currentUnit, trueValue) - Units.ConvertTo(currentUnit, corr.Measurement); + lvi.SubItems.Add(Common.Utils.ToNiceString(difference, SignifDigits)); if (corr.Measurement == 0) { @@ -143,8 +163,8 @@ namespace TBF.UI.Bench.Metrology } else { - double error = Formulas.ErrorFromVolumes(corr.Measurement, corr.Measurement + corr.Correction); - lvi.SubItems.Add(error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5))); + double error = Formulas.ErrorFromVolumes(corr.Measurement, trueValue); + lvi.SubItems.Add(Common.Utils.ToNiceString(error, SignifDigits)); } listViewEx.Items.Add(lvi); @@ -167,13 +187,13 @@ namespace TBF.UI.Bench.Metrology } void listViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e) - { + { if (ParseItem(e.Item, e.SubItem, e.DisplayText)) return; /// New value is NOK, revert the original text - e.DisplayText = e.Item.Text; - e.Cancel = true; - } + e.DisplayText = e.Item.Text; + e.Cancel = true; + } /// /// Parse text of a ListViewItem @@ -181,18 +201,23 @@ namespace TBF.UI.Bench.Metrology /// true = value parsed OK bool ParseItem(ListViewItem item, int subItem, string strValue) { - double dblValue = 0; - if (subItem == 1 && Utils.TryParseEDouble(strValue, out dblValue) && dblValue >= 0) + double oriMeasurement; /// Measurement in selected units + double measurement; /// Measurement in default units + double difference; /// Correction in selected unit + double correction; /// Correction in default unit + double error = 0; + + if (subItem == 1 && Utils.TryParseEDouble(strValue, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) >= 0) { - (item.Tag as MeasurementCorrection).Measurement = (float)dblValue; + (item.Tag as MeasurementCorrection).Measurement = measurement; /// Update error (if possible) - double correction1000; - if (Utils.TryParseEDouble(item.SubItems[2].Text, out correction1000) && (dblValue != 0)) + if (Utils.TryParseEDouble(item.SubItems[2].Text, out difference) && (measurement != 0)) { - double correction = correction1000 / 1000; - double error = Formulas.ErrorFromVolumes(dblValue, dblValue + correction); - item.SubItems[3].Text = error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5)); + correction = Units.IsDefaultUnit(currentUnit) ? difference + : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement); + error = Formulas.ErrorFromVolumes(measurement, measurement + correction); + item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits); } else { @@ -201,39 +226,48 @@ namespace TBF.UI.Bench.Metrology return true; } - else if (subItem == 2 && Utils.TryParseEDouble(strValue, out dblValue)) + else if (subItem == 2 && Utils.TryParseEDouble(strValue, out difference)) { - double correctionInDefaultUnits = dblValue / 1000; - (item.Tag as MeasurementCorrection).Correction = (float)correctionInDefaultUnits; + if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement)) + { + measurement = Units.ConvertFrom(currentUnit, oriMeasurement); + correction = Units.IsDefaultUnit(currentUnit) ? difference + : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement); + (item.Tag as MeasurementCorrection).Correction = correction; - /// Update error (if possible) - double measurement; - if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && (measurement != 0)) - { - double error = Formulas.ErrorFromVolumes(measurement, measurement + correctionInDefaultUnits); - item.SubItems[3].Text = error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5)); - } - else - { - item.SubItems[3].Text = Strings.NaN; - } + /// Update error (if possible) + if (measurement != 0) + { + error = Formulas.ErrorFromVolumes(measurement, measurement + correction); + item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits); + } + else + { + item.SubItems[3].Text = Strings.NaN; + } - return true; + return true; + } + else + { + return false; + } } - else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out dblValue))) + else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out error))) { if (strValue == Strings.NaN) { } else { - double measurement; - if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && measurement != 0) + if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) != 0) { - double correction = Formulas.CorrectionFromError(measurement, dblValue); - double correction1000 = 1000 * correction; - item.SubItems[2].Text = correction1000.ToString(Common.Utils.SignificantDigitsToFmt(correction1000, 5)); - (item.Tag as MeasurementCorrection).Correction = (float)correction; + correction = Formulas.CorrectionFromError(measurement, error); + (item.Tag as MeasurementCorrection).Correction = correction; + difference = Units.IsDefaultUnit(currentUnit) + ? correction + : Units.ConvertTo(currentUnit, measurement + correction) - oriMeasurement; + item.SubItems[2].Text = Common.Utils.ToNiceString(difference, SignifDigits); } } @@ -373,18 +407,21 @@ namespace TBF.UI.Bench.Metrology private void measuredTextBox_TextChanged(object sender, EventArgs e) { - float measured; - if (float.TryParse(measuredTextBox.Text, + double measured; + if (double.TryParse(measuredTextBox.Text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.CurrentCulture, out measured) || - float.TryParse(measuredTextBox.Text, + double.TryParse(measuredTextBox.Text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out measured)) { - double corrected = MeasurementCorrection.CorrectedValue(measured, meterEntity.Corrections); - correctedTextBox.Text = corrected.ToString(); + 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(); } } @@ -401,5 +438,20 @@ namespace TBF.UI.Bench.Metrology { session.SaveOrUpdate(MeterEntity); } + + private void unitComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + for (Unit u = 0; u < Unit.Count; u++) + { + if (u.ToDescription() == unitComboBox.Text) + { + currentUnit = u; + break; + } + } + + InitializeColumns(listViewEx, currentUnit); + RefreshAll(); + } } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.Designer.cs b/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.Designer.cs index 62915ebbf..8f05448de 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.Designer.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.Designer.cs @@ -32,7 +32,11 @@ namespace TBF.UI.Bench.Metrology private void InitializeComponent() { this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.unitLabel = new System.Windows.Forms.Label(); + this.unitComboBox = new System.Windows.Forms.ComboBox(); this.calibrationGroupBox = new System.Windows.Forms.GroupBox(); + this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker(); this.calibValidDateLabel = new System.Windows.Forms.Label(); this.calibDateLabel = new System.Windows.Forms.Label(); this.calibCertificateNrTextBox = new System.Windows.Forms.TextBox(); @@ -47,8 +51,6 @@ namespace TBF.UI.Bench.Metrology this.correctedLabel = new System.Windows.Forms.Label(); this.measuredLabel = new System.Windows.Forms.Label(); this.listViewEx = new Common.Forms.ListViewEx(); - this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker(); - this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -68,6 +70,8 @@ namespace TBF.UI.Bench.Metrology // // splitContainer1.Panel1 // + this.splitContainer1.Panel1.Controls.Add(this.unitLabel); + this.splitContainer1.Panel1.Controls.Add(this.unitComboBox); this.splitContainer1.Panel1.Controls.Add(this.calibrationGroupBox); this.splitContainer1.Panel1.Controls.Add(this.nameGroupBox); this.splitContainer1.Panel1.Controls.Add(this.testGroupBox); @@ -79,6 +83,24 @@ namespace TBF.UI.Bench.Metrology this.splitContainer1.SplitterDistance = 102; this.splitContainer1.TabIndex = 2; // + // unitLabel + // + this.unitLabel.AutoSize = true; + this.unitLabel.Location = new System.Drawing.Point(21, 76); + this.unitLabel.Name = "unitLabel"; + this.unitLabel.Size = new System.Drawing.Size(63, 13); + this.unitLabel.TabIndex = 10; + this.unitLabel.Text = "Unit of flow:"; + // + // unitComboBox + // + this.unitComboBox.FormattingEnabled = true; + this.unitComboBox.Location = new System.Drawing.Point(107, 73); + this.unitComboBox.Name = "unitComboBox"; + this.unitComboBox.Size = new System.Drawing.Size(62, 21); + this.unitComboBox.TabIndex = 9; + this.unitComboBox.SelectedIndexChanged += new System.EventHandler(this.unitComboBox_SelectedIndexChanged); + // // calibrationGroupBox // this.calibrationGroupBox.Controls.Add(this.calibExpirationDateTimePicker); @@ -94,6 +116,26 @@ namespace TBF.UI.Bench.Metrology this.calibrationGroupBox.TabStop = false; this.calibrationGroupBox.Text = "Calibration"; // + // calibExpirationDateTimePicker + // + this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy"; + this.calibExpirationDateTimePicker.Enabled = false; + this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(140, 59); + this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker"; + this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20); + this.calibExpirationDateTimePicker.TabIndex = 19; + // + // calibDateTimePicker + // + this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy"; + this.calibDateTimePicker.Enabled = false; + this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.calibDateTimePicker.Location = new System.Drawing.Point(140, 37); + this.calibDateTimePicker.Name = "calibDateTimePicker"; + this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20); + this.calibDateTimePicker.TabIndex = 18; + // // calibValidDateLabel // this.calibValidDateLabel.AutoSize = true; @@ -136,7 +178,7 @@ namespace TBF.UI.Bench.Metrology this.nameGroupBox.Controls.Add(this.cmpntNameLabel); this.nameGroupBox.Location = new System.Drawing.Point(16, 10); this.nameGroupBox.Name = "nameGroupBox"; - this.nameGroupBox.Size = new System.Drawing.Size(160, 86); + this.nameGroupBox.Size = new System.Drawing.Size(160, 53); this.nameGroupBox.TabIndex = 5; this.nameGroupBox.TabStop = false; this.nameGroupBox.Text = "Component"; @@ -198,7 +240,7 @@ namespace TBF.UI.Bench.Metrology // correctedLabel // this.correctedLabel.AutoSize = true; - this.correctedLabel.Location = new System.Drawing.Point(17, 40); + this.correctedLabel.Location = new System.Drawing.Point(11, 40); this.correctedLabel.Name = "correctedLabel"; this.correctedLabel.Size = new System.Drawing.Size(53, 13); this.correctedLabel.TabIndex = 3; @@ -207,7 +249,7 @@ namespace TBF.UI.Bench.Metrology // measuredLabel // this.measuredLabel.AutoSize = true; - this.measuredLabel.Location = new System.Drawing.Point(17, 18); + this.measuredLabel.Location = new System.Drawing.Point(11, 18); this.measuredLabel.Name = "measuredLabel"; this.measuredLabel.Size = new System.Drawing.Size(54, 13); this.measuredLabel.TabIndex = 2; @@ -228,26 +270,6 @@ namespace TBF.UI.Bench.Metrology this.listViewEx.View = System.Windows.Forms.View.Details; this.listViewEx.SelectedIndexChanged += new System.EventHandler(this.listViewEx_SelectedIndexChanged); // - // calibExpirationDateTimePicker - // - this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy"; - this.calibExpirationDateTimePicker.Enabled = false; - this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(140, 59); - this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker"; - this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20); - this.calibExpirationDateTimePicker.TabIndex = 19; - // - // calibDateTimePicker - // - this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy"; - this.calibDateTimePicker.Enabled = false; - this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.calibDateTimePicker.Location = new System.Drawing.Point(140, 37); - this.calibDateTimePicker.Name = "calibDateTimePicker"; - this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20); - this.calibDateTimePicker.TabIndex = 18; - // // MetrologyDlgFlowMeterTab // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -257,6 +279,7 @@ namespace TBF.UI.Bench.Metrology this.Size = new System.Drawing.Size(650, 400); this.Load += new System.EventHandler(this.MetrologyDlgFlowMeterTab_Load); this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel1.PerformLayout(); this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); @@ -290,6 +313,8 @@ namespace TBF.UI.Bench.Metrology private System.Windows.Forms.Label tempFromToLabel; private System.Windows.Forms.DateTimePicker calibExpirationDateTimePicker; private System.Windows.Forms.DateTimePicker calibDateTimePicker; + private System.Windows.Forms.Label unitLabel; + private System.Windows.Forms.ComboBox unitComboBox; } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs index c91c128d8..2de0ba6da 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgFlowMeterTab.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2019 Sensus Slovensko a.s. +/// Copyright (c) 2013-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -18,6 +18,8 @@ namespace TBF.UI.Bench.Metrology { static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgFlowMeterTab)); + public const int SignifDigits = 5; + /// /// Component entity that has a list of 'measurement-correction' pairs /// to be updated in the database on OK. @@ -52,6 +54,7 @@ namespace TBF.UI.Bench.Metrology readonly int rangeIx; /// 0 (no range) or 1..5 (range #) readonly bool isLastFlowMeterRange; /// true when this is the last range of this flow meter. /// This is to prevent double saving of the meter entity to a DB + Unit currentUnit; public MetrologyDlgFlowMeterTab() : this(0, true) {} @@ -88,28 +91,39 @@ namespace TBF.UI.Bench.Metrology pressFromToLabel.Text = string.Format("{0} {1} {2} {3} bar", Strings.from, CalibInfoCfg.GetPressLo(rangeIx), Strings.to, CalibInfoCfg.GetPressHi(rangeIx)); } - testGroupBox.Text = Strings.Test_measured_corrected; - measuredLabel.Text = Strings.Measured; - correctedLabel.Text = Strings.Corrected; - measuredTextBox.Text = string.Empty; - correctedTextBox.Text = string.Empty; + for (Unit u = 0; u < Unit.Count; u++) + if (Units.IsFlow(u)) + unitComboBox.Items.Add(u.ToDescription()); /// Panel2 this.Controls.Add(measurementTextBox = new TextBox()); this.Controls.Add(correctionTextBox = new TextBox()); this.Controls.Add(errorTextBox = new TextBox()); + currentUnit = TBF.Rig.Sequences.ProcessData.FlowUnit; + unitComboBox.Text = currentUnit.ToDescription(); + InitializeColumns(listViewEx, currentUnit); + RefreshAll(rangeIx); + listViewEx.SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked); listViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing); - - listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 60 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [m3/h]", Strings.Flow), Width = 100 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [l/h]", Strings.Correction), Width = 100 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 }); - - RefreshAll(rangeIx); + unitComboBox.SelectedIndexChanged += new System.EventHandler(unitComboBox_SelectedIndexChanged); } + void InitializeColumns(ListView lv, Unit unit) + { + lv.Columns.Clear(); + lv.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 40 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Flow, unit.ToDescription()), Width = 120 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Correction, unit.ToDescription()), Width = 150 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 }); + + measuredLabel.Text = string.Format("{0} [{1}]:", Strings.Measured, unit.ToDescription()); + correctedLabel.Text = string.Format("{0} [{1}]:", Strings.Corrected, unit.ToDescription()); + measuredTextBox.Text = string.Empty; + correctedTextBox.Text = string.Empty; + } + void Localize() { nameGroupBox.Text = Strings.Component; @@ -118,10 +132,7 @@ namespace TBF.UI.Bench.Metrology calibCertificateNrLabel.Text = Strings.Certificate; calibDateLabel.Text = Strings.Date; calibValidDateLabel.Text = Strings.Valid_until; - testGroupBox.Text = Strings.Test_measured_corrected; - measuredLabel.Text = Strings.Measured; - correctedLabel.Text = Strings.Corrected; } void RefreshAll(int rangeIx1) @@ -145,8 +156,12 @@ namespace TBF.UI.Bench.Metrology int nr = listViewEx.Items.Count + 1; ListViewItem lvi = new ListViewItem(nr.ToString()); lvi.Tag = corr; - lvi.SubItems.Add(corr.Measurement.ToString()); - lvi.SubItems.Add((1000 * corr.Correction).ToString()); + lvi.SubItems.Add(Units.ConvertTo(currentUnit, corr.Measurement).ToString()); + double trueValue = corr.Measurement + corr.Correction; + double difference = Units.IsDefaultUnit(currentUnit) + ? corr.Correction + : Units.ConvertTo(currentUnit, trueValue) - Units.ConvertTo(currentUnit, corr.Measurement); + lvi.SubItems.Add(Common.Utils.ToNiceString(difference, SignifDigits)); if (corr.Measurement == 0) { @@ -154,11 +169,11 @@ namespace TBF.UI.Bench.Metrology } else { - double error = Formulas.ErrorFromVolumes(corr.Measurement, corr.Measurement + corr.Correction); - lvi.SubItems.Add(error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5))); + double error = Formulas.ErrorFromVolumes(corr.Measurement, trueValue); + lvi.SubItems.Add(Common.Utils.ToNiceString(error, SignifDigits)); } - listViewEx.Items.Add(lvi); + listViewEx.Items.Add(lvi); } void listViewEx_SubItemClicked(object sender, SubItemEventArgs e) @@ -175,16 +190,16 @@ namespace TBF.UI.Bench.Metrology { listViewEx.StartEditing(correctionTextBox, e.Item, e.SubItem); } - } + } void listViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e) - { + { if (ParseItem(e.Item, e.SubItem, e.DisplayText)) return; /// New value is NOK, revert the original text - e.DisplayText = e.Item.Text; - e.Cancel = true; - } + e.DisplayText = e.Item.Text; + e.Cancel = true; + } /// /// Parse text of a ListViewItem @@ -192,18 +207,23 @@ namespace TBF.UI.Bench.Metrology /// true = value parsed OK bool ParseItem(ListViewItem item, int subItem, string strValue) { - double dblValue = 0; - if (subItem == 1 && Utils.TryParseEDouble(strValue, out dblValue) && dblValue >= 0) + double oriMeasurement; /// Measurement in selected units + double measurement; /// Measurement in default units + double difference; /// Correction in selected unit + double correction; /// Correction in default unit + double error = 0; + + if (subItem == 1 && Utils.TryParseEDouble(strValue, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) >= 0) { - (item.Tag as MeasurementCorrection).Measurement = (float)dblValue; + (item.Tag as MeasurementCorrection).Measurement = measurement; /// Update error (if possible) - double correction1000; - if (Utils.TryParseEDouble(item.SubItems[2].Text, out correction1000) && (dblValue != 0)) + if (Utils.TryParseEDouble(item.SubItems[2].Text, out difference) && (measurement != 0)) { - double correction = correction1000 / 1000; - double error = Formulas.ErrorFromVolumes(dblValue, dblValue + correction); - item.SubItems[3].Text = error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5)); + correction = Units.IsDefaultUnit(currentUnit) ? difference + : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement); + error = Formulas.ErrorFromVolumes(measurement, measurement + correction); + item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits); } else { @@ -212,39 +232,48 @@ namespace TBF.UI.Bench.Metrology return true; } - else if (subItem == 2 && Utils.TryParseEDouble(strValue, out dblValue)) + else if (subItem == 2 && Utils.TryParseEDouble(strValue, out difference)) { - double correctionInDefaultUnits = dblValue / 1000; - (item.Tag as MeasurementCorrection).Correction = (float)correctionInDefaultUnits; + if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement)) + { + measurement = Units.ConvertFrom(currentUnit, oriMeasurement); + correction = Units.IsDefaultUnit(currentUnit) ? difference + : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement); + (item.Tag as MeasurementCorrection).Correction = correction; - /// Update error (if possible) - double measurement; - if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && (measurement != 0)) - { - double error = Formulas.ErrorFromVolumes(measurement, measurement + correctionInDefaultUnits); - item.SubItems[3].Text = error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5)); - } - else - { - item.SubItems[3].Text = Strings.NaN; - } + /// Update error (if possible) + if (measurement != 0) + { + error = Formulas.ErrorFromVolumes(measurement, measurement + correction); + item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits); + } + else + { + item.SubItems[3].Text = Strings.NaN; + } - return true; + return true; + } + else + { + return false; + } } - else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out dblValue))) + else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out error))) { if (strValue == Strings.NaN) { } else { - double measurement; - if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && measurement != 0) + if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) != 0) { - double correction = Formulas.CorrectionFromError(measurement, dblValue); - double correction1000 = 1000 * correction; - item.SubItems[2].Text = correction1000.ToString(Common.Utils.SignificantDigitsToFmt(correction1000, 5)); - (item.Tag as MeasurementCorrection).Correction = (float)correction; + correction = Formulas.CorrectionFromError(measurement, error); + (item.Tag as MeasurementCorrection).Correction = correction; + difference = Units.IsDefaultUnit(currentUnit) + ? correction + : Units.ConvertTo(currentUnit, measurement + correction) - oriMeasurement; + item.SubItems[2].Text = Common.Utils.ToNiceString(difference, SignifDigits); } } @@ -370,18 +399,21 @@ namespace TBF.UI.Bench.Metrology private void measuredTextBox_TextChanged(object sender, EventArgs e) { - float measured; - if (float.TryParse(measuredTextBox.Text, + double measured; + if (double.TryParse(measuredTextBox.Text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.CurrentCulture, out measured) || - float.TryParse(measuredTextBox.Text, + double.TryParse(measuredTextBox.Text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out measured)) { - double corrected = MeasurementCorrection.CorrectedValue(measured, meterEntity.Corrections); - correctedTextBox.Text = corrected.ToString(); + 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(); } } @@ -403,5 +435,20 @@ namespace TBF.UI.Bench.Metrology session.SaveOrUpdate(MeterEntity); } } + + private void unitComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + for (Unit u = 0; u < Unit.Count; u++) + { + if (u.ToDescription() == unitComboBox.Text) + { + currentUnit = u; + break; + } + } + + InitializeColumns(listViewEx, currentUnit); + RefreshAll(rangeIx); + } } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.Designer.cs b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.Designer.cs index 9f2353bcd..b4f2cb543 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.Designer.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.Designer.cs @@ -32,7 +32,11 @@ namespace TBF.UI.Bench.Metrology private void InitializeComponent() { this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.unitLabel = new System.Windows.Forms.Label(); + this.unitComboBox = new System.Windows.Forms.ComboBox(); this.calibrationGroupBox = new System.Windows.Forms.GroupBox(); + this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker(); this.calibValidDateLabel = new System.Windows.Forms.Label(); this.calibDateLabel = new System.Windows.Forms.Label(); this.calibCertificateNrTextBox = new System.Windows.Forms.TextBox(); @@ -45,8 +49,6 @@ namespace TBF.UI.Bench.Metrology this.componentLabel = new System.Windows.Forms.Label(); this.cmpntNameLabel = new System.Windows.Forms.Label(); this.listViewEx = new Common.Forms.ListViewEx(); - this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker(); - this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -65,6 +67,8 @@ namespace TBF.UI.Bench.Metrology // // splitContainer1.Panel1 // + this.splitContainer1.Panel1.Controls.Add(this.unitLabel); + this.splitContainer1.Panel1.Controls.Add(this.unitComboBox); this.splitContainer1.Panel1.Controls.Add(this.calibrationGroupBox); this.splitContainer1.Panel1.Controls.Add(this.testGroupBox); this.splitContainer1.Panel1.Controls.Add(this.componentLabel); @@ -73,10 +77,28 @@ namespace TBF.UI.Bench.Metrology // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.listViewEx); - this.splitContainer1.Size = new System.Drawing.Size(600, 300); + this.splitContainer1.Size = new System.Drawing.Size(650, 300); this.splitContainer1.SplitterDistance = 110; this.splitContainer1.TabIndex = 2; // + // unitLabel + // + this.unitLabel.AutoSize = true; + this.unitLabel.Location = new System.Drawing.Point(14, 56); + this.unitLabel.Name = "unitLabel"; + this.unitLabel.Size = new System.Drawing.Size(84, 13); + this.unitLabel.TabIndex = 10; + this.unitLabel.Text = "Unit of pressure:"; + // + // unitComboBox + // + this.unitComboBox.FormattingEnabled = true; + this.unitComboBox.Location = new System.Drawing.Point(123, 53); + this.unitComboBox.Name = "unitComboBox"; + this.unitComboBox.Size = new System.Drawing.Size(62, 21); + this.unitComboBox.TabIndex = 9; + this.unitComboBox.SelectedIndexChanged += new System.EventHandler(this.unitComboBox_SelectedIndexChanged); + // // calibrationGroupBox // this.calibrationGroupBox.Controls.Add(this.calibExpirationDateTimePicker); @@ -92,6 +114,26 @@ namespace TBF.UI.Bench.Metrology this.calibrationGroupBox.TabStop = false; this.calibrationGroupBox.Text = "Calibration"; // + // calibExpirationDateTimePicker + // + this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy"; + this.calibExpirationDateTimePicker.Enabled = false; + this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(117, 59); + this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker"; + this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20); + this.calibExpirationDateTimePicker.TabIndex = 19; + // + // calibDateTimePicker + // + this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy"; + this.calibDateTimePicker.Enabled = false; + this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.calibDateTimePicker.Location = new System.Drawing.Point(117, 37); + this.calibDateTimePicker.Name = "calibDateTimePicker"; + this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20); + this.calibDateTimePicker.TabIndex = 18; + // // calibValidDateLabel // this.calibValidDateLabel.AutoSize = true; @@ -113,7 +155,7 @@ namespace TBF.UI.Bench.Metrology // calibCertificateNrTextBox // this.calibCertificateNrTextBox.Enabled = false; - this.calibCertificateNrTextBox.Location = new System.Drawing.Point(120, 15); + this.calibCertificateNrTextBox.Location = new System.Drawing.Point(117, 15); this.calibCertificateNrTextBox.Name = "calibCertificateNrTextBox"; this.calibCertificateNrTextBox.Size = new System.Drawing.Size(82, 20); this.calibCertificateNrTextBox.TabIndex = 11; @@ -135,14 +177,14 @@ namespace TBF.UI.Bench.Metrology this.testGroupBox.Controls.Add(this.measuredLabel); this.testGroupBox.Location = new System.Drawing.Point(428, 12); this.testGroupBox.Name = "testGroupBox"; - this.testGroupBox.Size = new System.Drawing.Size(157, 86); + this.testGroupBox.Size = new System.Drawing.Size(200, 86); this.testGroupBox.TabIndex = 4; this.testGroupBox.TabStop = false; this.testGroupBox.Text = "Test"; // // correctedTextBox // - this.correctedTextBox.Location = new System.Drawing.Point(74, 48); + this.correctedTextBox.Location = new System.Drawing.Point(115, 49); this.correctedTextBox.Name = "correctedTextBox"; this.correctedTextBox.ReadOnly = true; this.correctedTextBox.Size = new System.Drawing.Size(73, 20); @@ -150,7 +192,7 @@ namespace TBF.UI.Bench.Metrology // // measuredTextBox // - this.measuredTextBox.Location = new System.Drawing.Point(74, 23); + this.measuredTextBox.Location = new System.Drawing.Point(115, 24); this.measuredTextBox.Name = "measuredTextBox"; this.measuredTextBox.Size = new System.Drawing.Size(73, 20); this.measuredTextBox.TabIndex = 4; @@ -159,7 +201,7 @@ namespace TBF.UI.Bench.Metrology // correctedLabel // this.correctedLabel.AutoSize = true; - this.correctedLabel.Location = new System.Drawing.Point(7, 51); + this.correctedLabel.Location = new System.Drawing.Point(7, 52); this.correctedLabel.Name = "correctedLabel"; this.correctedLabel.Size = new System.Drawing.Size(53, 13); this.correctedLabel.TabIndex = 3; @@ -168,7 +210,7 @@ namespace TBF.UI.Bench.Metrology // measuredLabel // this.measuredLabel.AutoSize = true; - this.measuredLabel.Location = new System.Drawing.Point(6, 30); + this.measuredLabel.Location = new System.Drawing.Point(7, 27); this.measuredLabel.Name = "measuredLabel"; this.measuredLabel.Size = new System.Drawing.Size(54, 13); this.measuredLabel.TabIndex = 2; @@ -201,39 +243,19 @@ namespace TBF.UI.Bench.Metrology this.listViewEx.GridLines = true; this.listViewEx.Location = new System.Drawing.Point(0, 0); this.listViewEx.Name = "listViewEx"; - this.listViewEx.Size = new System.Drawing.Size(600, 186); + this.listViewEx.Size = new System.Drawing.Size(650, 186); this.listViewEx.TabIndex = 0; this.listViewEx.UseCompatibleStateImageBehavior = false; this.listViewEx.View = System.Windows.Forms.View.Details; this.listViewEx.SelectedIndexChanged += new System.EventHandler(this.listViewEx_SelectedIndexChanged); // - // calibExpirationDateTimePicker - // - this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy"; - this.calibExpirationDateTimePicker.Enabled = false; - this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(120, 59); - this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker"; - this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20); - this.calibExpirationDateTimePicker.TabIndex = 19; - // - // calibDateTimePicker - // - this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy"; - this.calibDateTimePicker.Enabled = false; - this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.calibDateTimePicker.Location = new System.Drawing.Point(120, 37); - this.calibDateTimePicker.Name = "calibDateTimePicker"; - this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20); - this.calibDateTimePicker.TabIndex = 18; - // // MetrologyDlgPressMeterTab // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.splitContainer1); this.Name = "MetrologyDlgPressMeterTab"; - this.Size = new System.Drawing.Size(600, 300); + this.Size = new System.Drawing.Size(650, 300); this.Load += new System.EventHandler(this.MetrologyDlgPressMeterTab_Load); this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel1.PerformLayout(); @@ -266,6 +288,8 @@ namespace TBF.UI.Bench.Metrology private System.Windows.Forms.Label calibCertificateNrLabel; private System.Windows.Forms.DateTimePicker calibExpirationDateTimePicker; private System.Windows.Forms.DateTimePicker calibDateTimePicker; + private System.Windows.Forms.Label unitLabel; + private System.Windows.Forms.ComboBox unitComboBox; } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs index 6a1b7a070..26ab5b8bb 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2020 Sensus Slovensko a.s. +/// Copyright (c) 2013-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -18,6 +18,8 @@ namespace TBF.UI.Bench.Metrology { static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgPressMeterTab)); + public const int SignifDigits = 5; + /// /// Component entity that has a list of 'measurement-correction' pairs /// to be updated in the database on OK. @@ -50,6 +52,8 @@ namespace TBF.UI.Bench.Metrology Control correctionTextBox; Control errorTextBox; + Unit currentUnit; + public MetrologyDlgPressMeterTab() { InitializeComponent(); @@ -69,34 +73,46 @@ namespace TBF.UI.Bench.Metrology Localize(); - /// Panel1 + /// Panel1 cmpntNameLabel.Text = meterEntity.Name; + for (Unit u = 0; u < Unit.Count; u++) + if (Units.IsPressure(u)) + unitComboBox.Items.Add(u.ToDescription()); + /// Panel2 this.Controls.Add(measurementTextBox = new TextBox()); this.Controls.Add(correctionTextBox = new TextBox()); this.Controls.Add(errorTextBox = new TextBox()); + currentUnit = TBF.Rig.Sequences.ProcessData.PressUnit; + unitComboBox.Text = currentUnit.ToDescription(); + InitializeColumns(listViewEx, currentUnit); + RefreshAll(); + listViewEx.SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked); listViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing); + unitComboBox.SelectedIndexChanged += new System.EventHandler(this.unitComboBox_SelectedIndexChanged); + } - listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 60 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [bar]", Strings.Pressure), Width = 100 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [mbar]", Strings.Correction), Width = 100 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 }); + void InitializeColumns(ListView lv, Unit unit) + { + lv.Columns.Clear(); + lv.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 60 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Pressure, unit.ToDescription()), Width = 100 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Correction, unit.ToDescription()), Width = 100 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 }); - RefreshAll(); - } + measuredLabel.Text = string.Format("{0} [{1}]:", Strings.Measured, unit.ToDescription()); + correctedLabel.Text = string.Format("{0} [{1}]:", Strings.Corrected, unit.ToDescription()); + measuredTextBox.Text = string.Empty; + correctedTextBox.Text = string.Empty; + } void Localize() { componentLabel.Text = Strings.Component; testGroupBox.Text = Strings.Test_measured_corrected; - measuredLabel.Text = Strings.Measured; - correctedLabel.Text = Strings.Corrected; - measuredTextBox.Text = string.Empty; - correctedTextBox.Text = string.Empty; - calibrationGroupBox.Text = Strings.Calibration; calibCertificateNrLabel.Text = Strings.Certificate; calibDateLabel.Text = Strings.Date; @@ -121,8 +137,12 @@ namespace TBF.UI.Bench.Metrology int nr = listViewEx.Items.Count + 1; ListViewItem lvi = new ListViewItem(nr.ToString()); lvi.Tag = corr; - lvi.SubItems.Add(corr.Measurement.ToString()); - lvi.SubItems.Add((1000 * corr.Correction).ToString()); + lvi.SubItems.Add(Units.ConvertTo(currentUnit, corr.Measurement).ToString()); + double trueValue = corr.Measurement + corr.Correction; + double difference = Units.IsDefaultUnit(currentUnit) + ? corr.Correction + : Units.ConvertTo(currentUnit, trueValue) - Units.ConvertTo(currentUnit, corr.Measurement); + lvi.SubItems.Add(Common.Utils.ToNiceString(difference, SignifDigits)); if (corr.Measurement == 0) { @@ -130,8 +150,8 @@ namespace TBF.UI.Bench.Metrology } else { - double error = Formulas.ErrorFromVolumes(corr.Measurement, corr.Measurement + corr.Correction); - lvi.SubItems.Add(error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5))); + double error = Formulas.ErrorFromVolumes(corr.Measurement, trueValue); + lvi.SubItems.Add(Common.Utils.ToNiceString(error, SignifDigits)); } listViewEx.Items.Add(lvi); @@ -168,18 +188,23 @@ namespace TBF.UI.Bench.Metrology /// true = value parsed OK bool ParseItem(ListViewItem item, int subItem, string strValue) { - double dblValue = 0; - if (subItem == 1 && Utils.TryParseEDouble(strValue, out dblValue) && dblValue >= 0) + double oriMeasurement; /// Measurement in selected units + double measurement; /// Measurement in default units + double difference; /// Correction in selected unit + double correction; /// Correction in default unit + double error = 0; + + if (subItem == 1 && Utils.TryParseEDouble(strValue, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) >= 0) { - (item.Tag as MeasurementCorrection).Measurement = (float)dblValue; + (item.Tag as MeasurementCorrection).Measurement = measurement; /// Update error (if possible) - double correction1000; - if (Utils.TryParseEDouble(item.SubItems[2].Text, out correction1000) && (dblValue != 0)) + if (Utils.TryParseEDouble(item.SubItems[2].Text, out difference) && (measurement != 0)) { - double correction = correction1000 / 1000; - double error = Formulas.ErrorFromVolumes(dblValue, dblValue + correction); - item.SubItems[3].Text = error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5)); + correction = Units.IsDefaultUnit(currentUnit) ? difference + : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement); + error = Formulas.ErrorFromVolumes(measurement, measurement + correction); + item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits); } else { @@ -188,39 +213,48 @@ namespace TBF.UI.Bench.Metrology return true; } - else if (subItem == 2 && Utils.TryParseEDouble(strValue, out dblValue)) + else if (subItem == 2 && Utils.TryParseEDouble(strValue, out difference)) { - double correctionInDefaultUnits = dblValue / 1000; - (item.Tag as MeasurementCorrection).Correction = (float)correctionInDefaultUnits; + if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement)) + { + measurement = Units.ConvertFrom(currentUnit, oriMeasurement); + correction = Units.IsDefaultUnit(currentUnit) ? difference + : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement); + (item.Tag as MeasurementCorrection).Correction = correction; - /// Update error (if possible) - double measurement; - if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && (measurement != 0)) - { - double error = Formulas.ErrorFromVolumes(measurement, measurement + correctionInDefaultUnits); - item.SubItems[3].Text = error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5)); - } - else - { - item.SubItems[3].Text = Strings.NaN; - } + /// Update error (if possible) + if (measurement != 0) + { + error = Formulas.ErrorFromVolumes(measurement, measurement + correction); + item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits); + } + else + { + item.SubItems[3].Text = Strings.NaN; + } - return true; + return true; + } + else + { + return false; + } } - else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out dblValue))) + else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out error))) { if (strValue == Strings.NaN) { } else { - double measurement; - if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && measurement != 0) + if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) != 0) { - double correction = Formulas.CorrectionFromError(measurement, dblValue); - double correction1000 = 1000 * correction; - item.SubItems[2].Text = correction1000.ToString(Common.Utils.SignificantDigitsToFmt(correction1000, 5)); - (item.Tag as MeasurementCorrection).Correction = (float)correction; + correction = Formulas.CorrectionFromError(measurement, error); + (item.Tag as MeasurementCorrection).Correction = correction; + difference = Units.IsDefaultUnit(currentUnit) + ? correction + : Units.ConvertTo(currentUnit, measurement + correction) - oriMeasurement; + item.SubItems[2].Text = Common.Utils.ToNiceString(difference, SignifDigits); } } @@ -350,18 +384,21 @@ namespace TBF.UI.Bench.Metrology private void measuredTextBox_TextChanged(object sender, EventArgs e) { - float measured; - if (float.TryParse(measuredTextBox.Text, + double measured; + if (double.TryParse(measuredTextBox.Text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.CurrentCulture, out measured) || - float.TryParse(measuredTextBox.Text, + double.TryParse(measuredTextBox.Text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out measured)) { - double corrected = MeasurementCorrection.CorrectedValue(measured, meterEntity.Corrections); - correctedTextBox.Text = corrected.ToString(); + 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(); } } @@ -378,5 +415,20 @@ namespace TBF.UI.Bench.Metrology { session.SaveOrUpdate(MeterEntity); } + + private void unitComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + for (Unit u = 0; u < Unit.Count; u++) + { + if (u.ToDescription() == unitComboBox.Text) + { + currentUnit = u; + break; + } + } + + InitializeColumns(listViewEx, currentUnit); + RefreshAll(); + } } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.Designer.cs b/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.Designer.cs index 278383285..1e40e27a9 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.Designer.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.Designer.cs @@ -32,7 +32,11 @@ namespace TBF.UI.Bench.Metrology private void InitializeComponent() { this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.unitLabel = new System.Windows.Forms.Label(); + this.unitComboBox = new System.Windows.Forms.ComboBox(); this.calibrationGroupBox = new System.Windows.Forms.GroupBox(); + this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker(); this.calibValidDateLabel = new System.Windows.Forms.Label(); this.calibDateLabel = new System.Windows.Forms.Label(); this.calibCertificateNrTextBox = new System.Windows.Forms.TextBox(); @@ -45,8 +49,6 @@ namespace TBF.UI.Bench.Metrology this.componentLabel = new System.Windows.Forms.Label(); this.cmpntNameLabel = new System.Windows.Forms.Label(); this.listViewEx = new Common.Forms.ListViewEx(); - this.calibExpirationDateTimePicker = new System.Windows.Forms.DateTimePicker(); - this.calibDateTimePicker = new System.Windows.Forms.DateTimePicker(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -65,6 +67,8 @@ namespace TBF.UI.Bench.Metrology // // splitContainer1.Panel1 // + this.splitContainer1.Panel1.Controls.Add(this.unitLabel); + this.splitContainer1.Panel1.Controls.Add(this.unitComboBox); this.splitContainer1.Panel1.Controls.Add(this.calibrationGroupBox); this.splitContainer1.Panel1.Controls.Add(this.testGroupBox); this.splitContainer1.Panel1.Controls.Add(this.componentLabel); @@ -73,10 +77,27 @@ namespace TBF.UI.Bench.Metrology // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.listViewEx); - this.splitContainer1.Size = new System.Drawing.Size(600, 300); + this.splitContainer1.Size = new System.Drawing.Size(650, 300); this.splitContainer1.SplitterDistance = 110; this.splitContainer1.TabIndex = 2; // + // unitLabel + // + this.unitLabel.AutoSize = true; + this.unitLabel.Location = new System.Drawing.Point(14, 60); + this.unitLabel.Name = "unitLabel"; + this.unitLabel.Size = new System.Drawing.Size(100, 13); + this.unitLabel.TabIndex = 8; + this.unitLabel.Text = "Unit of temperature:"; + // + // unitComboBox + // + this.unitComboBox.FormattingEnabled = true; + this.unitComboBox.Location = new System.Drawing.Point(123, 57); + this.unitComboBox.Name = "unitComboBox"; + this.unitComboBox.Size = new System.Drawing.Size(62, 21); + this.unitComboBox.TabIndex = 1; + // // calibrationGroupBox // this.calibrationGroupBox.Controls.Add(this.calibExpirationDateTimePicker); @@ -92,6 +113,26 @@ namespace TBF.UI.Bench.Metrology this.calibrationGroupBox.TabStop = false; this.calibrationGroupBox.Text = "Calibration"; // + // calibExpirationDateTimePicker + // + this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy"; + this.calibExpirationDateTimePicker.Enabled = false; + this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(117, 59); + this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker"; + this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20); + this.calibExpirationDateTimePicker.TabIndex = 19; + // + // calibDateTimePicker + // + this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy"; + this.calibDateTimePicker.Enabled = false; + this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.calibDateTimePicker.Location = new System.Drawing.Point(117, 37); + this.calibDateTimePicker.Name = "calibDateTimePicker"; + this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20); + this.calibDateTimePicker.TabIndex = 18; + // // calibValidDateLabel // this.calibValidDateLabel.AutoSize = true; @@ -113,7 +154,7 @@ namespace TBF.UI.Bench.Metrology // calibCertificateNrTextBox // this.calibCertificateNrTextBox.Enabled = false; - this.calibCertificateNrTextBox.Location = new System.Drawing.Point(120, 15); + this.calibCertificateNrTextBox.Location = new System.Drawing.Point(117, 15); this.calibCertificateNrTextBox.Name = "calibCertificateNrTextBox"; this.calibCertificateNrTextBox.Size = new System.Drawing.Size(82, 20); this.calibCertificateNrTextBox.TabIndex = 11; @@ -135,14 +176,14 @@ namespace TBF.UI.Bench.Metrology this.testGroupBox.Controls.Add(this.measuredLabel); this.testGroupBox.Location = new System.Drawing.Point(428, 12); this.testGroupBox.Name = "testGroupBox"; - this.testGroupBox.Size = new System.Drawing.Size(157, 86); + this.testGroupBox.Size = new System.Drawing.Size(200, 86); this.testGroupBox.TabIndex = 4; this.testGroupBox.TabStop = false; this.testGroupBox.Text = "Test"; // // correctedTextBox // - this.correctedTextBox.Location = new System.Drawing.Point(74, 49); + this.correctedTextBox.Location = new System.Drawing.Point(115, 49); this.correctedTextBox.Name = "correctedTextBox"; this.correctedTextBox.ReadOnly = true; this.correctedTextBox.Size = new System.Drawing.Size(73, 20); @@ -150,7 +191,7 @@ namespace TBF.UI.Bench.Metrology // // measuredTextBox // - this.measuredTextBox.Location = new System.Drawing.Point(74, 24); + this.measuredTextBox.Location = new System.Drawing.Point(115, 24); this.measuredTextBox.Name = "measuredTextBox"; this.measuredTextBox.Size = new System.Drawing.Size(73, 20); this.measuredTextBox.TabIndex = 4; @@ -168,7 +209,7 @@ namespace TBF.UI.Bench.Metrology // measuredLabel // this.measuredLabel.AutoSize = true; - this.measuredLabel.Location = new System.Drawing.Point(6, 31); + this.measuredLabel.Location = new System.Drawing.Point(7, 27); this.measuredLabel.Name = "measuredLabel"; this.measuredLabel.Size = new System.Drawing.Size(54, 13); this.measuredLabel.TabIndex = 2; @@ -201,39 +242,19 @@ namespace TBF.UI.Bench.Metrology this.listViewEx.GridLines = true; this.listViewEx.Location = new System.Drawing.Point(0, 0); this.listViewEx.Name = "listViewEx"; - this.listViewEx.Size = new System.Drawing.Size(600, 186); + this.listViewEx.Size = new System.Drawing.Size(650, 186); this.listViewEx.TabIndex = 0; this.listViewEx.UseCompatibleStateImageBehavior = false; this.listViewEx.View = System.Windows.Forms.View.Details; this.listViewEx.SelectedIndexChanged += new System.EventHandler(this.listViewEx_SelectedIndexChanged); // - // calibExpirationDateTimePicker - // - this.calibExpirationDateTimePicker.CustomFormat = "dd.MM.yyyy"; - this.calibExpirationDateTimePicker.Enabled = false; - this.calibExpirationDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.calibExpirationDateTimePicker.Location = new System.Drawing.Point(120, 59); - this.calibExpirationDateTimePicker.Name = "calibExpirationDateTimePicker"; - this.calibExpirationDateTimePicker.Size = new System.Drawing.Size(82, 20); - this.calibExpirationDateTimePicker.TabIndex = 19; - // - // calibDateTimePicker - // - this.calibDateTimePicker.CustomFormat = "dd.MM.yyyy"; - this.calibDateTimePicker.Enabled = false; - this.calibDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.calibDateTimePicker.Location = new System.Drawing.Point(120, 37); - this.calibDateTimePicker.Name = "calibDateTimePicker"; - this.calibDateTimePicker.Size = new System.Drawing.Size(82, 20); - this.calibDateTimePicker.TabIndex = 18; - // // MetrologyDlgTempMeterTab // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.splitContainer1); this.Name = "MetrologyDlgTempMeterTab"; - this.Size = new System.Drawing.Size(600, 300); + this.Size = new System.Drawing.Size(650, 300); this.Load += new System.EventHandler(this.MetrologyDlgTempMeterTab_Load); this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel1.PerformLayout(); @@ -266,6 +287,8 @@ namespace TBF.UI.Bench.Metrology private System.Windows.Forms.Label calibCertificateNrLabel; private System.Windows.Forms.DateTimePicker calibExpirationDateTimePicker; private System.Windows.Forms.DateTimePicker calibDateTimePicker; + private System.Windows.Forms.Label unitLabel; + private System.Windows.Forms.ComboBox unitComboBox; } } diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs index 3bb57b5d7..aa27086fc 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgTempMeterTab.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2017-2020 Sensus Slovensko a.s. +/// Copyright (c) 2017-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -18,6 +18,8 @@ namespace TBF.UI.Bench.Metrology { static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgTempMeterTab)); + public const int SignifDigits = 5; + /// /// Component entity that has a list of 'measurement-correction' pairs /// to be updated in the database on OK. @@ -30,7 +32,7 @@ namespace TBF.UI.Bench.Metrology } /// - /// Balance configuration (with buoyancy parameters) + /// Calibration information configuration /// public Rig.GenericDevices.ICalibInfoCfg CalibInfoCfg; @@ -50,6 +52,8 @@ namespace TBF.UI.Bench.Metrology Control correctionTextBox; Control errorTextBox; + Unit currentUnit; + public MetrologyDlgTempMeterTab() { InitializeComponent(); @@ -58,8 +62,8 @@ namespace TBF.UI.Bench.Metrology calibExpirationDateTimePicker.CustomFormat = Constants.DateFormat; calibExpirationDateTimePicker.MinDate = Constants.MinDate; toBeRemoved = new List(); - unlocked = false; - } + unlocked = false; + } private void MetrologyDlgTempMeterTab_Load(object sender, System.EventArgs e) { @@ -72,31 +76,43 @@ namespace TBF.UI.Bench.Metrology /// Panel1 cmpntNameLabel.Text = meterEntity.Name; + for (Unit u = 0; u < Unit.Count; u++) + if (Units.IsTemperature(u)) + unitComboBox.Items.Add(u.ToDescription()); + /// Panel2 this.Controls.Add(measurementTextBox = new TextBox()); this.Controls.Add(correctionTextBox = new TextBox()); this.Controls.Add(errorTextBox = new TextBox()); + currentUnit = TBF.Rig.Sequences.ProcessData.TempUnit; + unitComboBox.Text = currentUnit.ToDescription(); + InitializeColumns(listViewEx, currentUnit); + RefreshAll(); + listViewEx.SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked); listViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing); - - listViewEx.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 40 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [°C]", Strings.Temperature), Width = 120 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [1/1000 °C]", Strings.Correction), Width = 150 }); - listViewEx.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 }); - - RefreshAll(); + unitComboBox.SelectedIndexChanged += new System.EventHandler(unitComboBox_SelectedIndexChanged); } + void InitializeColumns(ListView lv, Unit unit) + { + lv.Columns.Clear(); + lv.Columns.Add(new ColumnHeader() { Text = Strings.Nr, Width = 40 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Temperature, unit.ToDescription()), Width = 120 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [{1}]", Strings.Correction, unit.ToDescription()), Width = 150 }); + lv.Columns.Add(new ColumnHeader() { Text = string.Format("{0} [%]", Strings.Error), Width = 100 }); + + measuredLabel.Text = string.Format("{0} [{1}]:", Strings.Measured, unit.ToDescription()); + correctedLabel.Text = string.Format("{0} [{1}]:", Strings.Corrected, unit.ToDescription()); + measuredTextBox.Text = string.Empty; + correctedTextBox.Text = string.Empty; + } + void Localize() { componentLabel.Text = Strings.Component; testGroupBox.Text = Strings.Test_measured_corrected; - measuredLabel.Text = Strings.Measured; - correctedLabel.Text = Strings.Corrected; - measuredTextBox.Text = string.Empty; - correctedTextBox.Text = string.Empty; - calibrationGroupBox.Text = Strings.Calibration; calibCertificateNrLabel.Text = Strings.Certificate; calibDateLabel.Text = Strings.Date; @@ -112,7 +128,7 @@ namespace TBF.UI.Bench.Metrology calibExpirationDateTimePicker.Value = (CalibInfoCfg.CalibValidDate < Constants.MinDate) ? Constants.MinDate : CalibInfoCfg.CalibValidDate; } - listViewEx.Items.Clear(); + listViewEx.Items.Clear(); foreach (var corr in MeterEntity.Corrections) AddOneLVI(corr); } @@ -121,8 +137,12 @@ namespace TBF.UI.Bench.Metrology int nr = listViewEx.Items.Count + 1; ListViewItem lvi = new ListViewItem(nr.ToString()); lvi.Tag = corr; - lvi.SubItems.Add(corr.Measurement.ToString()); - lvi.SubItems.Add((1000 * corr.Correction).ToString()); + lvi.SubItems.Add(Units.ConvertTo(currentUnit, corr.Measurement).ToString()); + double trueValue = corr.Measurement + corr.Correction; + double difference = Units.IsDefaultUnit(currentUnit) + ? corr.Correction + : Units.ConvertTo(currentUnit, trueValue) - Units.ConvertTo(currentUnit, corr.Measurement); + lvi.SubItems.Add(Common.Utils.ToNiceString(difference, SignifDigits)); if (corr.Measurement == 0) { @@ -130,8 +150,8 @@ namespace TBF.UI.Bench.Metrology } else { - double error = Formulas.ErrorFromVolumes(corr.Measurement, corr.Measurement + corr.Correction); - lvi.SubItems.Add(error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5))); + double error = Formulas.ErrorFromVolumes(corr.Measurement, trueValue); + lvi.SubItems.Add(Common.Utils.ToNiceString(error, SignifDigits)); } listViewEx.Items.Add(lvi); @@ -168,18 +188,23 @@ namespace TBF.UI.Bench.Metrology /// true = value parsed OK bool ParseItem(ListViewItem item, int subItem, string strValue) { - double dblValue = 0; - if (subItem == 1 && Utils.TryParseEDouble(strValue, out dblValue) && dblValue >= 0) + double oriMeasurement; /// Measurement in selected units + double measurement; /// Measurement in default units + double difference; /// Correction in selected unit + double correction; /// Correction in default unit + double error = 0; + + if (subItem == 1 && Utils.TryParseEDouble(strValue, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) >= 0) { - (item.Tag as MeasurementCorrection).Measurement = (float)dblValue; + (item.Tag as MeasurementCorrection).Measurement = measurement; /// Update error (if possible) - double correction1000; - if (Utils.TryParseEDouble(item.SubItems[2].Text, out correction1000) && (dblValue != 0)) + if (Utils.TryParseEDouble(item.SubItems[2].Text, out difference) && (measurement != 0)) { - double correction = correction1000 / 1000; - double error = Formulas.ErrorFromVolumes(dblValue, dblValue + correction); - item.SubItems[3].Text = error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5)); + correction = Units.IsDefaultUnit(currentUnit) ? difference + : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement); + error = Formulas.ErrorFromVolumes(measurement, measurement + correction); + item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits); } else { @@ -188,39 +213,48 @@ namespace TBF.UI.Bench.Metrology return true; } - else if (subItem == 2 && Utils.TryParseEDouble(strValue, out dblValue)) + else if (subItem == 2 && Utils.TryParseEDouble(strValue, out difference)) { - double correctionInDefaultUnits = dblValue / 1000; - (item.Tag as MeasurementCorrection).Correction = (float)correctionInDefaultUnits; + if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement)) + { + measurement = Units.ConvertFrom(currentUnit, oriMeasurement); + correction = Units.IsDefaultUnit(currentUnit) ? difference + : Units.ConvertFrom(currentUnit, oriMeasurement + difference) - Units.ConvertFrom(currentUnit, oriMeasurement); + (item.Tag as MeasurementCorrection).Correction = correction; - /// Update error (if possible) - double measurement; - if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && (measurement != 0)) - { - double error = Formulas.ErrorFromVolumes(measurement, measurement + correctionInDefaultUnits); - item.SubItems[3].Text = error.ToString(Common.Utils.SignificantDigitsToFmt(error, 5)); - } - else - { - item.SubItems[3].Text = Strings.NaN; - } + /// Update error (if possible) + if (measurement != 0) + { + error = Formulas.ErrorFromVolumes(measurement, measurement + correction); + item.SubItems[3].Text = Common.Utils.ToNiceString(error, SignifDigits); + } + else + { + item.SubItems[3].Text = Strings.NaN; + } - return true; + return true; + } + else + { + return false; + } } - else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out dblValue))) + else if (subItem == 3 && ((strValue == Strings.NaN) || Utils.TryParseEDouble(strValue, out error))) { if (strValue == Strings.NaN) { } else { - double measurement; - if (Utils.TryParseEDouble(item.SubItems[1].Text, out measurement) && measurement != 0) + if (Utils.TryParseEDouble(item.SubItems[1].Text, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) != 0) { - double correction = Formulas.CorrectionFromError(measurement, dblValue); - double correction1000 = 1000 * correction; - item.SubItems[2].Text = correction1000.ToString(Common.Utils.SignificantDigitsToFmt(correction1000, 5)); - (item.Tag as MeasurementCorrection).Correction = (float)correction; + correction = Formulas.CorrectionFromError(measurement, error); + (item.Tag as MeasurementCorrection).Correction = correction; + difference = Units.IsDefaultUnit(currentUnit) + ? correction + : Units.ConvertTo(currentUnit, measurement + correction) - oriMeasurement; + item.SubItems[2].Text = Common.Utils.ToNiceString(difference, SignifDigits); } } @@ -350,18 +384,21 @@ namespace TBF.UI.Bench.Metrology private void measuredTextBox_TextChanged(object sender, EventArgs e) { - float measured; - if (float.TryParse(measuredTextBox.Text, + double measured; + if (double.TryParse(measuredTextBox.Text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.CurrentCulture, out measured) || - float.TryParse(measuredTextBox.Text, + double.TryParse(measuredTextBox.Text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out measured)) { - double corrected = MeasurementCorrection.CorrectedValue(measured, meterEntity.Corrections); - correctedTextBox.Text = corrected.ToString(); + 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(); } } @@ -378,5 +415,20 @@ namespace TBF.UI.Bench.Metrology { session.SaveOrUpdate(MeterEntity); } + + private void unitComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + for (Unit u = 0; u < Unit.Count; u++) + { + if (u.ToDescription() == unitComboBox.Text) + { + currentUnit = u; + break; + } + } + + InitializeColumns(listViewEx, currentUnit); + RefreshAll(); + } } }