tbf/TBF/Rig/OutputPath.cs
2022-04-15 13:30:58 +02:00

104 lines
4.1 KiB
C#

///
/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
///
using System.Collections.Generic;
using TBF.Rig.GenericDevices;
namespace TBF.Rig
{
public class OutputPath
{
public int ItemNr;
public string Name;
public float Qfrom;
public float Qto;
public string Selector;
public IFlowMeter FlowMeter;
public IRegValve RegulValve;
public float PidCoef;
public IDiverter Diverter;
public ITempMeter TempDiv;
public IScaleOrTank Scale;
public IValve StartValve1;
public bool InvertSV1;
public IValve StartValve2;
public bool InvertSV2;
public int LagSV2;
public IValve StartValve3;
public bool InvertSV3;
public int LagSV3;
public float[] RegulValvesPct;
public IList<IValve> ValvesOpen;
public IList<IValve> ValvesClose;
/// Constructor from name, the rest is empty
public OutputPath(string name, int itemNr)
{
ItemNr = itemNr;
Name = name;
ValvesOpen = new List<IValve>();
ValvesClose = new List<IValve>();
}
/// Constructor from data entity
public OutputPath(Config.Entities.OutputPath entity, IList<Rig.Generic.IComponent> components)
: this(entity.Name, entity.ItemNr)
{
Qfrom = entity.Qfrom;
Qto = entity.Qto;
Selector = entity.Selector;
FlowMeter = TbfComponents.FindComponent(entity.FlowMeter, components) as IFlowMeter;
RegulValve = TbfComponents.FindComponent(entity.RegulValve, components) as IRegValve;
PidCoef = entity.PidCoef;
Diverter = TbfComponents.FindComponent(entity.Diverter, components) as IDiverter;
TempDiv = TbfComponents.FindComponent(entity.TempDiv, components) as ITempMeter;
Scale = TbfComponents.FindComponent(entity.Scale, components) as IScaleOrTank;
int regvCount = 0;
foreach (var cmpnt in components)
{
if ((cmpnt is IRegValve) && !(cmpnt is Rig.Elde.RegulValveTandem.RegulValveTandem)) regvCount++;
}
RegulValvesPct = string.IsNullOrEmpty(entity.RegulValvesPct) ? new float[0] : Utils.GetRegulValvesPositions(entity.RegulValvesPct, regvCount);
string[] svs = entity.StartValve != null ? entity.StartValve.Split(new char[] { '~' }) : new string[0];
int iTmp;
///
StartValve1 = TbfComponents.FindComponent(((svs.Length > 0) ? svs[0] : string.Empty), components) as IValve;
InvertSV1 = (svs.Length > 1) ? svs[1].Equals("i") : false;
StartValve2 = TbfComponents.FindComponent(((svs.Length > 2) ? svs[2] : string.Empty), components) as IValve;
InvertSV2 = (svs.Length > 3) ? svs[3].Equals("i") : false;
LagSV2 = (svs.Length > 4 && int.TryParse(svs[4], out iTmp)) ? iTmp : 0;
StartValve3 = TbfComponents.FindComponent(((svs.Length > 5) ? svs[5] : string.Empty), components) as IValve;
InvertSV3 = (svs.Length > 6) ? svs[6].Equals("i") : false;
LagSV3 = (svs.Length > 7 && int.TryParse(svs[7], out iTmp)) ? iTmp : 0;
string[] vOpen = entity.ValvesOpen.Split(new char[] { ';' });
ValvesOpen = new List<IValve>();
foreach (var vName in vOpen)
{
var cmpnt = TbfComponents.FindComponent(vName, components);
if (cmpnt is IValve) ValvesOpen.Add(cmpnt as IValve);
}
string[] vClose = entity.ValvesClose.Split(new char[] { ';' });
ValvesClose = new List<IValve>();
foreach (var vName in vClose)
{
var cmpnt = TbfComponents.FindComponent(vName, components);
if (cmpnt is IValve) ValvesClose.Add(cmpnt as IValve);
}
}
public override string ToString()
{
return string.Format("{0} RV={1}, Flowm.={2}, Div.={3}, Scale={4}",
Name,
(RegulValve != null) ? RegulValve.Name : "---",
(FlowMeter != null) ? FlowMeter.Name : "---",
(Diverter != null) ? Diverter.Name : "---",
(Scale != null) ? Scale.Name : "---");
}
}
}