cloudflight
2023-12-26 5fa6947054206e2e781eadd4effdcdf52eda28c4
Hydro.Core/Base/LinkCalcModel.cs
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hydro.Core.Model
{
    [Serializable]
    public class LinkModel : BaseModel
    {
        public LinkModel() { }
@@ -18,6 +20,7 @@
            this.Length = model.Length;
            this.Roughness = model.Roughness;
            this.MinorLoss = model.MinorLoss;
        }
        /// <summary>
        /// Node1
@@ -63,6 +66,7 @@
            return "";
        }
    }
    [Serializable]
    public class LinkCalcModel : LinkModel
    {
        public LinkCalcModel() { }
@@ -76,9 +80,75 @@
            this.Roughness = model.Roughness;
            this.MinorLoss = model.MinorLoss;
        }
        public NodeCalcModel StartNode { get; set; }
        public NodeCalcModel EndNode { get; set; }
        public string Node1
        {
            get
            {
                if (_StartNode != null) return _StartNode.ID;
                return base.Node1;
            }
            set
            {
                base.Node1 = value;
            }
        }
        public string Node2
        {
            get
            {
                if (_EndNode != null) return _EndNode.ID;
                return base.Node2;
            }
            set
            {
                base.Node2 = value;
            }
        }
        private NodeCalcModel _StartNode;
        public NodeCalcModel StartNode {
            get { return _StartNode; }
            set { _StartNode = value; if (_StartNode != null) this.Node1 = _StartNode.ID; }
        }
        private NodeCalcModel _EndNode;
        public NodeCalcModel EndNode {
            get { return _EndNode; }
            set { _EndNode = value; if (_EndNode!=null)this.Node2 = _EndNode.ID; }
        }
        /// <summary>
        /// 长度
        /// </summary>
        public float Length
        {
            get
            {
                if (base.Length>=0) return base.Length;
                else
                {
                    if (_StartNode!=null && _EndNode!=null)
                    {
                        ////求_StartNode到_EndNode的距离
                        return (float)Math.Sqrt( Math.Pow(_StartNode.X-_EndNode.X, 2)+ Math.Pow(_StartNode.Y-_EndNode.Y,2)+Math.Pow(_StartNode.Elev-_EndNode.Elev,2));
                    }
                    else
                    {
                        return 0;
                    }
                }
            }
            set
            {
                base.Length = value;
            }
        }
    }
}