Schematic drawing with live function, bench control by mouse, Dijkstra algo, vacuum, etc.
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
///
|
||||
/// Copyright (c) 2020 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using Config.Entities;
|
||||
using SchematicDrawing;
|
||||
using TBF.BenchControl.Generic;
|
||||
|
||||
namespace TBF.BenchControl.Various.Drawing.Pipes
|
||||
{
|
||||
public class Configuration : ComponentCfgBase, IComponentCfg, Config.Entities.IParamsProvider
|
||||
{
|
||||
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(Configuration) })[0];
|
||||
public override XmlSerializer GetSerializer() { return Serializer; }
|
||||
|
||||
public IComponentCfgCtrl GetControl() { return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); }
|
||||
|
||||
///
|
||||
/// Serialized parameters
|
||||
///
|
||||
public Sz Sz { get; set; }
|
||||
public string[] Pipes { get; set; }
|
||||
|
||||
|
||||
public Configuration() { }
|
||||
///
|
||||
public Configuration(string name, IComponentFactory factory)
|
||||
: this()
|
||||
{
|
||||
Name = name;
|
||||
ParentName = string.Empty;
|
||||
Factory = factory;
|
||||
Sz = Sz.S;
|
||||
Pipes = new string[0];
|
||||
}
|
||||
|
||||
public string ComponentName { get { return Name; } }
|
||||
|
||||
public void InitializeAll()
|
||||
{
|
||||
Sz = Sz.S;
|
||||
Pipes = new string[0];
|
||||
}
|
||||
string[] paramNames = new string[] { "Size" };
|
||||
public string ParamName(int i) { return paramNames[i]; }
|
||||
public int ParamsCount() { return paramNames.Length; }
|
||||
public IList<string> ParamValues(int i)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
IList<string> values = new List<string>();
|
||||
for (var size = Sz.S; size <= Sz.XL; size++) values.Add(size.ToString());
|
||||
return values;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
if (i == -1) return string.Format("name={0} sz={1}", Name, Sz);
|
||||
if (i == 0) return Sz.ToString();
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateParam(int i, string strValue)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
for (var size = Sz.S; size <= Sz.XL; size++)
|
||||
{
|
||||
if (strValue == size.ToString())
|
||||
{
|
||||
Sz = size;
|
||||
return CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return CfgUpdateFlags.None;
|
||||
}
|
||||
|
||||
public bool ValidateParam(int i, string strValue, out string message)
|
||||
{
|
||||
message = string.Empty;
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
for (var size = Sz.S; size <= Sz.XL; size++)
|
||||
{
|
||||
if (strValue == size.ToString()) return true;
|
||||
}
|
||||
message = string.Format("Invalid '{0}'", ParamName(i));
|
||||
return false;
|
||||
|
||||
default:
|
||||
message = "Invalid index";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void CopyContentTo(Configuration prms)
|
||||
{
|
||||
prms.Sz = this.Sz;
|
||||
prms.Pipes = new string[this.Pipes.Length];
|
||||
for (int i = 0; i < this.Pipes.Length; i++)
|
||||
{
|
||||
prms.Pipes[i] = this.Pipes[i];
|
||||
}
|
||||
}
|
||||
|
||||
public Config.Entities.IParamsProvider Clone()
|
||||
{
|
||||
Configuration pars = new Configuration();
|
||||
CopyContentTo(pars);
|
||||
return pars;
|
||||
}
|
||||
|
||||
public bool UpdateEmbeddedDbEntity()
|
||||
{
|
||||
return true; /// =OK, do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user