namespace HydroUI { [Serializable] public class LinkViewModel : LinkCalcModel, IBaseViewModel { #region 构造函数 public LinkViewModel() { } public LinkViewModel(PointF startPoint, PointF endPoint) { StartNode = new NodeViewModel(startPoint); EndNode = new NodeViewModel(endPoint); } public LinkViewModel(PointF startPoint, PointF endPoint, List points) { StartNode = new NodeViewModel(startPoint); EndNode = new NodeViewModel(endPoint); } #endregion #region 属性 [DisplayName("编号")] [Browsable(true)] public new string ID { get { return base.ID; } set { base.ID = value; } } [DisplayName("名称")] [Browsable(true)] public new string Name { get { return base.Name; } set { base.Name = value; } } [DisplayName("起始节点")] [Browsable(true)] public string Node1 { get { return base.Node1; } set { base.Node1 = value; } } [DisplayName("终止节点")] [Browsable(true)] public string Node2 { get { return base.Node2; } set { base.Node2 = value; } } public NodeViewModel StartNode { get { return (NodeViewModel)base.StartNode; } set { base.StartNode = value; } } public NodeViewModel EndNode { get { return (NodeViewModel)base.EndNode; } set { base.EndNode = value; } } private PointF _position { get; set; } = new PointF(0, 0); public PointF Position { get { { 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); } return _position; } set { } } public List Points { get { return new List() { StartNode.Position, EndNode.Position }; } } 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)) }; } [DisplayName("标高(m)")] public float Elev { get { if (StartNode == null || EndNode == null) return 0; return (StartNode.Elev + EndNode.Elev) / 2; } set { } } [Category("计算参数")] [DisplayName("初始状态")] [Browsable(true)] public StatusType Status { get { return base.Status; } set { base.Status = value; } } [DisplayName("口径(mm)")] [Browsable(true)] public new float Diameter { get { return base.Diameter; } set { base.Diameter = value; } } [DisplayName("长度(m)")] [Browsable(true)] /// 长度 public float Length { get { return base.Length; } set { base.Length = value; } } public String RegionName { get; set; } = null; [Description("X坐标")] [DisplayName("X坐标")] [Browsable(true)] public float X { get { return Position.X; } set { } } [Description("Y坐标")] [DisplayName("Y坐标")] [Browsable(true)] public float Y { get { return Position.Y; } set { } } [Description("对象的等级")] [DisplayName("级别")] public int Level { get; set; } = 0; [Description("对象的等级")] [DisplayName("是否显示")] public bool Visible { get; set; } = true; [Description("标签")] [DisplayName("标签")] public TagList Tags { get; set; } = null; public MapObjectType Type { get { return this.GetTypeString(); } } [Description("ID类型")] [DisplayName("ID类型")] #endregion #region 方法 public string IDType => Type.ToString() + "\t" + ID; public MapObjectType GetTypeString() { if (this is JunctionViewModel) return MapObjectType.节点; if (this is ReservoirViewModel) return MapObjectType.水库; if (this is TankViewModel) return MapObjectType.水池; if (this is MeterViewModel) return MapObjectType.水表; if (this is NozzleViewModel) return MapObjectType.喷头; if (this is ValveNodeViewModel) return MapObjectType.阀门点; if (this is PipeViewModel) return MapObjectType.管线; if (this is ValveViewModel) return MapObjectType.阀门; if (this is RepeaterViewModel) return MapObjectType.重复器; if (this is PumpViewModel) return MapObjectType.水泵; if (this is PumpNodeViewModel) return MapObjectType.水泵点; return MapObjectType.节点; } public bool isNode() { if (this is JunctionViewModel) return true; if (this is ReservoirViewModel) return true; if (this is TankViewModel) return true; if (this is MeterViewModel) return true; if (this is NozzleViewModel) return true; return false; } #endregion } }