ningshuxia
2024-04-29 6eb4d5574aee7042b1883e043d5798865e84d1d1
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
namespace IStation.Curve
{
    public class GroupPoint : ICloneable
    {
        private int id = 0;
        public int ID { get { return id; } set { id = value; } }
        public double Q { get; set; }
        public double H { get; set; }
        public double E { get; set; }
        public double P { get; set; }
        public double NPSH { get { return _npsh; } set { _npsh = value; } }
        private double _npsh = -1;
        public GroupPoint() { }
        public GroupPoint(GroupPoint rhs)
        {
            this.ID = rhs.ID;
            this.Q = rhs.Q;
            this.H = rhs.H;
            this.E = rhs.E;
            this.P = rhs.P;
            this.NPSH = rhs.NPSH;
        }
        public GroupPoint(string dsString)
        {
            ResetParas(dsString);
        }
        public bool ResetParas(string dsString)
        {
            if (string.IsNullOrEmpty(dsString)) return false;
            if (dsString.Contains("|"))
            {//可能是GroupPointList的字符
 
                string[] strParas = dsString.Split('|');
                int iCount = strParas.Count();
                if (iCount < 2)
                    return false;
 
                return ResetParas(strParas[1]);//取默认第一个成员即可
 
            }
            var paras = dsString.Split(',');
            if (paras.Count() < 5)
                return false;
            ID = Convert.ToInt32(paras[0]);
            Q = Convert.ToDouble(paras[1]);
            H = Convert.ToDouble(paras[2]);
            E = Convert.ToDouble(paras[3]);
            P = Convert.ToDouble(paras[4]);
            NPSH = Convert.ToDouble(paras[5]);
            return true;
        }
        public static GroupPoint ToParameter(string dsString)
        {
            if (string.IsNullOrEmpty(dsString)) return null;
            if (dsString.Contains("|"))
            {//可能是GroupPointList的字符
 
                string[] strParas = dsString.Split('|');
                int iCount = strParas.Count();
                if (iCount < 2)
                    return null;
 
                return GroupPoint.ToParameter(strParas[1]);//取默认第一个成员即可
            }
 
            var paras = dsString.Split(',');
            if (paras.Count() < 5)
                return null;
            GroupPoint pt = new GroupPoint();
            pt.ID = Convert.ToInt32(paras[0]);
            pt.Q = Convert.ToDouble(paras[1]);
            pt.H = Convert.ToDouble(paras[2]);
            pt.E = Convert.ToDouble(paras[3]);
            pt.P = Convert.ToDouble(paras[4]);
            pt.NPSH = Convert.ToDouble(paras[5]);
 
            return pt;
        }
 
 
        public GroupPoint(int id, double q, double h, double e, double p)
        {
            ID = id;
            Q = q;
            H = h;
            E = e;
            P = p;
        }
        public GroupPoint(int id, double q, double h, double e, double p, double npsh)
        {
            ID = id;
            Q = q;
            H = h;
            E = e;
            P = p;
            NPSH = npsh;
        }
 
        public override string ToString()
        {
            return string.Format("Q:{0:0.0},H:{1:0.0},E:{2:0.0},P:{3:0.0}", Q, H, E, P);
        }
        public string ToDsString()
        {
            return string.Format("{0},{1},{2},{3},{4},{5}", ID, Q, H, E, P, NPSH);
        }
 
        public IStation.Curve.GroupPoint RoundAll(int decimals)
        {
            this.Q = Math.Round(this.Q, decimals);
            this.H = Math.Round(this.H, decimals);
            this.E = Math.Round(this.E, decimals);
            this.P = Math.Round(this.P, decimals);
            this.NPSH = Math.Round(this.NPSH, decimals);
            return this;
        }
        public IStation.Curve.GroupPoint RoundAll_Small(int decimals, double small = 2)
        {
            if (this.Q < small)
                this.Q = Math.Round(this.Q, 3);
            else
                this.Q = Math.Round(this.Q, decimals);
            if (this.H < small)
                this.H = Math.Round(this.H, 3);
            else
                this.H = Math.Round(this.H, decimals);
            if (this.E < small)
                this.E = Math.Round(this.E, 3);
            else
                this.E = Math.Round(this.E, decimals);
            if (this.P < small)
                this.P = Math.Round(this.P, 3);
            else
                this.P = Math.Round(this.P, decimals);
            this.NPSH = Math.Round(this.NPSH, decimals);
            return this;
        }
 
        #region Clone
        public GroupPoint Clone()  //对外提供一个创建自身的浅表副本的能力
        {
            return (GroupPoint)this.MemberwiseClone();
        }
        object ICloneable.Clone()
        {
            return this.Clone();
        }
        #endregion
 
        public enum eSortType
        {
            ID,
            Q,
            H,
            E,
            P
        }
 
        //排序方法
        public class Comparer : IComparer<IStation.Curve.GroupPoint>
        {
            private eSortType sortType;
            public Comparer(eSortType type = eSortType.Q)
            {
                sortType = type;
            }
 
            #region IComparer<GroupPoint> 成员
            int IComparer<IStation.Curve.GroupPoint>.Compare(IStation.Curve.GroupPoint obj1, IStation.Curve.GroupPoint obj2)
            {
                if (sortType == eSortType.ID)
                {
                    if (obj1.ID == obj2.ID)
                    {
                        return 0;
                    }
                    else if (obj1.ID > obj2.ID)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else if (sortType == eSortType.Q)
                {
                    if (Math.Abs(obj1.Q - obj2.Q) < 0.0001)
                    {
                        return 0;
                    }
                    else if (obj1.Q > obj2.Q)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else if (sortType == eSortType.H)
                {
                    if (Math.Abs(obj1.H - obj2.H) < 0.0001)
                    {
                        return 0;
                    }
                    else if (obj1.H > obj2.H)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else if (sortType == eSortType.E)
                {
                    if (Math.Abs(obj1.E - obj2.E) < 0.0001)
                    {
                        return 0;
                    }
                    else if (obj1.E > obj2.E)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else
                {
                    if (Math.Abs(obj1.P - obj2.P) < 0.0001)
                    {
                        return 0;
                    }
                    else if (obj1.P > obj2.P)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
            }
 
            #endregion
        }
 
        //比较相同:主要用与LIST的Contains方法
        public class EqualComparer : IEqualityComparer<IStation.Curve.GroupPoint>
        {
            private double ignoreDis = 0.001;
            public EqualComparer()
            {
                ignoreDis = 0.001;
            }
            public EqualComparer(double dis)
            {
                ignoreDis = dis;
            }
            public bool Equals(IStation.Curve.GroupPoint lhs, IStation.Curve.GroupPoint rhs)
            {
                if (Math.Abs(lhs.Q - rhs.Q) < ignoreDis && Math.Abs(lhs.H - rhs.H) < ignoreDis)
                    return true;
 
                return false;
            }
 
            public int GetHashCode(IStation.Curve.GroupPoint obj)
            {
                return 0;
                // return obj.H.GetHashCode() + obj.Q.GetHashCode();
            }
        }
    }
}