cloudflight
2025-01-13 02c14c9c57dbde72d9c771bd8b0fab1cd023047d
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
using Yw.WinFrmUI.HydroW3d;
 
namespace Yw.WinFrmUI
{
    /// <summary>
    /// W3d转换辅助类
    /// </summary>
    public static class HydroW3dTransferHelper
    {
        /// <summary>
        /// 
        /// </summary>
        public static NetworkViewModel ToW3dNetworkViewModel(this Yw.Model.HydroModelInfo model)
        {
            if (model == null)
            {
                return default;
            }
            var netWork = new NetworkViewModel();
 
            #region 节点
 
            //水库
            if (model.Reservoirs != null && model.Reservoirs.Count > 0)
            {
                foreach (var reservoir in model.Reservoirs)
                {
                    var reservoirModel = new ReservoirViewModel();
                    reservoirModel.Id = reservoir.Code;
                    reservoirModel.Catalog = Catalog.Reservoir;
                    reservoirModel.Name = reservoir.Name;
                    reservoirModel.Position = new Point3d(reservoir.Position3d.X, reservoir.Position3d.Y, reservoir.Position3d.Z);
                    netWork.Reservoirs.Add(reservoirModel);
                }
            }
 
            //水池
            if (model.Tanks != null && model.Tanks.Count > 0)
            {
                foreach (var tank in model.Tanks)
                {
                    var tankModel = new TankViewModel();
                    tankModel.Id = tank.Code;
                    tankModel.Catalog = Catalog.Tank;
                    tankModel.Name = tank.Name;
                    tankModel.Position = new Point3d(tank.Position3d.X, tank.Position3d.Y, tank.Position3d.Z);
                    netWork.Tanks.Add(tankModel);
                }
            }
 
            //水箱
            if (model.Waterboxs != null && model.Waterboxs.Count > 0)
            {
                foreach (var waterbox in model.Waterboxs)
                {
                    var waterboxModel = new WaterboxViewModel();
                    waterboxModel.Id = waterbox.Code;
                    waterboxModel.Catalog = Catalog.Waterbox;
                    waterboxModel.Name = waterbox.Name;
                    waterboxModel.Position = new Point3d(waterbox.Position3d.X, waterbox.Position3d.Y, waterbox.Position3d.Z);
                    netWork.Waterboxs.Add(waterboxModel);
                }
            }
 
            //连接节点
            if (model.Junctions != null && model.Junctions.Count > 0)
            {
                foreach (var junction in model.Junctions)
                {
                    var junctionModel = new JunctionViewModel();
                    junctionModel.Id = junction.Code;
                    junctionModel.Catalog = Catalog.Junction;
                    junctionModel.Name = junction.Name;
                    junctionModel.Position = new Point3d(junction.Position3d.X, junction.Position3d.Y, junction.Position3d.Z);
                    netWork.Junctions.Add(junctionModel);
                }
            }
 
            //喷嘴
            if (model.Nozzles != null && model.Nozzles.Count > 0)
            {
                foreach (var nozzle in model.Nozzles)
                {
                    var nozzleModel = new NozzleViewModel();
                    nozzleModel.Id = nozzle.Code;
                    nozzleModel.Catalog = Catalog.Nozzle;
                    nozzleModel.Name = nozzle.Name;
                    nozzleModel.Position = new Point3d(nozzle.Position3d.X, nozzle.Position3d.Y, nozzle.Position3d.Z);
                    netWork.Nozzles.Add(nozzleModel);
                }
            }
 
            //消火栓
            if (model.Hydrants != null && model.Hydrants.Count > 0)
            {
                foreach (var hydrant in model.Hydrants)
                {
                    var hydrantModel = new HydrantViewModel();
                    hydrantModel.Id = hydrant.Code;
                    hydrantModel.Catalog = Catalog.Hydrant;
                    hydrantModel.Name = hydrant.Name;
                    hydrantModel.Position = new Point3d(hydrant.Position3d.X, hydrant.Position3d.Y, hydrant.Position3d.Z);
                    netWork.Hydrants.Add(hydrantModel);
                }
            }
 
            //闷头
            if (model.Bluntheads != null && model.Bluntheads.Count > 0)
            {
                foreach (var blunthead in model.Bluntheads)
                {
                    var bluntheadModel = new BluntheadViewModel();
                    bluntheadModel.Id = blunthead.Code;
                    bluntheadModel.Catalog = Catalog.Blunthead;
                    bluntheadModel.Name = blunthead.Name;
                    bluntheadModel.Position = new Point3d(blunthead.Position3d.X, blunthead.Position3d.Y, blunthead.Position3d.Z);
                    netWork.Bluntheads.Add(bluntheadModel);
                }
            }
 
            //弯头
            if (model.Elbows != null && model.Elbows.Count > 0)
            {
                foreach (var elbow in model.Elbows)
                {
                    var elbowModel = new ElbowViewModel();
                    elbowModel.Id = elbow.Code;
                    elbowModel.Catalog = Catalog.Elbow;
                    elbowModel.Name = elbow.Name;
                    elbowModel.Position = new Point3d(elbow.Position3d.X, elbow.Position3d.Y, elbow.Position3d.Z);
                    netWork.Elbows.Add(elbowModel);
                }
            }
 
            //三通
            if (model.Threelinks != null && model.Threelinks.Count > 0)
            {
                foreach (var threelink in model.Threelinks)
                {
                    var threelinkModel = new ThreelinkViewModel();
                    threelinkModel.Id = threelink.Code;
                    threelinkModel.Catalog = Catalog.Threelink;
                    threelinkModel.Name = threelink.Name;
                    threelinkModel.Position = new Point3d(threelink.Position3d.X, threelink.Position3d.Y, threelink.Position3d.Z);
                    netWork.Threelinks.Add(threelinkModel);
                }
            }
 
            //四通
            if (model.Fourlinks != null && model.Fourlinks.Count > 0)
            {
                foreach (var fourlink in model.Fourlinks)
                {
                    var fourlinkModel = new FourlinkViewModel();
                    fourlinkModel.Id = fourlink.Code;
                    fourlinkModel.Catalog = Catalog.Fourlink;
                    fourlinkModel.Name = fourlink.Name;
                    fourlinkModel.Position = new Point3d(fourlink.Position3d.X, fourlink.Position3d.Y, fourlink.Position3d.Z);
                    netWork.Fourlinks.Add(fourlinkModel);
                }
            }
 
            //水表
            if (model.Meters != null && model.Meters.Count > 0)
            {
                foreach (var meter in model.Meters)
                {
                    var meterModel = new MeterViewModel();
                    meterModel.Id = meter.Code;
                    meterModel.Catalog = Catalog.Meter;
                    meterModel.Name = meter.Name;
                    meterModel.Position = new Point3d(meter.Position3d.X, meter.Position3d.Y, meter.Position3d.Z);
                    netWork.Meters.Add(meterModel);
                }
            }
 
            //流量计
            if (model.Flowmeters != null && model.Flowmeters.Count > 0)
            {
                foreach (var flowmeter in model.Flowmeters)
                {
                    var flowmeterModel = new FlowmeterViewModel();
                    flowmeterModel.Id = flowmeter.Code;
                    flowmeterModel.Catalog = Catalog.Flowmeter;
                    flowmeterModel.Name = flowmeter.Name;
                    flowmeterModel.Position = new Point3d(flowmeter.Position3d.X, flowmeter.Position3d.Y, flowmeter.Position3d.Z);
                    netWork.Flowmeters.Add(flowmeterModel);
                }
            }
 
            //压力表
            if (model.Pressmeters != null && model.Pressmeters.Count > 0)
            {
                foreach (var pressmeter in model.Pressmeters)
                {
                    var pressmeterModel = new PressmeterViewModel();
                    pressmeterModel.Id = pressmeter.Code;
                    pressmeterModel.Catalog = Catalog.Pressmeter;
                    pressmeterModel.Name = pressmeter.Name;
                    pressmeterModel.Position = new Point3d(pressmeter.Position3d.X, pressmeter.Position3d.Y, pressmeter.Position3d.Z);
                    netWork.Pressmeters.Add(pressmeterModel);
                }
            }
 
            #endregion
 
            #region 管段
 
            var allNodes = netWork.GetAllNodes();
            var allNodeDict = new Dictionary<string, NodeViewModel>();
            allNodes.ForEach(x => allNodeDict.Add(x.Id, x));
 
            //管道
            if (model.Pipes != null && model.Pipes.Count > 0)
            {
                foreach (var pipe in model.Pipes)
                {
                    var pipeModel = new PipeViewModel();
                    pipeModel.Id = pipe.Code;
                    pipeModel.Catalog = Catalog.Pipe;
                    pipeModel.Name = pipe.Name;
                    pipeModel.StartId = pipe.StartCode;
                    pipeModel.EndId = pipe.EndCode;
                    pipeModel.Diameter = pipe.Diameter;
                    netWork.Pipes.Add(pipeModel);
                }
            }
 
            //过渡件
            if (model.Translations != null && model.Translations.Count > 0)
            {
                foreach (var translation in model.Translations)
                {
                    var translationModel = new TranslationViewModel();
                    translationModel.Id = translation.Code;
                    translationModel.Catalog = Catalog.Translation;
                    translationModel.Name = translation.Name;
                    translationModel.StartId = translation.StartCode;
                    translationModel.EndId = translation.EndCode;
                    translationModel.Diameter = translation.Diameter;
                    translationModel.StartDiameter = translation.StartDiameter;
                    translationModel.EndDiameter = translation.EndDiameter;
                    netWork.Translations.Add(translationModel);
                }
            }
 
            //水泵
            if (model.Pumps != null && model.Pumps.Count > 0)
            {
                foreach (var pump in model.Pumps)
                {
                    var pumpModel = new HydroW3d.PumpViewModel();
                    pumpModel.Id = pump.Code;
                    pumpModel.Catalog = Catalog.Pump;
                    pumpModel.Name = pump.Name;
                    pumpModel.StartId = pump.StartCode;
                    pumpModel.EndId = pump.EndCode;
                    netWork.Pumps.Add(pumpModel);
                }
            }
 
            //阀门
            if (model.Valves != null && model.Valves.Count > 0)
            {
                foreach (var valve in model.Valves)
                {
                    var valveModel = new ValveViewModel();
                    valveModel.Id = valve.Code;
                    valveModel.Catalog = Catalog.Valve;
                    valveModel.Name = valve.Name;
                    valveModel.StartId = valve.StartCode;
                    valveModel.EndId = valve.EndCode;
                    valveModel.Diameter = valve.Diameter;
                    netWork.Valves.Add(valveModel);
                }
            }
 
            //换热器
            if (model.Exchangers != null && model.Exchangers.Count > 0)
            {
                foreach (var exchanger in model.Exchangers)
                {
                    var exchangerModel = new ExchangerViewModel();
                    exchangerModel.Id = exchanger.Code;
                    exchangerModel.Catalog = Catalog.Exchanger;
                    exchangerModel.Name = exchanger.Name;
                    exchangerModel.StartId = exchanger.StartCode;
                    exchangerModel.EndId = exchanger.EndCode;
                    exchangerModel.Diameter = exchanger.Diameter;
                    netWork.Exchangers.Add(exchangerModel);
                }
            }
 
            //压缩机
            if (model.Compressors != null && model.Compressors.Count > 0)
            {
                foreach (var compressor in model.Compressors)
                {
                    var compressorModel = new CompressorViewModel();
                    compressorModel.Id = compressor.Code;
                    compressorModel.Catalog = Catalog.Compressor;
                    compressorModel.Name = compressor.Name;
                    compressorModel.StartId = compressor.StartCode;
                    compressorModel.EndId = compressor.EndCode;
                    compressorModel.Diameter = compressor.Diameter;
                    netWork.Compressors.Add(compressorModel);
                }
            }
 
 
            #endregion
 
            #region 节点连接
 
            var allLinks = netWork.GetAllLinks();
            foreach (var node in allNodes)
            {
                var links = allLinks.Where(x => x.StartId == node.Id || x.EndId == node.Id).ToList();
                node.LinkIds = links.Select(x => x.Id).Distinct().ToList();
            }
 
            #endregion
 
 
            return netWork;
        }
 
 
 
 
    }
}