using CloudWaterNetwork;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Xml.Linq;
using System.Diagnostics.Eventing.Reader;
namespace CloudWaterNetwork
{
public class StringArr
{
public StringArr(string[] values)
{
this.values = values;
}
private string[] values = null;
public string this[int index]
{
get { return (index >= 0 && values != null && index < values.Length) ? values[index] : ""; }
set { values[index] = value; }
}
}
[Serializable]
public class MapObject
{
[Category("1、基本信息")]
[Description("对象的ID唯一标识")]
[DisplayName(" 编号 ")]
public string ID { get; set; }
[Category("其他")]
[Description("选中")]
[DisplayName("选中")]
[Browsable(false)]
public bool Selected { get; set; }
[Category("其他")]
[Description("选中")]
[DisplayName("位置信息")]
[Browsable(false)]
public PointF Position { get; set; } = new PointF(0, 0);
[Category("1、基本信息")]
[Description("X坐标")]
[DisplayName("X坐标")]
[Browsable(true)]
public float X
{
get
{
return Position.X;
}
set
{
Position = new PointF(value, Position.Y);
}
}
[Category("1、基本信息")]
[Description("Y坐标")]
[DisplayName("Y坐标")]
[Browsable(true)]
public float Y
{
get
{
return Position.Y;
}
set
{
Position = new PointF(Position.X, value);
}
}
[Category("1、基本信息")]
[Description("标高")]
[DisplayName("标高")]
[Browsable(true)]
public float Elev { get; set; }
[Category("其他")]
[Description("对象的等级")]
[DisplayName("级别")]
//[Editor(typeof(MyPropertyEditor), typeof(UITypeEditor))]
public int Level { get; set; } = 0;
[Category("其他")]
[Description("对象的等级")]
[DisplayName("是否显示")]
public bool Visible { get; set; } = true;
//[Category("其他")]
//[Description("标签集合")]
//[DisplayName("标签")]
//public string Tags { get; set; } = null;
public string GetTypeString()
{
if (this is Junction) return "Junction";
if (this is Reservoir) return "Reservoir";
if (this is Tank) return "Tank";
if (this is Meter) return "Meter";
if (this is Pipe) return "Pipe";
if (this is Valve) return "Valve";
if (this is Repeater) return "Repeater";
return "Junction";
}
public bool isNode()
{
if (this is Junction) return true;
if (this is Reservoir) return true;
if (this is Tank) return true;
if (this is Meter) return true;
return false;
}
}
[Serializable]
public class Tag
{
[DisplayName("名称")]
public string Name { get; set; }
}
public static class PointFExtansion
{
public static Point ToPoint(this PointF p)
{
return new Point((int)p.X, (int)p.Y);
}
}
public class PointF3D
{
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
public PointF3D(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
}
[Serializable]
public partial class Node : MapObject
{
public Node()
{
}
public Node(PointF position)
{
Position = position;
}
public Node(int X, int Y)
{
Position = new PointF(X, Y);
}
public PointF3D ToPointF3D()
{
return new PointF3D(X,Y,Elev);
}
[Category("2、参数")]
[Description("需水量")]
[DisplayName("需水量")]
[Browsable(true)]
public float Demand { get; set; }
[Category("2、参数")]
[Description("模式")]
[DisplayName("模式")]
[Browsable(true)]
public string Pattern { get; set; }
[Category("1、基本信息")]
[Description("口径")]
[DisplayName("口径")]
[Browsable(false)]
public float MaxDiameter { get; set; } = 0;
[Category("3、其他")]
[DisplayName("链表清单")]
[Browsable(true)]
public List Links { get; set; }=new List();
public string ToCoorString()
{
return $"{ID}\t{X}\t{Y}";
}
public void Move(Vector3 vector)
{
X += vector.X;
Y += vector.Y;
Elev += vector.Z;
}
}
[Serializable]
public class Junction:Node
{
public override string ToString()
{
return $"{ID}\t{Elev}\t{Demand}";
}
public string ToString(bool originalVersion)
{
if (originalVersion)
return this.ToString();
else
{
var pTemp = Pattern;
if (string.IsNullOrEmpty(pTemp) || pTemp == ";") pTemp = "NONE";
return $"{ID}\t{Elev}\t{Demand}\t{pTemp}\t;Junction\t";
}
}
}
[Serializable]
public class Link : MapObject
{
public Link()
{
}
public Link(PointF startPoint, PointF endPoint)
{
StartNode = new Node(startPoint);
EndNode = new Node(endPoint);
Points = new List() { startPoint, endPoint };
}
public Link(PointF startPoint, PointF endPoint, List points)
{
StartNode = new Node(startPoint);
EndNode = new Node(endPoint);
Points = points;
}
private string node1;
[Category("1、基本信息")]
[DisplayName("节点1")]
[Browsable(true)]
public string Node1
{
get
{
if (StartNode != null && node1 != StartNode.ID)
{
node1 = StartNode.ID;
}
return node1;
}
set
{
node1 = value;
}
}
private string node2;
[Category("1、基本信息")]
[DisplayName("节点2")]
[Browsable(true)]
public string Node2
{
get
{
if (EndNode != null && node2 != EndNode.ID)
{
node2 = EndNode.ID;
}
return node2;
}
set
{
node2 = value;
}
}
[Browsable(false)]
public Node StartNode { get; set; }
[Browsable(false)]
public Node EndNode { get; set; }
private PointF _position { get; set; } = new PointF(0, 0);
public new PointF Position
{
get
{
//if (StartPoint.Position==new PointF(0,0) || EndPoint.Position == new PointF(0, 0))
//{
// return new PointF(0,0);
//}
//if (_position == new PointF(0, 0))
{
if (StartNode == null || EndNode == null) return _position;
var x = (StartNode.Position.X + EndNode.Position.X) / 2;
var y = (StartNode.Position.Y + EndNode.Position.Y) / 2;
_position = new PointF(x, y);
base.Position = new PointF(x, y);
}
return _position;
}
set
{
_position = value;
}
}
[Browsable(false)]
public List Points { get; set; }
public PointF[] ToArray(bool is3Dview = false)
{
if (!is3Dview)
return new PointF[] { new PointF((float)(StartNode.X), (float)(StartNode.Y)), new PointF((float)(EndNode.X), (float)(EndNode.Y)) };
else
return new PointF[] { new PointF((float)(StartNode.X), (float)(StartNode.Y - 2 * StartNode.Elev)), new PointF((float)(EndNode.X), (float)(EndNode.Y - 2 * EndNode.Elev)) };
}
[Category("1、基本信息")]
[DisplayName("标高")]
[Browsable(true)]
public new float Elev {
get
{
if (StartNode == null || EndNode == null) return 0;
return (StartNode.Elev + EndNode.Elev) / 2;
}
}
[Category("1、基本信息")]
[DisplayName("口径")]
[Browsable(true)]
public float Diameter { get; set; }
}
[Serializable]
public class Pipe:Link
{
private float _length;
[Category("1、基本信息")]
[DisplayName("长度")]
[Browsable(true)]
public float Length
{
get
{
//if (_length==0)
{
_length =(float) Math.Sqrt(
Math.Pow(EndNode.Elev - StartNode.Elev, 2) +
Math.Pow(EndNode.X - StartNode.X, 2) +
Math.Pow(EndNode.Y - StartNode.Y, 2));
}
return _length;
}
set { _length = value; }
}
[Category("2、参数")]
[DisplayName("海森威廉系数")]
[Browsable(true)]
public float Roughness { get; set; }
[Category("2、参数")]
[DisplayName("局部阻力系数")]
[Browsable(true)]
public float MinorLoss { get; set; }
[Category("2、参数")]
[DisplayName("初始状态")]
[Browsable(true)]
public string Status { get; set; }
public override string ToString()
{
return $"{ID}\t{Node1}\t{Node2}\t{Length}\t{Diameter}\t{Roughness}\t{MinorLoss}\t{Status}\t";
}
}
[Serializable]
public partial class Area : MapObject
{
public List Points { get; set; }
}
// Junction类
[Serializable]
public partial class Reservoir : Node
{
//public string ID { get; set; }
[Category("2、参数")]
[Description("需水量")]
[DisplayName("需水量")]
[Browsable(false)]
public float Demand { get; set; }
[Category("2、参数")]
[Description("总水头")]
[DisplayName("绝对水压")]
public float Head { get; set; }
//public string Pattern { get; set; }
public override string ToString()
{
return $"{ID}\t{Head}\t{Pattern};";
}
}
[Serializable]
public class Tank : Node
{
//public string Elevation;
public string InitLevel;
public string MinLevel;
public string MaxLevel;
public string Diameter;
public string MinVol;
public string VolCurve;
public string Overflow;
public Tank()
{
}
public Tank(string id, string elevation, string initlevel, string minlevel, string maxlevel, string diameter, string minvol, string volcurve, string overflow)
{
ID = id;
Elev = float.Parse(elevation);
InitLevel = initlevel;
MinLevel = minlevel;
MaxLevel = maxlevel;
Diameter = diameter;
MinVol = minvol;
VolCurve = volcurve;
Overflow = overflow;
}
public override string ToString()
{
return $"{ID}\t{Elev}\t{InitLevel}\t{MinLevel}\t{MaxLevel}\t{Diameter}\t{MinVol}\t{VolCurve}\t{Overflow}\t";
}
}
[Serializable]
public class Meter : Node
{
public override string ToString()
{
if (string.IsNullOrEmpty(Pattern)) Pattern = "NONE";
return $"{ID}\t{Elev}\t{Demand}\t{Pattern}\tMeter\t";
}
}
// Pipe类
[Serializable]
public class Valve : Link
{
[Category("1、基本信息")]
[DisplayName("长度")]
[Browsable(true)]
public float Length { get; set; }
[Category("1、基本信息")]
[DisplayName("口径")]
[Browsable(true)]
public float Diameter { get; set; }
[Category("2、参数")]
[DisplayName("海森威廉系数")]
[Browsable(true)]
public float Roughness { get; set; }
[Category("2、参数")]
[DisplayName("局部阻力系数")]
[Browsable(true)]
public float MinorLoss { get; set; }
[Category("2、参数")]
[DisplayName("初始状态")]
[Browsable(true)]
public string Status { get; set; }
public string Type { get; set; }
public string Setting { get; set; }
// 重写ToString()方法以便将阀门属性转换为字符串
public override string ToString()
{
return $"{ID}\t{Node1}\t{Node2}\t{Diameter:F4}\t{Type}\t{Setting}\t{MinorLoss:F4}\t";
}
}
// Pipe类
[Serializable]
public class Pump:Link
{
public string HeadCurve { get; set; }
public List Parameters { get; set; }
public static Pump FromString(string line)
{
string[] values = line.Split('\t', ' ', ',', ';');
Pump pump = new Pump();
pump.ID = values[0];
pump.Node1 = values[1];
pump.Node2 = values[2];
//pump.Parameters = new List() { values[3], values[4], values[5] };
return pump;
}
public override string ToString()
{
return ID.ToString() + "\t" + Node1 + "\t" + Node2 + "\t" + string.Join("\t", Parameters) + "\t";
}
}
}