Shuxia Ning
2024-12-05 1e9a72970e30b74b8f0cb7c74e2bec9df1aa1d22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System.Runtime.Serialization;
using System.Text;
 
namespace Eventech.Model
{
    //穿过点的线
    [DataContract]
    public class ThroughCurve : ICloneable
    {
        #region 构造函数
        public ThroughCurve() { }
        public ThroughCurve(string strPara)
        {
            if (string.IsNullOrEmpty(strPara))
            {
                isNull = true;
                return;
            }
 
            string[] strParas = strPara.Split(',');
            if (strParas.Count() < 4)
            {
                isNull = true;
                return;
            }
 
            DispTension = float.Parse(strParas[0]);
            IsClosed = bool.Parse(strParas[1]);
 
            int iPtCount = Convert.ToInt32(strParas[2]);
            if (iPtCount == 0)
            {
                isNull = true;
                return;
            }
 
            PointInfo = new Eventech.Model.FeatPointList();
            for (int i = 0; i < iPtCount; i++)
            {//可能只有一个点
                PointInfo.Add(new Eventech.Model.FeatPoint() { X = Convert.ToDouble(strParas[3 + i * 2]), Y = Convert.ToDouble(strParas[3 + 2 * i + 1]) });
            }
        }
        public ThroughCurve(ThroughCurve rhs)
        {
            this.DispTension = rhs.DispTension;
            this.IsClosed = rhs.IsClosed;
            this.PointInfo = rhs.PointInfo.Clone();
        } 
        #endregion
   
        //显示的张力
        [DataMember]
        public float DispTension { get { return _dispTension; } set { _dispTension = value; } }
        private float _dispTension = 0.5f;
 
        //是否封闭
        [DataMember]
        public bool IsClosed { get { return _isClosed; } set { _isClosed = value; } }
        public bool _isClosed = false;
 
        //曲线点参数,存储时不能用拟合参数
        //(注意可能一个点,两个点,或多个点,两个点就连成直线即可)
        public Eventech.Model.FeatPointList _pointInfo = null;
        public Eventech.Model.FeatPointList PointInfo { get { return _pointInfo; } set { _pointInfo = value; } }
 
        protected bool isNull = false;
        public bool IsNull
        {
            get { return isNull; }
        }
 
        public ThroughCurve Clone() 
        {
            return new ThroughCurve(this);
        }
        object ICloneable.Clone()
        {
            return Clone();
        }
 
        public string ToDsString()
        {
            return ToDsString(this);
        }
 
        public static string ToDsString(ThroughCurve curve)
        {
            if (curve == null || curve.PointInfo == null)
                return null;
 
            StringBuilder sb = new StringBuilder();
            sb.Append(curve.DispTension);
            sb.Append(","); sb.Append(curve.IsClosed);
            sb.Append(","); sb.Append(curve.PointInfo.Count);
 
            foreach (var point in curve.PointInfo)
            {//必须用,分割,//可能只有一个点
                sb.AppendFormat(",{0},{1}", point.X, point.Y);
            }
 
            return sb.ToString();
        }
 
 
 
        public static ThroughParaCurve toM3H(Eventech.Model.UnitQ unit, ThroughParaCurve curvePara)
        {
            if (curvePara == null)
                return null;
            if (curvePara.PointInfo == null)
                return curvePara;
 
            ThroughParaCurve newCurve = curvePara.Clone();
            newCurve.PointInfo = new Eventech.Model.FeatPointList();
            for (int i = 0; i < curvePara.PointInfo.Count; i++)
            {
                Eventech.Model.FeatPoint pt = curvePara.PointInfo[i];
                newCurve.PointInfo.Add(new Eventech.Model.FeatPoint(Eventech.Common.UnitQHelper.toM3H(unit, pt.X), pt.Y));
            }
 
            return newCurve;
        }
 
        public static List<ThroughParaCurve> toM3H(UnitQ unit, List<ThroughParaCurve> curvePara)
        {
            if (curvePara == null)
                return null;
 
            List<ThroughParaCurve> newCurvePara = new List<ThroughParaCurve>();
            foreach (ThroughParaCurve curve in curvePara)
            {
                newCurvePara.Add(toM3H(unit, curve));
            } 
 
            return newCurvePara;
        }
 
        //获得X值的坐标位置,可能有多个点(是线形插值,不是曲线上的点)
        public List<double> GetInterPointY(double x)
        {
            if (this._pointInfo == null)
                return null;
 
             
            return this._pointInfo.GetInterPointY(x);
        }
 
    }
 
 
 
}