yangyin
2024-08-20 98e49c0dd42840a094837f7acae532bc237a719a
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
 
using Yw.WinFrmUI.HydroL2d;
 
namespace Yw.WinFrmUI
{
    /// <summary>
    /// 
    /// </summary>
    public static class HydroL2dTransferHelper
    {
        /// <summary>
        /// 
        /// </summary>
        public static Network ToL2dNetworkViewModel(this Yw.Model.HydroModelInfo rhs)
        {
            if (rhs == null)
            {
                return default;
            }
            var vm = new Network();
            if (rhs.Junctions != null && rhs.Junctions.Count > 0)
            {
                foreach (var junction in rhs.Junctions)
                {
                    var junctionViewModel = new Junction();
                    junctionViewModel.Id = junction.Code;
                    junctionViewModel.Name = junction.Name;
                    junctionViewModel.Position = new PointF((float)junction.Position2d.X, (float)junction.Position2d.Y);
                    vm.Append(junctionViewModel, out _);
                }
            }
            if (rhs.Nozzles != null && rhs.Nozzles.Count > 0)
            {
                foreach (var nozzle in rhs.Nozzles)
                {
                    var nozzleViewModel = new Junction();
                    nozzleViewModel.Id = nozzle.Code;
                    nozzleViewModel.Name = nozzle.Name;
                    nozzleViewModel.Position = new PointF((float)nozzle.Position2d.X, (float)nozzle.Position2d.Y);
                    vm.Append(nozzleViewModel, out _);
                }
            }
            if (rhs.Hydrants != null && rhs.Hydrants.Count > 0)
            {
                foreach (var hydrant in rhs.Hydrants)
                {
                    var hydrantViewModel = new Junction();
                    hydrantViewModel.Id = hydrant.Code;
                    hydrantViewModel.Name = hydrant.Name;
                    hydrantViewModel.Position = new PointF((float)hydrant.Position2d.X, (float)hydrant.Position2d.Y);
                    vm.Append(hydrantViewModel, out _);
                }
            }
            if (rhs.Elbows != null && rhs.Elbows.Count > 0)
            {
                foreach (var elbow in rhs.Elbows)
                {
                    var elbowViewModel = new Junction();
                    elbowViewModel.Id = elbow.Code;
                    elbowViewModel.Name = elbow.Name;
                    elbowViewModel.Position = new PointF((float)elbow.Position2d.X, (float)elbow.Position2d.Y);
                    vm.Append(elbowViewModel, out _);
                }
            }
            if (rhs.Threelinks != null && rhs.Threelinks.Count > 0)
            {
                foreach (var threelink in rhs.Threelinks)
                {
                    var threelinkViewModel = new Junction();
                    threelinkViewModel.Id = threelink.Code;
                    threelinkViewModel.Name = threelink.Name;
                    threelinkViewModel.Position = new PointF((float)threelink.Position2d.X, (float)threelink.Position2d.Y);
                    vm.Append(threelinkViewModel, out _);
                }
            }
            if (rhs.Fourlinks != null && rhs.Fourlinks.Count > 0)
            {
                foreach (var fourlink in rhs.Fourlinks)
                {
                    var fourlinkViewModel = new Junction();
                    fourlinkViewModel.Id = fourlink.Code;
                    fourlinkViewModel.Name = fourlink.Name;
                    fourlinkViewModel.Position = new PointF((float)fourlink.Position2d.X, (float)fourlink.Position2d.Y);
                    vm.Append(fourlinkViewModel, out _);
                }
            }
            if (rhs.Meters != null && rhs.Meters.Count > 0)
            {
                foreach (var meter in rhs.Meters)
                {
                    var meterViewModel = new Junction();
                    meterViewModel.Id = meter.Code;
                    meterViewModel.Name = meter.Name;
                    meterViewModel.Position = new PointF((float)meter.Position2d.X, (float)meter.Position2d.Y);
                    vm.Append(meterViewModel, out _);
                }
            }
            if (rhs.Flowmeters != null && rhs.Flowmeters.Count > 0)
            {
                foreach (var flowmeter in rhs.Flowmeters)
                {
                    var flowmeterViewModel = new Junction();
                    flowmeterViewModel.Id = flowmeter.Code;
                    flowmeterViewModel.Name = flowmeter.Name;
                    flowmeterViewModel.Position = new PointF((float)flowmeter.Position2d.X, (float)flowmeter.Position2d.Y);
                    vm.Append(flowmeterViewModel, out _);
                }
            }
            if (rhs.Pressmeters != null && rhs.Pressmeters.Count > 0)
            {
                foreach (var pressmeter in rhs.Pressmeters)
                {
                    var pressmeterViewModel = new Junction();
                    pressmeterViewModel.Id = pressmeter.Code;
                    pressmeterViewModel.Name = pressmeter.Name;
                    pressmeterViewModel.Position = new PointF((float)pressmeter.Position2d.X, (float)pressmeter.Position2d.Y);
                    vm.Append(pressmeterViewModel, out _);
                }
            }
            if (rhs.Bluntheads != null && rhs.Bluntheads.Count > 0)
            {
                foreach (var blunthead in rhs.Bluntheads)
                {
                    var bluntheadViewModel = new Junction();
                    bluntheadViewModel.Id = blunthead.Code;
                    bluntheadViewModel.Name = blunthead.Name;
                    bluntheadViewModel.Position = new PointF((float)blunthead.Position2d.X, (float)blunthead.Position2d.Y);
                    vm.Append(bluntheadViewModel, out _);
                }
            }
 
            if (rhs.Reservoirs != null && rhs.Reservoirs.Count > 0)
            {
                foreach (var reservoir in rhs.Reservoirs)
                {
                    var reservoirViewModel = new Reservoir();
                    reservoirViewModel.Id = reservoir.Code;
                    reservoirViewModel.Name = reservoir.Name;
                    reservoirViewModel.Position = new PointF((float)reservoir.Position2d.X, (float)reservoir.Position2d.Y);
                    vm.Append(reservoirViewModel, out _);
                }
            }
            if (rhs.Tanks != null && rhs.Tanks.Count > 0)
            {
                foreach (var tank in rhs.Tanks)
                {
                    var tankViewModel = new Tank();
                    tankViewModel.Id = tank.Code;
                    tankViewModel.Name = tank.Name;
                    tankViewModel.Position = new PointF((float)tank.Position2d.X, (float)tank.Position2d.Y);
                    vm.Append(tankViewModel, out _);
                }
            }
            if (rhs.Waterboxs != null && rhs.Waterboxs.Count > 0)
            {
                foreach (var waterbox in rhs.Waterboxs)
                {
                    var waterboxViewModel = new Tank();
                    waterboxViewModel.Id = waterbox.Code;
                    waterboxViewModel.Name = waterbox.Name;
                    waterboxViewModel.Position = new PointF((float)waterbox.Position2d.X, (float)waterbox.Position2d.Y);
                    vm.Append(waterboxViewModel, out _);
                }
            }
 
            if (rhs.Pipes != null && rhs.Pipes.Count > 0)
            {
                foreach (var pipe in rhs.Pipes)
                {
                    var startNode = rhs.GetAllNodes().Find(x => x.Code == pipe.StartCode);
                    var endNode = rhs.GetAllNodes().Find(x => x.Code == pipe.EndCode);
                    var pipeViewModel = new Pipe();
                    pipeViewModel.Id = pipe.Code;
                    pipeViewModel.Name = pipe.Name;
                    pipeViewModel.StartPosition = new PointF((float)startNode.Position2d.X, (float)startNode.Position2d.Y);
                    pipeViewModel.EndPosition = new PointF((float)endNode.Position2d.X, (float)endNode.Position2d.Y);
                    vm.Append(pipeViewModel, out _);
                }
            }
            if (rhs.Translations != null && rhs.Translations.Count > 0)
            {
                foreach (var translation in rhs.Translations)
                {
                    var startNode = rhs.GetAllNodes().Find(x => x.Code == translation.StartCode);
                    var endNode = rhs.GetAllNodes().Find(x => x.Code == translation.EndCode);
                    var translationViewModel = new Pipe();
                    translationViewModel.Id = translation.Code;
                    translationViewModel.Name = translation.Name;
                    translationViewModel.StartPosition = new PointF((float)startNode.Position2d.X, (float)startNode.Position2d.Y);
                    translationViewModel.EndPosition = new PointF((float)endNode.Position2d.X, (float)endNode.Position2d.Y);
                    vm.Append(translationViewModel, out _);
                }
            }
            if (rhs.Exchangers != null && rhs.Exchangers.Count > 0)
            {
                foreach (var exchanger in rhs.Exchangers)
                {
                    var startNode = rhs.GetAllNodes().Find(x => x.Code == exchanger.StartCode);
                    var endNode = rhs.GetAllNodes().Find(x => x.Code == exchanger.EndCode);
                    var exchangerViewModel = new Pipe();
                    exchangerViewModel.Id = exchanger.Code;
                    exchangerViewModel.Name = exchanger.Name;
                    exchangerViewModel.StartPosition = new PointF((float)startNode.Position2d.X, (float)startNode.Position2d.Y);
                    exchangerViewModel.EndPosition = new PointF((float)endNode.Position2d.X, (float)endNode.Position2d.Y);
                    vm.Append(exchangerViewModel, out _);
                }
            }
 
            if (rhs.Pumps != null && rhs.Pumps.Count > 0)
            {
                foreach (var pump in rhs.Pumps)
                {
                    var startNode = rhs.GetAllNodes().Find(x => x.Code == pump.StartCode);
                    var endNode = rhs.GetAllNodes().Find(x => x.Code == pump.EndCode);
                    var pumpViewModel = new Pump();
                    pumpViewModel.Id = pump.Code;
                    pumpViewModel.Name = pump.Name;
                    pumpViewModel.StartPosition = new PointF((float)startNode.Position2d.X, (float)startNode.Position2d.Y);
                    pumpViewModel.EndPosition = new PointF((float)endNode.Position2d.X, (float)endNode.Position2d.Y);
                    vm.Append(pumpViewModel, out _);
                }
            }
            if (rhs.Valves != null && rhs.Valves.Count > 0)
            {
                foreach (var valve in rhs.Valves)
                {
                    var startNode = rhs.GetAllNodes().Find(x => x.Code == valve.StartCode);
                    var endNode = rhs.GetAllNodes().Find(x => x.Code == valve.EndCode);
                    var valveViewModel = new Valve();
                    valveViewModel.Id = valve.Code;
                    valveViewModel.Name = valve.Name;
                    valveViewModel.StartPosition = new PointF((float)startNode.Position2d.X, (float)startNode.Position2d.Y);
                    valveViewModel.EndPosition = new PointF((float)endNode.Position2d.X, (float)endNode.Position2d.Y);
                    vm.Append(valveViewModel, out _);
                }
            }
 
            return vm;
        }
    }
}