215 lines
7.4 KiB
C#
215 lines
7.4 KiB
C#
///
|
|
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Xml.Serialization;
|
|
using Config.Entities;
|
|
using SchematicDrawing;
|
|
using TBF.Resources;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.ControlBoard.Uni
|
|
{
|
|
/// <summary>
|
|
/// Holds backup and security options - serializable configuration.
|
|
/// </summary>
|
|
public class UniCBCfg : ComponentCfgBase, Generic.IComponentCfg, Config.Entities.IParamsProvider, IDrawingItemWithMeasuredVal
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(UniCBCfg) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public IComponentCfgCtrl GetControl(IList<Config.Entities.Component> cmpntEntities) { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); }
|
|
|
|
///
|
|
/// Serialized parameters
|
|
///
|
|
public int ComPortNr;
|
|
public int DivertersCount;
|
|
public int DrainValvesCount;
|
|
public int RegValvesCount;
|
|
public bool RelaysFInstalled;
|
|
public bool RelaysGInstalled;
|
|
public bool RelaysHInstalled;
|
|
|
|
/// Schematic drawing info
|
|
public Shape Shape { get; set; }
|
|
public int X { get; set; }
|
|
public int Y { get; set; }
|
|
public Sz Sz { get; set; }
|
|
public Orient Orient { get; set; }
|
|
public bool Flip { get; set; }
|
|
public int LblX { get; set; }
|
|
public int LblY { get; set; }
|
|
public Orient LblOrient { get; set; }
|
|
public int MsrdX { get; set; }
|
|
public int MsrdY { get; set; }
|
|
public Orient MsrdOrient { get; set; }
|
|
public Config.Unit MsrdUnit { get; set; }
|
|
public string MsrdFormat { get; set; }
|
|
public double MsrdValLimLo { get; set; }
|
|
public double MsrdValLimHi { get; set; }
|
|
|
|
[XmlIgnore]
|
|
public IList<GNode> GNodes { get; set; }
|
|
[XmlIgnore]
|
|
public IList<GEdge> EdgesToSet { get; set; }
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
UniCBCfg()
|
|
{
|
|
GNodes = new List<GNode>();
|
|
EdgesToSet = new List<GEdge>();
|
|
}
|
|
|
|
public UniCBCfg(string name, IComponentFactory factory)
|
|
: this()
|
|
{
|
|
Shape = Shape.UniCB;
|
|
Sz = Sz.L;
|
|
|
|
Name = name;
|
|
Factory = factory;
|
|
ParentName = string.Empty;
|
|
InitializeAll();
|
|
}
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
public void InitializeAll()
|
|
{
|
|
ComPortNr = 1;
|
|
DivertersCount = 3;
|
|
DrainValvesCount = 4;
|
|
RegValvesCount = 5;
|
|
RelaysFInstalled = true;
|
|
RelaysGInstalled = true;
|
|
RelaysHInstalled = true;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"Serial port number",
|
|
"Diverters count (1..5)",
|
|
"Drain valves count (0..8)",
|
|
"Regulation valves count (4..8)",
|
|
"Relays F are installed",
|
|
"Relays G are installed",
|
|
"Relays H are installed",
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public ICollection<string> ParamValues(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 1:
|
|
return new string[] { "1", "2", "3", "4", "5" };
|
|
case 2:
|
|
return new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8" };
|
|
case 3:
|
|
return new string[] { "4", "5", "6", "7", "8" };
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
return new string[] { Strings.yes, Strings.no };
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
if (i == -1)
|
|
{
|
|
return string.Format("{0}: COM{1} DIVs={2} VBs={3} RVs={4} RelaysF={5} RelaysG={6} RelaysH={7}",
|
|
Name, ComPortNr, DivertersCount, DrainValvesCount, RegValvesCount, RelaysFInstalled, RelaysGInstalled, RelaysHInstalled);
|
|
}
|
|
|
|
switch (i)
|
|
{
|
|
case 0: return ComPortNr.ToString();
|
|
case 1: return DivertersCount.ToString();
|
|
case 2: return DrainValvesCount.ToString();
|
|
case 3: return RegValvesCount.ToString();
|
|
case 4: return RelaysFInstalled ? Strings.yes : Strings.no;
|
|
case 5: return RelaysGInstalled ? Strings.yes : Strings.no;
|
|
case 6: return RelaysHInstalled ? Strings.yes : Strings.no;
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string str)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: ComPortNr = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
|
case 1: DivertersCount = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
|
case 2: DrainValvesCount = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
|
case 3: RegValvesCount = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
|
case 4: RelaysFInstalled = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
case 5: RelaysGInstalled = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
case 6: RelaysHInstalled = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
public bool ValidateParam(int i, string str, out string message)
|
|
{
|
|
message = string.Empty;
|
|
int n;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
if (int.TryParse(str, out n) && (n >= 1)) return true;
|
|
break;
|
|
case 1:
|
|
if (int.TryParse(str, out n) && (n >= 1) && n <= 5) return true;
|
|
break;
|
|
case 2:
|
|
if (int.TryParse(str, out n) && (n >= 0) && n <= 8) return true;
|
|
break;
|
|
case 3:
|
|
if (int.TryParse(str, out n) && (n >= 4) && n <= 8) return true;
|
|
break;
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
if (ParamValues(i).Contains(str)) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(UniCBCfg prms)
|
|
{
|
|
prms.ComPortNr = ComPortNr;
|
|
prms.DivertersCount = DivertersCount;
|
|
prms.DrainValvesCount = DrainValvesCount;
|
|
prms.RegValvesCount = RegValvesCount;
|
|
prms.RelaysFInstalled = RelaysFInstalled;
|
|
prms.RelaysGInstalled = RelaysGInstalled;
|
|
prms.RelaysHInstalled = RelaysHInstalled;
|
|
}
|
|
|
|
public Config.Entities.IParamsProvider Clone()
|
|
{
|
|
var pars = new UniCBCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
return true; /// =OK, do nothing
|
|
}
|
|
}
|
|
}
|