New style Dummy.FlowMeter.FlowMeterCfg with format and unit.

This commit is contained in:
Milan Hanajik 2021-04-26 10:48:33 +02:00
parent 5ea9c51f77
commit 4e32d037ea
6 changed files with 119 additions and 341 deletions

View File

@ -49,7 +49,11 @@ namespace TBF.Rig.Dummy.FlowMeter
log.Warn(this.ToString());
}
public override void Initialize() { }
public override void Initialize()
{
MsrdValLimLo = 0;
MsrdValLimHi = NominalFlow;
}
public double ReadFlow() { return ProcessData.FlowFromMassIncrease; }

View File

@ -1,25 +1,36 @@
///
/// Copyright (c) 2017-2021 Sensus Slovensko a.s.
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using Config;
using Config.Entities;
using SchematicDrawing;
using TBF.Rig.Generic;
namespace TBF.Rig.Dummy.FlowMeter
{
public class FlowMeterCfg : ComponentCfgBase, IComponentCfg, IDrawingItemWithMeasuredVal
public class FlowMeterCfg : ComponentCfgBase, IComponentCfg, IParamsProvider, IDrawingItemWithMeasuredVal
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(FlowMeterCfg) })[0];
public override XmlSerializer GetSerializer() { return Serializer; }
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities) { return new FlowMeterCfgCtrl(); }
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities)
{
var parents = cmpntEntities.Where(x => x.ClassName == "ControlBoard.Uni");
return new Configs.ParamsProvider.ComponentCfgCtrl(this, parents);
}
///
/// Serialized parameters
///
public float NominalFlow; /// Nominal flow in m3/h at output frequency 2000 Hz
public double NominalFlow; /// 0 Nominal flow in m3/h
public string MsrdFormat { get; set; } /// 1
public Unit MsrdUnit { get; set; } /// 2
/// Schematic drawing info
public Shape Shape { get; set; }
public int X { get; set; }
public int Y { get; set; }
@ -29,12 +40,9 @@ namespace TBF.Rig.Dummy.FlowMeter
public int LblX { get; set; }
public int LblY { get; set; }
public Orient LblOrient { get; set; }
public int MsrdX { get; set; }
public int MsrdY { get; set; }
public Orient MsrdOrient { get; set; }
public string MsrdFormat { get; set; }
public Config.Unit MsrdUnit { get; set; }
[XmlIgnore]
public IList<GNode> GNodes { get; set; }
@ -43,31 +51,121 @@ namespace TBF.Rig.Dummy.FlowMeter
[XmlIgnore]
public double MsrdValLimHi { get { return msrdValLimHi; } set { msrdValLimHi = value; } }
double msrdValLimLo;
double msrdValLimLo = 0;
double msrdValLimHi;
/// Private parameterless constructor invoked by all other (public) constructors
FlowMeterCfg()
{
GNodes = new List<GNode>();
}
public FlowMeterCfg(string name, IComponentFactory factory)
public FlowMeterCfg(string name, IComponentFactory factory)
: this()
{
Factory = factory;
Name = name;
InitializeAll();
}
public string ComponentName { get { return Name; } }
public void InitializeAll()
{
Shape = Shape.FlowM;
Sz = Sz.M;
MsrdFormat = "{0:F4}";
MsrdUnit = Config.Unit.m3ph;
Name = name;
Factory = factory;
NominalFlow = 1.0f;
NominalFlow = 1;
MsrdFormat = "{0:F3} m2/h";
MsrdUnit = Unit.m3ph;
LblX = 38;
MsrdX = 38;
MsrdY = 22;
}
string[] paramNames = new string[]
{
"Nominal flow [m3/h]", /// 0
"Display format", /// 1
"Unit of flow on a display", /// 2
};
public string ParamName(int i) { return paramNames[i]; }
public int ParamsCount() { return paramNames.Length; }
public ICollection<string> ParamValues(int i)
{
switch (i)
{
case 2: return new string[] { "m3/h", "l/h" };
default: return null;
}
}
public string ToString(int i)
{
return string.Format("{0} {1}[{2},{3}] NominalFlow={4}", Name, Shape, X, Y, NominalFlow);
switch (i)
{
case 0: return NominalFlow.ToString();
case 1: return MsrdFormat;
case 2: return MsrdUnit.ToDescription();
default: return string.Format("{0} {1}[{2},{3}] NominalFlow={4}", Name, Shape, X, Y, NominalFlow);
}
}
}
public CfgUpdateFlags UpdateParam(int i, string str)
{
switch (i)
{
case 0: NominalFlow = TBF.Utils.ParseUDouble(str); return CfgUpdateFlags.RestartRqrd;
case 1: MsrdFormat = str; return CfgUpdateFlags.RestartRqrd;
case 2: MsrdUnit = (str == "l/h") ? Unit.lph : Unit.m3ph; return CfgUpdateFlags.RestartRqrd;
default: return CfgUpdateFlags.None;
}
}
public bool ValidateParam(int i, string str, out string message)
{
message = string.Empty;
double dummy;
switch (i)
{
case 0:
if (TBF.Utils.TryParseUDouble(str, out dummy)) return true;
break;
case 1:
return true;
case 2:
if (ParamValues(i).Contains(str)) return true;
break;
default:
message = "Invalid index";
return false;
}
message = ParamName(i) + " is invalid";
return false;
}
void CopyContentTo(FlowMeterCfg prms)
{
prms.NominalFlow = NominalFlow;
prms.MsrdFormat = MsrdFormat;
prms.MsrdUnit = MsrdUnit;
}
public Config.Entities.IParamsProvider Clone()
{
FlowMeterCfg pars = new FlowMeterCfg();
CopyContentTo(pars);
return pars;
}
public bool UpdateEmbeddedDbEntity()
{
return true; /// =OK, do nothing
}
}
}

View File

@ -1,109 +0,0 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
namespace TBF.Rig.Dummy.FlowMeter
{
partial class FlowMeterCfgCtrl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.nominalFlowTextBox = new System.Windows.Forms.TextBox();
this.nominalFlowLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(140, 61);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(130, 20);
this.nameTextBox.TabIndex = 2;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(30, 64);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 1;
this.nameLabel.Text = "Name";
//
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(137, 37);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
this.classNameLabel.TabIndex = 0;
this.classNameLabel.Text = "ComonentName";
//
// nominalFlowTextBox
//
this.nominalFlowTextBox.Enabled = false;
this.nominalFlowTextBox.Location = new System.Drawing.Point(224, 87);
this.nominalFlowTextBox.Name = "nominalFlowTextBox";
this.nominalFlowTextBox.Size = new System.Drawing.Size(46, 20);
this.nominalFlowTextBox.TabIndex = 8;
//
// nominalFlowLabel
//
this.nominalFlowLabel.AutoSize = true;
this.nominalFlowLabel.Location = new System.Drawing.Point(30, 90);
this.nominalFlowLabel.Name = "nominalFlowLabel";
this.nominalFlowLabel.Size = new System.Drawing.Size(140, 13);
this.nominalFlowLabel.TabIndex = 7;
this.nominalFlowLabel.Text = "Nominal flow [m3/h @2kHz]";
//
// FlowMeterCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.nominalFlowTextBox);
this.Controls.Add(this.nominalFlowLabel);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "FlowMeterCfgCtrl";
this.Size = new System.Drawing.Size(300, 200);
this.Load += new System.EventHandler(this.FlowMeterCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox nameTextBox;
private System.Windows.Forms.Label nameLabel;
private System.Windows.Forms.Label classNameLabel;
private System.Windows.Forms.TextBox nominalFlowTextBox;
private System.Windows.Forms.Label nominalFlowLabel;
}
}

View File

@ -1,86 +0,0 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using Config.Entities;
using TBF.Rig.Generic;
using TBF.UI.Bench.Components;
namespace TBF.Rig.Dummy.FlowMeter
{
public partial class FlowMeterCfgCtrl : UserControl, IComponentCfgCtrl
{
ComponentParametersDlg parent;
public bool ShowMore { get { return false; } }
FlowMeterCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as FlowMeterCfg;
Redraw();
}
}
public FlowMeterCfgCtrl()
{
InitializeComponent();
}
private void FlowMeterCfgCtrl_Load(object sender, EventArgs e)
{
parent = ParentForm as ComponentParametersDlg;
if (parent == null) return;
Redraw();
}
public void Closing()
{
}
void Redraw()
{
if (config == null) return; /// Control was not loaded, settings were not changed
classNameLabel.Text = config.Factory.ClassName;
nameTextBox.Text = config.Name;
nominalFlowTextBox.Text = config.NominalFlow.ToString();
}
public void Unlock()
{
nameTextBox.Enabled = true;
nominalFlowTextBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
float fdummy;
if (!Utils.TryParseUFloat(nominalFlowTextBox.Text, out fdummy) || fdummy < 0.01 || fdummy > 1600)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Nominal flow' should be between 0.01 and 1600";
}
return flags;
}
public CfgUpdateFlags UpdateCfg()
{
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
config.Name = nameTextBox.Text;
Utils.TryParseUFloat(nominalFlowTextBox.Text, out config.NominalFlow);
return flags;
}
}
}

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -512,12 +512,6 @@
<Compile Include="Rig\Dummy\Diverter\Factory.cs" />
<Compile Include="Rig\Dummy\FlowMeter\FlowMeter.cs" />
<Compile Include="Rig\Dummy\FlowMeter\FlowMeterCfg.cs" />
<Compile Include="Rig\Dummy\FlowMeter\FlowMeterCfgCtrl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Rig\Dummy\FlowMeter\FlowMeterCfgCtrl.designer.cs">
<DependentUpon>FlowMeterCfgCtrl.cs</DependentUpon>
</Compile>
<Compile Include="Rig\Dummy\FlowMeter\Factory.cs" />
<Compile Include="Rig\Dummy\FlowMeter\ReadFlowOp.cs" />
<Compile Include="Rig\Dummy\RegValve\ChangeRegValvePositionOp.cs" />
@ -2593,9 +2587,6 @@
<EmbeddedResource Include="Rig\DataEntry\StandardCamera\TestStartEndForm.resx">
<DependentUpon>TestStartEndForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Rig\Dummy\FlowMeter\FlowMeterCfgCtrl.resx">
<DependentUpon>FlowMeterCfgCtrl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Rig\Dummy\RegValve\RegulValveCfgCtrl.resx">
<DependentUpon>RegulValveCfgCtrl.cs</DependentUpon>
</EmbeddedResource>