| | |
| | | using Yw.WpfUI.Hydro; |
| | | using Yw.Epanet; |
| | | using System.Windows.Media; |
| | | using System.Security.Policy; |
| | | using System.IO; |
| | | |
| | | |
| | | namespace Yw.Wpf.Test.Core |
| | |
| | | { |
| | | InitializeComponent(); |
| | | this.Loaded += MainWindow_Loaded; |
| | | //Initialize3DScene(); |
| | | this.KeyDown += MainWindow_KeyDown; |
| | | } |
| | | |
| | | |
| | | private NetworkL3d _nw = null; |
| | | private void MainWindow_Loaded(object sender, RoutedEventArgs e) |
| | | { |
| | | var nw = LoadEpaNetwork(); |
| | | var nw3d = Get3dNetwork(nw); |
| | | this.viewer.Initial(nw3d); |
| | | //BuildSimpleNetwork(this.viewport,nw3d.Nodes,nw3d.Links); |
| | | _nw = Get3dNetwork(nw); |
| | | //_nw = new NetworkL3d(); |
| | | this.editer.Initial(_nw); |
| | | } |
| | | |
| | | private void MainWindow_KeyDown(object sender, KeyEventArgs e) |
| | | { |
| | | if (e.Key== Key.Escape) |
| | | { |
| | | editer.EndEdit(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | private Yw.Epanet.Network LoadEpaNetwork() |
| | | { |
| | |
| | | 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() |
| | | }; |
| | | pipe3d.StartNode = nw3d.Nodes.Find(x => x.Id == pipe.StartNodeId); |
| | | pipe3d.EndNode = nw3d.Nodes.Find(x => x.Id == pipe.EndNodeId); |
| | | nw3d.Append(pipe3d, out msg); |
| | | } |
| | | |
| | |
| | | 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() |
| | | }; |
| | | pump3d.StartNode = nw3d.Nodes.Find(x => x.Id == pump.StartNodeId); |
| | | pump3d.EndNode = nw3d.Nodes.Find(x => x.Id == pump.EndNodeId); |
| | | nw3d.Append(pump3d, out msg); |
| | | } |
| | | |
| | |
| | | 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() |
| | | }; |
| | | valve3d.StartNode = nw3d.Nodes.Find(x => x.Id == valve.StartNodeId); |
| | | valve3d.EndNode = nw3d.Nodes.Find(x => x.Id == valve.EndNodeId); |
| | | nw3d.Append(valve3d, out msg); |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | public void BuildSimpleNetwork(HelixViewport3D viewport, List<NodeL3d> nodes, List<LinkL3d> pipes) |
| | | private void AddJunction_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | |
| | | // 清空现有内容 |
| | | viewport.Children.Clear(); |
| | | |
| | | // 添加光源 |
| | | viewport.Children.Add(new DefaultLights()); |
| | | |
| | | // 创建节点集合(点精灵技术) |
| | | var pointsVisual = new PointsVisual3D |
| | | { |
| | | Size = 5, // 显示大小(屏幕像素) |
| | | Color = Colors.Red, |
| | | |
| | | }; |
| | | |
| | | |
| | | nodes.ForEach(x => pointsVisual.Points.Add(new Point3D(x.Position.X, x.Position.Y, x.Position.Z))); |
| | | |
| | | viewport.Children.Add(pointsVisual); |
| | | |
| | | // 2. 显示管道线段(使用LinesVisual3D) |
| | | var linesVisual = new LinesVisual3D |
| | | { |
| | | Points = new Point3DCollection(pipes.Count * 2), // 预分配内存 |
| | | Color = Colors.Blue, |
| | | Thickness = 2.0 |
| | | }; |
| | | |
| | | foreach (var pipe in pipes) |
| | | { |
| | | linesVisual.Points.Add(new Point3D(pipe.StartPosition.X, pipe.StartPosition.Y, pipe.StartPosition.Z)); |
| | | linesVisual.Points.Add(new Point3D(pipe.EndPosition.X, pipe.EndPosition.Y, pipe.EndPosition.Z)); |
| | | } |
| | | |
| | | viewport.Children.Add(linesVisual); |
| | | // 4. 自动缩放到合适大小 |
| | | viewport.ZoomExtents(); |
| | | this.editer.StartAddJunction(); |
| | | } |
| | | |
| | | private void AddReservoir_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.StartAddReservoir(); |
| | | } |
| | | |
| | | private void AddTank_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.StartAddTank(); |
| | | } |
| | | |
| | | private void AddPipe_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.StartAddPipe(); |
| | | } |
| | | |
| | | private void AddHorizPipe_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.StartAddHorizPipe(); |
| | | } |
| | | |
| | | private void AddVertPipe_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.StartAddVertPipe(); |
| | | } |
| | | |
| | | private void AddPump_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.StartAddPump(); |
| | | } |
| | | |
| | | private void AddValve_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.StartAddValve(); |
| | | } |
| | | |
| | | private void TopMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SetTopView(); |
| | | } |
| | | |
| | | private void BottomMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SetBottomView(); |
| | | } |
| | | |
| | | private void LeftMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SetLeftView(); |
| | | } |
| | | |
| | | private void RightMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SetRightView(); |
| | | } |
| | | |
| | | private void FrontMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SetFrontView(); |
| | | } |
| | | |
| | | private void BackMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SetBackView(); |
| | | } |
| | | |
| | | private void BillboardText_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | var list = _nw.Visuals.Select(x => new TextL3d() |
| | | { |
| | | Id = x.Id, |
| | | Text = x.Id |
| | | }).ToList(); |
| | | this.editer.SetBillboardText(list); |
| | | } |
| | | |
| | | private void CheckBox_Checked(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.GridLinesVisible = true; |
| | | } |
| | | |
| | | private void ckGridLines_Unchecked(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.GridLinesVisible = false; |
| | | } |
| | | |
| | | private void ckBackgroud_Checked(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.BackgroudVisible = true; |
| | | this.editer.SetBackgroud("mt.png"); |
| | | } |
| | | |
| | | private void ckBackgroud_Unchecked(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.BackgroudVisible = false; |
| | | } |
| | | |
| | | private void SouthWestMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SetSouthWestView(); |
| | | } |
| | | |
| | | private void SouthEastMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SetSouthEastView(); |
| | | } |
| | | |
| | | private void NonthWestMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SetNorthWestView(); |
| | | } |
| | | |
| | | private void NonthEastMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SetNorthEastView(); |
| | | } |
| | | |
| | | private void SaveDefaultCameraMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.SaveDefaultCamera(); |
| | | } |
| | | |
| | | private void ApplyDefaultCameraMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.ApplyDefaultCamera(); |
| | | } |
| | | |
| | | private void StartEditMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.StartEdit(); |
| | | } |
| | | |
| | | private void EndEditCameraMenuItem_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.EndEdit(); |
| | | } |
| | | |
| | | private void FlowEffect_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | this.editer.ShowFlowDirection(); |
| | | } |
| | | } |
| | | |
| | | |