/// /// Copyright (c) 2013-2016 Sensus Metering Systems /// using System.Collections.Generic; using TBF.BenchControl.GenericDevices; namespace TBF.BenchControl { public class FeedingPath { public int ItemNr; public string Name; public float Qfrom; public float Qto; public IValve Pump; /// pump to use with this path or null public IList RegulValves; public IList RegulValvesPct; public IList ValvesOpen; /// a list of valves to open or null public IList 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(); ValvesClose = new List(); RegulValves = new List(); RegulValvesPct = new List(); } /// Constructor from data entity public FeedingPath(Config.Entities.FeedingPath entity, IList components) : this(entity.Name, entity.ItemNr) { Qfrom = entity.Qfrom; Qto = entity.Qto; Pump = (IValve)TbfComponents.FindComponent(entity.Pump, components); /// /// Feeding regulation valve components /// foreach (var cmpnt in components) { IRegulValve regValve = cmpnt as IRegulValve; if (regValve != null && (regValve.Category == TBF.BenchControl.ValveCategory.Feeding || regValve.Category == TBF.BenchControl.ValveCategory.All)) { 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(); foreach (var vName in vOpen) ValvesOpen.Add((IValve)TbfComponents.FindComponent(vName, components)); string[] vClose = entity.ValvesClose.Split(new char[] { ';' }); ValvesClose = new List(); foreach (var vName in vClose) ValvesClose.Add((IValve)TbfComponents.FindComponent(vName, components)); } public override string ToString() { return string.Format("{0} Pump={1}", Name, (Pump != null) ? Pump.Name : "---"); } } }