tbf/TBF/Rig/BuiltIn/ValveBase.cs

107 lines
3.1 KiB
C#

///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using TBF.Rig.GenericDevices;
namespace TBF.Rig.BuiltIn
{
public abstract class ValveBase : ComponentBase
{
public ValveBase() { }
/// <summary>
/// Invokes ComponentBase constructor
/// </summary>
public ValveBase(Generic.IComponentCfg cfg)
: base(cfg)
{
}
/// <summary>
/// Process the list of components and return all valves (masters and coupled)
/// </summary>
public static IList<IValve> AllValves(IList<Generic.IComponent> cmpnts)
{
IList<IValve> result = new List<IValve>();
foreach (var cmpnt in cmpnts) if (cmpnt is IValve) result.Add(cmpnt as IValve);
return result;
}
/// <summary>
/// Process the list of components and return masters valves
/// </summary>
public static IList<IValve> GetMasterValves(IList<Generic.IComponent> cmpnts)
{
IList<IValve> result = new List<IValve>();
foreach (var cmpnt in cmpnts)
{
IValve valve = cmpnt as IValve;
if (valve != null && valve.CoupledTo == null && !(valve is PumpTandem.Pump))
{
result.Add(valve);
}
}
return result;
}
/// <summary>
/// Process the list of components and return coupled valves
/// </summary>
public static IList<IValve> CoupledValves(IList<Generic.IComponent> cmpnts)
{
IList<IValve> result = new List<IValve>();
foreach (var cmpnt in cmpnts)
{
IValve valve = cmpnt as IValve;
if (valve != null && valve.CoupledTo != null) result.Add(valve);
}
return result;
}
/// <summary>
/// Process the list of components and return logical function valves
/// (their state is calculated from states of other valves).
/// </summary>
public static IList<BuiltIn.ValveEx.Valve> LogicalFnValves(IList<Generic.IComponent> cmpnts)
{
IList<BuiltIn.ValveEx.Valve> result = new List<BuiltIn.ValveEx.Valve>();
foreach (var cmpnt in cmpnts)
{
if (cmpnt is BuiltIn.ValveEx.Valve) result.Add(cmpnt as BuiltIn.ValveEx.Valve);
}
return result;
}
/// <summary>
/// Create a list with one valved passed as an argument to this function
/// </summary>
/// <param name="valve">Valve</param>
/// <returns>List with one valve</returns>
public static IList<IValve> MakeList(IValve valve)
{
IList<IValve> result = new List<IValve>();
if (valve != null) result.Add(valve);
return result;
}
public static IList<IValve> Merge(IList<IValve> valves1, IList<IValve> valves2)
{
IList<IValve> result = new List<IValve>();
if (valves1 != null) foreach (var valve in valves1) result.Add(valve);
if (valves2 != null) foreach (var valve in valves2) result.Add(valve);
return result;
}
public static IList<IValve> Merge(IList<IValve> valves1, IList<IValve> valves2, IList<IValve> valves3)
{
IList<IValve> result = new List<IValve>();
if (valves1 != null) foreach (var valve in valves1) result.Add(valve);
if (valves2 != null) foreach (var valve in valves2) result.Add(valve);
if (valves3 != null) foreach (var valve in valves3) result.Add(valve);
return result;
}
}
}