qinjie
2023-12-02 c2fa168aff53d879f72412c94baa7be4998dae5e
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
using Hydro.Core.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static Hydro.MapView.MapViewEnum;
using System.Xml.Linq;
using Newtonsoft.Json;
using static Hydro.Core.ObjectEnum;
 
namespace Hydro.MapView
{
    public class LinkViewModel : LinkModel, IBaseViewModel
    {
        public LinkViewModel()
        {
 
        }
        public LinkViewModel(PointF startPoint, PointF endPoint)
        {
            StartNode = new NodeViewModel(startPoint);
            EndNode = new NodeViewModel(endPoint);
            Points = new List<PointF>() { startPoint, endPoint };
        }
        public LinkViewModel(PointF startPoint, PointF endPoint, List<PointF> points)
        {
            StartNode = new NodeViewModel(startPoint);
            EndNode = new NodeViewModel(endPoint);
            Points = points;
        }
 
 
 
        //private string Node1;
 
        [Category("1、基本信息")]
        [DisplayName("节点1")]
        [Browsable(true)]
        public new string Node1 
        {
            get
            {
                if (StartNode != null && Node1 != StartNode.ID)
                {
                    base.Node1 = StartNode.ID;
                }
                return base.Node1;
            }
            set
            {
 
                base.Node1 = value;
            }
        }
        //private string Node2;
 
 
        [Category("1、基本信息")]
        [DisplayName("节点2")]
        [Browsable(true)]
        public new string Node2
        {
            get
            {
                if (EndNode != null && Node2 != EndNode.ID)
                {
                    base.Node2 = EndNode.ID;
                }
                return base.Node2;
            }
            set
            {
                base.Node2 = value;
            }
        }
 
        [Browsable(false)]
        [JsonIgnore]
 
        public NodeViewModel StartNode { get; set; }
        [Browsable(false)]
        [JsonIgnore]
 
        public NodeViewModel EndNode { get; set; }
 
        private PointF _position { get; set; } = new PointF(0, 0);
        public  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);
 
 
                }
                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  float Elev
        {
            get
            {
                if (StartNode == null || EndNode == null) return 0;
                return (StartNode.Elev + EndNode.Elev) / 2;
            }
            set
            {
 
            }
        }
 
        [Category("2、计算参数")]
        [DisplayName("1)初始状态")]
        [Browsable(true)]
        public new StatusType Status { get; set; } = StatusType.DEFAULT;
 
 
        //public string ToStatusString()
        //{
        //    //string s = Status.ToUpper();
 
        //    //if (s == "CLOSED" || s=="CLOSE")
        //    if (Status == StatusType.CLOSED)
        //    {
        //        return $"{ID}\tCLOSED\r\n";
        //    }
        //    return "";
        //}
 
        [Category("1、基本信息")]
        [DisplayName("口径")]
        [Browsable(true)]
        public new float Diameter { get { return base.Diameter; } set { base.Diameter = value; } }
 
 
        //实际需水量
        [Category("3、计算结果")]
        [DisplayName("1)流量")]
        [Browsable(true)]
        public float EN_FLOW { get; set; } = float.NaN;
 
        //实际需水量
        [Category("3、计算结果")]
        [DisplayName("2)流速")]
        [Browsable(true)]
        public float EN_VELOCITY { get; set; } = float.NaN;
        //实际需水量
        [Category("3、计算结果")]
        [DisplayName("水头损失")]
        [Browsable(true)]
        public float EN_HEADLOSS { get; set; } = float.NaN;
        //实际需水量
        [Category("3、计算结果")]
        [DisplayName("当前状态")]
        [Browsable(false)]
        public float EN_STATUS { get; set; } = float.NaN;
        //EN_DEMAND 9 实际需水量 EN_HEAD 10 水力水头 EN_PRESSURE 11 压强
 
        [Category("4、其他参数")]
        [Description("选中")]
        [DisplayName("选中")]
        [Browsable(false)]
        public bool Selected { get; set; }
 
 
 
        [Browsable(false)]
        [JsonIgnore]
        public String regionName { get; set; } = null;
 
        [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("4、其他参数")]
        [Description("对象的等级")]
        [DisplayName("级别")]
 
 
        public int Level { get; set; } = 0;
        [Category("4、其他参数")]
        [Description("对象的等级")]
        [DisplayName("是否显示")]
        public bool Visible { get; set; } = true;
 
 
        [Category("1、基本信息")]
        [Description("类型")]
        [DisplayName("类型")]
        public MapObjectType Type { get { return this.GetTypeString(); } }
 
 
        [Category("4、其他参数")]
        [Description("ID类型")]
        [DisplayName("ID类型")]
        [Browsable(false)]
        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;
        }
    }
}