lixiaojun
2025-01-20 bef933e7e166b085ba7e46e38ea62d9ae0129ec6
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
using Yw.WinFrmUI.Q3d;
namespace Yw.WinFrmUI
{
    /// <summary>
    /// Q3d转换辅助类
    /// </summary>
    public static class HydroQ3dTransferHelper
    {
        /// <summary>
        /// 
        /// </summary>
        public static NetworkViewModel ToNetworkViewModel(this Yw.Model.HydroModelInfo rhs)
        {
            if (rhs == null)
            {
                return default;
            }
            var vm = new NetworkViewModel();
 
            if (rhs.Reservoirs != null && rhs.Reservoirs.Count > 0)
            {
                foreach (var reservoir in rhs.Reservoirs)
                {
                    var reservoirViewModel = new ReservoirViewModel();
                    reservoirViewModel.ID = reservoir.Code;
                    reservoirViewModel.Name = reservoir.Name;
                    reservoirViewModel.Position3D = new PointF3D((float)reservoir.Position3d.X, (float)reservoir.Position3d.Y, (float)reservoir.Position3d.Z);
                    vm.Nodes.Add(reservoirViewModel);
                }
            }
            if (rhs.Tanks != null && rhs.Tanks.Count > 0)
            {
                foreach (var tank in rhs.Tanks)
                {
                    var tankViewModel = new TankViewModel();
                    tankViewModel.ID = tank.Code;
                    tankViewModel.Name = tank.Name;
                    tankViewModel.Position3D = new PointF3D((float)tank.Position3d.X, (float)tank.Position3d.Y, (float)tank.Position3d.Z);
                    vm.Nodes.Add(tankViewModel);
                }
            }
            if (rhs.Waterboxs != null && rhs.Waterboxs.Count > 0)
            {
                foreach (var waterbox in rhs.Waterboxs)
                {
                    var waterboxViewModel = new TankViewModel();
                    waterboxViewModel.ID = waterbox.Code;
                    waterboxViewModel.Name = waterbox.Name;
                    waterboxViewModel.Position3D = new PointF3D((float)waterbox.Position3d.X, (float)waterbox.Position3d.Y, (float)waterbox.Position3d.Z);
                    vm.Nodes.Add(waterboxViewModel);
                }
            }
            if (rhs.Junctions != null && rhs.Junctions.Count > 0)
            {
                foreach (var junction in rhs.Junctions)
                {
                    var junctionViewModel = new JunctionViewModel();
                    junctionViewModel.ID = junction.Code;
                    junctionViewModel.Name = junction.Name;
                    junctionViewModel.Position3D = new PointF3D((float)junction.Position3d.X, (float)junction.Position3d.Y, (float)junction.Position3d.Z);
                    vm.Nodes.Add(junctionViewModel);
                }
            }
            if (rhs.Nozzles != null && rhs.Nozzles.Count > 0)
            {
                foreach (var nozzle in rhs.Nozzles)
                {
                    var nozzleViewModel = new NozzleViewModel();
                    nozzleViewModel.ID = nozzle.Code;
                    nozzleViewModel.Name = nozzle.Name;
                    nozzleViewModel.Position3D = new PointF3D((float)nozzle.Position3d.X, (float)nozzle.Position3d.Y, (float)nozzle.Position3d.Z);
                    vm.Nodes.Add(nozzleViewModel);
                }
            }
            if (rhs.Hydrants != null && rhs.Hydrants.Count > 0)
            {
                foreach (var hydrant in rhs.Hydrants)
                {
                    var hydrantViewModel = new JunctionViewModel();
                    hydrantViewModel.ID = hydrant.Code;
                    hydrantViewModel.Name = hydrant.Name;
                    hydrantViewModel.Position3D = new PointF3D((float)hydrant.Position3d.X, (float)hydrant.Position3d.Y, (float)hydrant.Position3d.Z);
                    vm.Nodes.Add(hydrantViewModel);
                }
            }
            if (rhs.Coolings != null && rhs.Coolings.Count > 0)
            {
                foreach (var cooling in rhs.Coolings)
                {
                    var coolingViewModel = new JunctionViewModel();
                    coolingViewModel.ID = cooling.Code;
                    coolingViewModel.Name = cooling.Name;
                    coolingViewModel.Position3D = new PointF3D((float)cooling.Position3d.X, (float)cooling.Position3d.Y, (float)cooling.Position3d.Z);
                    vm.Nodes.Add(coolingViewModel);
                }
            }
            if (rhs.Bluntheads != null && rhs.Bluntheads.Count > 0)
            {
                foreach (var blunthead in rhs.Bluntheads)
                {
                    var bluntheadViewModel = new JunctionViewModel();
                    bluntheadViewModel.ID = blunthead.Code;
                    bluntheadViewModel.Name = blunthead.Name;
                    bluntheadViewModel.Position3D = new PointF3D((float)blunthead.Position3d.X, (float)blunthead.Position3d.Y, (float)blunthead.Position3d.Z);
                    vm.Nodes.Add(bluntheadViewModel);
                }
            }
            if (rhs.Elbows != null && rhs.Elbows.Count > 0)
            {
                foreach (var elbow in rhs.Elbows)
                {
                    var elbowViewModel = new JunctionViewModel();
                    elbowViewModel.ID = elbow.Code;
                    elbowViewModel.Name = elbow.Name;
                    elbowViewModel.Position3D = new PointF3D((float)elbow.Position3d.X, (float)elbow.Position3d.Y, (float)elbow.Position3d.Z);
                    vm.Nodes.Add(elbowViewModel);
                }
            }
            if (rhs.Threelinks != null && rhs.Threelinks.Count > 0)
            {
                foreach (var threelink in rhs.Threelinks)
                {
                    var threelinkViewModel = new JunctionViewModel();
                    threelinkViewModel.ID = threelink.Code;
                    threelinkViewModel.Name = threelink.Name;
                    threelinkViewModel.Position3D = new PointF3D((float)threelink.Position3d.X, (float)threelink.Position3d.Y, (float)threelink.Position3d.Z);
                    vm.Nodes.Add(threelinkViewModel);
                }
            }
            if (rhs.Fourlinks != null && rhs.Fourlinks.Count > 0)
            {
                foreach (var fourlink in rhs.Fourlinks)
                {
                    var fourlinkViewModel = new JunctionViewModel();
                    fourlinkViewModel.ID = fourlink.Code;
                    fourlinkViewModel.Name = fourlink.Name;
                    fourlinkViewModel.Position3D = new PointF3D((float)fourlink.Position3d.X, (float)fourlink.Position3d.Y, (float)fourlink.Position3d.Z);
                    vm.Nodes.Add(fourlinkViewModel);
                }
            }
            if (rhs.Meters != null && rhs.Meters.Count > 0)
            {
                foreach (var meter in rhs.Meters)
                {
                    var meterViewModel = new MeterViewModel();
                    meterViewModel.ID = meter.Code;
                    meterViewModel.Name = meter.Name;
                    meterViewModel.Position3D = new PointF3D((float)meter.Position3d.X, (float)meter.Position3d.Y, (float)meter.Position3d.Z);
                    vm.Nodes.Add(meterViewModel);
                }
            }
            if (rhs.Flowmeters != null && rhs.Flowmeters.Count > 0)
            {
                foreach (var flowmeter in rhs.Flowmeters)
                {
                    var flowmeterViewModel = new JunctionViewModel();
                    flowmeterViewModel.ID = flowmeter.Code;
                    flowmeterViewModel.Name = flowmeter.Name;
                    flowmeterViewModel.Position3D = new PointF3D((float)flowmeter.Position3d.X, (float)flowmeter.Position3d.Y, (float)flowmeter.Position3d.Z);
                    vm.Nodes.Add(flowmeterViewModel);
                }
            }
            if (rhs.Pressmeters != null && rhs.Pressmeters.Count > 0)
            {
                foreach (var pressmeter in rhs.Pressmeters)
                {
                    var pressmeterViewModel = new JunctionViewModel();
                    pressmeterViewModel.ID = pressmeter.Code;
                    pressmeterViewModel.Name = pressmeter.Name;
                    pressmeterViewModel.Position3D = new PointF3D((float)pressmeter.Position3d.X, (float)pressmeter.Position3d.Y, (float)pressmeter.Position3d.Z);
                    vm.Nodes.Add(pressmeterViewModel);
                }
            }
 
            if (rhs.Pipes != null && rhs.Pipes.Count > 0)
            {
                foreach (var pipe in rhs.Pipes)
                {
                    var pipeViewModel = new PipeViewModel();
                    pipeViewModel.ID = pipe.Code;
                    pipeViewModel.Name = pipe.Name;
                    pipeViewModel.StartNode = vm.Nodes.Find(x => x.ID == pipe.StartCode);
                    pipeViewModel.EndNode = vm.Nodes.Find(x => x.ID == pipe.EndCode);
                    vm.Links.Add(pipeViewModel);
                }
            }
            if (rhs.Translations != null && rhs.Translations.Count > 0)
            {
                foreach (var translation in rhs.Translations)
                {
                    var translationViewModel = new PipeViewModel();
                    translationViewModel.ID = translation.Code;
                    translationViewModel.Name = translation.Name;
                    translationViewModel.StartNode = vm.Nodes.Find(x => x.ID == translation.StartCode);
                    translationViewModel.EndNode = vm.Nodes.Find(x => x.ID == translation.EndCode);
                    vm.Links.Add(translationViewModel);
                }
            }
 
            if (rhs.Pumps != null && rhs.Pumps.Count > 0)
            {
                foreach (var pump in rhs.Pumps)
                {
                    var pumpViewModel = new PumpViewModel();
                    pumpViewModel.ID = pump.Code;
                    pumpViewModel.Name = pump.Name;
                    pumpViewModel.StartNode = vm.Nodes.Find(x => x.ID == pump.StartCode);
                    pumpViewModel.EndNode = vm.Nodes.Find(x => x.ID == pump.EndCode);
                    vm.Links.Add(pumpViewModel);
                }
            }
            if (rhs.Valves != null && rhs.Valves.Count > 0)
            {
                foreach (var valve in rhs.Valves)
                {
                    var valveViewModel = new ValveViewModel();
                    valveViewModel.ID = valve.Code;
                    valveViewModel.Name = valve.Name;
                    valveViewModel.StartNode = vm.Nodes.Find(x => x.ID == valve.StartCode);
                    valveViewModel.EndNode = vm.Nodes.Find(x => x.ID == valve.EndCode);
                    vm.Links.Add(valveViewModel);
                }
            }
 
            if (rhs.Exchangers != null && rhs.Exchangers.Count > 0)
            {
                foreach (var exchanger in rhs.Exchangers)
                {
                    var exchangerViewModel = new PipeViewModel();
                    exchangerViewModel.ID = exchanger.Code;
                    exchangerViewModel.Name = exchanger.Name;
                    exchangerViewModel.StartNode = vm.Nodes.Find(x => x.ID == exchanger.StartCode);
                    exchangerViewModel.EndNode = vm.Nodes.Find(x => x.ID == exchanger.EndCode);
                    vm.Links.Add(exchangerViewModel);
                }
            }
            if (rhs.Compressors != null && rhs.Compressors.Count > 0)
            {
                foreach (var compressor in rhs.Compressors)
                {
                    var compresorViewModel = new PipeViewModel();
                    compresorViewModel.ID = compressor.Code;
                    compresorViewModel.Name = compressor.Name;
                    compresorViewModel.StartNode = vm.Nodes.Find(x => x.ID == compressor.StartCode);
                    compresorViewModel.EndNode = vm.Nodes.Find(x => x.ID == compressor.EndCode);
                    vm.Links.Add(compresorViewModel);
                }
            }
 
 
            return vm;
        }
 
 
 
    }
}