2019-09-14 08:44:20 +00:00
|
|
|
|
///
|
2021-08-18 06:52:34 +00:00
|
|
|
|
/// Copyright (c) 2019-2021 Sensus Slovensko a.s.
|
2019-09-14 08:44:20 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Xml.Serialization;
|
2021-09-23 09:46:40 +00:00
|
|
|
|
using Common;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
using Config.Entities;
|
2021-10-26 09:23:57 +00:00
|
|
|
|
using TBF.Rig.Generic;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig.DataContainers.Density
|
2019-09-14 08:44:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Holds backup and security options - serializable configuration.
|
|
|
|
|
|
/// </summary>
|
2022-01-23 18:56:15 +00:00
|
|
|
|
public class ComponentCfg : ComponentCfgBase, Generic.IComponentCfg, IParamsProvider, TBF.Rig.GenericDevices.ICalibInfoCfg
|
2019-09-14 08:44:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ComponentCfg) })[0];
|
|
|
|
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
|
|
|
2021-08-29 11:01:34 +00:00
|
|
|
|
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities) { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); }
|
2019-09-14 08:44:20 +00:00
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Serialized parameters
|
|
|
|
|
|
///
|
2019-09-18 07:09:00 +00:00
|
|
|
|
public double RealDensity;
|
|
|
|
|
|
public double AtTemperature;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
|
2020-05-06 07:45:23 +00:00
|
|
|
|
/// Calibration info serialized parameters displayed in Metrology tab page
|
2021-08-18 06:52:34 +00:00
|
|
|
|
public string CalibCertificateNr { get; set; }
|
|
|
|
|
|
public DateTime CalibDate { get; set; }
|
|
|
|
|
|
public DateTime CalibValidDate { get; set; }
|
2020-05-06 07:45:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-09-14 08:44:20 +00:00
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
|
|
|
|
ComponentCfg() {}
|
|
|
|
|
|
|
2019-09-18 07:09:00 +00:00
|
|
|
|
public ComponentCfg(string name, IComponentFactory factory)
|
2019-09-14 08:44:20 +00:00
|
|
|
|
: this()
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
Name = name;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
Factory = factory;
|
|
|
|
|
|
ParentName = string.Empty;
|
|
|
|
|
|
InitializeAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
|
|
|
|
|
|
|
|
public void InitializeAll()
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
RealDensity = 998.2008; /// kg/m3
|
|
|
|
|
|
AtTemperature = 20.0; /// °C
|
2021-08-18 06:52:34 +00:00
|
|
|
|
|
|
|
|
|
|
CalibCertificateNr = string.Empty;
|
|
|
|
|
|
CalibDate = TBF.UI.Constants.MinDate;
|
|
|
|
|
|
CalibValidDate = TBF.UI.Constants.MaxDate;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] paramNames = new string[]
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
"True density [kg/m3]",
|
|
|
|
|
|
"@temperature [°C]",
|
2019-09-14 08:44:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
|
|
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
|
|
|
2021-07-28 11:31:18 +00:00
|
|
|
|
public ICollection<string> ParamValues(int i)
|
2019-09-14 08:44:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string ToString(int i)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i == -1)
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
return string.Format("{0}: True density = {1} kg/m3 measured @temperature {2} °C", Name, RealDensity, AtTemperature);
|
2019-09-14 08:44:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
case 0: return RealDensity.ToString();
|
|
|
|
|
|
case 1: return AtTemperature.ToString();
|
2019-09-14 08:44:20 +00:00
|
|
|
|
default: return string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (i)
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
case 0: RealDensity = Utils.ParseUDouble(strValue); return CfgUpdateFlags.RestartRqrd;
|
|
|
|
|
|
case 1: AtTemperature = Utils.ParseUDouble(strValue); return CfgUpdateFlags.RestartRqrd;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
default: return CfgUpdateFlags.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
message = string.Empty;
|
2019-09-18 07:09:00 +00:00
|
|
|
|
double dummy;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
2019-09-18 07:09:00 +00:00
|
|
|
|
/// Real number between 800 and 1200 kg/m3 expected
|
|
|
|
|
|
if (Utils.TryParseUDouble(strValue, out dummy) && (dummy >= 800) && (dummy <= 1200)) return true;
|
|
|
|
|
|
break;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
case 1:
|
2019-09-18 07:09:00 +00:00
|
|
|
|
/// Real number above 0 expected
|
|
|
|
|
|
if (Utils.TryParseUDouble(strValue, out dummy) && (dummy >= 0)) return true;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
message = "Invalid index";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CopyContentTo(ComponentCfg prms)
|
|
|
|
|
|
{
|
2019-09-18 07:09:00 +00:00
|
|
|
|
prms.RealDensity = this.RealDensity;
|
|
|
|
|
|
prms.AtTemperature = this.AtTemperature;
|
2019-09-14 08:44:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-23 18:56:15 +00:00
|
|
|
|
public IParamsProvider Clone()
|
2019-09-14 08:44:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
ComponentCfg pars = new ComponentCfg();
|
|
|
|
|
|
CopyContentTo(pars);
|
|
|
|
|
|
return pars;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true; /// =OK, do nothing
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|