From 047ad0402e2fe88959b2f14b28a681e39d791198 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Fri, 15 May 2015 15:06:06 +0200 Subject: [PATCH] Correction for real water density used in all methods, in Metrology UI. --- TestBenchFramework/BenchControl/Formulas.cs | 19 ++- TestBenchFramework/LocalSettings.cs | 4 +- TestBenchFramework/MetrologyDlg.cs | 20 ++- .../Resources/Strings.Designer.cs | 27 ++++ TestBenchFramework/Resources/Strings.resx | 9 ++ TestBenchFramework/TBF.csproj | 9 ++ .../MetrologyDlgDensityTab.Designer.cs | 120 ++++++++++++++++++ .../UiControls/MetrologyDlgDensityTab.cs | 108 ++++++++++++++++ .../UiControls/MetrologyDlgDensityTab.resx | 120 ++++++++++++++++++ 9 files changed, 431 insertions(+), 5 deletions(-) create mode 100644 TestBenchFramework/UiControls/MetrologyDlgDensityTab.Designer.cs create mode 100644 TestBenchFramework/UiControls/MetrologyDlgDensityTab.cs create mode 100644 TestBenchFramework/UiControls/MetrologyDlgDensityTab.resx diff --git a/TestBenchFramework/BenchControl/Formulas.cs b/TestBenchFramework/BenchControl/Formulas.cs index 2eea716d8..dfde1e5a6 100644 --- a/TestBenchFramework/BenchControl/Formulas.cs +++ b/TestBenchFramework/BenchControl/Formulas.cs @@ -9,11 +9,11 @@ namespace TBF.BenchControl public static class Formulas { /// - /// Calculate water density from temperature + /// Calculate density of distilled water from temperature /// /// Temperature in [degC] /// Density in [kg/m3] - public static float WaterDensityFromTemp(float t) + public static float DistilledWaterDensityFromTemp(float t) { double tt = (double)t; const double a0 = 999.842594; @@ -26,6 +26,21 @@ namespace TBF.BenchControl return (float)(((((a5 * tt + a4) * tt + a3) * tt + a2) * tt + a1) * tt + a0); } + /// + /// Calculate corrected (real) water density from temperature + /// + /// Temperature in [degC] + /// Density in [kg/m3] + public static float WaterDensityFromTemp(float t) + { + float realDensity = Program.LocalSettings.RealDensity; + float atTemperature = Program.LocalSettings.AtTemperature; + + float c_rho = realDensity / DistilledWaterDensityFromTemp(atTemperature); + + return c_rho * DistilledWaterDensityFromTemp(t); + } + public static float AirDensityFromAmbientVales(float tempC, float pressureBar, float humiPct) { diff --git a/TestBenchFramework/LocalSettings.cs b/TestBenchFramework/LocalSettings.cs index bb5777dd8..4bc1eb68c 100644 --- a/TestBenchFramework/LocalSettings.cs +++ b/TestBenchFramework/LocalSettings.cs @@ -43,9 +43,11 @@ namespace TBF /// [XmlElementAttribute("LastProcedure")] public string LastProcedureName; - public int BatchNr; + public float RealDensity; + public float AtTemperature; + public int RightPaneHorizSplitterDistance; /// MainWnd diff --git a/TestBenchFramework/MetrologyDlg.cs b/TestBenchFramework/MetrologyDlg.cs index 31f00eae1..31214099e 100644 --- a/TestBenchFramework/MetrologyDlg.cs +++ b/TestBenchFramework/MetrologyDlg.cs @@ -44,6 +44,7 @@ namespace TBF Text = Strings.Metrology; + int fixedCount = 0; int balancesCount = 0; int flowMetersCount = 0; int pressMetersCount = 0; @@ -52,10 +53,20 @@ namespace TBF cmpntEntities = session.CreateQuery("FROM Component ORDER BY ItemNr") .List(); + // Density tab-page + fixedCount++; + TabPage dstyTabPage = new TabPage(" " + Strings.Density + " "); + MetrologyDlgDensityTab uiCtl = new MetrologyDlgDensityTab(); + uiCtl.Dock = DockStyle.Fill; + dstyTabPage.Tag = uiCtl; + dstyTabPage.Controls.Add(uiCtl); + metrologyTabControl.TabPages.Add(dstyTabPage); + foreach (var cmpnt in cmpntEntities) { BenchControl.Generic.IComponentFactory factory = TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName); + // Balance tab-pages if (factory is BenchControl.MettlerToledo.Standard.BalanceFactory || factory is BenchControl.MettlerToledo.Standard.BalanceNewFactory) { @@ -68,6 +79,7 @@ namespace TBF tabPage.Controls.Add(uiControl); metrologyTabControl.TabPages.Add(tabPage); } + // Flowmeter tab-pages if (factory is BenchControl.Elde.FlowMeter.FlowMeterFactory) { flowMetersCount++; @@ -79,6 +91,7 @@ namespace TBF tabPage.Controls.Add(uiControl); metrologyTabControl.TabPages.Add(tabPage); } + // Pressure meter tab-pages if (factory is BenchControl.Elde.PressureMeter.PressureMeterFactory) { pressMetersCount++; @@ -107,8 +120,11 @@ namespace TBF { IMetrologyDlgTab tab = tabPage.Tag as IMetrologyDlgTab; tab.OkBtnClicked(); - FluentCommon.SaveToDb(session, tab.MeterEntity); - foreach (var entity in tab.ToBeRemoved) FluentCommon.DeleteFromDb(session, entity); + if (!(tabPage.Tag is MetrologyDlgDensityTab)) + { + FluentCommon.SaveToDb(session, tab.MeterEntity); + foreach (var entity in tab.ToBeRemoved) FluentCommon.DeleteFromDb(session, entity); + } } Program.LocalSettings.MetrologyDlgLeft = Location.X; diff --git a/TestBenchFramework/Resources/Strings.Designer.cs b/TestBenchFramework/Resources/Strings.Designer.cs index efff4ffab..eefe3d316 100644 --- a/TestBenchFramework/Resources/Strings.Designer.cs +++ b/TestBenchFramework/Resources/Strings.Designer.cs @@ -186,6 +186,15 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to @temperature [degC]. + /// + internal static string AtTemperature_C { + get { + return ResourceManager.GetString("AtTemperature_C", resourceCulture); + } + } + /// /// Looks up a localized string similar to Aux Water Meter. /// @@ -537,6 +546,24 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Density. + /// + internal static string Density { + get { + return ResourceManager.GetString("Density", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Density [kg/liter]. + /// + internal static string Density_kgLtr { + get { + return ResourceManager.GetString("Density_kgLtr", resourceCulture); + } + } + /// /// Looks up a localized string similar to Description. /// diff --git a/TestBenchFramework/Resources/Strings.resx b/TestBenchFramework/Resources/Strings.resx index 9e27d29e8..8d515ad6e 100644 --- a/TestBenchFramework/Resources/Strings.resx +++ b/TestBenchFramework/Resources/Strings.resx @@ -1033,4 +1033,13 @@ Start + + @temperature [degC] + + + Density [kg/liter] + + + Density + \ No newline at end of file diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index 97a05c9b3..c88410134 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -1055,6 +1055,12 @@ + + UserControl + + + MetrologyDlgDensityTab.cs + UserControl @@ -1486,6 +1492,9 @@ CameraPictureCtrl.cs + + MetrologyDlgDensityTab.cs + MetrologyDlgFlowMeterTab.cs diff --git a/TestBenchFramework/UiControls/MetrologyDlgDensityTab.Designer.cs b/TestBenchFramework/UiControls/MetrologyDlgDensityTab.Designer.cs new file mode 100644 index 000000000..c7e9e6ea3 --- /dev/null +++ b/TestBenchFramework/UiControls/MetrologyDlgDensityTab.Designer.cs @@ -0,0 +1,120 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +namespace TBF.UiControls +{ + partial class MetrologyDlgDensityTab + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.temperatureTextBox = new System.Windows.Forms.TextBox(); + this.temperatureLabel = new System.Windows.Forms.Label(); + this.densityTextBox = new System.Windows.Forms.TextBox(); + this.densityLabel = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.temperatureTextBox); + this.splitContainer1.Panel1.Controls.Add(this.temperatureLabel); + this.splitContainer1.Panel1.Controls.Add(this.densityTextBox); + this.splitContainer1.Panel1.Controls.Add(this.densityLabel); + this.splitContainer1.Size = new System.Drawing.Size(420, 300); + this.splitContainer1.SplitterDistance = 80; + this.splitContainer1.TabIndex = 1; + // + // temperatureTextBox + // + this.temperatureTextBox.Enabled = false; + this.temperatureTextBox.Location = new System.Drawing.Point(159, 43); + this.temperatureTextBox.Name = "temperatureTextBox"; + this.temperatureTextBox.Size = new System.Drawing.Size(100, 20); + this.temperatureTextBox.TabIndex = 3; + // + // temperatureLabel + // + this.temperatureLabel.AutoSize = true; + this.temperatureLabel.Location = new System.Drawing.Point(37, 46); + this.temperatureLabel.Name = "temperatureLabel"; + this.temperatureLabel.Size = new System.Drawing.Size(112, 13); + this.temperatureLabel.TabIndex = 2; + this.temperatureLabel.Text = "@Temperature [degC]"; + // + // densityTextBox + // + this.densityTextBox.Enabled = false; + this.densityTextBox.Location = new System.Drawing.Point(159, 17); + this.densityTextBox.Name = "densityTextBox"; + this.densityTextBox.Size = new System.Drawing.Size(100, 20); + this.densityTextBox.TabIndex = 1; + // + // densityLabel + // + this.densityLabel.AutoSize = true; + this.densityLabel.Location = new System.Drawing.Point(37, 20); + this.densityLabel.Name = "densityLabel"; + this.densityLabel.Size = new System.Drawing.Size(84, 13); + this.densityLabel.TabIndex = 0; + this.densityLabel.Text = "Density [kg/liter]"; + // + // MetrologyDlgDensityTab + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.splitContainer1); + this.Name = "MetrologyDlgDensityTab"; + this.Size = new System.Drawing.Size(420, 300); + this.Load += new System.EventHandler(this.MetrologyDlgDensityTab_Load); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.TextBox temperatureTextBox; + private System.Windows.Forms.Label temperatureLabel; + private System.Windows.Forms.TextBox densityTextBox; + private System.Windows.Forms.Label densityLabel; + } +} diff --git a/TestBenchFramework/UiControls/MetrologyDlgDensityTab.cs b/TestBenchFramework/UiControls/MetrologyDlgDensityTab.cs new file mode 100644 index 000000000..5cfab4eaf --- /dev/null +++ b/TestBenchFramework/UiControls/MetrologyDlgDensityTab.cs @@ -0,0 +1,108 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Windows.Forms; +using log4net; +using TBF.Resources; + +namespace TBF.UiControls +{ + public partial class MetrologyDlgDensityTab : UserControl, IMetrologyDlgTab + { + static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgDensityTab)); + + /// + /// Component entity that has a list of 'measurement-correction' pairs + /// to be updated in the database on OK. + /// + public Entities.Component MeterEntity + { + get { return null; } + set { } + } + + /// + /// A list of 'measurement-correction' pairs to be deleted from the database on OK. + /// + public IList ToBeRemoved + { + get { return toBeRemoved; } + set { toBeRemoved = value; } + } + IList toBeRemoved; + + MetrologyDlg parent; + bool unlocked; + + public MetrologyDlgDensityTab() + { + InitializeComponent(); + toBeRemoved = new List(); + unlocked = false; + } + + private void MetrologyDlgDensityTab_Load(object sender, System.EventArgs e) + { + parent = ParentForm as MetrologyDlg; + + /// Panel1 + densityLabel.Text = Strings.Density_kgLtr; + temperatureLabel.Text = Strings.AtTemperature_C; + + /// Panel2 + + RefreshAll(); + } + + void RefreshAll() + { + densityTextBox.Text = Program.LocalSettings.RealDensity.ToString(); + temperatureTextBox.Text = Program.LocalSettings.AtTemperature.ToString(); + } + + public void Unlock() + { + unlocked = true; + + densityTextBox.Enabled = true; + temperatureTextBox.Enabled = true; + } + + public void OkBtnClicked() + { + float tmp; + if (Utils.TryParseUFloat(densityTextBox.Text, out tmp)) + { + Program.LocalSettings.RealDensity = tmp; + } + if (Utils.TryParseUFloat(temperatureTextBox.Text, out tmp)) + { + Program.LocalSettings.AtTemperature = tmp; + } + Program.LocalSettings.Save(); + } + + public void CancelBtnClicked() + { + } + + public void AddOne() + { + } + + public void RemoveSelected() + { + } + + public void MoveUpSelected() + { + } + + public void MoveDownSelected() + { + } + } +} diff --git a/TestBenchFramework/UiControls/MetrologyDlgDensityTab.resx b/TestBenchFramework/UiControls/MetrologyDlgDensityTab.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TestBenchFramework/UiControls/MetrologyDlgDensityTab.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file