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

89 lines
3.0 KiB
C#

///
/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
///
using System.Collections.Generic;
using TBF.Rig.GenericDevices;
namespace TBF.Rig
{
public class FeedingPath
{
public int ItemNr;
public string Name;
public float Qfrom;
public float Qto;
public string Selector;
public IValve Pump; /// pump to use with this path or null
public IList<IRegValve> RegulValves;
public IList<float> RegulValvesPct;
public IList<IValve> ValvesOpen; /// a list of valves to open or null
public IList<IValve> ValvesClose; /// a list of valves to close or null
/// Constructor from name, the rest is empty
public FeedingPath(string name, int itemNr)
{
ItemNr = itemNr;
Name = name;
ValvesOpen = new List<IValve>();
ValvesClose = new List<IValve>();
RegulValves = new List<IRegValve>();
RegulValvesPct = new List<float>();
}
/// Constructor from data entity
public FeedingPath(Config.Entities.FeedingPath entity, IList<Rig.Generic.IComponent> components)
: this(entity.Name, entity.ItemNr)
{
Qfrom = entity.Qfrom;
Qto = entity.Qto;
Selector = entity.Selector;
Pump = TbfComponents.FindComponent(entity.Pump, components) as IValve;
///
/// Feeding regulation valve components
///
foreach (var cmpnt in components)
{
IRegValve regValve = cmpnt as IRegValve;
if (regValve != null && regValve.Category == TBF.Rig.ValveCategory.Feeding)
{
RegulValves.Add(regValve);
}
}
///
/// Feeding regulation valve precentages
///
string[] rvPosStr = (entity.RegulValvesPct != null) ? entity.RegulValvesPct.Split(new char[] { ';' }) : new string[0];
for (int i = 0; i < RegulValves.Count; i++)
{
string str = (i < rvPosStr.Length) ? rvPosStr[i] : "---";
float pct;
if (!Utils.TryParseUFloat(str, out pct) || pct > 100.0f || str == "---") pct = 0;
RegulValvesPct.Add(pct);
}
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} Pump={1}", Name, (Pump != null) ? Pump.Name : "---");
}
}
}