lixiaojun
2025-04-03 6c865e1270ec79a1fad60e31635513d5966d3431
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using Yw.WpfUI.Hydro;
using Yw.Epanet;
 
namespace Yw.WinFrmUI.Test.Core
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
            this.Load += Form3_Load;
        }
 
        private void Form3_Load(object sender, EventArgs e)
        {
            var nw = LoadEpaNetwork();
            var nw3d = Get3dNetwork(nw);
            this.viewerL3d21.Initial(nw3d);
        }
 
 
        private Yw.Epanet.Network LoadEpaNetwork()
        {
            var fileName = "wh.inp";
            var nw = new Yw.Epanet.Network().ParseInpFile(fileName);
            return nw;
        }
 
        private NetworkL3d Get3dNetwork(Yw.Epanet.Network nw)
        {
            string msg = null;
            var nw3d = new NetworkL3d();
            foreach (var tank in nw.Tanks)
            {
                var tank3d = new TankL3d();
                tank3d.Id = tank.Id;
                tank3d.Name = tank.Name;
                tank3d.Position = new PointL3d()
                {
                    X = (float)tank.Position.X,
                    Y = (float)tank.Position.Y,
                    Z = (float)tank.GetElev()
                };
                nw3d.Append(tank3d, out msg);
            }
 
            foreach (var junction in nw.Junctions)
            {
                var junction3d = new JunctionL3d();
                junction3d.Id = junction.Id;
                junction3d.Name = junction.Name;
                junction3d.Position = new PointL3d()
                {
                    X = (float)junction.Position.X,
                    Y = (float)junction.Position.Y,
                    Z = (float)junction.GetElev()
                };
                nw3d.Append(junction3d, out msg);
            }
 
            foreach (var pipe in nw.Pipes)
            {
                var pipe3d = new PipeL3d();
                pipe3d.Id = pipe.Id;
                pipe3d.Name = pipe.Name;
                pipe3d.StartPosition = new PointL3d()
                {
                    X = (float)pipe.StartNode.Position.X,
                    Y = (float)pipe.StartNode.Position.Y,
                    Z = (float)pipe.StartNode.GetElev()
                };
                pipe3d.EndPosition = new PointL3d()
                {
                    X = (float)pipe.EndNode.Position.X,
                    Y = (float)pipe.EndNode.Position.Y,
                    Z = (float)pipe.EndNode.GetElev()
                };
                nw3d.Append(pipe3d, out msg);
            }
 
            foreach (var pump in nw.Pumps)
            {
                var pump3d = new PumpL3d();
                pump3d.Id = pump.Id;
                pump3d.Name = pump.Name;
                pump3d.StartPosition = new PointL3d()
                {
                    X = (float)pump.StartNode.Position.X,
                    Y = (float)pump.StartNode.Position.Y,
                    Z = (float)pump.StartNode.GetElev()
                };
                pump3d.EndPosition = new PointL3d()
                {
                    X = (float)pump.EndNode.Position.X,
                    Y = (float)pump.EndNode.Position.Y,
                    Z = (float)pump.EndNode.GetElev()
                };
                nw3d.Append(pump3d, out msg);
            }
 
            foreach (var valve in nw.Valves)
            {
                var valve3d = new ValveL3d();
                valve3d.Id = valve.Id;
                valve3d.Name = valve.Name;
                valve3d.StartPosition = new PointL3d()
                {
                    X = (float)valve.StartNode.Position.X,
                    Y = (float)valve.StartNode.Position.Y,
                    Z = (float)valve.StartNode.GetElev()
                };
                valve3d.EndPosition = new PointL3d()
                {
                    X = (float)valve.EndNode.Position.X,
                    Y = (float)valve.EndNode.Position.Y,
                    Z = (float)valve.EndNode.GetElev()
                };
                nw3d.Append(valve3d, out msg);
            }
 
            return nw3d;
 
        }
    }
}