tbf/TBF/Rig/OutputPath.cs

120 lines
4.7 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 double Qfrom;
public double Qto;
public string Selector;
public IFlowMeter FlowMeter;
public IRegValve RegValve;
public int RegulMinStep;
public float PidCoef;
public IDiverter Diverter;
public ITempMeter TempMtrDiv;
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 IList<RegValvePosition> RegVPositions;
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;
RegVPositions = new List<RegValvePosition>();
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;
RegValve = TbfComponents.FindComponent(entity.RegValve, components) as IRegValve;
RegulMinStep = entity.RegulMinStep;
PidCoef = entity.PidCoef;
Diverter = TbfComponents.FindComponent(entity.Diverter, components) as IDiverter;
TempMtrDiv = TbfComponents.FindComponent(entity.TempMtrDiv, components) as ITempMeter;
Scale = TbfComponents.FindComponent(entity.Scale, components) as IScaleOrTank;
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;
///
/// Output regulation valves and their positions
///
RegVPositions.Clear();
foreach (var cmpnt in components)
{
IRegValve rv = cmpnt as IRegValve;
if (rv != null && rv.Category == TBF.Rig.ValveCategory.Output && !(rv is TBF.Rig.Uni.RegValveTandem.RegValveTandem))
{
RegVPositions.Add(new RegValvePosition(rv));
}
}
TBF.Utils.UpdateRegVPositionsFromStr(ref RegVPositions, entity.RegVPositions);
///
/// Regular valves to open
///
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);
}
///
/// Regular valves to close
///
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,
(RegValve != null) ? RegValve.Name : "---",
(FlowMeter != null) ? FlowMeter.Name : "---",
(Diverter != null) ? Diverter.Name : "---",
(Scale != null) ? Scale.Name : "---");
}
}
}