cloudflight
2024-06-17 b62f5f0104845c2a3a74707792ebf28a506e24f1
Hydraulic/Hydro.MapUI/Map/MapViewer.cs
@@ -1,5 +1,7 @@
//using CloudWaterNetwork.Magnifier;
//using DevExpress.XtraEditors;
using Hydro.CommonBase;
using Hydro.Core.Model;
using Hydro.Inp;
//using ConfigApp;
//using DevExpress.Diagram.Core.Layout;
@@ -7,6 +9,7 @@
//using DevExpress.Utils.Extensions;
//using dict_py_Inner;
using Hydro.MapView;
using Hydro.MapView.Base;
using Hydro.MapView.Common;
using Newtonsoft.Json;
//using ReflectionManager_NameSpace;
@@ -16,20 +19,21 @@
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
//using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.Remoting.Metadata;
//using System.Runtime.InteropServices.WindowsRuntime;
//using System.Runtime.Remoting.Metadata;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
//using System.Windows.Forms.DataVisualization.Charting;
//using static Hydro.Core.ObjectEnum;
using static Hydro.MapView.MapViewEnum;
using static System.Net.Mime.MediaTypeNames;
@@ -102,7 +106,7 @@
        //    DoubleBuffered = true;
        //    SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        //    BackColor = Color.Transparent;
        //}
        public MapViewer(bool showToolBar = false)
@@ -110,7 +114,9 @@
            this.showToolBar = showToolBar;
            InitializeComponent();
            //var propertyForm = new PropertyForm();
            //propertyForm.Dock = DockStyle.Right;
            //this.Controls.Add(propertyForm);
            MapCenter = PointF.Empty;
            zoom = 1.0f;
            DoubleBuffered = true;
@@ -138,6 +144,7 @@
        }   
        private void MapViewer_Load(object sender, EventArgs e)
        {
            GlobalObject.PropertyForm = this.propertyForm;
            this.panel1.Visible = _showToolBar;
            this.statusStrip1.Visible = _showStatusBar;
@@ -165,10 +172,64 @@
            cb_Link_Colour.SelectedIndex = 0;
            map.Init(TC,new DrawDelegate[] { Draw, Draw, DrawH },new MouseDelegate[] { mapMouseDown, mapMouseMove, mapMouseUp, mapMouseWheel });
            map.Init(TC,new DrawDelegate[] { Draw, Draw, DrawBackGroud, DrawH },new MouseDelegate[] { mapMouseDown, mapMouseMove, mapMouseUp, mapMouseWheel });
            TContainer TCCube = new TContainer();
            TCCube.template = new Template();
            TCCube.template.network = new MapViewNetWork();
            TCCube.template.network.Areas = new List<AreaViewModel>();
            Cube cb=new Cube();
            foreach (var item in cb.FacesVertices)
            {
                AreaViewModel area = new AreaViewModel();
                area.ID = item.Key.ToString();
                area.InnerNodes = new List<NodeViewModel>();
                //area.Name= item.Key.ToString();
                //6个面设置不一样的颜色
                switch (item.Key)
                {
                    case 1:
                        area.color = Color.Red;
                        area.Name = "右";
                        break;
                    case 2:
                        area.color = Color.SkyBlue;
                        area.Name = "左";
                        break;
                    case 3:
                        area.color = Color.Green;
                        area.Name = "后";
                        break;
                    case 4:
                        area.color = Color.DarkBlue;
                        area.Name = "前";
                        break;
                    case 5:
                        area.color = Color.Purple;
                        area.Name = "上";
                        break;
                    case 6:
                        area.color = Color.Orange;
                        area.Name = "下";
                        break;
                    default:
                        area.color = Color.White;
                        break;
                }
                foreach (var p in item.Value)
                {
                    NodeViewModel node = new NodeViewModel();
                    node.X = p.X;
                    node.Y = p.Y;
                    node.Elev = p.Z;
                    area.InnerNodes.Add(node);
                }
                TCCube.template.network.Areas.Add(area);
            }
            CubeView.Init(TCCube, new DrawDelegate[] { Draw, Draw, DrawBackGroud, DrawH }, new MouseDelegate[] { mapMouseDown, mapMouseMove, mapMouseUp, mapMouseWheel });
        }
@@ -392,141 +453,7 @@
                __needpaintall = value;
            }
        }
        //protected override void OnPaint(PaintEventArgs e)
        //{
        //    base.OnPaint(e);
        //    if (float.IsInfinity(zoom)) return;
        //    //label_center.Text = $"center:({MapCenter.X.ToString("0.00")} ,{MapCenter.Y.ToString("0.00")})";
        //    //label_zoom.Text = $"Zoom:{zoom.ToString("0.000")}";
        //    //toolStripStatusLabel_rotation.Text = $"Rotation:({Rotation.ToString("0")},{RotationF.ToString("0")})";
        //    //if (!_needPaintAll)
        //    //    return;
        //    int heightOfBar = showToolBar ? 24 : 0;
        //    if (!showToolBar) heightOfBar = 0;
        //    if (e.ClipRectangle != new Rectangle(this.Left, heightOfBar, this.map.Width, this.map.Height - heightOfBar - statusStrip1.Height)) return;
        //    _needPaintAll = false;
        //    if (buffer == null || buffer.Width != Width || buffer.Height != Height)
        //    {
        //        buffer?.Dispose();
        //        buffer = new Bitmap(Width, Height);
        //    }
        //    // 使用缓存绘制,避免在每次重绘时重新计算所有要绘制的元素
        //    //if (bufferG == null) bufferG = Graphics.FromImage(buffer);
        //    using (var bufferG = Graphics.FromImage(buffer))
        //    //using (var bufferG = e.Graphics)
        //    {
        //        // 先将控件的背景填充为白色
        //        bufferG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        //        bufferG.Clear(Color.Transparent);
        //        bufferG.TranslateTransform(Width / 2, Height / 2);
        //        bufferG.ScaleTransform(Zoom.X, Zoom.Y);
        //        bufferG.TranslateTransform(-MapCenter.X, -MapCenter.Y);
        //        //if (_NodeColour==null)
        //        //{
        //        //    cb_Node_Colour_SelectedIndexChanged(1, new EventArgs());
        //        //}
        //        //if (_LinkColour==null)
        //        //{
        //        //    cb_Link_Colour_SelectedIndexChanged(1, new EventArgs());
        //        //}
        //        //BookMark    :绘制地图事件
        //        Draw(bufferG, _Template);
        //        if (_newTemplate?.network != null) Draw(bufferG, _newTemplate);
        //        var r = 2f / zoom;
        //        if (_isDragging && DragStartPos!=new PointF(0,0) && mousePosition!=new PointF(0,0))
        //        {
        //            label_center.Text = $"S:{DragStartPos.X}:{DragStartPos.Y} E:{mousePosition.X}:{mousePosition.Y}";
        //            var _lastMousePosition = DragStartPos;
        //            // 绘制矩形
        //            var start = new PointF((float)Math.Min(mousePosition.X, _lastMousePosition.X), (float)Math.Min(mousePosition.Y, _lastMousePosition.Y));
        //            var size = new SizeF((float)Math.Abs(_lastMousePosition.X - mousePosition.X), (float)Math.Abs(_lastMousePosition.Y - mousePosition.Y));
        //            if (size.Width == 0) size.Width = 0.01f;
        //            if (size.Height == 0) size.Height = 0.01f;
        //            var rectangle0 = new RectangleF(start, size);
        //            using (var pen = new Pen(Color.Black, 0.5f * r))
        //            {
        //                bufferG.DrawRectangles(pen, new RectangleF[] { rectangle0 });
        //            }
        //        }
        //        if (_isPainting)
        //        {
        //            if (_mouseState == MouseState.新增立管)
        //            {
        //                var wPos=GetZZWorldPoint(_select_junction1.Position3D, _MousePosition,new Vector3(0,0,1));
        //                using (var pen = new Pen(Color.Black, 1 * r))
        //                {
        //                    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
        //                    bufferG.DrawLine(pen, WorldPointToMapPoint(_select_junction1), WorldPointToMapPoint(wPos));
        //                }
        //            }
        //            else
        //            {
        //                using (var pen = new Pen(Color.Black, 1 * r))
        //                {
        //                    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
        //                    bufferG.DrawLine(pen, WorldPointToMapPoint(_select_junction1), _MousePosition);
        //                }
        //            }
        //        }
        //        if (_isDrawingPolygon && polygonPoints.Count > 0)
        //        {
        //            List<PointF> pf = polygonPoints.ToList();
        //            pf.Add(new PointF(mousePosition.X, mousePosition.Y));
        //            using (var pen = new Pen(Color.Black, 1 * r))
        //            {
        //                // 绘制多边形虚线边框
        //                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
        //                bufferG.DrawLines(pen, pf.ToArray());
        //            }
        //        }
        //        if (_isSettingBackGroundPictur)
        //        {
        //            var _lastMousePosition = DragStartPos;
        //            // 绘制矩形
        //            var start = new PointF((float)Math.Min(mousePosition.X, _lastMousePosition.X), (float)Math.Min(mousePosition.Y, _lastMousePosition.Y));
        //            var size = new SizeF((float)Math.Abs(_lastMousePosition.X - mousePosition.X), (float)Math.Abs(_lastMousePosition.Y - mousePosition.Y));
        //            var rectangle0 = new RectangleF(start, size);
        //            using (var pen = new Pen(Color.Black, 1 * r))
        //            {
        //                bufferG.DrawRectangles(pen, new RectangleF[] { rectangle0 });
        //            }
        //        }
        //        if (_isMovingObject)
        //        {
        //            var newP = _MousePosition;
        //            //var p = MapPointToWorldPoint(, _OperaNode.Elev);
        //            var oldP3D = (PointF3D)_undoOldValue;
        //            var oldP = WorldPointToMapPoint(new PointF(oldP3D.X, oldP3D.Y), oldP3D.Z);
        //            List<PointF> pf = new List<PointF> { oldP, newP };
        //            using (var pen = new Pen(Color.Black, 1 * r))
        //            {
        //                // 绘制多边形虚线边框
        //                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
        //                bufferG.DrawLines(pen, pf.ToArray());
        //            }
        //        }
        //    }
        //    // 将生成的画布绘制到控件上
        //    e.Graphics.DrawImage(buffer, 0, 0);
        //}
        PointF[] getCurclePoints(int num)
        {
@@ -551,9 +478,13 @@
        private void timer_draw_Tick(object sender, EventArgs e)
        {
            _mouseHoverCheckFlag = true;
            if (_timerDraw)
            if (_timerDraw && map.Status==DrawingStatus.Ready)
            {
                this.map.Invalidate();
            _timerDraw = false;
                this.CubeView.Invalidate();
                _timerDraw = false;
            }
        }
        protected override void OnResize(EventArgs e)
@@ -936,7 +867,8 @@
            }
            if  /*插入结构*/(e.Button == MouseButtons.Left && _isInsertingObject)
            {
                var net = _newTemplate.network;
                var net = _newTemplate.network;//clone
                var net0 = _newTemplate.network.DeepCopyByBin<MapViewNetWork>();
                List<NodeViewModel> nodes = _Nodes.Select(node => (NodeViewModel)node).ToList();
                float minDist = 100f;
                NodeViewModel minNode = null;
@@ -961,7 +893,7 @@
                    var p1 = (PointF3D)_undoOldValue;
                    var p2 = minNode.Position3D;
                    var dd = _newTemplate.OffSet;
                    //var dd = _newTemplate.OffSet;
                    dx = p2.X - p1.X;
                    dy = p2.Y - p1.Y;
                    dz = p2.Z - p1.Z;
@@ -992,7 +924,7 @@
                var list = _Network.Add(net);
                var j = _Network.AddPipe(minNode, _OperaNode);
                j.Length = 0.0001f;
                //j.Length = 0.0001f;
                list.Add(j);
                _OperaNode = null;
                _NewNet.Clear();
@@ -1006,12 +938,18 @@
                selectedObjs.AddRange(list);
                MapObjectExtensions.AddCommand(_Network, "Add", null, list);
                _isInsertingObject = false;
                //_OperaNode = null;
                //_Network.Nodes.AddRange(net.Nodes);
                //_Network.Links.AddRange(net.Links);
                _newTemplate.network = net0;
                _isInsertingObject = true;
                _undoOldValue = new PointF3D(0, 0, 0);
                _OperaNode = _newTemplate.network.Nodes.Find(node => node.ID == _newTemplate.Node1) as NodeViewModel;
                SetMapInvalidate();
                return;
            }
@@ -1868,7 +1806,7 @@
        {
            if (_filePath == null) return;
            FileInfo fi = new FileInfo(_filePath);
            Process.Start("explorer.exe", $"/select,\"{_filePath}\"");
            System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{_filePath}\"");
            //System.Diagnostics.Process.Start("explorer.exe", fi.Directory.FullName);
        }
        private void EPA中打开ToolStripMenuItem_Click(object sender, EventArgs e)
@@ -1876,7 +1814,7 @@
            if (_filePath == null) return;
            Process.Start(@"epanetH\Epanet2wH.exe", _filePath);
            System.Diagnostics.Process.Start(@"epanetH\Epanet2wH.exe", _filePath);
        }
        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
@@ -2594,7 +2532,98 @@
        }
        private void btn_初分配_Click(object sender, EventArgs e)
        {
            string result = null;
            if ((result=_Template.network.CheckValidate())!=null)
            {
                MessageBox.Show(result);
                return;
            }
            List<WaterEquivalentSettings> settings = new List<WaterEquivalentSettings>();
            settings.Add(new WaterEquivalentSettings()
            {
                waterEquivalents=new WaterEquivalentTemplate()
                {
                    ID="1",
                    Name="1",
                    WaterEquivalentCollection=new WaterEquivalentCollection()
                    {
                        new WaterEquivalent()
                        {
                            ID=1008,
                            MinRatedFlow=0.48f,
                            RatedFlow=0.72f,
                            Count=1,
                        },
                        new WaterEquivalent()
                        {
                            ID=1009,
                            MinRatedFlow=0.88f,
                            RatedFlow=0.96f,
                            Count=2,
                        },
                        new WaterEquivalent()
                        {
                            ID=1010,
                            MinRatedFlow=1.08f,
                            RatedFlow=1.08f,
                            Count=3,
                        }
                    }
                },
                Meters=new List<string>()
                {
                    //按以下规律生成数组到M10,"M1","M2"
                        "M1","M2","M3","M4","M5","M6","M7","M8","M9","M10","M11","M12","M13","M14","M15","M16",
                    "M17","M18","M19","M20","M21","M22","M23","M24","M25","M26","M27","M28","M29","M30"
                },
            });
            settings.Add(new WaterEquivalentSettings()
            {
                waterEquivalents = new WaterEquivalentTemplate()
                {
                    ID = "1",
                    Name = "1",
                    WaterEquivalentCollection = new WaterEquivalentCollection()
                    {
                        new WaterEquivalent()
                        {
                            ID=2008,
                            MinRatedFlow=0.48f,
                            RatedFlow=0.48f,
                            Count=1,
                        },
                        new WaterEquivalent()
                        {
                            ID=2009,
                            MinRatedFlow=0.12f,
                            RatedFlow=0.12f,
                            Count=5,
                        },
                        new WaterEquivalent()
                        {
                            ID=2010,
                            MinRatedFlow=0.16f,
                            RatedFlow=0.18f,
                            Count=6,
                        }
                    }
                },
                Meters = new List<string>()
                {
                    //按以下规律生成数组到M10,"M1","M2"
                       "M31","M32","M33","M34","M35","M36","M37","M38","M39","M40","M41","M42","M43","M44","M45","M46","M47","M48","M49","M50","M51","M52","M53","M54","M55","M56","M57","M58","M59","M60","M61","M62","M63","M64","M65","M66","M67","M68","M69","M70","M71","M72","M73","M74","M75","M76","M77","M78","M79","M80"
                },
            });
            var head=_Network.reservoirs.FirstOrDefault().Head;
            _Network.WaterDistribution(_Template.FullPath, GlobalPath.configPath + "config_waterDistri.wdb",settings,40, head);
        }
        public void toolStripButton_计算_Click(object sender, EventArgs e)
        {
@@ -3260,6 +3289,59 @@
            }
        }
        /// <summary>
        /// 批量一键生成楼层模型
        /// </summary>
        public void BatchInsertNet(Template temp)
        {
            var nodes = _Nodes.Where(c => c.Elev > 0).Select(node => (NodeViewModel)node).ToList();
            _undoOldValue = new PointF3D(0, 0, 0);
            _OperaNode = temp.network.Nodes.Find(node => node.ID == temp.Node1) as NodeViewModel;
            //foreach (var item in nodes)
            if (nodes.Any())
            {
                for (var i = 0; i < nodes.Count(); i++)
                {
                    var net = temp.network.DeepCopy();
                    float dx, dy, dz;
                    var p1 = (PointF3D)_undoOldValue;
                    var p2 = nodes[i].Position3D;
                    var dd = temp.OffSet;
                    dx = p2.X - p1.X;
                    dy = p2.Y - p1.Y;
                    dz = p2.Z - p1.Z;
                    net.Nodes.ForEach(n => { ((NodeViewModel)n).Position3D = new PointF3D(n.X + dx, n.Y + dy, n.Elev + dz); });
                    var list = _Network.Add(net);
                    //var j = _Network.AddPipe(nodes[i], _OperaNode);
                    //j.Length = 0.0001f;
                    //list.Add(j);
                    _NewNet.Clear();
                    _Network.BuildRelation();
                    selectedObjs.ForEach(o => o.Selected = false);
                    selectedObjs.Clear();
                    //list.ForEach(m => m.Selected = true);
                    //selectedObjs.AddRange(list);
                    MapObjectExtensions.AddCommand(_Network, "Add", null, list);
                }
                _OperaNode = null;
                //_OperaNode = null;
                //_Network.Nodes.AddRange(net.Nodes);
                //_Network.Links.AddRange(net.Links);
                SetMapInvalidate();
            }
        }
        private void 以当前视角另存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_Template == null) return;
@@ -3392,7 +3474,7 @@
                if (net.StartPoint == null) return;
                string SID = net.StartPoint.ID;
                net.StartPoint=net.Nodes.Find(n => n.ID == SID);
                PointF minPoint = new PointF(net.StartPoint.X, net.StartPoint.Y);
                PointF3D minPoint = net.StartPoint.Position3D;// new PointF(net.StartPoint.X, net.StartPoint.Y);
                Point controlLocation = this.PointToScreen(new Point(0, 0));
                int offsetX = Cursor.Position.X - controlLocation.X;
                int offsetY = Cursor.Position.Y - controlLocation.Y;
@@ -3404,11 +3486,12 @@
                if (hoveredObjs.Count>0 && hoveredObjs[0] is NodeViewModel minNode) 
                {
                   
                    var basePoint = minNode.Position;
                    var basePoint = minNode.Position3D;
                    net.Nodes.ForEach(obj =>
                    {
                        obj.X = obj.X + basePoint.X - minPoint.X;
                        obj.Y = obj.Y + basePoint.Y - minPoint.Y;
                        obj.Elev = obj.Elev + basePoint.Z - minPoint.Z;
                    });
                    
                    selectedObjs.ForEach(o => o.Selected = false);
@@ -3416,7 +3499,7 @@
                    selectedObjs.AddRange(net.Nodes.Select(n => (NodeViewModel)n));
                    selectedObjs.AddRange(net.Links.ViewLinks);
                    var list = _Network.Add(net,null,false,minNode);
                    net.BuildRelation();
                    //list.Add(_Network.AddPipe(Snode, minNode));
                    MapObjectExtensions.AddCommand(_Network, "Add", null, list);
                    SetMapInvalidate();
@@ -3434,6 +3517,7 @@
                    selectedObjs.AddRange(net.Nodes.Select(n => (NodeViewModel)n));
                    selectedObjs.AddRange(net.Links.ViewLinks);
                    var list = _Network.Add(net);
                    net.BuildRelation();
                    MapObjectExtensions.AddCommand(_Network, "Add", null, list);
                    SetMapInvalidate();
                }
@@ -3587,7 +3671,7 @@
            {
                var backgroundImagePath = openFileDialog.FileName;
                Global.ClearFileReadOnly(_Template.BackGroundImg_FullPath);
                File.Copy(backgroundImagePath, _Template.BackGroundImg_FullPath, true);
                FileCopy.Copy(backgroundImagePath, _Template.BackGroundImg_FullPath, true);
                设置底图ToolStripMenuItem_Click(1, new EventArgs());
            }
        }
@@ -3645,13 +3729,13 @@
        {
            if (_filePath == null) return;
            FileInfo fi = new FileInfo(_filePath);
            Process.Start("explorer.exe", $"/select,\"{_filePath}\"");
            System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{_filePath}\"");
        }
        private void label_file_Click(object sender, EventArgs e)
        {
            if (_filePath == null) return;
            FileInfo fi = new FileInfo(_filePath);
            Process.Start("explorer.exe", $"/select,\"{_filePath}\"");
            System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{_filePath}\"");
        }
        private void 设为立管点ToolStripMenuItem_Click(object sender, EventArgs e)
        {
@@ -3825,7 +3909,7 @@
        bool _isShowDirection=false;
        private void 颜色分级管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_Colour form_Colour = new Form_Colour(_Template.Colours);
            Form_Colour form_Colour = new Form_Colour(_Template.Colours,_Template);
            form_Colour.Show(this);
        }
       
@@ -3836,18 +3920,30 @@
        private void cb_Link_Colour_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_Template == null) return;
            var type = cb_Link_Colour.SelectedItem==null?ColourType.管线流量:(ColourType)cb_Link_Colour.SelectedItem;
            mapOption.ColourLink = type;
            var type = cb_Link_Colour.SelectedItem == null ? ColourType.管线流量 : (ColourType)cb_Link_Colour.SelectedItem;
            var doubles = _Template.network.getMinMax(type);
            var colour = new Colour(type, null, type.ToString());
            List<ColourItem> colours = Colour.GetColourItems((float)doubles[0], (float)doubles[1], 5, Color.Gray, Color.Red);
            colour.Items = colours;
            LinkColour = colour;
            this.SetMapInvalidate();
        }
        private void cb_Node_Colour_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_Template == null) return;
            var type = cb_Node_Colour.SelectedItem==null?ColourType.节点自由压力:(ColourType)cb_Node_Colour.SelectedItem;
            mapOption.ColourNode = type;
            var type = cb_Node_Colour.SelectedItem == null ? ColourType.节点自由压力 : (ColourType)cb_Node_Colour.SelectedItem;
            var doubles = _Template.network.getMinMax(type);
            var colour = new Colour(type, null, type.ToString());
            List<ColourItem> colours = Colour.GetColourItems((float)doubles[0], (float)doubles[1], 5, Color.Gray, Color.Red);
            colour.Items = colours;
            NodeColour = colour;
            this.SetMapInvalidate();
        }
        private void label_ZZ_Click(object sender, EventArgs e)