1
cloudflight
2024-07-20 fab5d6e30b9a42a1f94524fca74ef227d2c963e4
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
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<Link> Links { get; set; }=new List<Link>();
 
        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<PointF>() { startPoint, endPoint };
        }
        public Link(PointF startPoint, PointF endPoint, List<PointF> 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<PointF> 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<PointF> 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<string> 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<string>() { 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";
        }
    }
 
 
 
}